From b6da04424aff71ddba9629c94401a9a897b152a0 Mon Sep 17 00:00:00 2001 From: Pankaj Mistry <63069047+pmistryNV@users.noreply.github.com> Date: Sat, 16 Dec 2023 12:48:27 -0800 Subject: Fix nonuniform decoration on direct-to-spirv backend path. (#3338) (#3417) --- source/slang/hlsl.meta.slang | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 945dfa862..2c5f384a3 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -5963,6 +5963,18 @@ __generic float noise(vector x) /// to this function as necessary in output code, rather than make this /// the user's responsibility, so that the default behavior of the language /// is more semantically "correct." +[ForceInline] +T __copyObject(T v) +{ + __target_switch { + case spirv: + return spirv_asm { + result:$$T = OpCopyObject $v; + }; + } +} + + __glsl_extension(GL_EXT_nonuniform_qualifier) [__readNone] [ForceInline] @@ -5975,12 +5987,13 @@ uint NonUniformResourceIndex(uint index) case glsl: __intrinsic_asm "nonuniformEXT"; case spirv: + var indexCopy = __copyObject(index); spirv_asm { OpCapability ShaderNonUniform; - OpDecorate $index NonUniform; + OpDecorate $indexCopy NonUniform; }; - return index; + return indexCopy; default: return index; } @@ -5988,6 +6001,7 @@ uint NonUniformResourceIndex(uint index) __glsl_extension(GL_EXT_nonuniform_qualifier) [__readNone] +[ForceInline] int NonUniformResourceIndex(int index) { __target_switch @@ -5997,12 +6011,13 @@ int NonUniformResourceIndex(int index) case glsl: __intrinsic_asm "nonuniformEXT"; case spirv: + var indexCopy = __copyObject(index); spirv_asm { OpCapability ShaderNonUniform; - OpDecorate $index NonUniform; + OpDecorate $indexCopy NonUniform; }; - return index; + return indexCopy; default: return index; } -- cgit v1.2.3