Skip to content

Commit

Permalink
[renderer] made it show that all remaining buffers update via cmd_lis…
Browse files Browse the repository at this point in the history
…t->UpdateBuffer()
  • Loading branch information
PanosK92 committed Dec 19, 2024
1 parent 90f287d commit 4fd4d9b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 31 deletions.
20 changes: 4 additions & 16 deletions runtime/RHI/Vulkan/Vulkan_Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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<std::byte*>(m_data_gpu) + m_offset, // destination
reinterpret_cast<std::byte*>(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);
}
}
7 changes: 3 additions & 4 deletions runtime/Rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,6 @@ namespace Spartan

void Renderer::OnUpdateBuffers(RHI_CommandList* cmd_list)
{

// reset dynamic buffers and parse deletion queue
{
m_resource_index++;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<Sb_Material, rhi_max_array_size> properties; // mapped to the gpu as a structured properties buffer
static unordered_set<uint64_t> unique_material_ids;
Expand Down Expand Up @@ -966,7 +965,7 @@ namespace Spartan
// material properties
Renderer::GetBuffer(Renderer_Buffer::StorageMaterials)->ResetOffset();
uint32_t update_size = static_cast<uint32_t>(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;
Expand Down
2 changes: 1 addition & 1 deletion runtime/Rendering/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions runtime/Rendering/Renderer_Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions runtime/Rendering/Renderer_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,11 @@ namespace Spartan
buffer(Renderer_Buffer::ConstantFrame) = make_shared<RHI_Buffer>(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<uint32_t>(sizeof(uint32_t));
buffer(Renderer_Buffer::StorageSpd) = make_shared<RHI_Buffer>(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<uint32_t>(sizeof(uint32_t));
buffer(Renderer_Buffer::StorageSpd) = make_shared<RHI_Buffer>(RHI_Buffer_Type::Storage, stride, element_count * times_used_in_frame, nullptr, true, "spd_counter");

uint32_t stride = static_cast<uint32_t>(sizeof(Sb_Material)) * rhi_max_array_size;
stride = static_cast<uint32_t>(sizeof(Sb_Material)) * rhi_max_array_size;
buffer(Renderer_Buffer::StorageMaterials) = make_shared<RHI_Buffer>(RHI_Buffer_Type::Storage, stride, 1, nullptr, true, "materials");

stride = static_cast<uint32_t>(sizeof(Sb_Light)) * rhi_max_array_size_lights;
Expand Down

0 comments on commit 4fd4d9b

Please sign in to comment.