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
allow workgroup size components to be pipeline-overrideable constants #1442
We currently have a workgroup_size attribute for compute shader that takes a 3D grid size expressed as 3 integer literals.
It's very common to tune compute shaders based on workgroup sizes, after initial shader compilation:
in OpenCL you set it at enqueue time: see the local_work_size parameter to clEnqueueNDRangeKernel
in Metal it's the threadsPerThreadgroup parameter to dispatchThreads
in Vulkan you can make workgroup sizes from specialization constants, and then override them at pipeline creation time. See use of the WorkgroupSize builtin.
See also the DXIL reference for compute shaders
It's conceivable to patch in the workgroup size at pipleline creation time by modifying the metadata nodes directly.
It's conceivable to patch in the workgroup size at pipleline creation time by modifying the metadata nodes directly.
While this seems conceivable, it's actually possible to do optimizations based on the statically declared workgroup size. In that case, you have baked the size assumption into the code invisibly, and simply modifying the metadata will yield a broken shader at a different workgroup size. The FXC HLSL->DXBC codepath actually does this aggressively, so no workgroup size modification should be considered legal after compilation.
@tex3d sorry for a dumb question, I don't know the details of DXIL, but I'm confused by your answer.
What code is going to do the optimizations based on the declared workgroup size, exactly? We are talking about WebGPU implementations that generate DXIL directly, we aren't talking about FXC or DXC. So it seems to me that we (the WebGPU implementors) have full power to decide how we process the workgroup size constants when we generate DXIL.
The idea of the 3-word tweak was for the scenario where:
DXIL is generated early
spec constant values are provided later @tex3d pointed out that's not valid because those constant values could have been folded elsewhere not covered by the 3-word tweak.
But @kvark is right that even if DXIL doesn't support spec constants directly, that it's up to implementors to decide when to lower to DXIL.
So as long as implementors who target DXIL take on the responsibility of handling this well, then the feature is ok to include. As far as I know that would be Naga and Tint, and we're both ok with it.
@RafaelCintron@litherum I think we were close to accepting this, with this concern being the only showstopper. The concern is ruled out now, so can we just merge and have it for MVP?
it's up to implementors to decide when to lower to DXIL.
Yes, that's right, as long as we aren't pushing this through something that optimizes based on some up-front values, there is no problem updating these later.
Activity
dneto0 commentedon Feb 17, 2021
This shows how we can map to an HLSL shader using the scheme we talked about for pipeline-overrideable constants that are implemented as #defines
The shader playground output shows how it maps to DXIL, with this fragment indicating the workgroup-size metadata.
See also the DXIL reference for compute shaders
It's conceivable to patch in the workgroup size at pipleline creation time by modifying the metadata nodes directly.
Workgroup size dimensions can be module-scope constants
Workgroup size dimensions can be pipeline-overrideable constants
tex3d commentedon Feb 22, 2021
Re: HLSL and DXIL workgroup size:
While this seems conceivable, it's actually possible to do optimizations based on the statically declared workgroup size. In that case, you have baked the size assumption into the code invisibly, and simply modifying the metadata will yield a broken shader at a different workgroup size. The FXC HLSL->DXBC codepath actually does this aggressively, so no workgroup size modification should be considered legal after compilation.
kvark commentedon Feb 22, 2021
@tex3d sorry for a dumb question, I don't know the details of DXIL, but I'm confused by your answer.
What code is going to do the optimizations based on the declared workgroup size, exactly? We are talking about WebGPU implementations that generate DXIL directly, we aren't talking about FXC or DXC. So it seems to me that we (the WebGPU implementors) have full power to decide how we process the workgroup size constants when we generate DXIL.
dneto0 commentedon Feb 22, 2021
The idea of the 3-word tweak was for the scenario where:
@tex3d pointed out that's not valid because those constant values could have been folded elsewhere not covered by the 3-word tweak.
But @kvark is right that even if DXIL doesn't support spec constants directly, that it's up to implementors to decide when to lower to DXIL.
So as long as implementors who target DXIL take on the responsibility of handling this well, then the feature is ok to include. As far as I know that would be Naga and Tint, and we're both ok with it.
kvark commentedon Feb 22, 2021
@RafaelCintron @litherum I think we were close to accepting this, with this concern being the only showstopper. The concern is ruled out now, so can we just merge and have it for MVP?
tex3d commentedon Feb 23, 2021
Yes, that's right, as long as we aren't pushing this through something that optimizes based on some up-front values, there is no problem updating these later.
Workgroup size dimensions can be pipeline-overrideable constants (#1444)