It shouldn't be needed to emit the initial graphics or compute
state when beginning a new command buffer. Emitting them in
the preamble should be enough and this will reduce IB sizes.

Signed-off-by: Samuel Pitoiset <samuel.pitoi...@gmail.com>
---
 src/amd/vulkan/radv_cmd_buffer.c | 29 ----------------------
 src/amd/vulkan/radv_device.c     | 41 ++++++++++++++++++++++++++++++++
 src/amd/vulkan/radv_private.h    |  6 +++--
 src/amd/vulkan/si_cmd_buffer.c   | 24 ++++---------------
 4 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c
index 2d66098873..3bc6a08a05 100644
--- a/src/amd/vulkan/radv_cmd_buffer.c
+++ b/src/amd/vulkan/radv_cmd_buffer.c
@@ -2290,20 +2290,6 @@ VkResult radv_ResetCommandBuffer(
        return radv_reset_cmd_buffer(cmd_buffer);
 }
 
-static void emit_gfx_buffer_state(struct radv_cmd_buffer *cmd_buffer)
-{
-       struct radv_device *device = cmd_buffer->device;
-       if (device->gfx_init) {
-               uint64_t va = radv_buffer_get_va(device->gfx_init);
-               radv_cs_add_buffer(device->ws, cmd_buffer->cs, 
device->gfx_init);
-               radeon_emit(cmd_buffer->cs, PKT3(PKT3_INDIRECT_BUFFER_CIK, 2, 
0));
-               radeon_emit(cmd_buffer->cs, va);
-               radeon_emit(cmd_buffer->cs, va >> 32);
-               radeon_emit(cmd_buffer->cs, device->gfx_init_size_dw & 0xffff);
-       } else
-               si_init_config(cmd_buffer);
-}
-
 VkResult radv_BeginCommandBuffer(
        VkCommandBuffer commandBuffer,
        const VkCommandBufferBeginInfo *pBeginInfo)
