From 7c162eba5329eae7755e55298a455a144fcb0dce Mon Sep 17 00:00:00 2001 From: sriramm-nv <85252063+sriramm-nv@users.noreply.github.com> Date: Fri, 19 Apr 2024 09:12:56 -0700 Subject: Enable NonUniformResourceIndex support for glsl, hlsl and spirv (#3899) Fixes #387676* ForceInline SampleLevel to allow decorations to apply * explictly add all the SPIRVAsmOperand Insts in non-differentiable list, which might get inadvertently processed when these functions are inlined into the main shader * Support NonUniformResourceIndex for SPIR-V target Fixes #3876 * add a new IR instruction for NonUniformResourceIndex * slang ir emitter for nonuniform resource index * update the hlsl meta slang * Add test cases for NonUniformResourceIndex access for buffers and textures, with/without cast, nested access etc. * add default c-like emitter for nonuniformresourceinfo * added hlsl emitter * added glsl emitter * requisites for spirv enabling - new decorator for nonuniformresourceindex - emitter for nonuniformresourceindex signature change * add hasResourceType checker * add rwStructBuffType in resourcetype checker * add a case for nonuniformres in emitDecorations * DO NOT COMMIT: This change adds special handling for RWStructBuf within the isResourceType function, if it is a pointer to this resource, return true to make it work with nonuniformres test * spirv emitter for decorations - update the emitLocalInst to perform decorations at the end * added main spirv emitter code * slang emit spirv bugfix * hacky way of supporting Call Inst * move code to cleanup nonuniform inst into helper function * remove stale codefrom test * add spirv decoration for nonuniform * update test to remove global variables * update coherent-2 test * update comment for special handling * update the spirv legalize to handle nested nonuniforms improved logic that handles call ops, rwstructbuf, nested nonuniforms etc. * update nonuniform-array-of-tex test * missed removing nonuniform inst causing duplicate decorations * add glsl and hlsl variants of nonuniform tests * repurpose the hasResource function into something specific for nonuniform inst decoration helper * clean up comments and code around spirv-legalization to emit nonuniform inst by recursively looking into the inst * use the helper canDecorateNonUniformInst to convert `nonUniformResourceInfo` inst to decoration * converted compute/unbounded-array-of-array cross compile test into a simple check test * update contains Resource helper function to be more generic * clean up the case for opcall handling with nonuniform resource inst * update ptr to struct buffer check to be more explicit and rename the function to check for ptr to resource type * update comments and fix the test for coherent * fix typos * update logic on spirv legalize to delete dead instructions - for some reason this doesn't automatically happen * add comments to declarations * add NonuniformResourceIndex to the non-differential inst list --- source/slang/hlsl.meta.slang | 53 +++++--------------------------------------- 1 file changed, 5 insertions(+), 48 deletions(-) (limited to 'source/slang/hlsl.meta.slang') diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 3576e46e3..cdd08b5d7 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -6990,55 +6990,12 @@ T __copyObject(T v) } } - -__glsl_extension(GL_EXT_nonuniform_qualifier) -[__readNone] -[ForceInline] -uint NonUniformResourceIndex(uint index) -{ - __target_switch - { - case hlsl: - __intrinsic_asm "NonUniformResourceIndex"; - case glsl: - __intrinsic_asm "nonuniformEXT"; - case spirv: - var indexCopy = __copyObject(index); - spirv_asm - { - OpCapability ShaderNonUniform; - OpDecorate $indexCopy NonUniform; - }; - return indexCopy; - default: - return index; - } -} - -__glsl_extension(GL_EXT_nonuniform_qualifier) +/// `NonUniformResourceIndex` function is used to indicate if the resource index is +/// divergent, and ensure scalarization happens correctly for each divergent lane. [__readNone] -[ForceInline] -[NonUniformReturn] -int NonUniformResourceIndex(int index) -{ - __target_switch - { - case hlsl: - __intrinsic_asm "NonUniformResourceIndex"; - case glsl: - __intrinsic_asm "nonuniformEXT"; - case spirv: - var indexCopy = __copyObject(index); - spirv_asm - { - OpCapability ShaderNonUniform; - OpDecorate $indexCopy NonUniform; - }; - return indexCopy; - default: - return index; - } -} +__generic +__intrinsic_op($(kIROp_NonUniformResourceIndex)) +T NonUniformResourceIndex(T index); /// HLSL allows NonUniformResourceIndex around non int/uint types. /// It's effect is presumably to ignore it, which the following implementation does. -- cgit v1.2.3