microsoft / microsoft/DirectXShaderCompiler

Sema should not allow assignment to resource

Open
#3,726 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

incorrect-code
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

DXIL backend reports error if the code has assignments to resources e.g.,

Texture2D<float4>               r0;
SamplerState                    r1;
RWByteAddressBuffer             r2;

Texture2D<float4>               x0;
SamplerState                    x1;
RWByteAddressBuffer             x2;

void getResource(out    Texture2D<float4>               a0,
                 out    SamplerState                    a1,
                 out    RWByteAddressBuffer             a2)
{
    a0 = r0;
    a1 = r1;
    a2 = r2;
}

float4 main(): SV_Target
{
    getResource(x0, x1, x2);
    return x0.Sample(x1, float2(x2.Load(0), x2.Load(1)));
}

To enable the error report for the SPIR-V backend, we need a SPIR-V analysis to check if the code conducts OpStore to a resource because it is not trivial to check the assignment by checking only a0 = r0. We have no idea a0 is a reference to a global resource or not.

Unfortunately, the spirv-opt legalization handles the code and somehow generates the legal code: x.legal.txt from the initial code generated by DXC: x.txt

To fix this issue, I guess we need a sophisticated handling in spirv-val ...

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

Compare the provided x.txt and x.legal.txt outputs to understand how spirv-opt changes the generated code, then trace the SPIR-V backend's handling of resource assignments and OpStore. Investigate how spirv-val could detect stores to resources; done means the SPIR-V backend reports the invalid assignment instead of accepting legalized code, consistently with the DXIL backend.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.