Skip to content

Commit 297055a

Browse files
gpuav: Create common GetDescriptorSetAndBinding
1 parent ce2edc7 commit 297055a

6 files changed

Lines changed: 19 additions & 46 deletions

layers/gpuav/spirv/descriptor_class_general_buffer_pass.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,7 @@ bool DescriptorClassGeneralBufferPass::RequiresInstrumentation(const Function& f
153153
meta.descriptor_index_id = type_manager_.GetConstantZeroUint32().Id();
154154
}
155155

156-
for (const auto& annotation : module_.annotations_) {
157-
if (annotation->Opcode() == spv::OpDecorate && annotation->Word(1) == variable->Id()) {
158-
if (annotation->Word(2) == spv::DecorationDescriptorSet) {
159-
meta.descriptor_set = annotation->Word(3);
160-
} else if (annotation->Word(2) == spv::DecorationBinding) {
161-
meta.descriptor_binding = annotation->Word(3);
162-
}
163-
}
164-
}
156+
GetDescriptorSetAndBinding(variable->Id(), meta.descriptor_set, meta.descriptor_binding);
165157

166158
if (meta.descriptor_set >= glsl::kDebugInputBindlessMaxDescSets) {
167159
module_.InternalWarning(Name(), "Tried to use a descriptor slot over the current max limit");

layers/gpuav/spirv/descriptor_class_texel_buffer_pass.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,7 @@ bool DescriptorClassTexelBufferPass::RequiresInstrumentation(const Function& fun
142142
meta.descriptor_index_id = type_manager_.GetConstantZeroUint32().Id();
143143
}
144144

145-
uint32_t variable_id = meta.var_inst->ResultId();
146-
for (const auto& annotation : module_.annotations_) {
147-
if (annotation->Opcode() == spv::OpDecorate && annotation->Word(1) == variable_id) {
148-
if (annotation->Word(2) == spv::DecorationDescriptorSet) {
149-
meta.descriptor_set = annotation->Word(3);
150-
} else if (annotation->Word(2) == spv::DecorationBinding) {
151-
meta.descriptor_binding = annotation->Word(3);
152-
}
153-
}
154-
}
145+
GetDescriptorSetAndBinding(meta.var_inst->ResultId(), meta.descriptor_set, meta.descriptor_binding);
155146

156147
if (meta.descriptor_set >= glsl::kDebugInputBindlessMaxDescSets) {
157148
module_.InternalWarning(Name(), "Tried to use a descriptor slot over the current max limit");

layers/gpuav/spirv/descriptor_indexing_oob_pass.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,7 @@ bool DescriptorIndexingOOBPass::RequiresInstrumentation(const Function& function
294294

295295
assert(meta.var_inst);
296296
uint32_t variable_id = meta.var_inst->ResultId();
297-
for (const auto& annotation : module_.annotations_) {
298-
if (annotation->Opcode() == spv::OpDecorate && annotation->Word(1) == variable_id) {
299-
if (annotation->Word(2) == spv::DecorationDescriptorSet) {
300-
meta.descriptor_set = annotation->Word(3);
301-
} else if (annotation->Word(2) == spv::DecorationBinding) {
302-
meta.descriptor_binding = annotation->Word(3);
303-
}
304-
}
305-
}
297+
GetDescriptorSetAndBinding(variable_id, meta.descriptor_set, meta.descriptor_binding);
306298

307299
if (meta.descriptor_set >= glsl::kDebugInputBindlessMaxDescSets) {
308300
module_.InternalWarning(Name(), "Tried to use a descriptor slot over the current max limit");
@@ -357,15 +349,7 @@ bool DescriptorIndexingOOBPass::RequiresInstrumentation(const Function& function
357349
}
358350

359351
variable_id = meta.sampler_var_inst->ResultId();
360-
for (const auto& annotation : module_.annotations_) {
361-
if (annotation->Opcode() == spv::OpDecorate && annotation->Word(1) == variable_id) {
362-
if (annotation->Word(2) == spv::DecorationDescriptorSet) {
363-
meta.sampler_descriptor_set = annotation->Word(3);
364-
} else if (annotation->Word(2) == spv::DecorationBinding) {
365-
meta.sampler_descriptor_binding = annotation->Word(3);
366-
}
367-
}
368-
}
352+
GetDescriptorSetAndBinding(variable_id, meta.sampler_descriptor_set, meta.sampler_descriptor_binding);
369353

370354
if (meta.sampler_descriptor_set >= glsl::kDebugInputBindlessMaxDescSets) {
371355
module_.InternalWarning(Name(), "Sampler Tried to use a descriptor slot over the current max limit");

layers/gpuav/spirv/pass.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@ const Instruction* Pass::GetMemberDecoration(uint32_t id, uint32_t member_index,
245245
return nullptr;
246246
}
247247

248+
void Pass::GetDescriptorSetAndBinding(uint32_t variable_id, uint32_t& out_set, uint32_t& out_binding) const {
249+
for (const auto& annotation : module_.annotations_) {
250+
if (annotation->Opcode() == spv::OpDecorate && annotation->Word(1) == variable_id) {
251+
if (annotation->Word(2) == spv::DecorationDescriptorSet) {
252+
out_set = annotation->Word(3);
253+
} else if (annotation->Word(2) == spv::DecorationBinding) {
254+
out_binding = annotation->Word(3);
255+
}
256+
}
257+
}
258+
}
259+
248260
// In an ideal world, this would be baked into the Type class when we construct it. The core issue is OpTypeMatrix size can be
249261
// different depending where it is used. Because of this, we need to have a higher level view what is going on in order to correctly
250262
// figure out the size of a given type.

layers/gpuav/spirv/pass.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Pass {
6363

6464
const Instruction* GetDecoration(uint32_t id, spv::Decoration decoration) const;
6565
const Instruction* GetMemberDecoration(uint32_t id, uint32_t member_index, spv::Decoration decoration) const;
66+
void GetDescriptorSetAndBinding(uint32_t variable_id, uint32_t& out_set, uint32_t& out_binding) const;
6667

6768
uint32_t FindTypeByteSize(uint32_t type_id, uint32_t matrix_stride = 0, bool col_major = false, bool in_matrix = false) const;
6869
// Currently only used in the General Buffer OOB check, put here so it can be adapted for general use if needed

layers/gpuav/spirv/post_process_descriptor_indexing_pass.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,8 @@ bool PostProcessDescriptorIndexingPass::RequiresInstrumentation(const Function&
147147

148148
assert(var_inst);
149149
meta.variable_id = var_inst->ResultId();
150-
for (const auto& annotation : module_.annotations_) {
151-
if (annotation->Opcode() == spv::OpDecorate && annotation->Word(1) == meta.variable_id) {
152-
if (annotation->Word(2) == spv::DecorationDescriptorSet) {
153-
meta.descriptor_set = annotation->Word(3);
154-
} else if (annotation->Word(2) == spv::DecorationBinding) {
155-
meta.descriptor_binding = annotation->Word(3);
156-
}
157-
}
158-
}
150+
151+
GetDescriptorSetAndBinding(meta.variable_id, meta.descriptor_set, meta.descriptor_binding);
159152

160153
if (meta.descriptor_set >= glsl::kDebugInputBindlessMaxDescSets) {
161154
module_.InternalWarning(Name(), "Tried to use a descriptor slot over the current max limit");

0 commit comments

Comments
 (0)