diff --git a/docs/command-line-slangc-reference.md b/docs/command-line-slangc-reference.md index e42b32d5150..7862640cb87 100644 --- a/docs/command-line-slangc-reference.md +++ b/docs/command-line-slangc-reference.md @@ -1542,6 +1542,7 @@ A capability describes an optional feature that a target may or may not support. * `texture_querylod` * `texture_querylevels` * `texture_shadowlod` +* `texture_shadowgrad` * `atomic_glsl_float1` * `atomic_glsl_float2` * `atomic_glsl_halfvec` diff --git a/docs/user-guide/a3-02-reference-capability-atoms.md b/docs/user-guide/a3-02-reference-capability-atoms.md index 7a025986c65..1e5cb44d9d8 100644 --- a/docs/user-guide/a3-02-reference-capability-atoms.md +++ b/docs/user-guide/a3-02-reference-capability-atoms.md @@ -1327,6 +1327,10 @@ Compound Capabilities `texture_querylod` > Capabilities required to query texture LOD info +`texture_shadowgrad` +> Capabilities required for shadow texture sampling with bias and gradients. +> New in HLSL SM6.8 but existed in older GLSL and SPIRV targets. + `texture_shadowlod` > Capabilities required to query shadow texture lod info diff --git a/source/slang/glsl.meta.slang b/source/slang/glsl.meta.slang index 30f20ab8c63..1096004de53 100644 --- a/source/slang/glsl.meta.slang +++ b/source/slang/glsl.meta.slang @@ -1327,44 +1327,9 @@ public typealias usamplerCube = SamplerCube; public typealias isamplerCube = SamplerCube; public typealias samplerCube = SamplerCube; -__generic -public typealias sampler1DShadow = _Texture< - float, - __Shape1D, - 0, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; - -__generic -public typealias sampler2DShadow = _Texture< - float, - __Shape2D, - 0, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; - -__generic -public typealias samplerCubeShadow = _Texture< - float, - __ShapeCube, - 0, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; +public typealias sampler1DShadow = Sampler1DShadow; +public typealias sampler2DShadow = Sampler2DShadow; +public typealias samplerCubeShadow = SamplerCubeShadow; public typealias usampler1DArray = Sampler1DArray; public typealias isampler1DArray = Sampler1DArray; @@ -1378,44 +1343,9 @@ public typealias usamplerCubeArray = SamplerCubeArray; public typealias isamplerCubeArray = SamplerCubeArray; public typealias samplerCubeArray = SamplerCubeArray; -__generic -public typealias sampler1DArrayShadow = _Texture< - float, - __Shape1D, - 1, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; - -__generic -public typealias sampler2DArrayShadow = _Texture< - float, - __Shape2D, - 1, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; - -__generic -public typealias samplerCubeArrayShadow = _Texture< - float, - __ShapeCube, - 1, // isArray - 0, // isMS - sampleCount, - 0, // access - 1, // isShadow - 1, // isCombined - format ->; +public typealias sampler1DArrayShadow = Sampler1DArrayShadow; +public typealias sampler2DArrayShadow = Sampler2DArrayShadow; +public typealias samplerCubeArrayShadow = SamplerCubeArrayShadow; public typealias sampler2DMS = Sampler2DMS; public typealias isampler2DMS = Sampler2DMS; diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 4d02c14ee5d..840e4e633fa 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -1062,7 +1062,7 @@ extension _Texture /// /// For HLSL/D3D targets, the texture element type must be a scalar or vector of float or half types. /// - ///@see `SampleBias`, `SampleLevel`, `SampleLevelZero`, `SampleGrad`, `SampleCmp`, `SampleCmpLevelZero`, `SampleCmpLevel`. + ///@see `SampleBias`, `SampleLevel`, `SampleLevelZero`, `SampleGrad`, `SampleCmp`, `SampleCmpLevelZero`, `SampleCmpLevel`, `SampleCmpBias`, `SampleCmpGrad`. [__readNone] [ForceInline] [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0_fragment)] @@ -1584,6 +1584,150 @@ extension _Texture } } + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpGrad(vector location, float compareValue, vector gradX, vector gradY) + { + static_assert(!(Shape is __ShapeCube && isArray != 0), "SampleCmpGrad is not supported for TextureCubeArray"); + __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().SampleCmpGrad(__getComparisonSampler(), location, compareValue, gradX, gradY); + case spirv: + return spirv_asm + { + result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Grad $gradX $gradY; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpGrad(vector location, float compareValue, vector gradX, vector gradY, constexpr vector offset) + { + static_assert(!(Shape is __ShapeCube && isArray != 0), "SampleCmpGrad is not supported for TextureCubeArray"); + static_assert(!(Shape is __ShapeCube), "SampleCmpGrad with offset is not supported for TextureCube or TextureCubeArray"); + __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().SampleCmpGrad(__getComparisonSampler(), location, compareValue, gradX, gradY, offset); + case spirv: + return spirv_asm + { + result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Grad|ConstOffset $gradX $gradY $offset; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpGrad(vector location, float compareValue, vector gradX, vector gradY, constexpr vector offset, out uint status) + { + static_assert(!(Shape is __ShapeCube && isArray != 0), "SampleCmpGrad is not supported for TextureCubeArray"); + static_assert(!(Shape is __ShapeCube), "SampleCmpGrad with offset is not supported for TextureCube or TextureCubeArray"); + __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().SampleCmpGrad(__getComparisonSampler(), location, compareValue, gradX, gradY, offset, status); + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint $$float; + + %sparseResult:%sparseResultType = OpImageSparseSampleDrefExplicitLod $this $location $compareValue Grad|ConstOffset $gradX $gradY $offset; + + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + OpStore &status %residentCode; + result:$$float = OpCompositeExtract %sparseResult 1; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpBias(vector location, float compareValue, float bias) + { + __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().SampleCmpBias(__getComparisonSampler(), location, compareValue, bias); + case spirv: + return spirv_asm + { + result:$$float = OpImageSampleDrefImplicitLod $this $location $compareValue Bias $bias; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpBias(vector location, float compareValue, float bias, constexpr vector offset) + { + static_assert(!(Shape is __ShapeCube), "SampleCmpBias with offset is not supported for TextureCube or TextureCubeArray"); + __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().SampleCmpBias(__getComparisonSampler(), location, compareValue, bias, offset); + case spirv: + return spirv_asm + { + result:$$float = OpImageSampleDrefImplicitLod $this $location $compareValue Bias|ConstOffset $bias $offset; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpBias(vector location, float compareValue, float bias, constexpr vector offset, out uint status) + { + static_assert(!(Shape is __ShapeCube), "SampleCmpBias with offset is not supported for TextureCube or TextureCubeArray"); + __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().SampleCmpBias(__getComparisonSampler(), location, compareValue, bias, offset, status); + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint $$float; + + %sparseResult:%sparseResultType = OpImageSparseSampleDrefImplicitLod $this $location $compareValue Bias|ConstOffset $bias $offset; + + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + OpStore &status %residentCode; + result:$$float = OpCompositeExtract %sparseResult 1; + }; + } + } + [__readNone] [ForceInline] [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)] @@ -2783,6 +2927,156 @@ extension _Texture } } + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpGrad(SamplerComparisonState s, vector location, float compareValue, vector gradX, vector gradY) + { + static_assert(!(Shape is __ShapeCube && isArray != 0), "SampleCmpGrad is not supported for TextureCubeArray"); + __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 ".SampleCmpGrad"; + case spirv: + return spirv_asm + { + %sampledImage : __sampledImageType(this) = OpSampledImage $this $s; + result:$$float = OpImageSampleDrefExplicitLod %sampledImage $location $compareValue Grad $gradX $gradY; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpGrad(SamplerComparisonState s, vector location, float compareValue, vector gradX, vector gradY, constexpr vector offset) + { + static_assert(!(Shape is __ShapeCube && isArray != 0), "SampleCmpGrad is not supported for TextureCubeArray"); + static_assert(!(Shape is __ShapeCube), "SampleCmpGrad with offset is not supported for TextureCube or TextureCubeArray"); + __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 ".SampleCmpGrad"; + case spirv: + return spirv_asm + { + %sampledImage : __sampledImageType(this) = OpSampledImage $this $s; + result:$$float = OpImageSampleDrefExplicitLod %sampledImage $location $compareValue Grad|ConstOffset $gradX $gradY $offset; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpGrad(SamplerComparisonState s, vector location, float compareValue, vector gradX, vector gradY, constexpr vector offset, out uint status) + { + static_assert(!(Shape is __ShapeCube && isArray != 0), "SampleCmpGrad is not supported for TextureCubeArray"); + static_assert(!(Shape is __ShapeCube), "SampleCmpGrad with offset is not supported for TextureCube or TextureCubeArray"); + __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 ".SampleCmpGrad"; + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint $$float; + %sampledImage:__sampledImageType(this) = OpSampledImage $this $s; + + %sparseResult:%sparseResultType = OpImageSparseSampleDrefExplicitLod %sampledImage $location $compareValue Grad|ConstOffset $gradX $gradY $offset; + + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + OpStore &status %residentCode; + result:$$float = OpCompositeExtract %sparseResult 1; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpBias(SamplerComparisonState s, vector location, float compareValue, float bias) + { + __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 ".SampleCmpBias"; + case spirv: + return spirv_asm + { + %sampledImage : __sampledImageType(this) = OpSampledImage $this $s; + result:$$float = OpImageSampleDrefImplicitLod %sampledImage $location $compareValue Bias $bias; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpBias(SamplerComparisonState s, vector location, float compareValue, float bias, constexpr vector offset) + { + static_assert(!(Shape is __ShapeCube), "SampleCmpBias with offset is not supported for TextureCube or TextureCubeArray"); + __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 ".SampleCmpBias"; + case spirv: + return spirv_asm + { + %sampledImage : __sampledImageType(this) = OpSampledImage $this $s; + result:$$float = OpImageSampleDrefImplicitLod %sampledImage $location $compareValue Bias|ConstOffset $bias $offset; + }; + } + } + + [__readNone] + [ForceInline] + [require(hlsl_spirv, texture_shadowgrad)] + float SampleCmpBias(SamplerComparisonState s, vector location, float compareValue, float bias, constexpr vector offset, out uint status) + { + static_assert(!(Shape is __ShapeCube), "SampleCmpBias with offset is not supported for TextureCube or TextureCubeArray"); + __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 ".SampleCmpBias"; + case spirv: + return spirv_asm + { + OpCapability SparseResidency; + %sparseResultType = OpTypeStruct $$uint $$float; + %sampledImage:__sampledImageType(this) = OpSampledImage $this $s; + + %sparseResult:%sparseResultType = OpImageSparseSampleDrefImplicitLod %sampledImage $location $compareValue Bias|ConstOffset $bias $offset; + + %residentCode:$$uint = OpCompositeExtract %sparseResult 0; + OpStore &status %residentCode; + result:$$float = OpCompositeExtract %sparseResult 1; + }; + } + } + [__readNone] [ForceInline] [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)] diff --git a/source/slang/slang-capabilities.capdef b/source/slang/slang-capabilities.capdef index 307390fe5ce..b63866ba3e8 100644 --- a/source/slang/slang-capabilities.capdef +++ b/source/slang/slang-capabilities.capdef @@ -2109,6 +2109,10 @@ alias texture_querylevels = texture_sm_4_1 | GL_ARB_texture_query_levels; /// [Compound] alias texture_shadowlod = texture_sm_4_1 | GL_EXT_texture_shadow_lod | texture_sm_4_1; +/// Capabilities required for shadow texture sampling with bias and gradients. +/// New in HLSL SM6.8 but existed in older GLSL and SPIRV targets. +/// [Compound] +alias texture_shadowgrad = _sm_6_8 | _GLSL_150 | spirv_1_0 | GL_EXT_texture_shadow_lod; /// (GLSL/SPIRV) Capabilities required to use GLSL-tier-1 float-atomic operations /// [Compound] diff --git a/tests/hlsl-intrinsic/texture/sample-cmp.slang b/tests/hlsl-intrinsic/texture/sample-cmp.slang new file mode 100644 index 00000000000..64612362b46 --- /dev/null +++ b/tests/hlsl-intrinsic/texture/sample-cmp.slang @@ -0,0 +1,340 @@ +// Test shader for SampleCmpGrad and SampleCmpBias functions +//TEST:SIMPLE(filecheck=CHECK_HLSL): -stage fragment -entry fragmentMain -target hlsl -DUSE_SPARSE +//TEST:SIMPLE(filecheck=CHECK_DXIL): -target dxil-assembly -entry fragmentMain -stage fragment -profile ps_6_8 -DUSE_SPARSE +//TEST:SIMPLE(filecheck=CHECK_SPIRV): -stage fragment -entry fragmentMain -target spirv -DUSE_SPARSE + +SamplerComparisonState shadowSampler; +Texture1D shadowMap1D; +Texture1DArray shadowMap1DArray; +Texture2D shadowMap2D; +Texture2DArray shadowMap2DArray; +TextureCube shadowMapCube; +TextureCubeArray shadowMapCubeArray; + +Sampler1DShadow sampler1DShadow; +Sampler1DArrayShadow sampler1DArrayShadow; +Sampler2DShadow sampler2DShadow; +Sampler2DArrayShadow sampler2DArrayShadow; +SamplerCubeShadow samplerCubeShadow; +SamplerCubeArrayShadow samplerCubeArrayShadow; + +struct PSInput +{ + float4 position : SV_Position; + float2 texCoord : TEXCOORD0; + float depth : DEPTH; +}; + +struct PSOutput +{ + float4 color : SV_Target0; +}; + +PSOutput fragmentMain(PSInput input) +{ + PSOutput output; + + float ddx1 = 0.001; + float ddy1 = 0.001; + float2 ddx2 = float2(0.001, 0.0); + float2 ddy2 = float2(0.0, 0.001); + float3 ddx3 = float3(0.001, 0.0, 0.0); + float3 ddy3 = float3(0.0, 0.001, 0.0); + + int offset1 = 1; + int2 offset2 = int2(1, 0); + int3 offset3 = int3(1, 0, 0); + + float bias = 0.5; + float shadow = 0; +#ifdef USE_SPARSE + uint status; +#endif + + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += shadowMap1D.SampleCmpGrad(shadowSampler, input.texCoord.x, input.depth, ddx1, ddy1); + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += shadowMap1D.SampleCmpGrad(shadowSampler, input.texCoord.x, input.depth, ddx1, ddy1, offset1); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += shadowMap1D.SampleCmpGrad(shadowSampler, input.texCoord.x, input.depth, ddx1, ddy1, offset1, status); +#endif + + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += sampler1DShadow.SampleCmpGrad(input.texCoord.x, input.depth, ddx1, ddy1); + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += sampler1DShadow.SampleCmpGrad(input.texCoord.x, input.depth, ddx1, ddy1, offset1); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += sampler1DShadow.SampleCmpGrad(input.texCoord.x, input.depth, ddx1, ddy1, offset1, status); +#endif + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += shadowMap1D.SampleCmpBias(shadowSampler, input.texCoord.x, input.depth, bias); + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += shadowMap1D.SampleCmpBias(shadowSampler, input.texCoord.x, input.depth, bias, offset1); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += shadowMap1D.SampleCmpBias(shadowSampler, input.texCoord.x, input.depth, bias, offset1, status); +#endif + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += sampler1DShadow.SampleCmpBias(input.texCoord.x, input.depth, bias); + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += sampler1DShadow.SampleCmpBias(input.texCoord.x, input.depth, bias, offset1); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += sampler1DShadow.SampleCmpBias(input.texCoord.x, input.depth, bias, offset1, status); +#endif + + // ===== Texture1DArray Tests ===== + float2 texCoord1DArray = float2(input.texCoord.x, 0); + + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += shadowMap1DArray.SampleCmpGrad(shadowSampler, texCoord1DArray, input.depth, ddx1, ddy1); + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += shadowMap1DArray.SampleCmpGrad(shadowSampler, texCoord1DArray, input.depth, ddx1, ddy1, offset1); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += shadowMap1DArray.SampleCmpGrad(shadowSampler, texCoord1DArray, input.depth, ddx1, ddy1, offset1, status); +#endif + + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += sampler1DArrayShadow.SampleCmpGrad(texCoord1DArray, input.depth, ddx1, ddy1); + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += sampler1DArrayShadow.SampleCmpGrad(texCoord1DArray, input.depth, ddx1, ddy1, offset1); + +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += sampler1DArrayShadow.SampleCmpGrad(texCoord1DArray, input.depth, ddx1, ddy1, offset1, status); +#endif + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += shadowMap1DArray.SampleCmpBias(shadowSampler, texCoord1DArray, input.depth, bias); + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += shadowMap1DArray.SampleCmpBias(shadowSampler, texCoord1DArray, input.depth, bias, offset1); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += shadowMap1DArray.SampleCmpBias(shadowSampler, texCoord1DArray, input.depth, bias, offset1, status); +#endif + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += sampler1DArrayShadow.SampleCmpBias(texCoord1DArray, input.depth, bias); + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += sampler1DArrayShadow.SampleCmpBias(texCoord1DArray, input.depth, bias, offset1); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += sampler1DArrayShadow.SampleCmpBias(texCoord1DArray, input.depth, bias, offset1, status); +#endif + + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += shadowMap2D.SampleCmpGrad(shadowSampler, input.texCoord, input.depth, ddx2, ddy2); + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += shadowMap2D.SampleCmpGrad(shadowSampler, input.texCoord, input.depth, ddx2, ddy2, offset2); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += shadowMap2D.SampleCmpGrad(shadowSampler, input.texCoord, input.depth, ddx2, ddy2, offset2, status); +#endif + + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += sampler2DShadow.SampleCmpGrad(input.texCoord, input.depth, ddx2, ddy2); + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += sampler2DShadow.SampleCmpGrad(input.texCoord, input.depth, ddx2, ddy2, offset2); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += sampler2DShadow.SampleCmpGrad(input.texCoord, input.depth, ddx2, ddy2, offset2, status); +#endif + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += shadowMap2D.SampleCmpBias(shadowSampler, input.texCoord, input.depth, bias); + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += shadowMap2D.SampleCmpBias(shadowSampler, input.texCoord, input.depth, bias, offset2); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += shadowMap2D.SampleCmpBias(shadowSampler, input.texCoord, input.depth, bias, offset2, status); +#endif + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += sampler2DShadow.SampleCmpBias(input.texCoord, input.depth, bias); + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += sampler2DShadow.SampleCmpBias(input.texCoord, input.depth, bias, offset2); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += sampler2DShadow.SampleCmpBias(input.texCoord, input.depth, bias, offset2, status); +#endif + + float3 texCoord2DArray = float3(input.texCoord, 0); + + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += shadowMap2DArray.SampleCmpGrad(shadowSampler, texCoord2DArray, input.depth, ddx2, ddy2); + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += shadowMap2DArray.SampleCmpGrad(shadowSampler, texCoord2DArray, input.depth, ddx2, ddy2, offset2); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += shadowMap2DArray.SampleCmpGrad(shadowSampler, texCoord2DArray, input.depth, ddx2, ddy2, offset2, status); +#endif + + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += sampler2DArrayShadow.SampleCmpGrad(texCoord2DArray, input.depth, ddx2, ddy2); + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += sampler2DArrayShadow.SampleCmpGrad(texCoord2DArray, input.depth, ddx2, ddy2, offset2); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefExplicitLod {{.*}} Grad|ConstOffset + shadow += sampler2DArrayShadow.SampleCmpGrad(texCoord2DArray, input.depth, ddx2, ddy2, offset2, status); +#endif + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += shadowMap2DArray.SampleCmpBias(shadowSampler, texCoord2DArray, input.depth, bias); + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += shadowMap2DArray.SampleCmpBias(shadowSampler, texCoord2DArray, input.depth, bias, offset2); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += shadowMap2DArray.SampleCmpBias(shadowSampler, texCoord2DArray, input.depth, bias, offset2, status); +#endif + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += sampler2DArrayShadow.SampleCmpBias(texCoord2DArray, input.depth, bias); + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += sampler2DArrayShadow.SampleCmpBias(texCoord2DArray, input.depth, bias, offset2); +#ifdef USE_SPARSE + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSparseSampleDrefImplicitLod {{.*}} Bias|ConstOffset + shadow += sampler2DArrayShadow.SampleCmpBias(texCoord2DArray, input.depth, bias, offset2, status); +#endif + + // ===== TextureCube Tests ===== + float3 texCoordCube = float3(input.texCoord, 1.0); + + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += shadowMapCube.SampleCmpGrad(shadowSampler, texCoordCube, input.depth, ddx3, ddy3); + //CHECK_HLSL: SampleCmpGrad + //CHECK_DXIL: dx.op.sampleCmpGrad.f32 + //CHECK_SPIRV: OpImageSampleDrefExplicitLod {{.*}} Grad + shadow += samplerCubeShadow.SampleCmpGrad(texCoordCube, input.depth, ddx3, ddy3); + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += shadowMapCube.SampleCmpBias(shadowSampler, texCoordCube, input.depth, bias); + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += samplerCubeShadow.SampleCmpBias(texCoordCube, input.depth, bias); + + // ===== TextureCubeArray Tests ===== + float4 texCoordCubeArray = float4(input.texCoord, 1.0, 0); + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += shadowMapCubeArray.SampleCmpBias(shadowSampler, texCoordCubeArray, input.depth, bias); + + //CHECK_HLSL: SampleCmpBias + //CHECK_DXIL: dx.op.sampleCmpBias.f32 + //CHECK_SPIRV: OpImageSampleDrefImplicitLod {{.*}} Bias + shadow += samplerCubeArrayShadow.SampleCmpBias(texCoordCubeArray, input.depth, bias); + + float finalShadow = shadow / 72.0; + + output.color = float4(finalShadow, finalShadow, finalShadow, 1.0); + return output; +} +