Skip to content

Commit 2888a87

Browse files
authored
[SPIR-V] Add parent map when handling var init (microsoft#8221)
ResourceHeap resource type is not know looking at the type, but at the context around it (we need to look how the variable is assigned). This means we need a parent map. When the heap is used in a function, the parentMap is set to the function scope, so everything is fine. But when a static variable is set, we are in the global scope, and the parent should be the current variable declaration. Fixes microsoft#8220
1 parent 1f63535 commit 2888a87

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14741,11 +14741,13 @@ bool SpirvEmitter::emitEntryFunctionWrapperForRayTracing(
1474114741
const auto varInfo =
1474214742
declIdMapper.getDeclEvalInfo(varDecl, varDecl->getLocation());
1474314743
if (const auto *init = varDecl->getInit()) {
14744+
parentMap = std::make_unique<ParentMap>(const_cast<Expr *>(init));
1474414745
storeValue(varInfo, loadIfGLValue(init), varDecl->getType(),
1474514746
init->getLocStart());
1474614747

1474714748
// Update counter variable associated with global variables
1474814749
tryToAssignCounterVar(varDecl, init);
14750+
parentMap.reset(nullptr);
1474914751
}
1475014752
// If not explicitly initialized, initialize with their zero values if not
1475114753
// resource objects
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %dxc -T lib_6_8 -fspv-target-env=vulkan1.3 -Od -spirv %s | FileCheck %s
2+
3+
// CHECK-DAG: OpCapability RuntimeDescriptorArray
4+
// CHECK-DAG: OpExtension "SPV_EXT_descriptor_indexing"
5+
6+
// CHECK-DAG: [[uint_00:%[_a-zA-Z0-9]+]] = OpConstantComposite %v2uint %uint_0 %uint_0
7+
// CHECK-DAG: [[float_0000:%[_a-zA-Z0-9]+]] = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
8+
// CHECK-DAG: [[image_t:%[_a-zA-Z0-9]+]] = OpTypeImage %float 2D 2 0 0 2 Rgba32f
9+
// CHECK-DAG: [[ptr_u_image_t:%[_a-zA-Z0-9]+]] = OpTypePointer UniformConstant [[image_t]]
10+
// CHECK-DAG: [[ra_image_t:%[_a-zA-Z0-9]+]] = OpTypeRuntimeArray [[image_t]]
11+
// CHECK-DAG: [[ptr_u_ra_image_t:%[_a-zA-Z0-9]+]] = OpTypePointer UniformConstant [[ra_image_t]]
12+
13+
// CHECK-DAG: OpDecorate %ResourceDescriptorHeap DescriptorSet 0
14+
// CHECK-DAG: OpDecorate %ResourceDescriptorHeap Binding 0
15+
16+
// CHECK: %ResourceDescriptorHeap = OpVariable [[ptr_u_ra_image_t]] UniformConstant
17+
18+
// CHECK: [[ptr:%[_a-zA-Z0-9]+]] = OpAccessChain [[ptr_u_image_t]] %ResourceDescriptorHeap %uint_0
19+
// CHECK: [[img:%[_a-zA-Z0-9]+]] = OpLoad %type_2d_image [[ptr]]
20+
// CHECK: OpImageWrite [[img]] [[uint_00]] [[float_0000]] None
21+
22+
static RWTexture2D<float4> OutputTexture = ResourceDescriptorHeap[0];
23+
24+
[shader("raygeneration")]
25+
void RayGenMain() {
26+
OutputTexture[uint2(0, 0)] = float4(0, 0, 0, 0);
27+
}

0 commit comments

Comments
 (0)