Initializing workgroup memory
kevinboulain opened this issue · comments
As far as I can tell, the workgroup/shared memory (context) can not be declared as to be zero-initialized and one has to do it manually.
KhronosGroup/Vulkan-Docs#1457 has a bunch of interesting links: the extension VK_KHR_zero_initialize_workgroup_memory
(promoted to core in Vulkan 1.3) allows to declare workgroup/shared variables with a null initializer. On the SPIR-V side, OpVariable
with a Workgroup
storage class is allowed to be initialized with OpConstantNull
only (like so).
I don't know what the project would prefer, it could be an option to pass to the SpirvBuilder
(I assume it could be desirable to always initialize these variables) or another symbol (similarly to how storage_buffer
allows extra arguments):
#[spirv(compute(threads(256)))]
fn compute(
#[spirv(workgroup, null_initialized = true)] array: &mut [u32; N],
// ...
) {
// ...
}
Btw, since recently, Naga automatically includes some glue code that zero-initializes workgroup memory.
Yeah, but unless I'm handling it wrong, it doesn't support a bunch of features and that limit its usefulness (e.g.: subgroups or atomics).