Skip to content

Commit

Permalink
layers: Misc memory optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
arno-lunarg committed Jul 26, 2024
1 parent ce5542f commit b73eea4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
44 changes: 23 additions & 21 deletions layers/gpu/descriptor_validation/gpuav_descriptor_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "gpu/core/gpuav.h"
#include "gpu/resources/gpuav_subclasses.h"

#include "profiling/profiling.h"

namespace gpuav {
void UpdateBoundPipeline(Validator &gpuav, VkCommandBuffer cb, VkPipelineBindPoint pipeline_bind_point, VkPipeline pipeline,
const Location &loc) {
Expand Down Expand Up @@ -110,37 +112,37 @@ void UpdateBoundDescriptors(Validator &gpuav, VkCommandBuffer cb, VkPipelineBind
cb_state->current_bindless_buffer = di_buffers.bindless_state_buffer;

bindless_state->global_state = gpuav.desc_heap_->GetDeviceAddress();
di_buffers.descriptor_set_buffers.reserve(di_buffers.descriptor_set_buffers.size() + last_bound.per_set.size());
for (uint32_t i = 0; i < last_bound.per_set.size(); i++) {
const auto &s = last_bound.per_set[i];
auto set = s.bound_descriptor_set;
if (!set) {
continue;
}
if (gpuav.gpuav_settings.validate_descriptors) {
DescSetState desc_set_state;
desc_set_state.num = i;
desc_set_state.state = std::static_pointer_cast<DescriptorSet>(set);
bindless_state->desc_sets[i].layout_data = desc_set_state.state->GetLayoutState();
// The pipeline might not have been bound yet, so will need to update binding_req later
if (last_bound.pipeline_state) {
auto slot = last_bound.pipeline_state->active_slots.find(i);
if (slot != last_bound.pipeline_state->active_slots.end()) {
desc_set_state.binding_req = slot->second;
}

DescSetState desc_set_state;
desc_set_state.num = i;
desc_set_state.state = std::static_pointer_cast<DescriptorSet>(set);
bindless_state->desc_sets[i].layout_data = desc_set_state.state->GetLayoutState();
// The pipeline might not have been bound yet, so will need to update binding_req later
if (last_bound.pipeline_state) {
auto slot = last_bound.pipeline_state->active_slots.find(i);
if (slot != last_bound.pipeline_state->active_slots.end()) {
desc_set_state.binding_req = slot->second;
}
if (!desc_set_state.state->IsUpdateAfterBind()) {
desc_set_state.gpu_state = desc_set_state.state->GetCurrentState();
bindless_state->desc_sets[i].in_data = desc_set_state.gpu_state->device_addr;
desc_set_state.output_state = desc_set_state.state->GetOutputState(gpuav, loc);
if (!desc_set_state.output_state) {
goto exit;
}
bindless_state->desc_sets[i].out_data = desc_set_state.output_state->device_addr;
}
if (!desc_set_state.state->IsUpdateAfterBind()) {
desc_set_state.gpu_state = desc_set_state.state->GetCurrentState();
bindless_state->desc_sets[i].in_data = desc_set_state.gpu_state->device_addr;
desc_set_state.output_state = desc_set_state.state->GetOutputState(gpuav, loc);
if (!desc_set_state.output_state) {
goto exit;
}
di_buffers.descriptor_set_buffers.emplace_back(std::move(desc_set_state));
bindless_state->desc_sets[i].out_data = desc_set_state.output_state->device_addr;
}
di_buffers.descriptor_set_buffers.emplace_back(std::move(desc_set_state));
}
cb_state->di_input_buffer_list.emplace_back(di_buffers);
cb_state->di_input_buffer_list.emplace_back(std::move(di_buffers));
exit:
vmaUnmapMemory(gpuav.vma_allocator_, di_buffers.bindless_state_buffer_allocation);
}
Expand Down
10 changes: 5 additions & 5 deletions layers/gpu/resources/gpuav_subclasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ namespace gpuav {
class Validator;

struct DescSetState {
uint32_t num;
std::shared_ptr<DescriptorSet> state;
BindingVariableMap binding_req;
uint32_t num = 0;
std::shared_ptr<DescriptorSet> state = {};
BindingVariableMap binding_req = {};
// State that will be used by the GPU-AV shader instrumentation
// For update-after-bind, this will be set during queue submission
// Otherwise it will be set when the DescriptorSet is bound.
std::shared_ptr<DescriptorSet::State> gpu_state;
std::shared_ptr<DescriptorSet::State> output_state;
std::shared_ptr<DescriptorSet::State> gpu_state = {};
std::shared_ptr<DescriptorSet::State> output_state = {};
};

struct DescBindingInfo {
Expand Down
4 changes: 3 additions & 1 deletion layers/state_tracker/shader_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ Module::StaticData::StaticData(const Module& module_state, StatelessData* statel
{
std::vector<uint32_t>::const_iterator it = module_state.words_.cbegin();
it += 5; // skip first 5 word of header
instructions.reserve(module_state.words_.size() * 4);
while (it != module_state.words_.cend()) {
Instruction insn(it);
const uint32_t opcode = insn.Opcode();
Expand Down Expand Up @@ -2002,7 +2003,8 @@ bool ResourceInterfaceVariable::IsStorageBuffer(const ResourceInterfaceVariable&
const bool storage_buffer = variable.storage_class == spv::StorageClassStorageBuffer;
const bool uniform = variable.storage_class == spv::StorageClassUniform;
// Block decorations are always on the struct of the variable
const bool buffer_block = variable.type_struct_info && variable.type_struct_info->decorations.Has(DecorationSet::buffer_block_bit);
const bool buffer_block =
variable.type_struct_info && variable.type_struct_info->decorations.Has(DecorationSet::buffer_block_bit);
const bool block = variable.type_struct_info && variable.type_struct_info->decorations.Has(DecorationSet::block_bit);
return ((uniform && buffer_block) || ((storage_buffer || physical_storage_buffer) && block));
}
Expand Down

0 comments on commit b73eea4

Please sign in to comment.