You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SPIR-V] Allow thread group size to be specified with specialization constants #3092
In glsl it's possible to set the thread group / work group size for compute shaders via specialization constants. This allows an application to use different sizes depending e.g. on the hardware limits, without the need for different shaders.
The GL_ARB_gl_spirv extension added explicit qualifiers for this:
"The built-in constant vector gl_WorkGroupSize can be specialized using
the local_size_{xyz}_id qualifiers, to individually give the components
an id. For example:
Related: #4032#2191
Seems like specialization constant logic in dxc doesn't propagate constants that can be evaluated early-on?
(earlier shader models seems to recognize #2191)
One suggestion would be detecting [[xxx]] attributes in [numthreads(4, 4, 1)], and use the actual numbers as the default number (no current code will be affected). Then the following may be ok:
Don't know if OpSpecConstantComposite is currently implemented in dxc, also it seems to reference OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize, things may be easier with a post-processor in this case.
Steven Perron (@s-perron), no I think this is just a bug. We should allow any compile-time constant in that attribute, but I think the way it is implemented we don’t correctly support that. We have a few related issues:
I have a draft PR that implements this: #7084. However, this cannot go into DXC yet. We would need an HLSL spec update. We could add a new attribute or update numthreads. If we update numthreads, the implementation of it will have to completely change. That would need to be discussed.
Also in the compute derivatives feature, the quads are determined by the values in the numthreads attribute. This assumes the values are all known at compile time, so we can add the correct SPIR-V capability/executionmode. We will need to update the HLSL in this respect for the new attribute.
There are solutions to these, but they have to be handled in the HLSL spec first.
The draft PR also includes a partial refactoring of the OpExecutionModeId instruction in the SPIR-V backend. The current implementation is not expressive enough for what we want to do. This refactoring should be pulled out into its own PR.
Add a new attribute vk::LocalSizeId or update the spec for numthreads to allow spec constant.
Update the compute derivatives spec to account for an unknown dimension size.
Refactor the DXC implementation of OpExecutionModeId.
Activity
ehsannas commentedon Aug 19, 2020
Thanks for reporting Sascha Willems (@SaschaWillems)
shangjiaxuan commentedon Jul 27, 2022
Related: #4032 #2191
Seems like specialization constant logic in dxc doesn't propagate constants that can be evaluated early-on?
(earlier shader models seems to recognize #2191)
shangjiaxuan commentedon Jul 27, 2022
One suggestion would be detecting
[[xxx]]attributes in[numthreads(4, 4, 1)], and use the actual numbers as the default number (no current code will be affected). Then the following may be ok:Seems a bit hacky though...
shangjiaxuan commentedon Jul 27, 2022
Sample assembly from
glslccompilation of following code:Assembly:
Don't know if
OpSpecConstantCompositeis currently implemented in dxc, also it seems to referenceOpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize, things may be easier with a post-processor in this case.SaschaWillems commentedon Apr 17, 2023
Any updates on this?
s-perron commentedon Nov 3, 2023
My preferred syntax would be
We can already define spec constants, so I would want to reuse the same syntax, just allow them in the
numthreadsattribute.Chris B (@llvm-beanz) Is this something that would need to go through hlsl specs?
llvm-beanz commentedon Nov 3, 2023
Steven Perron (@s-perron), no I think this is just a bug. We should allow any compile-time constant in that attribute, but I think the way it is implemented we don’t correctly support that. We have a few related issues:
13 remaining items
s-perron commentedon Jan 24, 2025
I have a draft PR that implements this: #7084. However, this cannot go into DXC yet. We would need an HLSL spec update. We could add a new attribute or update numthreads. If we update numthreads, the implementation of it will have to completely change. That would need to be discussed.
Also in the compute derivatives feature, the quads are determined by the values in the numthreads attribute. This assumes the values are all known at compile time, so we can add the correct SPIR-V capability/executionmode. We will need to update the HLSL in this respect for the new attribute.
There are solutions to these, but they have to be handled in the HLSL spec first.
The draft PR also includes a partial refactoring of the OpExecutionModeId instruction in the SPIR-V backend. The current implementation is not expressive enough for what we want to do. This refactoring should be pulled out into its own PR.
vk::LocalSizeIdor update the spec fornumthreadsto allow spec constant.s-perron commentedon Jan 24, 2025
I do not have any timeline on when we can get to this.
[SPIRV] Refactor OpExecutionModeId
[SPIRV] Refactor OpExecutionModeId
[SPIRV] Refactor OpExecutionModeId (#7378)
s-perron commentedon Jul 8, 2025
See #7439
[spirv] Allows spec constants as attribute arguments (for selected at…