diff --git a/tools/clang/lib/SPIRV/SpirvEmitter.cpp b/tools/clang/lib/SPIRV/SpirvEmitter.cpp index ad4fe19238..c135a0080b 100644 --- a/tools/clang/lib/SPIRV/SpirvEmitter.cpp +++ b/tools/clang/lib/SPIRV/SpirvEmitter.cpp @@ -14740,11 +14740,13 @@ bool SpirvEmitter::emitEntryFunctionWrapperForRayTracing( const auto varInfo = declIdMapper.getDeclEvalInfo(varDecl, varDecl->getLocation()); if (const auto *init = varDecl->getInit()) { + parentMap = std::make_unique(const_cast(init)); storeValue(varInfo, loadIfGLValue(init), varDecl->getType(), init->getLocStart()); // Update counter variable associated with global variables tryToAssignCounterVar(varDecl, init); + parentMap.reset(nullptr); } // If not explicitly initialized, initialize with their zero values if not // resource objects diff --git a/tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.global.lib.hlsl b/tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.global.lib.hlsl new file mode 100644 index 0000000000..c9c074f212 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.global.lib.hlsl @@ -0,0 +1,27 @@ +// RUN: %dxc -T lib_6_8 -fspv-target-env=vulkan1.3 -Od -spirv %s | FileCheck %s + +// CHECK-DAG: OpCapability RuntimeDescriptorArray +// CHECK-DAG: OpExtension "SPV_EXT_descriptor_indexing" + +// CHECK-DAG: [[uint_00:%[_a-zA-Z0-9]+]] = OpConstantComposite %v2uint %uint_0 %uint_0 +// CHECK-DAG: [[float_0000:%[_a-zA-Z0-9]+]] = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0 +// CHECK-DAG: [[image_t:%[_a-zA-Z0-9]+]] = OpTypeImage %float 2D 2 0 0 2 Rgba32f +// CHECK-DAG: [[ptr_u_image_t:%[_a-zA-Z0-9]+]] = OpTypePointer UniformConstant [[image_t]] +// CHECK-DAG: [[ra_image_t:%[_a-zA-Z0-9]+]] = OpTypeRuntimeArray [[image_t]] +// CHECK-DAG: [[ptr_u_ra_image_t:%[_a-zA-Z0-9]+]] = OpTypePointer UniformConstant [[ra_image_t]] + +// CHECK-DAG: OpDecorate %ResourceDescriptorHeap DescriptorSet 0 +// CHECK-DAG: OpDecorate %ResourceDescriptorHeap Binding 0 + +// CHECK: %ResourceDescriptorHeap = OpVariable [[ptr_u_ra_image_t]] UniformConstant + +// CHECK: [[ptr:%[_a-zA-Z0-9]+]] = OpAccessChain [[ptr_u_image_t]] %ResourceDescriptorHeap %uint_0 +// CHECK: [[img:%[_a-zA-Z0-9]+]] = OpLoad %type_2d_image [[ptr]] +// CHECK: OpImageWrite [[img]] [[uint_00]] [[float_0000]] None + +static RWTexture2D OutputTexture = ResourceDescriptorHeap[0]; + +[shader("raygeneration")] +void RayGenMain() { + OutputTexture[uint2(0, 0)] = float4(0, 0, 0, 0); +}