Mesa (main): radv: optimised command buffer reset of vertex bindings.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed May 11 05:58:11 UTC 2022


Module: Mesa
Branch: main
Commit: 9775da1196362558a485dd49cc273344f773b4a6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9775da1196362558a485dd49cc273344f773b4a6

Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Apr 11 13:42:58 2022 +1000

radv: optimised command buffer reset of vertex bindings.

This takes the buffer ptrs out of the struct, so they can be memset
separately and optimises the memset to be minimal for them.

Removing them from the struct avoids having to loop to clear them.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16393>

---

 src/amd/vulkan/radv_cmd_buffer.c | 13 +++++++++----
 src/amd/vulkan/radv_private.h    |  3 ++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c
index 2f569437f09..8c1b541c1ad 100644
--- a/src/amd/vulkan/radv_cmd_buffer.c
+++ b/src/amd/vulkan/radv_cmd_buffer.c
@@ -518,7 +518,8 @@ radv_reset_cmd_buffer(struct radv_cmd_buffer *cmd_buffer)
 
    cmd_buffer->record_result = VK_SUCCESS;
 
-   memset(cmd_buffer->vertex_bindings, 0, sizeof(cmd_buffer->vertex_bindings));
+   memset(cmd_buffer->vertex_binding_buffers, 0, sizeof(struct radv_buffer *) * cmd_buffer->used_vertex_bindings);
+   cmd_buffer->used_vertex_bindings = 0;
 
    for (unsigned i = 0; i < MAX_BIND_POINTS; i++) {
       cmd_buffer->descriptors[i].dirty = 0;
@@ -3390,7 +3391,7 @@ radv_flush_vertex_descriptors(struct radv_cmd_buffer *cmd_buffer, bool pipeline_
          unsigned binding =
             vs_state ? cmd_buffer->state.dynamic_vs_input.bindings[i]
                      : (pipeline->use_per_attribute_vb_descs ? pipeline->attrib_bindings[i] : i);
-         struct radv_buffer *buffer = cmd_buffer->vertex_bindings[binding].buffer;
+         struct radv_buffer *buffer = cmd_buffer->vertex_binding_buffers[binding];
          unsigned num_records;
          unsigned stride;
 
@@ -4713,13 +4714,17 @@ radv_CmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
    assert(firstBinding + bindingCount <= MAX_VBS);
    cmd_buffer->state.vbo_misaligned_mask = state->misaligned_mask;
    enum chip_class chip = cmd_buffer->device->physical_device->rad_info.chip_class;
+
+   if (firstBinding + bindingCount > cmd_buffer->used_vertex_bindings)
+      cmd_buffer->used_vertex_bindings = firstBinding + bindingCount;
+
    for (uint32_t i = 0; i < bindingCount; i++) {
       RADV_FROM_HANDLE(radv_buffer, buffer, pBuffers[i]);
       uint32_t idx = firstBinding + i;
       VkDeviceSize size = pSizes ? pSizes[i] : 0;
       VkDeviceSize stride = pStrides ? pStrides[i] : 0;
 
-      vb[idx].buffer = buffer;
+      cmd_buffer->vertex_binding_buffers[idx] = buffer;
       vb[idx].offset = pOffsets[i];
       vb[idx].size = size;
 
@@ -4747,7 +4752,7 @@ radv_CmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
          vb[idx].stride = stride;
 
       if (buffer) {
-         radv_cs_add_buffer(cmd_buffer->device->ws, cmd_buffer->cs, vb[idx].buffer->bo);
+         radv_cs_add_buffer(cmd_buffer->device->ws, cmd_buffer->cs, cmd_buffer->vertex_binding_buffers[idx]->bo);
       }
    }
 
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index 2abf56017eb..d8eeb2de853 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -1149,7 +1149,6 @@ enum radv_nggc_settings {
 };
 
 struct radv_vertex_binding {
-   struct radv_buffer *buffer;
    VkDeviceSize offset;
    VkDeviceSize size;
    VkDeviceSize stride;
@@ -1535,7 +1534,9 @@ struct radv_cmd_buffer {
    enum radv_cmd_buffer_status status;
    struct radeon_cmdbuf *cs;
    struct radv_cmd_state state;
+   struct radv_buffer *vertex_binding_buffers[MAX_VBS];
    struct radv_vertex_binding vertex_bindings[MAX_VBS];
+   uint32_t used_vertex_bindings;
    struct radv_streamout_binding streamout_bindings[MAX_SO_BUFFERS];
    enum radv_queue_family qf;
 



More information about the mesa-commit mailing list