From 4fd4d9bcd7cd2c149e93c705be0a3c9d07fa4c88 Mon Sep 17 00:00:00 2001 From: Panos Karabelas Date: Thu, 19 Dec 2024 14:21:06 +0000 Subject: [PATCH] [renderer] made it show that all remaining buffers update via cmd_list->UpdateBuffer() --- runtime/RHI/Vulkan/Vulkan_Buffer.cpp | 20 ++++---------------- runtime/Rendering/Renderer.cpp | 7 +++---- runtime/Rendering/Renderer.h | 2 +- runtime/Rendering/Renderer_Passes.cpp | 9 +++++++++ runtime/Rendering/Renderer_Resources.cpp | 14 ++++---------- 5 files changed, 21 insertions(+), 31 deletions(-) diff --git a/runtime/RHI/Vulkan/Vulkan_Buffer.cpp b/runtime/RHI/Vulkan/Vulkan_Buffer.cpp index 6f6aecca4..2b90ec2ad 100644 --- a/runtime/RHI/Vulkan/Vulkan_Buffer.cpp +++ b/runtime/RHI/Vulkan/Vulkan_Buffer.cpp @@ -117,7 +117,8 @@ namespace Spartan void RHI_Buffer::Update(RHI_CommandList* cmd_list, void* data_cpu, const uint32_t size) { - SP_ASSERT_MSG(m_mappable, "Can't update unmappable buffer"); + SP_ASSERT(cmd_list); + SP_ASSERT_MSG(m_mappable, "Can't update unmapped buffer"); SP_ASSERT_MSG(data_cpu != nullptr, "Invalid cpu data"); SP_ASSERT_MSG(m_data_gpu != nullptr, "Invalid gpu data"); SP_ASSERT_MSG(m_offset + m_stride <= m_object_size, "Out of memory"); @@ -132,20 +133,7 @@ namespace Spartan m_offset += m_stride; } - // update - if (cmd_list) - { - // vkCmdUpdateBuffer and vkCmdPipelineBarrier - cmd_list->UpdateBuffer(this, m_offset, size != 0 ? size : m_stride, data_cpu); - } - else - { - // direct and async - memcpy( - reinterpret_cast(m_data_gpu) + m_offset, // destination - reinterpret_cast(data_cpu), // source - size != 0 ? size : m_stride // size - ); - } + // vkCmdUpdateBuffer and vkCmdPipelineBarrier + cmd_list->UpdateBuffer(this, m_offset, size != 0 ? size : m_stride, data_cpu); } } diff --git a/runtime/Rendering/Renderer.cpp b/runtime/Rendering/Renderer.cpp index f9a317ca5..0c0f6a98c 100644 --- a/runtime/Rendering/Renderer.cpp +++ b/runtime/Rendering/Renderer.cpp @@ -575,7 +575,6 @@ namespace Spartan void Renderer::OnUpdateBuffers(RHI_CommandList* cmd_list) { - // reset dynamic buffers and parse deletion queue { m_resource_index++; @@ -599,7 +598,7 @@ namespace Spartan if (bindless_materials_dirty) { - BindlessUpdateMaterials(); // properties + BindlessUpdateMaterials(cmd_list); // properties RHI_Device::UpdateBindlessResources(nullptr, &bindless_textures); // textures bindless_materials_dirty = false; } @@ -851,7 +850,7 @@ namespace Spartan cmd_list->SetTexture(Renderer_BindingsSrv::gbuffer_depth_opaque, GetRenderTarget(Renderer_RenderTarget::gbuffer_depth_opaque)); } - void Renderer::BindlessUpdateMaterials() + void Renderer::BindlessUpdateMaterials(RHI_CommandList* cmd_list) { static array properties; // mapped to the gpu as a structured properties buffer static unordered_set unique_material_ids; @@ -966,7 +965,7 @@ namespace Spartan // material properties Renderer::GetBuffer(Renderer_Buffer::StorageMaterials)->ResetOffset(); uint32_t update_size = static_cast(sizeof(Sb_Material)) * index; - Renderer::GetBuffer(Renderer_Buffer::StorageMaterials)->Update(nullptr, &properties[0], update_size); + Renderer::GetBuffer(Renderer_Buffer::StorageMaterials)->Update(cmd_list, &properties[0], update_size); } index = 0; diff --git a/runtime/Rendering/Renderer.h b/runtime/Rendering/Renderer.h index c9b03a3f5..eaf876917 100644 --- a/runtime/Rendering/Renderer.h +++ b/runtime/Rendering/Renderer.h @@ -189,7 +189,7 @@ namespace Spartan static void DestroyResources(); // bindless - static void BindlessUpdateMaterials(); + static void BindlessUpdateMaterials(RHI_CommandList* cmd_list); static void BindlessUpdateLights(RHI_CommandList* cmd_lis); // misc diff --git a/runtime/Rendering/Renderer_Passes.cpp b/runtime/Rendering/Renderer_Passes.cpp index 174c655d8..483b50807 100644 --- a/runtime/Rendering/Renderer_Passes.cpp +++ b/runtime/Rendering/Renderer_Passes.cpp @@ -1829,6 +1829,15 @@ namespace Spartan return; } + // only needs to be set once, then after each use SPD resets it itself + static bool initialized = false; + if (!initialized) + { + uint32_t counter_value = 0; + GetBuffer(Renderer_Buffer::StorageSpd)->Update(cmd_list, &counter_value); + initialized = true; + } + cmd_list->BeginMarker("downscale"); { // set pipeline state diff --git a/runtime/Rendering/Renderer_Resources.cpp b/runtime/Rendering/Renderer_Resources.cpp index b002ca73a..63707a6bf 100644 --- a/runtime/Rendering/Renderer_Resources.cpp +++ b/runtime/Rendering/Renderer_Resources.cpp @@ -76,17 +76,11 @@ namespace Spartan buffer(Renderer_Buffer::ConstantFrame) = make_shared(RHI_Buffer_Type::Constant, sizeof(Cb_Frame), element_count, nullptr, true, "frame"); // single dispatch downsample buffer - { - uint32_t times_used_in_frame = 12; // safe to tweak this, if it's not enough the engine will assert - uint32_t stride = static_cast(sizeof(uint32_t)); - buffer(Renderer_Buffer::StorageSpd) = make_shared(RHI_Buffer_Type::Storage, stride, element_count * times_used_in_frame, nullptr, true, "spd_counter"); - - // only needs to be set once, then after each use SPD resets it itself - uint32_t counter_value = 0; - buffer(Renderer_Buffer::StorageSpd)->Update(nullptr, &counter_value); - } + uint32_t times_used_in_frame = 12; // safe to tweak this, if it's not enough the engine will assert + uint32_t stride = static_cast(sizeof(uint32_t)); + buffer(Renderer_Buffer::StorageSpd) = make_shared(RHI_Buffer_Type::Storage, stride, element_count * times_used_in_frame, nullptr, true, "spd_counter"); - uint32_t stride = static_cast(sizeof(Sb_Material)) * rhi_max_array_size; + stride = static_cast(sizeof(Sb_Material)) * rhi_max_array_size; buffer(Renderer_Buffer::StorageMaterials) = make_shared(RHI_Buffer_Type::Storage, stride, 1, nullptr, true, "materials"); stride = static_cast(sizeof(Sb_Light)) * rhi_max_array_size_lights;