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] Resources declared in cbuffer scope result in validation errors instead of being moved out (works with FXC) #4019

Closed
Dredhog opened this issue Oct 19, 2021 · 1 comment · Fixed by #4040
Assignees
Labels
spirv Work related to SPIR-V

Comments

@Dredhog
Copy link

Dredhog commented Oct 19, 2021

Title

[SPIR-V] Resources declared in cbuffer scope result in validation errors instead of being moved out (works with FXC)

Functional impact

Can't declare resources inside of constant buffers which breaks backwards compatibility with FXC. The DXIL backend keeps the resources inside the CBuffer which results in a different cbuffer layout than FXC but as the types aren't opaque they at least don't fail validation so the shaders are usable. The SPIR-V backend results in a validator error about opaque types in the cbuffer.

Minimal repro steps

  1. Compile repro_shader.txt (see below) with dxc.exe -T ps_6_0 -E PSMain -spirv repro_shader.txt:
cbuffer NamedCBuffer
{
    float4 testColor;
    Texture2D myTexture;
    SamplerState mySampler;
}

float4 PSMain(float2 uv : TEXCOORD) : SV_TARGET
{
	return testColor + myTexture.Sample(mySampler, uv);
}
  1. Observe the output errors:
fatal error: generated SPIR-V is invalid: In Vulkan, OpTypeStruct must not contain an opaque type.
  %type_NamedCBuffer = OpTypeStruct %v4float %type_2d_image %type_sampler

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

Expected result

No validator error is printed. This could be achieved by moving the resources out of the cbuffer scope to be be declared in the global scope.

Actual result

Compiler prints the validation error seen in step 2. of the Minimlar repro steps section

Further technical details

Test output copied from shader playground (link here).

Slightly related to #2695, where resources in structs used to be placed in the global cbuffer, which was fixed.

@jaebaek jaebaek self-assigned this Oct 20, 2021
@jaebaek jaebaek added the spirv Work related to SPIR-V label Oct 20, 2021
@jaebaek
Copy link
Collaborator

jaebaek commented Oct 20, 2021

Thank you for reporting this issue. I will take a look.

jaebaek added a commit to jaebaek/DirectXShaderCompiler that referenced this issue Oct 26, 2021
The current DXC does not separate the resources from a cbuffer, which
results in a OpTypeStruct including resources. We have to separate the
resources from a cbuffer.

Fixes microsoft#4019
jaebaek added a commit that referenced this issue Nov 2, 2021
The current DXC does not separate the resources from a cbuffer, which
results in a OpTypeStruct including resources. We have to separate the
resources from a cbuffer.

Fixes #4019
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

Successfully merging a pull request may close this issue.

2 participants