From 8b3f9048cb94164a036be4ae144b2108968b65b5 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:56:07 -0700 Subject: Use Offset instead of ConstOffset for GLSL function textureGatherOffset (#5426) * Use Offset instead of ConstOffset for GLSL function textureGatherOffset This commit changes to use `Offset` option on OpImageGather instruction when translating `textureGatherOffset` to SPIR-V code. Interestingly GLSL allows the offset value to be a variable not constant just for the function `textureGatherOffset` while all other offset variants of texture sampling functions require the offset to be a constant value. From a few experiments, I found that the spirv-optimizer changes `Offset` to `ConstOffset` if the offset is a compile-time value. I also found that when the offset value is zero, it changes to `None` with no offset value. --- source/slang/hlsl.meta.slang | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 2df6c5492..dad634934 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -2536,7 +2536,7 @@ __generic __texture_gather_offset( _Texture texture, SamplerState s, - constexpr vector location, + vector location, constexpr vector offset, int component) { @@ -2557,8 +2557,9 @@ vector __texture_gather_offset( __intrinsic_asm "$0.gather($1, $2, $3, metal::component($4))"; case spirv: return spirv_asm { + OpCapability ImageGatherExtended; %sampledImage : __sampledImageType(texture) = OpSampledImage $texture $s; - result:$$vector = OpImageGather %sampledImage $location $component ConstOffset $offset; + result:$$vector = OpImageGather %sampledImage $location $component Offset $offset; }; case wgsl: if (isShadow == 1) @@ -2606,7 +2607,8 @@ vector __texture_gather_offset( __intrinsic_asm "textureGatherOffset($0, $1, $2, $3)"; case spirv: return spirv_asm { - result:$$vector = OpImageGather $sampler $location $component ConstOffset $offset; + OpCapability ImageGatherExtended; + result:$$vector = OpImageGather $sampler $location $component Offset $offset; }; } } -- cgit v1.2.3