KhronosGroup / KhronosGroup/glslang

HLSL: Texture uniform in entry point parameter not being marked as depth

Open
#2,444 3 comments 0 reactions 0 assignees View on GitHub
bug HLSL SPIR-V
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

Take this `test.frag.hlsl` file:
```hlsl
uniform Texture2D shadowmap;
SamplerComparisonState state;

float4 main(in float3 coords) : COLOR {
return shadowmap.SampleCmp(state, coords.xy, coords.z);
}
```
This gets marked as depth image, as expected:
```
❯ glslangValidator -e main -H test.frag.hlsl | grep TypeImage
14: TypeImage 6(float) 2D depth sampled format:Unknown
```
But when the Texture2D is instead in the entry point arguments, it doesn't get marked as depth image:
```hlsl
SamplerComparisonState state;

float4 main(in float3 coords, uniform Texture2D shadowmap) : COLOR {
return shadowmap.SampleCmp(state, coords.xy, coords.z);
}
```
```
❯ glslangValidator -e main -H test.frag.hlsl | grep TypeImage
9: TypeImage 6(float) 2D sampled format:Unknown
```

I first thought that fixing this should be as simple as adding a `trackLinkage` to the right location, but the problem is that the actual uniform TVariable created in `transformEntryPoint` isn't the one that is seen by `handleSamplerTextureCombine`—that one only sees the locally-scoped variable created in `handleFunctionDefinition`. So I'm not really sure what the fix should be.

I ended up working around this by detecting this in our engine and rewriting the variable with a different type, but I am posting this as issue in case others run into it.

Contributor guide

Open the contributing guide

Research direction

Start with the test.frag.hlsl reproductions and compare the glslangValidator -e main -H output for the two parameter forms. Trace transformEntryPoint, handleFunctionDefinition, and handleSamplerTextureCombine to understand which TVariable each stage sees. Done means the entry-point Texture2D used with SampleCmp is emitted as a depth image, matching the uniform declaration case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.