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

Using @builtin(sample_mask) in a fragment shader with OpenGL panics due to a naga translation error #6085

Open
RedMindZ opened this issue Aug 6, 2024 · 1 comment
Labels
area: naga back-end Outputs of naga shader conversion lang: GLSL OpenGL Shading Language naga Shader Translator type: bug Something isn't working

Comments

@RedMindZ
Copy link

RedMindZ commented Aug 6, 2024

Description
When using the built-in variable sample_mask in a wgsl fragment shader, naga produces incorrect glsl, leading to a panic when using OpenGL.

Repro steps
Given the following wgsl (which I will call sample_mask.wgsl):

@fragment
fn main(@builtin(sample_mask) sample_mask: u32) -> @location(0) vec4<f32> {
    return vec4<f32>(0.0);
}

Running the command naga sample_mask.wgsl sample_mask.frag produces the following output:

#version 310 es

precision highp float;
precision highp int;

layout(location = 0) out vec4 _fs2p_location0;

void main() {
    uint sample_mask = gl_SampleMaskIn;
    _fs2p_location0 = vec4(0.0);
    return;
}

The problematic line is line 9:

uint sample_mask = gl_SampleMaskIn;

According to the spec, gl_SampleMaskIn is an array, so the correct line should be:

uint sample_mask = gl_SampleMaskIn[0];

Additionally, according to the spec, it appears that gl_SampleMaskIn is only supported in GLES version 3.20, so naga should probably also update the first line from #version 310 es to #version 320 es.

Expected vs observed behavior
Shaders using sample_mask works fine in Vulkan and DX12, but cause a panic in OpenGL.

Platform
This happens both when using the naga command line version 22.0.0, in a simple test program using wgpu 22.1.0, and in my application that uses wgpu 0.20.0.

@teoxoy teoxoy added type: bug Something isn't working area: naga back-end Outputs of naga shader conversion naga Shader Translator lang: GLSL OpenGL Shading Language labels Aug 7, 2024
@teoxoy
Copy link
Member

teoxoy commented Aug 7, 2024

Thanks for the report!
This is a duplicate of #4335 but let's keep it open since it has more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga back-end Outputs of naga shader conversion lang: GLSL OpenGL Shading Language naga Shader Translator type: bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

2 participants