microsoft / microsoft/DirectXShaderCompiler

[SPIR-V] Cannot store to OpTypeImage, OpTypeSampler, OpTypeSampledImage, or OpTypeAccelerationStructureKHR objects

Open
#8,417 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage spirv
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description

Fatal error during compilation (during validation if I'm not mistaken):

fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-OpTypeImage-06924] Cannot store to OpTypeImage, OpTypeSampler, OpTypeSampledImage, or OpTypeAccelerationStructureKHR objects
OpStore %21 %27

Steps to Reproduce
Sample code here: https://godbolt.org/z/TETvedGW7

RWBuffer<uint> ShaderPrint_RWEntryBuffer;

struct FShaderPrintBuffers
{
	RWBuffer<uint> RWEntryBuffer;
};

void ShaderPrintValue_Internal(FShaderPrintBuffers Ctx)
{
    int IndexToStore = 0;
    // Replacing the struct member with the global fixes the issue
    InterlockedAdd( Ctx.RWEntryBuffer[2] , 1 , IndexToStore );
    //InterlockedAdd( ShaderPrint_RWEntryBuffer[2], 1 , IndexToStore );
}

void Print(inout FShaderPrintBuffers Ctx)
{
    // Commenting this unroll fixes the issue
    [unroll]
    for (uint CompIt=0;CompIt< 2 ;++CompIt)
    {
        ShaderPrintValue_Internal(Ctx); 
    } 
}

[numthreads(8, 8, 1)]
void MainCS(uint3 DispatchThreadId : SV_DispatchThreadID)
{
	if (all(DispatchThreadId == 0))
	{
    	FShaderPrintBuffers Buffers;
	    Buffers.RWEntryBuffer = ShaderPrint_RWEntryBuffer;
		Print(Buffers);
	}
}

DXC command line: -E MainCS -T cs_6_6 -spirv -Qunused-arguments -HV 2021 -Wno-unknown-attributes -fvk-use-scalar-layout -fspv-svposition-implicit-invariant -fspv-target-env=vulkan1.3

Removing the unroll or using the global directly in the atomic resolves the issue. See comments in code.

Environment

  • DXC version 1.9.2602

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 by reproducing the Godbolt sample with the listed DXC command line and compare the generated SPIR-V for the struct-member atomic with and without [unroll]. Trace the SPIR-V lowering involved in that case; done means the generated module no longer stores to OpTypeImage, OpTypeSampler, OpTypeSampledImage, or OpTypeAccelerationStructureKHR objects while preserving the working cases.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.