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

[glsl-out] Invalid GLSL emission when using firstLeadingBit and others #1968

Closed
hanawatson opened this issue Jun 2, 2022 · 3 comments · Fixed by #1978
Closed

[glsl-out] Invalid GLSL emission when using firstLeadingBit and others #1968

hanawatson opened this issue Jun 2, 2022 · 3 comments · Fixed by #1978
Labels
area: back-end Outputs of shader conversion kind: bug Something isn't working lang: GLSL OpenGL Shading Language

Comments

@hanawatson
Copy link

Apologies for the lack of clarity in #1946, but I didn't mention specifically that the GLSL in that issue was emitted by naga after being provided valid WGSL. I assumed it was a glsl-in problem, but it seems I was incorrect - sorry for the confusion! I'm not sure that the GLSL mentioned in the linked issue should be being output by naga, as it's invalid (as answered in the issue).

WGSL:

@stage(compute) @workgroup_size(1)
fn main() {
    var var0 = firstLeadingBit(abs(0u));
}

GLSL output by naga (included in linked issue, also applies for 450 core):

#version 440 core
#extension GL_ARB_compute_shader : require
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

void main() {
    uint var0_ = findMSB(abs(0u));
}

Error when validating above GLSL with naga (included in linked issue):

error: Unknown function 'findMSB'
  ┌─ temptest.comp:6:18
  │
6 │     uint var0_ = findMSB(abs(0u));
  │                  ^^^^^^^^^^^^^^^^
@JCapucho JCapucho added kind: bug Something isn't working area: back-end Outputs of shader conversion lang: GLSL OpenGL Shading Language labels Jun 7, 2022
@JCapucho
Copy link
Collaborator

JCapucho commented Jun 7, 2022

This actually a problem with wgsl-in since abs is defines as

@const fn abs(e: T) -> T

where T is a scalar or a vector of scalars, but firstLeadingBit is defined as

@const fn firstLeadingBit(e: T) -> T

where T is an i32 or vecN<i32>
Nevermind it's also defined for u32

@JCapucho JCapucho added area: validation Validation of the IR area: back-end Outputs of shader conversion lang: GLSL OpenGL Shading Language and removed area: back-end Outputs of shader conversion lang: GLSL OpenGL Shading Language area: validation Validation of the IR labels Jun 7, 2022
@JCapucho
Copy link
Collaborator

JCapucho commented Jun 7, 2022

I've looked at the other issue referenced and there are mentions of other functions causing the same problems but those definitely only support floats, could you provide some reproductions cases with the other functions like exp?

@hanawatson
Copy link
Author

hanawatson commented Jun 9, 2022

I've looked at the other issue referenced and there are mentions of other functions causing the same problems but those definitely only support floats, could you provide some reproductions cases with the other functions like exp?

Apologies for that - those other functions did cause the same problems in GLSL, but you pointed out that was expected behavior as it was incorrect GLSL. The same behavior doesn't occur in the GLSL output by naga when using e.g. exp, since it is invalid WGSL typing as you say (e.g. exp outputting a float, findLeadingBit expecting an integer) and therefore no GLSL is actually output.

If exp(0.0) is used instead of abs(0u) in the WGSL above, the error message is thrown by naga when validating the WGSL and is:

error: Incompatible operands: FindMsb(Scalar { kind: Float, width: 4 })

Could not parse WGSL

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

Successfully merging a pull request may close this issue.

2 participants