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

gl_WorkGroupSize is {1,1,1} if it precedes workgroup size declaration in source #2479

Closed
martty opened this issue Dec 9, 2020 · 3 comments
Closed

Comments

@martty
Copy link

martty commented Dec 9, 2020

Using the variable gl_WorkGroupSize before a workgroup size declaration in the source results in the builtin having the value {1,1,1}. I think this doesn't align with the specification, but even if it does, I think this behavior is counterintuitive and bug-prone, and should merit at least a warning or an error.

#version 460

layout(binding = 0) buffer d {
    uvec3 data1;
    uvec3 data2;
};

void fn(){
    data1 = gl_WorkGroupSize; // {1,1,1}
}

layout(local_size_x = 64) in;

void main(){
    fn();
    data2 = gl_WorkGroupSize; // {64,1,1}
}

http://shader-playground.timjones.io/a5c1b173a1fd1458c9059677b745b6c0

@greg-lunarg
Copy link
Contributor

greg-lunarg commented Dec 23, 2020

I agree that this is a bug, based on this passage from the GLSL spec:

It is a compile-time error to use gl_WorkGroupSize in a shader that does not declare a fixed
workgroup size, or before that shader has declared a fixed workgroup size, using local_size_x,
local_size_y, and local_size_z.

I interpret the word before here as referring to static position, since a dynamic interpretation is trivially true.

I consequently believe that the compiler should have given an error on the usage of gl_WorkgroupSize in fn() since it had not been completely initialized at this static position in the program.

I believe the GLSL spec is clear on this point and does not need to be updated.

I will ping the GLSL spec editor @gnl21 to confirm.

Would you like to submit a PR or have someone else fix it? I should be able to get to this in the near-to-medium term.

@gnl21
Copy link
Contributor

gnl21 commented Dec 28, 2020

I agree that this is a bug and that it should be an error. Perhaps the spec should say that no compilation unit (rather than shader) may use the workgroup size without declaring it.

@greg-lunarg
Copy link
Contributor

Fixed with merge of #2549

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants