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

[SPIR-V] Writing to a read only Buffer<> resource produces validation errors (asks to report a bug) #3465

Closed
Dredhog opened this issue Feb 15, 2021 · 2 comments
Assignees
Labels
spirv Work related to SPIR-V

Comments

@Dredhog
Copy link

Dredhog commented Feb 15, 2021

Title

[SPIR-V] Writing to a read only Buffer<> resource produces validation errors (asks to report a bug)

Functional impact

The shader fails to compile without a clear error message which would indicate the issue. The generated message asks to report a bug.

Minimal repro steps

  1. Compile the following shader with dxc.exe -T cs_6_0 -E CSMain -spirv issue_shader.txt:
Buffer<uint> MyBuffer;

[numthreads(1, 1, 1)]
void CSMain (int3 id : SV_DispatchThreadID)
{
    MyBuffer[id.x] = id.y;
};

Expected result

The shader compilation fails with a clear error message indicating where in the source code the invalid write is.

Actual result

fatal error: generated SPIR-V is invalid: Expected Image 'Sampled' parameter to be 0 or 2
  OpImageWrite %18 %17 %15 None

note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Further technical details

Ran this on shader playground with DXC from 2020 12 16

NOTE: the same happens with the DXIL backend but it does not ask to report a bug:

error: validation errors
Function: CSMain: error: store should be on uav resource. Use /Zi for source location.
note: at 'call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 %2, i32 undef, i32 %3, i32 %3, i32 %3, i32 %3, i8 15)' in block '#0' of function 'CSMain'.
Validation failed.

shader playground

@jaebaek jaebaek added the spirv Work related to SPIR-V label Feb 16, 2021
@jaebaek
Copy link
Collaborator

jaebaek commented Feb 16, 2021

@Dredhog Thank you for reporting the issue. We will take a look.

@jaebaek jaebaek self-assigned this Jul 15, 2021
@jaebaek
Copy link
Collaborator

jaebaek commented Jul 15, 2021

I tested it with the current tot 9972b66 build and confirmed it is fixed.

a.hlsl:6:20: error: cannot assign to return value because function 'operator[]<const unsigned int &>' returns a const value
    MyBuffer[id.x] = id.y;
    ~~~~~~~~~~~~~~ ^
note: function 'operator[]<const unsigned int &>' which returns const-qualified type 'const unsigned int &' declared here

The new error message clearly pinpoints the code location causing the error.

@jaebaek jaebaek closed this as completed Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spirv Work related to SPIR-V
Projects
None yet
Development

No branches or pull requests

2 participants