summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2024-12-19 12:13:02 -0500
committerGitHub <noreply@github.com>2024-12-19 09:13:02 -0800
commit237af82f7e9ed1dd5d97a981939fc23aec2008b3 (patch)
tree4d89f5135837ede9e4bc49f3eff5f6f4350655c4 /source
parentc6662b6e42d1e6e1ed2752846312074a06cd05e8 (diff)
Add HLSL texture sample with status intrinsics (#5901)
* Implement HLSL texture sample with status intrinsics * fix test and cleanup --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/hlsl.meta.slang156
1 files changed, 155 insertions, 1 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 194c14b19..85a81eabf 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -1059,6 +1059,22 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
[__readNone]
[ForceInline]
+ [require(hlsl, sm_5_0)]
+ T SampleBias(vector<float, Shape.dimensions+isArray> location, float bias, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)
+ {
+ __requireComputeDerivative();
+ __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().SampleBias(__getSampler(), location, bias, offset, clamp, status);
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
[require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]
float SampleCmp(vector<float, Shape.dimensions+isArray> location, float compareValue)
{
@@ -1163,6 +1179,23 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
}
}
+
+ [__readNone]
+ [ForceInline]
+ [require(hlsl, sm_5_0)]
+ float SampleCmp(vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)
+ {
+ __requireComputeDerivative();
+ __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().SampleCmp(__getComparisonSampler(), location, compareValue, offset, clamp, status);
+ }
+ }
+
[__readNone]
[ForceInline]
[require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]
@@ -1199,6 +1232,21 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
[__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(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]
T SampleGrad(vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY)
{
@@ -1283,6 +1331,21 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
[__readNone]
[ForceInline]
+ [require(hlsl, sm_5_0)]
+ T SampleGrad(vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset, float lodClamp, 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().SampleGrad(__getSampler(), location, gradX, gradY, offset, lodClamp, status);
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]
T SampleLevel(vector<float, Shape.dimensions+isArray> location, float level)
{
@@ -1367,6 +1430,21 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>
return __getTexture().SampleLevel(__getSampler(), location, level, offset);
}
}
+
+ [__readNone]
+ [ForceInline]
+ [require(hlsl, sm_5_0)]
+ T SampleLevel(vector<float, Shape.dimensions+isArray> location, 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().SampleLevel(__getSampler(), location, level, offset, status);
+ }
+ }
}
// Non-combined texture types specific functions
@@ -1785,6 +1863,22 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
[__readNone]
[ForceInline]
+ [require(hlsl, sm_5_0)]
+ T SampleBias(SamplerState s, vector<float, Shape.dimensions+isArray> location, float bias, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)
+ {
+ __requireComputeDerivative();
+ __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 ".SampleBias";
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
[require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]
float SampleCmp(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue)
{
@@ -1990,6 +2084,22 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
[__readNone]
[ForceInline]
+ [require(hlsl, sm_5_0)]
+ float SampleCmp(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)
+ {
+ __requireComputeDerivative();
+ __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 ".SampleCmp";
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
[require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]
float SampleCmpLevelZero(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset)
{
@@ -2057,6 +2167,21 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
[__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(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]
T SampleGrad(SamplerState s, vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY)
{
@@ -2237,6 +2362,21 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
[__readNone]
[ForceInline]
+ [require(hlsl, sm_5_0)]
+ T SampleGrad(SamplerState s, vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset, float lodClamp, 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 ".SampleGrad";
+ }
+ }
+
+ [__readNone]
+ [ForceInline]
[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]
T SampleLevel(SamplerState s, vector<float, Shape.dimensions+isArray> location, float level)
{
@@ -2337,7 +2477,6 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
[__readNone]
[ForceInline]
-
[require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]
T SampleLevel(SamplerState s, vector<float, Shape.dimensions+isArray> location, float level, constexpr vector<int, Shape.planeDimensions> offset)
{
@@ -2399,6 +2538,21 @@ extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>
__intrinsic_asm "textureSampleLevel($0, $1, $2, $3, $4)$z";
}
}
+
+ [__readNone]
+ [ForceInline]
+ [require(hlsl, sm_5_0)]
+ T SampleLevel(SamplerState s, vector<float, Shape.dimensions+isArray> location, 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");
+ __intrinsic_asm ".SampleLevel";
+ }
+ }
}
// Texture.GetDimensions and Sampler.GetDimensions