Skip to content

Commit

Permalink
[vulkan] improved resource deletion logic to ensure that no resource …
Browse files Browse the repository at this point in the history
…is deleted while a command list is using it
  • Loading branch information
PanosK92 committed Oct 28, 2024
1 parent 887f1af commit 6a546b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
8 changes: 4 additions & 4 deletions runtime/Core/Debugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ namespace Spartan
private:
inline static bool m_validation_layer_enabled = false; // enables vulkan validation, high cpu overhead per draw
inline static bool m_gpu_assisted_validation_enabled = false; // gpu-based validation, significant cpu and gpu cost
inline static bool m_breadcrumbs_enabled = false; // breadcrumbs: tracks gpu crashes and writes info into breadcrumbs.txt, minimal overhead - will be ignored for non-amd gpus
inline static bool m_breadcrumbs_enabled = false; // tracks gpu crashes and writes info into breadcrumbs.txt, minimal overhead - will be ignored for non-amd gpus
inline static bool m_logging_to_file_enabled = false; // logs to file, high cpu cost due to disk i/o
inline static bool m_renderdoc_enabled = false; // integrates renderdoc, high cpu overhead from api wrapping
inline static bool m_gpu_marking_enabled = true; // gpu markers for debugging, no performance impact
inline static bool m_gpu_timing_enabled = true; // measures gpu timings, negligible cost
inline static bool m_shader_optimization_enabled = true; // enables shader optimizations, high cost when off
inline static bool m_gpu_marking_enabled = true; // negligible cost
inline static bool m_gpu_timing_enabled = true; // negligible cost
inline static bool m_shader_optimization_enabled = true; // high cost when off
};
}
34 changes: 30 additions & 4 deletions runtime/RHI/Vulkan/Vulkan_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1596,15 +1596,41 @@ namespace Spartan
deletion_queue.clear();
}

bool RHI_Device::DeletionQueueNeedsToParse()
bool RHI_Device::DeletionQueueNeedsToParse()
{
uint32_t objects_to_delete = 0;
const uint32_t frames_selflife = 10;
static uint32_t frames_equilibrium = 0;
static uint32_t previous_objects_to_delete = 0;

// count deletions in the queue
uint32_t current_objects_to_delete = 0;
for (uint32_t i = 0; i < static_cast<uint32_t>(RHI_Resource_Type::Max); i++)
{
objects_to_delete += static_cast<uint32_t>(deletion_queue[static_cast<RHI_Resource_Type>(i)].size());
current_objects_to_delete += static_cast<uint32_t>(deletion_queue[static_cast<RHI_Resource_Type>(i)].size());
}

// check if the number of objects to delete has remained unchanged
if (current_objects_to_delete > 0 && current_objects_to_delete == previous_objects_to_delete)
{
frames_equilibrium++;

return objects_to_delete > 0;
// if it’s been stable for frame_selflife frames, reset counter and delete
if (frames_equilibrium >= frames_selflife)
{
frames_equilibrium = 0;
return true;
}
}
else
{
// reset counter if the count changed or if nothing is in the queue
frames_equilibrium = 0;
}

// update the previous object count to the current count
previous_objects_to_delete = current_objects_to_delete;

return false;
}

// descriptors
Expand Down

0 comments on commit 6a546b1

Please sign in to comment.