summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2025-01-08 22:50:57 -0500
committerGitHub <noreply@github.com>2025-01-08 19:50:57 -0800
commit2249d6ffb19e4db8580c76ccb04ab4ca3ddc8394 (patch)
treea5d975e79c60fe735a5d9f5948a5534e3a37ec5b
parent63b8d9e1d0b0bba66f13013aa6b80bd9fab4036b (diff)
Add SampleCmpLevel intrinsics (#6004)
* add SampleCmpLevel intrinsics * update tests * fix typo * fix broken glsl test * refactor SampleCmpLevelZero * fix metallib test * fix broken test on dx12 --------- Co-authored-by: Yong He <yonghe@outlook.com>
-rw-r--r--source/slang/hlsl.meta.slang310
-rw-r--r--tests/cross-compile/glsl-samplecmplevelzero.slang10
-rw-r--r--tests/hlsl-intrinsic/texture-lod-shadow.slang8
-rw-r--r--tests/hlsl-intrinsic/texture/texture-intrinsics.slang27
-rw-r--r--tests/metal/texture-sampler-less.slang27
-rw-r--r--tests/metal/texture.slang31
-rw-r--r--tests/spirv/sampler-shadow.slang6
7 files changed, 300 insertions, 119 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index d5b59427f..a27cafbd4 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -649,41 +649,41 @@ float __glsl_texture_offset_1d_shadow<TSampler, TCoord, TOffset>(TSampler s, TCo
__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_sm_4_1)]
-float __glsl_texture_level_zero<TSampler, TCoord>(TSampler s, TCoord value)
+float __glsl_texture_level<TSampler, TCoord>(TSampler s, TCoord value, float level)
{
__target_switch
{
- case glsl: __intrinsic_asm "textureLod($0, $1, 0)";
+ case glsl: __intrinsic_asm "textureLod($0, $1, $2)";
}
}
__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowlod)]
-float __glsl_texture_level_zero_1d_shadow<TSampler, TCoord>(TSampler s, TCoord value)
+float __glsl_texture_level_1d_shadow<TSampler, TCoord>(TSampler s, TCoord value, float level)
{
__target_switch
{
- case glsl: __intrinsic_asm "textureLod($0, $1, 0)";
+ case glsl: __intrinsic_asm "textureLod($0, $1, $2)";
}
}
__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowlod)]
-float __glsl_texture_offset_level_zero<TSampler, TCoord, TOffset>(TSampler s, TCoord value, constexpr TOffset offset)
+float __glsl_texture_level_offset<TSampler, TCoord, TOffset>(TSampler s, TCoord value, float level, constexpr TOffset offset)
{
__target_switch
{
- case glsl: __intrinsic_asm "textureLodOffset($0, $1, 0, $2)";
+ case glsl: __intrinsic_asm "textureLodOffset($0, $1, $2, $3)";
}
}
__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowlod)]
-float __glsl_texture_offset_level_zero_1d_shadow<TSampler, TCoord, TOffset>(TSampler s, TCoord value, constexpr TOffset offset)
+float __glsl_texture_level_offset_1d_shadow<TSampler, TCoord, TOffset>(TSampler s, TCoord value, float level, constexpr TOffset offset)
{
__target_switch
{
- case glsl: __intrinsic_asm "textureLodOffset($0, $1, 0, $2)";
+ case glsl: __intrinsic_asm "textureLodOffset($0, $1, $2, $3)";
}
}
@@ -736,41 +736,41 @@ float __glsl_texture_offset_1d_shadow<TTexture, TCoord, TOffset>(TTexture t,Samp
}
[require(glsl, texture_sm_4_1)]
-float __glsl_texture_level_zero<TTexture, TCoord>(TTexture t,SamplerComparisonState s, TCoord value)
+float __glsl_texture_level<TTexture, TCoord>(TTexture t,SamplerComparisonState s, TCoord value, float level)
{
__target_switch
{
- case glsl: __intrinsic_asm "textureLod($p, $2, 0)";
+ case glsl: __intrinsic_asm "textureLod($p, $2, $3)";
}
}
__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowlod)]
-float __glsl_texture_level_zero_1d_shadow<TTexture, TCoord>(TTexture t,SamplerComparisonState s, TCoord value)
+float __glsl_texture_level_1d_shadow<TTexture, TCoord>(TTexture t,SamplerComparisonState s, TCoord value, float level)
{
__target_switch
{
- case glsl: __intrinsic_asm "textureLod($p, $2, 0)";
+ case glsl: __intrinsic_asm "textureLod($p, $2, $3)";
}
}
__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowlod)]
-float __glsl_texture_offset_level_zero<TTexture, TCoord, TOffset>(TTexture t,SamplerComparisonState s, TCoord value, constexpr TOffset offset)
+float __glsl_texture_level_offset<TTexture, TCoord, TOffset>(TTexture t,SamplerComparisonState s, TCoord value, float level, constexpr TOffset offset)
{
__target_switch
{
- case glsl: __intrinsic_asm "textureLodOffset($p, $2, 0, $3)";
+ case glsl: __intrinsic_asm "textureLodOffset($p, $2, $3, $4)";
}
}
__glsl_extension(GL_EXT_texture_shadow_lod)
[require(glsl, texture_shadowlod)]
-float __glsl_texture_offset_level_zero_1d_shadow<TTexture, TCoord, TOffset>(TTexture t,SamplerComparisonState s, TCoord value, constexpr TOffset offset)
+float __glsl_texture_level_offset_1d_shadow<TTexture, TCoord, TOffset>(TTexture t,SamplerComparisonState s, TCoord value, float level, constexpr TOffset offset)
{
__target_switch
{
- case glsl: __intrinsic_asm "textureLodOffset($p, $2, 0, $3)";
+ case glsl: __intrinsic_asm "textureLodOffset($p, $2, $3, $4)";
}
}
@@ -854,7 +854,7 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
/// This parameter is currently only used when targeting HLSL.
/// For other targets, the result status is always 0.
///@return The sampled texture value.
- ///@see `SampleBias`, `SampleLevel`, `SampleGrad`, `SampleCmp`, `SampleCmpLevelZero`.
+ ///@see `SampleBias`, `SampleLevel`, `SampleGrad`, `SampleCmp`, `SampleCmpLevelZero`, `SampleCmpLevel`.
///@remarks
/// The `Sample` function is defined for all read-only texture types, including
/// `Texture1D`, `Texture2D`, `Texture3D`, `TextureCube`,
@@ -1118,30 +1118,15 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
{
__target_switch
{
- case glsl:
- if (Shape.dimensions == 1 && isArray == 0)
- {
- return __glsl_texture_level_zero_1d_shadow(this, __makeVector(__makeVector(location, 0.0), compareValue));
- }
- else
- {
- return __glsl_texture_level_zero(this, __makeVector(location, compareValue));
- }
case hlsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
, "HLSL supports only float and half type textures");
return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue);
- case metal:
- return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue);
- case spirv:
- const float zeroFloat = 0.0f;
- return spirv_asm
- {
- result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Lod $zeroFloat;
- };
case wgsl:
return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue);
+ default:
+ return SampleCmpLevel(location, compareValue, 0.0);
}
}
@@ -1203,45 +1188,107 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
{
__target_switch
{
+ case hlsl:
+ static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
+ || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
+ , "HLSL supports only float and half type textures");
+ return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset);
+ case wgsl:
+ return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset);
+ default:
+ return SampleCmpLevel(location, compareValue, 0.0, offset);
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
+ [require(hlsl, sm_5_0)]
+ float SampleCmpLevelZero(vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, out uint status)
+ {
+ __target_switch
+ {
+ case hlsl:
+ static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
+ || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
+ , "HLSL supports only float and half type textures");
+ return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset, status);
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
+ [require(glsl_hlsl_metal_spirv, texture_shadowlod)]
+ float SampleCmpLevel(vector<float, Shape.dimensions+isArray> location, float compareValue, float level)
+ {
+ __target_switch
+ {
case glsl:
if (Shape.dimensions == 1 && isArray == 0)
{
- return __glsl_texture_offset_level_zero_1d_shadow(this, __makeVector(__makeVector(location,0.0), compareValue), offset);
+ return __glsl_texture_level_1d_shadow(this, __makeVector(__makeVector(location, 0.0), compareValue), level);
}
else
{
- return __glsl_texture_offset_level_zero(this, __makeVector(location, compareValue), offset);
+ return __glsl_texture_level(this, __makeVector(location, compareValue), level);
}
case hlsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
, "HLSL supports only float and half type textures");
- return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset);
+ return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level);
case metal:
- return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset);
+ return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level);
case spirv:
- const float zeroFloat = 0.0f;
return spirv_asm
{
- result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Lod|ConstOffset $zeroFloat $offset;
+ result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Lod $level;
};
- case wgsl:
- return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset);
}
}
[__readNone]
[ForceInline]
- [require(hlsl, sm_5_0)]
- float SampleCmpLevelZero(vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, out uint status)
+ [require(glsl_hlsl_metal_spirv, texture_shadowlod)]
+ float SampleCmpLevel(vector<float, Shape.dimensions+isArray> location, float compareValue, float level, constexpr vector<int, Shape.planeDimensions> offset)
{
__target_switch
{
+ case glsl:
+ if (Shape.dimensions == 1 && isArray == 0)
+ {
+ return __glsl_texture_level_offset_1d_shadow(this, __makeVector(__makeVector(location,0.0), compareValue), level, offset);
+ }
+ else
+ {
+ return __glsl_texture_level_offset(this, __makeVector(location, compareValue), level, offset);
+ }
case hlsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
, "HLSL supports only float and half type textures");
- return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset, status);
+ return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level, offset);
+ case metal:
+ return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level, offset);
+ case spirv:
+ return spirv_asm
+ {
+ result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Lod|ConstOffset $level $offset;
+ };
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
+ [require(hlsl, texture_shadowlod)]
+ float SampleCmpLevel(vector<float, Shape.dimensions+isArray> location, float compareValue, float level, constexpr vector<int, Shape.planeDimensions> offset, out uint status)
+ {
+ __target_switch
+ {
+ case hlsl:
+ static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
+ || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
+ , "HLSL supports only float and half type textures");
+ return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level, offset, status);
}
}
@@ -1956,48 +2003,11 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
{
__target_switch
{
- case glsl:
- if (Shape.dimensions == 1 && isArray == 0)
- {
- return __glsl_texture_level_zero_1d_shadow(this, s, __makeVector(__makeVector(location, 0.0), compareValue));
- }
- else
- {
- return __glsl_texture_level_zero(this, s, __makeVector(location,compareValue));
- }
case hlsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
, "HLSL supports only float and half type textures");
__intrinsic_asm ".SampleCmpLevelZero";
- case metal:
- if (isArray == 1)
- {
- switch (Shape.flavor)
- {
- case $(SLANG_TEXTURE_2D):
- __intrinsic_asm "$0.sample_compare($1, ($2).xy, uint(($2).z), $3, level(0))";
- case $(SLANG_TEXTURE_CUBE):
- __intrinsic_asm "$0.sample_compare($1, ($2).xyz, uint(($2).w), $3, level(0))";
- }
- }
- else
- {
- switch (Shape.flavor)
- {
- case $(SLANG_TEXTURE_2D):
- case $(SLANG_TEXTURE_CUBE):
- __intrinsic_asm "$0.sample_compare($1, $2, $3, level(0))";
- }
- }
- __intrinsic_asm "<invalid intrinsic>";
- case spirv:
- const float zeroFloat = 0.0f;
- return spirv_asm
- {
- %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;
- result:$$float = OpImageSampleDrefExplicitLod %sampledImage $location $compareValue Lod $zeroFloat;
- };
case wgsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
, "WGSL supports only f32 type textures");
@@ -2014,6 +2024,8 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
}
}
__intrinsic_asm "textureSampleCompareLevel($0, $1, $2, $3)";
+ default:
+ return SampleCmpLevel(s, location, compareValue, 0.0);
}
}
@@ -2105,20 +2117,119 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
{
__target_switch
{
+ case hlsl:
+ static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
+ || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
+ , "HLSL supports only float and half type textures");
+ __intrinsic_asm ".SampleCmpLevelZero";
+ case wgsl:
+ static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
+ , "WGSL supports only f32 type textures");
+ if (isArray == 1)
+ {
+ switch (Shape.flavor)
+ {
+ case $(SLANG_TEXTURE_1D):
+ __intrinsic_asm "textureSampleCompareLevel($0, $1, ($2).x, i32(($2).y), $3, $4)";
+ case $(SLANG_TEXTURE_2D):
+ __intrinsic_asm "textureSampleCompareLevel($0, $1, ($2).xy, i32(($2).z), $3, $4)";
+ case $(SLANG_TEXTURE_CUBE):
+ __intrinsic_asm "textureSampleCompareLevel($0, $1, ($2).xyz, i32(($2).w), $3, $4)";
+ }
+ }
+ __intrinsic_asm "textureSampleCompareLevel($0, $1, $2, $3, $4)";
+ default:
+ return SampleCmpLevel(s, location, compareValue, 0.0, offset);
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
+ [require(hlsl, sm_5_0)]
+ float SampleCmpLevelZero(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, out uint status)
+ {
+ __target_switch
+ {
+ case hlsl:
+ static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
+ || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
+ , "HLSL supports only float and half type textures");
+ __intrinsic_asm ".SampleCmpLevelZero";
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
+ [require(glsl_hlsl_metal_spirv, texture_shadowlod)]
+ float SampleCmpLevel(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, float level)
+ {
+ __target_switch
+ {
case glsl:
if (Shape.dimensions == 1 && isArray == 0)
{
- return __glsl_texture_offset_level_zero_1d_shadow(this, s, __makeVector(__makeVector(location,0.0),compareValue), offset);
+ return __glsl_texture_level_1d_shadow(this, s, __makeVector(__makeVector(location, 0.0), compareValue), level);
}
else
{
- return __glsl_texture_offset_level_zero(this, s, __makeVector(location,compareValue), offset);
+ return __glsl_texture_level(this, s, __makeVector(location,compareValue), level);
}
case hlsl:
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
, "HLSL supports only float and half type textures");
- __intrinsic_asm ".SampleCmpLevelZero";
+ __intrinsic_asm ".SampleCmpLevel";
+ case metal:
+ if (isArray == 1)
+ {
+ switch (Shape.flavor)
+ {
+ case $(SLANG_TEXTURE_2D):
+ __intrinsic_asm "$0.sample_compare($1, ($2).xy, uint(($2).z), $3, level($4))";
+ case $(SLANG_TEXTURE_CUBE):
+ __intrinsic_asm "$0.sample_compare($1, ($2).xyz, uint(($2).w), $3, level($4))";
+ }
+ }
+ else
+ {
+ switch (Shape.flavor)
+ {
+ case $(SLANG_TEXTURE_2D):
+ case $(SLANG_TEXTURE_CUBE):
+ __intrinsic_asm "$0.sample_compare($1, $2, $3, level($4))";
+ }
+ }
+ __intrinsic_asm "<invalid intrinsic>";
+ case spirv:
+ return spirv_asm
+ {
+ %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;
+ result:$$float = OpImageSampleDrefExplicitLod %sampledImage $location $compareValue Lod $level;
+ };
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
+ [require(glsl_hlsl_metal_spirv, texture_shadowlod)]
+ float SampleCmpLevel(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, float level, constexpr vector<int, Shape.planeDimensions> offset)
+ {
+ __target_switch
+ {
+ case glsl:
+ if (Shape.dimensions == 1 && isArray == 0)
+ {
+ return __glsl_texture_level_offset_1d_shadow(this, s, __makeVector(__makeVector(location,0.0),compareValue), level, offset);
+ }
+ else
+ {
+ return __glsl_texture_level_offset(this, s, __makeVector(location,compareValue), level, offset);
+ }
+ case hlsl:
+ static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
+ || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
+ , "HLSL supports only float and half type textures");
+ __intrinsic_asm ".SampleCmpLevel";
case metal:
if (isShadow == 1)
{
@@ -2128,47 +2239,30 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
if (isArray == 1)
{
// T sample_compare(sampler s, float2 coord, uint array, float compare_value, lod_options options, int2 offset = int2(0)) const
- __intrinsic_asm "$0.sample_compare($1, ($2).xy, uint(($2).z), $3, level(0), $4)";
+ __intrinsic_asm "$0.sample_compare($1, ($2).xy, uint(($2).z), $3, level($4), $5)";
}
else
{
// T sample_compare(sampler s, float2 coord, float compare_value, lod_options options, int2 offset = int2(0)) const
- __intrinsic_asm "$0.sample_compare($1, $2, $3, level(0), $4)";
+ __intrinsic_asm "$0.sample_compare($1, $2, $3, level($4), $5)";
}
break;
}
}
__intrinsic_asm "<invalid intrinsic>";
case spirv:
- const float zeroFloat = 0.0f;
return spirv_asm
{
%sampledImage : __sampledImageType(this) = OpSampledImage $this $s;
- result:$$float = OpImageSampleDrefExplicitLod %sampledImage $location $compareValue Lod|ConstOffset $zeroFloat $offset;
+ result:$$float = OpImageSampleDrefExplicitLod %sampledImage $location $compareValue Lod|ConstOffset $level $offset;
};
- case wgsl:
- static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
- , "WGSL supports only f32 type textures");
- if (isArray == 1)
- {
- switch (Shape.flavor)
- {
- case $(SLANG_TEXTURE_1D):
- __intrinsic_asm "textureSampleCompareLevel($0, $1, ($2).x, i32(($2).y), $3, $4)";
- case $(SLANG_TEXTURE_2D):
- __intrinsic_asm "textureSampleCompareLevel($0, $1, ($2).xy, i32(($2).z), $3, $4)";
- case $(SLANG_TEXTURE_CUBE):
- __intrinsic_asm "textureSampleCompareLevel($0, $1, ($2).xyz, i32(($2).w), $3, $4)";
- }
- }
- __intrinsic_asm "textureSampleCompareLevel($0, $1, $2, $3, $4)";
}
}
[__readNone]
[ForceInline]
- [require(hlsl, sm_5_0)]
- float SampleCmpLevelZero(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, out uint status)
+ [require(hlsl, texture_shadowlod)]
+ float SampleCmpLevel(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, float level, constexpr vector<int, Shape.planeDimensions> offset, out uint status)
{
__target_switch
{
@@ -2176,7 +2270,7 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>
|| T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>
, "HLSL supports only float and half type textures");
- __intrinsic_asm ".SampleCmpLevelZero";
+ __intrinsic_asm ".SampleCmpLevel";
}
}
diff --git a/tests/cross-compile/glsl-samplecmplevelzero.slang b/tests/cross-compile/glsl-samplecmplevelzero.slang
index 556addf80..7ef1f28f3 100644
--- a/tests/cross-compile/glsl-samplecmplevelzero.slang
+++ b/tests/cross-compile/glsl-samplecmplevelzero.slang
@@ -1,12 +1,16 @@
//TEST:CROSS_COMPILE(filecheck=CHECK): -profile ps_5_0 -entry main -target glsl
-// CHECK: float {{.*}} = (textureLod(sampler2DShadow(shadowMap_0,sampler_0), ({{.*}}), 0));
-// CHECK: float {{.*}} = (textureLodOffset(sampler2DShadow(shadowMap_0,sampler_0), ({{.*}}), 0, (ivec2(1, 1))));
+// CHECK: float {{.*}} = (textureLod(sampler2DShadow(shadowMap_0,sampler_0), ({{.*}}), (0.0)));
+// CHECK: float {{.*}} = (textureLodOffset(sampler2DShadow(shadowMap_0,sampler_0), ({{.*}}), (0.0), (ivec2(1, 1))));
+// CHECK: float {{.*}} = (textureLod(sampler2DShadow(shadowMap_0,sampler_0), ({{.*}}), (1.5)));
+// CHECK: float {{.*}} = (textureLodOffset(sampler2DShadow(shadowMap_0,sampler_0), ({{.*}}), (1.5), (ivec2(2, 2))));
Texture2D shadowMap;
SamplerComparisonState sampler;
float4 main(float4 p : SV_POSITION)
{
return shadowMap.SampleCmpLevelZero(sampler, float2(0.0), 0.0)
- + shadowMap.SampleCmpLevelZero(sampler, float2(0.0), 0.0, int2(1,1));
+ + shadowMap.SampleCmpLevelZero(sampler, float2(0.0), 0.0, int2(1,1))
+ + shadowMap.SampleCmpLevel(sampler, float2(0.0), 0.0, 1.5)
+ + shadowMap.SampleCmpLevel(sampler, float2(0.0), 0.0, 1.5, int2(2,2));
}
diff --git a/tests/hlsl-intrinsic/texture-lod-shadow.slang b/tests/hlsl-intrinsic/texture-lod-shadow.slang
index bc78a9382..bfe2e10fc 100644
--- a/tests/hlsl-intrinsic/texture-lod-shadow.slang
+++ b/tests/hlsl-intrinsic/texture-lod-shadow.slang
@@ -6,10 +6,14 @@ RWStructuredBuffer<float4> result;
SamplerComparisonState s;
// CHECK: OpSourceExtension "GL_EXT_texture_shadow_lod"
-// CHECK: %{{[0-9]*}} = OpImageSampleDrefExplicitLod %float %{{[0-9]*}} %{{[0-9]*}} %float_0_5 Lod|ConstOffset %float_0 %{{[0-9]*}}
+// CHECK: %{{[0-9]*}} = OpImageSampleDrefExplicitLod %float %{{[0-9]*}} %{{[0-9]*}} %{{[0-9]*}} Lod|ConstOffset %float_0 %{{[0-9]*}}
+// CHECK: %{{[0-9]*}} = OpImageSampleDrefExplicitLod %float %{{[0-9]*}} %{{[0-9]*}} %{{[0-9]*}} Lod|ConstOffset %float_1_5 %{{[0-9]*}}
[numthreads(1,1,1)]
void computeMain()
{
result[0] = t2dArray.SampleCmpLevelZero(s, float3(1, 2, 3), 0.5, int2(0, 0));
-} \ No newline at end of file
+
+ float level = 1.5;
+ result[1] = t2dArray.SampleCmpLevel(s, float3(1, 2, 3), 0.5, level, int2(0, 0));
+}
diff --git a/tests/hlsl-intrinsic/texture/texture-intrinsics.slang b/tests/hlsl-intrinsic/texture/texture-intrinsics.slang
index 0543c71b2..e13389ccb 100644
--- a/tests/hlsl-intrinsic/texture/texture-intrinsics.slang
+++ b/tests/hlsl-intrinsic/texture/texture-intrinsics.slang
@@ -105,6 +105,25 @@ void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
#endif
/*
+ float Object.SampleCmpLevel().
+ These require SM 6.7 for dx12 but functional compute tests currently do not run with the cs_6_7,
+ hence only enable these for vk.
+ */
+#if defined(VK)
+ float level = 1.0;
+ val += t1D.SampleCmpLevel(shadowSampler, u, 0, level);
+ val += t2D.SampleCmpLevel(shadowSampler, float2(u, u), 0, level);
+ val += t1DArray.SampleCmpLevel(shadowSampler, float2(u, u), 0, level);
+ val += tCube.SampleCmpLevel(shadowSampler, normalize(float3(u, 1 - u, u)), 0, level);
+ val += t2DArray.SampleCmpLevel(shadowSampler, normalize(float3(u, 1 - u, u)), 0, level);
+ val += tCubeArray.SampleCmpLevel(shadowSampler, normalize(float4(u, 1-u, u, u)), 0, level);
+
+ // Offset variant
+ val += t1D.SampleCmpLevel(shadowSampler, u, 0, level, 0);
+ val += t2D.SampleCmpLevel(shadowSampler, float2(u, u), 0, level, int2(0, 0));
+#endif
+
+ /*
void Object.GetDimensions()
*/
t1D.GetDimensions(width);
@@ -353,7 +372,7 @@ void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
// DX12CS6: 377
// DX12CS6: 377
// DX12CS6: 377
-// VK: 351
-// VK: 351
-// VK: 351
-// VK: 351 \ No newline at end of file
+// VK: 359
+// VK: 359
+// VK: 359
+// VK: 359
diff --git a/tests/metal/texture-sampler-less.slang b/tests/metal/texture-sampler-less.slang
index 188b15469..78d092e17 100644
--- a/tests/metal/texture-sampler-less.slang
+++ b/tests/metal/texture-sampler-less.slang
@@ -448,6 +448,33 @@ bool TEST_texture_float()
// METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
&& float(1) == d2D.SampleCmpLevelZero(float2(u2, u), 0, int2(0, 0))
+ // ===================================
+ // float SampleCmpLevel()
+ // ===================================
+
+ // METAL: d2D{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
+ && float(1) == d2D.SampleCmpLevel(float2(u, u), 0, 1.0)
+
+ // METAL: d2DArray{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_2d_array.f32(
+ && float(1) == d2DArray.SampleCmpLevel(float3(u, u, 0), 0, 1.0)
+
+ // METAL: dCube{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_cube.f32(
+ && float(1) == dCube.SampleCmpLevel(normalize(float3(u, 1 - u, u)), 0, 1.0)
+
+ // METAL: dCubeArray{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_cube_array.f32(
+ && float(1) == dCubeArray.SampleCmpLevel(float4(normalize(float3(u, 1-u, u)), 0), 0, 1.0)
+
+ // Offset variant
+
+ // METAL: d2D{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
+ && float(1) == d2D.SampleCmpLevel(float2(u2, u), 0, 1.0, int2(0, 0))
+
+
// ==================================
// vector<T,4> Gather()
// ==================================
diff --git a/tests/metal/texture.slang b/tests/metal/texture.slang
index 37c8fa286..feb0b4738 100644
--- a/tests/metal/texture.slang
+++ b/tests/metal/texture.slang
@@ -3,7 +3,7 @@
//TEST:SIMPLE(filecheck=HLSL): -stage compute -entry computeMain -target hlsl -DEXCLUDE_INTEGER_TYPE
//TEST:SIMPLE(filecheck=SPIR): -stage compute -entry computeMain -target spirv -emit-spirv-directly -DEXCLUDE_HALF_TYPE -DEXCLUDE_SHORT_TYPE
-//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=FUNCTIONAL):-slang -compute -dx12 -profile cs_6_6 -use-dxil -shaderobj -output-using-type -xslang -DEXCLUDE_INTEGER_TYPE
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=FUNCTIONAL):-slang -compute -dx12 -profile cs_6_6 -use-dxil -shaderobj -output-using-type -xslang -DEXCLUDE_INTEGER_TYPE -xslang -DEXCLUDE_SM_6_7
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=FUNCTIONAL):-vk -emit-spirv-directly -compute -shaderobj -output-using-type -render-feature hardware-device -xslang -DEXCLUDE_HALF_TYPE -xslang -DEXCLUDE_SHORT_TYPE
//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer
@@ -567,6 +567,35 @@ bool TEST_texture(
// METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
&& float(0) == d2D.SampleCmpLevelZero(shadowSampler, float2(u2, u), 0, int2(0, 0))
+ // ===================================
+ // float SampleCmpLevel()
+ // ===================================
+
+ // These require SM 6.7 for dx12 but functional compute tests currently do not run with the cs_6_7.
+#if !defined(EXCLUDE_SM_6_7)
+ // METAL: d2D{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
+ && float(0) == d2D.SampleCmpLevel(shadowSampler, float2(u, u), 0, 0.0)
+
+ // METAL: d2DArray{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_2d_array.f32(
+ && float(0) == d2DArray.SampleCmpLevel(shadowSampler, float3(u, u, 0), 0, 0.0)
+
+ // METAL: dCube{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_cube.f32(
+ && float(0) == dCube.SampleCmpLevel(shadowSampler, normalize(float3(u, 1 - u, u)), 0, 0.0)
+
+ // METAL: dCubeArray{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_cube_array.f32(
+ && float(0) == dCubeArray.SampleCmpLevel(shadowSampler, float4(normalize(float3(u, 1-u, u)), 0), 0, 0.0)
+
+ // Offset variant
+
+ // METAL: d2D{{.*}}.sample_compare(
+ // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
+ && float(0) == d2D.SampleCmpLevel(shadowSampler, float2(u2, u), 0, 0.0, int2(0, 0))
+#endif
+
// ==================================
// vector<T,4> Gather()
// ==================================
diff --git a/tests/spirv/sampler-shadow.slang b/tests/spirv/sampler-shadow.slang
index 89bdbc405..35b96e746 100644
--- a/tests/spirv/sampler-shadow.slang
+++ b/tests/spirv/sampler-shadow.slang
@@ -1,6 +1,7 @@
//TEST:SIMPLE(filecheck=CHECK): -target spirv
// CHECK: OpImageSampleDrefExplicitLod
+// CHECK: OpImageSampleDrefExplicitLod
Sampler2DShadow ss;
@@ -10,4 +11,7 @@ RWStructuredBuffer<float> output;
void computeMain()
{
output[0] = ss.SampleCmpLevelZero(float2(0.0), 0.5);
-} \ No newline at end of file
+
+ float level = 1.5;
+ output[1] = ss.SampleCmpLevel(float2(0.0), 0.5, level);
+}