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

local_size_x_id layout qualifier is unrecognized in GLSL compatibility mode #5948

Open
juliusikkala opened this issue Dec 28, 2024 · 3 comments · May be fixed by #5963
Open

local_size_x_id layout qualifier is unrecognized in GLSL compatibility mode #5948

juliusikkala opened this issue Dec 28, 2024 · 3 comments · May be fixed by #5963

Comments

@juliusikkala
Copy link
Contributor

In GLSL/Vulkan, it's possible to define the workgroup size using a specialization constant, using local_size_{x,y,z}_id = <specialization constant id>. This is e.g. useful for ensuring that the workgroup size matches the subgroup size. It appears to not yet be supported by slangc's GLSL compatibility mode.

// test.comp
#version 460
layout(constant_id = 0) const uint WG_SIZE = 8;
layout(local_size_x_id = 0) in;

void main()
{
}

Output:

test.comp(4): error 31216: GLSL layout qualifier is unrecognized
layout(local_size_x_id = 0) in;
       ^~~~~~~~~~~~~~~

(Also, is this feature available via HLSL or Slang proper? I guess this is a GLSL compatibility bug in any case, but in practice I only have like two fairly simple shaders that do this, so porting them to Slang up-front wouldn't too big of a deal.)

@csyonghe
Copy link
Collaborator

csyonghe commented Dec 29, 2024

This feature is not yet supported in Slang. If we are to add support for it, we should just allow:

layout(local_size_x= WG_SIZE) in;

Or

[numthreads(WG_SIZE, 1, 1)]

But right now the sizes are restricted to compile time constants only, and a specialization constant is not a compile time constant.

Slang does have link time constants and they are allowed in numthreads decoration. However you will need to use slang to specialize the shader instead of doing it with the Vulkan api.

See https://shader-slang.com/slang/user-guide/link-time-specialization.html

@juliusikkala
Copy link
Contributor Author

Okay, thanks for the info. I happen to have a bit too much time right now, so I'll probably try to implement this for fun at some point soon and submit some kind of draft PR once it seems to work properly. I already hacked together something that barely works with the GLSL backend only, but what I really need for my hobby project is the SPIR-V backend.

What I'm currently doing in my project is embedding the SPIR-V into the executable and not shipping a compiler with the program, but I'll consider Slang's own specialization if this turns out to be too complicated to implement.

@csyonghe
Copy link
Collaborator

If you just want to add the same local_size_x_id qualifier for glsl input, this shouldn’t be hard. Properly allowing use of specialization constant directly in local_size_x is a bit harder.

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

Successfully merging a pull request may close this issue.

2 participants