From b73eea47bc9223622dbceca41cfff971375a92f5 Mon Sep 17 00:00:00 2001 From: Arno Date: Thu, 25 Jul 2024 18:20:52 +0200 Subject: [PATCH] layers: Misc memory optimisations --- .../gpuav_descriptor_validation.cpp | 44 ++++++++++--------- layers/gpu/resources/gpuav_subclasses.h | 10 ++--- layers/state_tracker/shader_module.cpp | 4 +- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/layers/gpu/descriptor_validation/gpuav_descriptor_validation.cpp b/layers/gpu/descriptor_validation/gpuav_descriptor_validation.cpp index 34fd40d97d3..83bccf20368 100644 --- a/layers/gpu/descriptor_validation/gpuav_descriptor_validation.cpp +++ b/layers/gpu/descriptor_validation/gpuav_descriptor_validation.cpp @@ -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) { @@ -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(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(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); } diff --git a/layers/gpu/resources/gpuav_subclasses.h b/layers/gpu/resources/gpuav_subclasses.h index 44bf5a02e71..c0f9b7828ee 100644 --- a/layers/gpu/resources/gpuav_subclasses.h +++ b/layers/gpu/resources/gpuav_subclasses.h @@ -40,14 +40,14 @@ namespace gpuav { class Validator; struct DescSetState { - uint32_t num; - std::shared_ptr state; - BindingVariableMap binding_req; + uint32_t num = 0; + std::shared_ptr 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 gpu_state; - std::shared_ptr output_state; + std::shared_ptr gpu_state = {}; + std::shared_ptr output_state = {}; }; struct DescBindingInfo { diff --git a/layers/state_tracker/shader_module.cpp b/layers/state_tracker/shader_module.cpp index 4039d2e876d..36e47028626 100644 --- a/layers/state_tracker/shader_module.cpp +++ b/layers/state_tracker/shader_module.cpp @@ -852,6 +852,7 @@ Module::StaticData::StaticData(const Module& module_state, StatelessData* statel { std::vector::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(); @@ -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)); }