-
Notifications
You must be signed in to change notification settings - Fork 576
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
Support for VK_KHR_zero_initialize_workgroup_memory #2443
Comments
Actually I also happened looking into it recently. Your observation is accurate. I will share my current thinking and attempts here.
For the first one, I would say to keep the current logic for non-workgroup memory. But for workgroup (i.e., shared in GLSL, threadgroup in MSL) memory with initializer, we add a simplified logic as I believe workgroup memory can only be initialized with OpConstantNull (Reference: Validation logic in SPIRV-Tools as of now). Now the question becomes how to initialize the memory in different shading languages. In GLSL this is simple, we can just use GL_EXT_null_initializer and initialize everything to In MSL, this becomes trickier. I just attempted the cheapest way out, namely trying to use initializer on threadgroup variables (as MSL "follows" C++14 it should support this, although I have no idea how they map it into implementation). I initialize array or composite types with If the above approach doesn't work, the correct approach should be generating a code snippet after threadgroup variable definition and let the threads cooperatively initialize the memory, and then add a threadgroup barrier. Just like the lowering logic in NIR and the example snippet from Dawn. I've no idea about HLSL, or if we want to support it there at all.
Allowing specialization constant here will affect the code that follows, which (I think) is mainly related to the initializer generation. My current logic (hack) is that if the array size is not literal, assume that it has one element to initialize. Apparently we cannot use the default value of the specialization constant as it can be smaller after specialization, and the compiler won't complain if we have less elements than there actually are in the initializer list. I'm not very sure if I am missing something. |
Also, using specialization constants for array sizes is problematic in MoltenVK (KhronosGroup/MoltenVK#2423). A proper fix requires the aid of SPIRV-Cross, and I have #2442 here and KhronosGroup/MoltenVK#2434 for MoltenVK. Unfortunately I haven't got a review on either side yet. For my own CTS runs I have applied my fix for specialization constants locally. |
This extension allows initializing workgroup memory in shaders using a null constant. It is also required for Vulkan 1.3 support in MoltenVK.
What seems to be missing currently:
Cannot zero-initialize workgroup memory; seems to be unimplemented and blocked by this conditional:
SPIRV-Cross/spirv_glsl.cpp
Line 15776 in 1a7b7ef
The CTS tests for this use specialization constants for array sizes, which is also unsupported with
OpConstantNull
:SPIRV-Cross/spirv_cross_parsed_ir.cpp
Lines 1053 to 1054 in 1a7b7ef
The text was updated successfully, but these errors were encountered: