Skip to content

NIR: Work around shaders that don't use the invariant keyword but should

Ian Romanick requested to merge idr/mesa:review/bug-111490 into master

See also

I'm not terribly pleased with patch #2 (closed). Looking at the affected shaders in Hand of Fate 2, they appear to be doing something like:

    gl_Position = view_projection_matrix * (model_matrix * vertex);

There are at least three shaders the transform vertices belonging to polygons that cover the same pixels.. After my original patch, the first shader had the DPH optimization applied. After the first patch in this series, an additional shader gets the DPH optimization applied. There is still at least one other shader that (possibly) isn't getting the optimization applied, and that shader generates a slightly different vertex position. The other possibility, and there definitely are shaders in this game that do this, is that the other shader does:

   gl_Position = model_view_projection_matrix * vertex;

In this case the difference in precision between the two calculations will always be a potential problem.

The number of affected shaders is quite large, but it is much better than just disabling the optimization altogether in vertex and geometry shaders.

The other alternative that I have toyed with is adding a driconf gl_Position_always_invariant that marks gl_Position as invariant in apps that are known to be a problem. I'm never very fond of those kinds of work arounds either.

Merge request reports