Skip to content

Commit ce1ff6e

Browse files
committed
pr-feedback: simple code nits
1 parent 02fd8e2 commit ce1ff6e

9 files changed

Lines changed: 68 additions & 107 deletions

File tree

tools/clang/include/clang/SPIRV/SpirvBuilder.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,6 @@ class SpirvBuilder {
288288
/// parameters.
289289
SpirvConvertUToPtr *createConvertUToPtr(SpirvInstruction *val, QualType type);
290290

291-
/// \brief Creates an OpBufferPointerEXT SPIR-V instruction with the given
292-
/// parameters.
293-
SpirvBufferPointerEXT *createBufferPointerEXT(const SpirvType *resultType,
294-
SpirvInstruction *buffer,
295-
SourceLocation);
296-
297291
/// \brief Creates SPIR-V instructions for sampling the given image.
298292
///
299293
/// If compareVal is given a non-zero value, *Dref* variants of OpImageSample*
@@ -720,9 +714,10 @@ class SpirvBuilder {
720714
SourceLocation loc = {});
721715

722716
/// \brief Adds an untyped module variable.
723-
SpirvUntypedVariableKHR *createUntypedVariableKHR(
724-
const SpirvType *valueType, spv::StorageClass storageClass,
725-
SourceLocation loc = {}, llvm::StringRef name = "heap");
717+
SpirvUntypedVariableKHR *
718+
createUntypedVariableKHR(const SpirvType *valueType,
719+
spv::StorageClass storageClass, llvm::StringRef name,
720+
SourceLocation loc = {});
726721

727722
/// \brief Creates an OpUntypedAccessChainKHR instruction.
728723
SpirvUntypedAccessChainKHR *

tools/clang/include/clang/SPIRV/SpirvInstruction.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,26 +1594,6 @@ class SpirvConvertUToPtr : public SpirvInstruction {
15941594
SpirvInstruction *val;
15951595
};
15961596

1597-
class SpirvBufferPointerEXT : public SpirvInstruction {
1598-
public:
1599-
SpirvBufferPointerEXT(const SpirvType *resultType, SourceLocation loc,
1600-
SpirvInstruction *buffer);
1601-
1602-
DEFINE_RELEASE_MEMORY_FOR_CLASS(SpirvBufferPointerEXT)
1603-
1604-
// For LLVM-style RTTI
1605-
static bool classof(const SpirvInstruction *inst) {
1606-
return inst->getKind() == IK_BufferPointerEXT;
1607-
}
1608-
1609-
bool invokeVisitor(Visitor *v) override;
1610-
1611-
SpirvInstruction *getBuffer() const { return buffer; }
1612-
1613-
private:
1614-
SpirvInstruction *buffer;
1615-
};
1616-
16171597
class SpirvUndef : public SpirvInstruction {
16181598
public:
16191599
SpirvUndef(QualType type);

tools/clang/include/clang/SPIRV/SpirvVisitor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class Visitor {
100100
DEFINE_VISIT_METHOD(SpirvConstantNull)
101101
DEFINE_VISIT_METHOD(SpirvConvertPtrToU)
102102
DEFINE_VISIT_METHOD(SpirvConvertUToPtr)
103-
DEFINE_VISIT_METHOD(SpirvBufferPointerEXT)
104103
DEFINE_VISIT_METHOD(SpirvUndef)
105104
DEFINE_VISIT_METHOD(SpirvCompositeConstruct)
106105
DEFINE_VISIT_METHOD(SpirvCompositeExtract)

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,48 +1174,57 @@ DeclResultIdMapper::createFileVar(const VarDecl *var,
11741174
}
11751175

11761176
SpirvInstruction *
1177-
DeclResultIdMapper::createResourceHeap(const VarDecl *var,
1178-
QualType ResourceType) {
1179-
if (spirvOptions.useDescriptorHeap) {
1180-
SpirvUntypedVariableKHR *HeapVar = nullptr;
1181-
1182-
if (isResourceDescriptorHeap(var)) {
1183-
if (!ResourceHeapVar) {
1184-
const auto loc = var->getLocation();
1185-
const auto *type = spvContext.getUntypedPointerKHRType(
1186-
spv::StorageClass::UniformConstant);
1187-
ResourceHeapVar = spvBuilder.createUntypedVariableKHR(
1188-
type, spv::StorageClass::UniformConstant, loc, "resource_heap");
1189-
spvBuilder.decorateWithLiterals(
1190-
ResourceHeapVar, static_cast<uint32_t>(spv::Decoration::BuiltIn),
1191-
{static_cast<uint32_t>(spv::BuiltIn::ResourceHeapEXT)}, loc);
1192-
}
1193-
HeapVar = ResourceHeapVar;
1194-
} else if (isSamplerDescriptorHeap(var)) {
1195-
if (!SamplerHeapVar) {
1196-
const auto loc = var->getLocation();
1197-
const auto *type = spvContext.getUntypedPointerKHRType(
1198-
spv::StorageClass::UniformConstant);
1199-
SamplerHeapVar = spvBuilder.createUntypedVariableKHR(
1200-
type, spv::StorageClass::UniformConstant, loc, "sampler_heap");
1201-
spvBuilder.decorateWithLiterals(
1202-
SamplerHeapVar, static_cast<uint32_t>(spv::Decoration::BuiltIn),
1203-
{static_cast<uint32_t>(spv::BuiltIn::SamplerHeapEXT)}, loc);
1204-
}
1205-
HeapVar = SamplerHeapVar;
1206-
} else
1207-
assert(0 && "Unsupported heap type");
1177+
DeclResultIdMapper::createResourceDescriptorHeap(const VarDecl *var) {
1178+
SpirvUntypedVariableKHR *HeapVar = nullptr;
1179+
1180+
if (isResourceDescriptorHeap(var)) {
1181+
if (!ResourceHeapVar) {
1182+
const auto loc = var->getLocation();
1183+
const auto *type = spvContext.getUntypedPointerKHRType(
1184+
spv::StorageClass::UniformConstant);
1185+
ResourceHeapVar = spvBuilder.createUntypedVariableKHR(
1186+
type, spv::StorageClass::UniformConstant, "resource_heap", loc);
1187+
spvBuilder.decorateWithLiterals(
1188+
ResourceHeapVar, static_cast<uint32_t>(spv::Decoration::BuiltIn),
1189+
{static_cast<uint32_t>(spv::BuiltIn::ResourceHeapEXT)}, loc);
1190+
}
1191+
HeapVar = ResourceHeapVar;
1192+
} else if (isSamplerDescriptorHeap(var)) {
1193+
if (!SamplerHeapVar) {
1194+
const auto loc = var->getLocation();
1195+
const auto *type = spvContext.getUntypedPointerKHRType(
1196+
spv::StorageClass::UniformConstant);
1197+
SamplerHeapVar = spvBuilder.createUntypedVariableKHR(
1198+
type, spv::StorageClass::UniformConstant, "sampler_heap", loc);
1199+
spvBuilder.decorateWithLiterals(
1200+
SamplerHeapVar, static_cast<uint32_t>(spv::Decoration::BuiltIn),
1201+
{static_cast<uint32_t>(spv::BuiltIn::SamplerHeapEXT)}, loc);
1202+
}
1203+
HeapVar = SamplerHeapVar;
1204+
} else
1205+
assert(0 && "Unsupported heap type");
12081206

1209-
// Decorate with BuiltIn
1210-
astDecls[var] = createDeclSpirvInfo(HeapVar);
1211-
return HeapVar;
1212-
}
1207+
// Decorate with BuiltIn
1208+
astDecls[var] = createDeclSpirvInfo(HeapVar);
1209+
return HeapVar;
1210+
}
12131211

1212+
SpirvInstruction *
1213+
DeclResultIdMapper::createEmulatedDescriptorHeap(const VarDecl *var,
1214+
QualType resourceType) {
12141215
QualType ResourceArrayType = astContext.getIncompleteArrayType(
1215-
ResourceType, clang::ArrayType::Normal, 0);
1216+
resourceType, clang::ArrayType::Normal, 0);
12161217
return createExternVar(var, ResourceArrayType);
12171218
}
12181219

1220+
SpirvInstruction *
1221+
DeclResultIdMapper::createResourceHeap(const VarDecl *var,
1222+
QualType resourceType) {
1223+
if (spirvOptions.useDescriptorHeap)
1224+
return createResourceDescriptorHeap(var);
1225+
return createEmulatedDescriptorHeap(var, resourceType);
1226+
}
1227+
12191228
SpirvVariable *DeclResultIdMapper::createExternVar(const VarDecl *var) {
12201229
return createExternVar(var, var->getType());
12211230
}
@@ -3933,13 +3942,15 @@ bool DeclResultIdMapper::createPayloadStageVars(
39333942
if (featureManager.isExtensionEnabled(Extension::EXT_mesh_shader)) {
39343943
for (SpirvInstruction *moduleInst :
39353944
spvBuilder.getModule()->getVariables()) {
3936-
if (auto *moduleVar = dyn_cast<SpirvVariable>(moduleInst)) {
3937-
if (moduleVar->getAstResultType() == type) {
3938-
moduleVar->setStorageClass(
3939-
spv::StorageClass::TaskPayloadWorkgroupEXT);
3940-
varInstr = moduleVar;
3941-
}
3942-
}
3945+
auto *moduleVar = dyn_cast<SpirvVariable>(moduleInst);
3946+
if (!moduleVar)
3947+
continue;
3948+
3949+
if (moduleVar->getAstResultType() != type)
3950+
continue;
3951+
3952+
moduleVar->setStorageClass(spv::StorageClass::TaskPayloadWorkgroupEXT);
3953+
varInstr = moduleVar;
39433954
}
39443955
}
39453956

tools/clang/lib/SPIRV/DeclResultIdMapper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,14 @@ class DeclResultIdMapper {
10061006
/// all of them should be associated with the same variable.
10071007
void registerVariableForDecl(const VarDecl *var, DeclSpirvInfo spirvInfo);
10081008

1009+
/// Creates a global variable for resource heaps using VK_EXT_descriptor_heap.
1010+
SpirvInstruction *createResourceDescriptorHeap(const VarDecl *var);
1011+
1012+
/// Creates a global variable for resource heaps containing elements of type
1013+
/// |type| (emulated descriptor heaps).
1014+
SpirvInstruction *createEmulatedDescriptorHeap(const VarDecl *var,
1015+
QualType resourceType);
1016+
10091017
private:
10101018
SpirvBuilder &spvBuilder;
10111019
SpirvEmitter &theEmitter;

tools/clang/lib/SPIRV/EmitVisitor.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -816,17 +816,6 @@ bool EmitVisitor::visit(SpirvUntypedAccessChainKHR *inst) {
816816
return true;
817817
}
818818

819-
bool EmitVisitor::visit(SpirvBufferPointerEXT *inst) {
820-
initInstruction(inst);
821-
curInst.push_back(inst->getResultTypeId());
822-
curInst.push_back(getOrAssignResultId<SpirvInstruction>(inst));
823-
curInst.push_back(getOrAssignResultId<SpirvInstruction>(inst->getBuffer()));
824-
finalizeInstruction(&mainBinary);
825-
emitDebugNameForInstruction(getOrAssignResultId<SpirvInstruction>(inst),
826-
inst->getDebugName());
827-
return true;
828-
}
829-
830819
bool EmitVisitor::visit(SpirvUntypedImageTexelPointerEXT *inst) {
831820
initInstruction(inst);
832821
curInst.push_back(inst->getResultTypeId());

tools/clang/lib/SPIRV/EmitVisitor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ class EmitVisitor : public Visitor {
245245
bool visit(SpirvVariable *) override;
246246
bool visit(SpirvUntypedVariableKHR *) override;
247247
bool visit(SpirvUntypedAccessChainKHR *) override;
248-
bool visit(SpirvBufferPointerEXT *) override;
249248
bool visit(SpirvUntypedImageTexelPointerEXT *) override;
250249
bool visit(SpirvFunctionParameter *) override;
251250
bool visit(SpirvLoopMerge *) override;

tools/clang/lib/SPIRV/SpirvBuilder.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -560,16 +560,6 @@ SpirvConvertUToPtr *SpirvBuilder::createConvertUToPtr(SpirvInstruction *val,
560560
return instruction;
561561
}
562562

563-
SpirvBufferPointerEXT *SpirvBuilder::createBufferPointerEXT(
564-
const SpirvType *resultType, SpirvInstruction *buffer, SourceLocation loc) {
565-
assert(insertPoint && "null insert point");
566-
auto *instruction =
567-
new (context) SpirvBufferPointerEXT(resultType, loc, buffer);
568-
instruction->setRValue(true);
569-
insertPoint->addInstruction(instruction);
570-
return instruction;
571-
}
572-
573563
spv::ImageOperandsMask SpirvBuilder::composeImageOperandsMask(
574564
SpirvInstruction *bias, SpirvInstruction *lod,
575565
const std::pair<SpirvInstruction *, SpirvInstruction *> &grad,
@@ -1739,8 +1729,8 @@ SpirvVariable *SpirvBuilder::addModuleVar(
17391729
}
17401730

17411731
SpirvUntypedVariableKHR *SpirvBuilder::createUntypedVariableKHR(
1742-
const SpirvType *type, spv::StorageClass storageClass, SourceLocation loc,
1743-
llvm::StringRef name) {
1732+
const SpirvType *type, spv::StorageClass storageClass, llvm::StringRef name,
1733+
SourceLocation loc) {
17441734
assert(storageClass != spv::StorageClass::Function);
17451735
auto *var = new (context) SpirvUntypedVariableKHR(type, loc, storageClass);
17461736
mod->addVariable(var);

tools/clang/lib/SPIRV/SpirvInstruction.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ DEFINE_INVOKE_VISITOR_FOR_CLASS(SpirvConstantString)
7070
DEFINE_INVOKE_VISITOR_FOR_CLASS(SpirvConstantNull)
7171
DEFINE_INVOKE_VISITOR_FOR_CLASS(SpirvConvertPtrToU)
7272
DEFINE_INVOKE_VISITOR_FOR_CLASS(SpirvConvertUToPtr)
73-
DEFINE_INVOKE_VISITOR_FOR_CLASS(SpirvBufferPointerEXT)
7473
DEFINE_INVOKE_VISITOR_FOR_CLASS(SpirvUndef)
7574
DEFINE_INVOKE_VISITOR_FOR_CLASS(SpirvCompositeConstruct)
7675
DEFINE_INVOKE_VISITOR_FOR_CLASS(SpirvCompositeExtract)
@@ -736,15 +735,6 @@ bool SpirvConvertUToPtr::operator==(const SpirvConvertUToPtr &that) const {
736735
astResultType == that.astResultType && val == that.val;
737736
}
738737

739-
SpirvBufferPointerEXT::SpirvBufferPointerEXT(const SpirvType *resultType,
740-
SourceLocation loc,
741-
SpirvInstruction *bufferInst)
742-
: SpirvInstruction(IK_BufferPointerEXT, spv::Op::OpBufferPointerEXT,
743-
QualType(), loc),
744-
buffer(bufferInst) {
745-
setResultType(resultType);
746-
}
747-
748738
SpirvUndef::SpirvUndef(QualType type)
749739
: SpirvInstruction(IK_Undef, spv::Op::OpUndef, type,
750740
/*SourceLocation*/ {}) {}

0 commit comments

Comments
 (0)