microsoft / microsoft/DirectXShaderCompiler

Variable has incomplete type 'SamplerState [2]'

Open
#4,666 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello! I have a function in the shader that takes an array of textures and samplers (for ray tracing). It looks like this:

... Reflection(Texture2D<float4> Textures[4],
               SamplerState Samplers[2],
               ...

This function and the shader used to work just fine, however, with the latest version of DXC (https://github.com/microsoft/DirectXShaderCompiler/commit/42eb79311e1c7f4ce6e110ec631243708664133b) it fails with the following error:

hlsl.hlsl:175:42: error: variable has incomplete type 'SamplerState [2]'
                            SamplerState Samplers[2],
                                         ^

Note that placing the sampler into a struct and passing this struct to the function fixes the error for DXIL:

struct Resources
{
    SamplerState Samplers[2];
};
... Reflection(Texture2D<float4> Textures[4],
               Resources Res, // No error
               ...

However, when compiling this shader for SPIR-V, it errors out with the following message:

fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-None-04667] In Vulkan, OpTypeStruct must not contain an opaque type.
  %Test = OpTypeStruct %_arr_type_sampler_uint_2

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

Interestingly, just having the structure before the function actually makes sampler array work.

struct Resources
{
    SamplerState Samplers[2];
};
... Reflection(Texture2D<float4> Textures[4],
               SamplerState Samplers[2], // No error
               ...

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 with the HLSL reproduction in hlsl.hlsl around line 175 and compare behavior before and after the referenced DXC commit. Reproduce both the DXIL and SPIR-V compilations, including the struct workaround. Done means the sampler array parameter compiles correctly without producing invalid SPIR-V.

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
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.