Rust-GPU / rust-gpu

🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧
https://rust-gpu.github.io
Apache License 2.0
956 stars 27 forks source link

Workgroup size from spec constant #150

Open Firestar99 opened 1 week ago

Firestar99 commented 1 week ago

When you use subgroups, you can often simplify code by assuming subgroup size == workgroup size for any subgroup intrinsics. But subgroup size is defined by the HW you are executing on, so what you'd need to do is use a specialization constant to set your workgroup size. You can already do this in glsl since vulkan first released:

The built-in vector gl_WorkGroupSize can be specialized using special layout localsize{xyz}_id's applied to the "in" qualifier. For example: layout(local_size_x_id = 18, local_size_z_id = 19) in; This leaves gl_WorkGroupSize.y as a non-specialization constant, with gl_WorkGroupSize being a partially specialized vector. Its x and z components can be later specialized using the ID's 18 and 19.

https://github.com/KhronosGroup/GLSL/blob/3e0d9a3b3f54651ef53d533392a7401a3b19e16d/extensions/khr/GL_KHR_vulkan_glsl.txt#L192