Open hasenbanck opened 1 week ago
The bug is that naga's analyzer considers flat interpolants (which integers are by default) to be uniform, which is just plain wrong. There is nothing that says that something flat across the triangle will be subgroup uniform. https://github.com/gfx-rs/wgpu/blob/eb18854b46a4d6c973a1981be6739ec19282f2f3/naga/src/valid/analyzer.rs#L604-L608
That's a big oops!
Description We had an off error that only occured on AMD GPUs (Vega, RDNA1 and RDNA2), where under Vulkan and DX12 textures where rendered with the wrong texel information (see attached screenshot). We use the "SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING" feature to select textures based on non-uniform vertex data inside the fragment shader. We found out, that the AMD devices sometimes used the wrong texture for some texels. We debugged the problem under Vulkan and saw, that sometimes in the SPIRV output the indexes used for indexing the binding array witht the texture where not properly markes as non-uniform indexes.
We traces the problem back to naga, which will not emmit the necessary marker for non-unified indexes when using fragment shader with no wrapper struct for the function parameter. We reproduces the problem using the texture_arrays example.
Repro steps Use the current trunk branch (eb18854b46a4d6c973a1981be6739ec19282f2f3) and remove the wrapper struct for the fragment input:
This will result in SPIRV code which does not have the expected non-uniform index marker in it. It looks like this in HLSL when de-compiled with SPIRV cross:
Normally the indexes should be marked as non-uniform indexes like (using the original texture_arrays code):
It is also possible to skip the wgpu part and directly convert both WGSL shader versions with the help of naga-cli:
Expected vs observed behavior Non-uniform indexes should properly marked as such in the resulting shader modules.
Extra materials
Platform WGPU stable (22.1) and WGPU trunk. Nvidia and Intel devices will accept the SPIRV modules and render them without any problem, but AMD devices on either Windows and Linux will render with artifacts (see screenshot).