KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
3.05k stars 836 forks source link

HLSL: unwanted implicit conversion from Texture2DArray to Texture2D #3338

Open Ace17 opened 1 year ago

Ace17 commented 1 year ago

Hi,

The following code is rejected by fxc and dxc. However, it is accepted by glslang - which will produce invalid SPIR-V code, if one tries to access texture in f.

void f(Texture2D texture) {}
void g(Texture2DArray array) { f(array); }

https://shader-playground.timjones.io/85b34b00156e57adb4bd6c401925fb7c

arcady-lunarg commented 1 year ago

Could you provide a full reproduction case that demonstrates the generation of invalid SPIR-V?

Ace17 commented 1 year ago

After reducing the test case, it turns out the generation of invalid SPIR-V code might be a separate issue (than the implicit conversion).

Here is a minimized test case anyway. Please do notice the --auto-sampled-textures.

Texture2D Text : register(t1);
SamplerState Samp : register(s1);

struct Combined
{
    Texture2D T;
    SamplerState S;
};

float3 PSMain() : DUMMY
{
  Combined comb;
  comb.T = Text;
  comb.S = Samp;

  // return Text.Load(0); // OK

  return comb.T.Load(0); // invalid code is generated:
  // error: SPIRV-Tools Validation Errors
  // error: Expected Image to be of type OpTypeImage
  //   %62 = OpImageFetch %v4float %54 %69 Lod %int_0
}

Compile with:

glslangValidator -S frag -e PSMain -D -V spirv_issue_3338.hlsl --spirv-val --auto-sampled-textures

The result:

spirv_issue_3338.hlsl
error: SPIRV-Tools Validation Errors
error: Expected Image to be of type OpTypeImage
  %62 = OpImageFetch %v4float %54 %69 Lod %int_0
arcady-lunarg commented 1 year ago

Note that this only reproduces with the --auto-sampled-textures option.

Ace17 commented 1 year ago

Yeah, actually that was my point ;-)

Please do notice the --auto-sampled-textures.

I think the automatic texture/sampler combining might be at fault here.