Skip to content

Commit 5aa6389

Browse files
[SPIR-V] Remove duplication of raytracing stage vars (microsoft#6268)
Only add raytracing stage var to `OpEntryPoint` interface if it is actually used by that entry point. Fixes microsoft#6265.
1 parent 13609db commit 5aa6389

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,6 +3938,11 @@ SpirvVariable *DeclResultIdMapper::getBuiltinVar(spv::BuiltIn builtIn,
39383938
return getBuiltinVar(builtIn, type, sc, loc);
39393939
}
39403940

3941+
SpirvFunction *
3942+
DeclResultIdMapper::getRayTracingStageVarEntryFunction(SpirvVariable *var) {
3943+
return rayTracingStageVarToEntryPoints[var];
3944+
}
3945+
39413946
SpirvVariable *DeclResultIdMapper::createSpirvStageVar(
39423947
StageVar *stageVar, const NamedDecl *decl, const llvm::StringRef name,
39433948
SourceLocation srcLoc) {
@@ -4542,6 +4547,8 @@ DeclResultIdMapper::createRayTracingNVStageVar(spv::StorageClass sc,
45424547
assert(false && "Unsupported SPIR-V storage class for raytracing");
45434548
}
45444549

4550+
rayTracingStageVarToEntryPoints[retVal] = entryFunction;
4551+
45454552
return retVal;
45464553
}
45474554

tools/clang/lib/SPIRV/DeclResultIdMapper.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ class DeclResultIdMapper {
205205
SpirvVariable *getBuiltinVar(spv::BuiltIn builtIn, QualType type,
206206
SourceLocation);
207207

208+
/// \brief If var is a raytracing stage variable, returns its entry point,
209+
/// otherwise returns nullptr.
210+
SpirvFunction *getRayTracingStageVarEntryFunction(SpirvVariable *var);
211+
208212
/// \brief Creates the stage output variables by parsing the semantics
209213
/// attached to the given function's parameter or return value and returns
210214
/// true on success. SPIR-V instructions will also be generated to update the
@@ -970,6 +974,11 @@ class DeclResultIdMapper {
970974
/// accessed using stage IO variables.
971975
llvm::DenseMap<uint32_t, SpirvVariable *> builtinToVarMap;
972976

977+
/// Maps from a raytracing stage variable to the entry point that variable is
978+
/// for.
979+
llvm::DenseMap<SpirvVariable *, SpirvFunction *>
980+
rayTracingStageVarToEntryPoints;
981+
973982
/// Whether the translated SPIR-V binary needs legalization.
974983
///
975984
/// The following cases will require legalization:

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,11 @@ SpirvEmitter::getInterfacesForEntryPoint(SpirvFunction *entryPoint) {
757757
for (auto *moduleVar : spvBuilder.getModule()->getVariables()) {
758758
if (moduleVar->getStorageClass() != spv::StorageClass::Input &&
759759
moduleVar->getStorageClass() != spv::StorageClass::Output) {
760+
if (auto *varEntry =
761+
declIdMapper.getRayTracingStageVarEntryFunction(moduleVar)) {
762+
if (varEntry != entryPoint)
763+
continue;
764+
}
760765
interfaces.insert(moduleVar);
761766
}
762767
}

tools/clang/test/CodeGenSPIRV/vk.layout.shader-record-ext.std430.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %dxc -T lib_6_3 -fspv-target-env=vulkan1.2 -fvk-use-gl-layout -fcgl %s -spirv | FileCheck %s
22

3+
// CHECK: OpEntryPoint ClosestHitNV %chs1 "chs1" %cbuf %block %P %A
4+
// CHECK: OpEntryPoint ClosestHitNV %chs2 "chs2" %cbuf %block %P_0 %A_0
5+
36
// CHECK: OpDecorate %_arr_v2float_uint_3 ArrayStride 8
47
// CHECK: OpDecorate %_arr_mat3v2float_uint_2 ArrayStride 32
58
// CHECK: OpDecorate %_arr_v2int_uint_3 ArrayStride 8

0 commit comments

Comments
 (0)