nir: Use deref instructions for UBO and SSBO access coming from GLSL
Previously, we trusted in the
lower_ubo_reference() pass in GLSL IR to lower UBO and SSBO access to intrinsics which take an index and offset. However, as of f393b10b, NIR now has the ability to handle UBO and SSBO derefs and as of 34af63fa, we're using it in our Vulkan driver. Thanks to 60d9bb9f, the NIR optimizer can safely handle SSBO derefs and even do some optimization on them. In 1458aa1f @cmarcelo further improved support in the optimizer. Even with all this work, however, GLSL has never been able to take advantage of it because we're still using
This MR changes all of this by adding a bit more NIR lowering and letting us lower UBO and SSBO derefs later in the compilation pipeline after NIR has had a chance to optimize things. Shader-db results for Kaby Lake are as follows:
total instructions in shared programs: 15187419 -> 15187072 (<.01%) instructions in affected programs: 6298 -> 5951 (-5.51%) helped: 17 HURT: 2 total cycles in shared programs: 338773838 -> 338569919 (-0.06%) cycles in affected programs: 69085718 -> 68881799 (-0.30%) helped: 638 HURT: 680 total loops in shared programs: 4420 -> 4366 (-1.22%) loops in affected programs: 186 -> 132 (-29.03%) helped: 27 HURT: 0 total spills in shared programs: 23267 -> 23240 (-0.12%) spills in affected programs: 38 -> 11 (-71.05%) helped: 1 HURT: 0 total fills in shared programs: 31446 -> 31375 (-0.23%) fills in affected programs: 98 -> 27 (-72.45%) helped: 1 HURT: 0 LOST: 12 GAINED: 12
You can find more analysis of these results on the second-to-last patch.