Skip to content

Commit c2cf37e

Browse files
ShchchowAMDspencer-lunargalan-baker
authored
Implement SPV_EXT_descriptor_heap (#6503)
Support SPV_EXT_descriptor_heap in SPIRV validatoin level. --------- Co-authored-by: spencer-lunarg <spencer@lunarg.com> Co-authored-by: Alan Baker <alanbaker@google.com>
1 parent 2e57045 commit c2cf37e

30 files changed

+3116
-89
lines changed

source/opcode.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ int32_t spvOpcodeIsConstant(const spv::Op opcode) {
153153
case spv::Op::OpSpecConstantArchitectureINTEL:
154154
case spv::Op::OpSpecConstantTargetINTEL:
155155
case spv::Op::OpSpecConstantCapabilitiesINTEL:
156+
case spv::Op::OpConstantSizeOfEXT:
156157
return true;
157158
default:
158159
return false;
@@ -198,8 +199,10 @@ bool spvOpcodeReturnsLogicalVariablePointer(const spv::Op opcode) {
198199
case spv::Op::OpInBoundsAccessChain:
199200
case spv::Op::OpUntypedAccessChainKHR:
200201
case spv::Op::OpUntypedInBoundsAccessChainKHR:
202+
case spv::Op::OpBufferPointerEXT:
201203
case spv::Op::OpFunctionParameter:
202204
case spv::Op::OpImageTexelPointer:
205+
case spv::Op::OpUntypedImageTexelPointerEXT:
203206
case spv::Op::OpCopyObject:
204207
case spv::Op::OpAllocateNodePayloadsAMDX:
205208
case spv::Op::OpSelect:
@@ -224,8 +227,10 @@ int32_t spvOpcodeReturnsLogicalPointer(const spv::Op opcode) {
224227
case spv::Op::OpInBoundsAccessChain:
225228
case spv::Op::OpUntypedAccessChainKHR:
226229
case spv::Op::OpUntypedInBoundsAccessChainKHR:
230+
case spv::Op::OpBufferPointerEXT:
227231
case spv::Op::OpFunctionParameter:
228232
case spv::Op::OpImageTexelPointer:
233+
case spv::Op::OpUntypedImageTexelPointerEXT:
229234
case spv::Op::OpCopyObject:
230235
case spv::Op::OpRawAccessChainNV:
231236
case spv::Op::OpAllocateNodePayloadsAMDX:
@@ -275,6 +280,7 @@ int32_t spvOpcodeGeneratesType(spv::Op op) {
275280
case spv::Op::OpTypeTensorARM:
276281
case spv::Op::OpTypeTaskSequenceINTEL:
277282
case spv::Op::OpTypeGraphARM:
283+
case spv::Op::OpTypeBufferEXT:
278284
return true;
279285
default:
280286
// In particular, OpTypeForwardPointer does not generate a type,
@@ -290,6 +296,7 @@ bool spvOpcodeIsDecoration(const spv::Op opcode) {
290296
case spv::Op::OpDecorate:
291297
case spv::Op::OpDecorateId:
292298
case spv::Op::OpMemberDecorate:
299+
case spv::Op::OpMemberDecorateIdEXT:
293300
case spv::Op::OpGroupDecorate:
294301
case spv::Op::OpGroupMemberDecorate:
295302
case spv::Op::OpDecorateStringGOOGLE:

source/operand.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ std::function<bool(unsigned)> spvOperandCanBeForwardDeclaredFunction(
523523
case spv::Op::OpSelectionMerge:
524524
case spv::Op::OpDecorate:
525525
case spv::Op::OpMemberDecorate:
526+
case spv::Op::OpMemberDecorateIdEXT:
526527
case spv::Op::OpDecorateId:
527528
case spv::Op::OpDecorateStringGOOGLE:
528529
case spv::Op::OpMemberDecorateStringGOOGLE:

source/opt/aggressive_dead_code_elim_pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ void AggressiveDCEPass::InitExtensions() {
11511151
"SPV_NV_shader_subgroup_partitioned",
11521152
"SPV_EXT_demote_to_helper_invocation",
11531153
"SPV_EXT_descriptor_indexing",
1154+
"SPV_EXT_descriptor_heap",
11541155
"SPV_NV_fragment_shader_barycentric",
11551156
"SPV_NV_compute_shader_derivatives",
11561157
"SPV_NV_shader_image_footprint",

source/opt/local_access_chain_convert_pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ void LocalAccessChainConvertPass::InitExtensions() {
436436
"SPV_NV_shader_subgroup_partitioned",
437437
"SPV_EXT_demote_to_helper_invocation",
438438
"SPV_EXT_descriptor_indexing",
439+
"SPV_EXT_descriptor_heap",
439440
"SPV_NV_fragment_shader_barycentric",
440441
"SPV_NV_compute_shader_derivatives",
441442
"SPV_NV_shader_image_footprint",

source/opt/local_single_block_elim_pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
272272
"SPV_NV_shader_subgroup_partitioned",
273273
"SPV_EXT_demote_to_helper_invocation",
274274
"SPV_EXT_descriptor_indexing",
275+
"SPV_EXT_descriptor_heap",
275276
"SPV_NV_fragment_shader_barycentric",
276277
"SPV_NV_compute_shader_derivatives",
277278
"SPV_NV_shader_image_footprint",

source/opt/local_single_store_elim_pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ void LocalSingleStoreElimPass::InitExtensionAllowList() {
122122
"SPV_GOOGLE_hlsl_functionality1",
123123
"SPV_NV_shader_subgroup_partitioned",
124124
"SPV_EXT_descriptor_indexing",
125+
"SPV_EXT_descriptor_heap",
125126
"SPV_NV_fragment_shader_barycentric",
126127
"SPV_NV_compute_shader_derivatives",
127128
"SPV_NV_shader_image_footprint",

source/opt/reflect.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ inline bool IsAnnotationInst(spv::Op opcode) {
4444
opcode <= spv::Op::OpGroupMemberDecorate) ||
4545
opcode == spv::Op::OpDecorateId ||
4646
opcode == spv::Op::OpDecorateStringGOOGLE ||
47-
opcode == spv::Op::OpMemberDecorateStringGOOGLE;
47+
opcode == spv::Op::OpMemberDecorateStringGOOGLE ||
48+
opcode == spv::Op::OpMemberDecorateIdEXT;
4849
}
4950
inline bool IsTypeInst(spv::Op opcode) {
5051
return spvOpcodeGeneratesType(opcode) ||

source/opt/type_manager.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,14 @@ uint32_t TypeManager::GetTypeInstruction(const Type* type) {
539539
id, ops);
540540
break;
541541
}
542+
case Type::kBufferEXT: {
543+
typeInst = MakeUnique<Instruction>(
544+
context(), spv::Op::OpTypeBufferEXT, 0, id,
545+
std::initializer_list<Operand>{
546+
{SPV_OPERAND_TYPE_STORAGE_CLASS,
547+
{static_cast<uint32_t>(type->AsBufferEXT()->storage_class())}}});
548+
break;
549+
}
542550
default:
543551
assert(false && "Unexpected type");
544552
break;
@@ -816,6 +824,11 @@ Type* TypeManager::RebuildType(uint32_t type_id, const Type& type) {
816824
rebuilt_ty = MakeUnique<GraphARM>(graph_type->num_inputs(), io_types);
817825
break;
818826
}
827+
case Type::kBufferEXT: {
828+
const BufferEXT* buffer_type = type.AsBufferEXT();
829+
rebuilt_ty = MakeUnique<BufferEXT>(buffer_type->storage_class());
830+
break;
831+
}
819832
default:
820833
assert(false && "Unhandled type");
821834
return nullptr;
@@ -1126,6 +1139,11 @@ Type* TypeManager::RecordIfTypeDefinition(const Instruction& inst) {
11261139
type = new GraphARM(inst.GetSingleWordInOperand(0), io_types);
11271140
break;
11281141
}
1142+
case spv::Op::OpTypeBufferEXT: {
1143+
type = new BufferEXT(
1144+
static_cast<spv::StorageClass>(inst.GetSingleWordInOperand(0)));
1145+
break;
1146+
}
11291147
default:
11301148
assert(false && "Type not handled by the type manager.");
11311149
break;

source/opt/types.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ std::unique_ptr<Type> Type::Clone() const {
138138
DeclareKindCase(HitObjectEXT);
139139
DeclareKindCase(TensorARM);
140140
DeclareKindCase(GraphARM);
141+
DeclareKindCase(BufferEXT);
141142
#undef DeclareKindCase
142143
default:
143144
assert(false && "Unhandled type");
@@ -193,6 +194,7 @@ bool Type::operator==(const Type& other) const {
193194
DeclareKindCase(TensorViewNV);
194195
DeclareKindCase(TensorARM);
195196
DeclareKindCase(GraphARM);
197+
DeclareKindCase(BufferEXT);
196198
#undef DeclareKindCase
197199
default:
198200
assert(false && "Unhandled type");
@@ -256,6 +258,7 @@ size_t Type::ComputeHashValue(size_t hash, SeenTypes* seen) const {
256258
DeclareKindCase(TensorViewNV);
257259
DeclareKindCase(TensorARM);
258260
DeclareKindCase(GraphARM);
261+
DeclareKindCase(BufferEXT);
259262
#undef DeclareKindCase
260263
default:
261264
assert(false && "Unhandled type");
@@ -993,6 +996,31 @@ bool GraphARM::IsSameImpl(const Type* that, IsSameCache* seen) const {
993996
return true;
994997
}
995998

999+
BufferEXT::BufferEXT(spv::StorageClass storage_class)
1000+
: Type(kBufferEXT), storage_class_(storage_class) {}
1001+
1002+
std::string BufferEXT::str() const {
1003+
std::ostringstream oss;
1004+
oss << "buffer<" << static_cast<uint32_t>(storage_class_) << ">";
1005+
return oss.str();
1006+
}
1007+
1008+
size_t BufferEXT::ComputeExtraStateHash(size_t hash, SeenTypes*) const {
1009+
hash = hash_combine(hash, static_cast<uint32_t>(storage_class_));
1010+
return hash;
1011+
}
1012+
1013+
bool BufferEXT::IsSameImpl(const Type* that, IsSameCache*) const {
1014+
const BufferEXT* og = that->AsBufferEXT();
1015+
if (!og) {
1016+
return false;
1017+
}
1018+
if (storage_class_ != og->storage_class_) {
1019+
return false;
1020+
}
1021+
return true;
1022+
}
1023+
9961024
} // namespace analysis
9971025
} // namespace opt
9981026
} // namespace spvtools

source/opt/types.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class TensorLayoutNV;
7272
class TensorViewNV;
7373
class TensorARM;
7474
class GraphARM;
75+
class BufferEXT;
7576

7677
// Abstract class for a SPIR-V type. It has a bunch of As<sublcass>() methods,
7778
// which is used as a way to probe the actual <subclass>.
@@ -120,6 +121,7 @@ class Type {
120121
kTensorViewNV,
121122
kTensorARM,
122123
kGraphARM,
124+
kBufferEXT,
123125
kLast
124126
};
125127

@@ -235,6 +237,7 @@ class Type {
235237
DeclareCastMethod(TensorViewNV)
236238
DeclareCastMethod(TensorARM)
237239
DeclareCastMethod(GraphARM)
240+
DeclareCastMethod(BufferEXT)
238241
#undef DeclareCastMethod
239242

240243
protected:
@@ -839,6 +842,26 @@ class GraphARM : public Type {
839842
const std::vector<const Type*> io_types_;
840843
};
841844

845+
class BufferEXT : public Type {
846+
public:
847+
BufferEXT(spv::StorageClass storage_class_);
848+
BufferEXT(const BufferEXT&) = default;
849+
850+
std::string str() const override;
851+
852+
BufferEXT* AsBufferEXT() override { return this; }
853+
const BufferEXT* AsBufferEXT() const override { return this; }
854+
855+
spv::StorageClass storage_class() const { return storage_class_; }
856+
857+
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
858+
859+
private:
860+
bool IsSameImpl(const Type* that, IsSameCache*) const override;
861+
862+
const spv::StorageClass storage_class_;
863+
};
864+
842865
#define DefineParameterlessType(type, name) \
843866
class type : public Type { \
844867
public: \

0 commit comments

Comments
 (0)