KhronosGroup / glslang

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

Loading shadow texture causes spirv-val error #3653

Closed spencer-lunarg closed 1 month ago

spencer-lunarg commented 3 months ago
#version 450

layout (set = 0, binding = 0) uniform texture2D kTextures2DShadow[];
layout (set = 0, binding = 1) uniform samplerShadow kSamplersShadow[];

void main() {
    float x = texture(sampler2DShadow(kTextures2DShadow[0], kSamplersShadow[0]), vec3(0));
}

The following will produce a spirv-val error

error: line 48: Expected Image to have the same type as Result Type Image
  %29 = OpSampledImage %28 %19 %26

where the SPIR-V looks like

// Image
%9 = OpTypeImage %float 2D 0 0 0 1 Unknown
%19 = OpLoad %9 %18

// Result Type
%27 = OpTypeImage %float 2D 1 0 0 1 Unknown
%28 = OpTypeSampledImage %27
corporateshark commented 2 months ago

I experience this with the new Vulkan SDK 1.3.290 while running the Tiny_MeshLarge demo from https://github.com/corporateshark/lightweightvk.

TheMostDiligent commented 2 months ago

After updating to Vulkan SDK 1.3.290, we also started to see the same validation error.

Here is a simple HLSL shader that triggers this problem:

Texture2D<float>       g_ShadowMap;
SamplerComparisonState g_ShadowMap_sampler;

float SampleShadow(Texture2D<float> ShadowMap)
{
    return ShadowMap.SampleCmp(g_ShadowMap_sampler, float2(0.5, 0.5), 0.0).r;
}

float4 main() : SV_TARGET
{
    float Shadow = SampleShadow(g_ShadowMap);
    return float4(Shadow, Shadow, Shadow, 1.0);
}
arcady-lunarg commented 2 months ago

@spencer-lunarg What should glslang be doing here? I believe your example is valid GLSL, but what is the expected SPIR-V that should be output in such a case so as to not cause validation issues?

spencer-lunarg commented 2 months ago
- %9 = OpTypeImage %float 2D 0 0 0 1 Unknown
+ %9 = OpTypeImage %float 2D 1 0 0 1 Unknown

because the OpLoad for texture(sampler2DShadow(...)) should have a Depth operand of 1

spencer-lunarg commented 1 month ago

https://gitlab.khronos.org/vulkan/vulkan/-/issues/3993 https://github.com/KhronosGroup/SPIRV-Tools/issues/5781

so this has been causing issues everywhere, will wait to see how things are resolved

spencer-lunarg commented 1 month ago

@arcady-lunarg closing with https://github.com/KhronosGroup/SPIRV-Tools/pull/5789 now merged