From 383c0ef172fb19b3b9c7270fb6429ce19fd1b332 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 20 Nov 2023 14:51:27 -0800 Subject: Add missing SPIRV intrinsics for texture operations. (#3343) * Add missing SPIRV intrinsics for texture operations.. * Fixes. * Fix. --------- Co-authored-by: Yong He --- source/slang/hlsl.meta.slang | 132 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 117 insertions(+), 15 deletions(-) (limited to 'source') diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index cfa3143de..b424b868e 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -183,11 +183,41 @@ extension __TextureImpl typealias TextureCoord = vector; - __target_intrinsic(glsl, "textureQueryLod($0, $1).x") - float CalculateLevelOfDetail(TextureCoord location); + [ForceInline] + [__readNone] + float CalculateLevelOfDetail(TextureCoord location) + { + __target_switch + { + case hlsl: + __intrinsic_asm "CalculateLevelOfDetail"; + case glsl: + __intrinsic_asm "textureQueryLod($0, $1).x"; + case spirv: + return (spirv_asm + { + result:$$float2 = OpImageQueryLod $this $location + }).x; + } + } - __target_intrinsic(glsl, "textureQueryLod($0, $1).y") - float CalculateLevelOfDetailUnclamped(TextureCoord location); + [ForceInline] + [__readNone] + float CalculateLevelOfDetailUnclamped(TextureCoord location) + { + __target_switch + { + case hlsl: + __intrinsic_asm "CalculateLevelOfDetailUnclamped"; + case glsl: + __intrinsic_asm "textureQueryLod($0, $1).y"; + case spirv: + return (spirv_asm + { + result:$$float2 = OpImageQueryLod $this $location + }).y; + } + } [__readNone] T Sample(vector location) @@ -328,6 +358,11 @@ extension __TextureImpl __glsl_texture(__makeVector(location, compareValue)); case hlsl: __intrinsic_asm ".SampleCmp"; + case spirv: + return spirv_asm + { + result:$$float = OpImageSampleDrefImplicitLod $this $location $compareValue; + }; } } @@ -341,6 +376,12 @@ extension __TextureImpl __glsl_texture_level_zero(__makeVector(location, compareValue)); case hlsl: __intrinsic_asm ".SampleCmpLevelZero"; + case spirv: + const float zeroFloat = 0.0f; + return spirv_asm + { + result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Lod $zeroFloat; + }; } } @@ -354,6 +395,11 @@ extension __TextureImpl __glsl_texture_offset(__makeVector(location, compareValue), offset); case hlsl: __intrinsic_asm ".SampleCmp"; + case spirv: + return spirv_asm + { + result:$$float = OpImageSampleDrefImplicitLod $this $location $compareValue ConstOffset $offset; + }; } } @@ -367,6 +413,12 @@ extension __TextureImpl __glsl_texture_offset_level_zero(__makeVector(location, compareValue), offset); case hlsl: __intrinsic_asm ".SampleCmpLevelZero"; + case spirv: + const float zeroFloat = 0.0f; + return spirv_asm + { + result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Lod|ConstOffset $zeroFloat $offset; + }; } } @@ -404,7 +456,6 @@ extension __TextureImpl { %sampled : __sampledType(T) = OpImageSampleExplicitLod $this $location None|Grad|ConstOffset $gradX $gradY $offset; __truncate $$T result __sampledType(T) %sampled; - }; } } @@ -426,7 +477,6 @@ extension __TextureImpl OpCapability MinLod; %sampled : __sampledType(T) = OpImageSampleExplicitLod $this $location None|Grad|ConstOffset|MinLod $gradX $gradY $offset $lodClamp; __truncate $$T result __sampledType(T) %sampled; - }; } } @@ -505,11 +555,41 @@ extension __TextureImpl; - __target_intrinsic(glsl, "textureQueryLod($p, $2).x") - float CalculateLevelOfDetail(SamplerState s, TextureCoord location); + [__readNone] + [ForceInline] + float CalculateLevelOfDetail(SamplerState s, TextureCoord location) + { + __target_switch + { + case hlsl: + __intrinsic_asm "CalculateLevelOfDetail"; + case glsl: + __intrinsic_asm "textureQueryLod($p, $2).x"; + case spirv: + return (spirv_asm { + %sampledImage : __sampledImageType(this) = OpSampledImage $this $s; + result:$$float2 = OpImageQueryLod %sampledImage $location; + }).x; + } + } - __target_intrinsic(glsl, "textureQueryLod($p, $2).y") - float CalculateLevelOfDetailUnclamped(SamplerState s, TextureCoord location); + [__readNone] + [ForceInline] + float CalculateLevelOfDetailUnclamped(SamplerState s, TextureCoord location) + { + __target_switch + { + case hlsl: + __intrinsic_asm "CalculateLevelOfDetailUnclamped"; + case glsl: + __intrinsic_asm "textureQueryLod($p, $2).y"; + case spirv: + return (spirv_asm { + %sampledImage : __sampledImageType(this) = OpSampledImage $this $s; + result:$$float2 = OpImageQueryLod %sampledImage $location; + }).y; + } + } [__readNone] T Sample(SamplerState s, vector location) @@ -626,7 +706,6 @@ extension __TextureImpl