Skip to content
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

Sema should not allow assignment to resource #3726

Open
jaebaek opened this issue Apr 29, 2021 · 2 comments
Open

Sema should not allow assignment to resource #3726

jaebaek opened this issue Apr 29, 2021 · 2 comments
Labels
incorrect-code Issues relating to handling of incorrect code
Milestone

Comments

@jaebaek
Copy link
Collaborator

jaebaek commented Apr 29, 2021

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 ...

@jaebaek jaebaek added the spirv Work related to SPIR-V label Apr 29, 2021
@jaebaek jaebaek changed the title [SPIRV] do not allow assignment to resource [SPIR-V] do not allow assignment to resource Apr 29, 2021
@jaebaek
Copy link
Collaborator Author

jaebaek commented Apr 29, 2021

This is the first issue mentioned by #3721 (comment)

@damyanp damyanp moved this to For Google in HLSL Triage Jul 16, 2024
@damyanp damyanp added incorrect-code Issues relating to handling of incorrect code and removed spirv Work related to SPIR-V labels Jul 16, 2024
@damyanp
Copy link
Member

damyanp commented Jul 16, 2024

@jaebaek - we think that this is problem that impacts both the DXIL and SPIR-V backends, since relaly this error should be detected in sema.

(For reference, x0, x1 and x2 in the repro should be static)

@damyanp damyanp moved this from For Google to Triaged in HLSL Triage Jul 16, 2024
@damyanp damyanp added this to the Backlog milestone Jul 16, 2024
@damyanp damyanp changed the title [SPIR-V] do not allow assignment to resource Sema should not allow assignment to resource Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incorrect-code Issues relating to handling of incorrect code
Projects
Status: Triaged
Development

No branches or pull requests

2 participants