From 5c672cef1f6ac6b5cd6cd71bd47489b7b7331adb Mon Sep 17 00:00:00 2001 From: "Sami Kiminki (NVIDIA)" <235843927+skiminki-nv@users.noreply.github.com> Date: Fri, 10 Oct 2025 19:39:13 +0300 Subject: 8503 wgsl depth texture (#8645) Add built-in type aliases for DepthTexture* and unify Sampler*Shadow Add the following type aliases: - DepthTexture1D, DepthTexture1DArray - DepthTexture2D, DepthTexture2DArray - DepthTexture2DMS, DepthTexture2DMSArray - DepthTexture3D - DepthTextureCube, DepthTextureCubeArray These match with the type aliases for non-depth textures. Also, unify the Sampler*Shadow type aliases with DepthTexture* ones. This adds the following: - Sampler2DMSShadow - Sampler2DMSArrayShadow and removes the Sampler3DArrayShadow type alias. As a side-effect, the descriptions of Sampler*ArrayShadow type aliases are fixed ("texture-sampler for shadow" ==> "texture-sampler array for shadow"). Update the slang tests to use the newly introduced type aliases instead of the custom type aliases that use _Texture<> directly. Add DepthTexture testing in hlsl-intrinsic/texture/texture-intrinsics. Do this by extracting the test logic of computeMain() in a separate function and parametrize it for non-depth/depth texture types. This adds basic coverage for the following types: - DepthTexture1D - DepthTexture2D - DepthTexture3D - DepthTextureCube - DepthTexture1DArray - DepthTexture2DArray - DepthTextureCubeArray Issue #6166 Issue #8503 --- source/slang/hlsl.meta.slang | 26 ++- .../partial-resident-texture-combined.slang | 31 +-- .../texture/partial-resident-texture.slang | 55 +---- .../texture/texture-intrinsics.slang | 257 ++++++++++++--------- tests/metal/texture-sampler-less.slang | 61 +---- tests/metal/texture.slang | 61 +---- tests/spirv/depth-texture.slang | 13 -- tests/wgsl/texture-gather.slang | 60 +---- tests/wgsl/texture-load.slang | 45 +--- tests/wgsl/texture-sampler-less.slang | 60 +---- tests/wgsl/texture.slang | 60 +---- 11 files changed, 196 insertions(+), 533 deletions(-) diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 26c2a43cb..86e77c650 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -4753,17 +4753,35 @@ ${{{{ } }}}} -// Declare Sampler*Shadow type aliases. +// Declare DepthTexture* and Sampler*Shadow type aliases. ${{{{ for (int shape = 0; shape < 4; shape++) - for (int isArray = 0; isArray<=1; isArray++) + for (int isArray : { 0, 1 }) + for (int isMS : { 0, 1 }) { + if (isMS) + { + // Only DepthTexture2DMS and Sampler2DMSShadow. + if (shape != kCoreModule_ShapeIndex2D) + continue; + } + + // No 3D Array. + if (shape == kCoreModule_ShapeIndex3D && isArray == 1) + continue; }}}} -/// Represents a handle to a $(shapeTypeNames[shape]) combined texture-sampler for shadow comparison. +/// Represents a handle to a$(isMS?" multisampled": "") $(shapeTypeNames[shape]) depth texture$(isArray?" array":""). /// @param format The storage format of the texture. /// @see Please refer to `_Texture` for more information about texture types. /// @category texture_types -typealias Sampler$(shapeTypeNames[shape])$(arrayPostFix[isArray])Shadow = _Texture; +typealias DepthTexture$(shapeTypeNames[shape])$(msPostFix[isMS])$(arrayPostFix[isArray]) = _Texture; + +/// Represents a handle to a$(isMS?" multisampled": "") $(shapeTypeNames[shape]) combined texture-sampler$(isArray?" array":"") for shadow comparison. +/// @param format The storage format of the texture. +/// @see Please refer to `_Texture` for more information about texture types. +/// @category texture_types +typealias Sampler$(shapeTypeNames[shape])$(msPostFix[isMS])$(arrayPostFix[isArray])Shadow = _Texture; + ${{{{ } }}}} diff --git a/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang b/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang index dd5790ee2..b3ccac529 100644 --- a/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang +++ b/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang @@ -44,37 +44,10 @@ Sampler2DArray st2DArray_f32v4; // Combined depth texture samplers. // -__generic -typealias CombinedDepth2d = _Texture< - T, - __Shape2D, - 0, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; - -__generic -typealias CombinedDepth2d_array = _Texture< - T, - __Shape2D, - 1, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; - - //TEST_INPUT: TextureSampler2D(size=4, content = zero, format=D32Float):name cd2D -CombinedDepth2d cd2D; +Sampler2DShadow cd2D; //TEST_INPUT: TextureSampler2D(size=4, content = zero, arrayLength=2, format=D32Float):name cd2DArray -CombinedDepth2d_array cd2DArray; +Sampler2DArrayShadow cd2DArray; uint getNotMapped() { diff --git a/tests/hlsl-intrinsic/texture/partial-resident-texture.slang b/tests/hlsl-intrinsic/texture/partial-resident-texture.slang index 8ba1ca587..6f13bd77a 100644 --- a/tests/hlsl-intrinsic/texture/partial-resident-texture.slang +++ b/tests/hlsl-intrinsic/texture/partial-resident-texture.slang @@ -54,62 +54,11 @@ Texture2DMS t2DMS_f32v4; // // Depth textures. // -__generic -typealias depth2d = _Texture< - T, - __Shape2D, - 0, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 0, // isCombined - format ->; - -__generic -typealias depth2d_array = _Texture< - T, - __Shape2D, - 1, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 0, // isCombined - format ->; - -__generic -typealias depthcube = _Texture< - T, - __ShapeCube, - 0, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 0, // isCombined - format ->; - -__generic -typealias depthcube_array = _Texture< - T, - __ShapeCube, - 1, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 0, // isCombined - format ->; //TEST_INPUT: Texture2D(size=4, content = zero, format=D32Float):name d2D -depth2d d2D; +DepthTexture2D d2D; //TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2, format=D32Float):name d2DArray -depth2d_array d2DArray; +DepthTexture2DArray d2DArray; uint getNotMapped() { diff --git a/tests/hlsl-intrinsic/texture/texture-intrinsics.slang b/tests/hlsl-intrinsic/texture/texture-intrinsics.slang index 91ed13146..c4db8ba70 100644 --- a/tests/hlsl-intrinsic/texture/texture-intrinsics.slang +++ b/tests/hlsl-intrinsic/texture/texture-intrinsics.slang @@ -30,6 +30,22 @@ TextureCube tCube_RGBA; //TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name tCubeArray_RGBA TextureCubeArray tCubeArray_RGBA; +//TEST_INPUT: Texture1D(size=4, format=D32Float, content = one):name d1D +DepthTexture1D d1D; +//TEST_INPUT: Texture2D(size=4, format=D32Float, content = one):name d2D +DepthTexture2D d2D; +//TEST_INPUT: Texture3D(size=4, format=D32Float, content = one):name d3D +DepthTexture3D d3D; +//TEST_INPUT: TextureCube(size=4, format=D32Float, content = one):name dCube +DepthTextureCube dCube; + +//TEST_INPUT: Texture1D(size=4, format=D32Float, content = one, arrayLength=2):name d1DArray +DepthTexture1DArray d1DArray; +//TEST_INPUT: Texture2D(size=4, format=D32Float, content = one, arrayLength=2):name d2DArray +DepthTexture2DArray d2DArray; +//TEST_INPUT: TextureCube(size=4, format=D32Float, content = one, arrayLength=2):name dCubeArray +DepthTextureCubeArray dCubeArray; + //TEST_INPUT: Sampler:name samplerState SamplerState samplerState; //TEST_INPUT: Sampler(depthCompare):name shadowSampler @@ -39,10 +55,19 @@ SamplerComparisonState shadowSampler; //TEST_INPUT: ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer RWStructuredBuffer outputBuffer; -[numthreads(4, 1, 1)] -void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +// note: the RGBA texture types are not parameterized, since the depth +// texture element is always 'float' +float testOperations( + int idx, + _Texture x1D, + _Texture x2D, + _Texture x3D, + _Texture xCube, + _Texture x1DArray, + _Texture x2DArray, + _Texture xCubeArray +) { - int idx = dispatchThreadID.x; float u = idx * (1.0f / 4); float val = 0.0f; @@ -60,32 +85,32 @@ void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) /*