microsoft / microsoft/DirectXShaderCompiler

[SPIR-V] `static` variables always get nullinitialized

Open
#7,189 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug spirv
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.