Skip to content

WIP: nir: fix usage of implicit derivatives in non-uniform control flow

This series does 3 things:

  • a large rework of phi handling in the divergence analysis
  • added a 'degree of divergence' index per cf_node
  • a pass to lower implicit derivatives in non-uniform control flow

The rework of phi handling just made things simpler and should also make the pass slightly faster.

The new divergent_cf index is some generic index to indicate how much control flow diverged since the beginning of the shader. Directly comparable are only blocks in a dominance relation. Might also be useful to compute some overall divergence of a shader to make decisions about subgroup sizes and such.

The new pass to lower derivatives in non-uniform control flow is meant as workaround for games which don't respect the specification. It first attempts to just convert discard() intrinsics to demote() and then checks for remaining non-uniform tex instructions which are then lowered to use explicit derivatives computed in less divergent cf.

WIP because there are a few questions open:

  • I tried to find a sane default behavior for the driver to make all games happy, but figured this pass has high impact on shader stats. So, I recommend to only use it for affected games.
  • The pass is quite sensitive when converting discard to demote. It respects loops and subgroup operations. The question is if this is necessary as affected games apparently got it wrong anyway...
  • What should happen with is_helper_invocation and load_helper_invocation?
  • I think there are more tex instructions which use implicit derivatives, but I don't know how to lower them.
  • the commits still need to be squashed and get better messages
  • Do we want to make the divergence information metadata?
Edited by Daniel Schürmann

Merge request reports