Skip to content

Commit

Permalink
[rhi] RHI_CommandList::UpdateBuffer() now provides a parameter which …
Browse files Browse the repository at this point in the history
…allows zeroing out a buffer before updating it
  • Loading branch information
PanosK92 committed Jan 23, 2025
1 parent 8dfdfa9 commit a034fe7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion runtime/RHI/RHI_CommandList.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace spartan
void EndTimeblock();

// updates
void UpdateBuffer(RHI_Buffer* buffer, const uint64_t offset, const uint64_t size, const void* data);
void UpdateBuffer(RHI_Buffer* buffer, const uint64_t offset, const uint64_t size, const void* data, const bool zero_out);

// memory barriers
void InsertBarrierTexture(
Expand Down
2 changes: 1 addition & 1 deletion runtime/RHI/Vulkan/Vulkan_Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ namespace spartan
}

// vkCmdUpdateBuffer and vkCmdPipelineBarrier
cmd_list->UpdateBuffer(this, m_offset, size != 0 ? size : m_stride, data_cpu);
cmd_list->UpdateBuffer(this, m_offset, size != 0 ? size : m_stride, data_cpu, false);
}
}
7 changes: 6 additions & 1 deletion runtime/RHI/Vulkan/Vulkan_CommandList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1564,13 +1564,18 @@ namespace spartan
m_timeblock_active = nullptr;
}

void RHI_CommandList::UpdateBuffer(RHI_Buffer* buffer, const uint64_t offset, const uint64_t size, const void* data)
void RHI_CommandList::UpdateBuffer(RHI_Buffer* buffer, const uint64_t offset, const uint64_t size, const void* data, const bool zero_out)
{
SP_ASSERT(buffer);
SP_ASSERT(size);
SP_ASSERT(data);
SP_ASSERT(offset + size <= buffer->GetObjectSize());

if (zero_out)
{
memset(buffer->GetMappedData(), 0, buffer->GetObjectSize());
}

// check for vkCmdUpdateBuffer compliance to deduce if this is a small and synchronized update
// non-compliant updates are done via a memcpy, and they are there for the big bindless arrays
bool synchronized_update = true;
Expand Down
9 changes: 2 additions & 7 deletions runtime/Rendering/Font/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,8 @@ namespace spartan
cmd_list->InsertBarrierBufferReadWrite(m_buffer_vertex.get());
cmd_list->InsertBarrierBufferReadWrite(m_buffer_index.get());

// update vertex buffer
memset(m_buffer_vertex->GetMappedData(), 0, m_buffer_vertex->GetObjectSize());
cmd_list->UpdateBuffer(m_buffer_vertex.get(), 0, m_buffer_vertex->GetObjectSize(), &m_vertices[0]);

// update index buffer
memset(m_buffer_index->GetMappedData(), 0, m_buffer_index->GetObjectSize());
cmd_list->UpdateBuffer(m_buffer_index.get(), 0, m_buffer_index->GetObjectSize(), &m_indices[0]);
cmd_list->UpdateBuffer(m_buffer_vertex.get(), 0, m_buffer_vertex->GetObjectSize(), m_vertices.data(), true);
cmd_list->UpdateBuffer(m_buffer_index.get(), 0, m_buffer_index->GetObjectSize(), m_indices.data(), true);

m_font_data.clear();
}
Expand Down

0 comments on commit a034fe7

Please sign in to comment.