GL_FRAGMENT_SHADER_DERIVATIVE_HINT Is this useful anymore?

Started by
2 comments, last by Hodgman 10 years, 9 months ago

GL_FRAGMENT_SHADER_DERIVATIVE_HINT

This hint apparently enables high quality ( or low quality ) derivatives in fragement shaders.

Does anyone know if this actually does _anything_ on modern hardware?

( eg Nvidia cards etc... )

Anybody know anything about this hint?

I see very little discussion about it anywhere on the internet. :(

Thanks!

Ren

Advertisement

In GPU Pro 2, there's a chapter called "Shader Amortization using Pixel Quad Message Passing", which explains how you can use the derivative functions to communicate between different instances of a pixel shader function, which allows for certain kinds of optimisations to be made.

I've personally used this technique to output to a R10_G10_B10_A2 render target, as if it was a full-resolution R10_G10_B10 target and a half-resolution A8 target, which was pretty useful.

Back to the point, this kind of inter-pixel communication is only possible with "high quality" derivatives. With "low quality" derivatives, only 3 out of every 4 pixels can communicate, with 1 out of 4 pixels being isolated and unable to talk to the others in it's "2x2 quad".

As far as I know, there's no way to query the hardware to see whether "low" or "high" quality derivatives are the default... You can only discover this by attempting to use one of these communication algorithms, and then reading the results to see if it worked or not.

I guess that if you wanted to use one of these techniques, you could first use the GL hint to kindly request "high" quality derivatives, and then test if your algorithm works, to increase your chances.

n.b. as of DX10/GL3 level hardware, all GPUs support both "low" and "high" quality modes (HLSL has different instructions for each, with the old "dFdx" type instructions being a "don't care" option).


Back to the point, this kind of inter-pixel communication is only possible with "high quality" derivatives. With "low quality" derivatives, only 3 out of every 4 pixels can communicate, with 1 out of 4 pixels being isolated and unable to talk to the others in it's "2x2 quad".

Wow. Ok. Yes, this is was I was after. :)

Acknowledgement that there actually _are_ different levels of derivative "quality" on modern hardware.

I help author a high-end tool which runs on the most modern of cards. We're very quality concious ( rather than speed ).

So I'm going to set this hint to HighQuality regardless in our app from now on.

Question:

I know derivatives are used to select mip-map levels during texturing.

Do you know what happens if a polygon occupies only 1 pixel on screen? ( or even 2x1 )

Any idea what the derivatives will give in that scenario? And what mip-map level will be chosen?

Thanks!

Ren

Do you know what happens if a polygon occupies only 1 pixel on screen? ( or even 2x1 )
Any idea what the derivatives will give in that scenario? And what mip-map level will be chosen?

The hardware is designed to always run the shader on 2x2 "quads" of pixels. If a triangle only covers part of a "quad", e.g. 1 pixel, then the GPU will actually execute the shader 4 times so that derivatives are still valid, but not actually use the results for 3 pixels.
Due to this design, extremely tesselated models (which cause pixel-sized triangles) actually reduce your pixel shading efficiency.

This topic is closed to new replies.

Advertisement