Skip to content

WIP: nir: Add a discard optimization pass

Faith Ekstrand requested to merge gfxstrand/mesa:wip/nir-move-discards into main

Many fragment shaders do a discard using relatively little information but still put the discard fairly far down in the shader for no good reason. If the discard is moved higher up, we can possibly avoid doing some or almost all of the work in the shader. When this lets us skip texturing operations, it's an especially high win.

One of the biggest offenders here is DXVK. The D3D APIs have different rules for discards than OpenGL and Vulkan. One effective way (which is what DXVK uses) to implement DX behavior on top of GL or Vulkan is to wait until the very end of the shader to discard. This ends up in the pessimal case where we always do all of the work before discarding. This pass helps some DXVK shaders significantly.

Unfortunately, back in the day when I first wrote this pass it also hurt a bunch of stuff when I kicked it through Mark's perf CI. I suspect it needs more tuning somehow.

Merge request reports