Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accesses of expressions emitted by unpack4x{I,U}8 in {hlsl,msl}-out cause compilation errors #6772

Open
ErichDonGubler opened this issue Dec 17, 2024 · 2 comments · May be fixed by #6773
Open
Assignees
Labels
api: dx12 Issues with DX12 or DXGI api: metal Issues with Metal area: naga back-end Outputs of naga shader conversion lang: HLSL D3D Shading Language lang: Metal Metal Shading Language naga Shader Translator type: bug Something isn't working

Comments

@ErichDonGubler
Copy link
Member

unpack4x{I,U}8 emits some bit-shifting expressions that aren't composable with further accesses of the members of the emitted uint4. For example, the following WGSL:

@compute @workgroup_size(1, 1)
fn main() {
	let idx = 2;
	_ = unpack4xI8(12u)[idx];
	_ = unpack4xU8(12u)[1];
}
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

using metal::uint;


kernel void main_(
) {
    int phony = int4(12u, 12u >> 8, 12u >> 16, 12u >> 24) << 24 >> 24[2];
    uint phony_1 = uint4(12u, 12u >> 8, 12u >> 16, 12u >> 24) << 24 >> 24.y;
}

This needs to be properly parenthesized, i.e.:

@@ -7,6 +7,6 @@ using metal::uint;
 
 kernel void main_(
 ) {
-    int phony = int4(12u, 12u >> 8, 12u >> 16, 12u >> 24) << 24 >> 24[2];
-    uint phony_1 = uint4(12u, 12u >> 8, 12u >> 16, 12u >> 24) << 24 >> 24.y;
+    int phony = (int4(12u, 12u >> 8, 12u >> 16, 12u >> 24) << 24 >> 24)[2];
+    uint phony_1 = (uint4(12u, 12u >> 8, 12u >> 16, 12u >> 24) << 24 >> 24).y;
 }
@ErichDonGubler ErichDonGubler added type: bug Something isn't working api: metal Issues with Metal area: naga back-end Outputs of naga shader conversion naga Shader Translator labels Dec 17, 2024
@ErichDonGubler ErichDonGubler self-assigned this Dec 17, 2024
@ErichDonGubler ErichDonGubler changed the title Accesses of expressions emitted by unpack4x{I,U}8 on msl-out cause compilation errors Accesses of expressions emitted by unpack4x{I,U}8 in {hlsl,msl}-out cause compilation errors Dec 17, 2024
@ErichDonGubler ErichDonGubler added api: dx12 Issues with DX12 or DXGI lang: HLSL D3D Shading Language labels Dec 17, 2024
@ErichDonGubler
Copy link
Member Author

This issue causes miscompilations on the DX12 and Metal backends. These manifest as internal errors emitted during pipeline compilation.

@ErichDonGubler
Copy link
Member Author

I first noticed this issue while running WebGPU CTS' webgpu:shader,execution,expression,call,builtin,textureLoad:multisampled:* in current Firefox Nightly.

@ErichDonGubler ErichDonGubler added the lang: Metal Metal Shading Language label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: dx12 Issues with DX12 or DXGI api: metal Issues with Metal area: naga back-end Outputs of naga shader conversion lang: HLSL D3D Shading Language lang: Metal Metal Shading Language naga Shader Translator type: bug Something isn't working
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

1 participant