radv/amdgpu: use the correct IB size when growing a CS with RADV_DEBUG=noibs
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 21 Jun 2023 11:42:41 +0000 (13:42 +0200)
committerMarge Bot <emma+marge@anholt.net>
Mon, 26 Jun 2023 09:10:09 +0000 (09:10 +0000)
The current IB size is copied when radv_amdgpu_cs_add_old_ib_buffer()
is called, which might not be the real IB size because we might still
pad the CS with NOP packets after.

Found by inspection.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23727>

src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c

index e55a0e6..ca52430 100644 (file)
@@ -342,11 +342,17 @@ radv_amdgpu_cs_grow(struct radeon_cmdbuf *_cs, size_t min_size)
    enum amd_ip_type ip_type = cs->hw_ip;
    uint32_t ib_pad_dw_mask = MAX2(3, cs->ws->info.ib_pad_dw_mask[ip_type]);
    uint32_t nop_packet = get_nop_packet(cs);
-   while (!cs->base.cdw || (cs->base.cdw & ib_pad_dw_mask) != ib_pad_dw_mask - 3)
-      radeon_emit_unchecked(&cs->base, nop_packet);
 
-   if (cs->use_ib)
+   if (cs->use_ib) {
+      while (!cs->base.cdw || (cs->base.cdw & ib_pad_dw_mask) != ib_pad_dw_mask - 3)
+         radeon_emit_unchecked(&cs->base, nop_packet);
+
       *cs->ib_size_ptr |= cs->base.cdw + 4;
+   } else {
+      /* Pad the CS with NOP packets. */
+      while (!cs->base.cdw || (cs->base.cdw & ib_pad_dw_mask))
+         radeon_emit_unchecked(&cs->base, nop_packet);
+   }
 
    radv_amdgpu_cs_add_old_ib_buffer(cs);
    if (cs->status != VK_SUCCESS)
@@ -384,10 +390,6 @@ radv_amdgpu_cs_grow(struct radeon_cmdbuf *_cs, size_t min_size)
       radeon_emit_unchecked(&cs->base, S_3F2_CHAIN(1) | S_3F2_VALID(1));
 
       cs->ib_size_ptr = cs->base.buf + cs->base.cdw - 1;
-   } else {
-      /* Pad the CS with NOP packets. */
-      while (!cs->base.cdw || (cs->base.cdw & ib_pad_dw_mask))
-         radeon_emit_unchecked(&cs->base, nop_packet);
    }
 
    cs->base.buf = (uint32_t *)cs->ib_mapped;