@@ -2329,21 +2315,6 @@ VkResult radv_BeginCommandBuffer(
        cmd_buffer->state.predication_type = -1;
        cmd_buffer->usage_flags = pBeginInfo->flags;
 
-       /* setup initial configuration into command buffer */
-       if (cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
-               switch (cmd_buffer->queue_family_index) {
-               case RADV_QUEUE_GENERAL:
-                       emit_gfx_buffer_state(cmd_buffer);
-                       break;
-               case RADV_QUEUE_COMPUTE:
-                       si_init_compute(cmd_buffer);
-                       break;
-               case RADV_QUEUE_TRANSFER:
-               default:
-                       break;
-               }
-       }
-
        if (cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_SECONDARY &&
            (pBeginInfo->flags & 
VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
                assert(pBeginInfo->pInheritanceInfo);
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 7917ed7ffe..8724fa3848 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -2090,6 +2090,33 @@ radv_emit_global_shader_pointers(struct radv_queue 
*queue,
        }
 }
 
+static void
+radv_init_graphics_state(struct radeon_cmdbuf *cs, struct radv_queue *queue)
+{
+       struct radv_device *device = queue->device;
+
+       if (device->gfx_init) {
+               uint64_t va = radv_buffer_get_va(device->gfx_init);
+
+               radeon_emit(cs, PKT3(PKT3_INDIRECT_BUFFER_CIK, 2, 0));
+               radeon_emit(cs, va);
+               radeon_emit(cs, va >> 32);
+               radeon_emit(cs, device->gfx_init_size_dw & 0xffff);
+
+               radv_cs_add_buffer(device->ws, cs, device->gfx_init);
+       } else {
+               struct radv_physical_device *physical_device = 
device->physical_device;
+               si_emit_graphics(physical_device, cs);
+       }
+}
+
+static void
+radv_init_compute_state(struct radeon_cmdbuf *cs, struct radv_queue *queue)
+{
+       struct radv_physical_device *physical_device = 
queue->device->physical_device;
+       si_emit_compute(physical_device, cs);
+}
+
 static VkResult
 radv_get_preamble_cs(struct radv_queue *queue,
                      uint32_t scratch_size,
@@ -2244,6 +2271,20 @@ radv_get_preamble_cs(struct radv_queue *queue,
                if (scratch_bo)
                        radv_cs_add_buffer(queue->device->ws, cs, scratch_bo);
 
+               if (i == 0 || i == 1) {
+                       /* Emit initial configuration for the two preambles. */
+                       switch (queue->queue_family_index) {
+                       case RADV_QUEUE_GENERAL:
+                               radv_init_graphics_state(cs, queue);
+                               break;
+                       case RADV_QUEUE_COMPUTE:
+                               radv_init_compute_state(cs, queue);
+                               break;
+                       case RADV_QUEUE_TRANSFER:
+                               break;
+                       }
+               }
+
                if (descriptor_bo != queue->descriptor_bo) {
                        uint32_t *map = 
(uint32_t*)queue->device->ws->buffer_map(descriptor_bo);
 
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index 01a5a698a0..08425473fe 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -1065,8 +1065,10 @@ struct radv_image;
 
 bool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);
 
-void si_init_compute(struct radv_cmd_buffer *cmd_buffer);
-void si_init_config(struct radv_cmd_buffer *cmd_buffer);
+void si_emit_graphics(struct radv_physical_device *physical_device,
+                     struct radeon_cmdbuf *cs);
+void si_emit_compute(struct radv_physical_device *physical_device,
+                     struct radeon_cmdbuf *cs);
 
 void cik_create_gfx_config(struct radv_device *device);
 
diff --git a/src/amd/vulkan/si_cmd_buffer.c b/src/amd/vulkan/si_cmd_buffer.c
index 435878c372..aca0c61615 100644
--- a/src/amd/vulkan/si_cmd_buffer.c
+++ b/src/amd/vulkan/si_cmd_buffer.c
@@ -79,7 +79,7 @@ si_write_harvested_raster_configs(struct radv_physical_device 
*physical_device,
                radeon_set_context_reg(cs, R_028354_PA_SC_RASTER_CONFIG_1, 
raster_config_1);
 }
 
-static void
+void
 si_emit_compute(struct radv_physical_device *physical_device,
                 struct radeon_cmdbuf *cs)
 {
@@ -117,13 +117,6 @@ si_emit_compute(struct radv_physical_device 
*physical_device,
        }
 }
 
-void
-si_init_compute(struct radv_cmd_buffer *cmd_buffer)
-{
-       struct radv_physical_device *physical_device = 
cmd_buffer->device->physical_device;
-       si_emit_compute(physical_device, cmd_buffer->cs);
-}
-
 /* 12.4 fixed-point */
 static unsigned radv_pack_float_12p4(float x)
 {
@@ -159,9 +152,9 @@ si_set_raster_config(struct radv_physical_device 
*physical_device,
        }
 }
 
-static void
-si_emit_config(struct radv_physical_device *physical_device,
-              struct radeon_cmdbuf *cs)
+void
+si_emit_graphics(struct radv_physical_device *physical_device,
+                struct radeon_cmdbuf *cs)
 {
        int i;
 
@@ -388,13 +381,6 @@ si_emit_config(struct radv_physical_device 
*physical_device,
        si_emit_compute(physical_device, cs);
 }
 
-void si_init_config(struct radv_cmd_buffer *cmd_buffer)
-{
-       struct radv_physical_device *physical_device = 
cmd_buffer->device->physical_device;
-
-       si_emit_config(physical_device, cmd_buffer->cs);
-}
-
 void
 cik_create_gfx_config(struct radv_device *device)
 {
@@ -402,7 +388,7 @@ cik_create_gfx_config(struct radv_device *device)
        if (!cs)
                return;
 
-       si_emit_config(device->physical_device, cs);
+       si_emit_graphics(device->physical_device, cs);
 
        while (cs->cdw & 7) {
                if (device->physical_device->rad_info.gfx_ib_pad_with_type2)
-- 
2.18.0

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to