microsoft / microsoft/DirectXShaderCompiler
[SPIR-V] `static` variables always get nullinitialized
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
Experimenting with Inline-SPIRV for Input/Output variables
[[vk::ext_storage_class(/*spv::StorageClassInput*/1)]]
[[vk::ext_decorate(/*spv::DecorateLocation*/30, 0)]]
[[vk::ext_decorate(/*spv::DecoratePerVertexKHR*/5285)]]
static float4 color[3];
float4 PSMain() : SV_TARGET
{
return color[1];
}
Steps to Reproduce
This Godbolt https://godbolt.org/z/4KfeTcPcv
Actual Behavior
Obvioulsy if the variable is not declared static we run into the whole "implicit Descriptor Set 0" and hidden _Globals variable conundrum - so vars need to be declared static.
DXC loves to Initialize my static variables even if I don't ask for an initializer
%10 = OpConstantNull %_arr_v4float_uint_3
OpStore %color %10
This is obviously a validation error, because you can't write to Input storage class variables.
Also I'd consider it pretty harmful to initialize lets say large arrays or shared memory that I declare with Inline-SPIR-V.
And shouldn't it be OpUndef instead of initialize with null?
Furthermore if we're talking some new exotic storage classes like TileImageEXT, NodePayloadAMDX, CallableData, TaskPayloadWorkgroupEXT, CodeSectionINTEL we most definitely don't want those initialized with OpConstantNull.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Godbolt reproduction and inspect the generated SPIR-V around the static color variable. Trace the compiler path that emits its initialization, then verify the reproduction no longer emits an invalid store to Input storage and does not add unwanted initialization for the listed storage classes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100