Closed mitchmindtree closed 3 years ago
I'll add the explanation from @kvark in the wgpu room here too, in case someone hits this problem. The root cause is because we're sampling a color without a specified mip level inside of an if block.
It can be fixed by:
More detailed explanation:
Let me try to explain. In order to compute an implicit LOD (mipmap level), the HW needs to know how much your texture coordinates change per pixel. This is computed from derivatives. Derivatives are computed for 2x2 blocks of rasterized pixels. So for the implicit LOD to make sense, all of the pixel shaders in that 2x2 block (a quad group) need to run this code. Now, if you have a branch on a non-uniform condition (roughly speaking), then some of these pixel shaders may not be running this code, so the derivatives may be broken. In practice, they aren't, because the inactive invocations just compute the same code anyway, but this is implementation-dependent. Imagine, for example, that one of the threads in this 2x2 block has run into a discard(). The HW doesn't have to keep running it, technically, so derivatives stop being defined.
This should be a better source of knowledge - https://themaister.net/blog/2019/09/12/the-weird-world-of-shader-divergence-and-lod/
Hi folks! While updating conrod, I've run into a validation error on an old shader that seemingly worked OK on older versions (0.7 and prior).
Here's the error:
And here's the shader:
and the SPIR-V generated by glslangValidator:
Curiously, if I remove the conditions and just leave the first block like so:
It passes validation without issue. Similarly, if I leave the conditions but remove the texture lookup like so:
This also seems to pass validation without issues.
Perhaps I'm running into some odd edge-case w.r.t doing texture lookup inside of conditional branches?