diff options
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 6 | ||||
| -rw-r--r-- | tests/spirv/depth-texture.slang | 38 |
2 files changed, 43 insertions, 1 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index b3232de93..36368c3ee 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -2681,7 +2681,11 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex // Vulkan spec 16.1: "The “Depth” operand of OpTypeImage is ignored." SpvWord depth = - ImageOpConstants::unknownDepthImage; // No knowledge of if this is a depth image + inst->isShadow() + ? ImageOpConstants::isDepthImage // But we respect the `isShadow` flag of the + // texture + : ImageOpConstants::unknownDepthImage; // No knowledge of if this is a depth image + SpvWord ms = inst->isMultisample() ? ImageOpConstants::isMultisampled : ImageOpConstants::notMultisampled; diff --git a/tests/spirv/depth-texture.slang b/tests/spirv/depth-texture.slang new file mode 100644 index 000000000..17204249e --- /dev/null +++ b/tests/spirv/depth-texture.slang @@ -0,0 +1,38 @@ +//TEST:SIMPLE(filecheck=SPIRV): -target spirv +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry psMain -stage pixel + +// SPIRV: OpTypeImage %{{.*}} 2D 1 0 0 1 Unknown + +__generic<let sampleCount : int = 0, let format : int = 0> +typealias DepthTexture2D = _Texture< + float, + __Shape2D, + 0, // isArray + 0, // isMS + sampleCount, + 0, // access + 1, // isShadow + 0, // isCombined + format +>; + +[[vk::binding(0, 0)]] DepthTexture2D depthTexture : register(t0); +[[vk::binding(1, 0)]] SamplerComparisonState comparisonSampler : register(s0); + +[[shader("pixel")]] +float4 psMain( + float4 position : SV_POSITION, + float2 texCoord : TEXCOORD0 +) : SV_TARGET { + float comparison = depthTexture.SampleCmp( + comparisonSampler, + texCoord, + 0.5 + ); + + if (comparison != 0.0) { + return float4(1.0, 1.0, 1.0, 1.0); + } else { + return float4(0.0, 0.0, 0.0, 1.0); + } +} |
