When does a shader patching(so they called) occur?

This topic contains 2 replies, has 2 voices, and was last updated by  Tobias Hector 4 years, 8 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #31228

    Chrishoo
    Member

    HI all

    I’ve read the presentations of GDC provided by the imgtec website.

    A concept called “shader patching” was mentioned. I’m not sure what exactly it is.
    It seems like to happen when some gl states are changed, and may impact the performance.

    I want to know why this could happen, and what kind of states changing(please be specifically) could make this happen.

    Thanks!

    Chris

    #37064

    Chrishoo
    Member

    Excuse me, I also want to know what the thing: “shader patching” exactly does.
    Thanks!

    #37065

    Hi Chrishoo,

    Shader patching is something we do at run time, after shader compilation but before we actually use the shader to draw something. When a shader is compiled, it is done so semi-generically, so that there is scope to optimise for various reasons. Rather than causing a recompilation of the entire shader every time we need to change something, we simply apply a patch to the existing binary. This operation is generally not that expensive though, and is always done out of either necessity or because it will make the shader run faster.

    So some GL states don’t physically exist as a switch in the hardware, and are instead handled by passing code through the shader. In the case of blend states, we don’t have fixed function blending hardware, instead we patch the current fragment shader with a small binary blob to tell it how to blend.

    There are other reasons we perform shader patching, but they aren’t quantifiable in API terms, and I’m afraid I’m not at liberty to discuss the specifics. However, the way to optimise around these is the same optimisation we ask for other thing – group your draw calls by their various state. In other words, group opaque, blended and alpha tested values together, and group renders using the same shader/textures/vertex data/etc. together. The fewer changes you make between draw calls, the better.

    For the most part there are generally other things you’ll need to optimise well before this becomes an issue though, so I wouldn’t spend too much time worrying about it. As long as you follow the guidelines in the performance recommendations document you should get the best out of your renderer.

    Regards,
    Tobias

Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.