Skip to content

Commit 1152af7

Browse files
authored
Fix Sample() with depth texture + sampler comparison state; add minimal repro (#9043)
When something such as depthTexHandle.SampleCmpLevelZero(samplerComparisonState, ...) was translated to GLSL, Slangc erroneously translated this as sampler2DShadowShadow(depthTexHandle,samplerComparisonState, ...). The first 'Shadow' comes from the depthTexHandle type and the second 'Shadow' comes from the sampler state type (comparison = shadow sampler). To fix this while keeping things compatible with the existing use cases, emit the first 'Shadow' in GLSLSourceEmitter::_emitGLSLTextureOrTextureSamplerType() only when the type is a combined texture/sampler type. The sampler state type should decide the sampler type. Also, add a minimal repro for this issue. Fixes #8802
1 parent 7d05189 commit 1152af7

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

source/slang/slang-emit-glsl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,10 @@ void GLSLSourceEmitter::_emitGLSLTextureOrTextureSamplerType(
10631063
{
10641064
m_writer->emit("Array");
10651065
}
1066-
if (type->isShadow())
1066+
1067+
// Note: we're adding 'Shadow' only for combined texture/sampler types. Plain texture
1068+
// types don't have depth/shadow variants in GLSL. (Issue #8802)
1069+
if (type->isCombined() && type->isShadow())
10671070
{
10681071
m_writer->emit("Shadow");
10691072
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//TEST:SIMPLE(filecheck=POSITIVE): -entry fragMain -stage fragment -target glsl
2+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=POSITIVE_RESULT): -vk -emit-spirv-via-glsl
3+
4+
// This is a minimal repro for issue 8802
5+
6+
//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer
7+
RWStructuredBuffer<int> outputBuffer;
8+
9+
//TEST_INPUT: Texture2D(format=D32Float, size=4, content = zero):name texHandle
10+
DepthTexture2D texHandle;
11+
12+
//TEST_INPUT: Sampler(depthCompare):name samplerComparisonState
13+
SamplerComparisonState samplerComparisonState;
14+
15+
[shader("fragment")]
16+
void fragMain()
17+
{
18+
// POSITIVE-NOT: {{(error|warning).*}}:
19+
// POSITIVE: result code = 0
20+
// POSITIVE-NOT: {{(error|warning).*}}:
21+
// POSITIVE-LABEL: main
22+
// POSITIVE-NOT: {{(error|warning).*}}:
23+
24+
// Check that we get a properly constructed shadow sampler
25+
// POSITIVE: textureLod(sampler2DShadow(texHandle{{[^,]*}},samplerComparisonState{{[^,)]*}}),
26+
// POSITIVE-NOT: {{(error|warning).*}}:
27+
28+
int ret = 0;
29+
ret = int((texHandle.SampleCmpLevelZero(samplerComparisonState, float2(0, 0), float(0))).x);
30+
outputBuffer[0] = 0x12345 + ret;
31+
}
32+
33+
[numthreads(4, 1, 1)]
34+
void computeMain()
35+
{
36+
int ret = 0;
37+
ret = int((texHandle.SampleCmpLevelZero(samplerComparisonState, float2(0, 0), float(0))).x);
38+
outputBuffer[0] = 0x12345 + ret;
39+
}
40+
// POSITIVE_RESULT: 12345

0 commit comments

Comments
 (0)