From 93079085d3f406c377d158f600b12330c3ab2495 Mon Sep 17 00:00:00 2001 From: fairywreath Date: Mon, 17 Feb 2025 20:48:11 -0500 Subject: [PATCH 1/8] implement sparse residency samples for spirv --- source/slang/hlsl.meta.slang | 263 +++++++++++++++++++++++++++++------ 1 file changed, 220 insertions(+), 43 deletions(-) diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 81b28b30a9..a7db5b8621 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -1073,6 +1073,7 @@ extension _Texture [ForceInline] T Sample(vector location, vector offset, float clamp, out uint status) { + __requireComputeDerivative(); __target_switch { case hlsl: @@ -1080,6 +1081,20 @@ extension _Texture || T is half || T is vector || T is vector || T is vector , "HLSL supports only float and half type textures"); __intrinsic_asm ".Sample"; + case spirv: + return spirv_asm + { + OpCapability MinLod; + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint __sampledType(T); + + %sparseResult:%sparseResultType = OpImageSparseSampleImplicitLod $this $location ConstOffset|MinLod $offset $clamp; + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1; + + OpStore &status %residentCode; + __truncate $$T result __sampledType(T) %sampled; + }; default: status = 0; return Sample(location, offset, clamp); @@ -1147,17 +1162,30 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] T SampleBias(vector location, float bias, constexpr vector offset, float clamp, out uint status) { __requireComputeDerivative(); __target_switch { - case hlsl: - static_assert(T is float || T is vector || T is vector || T is vector - || T is half || T is vector || T is vector || T is vector - , "HLSL supports only float and half type textures"); - return __getTexture().SampleBias(__getSampler(), location, bias, offset, clamp, status); + case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleBias(__getSampler(), location, bias, offset, clamp, status); + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint __sampledType(T); + + %sparseResult:%sparseResultType = OpImageSparseSampleImplicitLod $this $location Bias|ConstOffset $bias $offset; + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1; + + OpStore &status %residentCode; + __truncate $$T result __sampledType(T) %sampled; + }; } } @@ -1255,7 +1283,7 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] float SampleCmp(vector location, float compareValue, constexpr vector offset, float clamp, out uint status) { __requireComputeDerivative(); @@ -1266,6 +1294,19 @@ extension _Texture || T is half || T is vector || T is vector || T is vector , "HLSL supports only float and half type textures"); return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue, offset, clamp, status); + case spirv: + return spirv_asm + { + OpCapability MinLod; + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint $$float; + + %sparseResult:%sparseResultType = OpImageSparseSampleDrefImplicitLod $this $location $compareValue ConstOffset|MinLod $offset $clamp; + + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + OpStore &status %residentCode; + result:$$float = OpCompositeExtract %sparseResult 1; + }; } } @@ -1290,7 +1331,7 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] float SampleCmpLevelZero(vector location, float compareValue, constexpr vector offset, out uint status) { __target_switch @@ -1300,6 +1341,8 @@ extension _Texture || T is half || T is vector || T is vector || T is vector , "HLSL supports only float and half type textures"); return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset, status); + case spirv: + return SampleCmpLevel(location, compareValue, 0.0, offset, status); } } @@ -1367,7 +1410,7 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, texture_shadowlod)] + [require(hlsl_spirv, texture_shadowlod)] float SampleCmpLevel(vector location, float compareValue, float level, constexpr vector offset, out uint status) { __target_switch @@ -1377,6 +1420,18 @@ extension _Texture || T is half || T is vector || T is vector || T is vector , "HLSL supports only float and half type textures"); return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level, offset, status); + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint $$float; + + %sparseResult:%sparseResultType = OpImageSparseSampleDrefExplicitLod $this $location $compareValue Lod|ConstOffset $level $offset; + + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + OpStore &status %residentCode; + result:$$float = OpCompositeExtract %sparseResult 1; + }; } } @@ -1466,16 +1521,30 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] T SampleGrad(vector location, vector gradX, vector gradY, constexpr vector offset, float lodClamp, out uint status) { __target_switch { - case hlsl: - static_assert(T is float || T is vector || T is vector || T is vector - || T is half || T is vector || T is vector || T is vector - , "HLSL supports only float and half type textures"); - return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset, lodClamp, status); + case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset, lodClamp, status); + case spirv: + return spirv_asm + { + OpCapability MinLod; + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint __sampledType(T); + + %sparseResult:%sparseResultType = OpImageSparseSampleExplicitLod $this $location Grad|ConstOffset|MinLod $gradX $gradY $offset $lodClamp; + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1; + + OpStore &status %residentCode; + __truncate $$T result __sampledType(T) %sampled; + }; } } @@ -1568,16 +1637,29 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] T SampleLevel(vector location, float level, constexpr vector offset, out uint status) { __target_switch { - case hlsl: - static_assert(T is float || T is vector || T is vector || T is vector - || T is half || T is vector || T is vector || T is vector - , "HLSL supports only float and half type textures"); - return __getTexture().SampleLevel(__getSampler(), location, level, offset, status); + case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + return __getTexture().SampleLevel(__getSampler(), location, level, offset, status); + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint __sampledType(T); + + %sparseResult:%sparseResultType = OpImageSparseSampleExplicitLod $this $location Lod|ConstOffset $level $offset; + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1; + + OpStore &status %residentCode; + __truncate $$T result __sampledType(T) %sampled; + }; } } } @@ -1992,6 +2074,7 @@ extension _Texture [ForceInline] T Sample(SamplerState s, vector location, constexpr vector offset, float clamp, out uint status) { + __requireComputeDerivative(); __target_switch { case hlsl: @@ -1999,6 +2082,21 @@ extension _Texture || T is half || T is vector || T is vector || T is vector , "HLSL supports only float and half type textures"); __intrinsic_asm ".Sample"; + case spirv: + return spirv_asm + { + OpCapability MinLod; + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint __sampledType(T); + %sampledImage:__sampledImageType(this) = OpSampledImage $this $s; + + %sparseResult:%sparseResultType = OpImageSparseSampleImplicitLod %sampledImage $location ConstOffset|MinLod $offset $clamp; + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1; + + OpStore &status %residentCode; + __truncate $$T result __sampledType(T) %sampled; + }; default: status = 0; return Sample(s, location, offset, clamp); @@ -2136,17 +2234,32 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] T SampleBias(SamplerState s, vector location, float bias, constexpr vector offset, float clamp, out uint status) { __requireComputeDerivative(); __target_switch { - case hlsl: - static_assert(T is float || T is vector || T is vector || T is vector - || T is half || T is vector || T is vector || T is vector - , "HLSL supports only float and half type textures"); - __intrinsic_asm ".SampleBias"; + case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + __intrinsic_asm ".SampleBias"; + case spirv: + return spirv_asm + { + OpCapability MinLod; + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint __sampledType(T); + %sampledImage:__sampledImageType(this) = OpSampledImage $this $s; + + %sparseResult:%sparseResultType = OpImageSparseSampleImplicitLod %sampledImage $location Bias|ConstOffset|MinLod $bias $offset $clamp; + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1; + + OpStore &status %residentCode; + __truncate $$T result __sampledType(T) %sampled; + }; } } @@ -2287,7 +2400,7 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] float SampleCmp(SamplerComparisonState s, vector location, float compareValue, constexpr vector offset, float clamp, out uint status) { __requireComputeDerivative(); @@ -2298,6 +2411,20 @@ extension _Texture || T is half || T is vector || T is vector || T is vector , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleCmp"; + case spirv: + return spirv_asm + { + OpCapability MinLod; + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint $$float; + %sampledImage:__sampledImageType(this) = OpSampledImage $this $s; + + %sparseResult:%sparseResultType = OpImageSparseSampleDrefImplicitLod %sampledImage $location $compareValue ConstOffset|MinLod $offset $clamp; + + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + OpStore &status %residentCode; + result:$$float = OpCompositeExtract %sparseResult 1; + }; } } @@ -2336,7 +2463,7 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] float SampleCmpLevelZero(SamplerComparisonState s, vector location, float compareValue, constexpr vector offset, out uint status) { __target_switch @@ -2346,6 +2473,8 @@ extension _Texture || T is half || T is vector || T is vector || T is vector , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleCmpLevelZero"; + case spirv: + return SampleCmpLevel(s, location, compareValue, 0.0, offset, status); } } @@ -2415,7 +2544,7 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, texture_shadowlod)] + [require(hlsl_spirv, texture_shadowlod)] float SampleCmpLevel(SamplerComparisonState s, vector location, float compareValue, float level, constexpr vector offset, out uint status) { __target_switch @@ -2425,6 +2554,19 @@ extension _Texture || T is half || T is vector || T is vector || T is vector , "HLSL supports only float and half type textures"); __intrinsic_asm ".SampleCmpLevel"; + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint $$float; + %sampledImage:__sampledImageType(this) = OpSampledImage $this $s; + + %sparseResult:%sparseResultType = OpImageSparseSampleDrefExplicitLod %sampledImage $location $compareValue Lod|ConstOffset $level $offset; + + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + OpStore &status %residentCode; + result:$$float = OpCompositeExtract %sparseResult 1; + }; } } @@ -2610,16 +2752,31 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] T SampleGrad(SamplerState s, vector location, vector gradX, vector gradY, constexpr vector offset, float lodClamp, out uint status) { __target_switch { - case hlsl: - static_assert(T is float || T is vector || T is vector || T is vector - || T is half || T is vector || T is vector || T is vector - , "HLSL supports only float and half type textures"); - __intrinsic_asm ".SampleGrad"; + case hlsl: + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + __intrinsic_asm ".SampleGrad"; + case spirv: + return spirv_asm + { + OpCapability MinLod; + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint __sampledType(T); + %sampledImage:__sampledImageType(this) = OpSampledImage $this $s; + + %sparseResult:%sparseResultType = OpImageSparseSampleExplicitLod %sampledImage $location Grad|ConstOffset|MinLod $gradX $gradY $offset $lodClamp; + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1; + + OpStore &status %residentCode; + __truncate $$T result __sampledType(T) %sampled; + }; } } @@ -2789,16 +2946,30 @@ extension _Texture [__readNone] [ForceInline] - [require(hlsl, sm_5_0)] + [require(hlsl_spirv, sm_5_0)] T SampleLevel(SamplerState s, vector location, float level, constexpr vector offset, out uint status) { __target_switch { case hlsl: - static_assert(T is float || T is vector || T is vector || T is vector - || T is half || T is vector || T is vector || T is vector - , "HLSL supports only float and half type textures"); - __intrinsic_asm ".SampleLevel"; + static_assert(T is float || T is vector || T is vector || T is vector + || T is half || T is vector || T is vector || T is vector + , "HLSL supports only float and half type textures"); + __intrinsic_asm ".SampleLevel"; + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint __sampledType(T); + %sampledImage:__sampledImageType(this) = OpSampledImage $this $s; + + %sparseResult:%sparseResultType = OpImageSparseSampleExplicitLod %sampledImage $location Lod|ConstOffset $level $offset; + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1; + + OpStore &status %residentCode; + __truncate $$T result __sampledType(T) %sampled; + }; } } } @@ -7463,12 +7634,18 @@ T copysign(T x, T y) // Check access status to tiled resource [ForceInline] -[require(hlsl, sm_5_0)] -bool CheckAccessFullyMapped(out uint status) +[require(hlsl_spirv, sm_5_0)] +bool CheckAccessFullyMapped(uint status) { __target_switch { case hlsl: __intrinsic_asm "CheckAccessFullyMapped"; + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + result:$$bool = OpImageSparseTexelsResident $status; + }; } } From 791b6474dcce8bd4cb9d5241b6cd701ae3f8cb29 Mon Sep 17 00:00:00 2001 From: fairywreath Date: Mon, 17 Feb 2025 20:48:17 -0500 Subject: [PATCH 2/8] udpate test --- .../texture/partial-resident-texture.slang | 484 +++++++++++++++++- 1 file changed, 463 insertions(+), 21 deletions(-) diff --git a/tests/hlsl-intrinsic/texture/partial-resident-texture.slang b/tests/hlsl-intrinsic/texture/partial-resident-texture.slang index ba7e318358..18e6e105b6 100644 --- a/tests/hlsl-intrinsic/texture/partial-resident-texture.slang +++ b/tests/hlsl-intrinsic/texture/partial-resident-texture.slang @@ -1,21 +1,427 @@ //TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -shaderobj -output-using-type -use-dxil -profile cs_6_6 -dx12 +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -compute -shaderobj -output-using-type -emit-spirv-directly -render-feature hardware-device -xslang -DVK //TEST_INPUT: ubuffer(data=[2], stride=4):out,name outputBuffer RWStructuredBuffer outputBuffer; -//TEST_INPUT: Texture2D(size=4, content = one):name t2D_f32 -Texture2D t2D_f32; - -//TEST_INPUT: Texture2D(size=4, content = one):name t2DMS_f32 -Texture2DMS t2DMS_f32; - //TEST_INPUT:ubuffer(data=[1 1 1 1]):name=iBuf RWByteAddressBuffer iBuf; //TEST_INPUT: Sampler:name samplerState SamplerState samplerState; +//TEST_INPUT: Sampler:name samplerCmpState +SamplerComparisonState samplerCmpState; + +// +// Textures. +// + +//TEST_INPUT: Texture1D(size=4, content = one):name t1D_f32v3 +Texture1D t1D_f32v3; +//TEST_INPUT: Texture2D(size=4, content = one):name t2D_f32v3 +Texture2D t2D_f32v3; +//TEST_INPUT: Texture3D(size=4, content = one):name t3D_f32v3 +Texture3D t3D_f32v3; +//TEST_INPUT: TextureCube(size=4, content = one):name tCube_f32v3 +TextureCube tCube_f32v3; +//TEST_INPUT: Texture1D(size=4, content = one, arrayLength=2):name t1DArray_f32v3 +Texture1DArray t1DArray_f32v3; +//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2):name t2DArray_f32v3 +Texture2DArray t2DArray_f32v3; +//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name tCubeArray_f32v3 +TextureCubeArray tCubeArray_f32v3; + +//TEST_INPUT: Texture1D(size=4, content = one):name t1D_f32v4 +Texture1D t1D_f32v4; +//TEST_INPUT: Texture2D(size=4, content = one):name t2D_f32v4 +Texture2D t2D_f32v4; +//TEST_INPUT: Texture3D(size=4, content = one):name t3D_f32v4 +Texture3D t3D_f32v4; +//TEST_INPUT: TextureCube(size=4, content = one):name tCube_f32v4 +TextureCube tCube_f32v4; + +//TEST_INPUT: Texture1D(size=4, content = one, arrayLength=2):name t1DArray_f32v4 +Texture1DArray t1DArray_f32v4; +//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2):name t2DArray_f32v4 +Texture2DArray t2DArray_f32v4; +//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name tCubeArray_f32v4 +TextureCubeArray tCubeArray_f32v4; + +//TEST_INPUT: Texture2D(size=4, content = one):name t2DMS_f32v4 +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 = one):name d2D +depth2d d2D; +//TEST_INPUT: TextureCube(size=4, content = one):name dCube +depthcube dCube; +//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2):name d2DArray +depth2d_array d2DArray; +//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name dCubeArray +depthcube_array dCubeArray; + +// +// Combined texture samplers. +// + +//TEST_INPUT: TextureSampler1D(size=4, content = one):name st1D_f32v3 +Sampler1D st1D_f32v3; + +//TEST_INPUT: TextureSampler2D(size=4, content = one):name st2D_f32v3 +Sampler2D st2D_f32v3; + +//TEST_INPUT: TextureSampler3D(size=4, content = one):name st3D_f32v3 +Sampler3D st3D_f32v3; +//TEST_INPUT: TextureSamplerCube(size=4, content = one):name stCube_f32v3 +SamplerCube stCube_f32v3; + +//TEST_INPUT: TextureSampler1D(size=4, content = one, arrayLength=2):name st1DArray_f32v3 +Sampler1DArray st1DArray_f32v3; +//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name st2DArray_f32v3 +Sampler2DArray st2DArray_f32v3; +//TEST_INPUT: TextureSamplerCube(size=4, content = one, arrayLength=2):name stCubeArray_f32v3 +SamplerCubeArray stCubeArray_f32v3; + +//TEST_INPUT: TextureSampler1D(size=4, content = one):name st1D_f32v4 +Sampler1D st1D_f32v4; +//TEST_INPUT: TextureSampler2D(size=4, content = one):name st2D_f32v4 +Sampler2D st2D_f32v4; +//TEST_INPUT: TextureSampler3D(size=4, content = one):name st3D_f32v4 +Sampler3D st3D_f32v4; +//TEST_INPUT: TextureSamplerCube(size=4, content = one):name stCube_f32v4 +SamplerCube stCube_f32v4; + +//TEST_INPUT: TextureSampler1D(size=4, content = one, arrayLength=2):name st1DArray_f32v4 +Sampler1DArray st1DArray_f32v4; +//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name st2DArray_f32v4 +Sampler2DArray st2DArray_f32v4; +//TEST_INPUT: TextureSamplerCube(size=4, content = one, arrayLength=2):name stCubeArray_f32v4 +SamplerCubeArray stCubeArray_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 +>; + +__generic +typealias CombinedDepthcube = _Texture< + T, + __ShapeCube, + 0, // isArray + 0, // isMS + sampleCount, + 0, // access + 1, // isShadow + 1, // isCombined + format +>; + +__generic +typealias CombinedDepthcube_array = _Texture< + T, + __ShapeCube, + 1, // isArray + 0, // isMS + sampleCount, + 0, // access + 1, // isShadow + 1, // isCombined + format +>; + + +//TEST_INPUT: TextureSampler2D(size=4, content = one):name cd2D +CombinedDepth2d cd2D; +//TEST_INPUT: TextureSamplerCube(size=4, content = one):name cdCube +CombinedDepthcube cdCube; +//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name cd2DArray +CombinedDepth2d_array cd2DArray; +//TEST_INPUT: TextureSamplerCube(size=4, content = one, arrayLength=2):name cdCubeArray +CombinedDepthcube_array cdCubeArray; + +uint getNotMapped() +{ + // We want to return a status uint that causes `CheckAccessFullyMapped` to return false. + // These are just educated guesses - actual implementation differ between platforms and drivers. +#if defined(VK) + return 0xFFFFFFFFU; +#else + return 0; +#endif +} + +bool TEST_combinedDepth() +{ + float u = 0.0; + int offset = 0; + float clamp = 0.0; + float slice = 0.0; + float level = 0.0; + float compareValue = 0.0; + + uint status; + + return true + // ================= + // float SampleCmp() + // ================= + && (status = getNotMapped(), all(1.0 == cd2D.SampleCmp(float2(u), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(1.0 == cd2DArray.SampleCmp(float3(u, u, slice), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + + // ========================== + // float SampleCmpLevelZero() + // ========================== + && (status = getNotMapped(), all(1.0 == cd2D.SampleCmpLevelZero(float2(u), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(1.0 == cd2DArray.SampleCmpLevelZero(float3(u, u, slice), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) + + // ====================== + // float SampleCmpLevel() + // ====================== + && (status = getNotMapped(), all(1.0 == cd2D.SampleCmpLevel(float2(u), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(1.0 == cd2DArray.SampleCmpLevel(float3(u, u, slice), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) + ; +} + +bool TEST_sampler( + Sampler1D t1D, + Sampler2D t2D, + Sampler3D t3D, + SamplerCube tCube, + Sampler1DArray t1DArray, + Sampler2DArray t2DArray, + SamplerCubeArray tCubeArray +) where T : ITexelElement, IArithmetic +{ + typealias TN = T; + + float u = 0.0; + int offset = 0; + float clamp = 0.0; + float slice = 0.0; + float bias = 0.0; + float grad = 0.0; + float level = 0.0; + constexpr const float ddx = 0.0f; + constexpr const float ddy = 0.0f; + + uint status; + + return true + // ========== + // T Sample() + // ========== + && (status = getNotMapped(), all(TN(T(1)) == t1D.Sample(u, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.Sample(float2(u), int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.Sample(float3(u), int3(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.Sample(float2(u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.Sample(float3(u, u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status) + + // ============== + // T SampleBias() + // ============== + && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleBias(u, bias, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleBias(float2(u), bias, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleBias(float3(u), bias, int3(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleBias(float2(u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleBias(float3(u, u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status) + + // ============== + // T SampleGrad() + // ============== + && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleGrad(u, ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleGrad(float2(u), ddx, ddy, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleGrad(float3(u), ddx, ddy, int3(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleGrad(float2(u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleGrad(float3(u, u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) + + // ============== + // T SampleLevel() + // ============== + && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleLevel(u, level, offset, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleLevel(float2(u), level, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleLevel(float3(u), level, int3(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleLevel(float2(u, slice), level, offset, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleLevel(float3(u, u, slice), level, offset, status))) && CheckAccessFullyMapped(status) + ; +} + +bool TEST_depthTexture() +{ + float u = 0.0; + int offset = 0; + float clamp = 0.0; + float slice = 0.0; + float level = 0.0; + float compareValue = 0.0; + + uint status; + + return true + // ================= + // float SampleCmp() + // ================= + && (status = getNotMapped(), all(1.0 == d2D.SampleCmp(samplerCmpState, float2(u), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(1.0 == d2DArray.SampleCmp(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + + // ========================== + // float SampleCmpLevelZero() + // ========================== + && (status = getNotMapped(), all(1.0 == d2D.SampleCmpLevelZero(samplerCmpState, float2(u), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(1.0 == d2DArray.SampleCmpLevelZero(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) + + // ====================== + // float SampleCmpLevel() + // ====================== + && (status = getNotMapped(), all(1.0 == d2D.SampleCmpLevel(samplerCmpState, float2(u), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(1.0 == d2DArray.SampleCmpLevel(samplerCmpState, float3(u, u, slice), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) + ; +} + bool TEST_texture( + Texture1D t1D, + Texture2D t2D, + Texture3D t3D, + TextureCube tCube, + Texture1DArray t1DArray, + Texture2DArray t2DArray, + TextureCubeArray tCubeArray, + ) + where T : ITexelElement, IArithmetic +{ + typealias TN = T; + + float u = 0.0; + int offset = 0; + float clamp = 0.0; + float slice = 0.0; + float bias = 0.0; + float grad = 0.0; + float level = 0.0; + constexpr const float ddx = 0.0f; + constexpr const float ddy = 0.0f; + + uint status; + + return true + // ========== + // T Sample() + // ========== + && (status = getNotMapped(), all(TN(T(1)) == t1D.Sample(samplerState, u, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.Sample(samplerState, float2(u), int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.Sample(samplerState, float3(u), int3(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.Sample(samplerState, float2(u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.Sample(samplerState, float3(u, u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status) + + // ============== + // T SampleBias() + // ============== + && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleBias(samplerState, u, bias, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleBias(samplerState, float2(u), bias, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleBias(samplerState, float3(u), bias, int3(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleBias(samplerState, float2(u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleBias(samplerState, float3(u, u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status) + + // ============== + // T SampleGrad() + // ============== + && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleGrad(samplerState, u, ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleGrad(samplerState, float2(u), ddx, ddy, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleGrad(samplerState, float3(u), ddx, ddy, int3(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleGrad(samplerState, float2(u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleGrad(samplerState, float3(u, u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) + + // ============== + // T SampleLevel() + // ============== + && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleLevel(samplerState, u, level, offset, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleLevel(samplerState, float2(u), level, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleLevel(samplerState, float3(u), level, int3(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleLevel(samplerState, float2(u, slice), level, offset, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleLevel(samplerState, float3(u, u, slice), level, offset, status))) && CheckAccessFullyMapped(status) + ; +} + +bool TEST_load( Texture2D t2D, Texture2DMS t2DMS) where T : ITexelElement, IArithmetic @@ -32,20 +438,16 @@ bool TEST_texture( int3 iuvs = int3(iuv, sampleIndex); return true - // Make sure CheckAccessFullyMapped can return false - && (status = 0, !CheckAccessFullyMapped(status)) - - // Sample - && (status = 0, all(TN(T(1)) == t2D.Sample(samplerState, uv, offset, clamp, status))) && CheckAccessFullyMapped(status) - - // Load - && (status = 0, all(TN(T(1)) == t2DMS.Load(iuv, sampleIndex, offset, status))) && CheckAccessFullyMapped(status) - && (status = 0, all(TN(T(1)) == t2D.Load(iuvs, offset, status))) && CheckAccessFullyMapped(status) - && (status = 0, 2 == outputBuffer.Load(0, status)) && CheckAccessFullyMapped(status) - && (status = 0, 1 == iBuf.Load(0, status)) && CheckAccessFullyMapped(status) - && (status = 0, all(int2(1) == iBuf.Load2(0, status))) && CheckAccessFullyMapped(status) - && (status = 0, all(int3(1) == iBuf.Load3(0, status))) && CheckAccessFullyMapped(status) - && (status = 0, all(int4(1) == iBuf.Load4(0, status))) && CheckAccessFullyMapped(status) + // Currently not supported by Slang on VK. +#if !defined(VK) + && (status = getNotMapped(), all(TN(T(1)) == t2DMS.Load(iuv, sampleIndex, offset, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.Load(iuvs, offset, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), 2 == outputBuffer.Load(0, status)) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), 1 == iBuf.Load(0, status)) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(int2(1) == iBuf.Load2(0, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(int3(1) == iBuf.Load3(0, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(int4(1) == iBuf.Load4(0, status))) && CheckAccessFullyMapped(status) +#endif ; } @@ -53,7 +455,47 @@ bool TEST_texture( void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) { bool result = true - && TEST_texture(t2D_f32, t2DMS_f32) + // Make sure CheckAccessFullyMapped can return false + && (!CheckAccessFullyMapped(getNotMapped())) + && TEST_texture( + t1D_f32v3, + t2D_f32v3, + t3D_f32v3, + tCube_f32v3, + t1DArray_f32v3, + t2DArray_f32v3, + tCubeArray_f32v3, + ) + && TEST_texture( + t1D_f32v4, + t2D_f32v4, + t3D_f32v4, + tCube_f32v4, + t1DArray_f32v4, + t2DArray_f32v4, + tCubeArray_f32v4, + ) + && TEST_depthTexture() + && TEST_sampler( + st1D_f32v3, + st2D_f32v3, + st3D_f32v3, + stCube_f32v3, + st1DArray_f32v3, + st2DArray_f32v3, + stCubeArray_f32v3, + ) + && TEST_sampler( + st1D_f32v4, + st2D_f32v4, + st3D_f32v4, + stCube_f32v4, + st1DArray_f32v4, + st2DArray_f32v4, + stCubeArray_f32v4, + ) + && TEST_combinedDepth() + && TEST_load(t2D_f32v4, t2DMS_f32v4) ; //CHK:1 From af7e91be08ddc0329cf8cc6a4c7ee8b8a33f8cfc Mon Sep 17 00:00:00 2001 From: fairywreath Date: Wed, 26 Feb 2025 17:36:11 -0500 Subject: [PATCH 3/8] separate tests to non-combined and combined sampler --- tests/expected-failure-github.txt | 1 + .../partial-resident-texture-combined.slang | 205 +++++++++++++++ .../texture/partial-resident-texture.slang | 240 +----------------- 3 files changed, 215 insertions(+), 231 deletions(-) create mode 100644 tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang diff --git a/tests/expected-failure-github.txt b/tests/expected-failure-github.txt index 8a399b2e08..9f3dc17b51 100644 --- a/tests/expected-failure-github.txt +++ b/tests/expected-failure-github.txt @@ -12,3 +12,4 @@ tests/compute/interface-shader-param-in-struct.slang.4 syn (wgpu) tests/compute/interface-shader-param.slang.5 syn (wgpu) tests/language-feature/shader-params/interface-shader-param-ordinary.slang.4 syn (wgpu) gfx-unit-test-tool/precompiledTargetModule2Vulkan.internal +tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang (dx12) diff --git a/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang b/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang new file mode 100644 index 0000000000..21b16eba8d --- /dev/null +++ b/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang @@ -0,0 +1,205 @@ +// TODO: There are issues running tests combined texture samplers in DX12. +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -shaderobj -output-using-type -use-dxil -profile cs_6_7 -dx12 + +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -compute -shaderobj -output-using-type -emit-spirv-directly -render-feature hardware-device -xslang -DVK + +//TEST_INPUT: ubuffer(data=[2], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +//TEST_INPUT:ubuffer(data=[1 1 1 1]):name=iBuf +RWByteAddressBuffer iBuf; + +// +// Combined texture samplers. +// + +//TEST_INPUT: TextureSampler1D(size=4, content = one):name st1D_f32v3 +Sampler1D st1D_f32v3; +//TEST_INPUT: TextureSampler2D(size=4, content = one):name st2D_f32v3 +Sampler2D st2D_f32v3; +//TEST_INPUT: TextureSampler3D(size=4, content = one):name st3D_f32v3 +Sampler3D st3D_f32v3; + +//TEST_INPUT: TextureSampler1D(size=4, content = one, arrayLength=2):name st1DArray_f32v3 +Sampler1DArray st1DArray_f32v3; +//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name st2DArray_f32v3 +Sampler2DArray st2DArray_f32v3; + +//TEST_INPUT: TextureSampler1D(size=4, content = one):name st1D_f32v4 +Sampler1D st1D_f32v4; +//TEST_INPUT: TextureSampler2D(size=4, content = one):name st2D_f32v4 +Sampler2D st2D_f32v4; +//TEST_INPUT: TextureSampler3D(size=4, content = one):name st3D_f32v4 +Sampler3D st3D_f32v4; + +//TEST_INPUT: TextureSampler1D(size=4, content = one, arrayLength=2):name st1DArray_f32v4 +Sampler1DArray st1DArray_f32v4; +//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name st2DArray_f32v4 +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):name cd2D +CombinedDepth2d cd2D; +//TEST_INPUT: TextureSampler2D(size=4, content = zero, arrayLength=2):name cd2DArray +CombinedDepth2d_array cd2DArray; + +uint getNotMapped() +{ + // We want to return a status uint that causes `CheckAccessFullyMapped` to return false. + // These are just educated guesses - actual implementation differ between platforms and drivers. +#if defined(VK) + return 0xFFFFFFFFU; +#else + return 0; +#endif +} + +bool TEST_combinedDepth() +{ + float u = 0.0; + int offset = 0; + float clamp = 0.0; + float slice = 0.0; + float level = 0.0; + float compareValue = 0.0; + + uint status; + + return true + // ================= + // float SampleCmp() + // ================= + && (status = getNotMapped(), all(0.0 == cd2D.SampleCmp(float2(u), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(0.0 == cd2DArray.SampleCmp(float3(u, u, slice), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + + // ========================== + // float SampleCmpLevelZero() + // ========================== + && (status = getNotMapped(), all(0.0 == cd2D.SampleCmpLevelZero(float2(u), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(0.0 == cd2DArray.SampleCmpLevelZero(float3(u, u, slice), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) + + // ====================== + // float SampleCmpLevel() + // ====================== + && (status = getNotMapped(), all(0.0 == cd2D.SampleCmpLevel(float2(u), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(0.0 == cd2DArray.SampleCmpLevel(float3(u, u, slice), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) + ; +} + +bool TEST_sampler( + Sampler1D t1D, + Sampler2D t2D, + Sampler3D t3D, + Sampler1DArray t1DArray, + Sampler2DArray t2DArray, +) where T : ITexelElement, IArithmetic +{ + typealias TN = T; + + float u = 0.0; + int offset = 0; + float clamp = 0.0; + float slice = 0.0; + float bias = 0.0; + float grad = 0.0; + float level = 0.0; + constexpr const float ddx = 0.0f; + constexpr const float ddy = 0.0f; + + uint status; + + return true + // ========== + // T Sample() + // ========== + && (status = getNotMapped(), all(TN(T(1)) == t1D.Sample(u, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.Sample(float2(u), int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.Sample(float3(u), int3(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.Sample(float2(u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.Sample(float3(u, u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status) + + // ============== + // T SampleBias() + // ============== + && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleBias(u, bias, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleBias(float2(u), bias, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleBias(float3(u), bias, int3(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleBias(float2(u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleBias(float3(u, u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status) + + // ============== + // T SampleGrad() + // ============== + && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleGrad(u, ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleGrad(float2(u), ddx, ddy, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleGrad(float3(u), ddx, ddy, int3(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleGrad(float2(u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleGrad(float3(u, u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) + + // ============== + // T SampleLevel() + // ============== + && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleLevel(u, level, offset, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleLevel(float2(u), level, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleLevel(float3(u), level, int3(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleLevel(float2(u, slice), level, offset, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleLevel(float3(u, u, slice), level, offset, status))) && CheckAccessFullyMapped(status) + ; +} + +[numthreads(4, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + bool result = true + // Make sure CheckAccessFullyMapped can return false + && (!CheckAccessFullyMapped(getNotMapped())) + && TEST_sampler( + st1D_f32v3, + st2D_f32v3, + st3D_f32v3, + st1DArray_f32v3, + st2DArray_f32v3, + ) + && TEST_sampler( + st1D_f32v4, + st2D_f32v4, + st3D_f32v4, + st1DArray_f32v4, + st2DArray_f32v4, + ) + && TEST_combinedDepth() + ; + + //CHK:1 + outputBuffer[0] = int(result); +} diff --git a/tests/hlsl-intrinsic/texture/partial-resident-texture.slang b/tests/hlsl-intrinsic/texture/partial-resident-texture.slang index 18e6e105b6..ee2c21225f 100644 --- a/tests/hlsl-intrinsic/texture/partial-resident-texture.slang +++ b/tests/hlsl-intrinsic/texture/partial-resident-texture.slang @@ -1,4 +1,4 @@ -//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -shaderobj -output-using-type -use-dxil -profile cs_6_6 -dx12 +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -shaderobj -output-using-type -use-dxil -profile cs_6_7 -dx12 //TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -compute -shaderobj -output-using-type -emit-spirv-directly -render-feature hardware-device -xslang -DVK //TEST_INPUT: ubuffer(data=[2], stride=4):out,name outputBuffer @@ -106,118 +106,10 @@ typealias depthcube_array = _Texture< format >; -//TEST_INPUT: Texture2D(size=4, content = one):name d2D +//TEST_INPUT: Texture2D(size=4, content = zero):name d2D depth2d d2D; -//TEST_INPUT: TextureCube(size=4, content = one):name dCube -depthcube dCube; -//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2):name d2DArray +//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name d2DArray depth2d_array d2DArray; -//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name dCubeArray -depthcube_array dCubeArray; - -// -// Combined texture samplers. -// - -//TEST_INPUT: TextureSampler1D(size=4, content = one):name st1D_f32v3 -Sampler1D st1D_f32v3; - -//TEST_INPUT: TextureSampler2D(size=4, content = one):name st2D_f32v3 -Sampler2D st2D_f32v3; - -//TEST_INPUT: TextureSampler3D(size=4, content = one):name st3D_f32v3 -Sampler3D st3D_f32v3; -//TEST_INPUT: TextureSamplerCube(size=4, content = one):name stCube_f32v3 -SamplerCube stCube_f32v3; - -//TEST_INPUT: TextureSampler1D(size=4, content = one, arrayLength=2):name st1DArray_f32v3 -Sampler1DArray st1DArray_f32v3; -//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name st2DArray_f32v3 -Sampler2DArray st2DArray_f32v3; -//TEST_INPUT: TextureSamplerCube(size=4, content = one, arrayLength=2):name stCubeArray_f32v3 -SamplerCubeArray stCubeArray_f32v3; - -//TEST_INPUT: TextureSampler1D(size=4, content = one):name st1D_f32v4 -Sampler1D st1D_f32v4; -//TEST_INPUT: TextureSampler2D(size=4, content = one):name st2D_f32v4 -Sampler2D st2D_f32v4; -//TEST_INPUT: TextureSampler3D(size=4, content = one):name st3D_f32v4 -Sampler3D st3D_f32v4; -//TEST_INPUT: TextureSamplerCube(size=4, content = one):name stCube_f32v4 -SamplerCube stCube_f32v4; - -//TEST_INPUT: TextureSampler1D(size=4, content = one, arrayLength=2):name st1DArray_f32v4 -Sampler1DArray st1DArray_f32v4; -//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name st2DArray_f32v4 -Sampler2DArray st2DArray_f32v4; -//TEST_INPUT: TextureSamplerCube(size=4, content = one, arrayLength=2):name stCubeArray_f32v4 -SamplerCubeArray stCubeArray_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 ->; - -__generic -typealias CombinedDepthcube = _Texture< - T, - __ShapeCube, - 0, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; - -__generic -typealias CombinedDepthcube_array = _Texture< - T, - __ShapeCube, - 1, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; - - -//TEST_INPUT: TextureSampler2D(size=4, content = one):name cd2D -CombinedDepth2d cd2D; -//TEST_INPUT: TextureSamplerCube(size=4, content = one):name cdCube -CombinedDepthcube cdCube; -//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name cd2DArray -CombinedDepth2d_array cd2DArray; -//TEST_INPUT: TextureSamplerCube(size=4, content = one, arrayLength=2):name cdCubeArray -CombinedDepthcube_array cdCubeArray; uint getNotMapped() { @@ -230,101 +122,6 @@ uint getNotMapped() #endif } -bool TEST_combinedDepth() -{ - float u = 0.0; - int offset = 0; - float clamp = 0.0; - float slice = 0.0; - float level = 0.0; - float compareValue = 0.0; - - uint status; - - return true - // ================= - // float SampleCmp() - // ================= - && (status = getNotMapped(), all(1.0 == cd2D.SampleCmp(float2(u), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(1.0 == cd2DArray.SampleCmp(float3(u, u, slice), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) - - // ========================== - // float SampleCmpLevelZero() - // ========================== - && (status = getNotMapped(), all(1.0 == cd2D.SampleCmpLevelZero(float2(u), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(1.0 == cd2DArray.SampleCmpLevelZero(float3(u, u, slice), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) - - // ====================== - // float SampleCmpLevel() - // ====================== - && (status = getNotMapped(), all(1.0 == cd2D.SampleCmpLevel(float2(u), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(1.0 == cd2DArray.SampleCmpLevel(float3(u, u, slice), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) - ; -} - -bool TEST_sampler( - Sampler1D t1D, - Sampler2D t2D, - Sampler3D t3D, - SamplerCube tCube, - Sampler1DArray t1DArray, - Sampler2DArray t2DArray, - SamplerCubeArray tCubeArray -) where T : ITexelElement, IArithmetic -{ - typealias TN = T; - - float u = 0.0; - int offset = 0; - float clamp = 0.0; - float slice = 0.0; - float bias = 0.0; - float grad = 0.0; - float level = 0.0; - constexpr const float ddx = 0.0f; - constexpr const float ddy = 0.0f; - - uint status; - - return true - // ========== - // T Sample() - // ========== - && (status = getNotMapped(), all(TN(T(1)) == t1D.Sample(u, offset, clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t2D.Sample(float2(u), int2(offset), clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t3D.Sample(float3(u), int3(offset), clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t1DArray.Sample(float2(u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t2DArray.Sample(float3(u, u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status) - - // ============== - // T SampleBias() - // ============== - && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleBias(u, bias, offset, clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleBias(float2(u), bias, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleBias(float3(u), bias, int3(offset), clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleBias(float2(u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleBias(float3(u, u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status) - - // ============== - // T SampleGrad() - // ============== - && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleGrad(u, ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleGrad(float2(u), ddx, ddy, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleGrad(float3(u), ddx, ddy, int3(offset), clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleGrad(float2(u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleGrad(float3(u, u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status) - - // ============== - // T SampleLevel() - // ============== - && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleLevel(u, level, offset, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleLevel(float2(u), level, int2(offset), status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleLevel(float3(u), level, int3(offset), status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleLevel(float2(u, slice), level, offset, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleLevel(float3(u, u, slice), level, offset, status))) && CheckAccessFullyMapped(status) - ; -} - bool TEST_depthTexture() { float u = 0.0; @@ -340,20 +137,20 @@ bool TEST_depthTexture() // ================= // float SampleCmp() // ================= - && (status = getNotMapped(), all(1.0 == d2D.SampleCmp(samplerCmpState, float2(u), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(1.0 == d2DArray.SampleCmp(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(0.0 == d2D.SampleCmp(samplerCmpState, float2(u), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(0.0 == d2DArray.SampleCmp(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status) // ========================== // float SampleCmpLevelZero() // ========================== - && (status = getNotMapped(), all(1.0 == d2D.SampleCmpLevelZero(samplerCmpState, float2(u), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(1.0 == d2DArray.SampleCmpLevelZero(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(0.0 == d2D.SampleCmpLevelZero(samplerCmpState, float2(u), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(0.0 == d2DArray.SampleCmpLevelZero(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status) // ====================== // float SampleCmpLevel() // ====================== - && (status = getNotMapped(), all(1.0 == d2D.SampleCmpLevel(samplerCmpState, float2(u), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) - && (status = getNotMapped(), all(1.0 == d2DArray.SampleCmpLevel(samplerCmpState, float3(u, u, slice), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(0.0 == d2D.SampleCmpLevel(samplerCmpState, float2(u), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) + && (status = getNotMapped(), all(0.0 == d2DArray.SampleCmpLevel(samplerCmpState, float3(u, u, slice), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status) ; } @@ -476,25 +273,6 @@ void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) tCubeArray_f32v4, ) && TEST_depthTexture() - && TEST_sampler( - st1D_f32v3, - st2D_f32v3, - st3D_f32v3, - stCube_f32v3, - st1DArray_f32v3, - st2DArray_f32v3, - stCubeArray_f32v3, - ) - && TEST_sampler( - st1D_f32v4, - st2D_f32v4, - st3D_f32v4, - stCube_f32v4, - st1DArray_f32v4, - st2DArray_f32v4, - stCubeArray_f32v4, - ) - && TEST_combinedDepth() && TEST_load(t2D_f32v4, t2DMS_f32v4) ; From 6f45f61396b3140746767bc6f964ec265aa8ee71 Mon Sep 17 00:00:00 2001 From: fairywreath Date: Wed, 26 Feb 2025 23:28:22 -0500 Subject: [PATCH 4/8] remove expected failure --- tests/expected-failure-github.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/expected-failure-github.txt b/tests/expected-failure-github.txt index 9f3dc17b51..8a399b2e08 100644 --- a/tests/expected-failure-github.txt +++ b/tests/expected-failure-github.txt @@ -12,4 +12,3 @@ tests/compute/interface-shader-param-in-struct.slang.4 syn (wgpu) tests/compute/interface-shader-param.slang.5 syn (wgpu) tests/language-feature/shader-params/interface-shader-param-ordinary.slang.4 syn (wgpu) gfx-unit-test-tool/precompiledTargetModule2Vulkan.internal -tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang (dx12) From 8b81472d219e170f9fdc01162167032bf5f3f700 Mon Sep 17 00:00:00 2001 From: fairywreath Date: Wed, 26 Feb 2025 23:32:33 -0500 Subject: [PATCH 5/8] add expected failure for dx12 combined sampler test --- tests/expected-failure-github.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/expected-failure-github.txt b/tests/expected-failure-github.txt index e9f634ea8f..fd12f6c3ff 100644 --- a/tests/expected-failure-github.txt +++ b/tests/expected-failure-github.txt @@ -10,4 +10,5 @@ tests/autodiff/custom-intrinsic.slang.2 syn (wgpu) tests/bugs/buffer-swizzle-store.slang.3 syn (wgpu) tests/compute/interface-shader-param-in-struct.slang.4 syn (wgpu) tests/compute/interface-shader-param.slang.5 syn (wgpu) -tests/language-feature/shader-params/interface-shader-param-ordinary.slang.4 syn (wgpu) \ No newline at end of file +tests/language-feature/shader-params/interface-shader-param-ordinary.slang.4 syn (wgpu) +tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang (dx12) From f4201ce64a3cac2f19e931d2582a268bc0c16ba3 Mon Sep 17 00:00:00 2001 From: fairywreath Date: Fri, 28 Feb 2025 23:40:12 -0500 Subject: [PATCH 6/8] remove expected failure --- tests/expected-failure-github.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/expected-failure-github.txt b/tests/expected-failure-github.txt index fd12f6c3ff..17de0aa262 100644 --- a/tests/expected-failure-github.txt +++ b/tests/expected-failure-github.txt @@ -11,4 +11,3 @@ tests/bugs/buffer-swizzle-store.slang.3 syn (wgpu) tests/compute/interface-shader-param-in-struct.slang.4 syn (wgpu) tests/compute/interface-shader-param.slang.5 syn (wgpu) tests/language-feature/shader-params/interface-shader-param-ordinary.slang.4 syn (wgpu) -tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang (dx12) From 9db5c8f7e7cf253de8525b8df354c9d5bbc102d8 Mon Sep 17 00:00:00 2001 From: fairywreath Date: Fri, 28 Feb 2025 23:45:10 -0500 Subject: [PATCH 7/8] fix submodule merge --- external/glslang | 2 +- external/slang-rhi | 2 +- external/spirv-headers | 2 +- external/spirv-tools | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/external/glslang b/external/glslang index a0995c49eb..8b822ee8ac 160000 --- a/external/glslang +++ b/external/glslang @@ -1 +1 @@ -Subproject commit a0995c49ebcaca2c6d3b03efbabf74f3843decdb +Subproject commit 8b822ee8ac2c3e52926820f46ad858532a895951 diff --git a/external/slang-rhi b/external/slang-rhi index f562c4f423..6b6cc8f951 160000 --- a/external/slang-rhi +++ b/external/slang-rhi @@ -1 +1 @@ -Subproject commit f562c4f4233b947766e3cc19b15ea3646642e3ca +Subproject commit 6b6cc8f9513732c2f8627eeefce7ea7e1a95415d diff --git a/external/spirv-headers b/external/spirv-headers index e7294a8ebe..54a521dd13 160000 --- a/external/spirv-headers +++ b/external/spirv-headers @@ -1 +1 @@ -Subproject commit e7294a8ebed84f8c5bd3686c68dbe12a4e65b644 +Subproject commit 54a521dd130ae1b2f38fef79b09515702d135bdd diff --git a/external/spirv-tools b/external/spirv-tools index 3364b98271..132103f44d 160000 --- a/external/spirv-tools +++ b/external/spirv-tools @@ -1 +1 @@ -Subproject commit 3364b982713a0440d1d342dd5eec65b122a61b71 +Subproject commit 132103f44d719f8df456c4c7b2658278dc422dc6 From 79efab6b724dd91682268b57cca9c94ca071c3aa Mon Sep 17 00:00:00 2001 From: fairywreath Date: Fri, 28 Feb 2025 23:46:19 -0500 Subject: [PATCH 8/8] add back dx12 test failure --- tests/expected-failure-github.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/expected-failure-github.txt b/tests/expected-failure-github.txt index 10897b31e7..c36e142f65 100644 --- a/tests/expected-failure-github.txt +++ b/tests/expected-failure-github.txt @@ -13,3 +13,4 @@ tests/compute/interface-shader-param.slang.5 syn (wgpu) tests/language-feature/shader-params/interface-shader-param-ordinary.slang.4 syn (wgpu) tests/glsl-intrinsic/shader-subgroup/shader-subgroup-builtin-variables.slang.8 (mtl) tests/glsl-intrinsic/shader-subgroup/shader-subgroup-builtin-variables-2.slang.3 (mtl) +tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang (dx12)