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

Author: Jordan Justen <[email protected]>
Date:   Wed Oct 11 12:56:45 2023 -0700

anv/batch: Assert that extend_cb is non-NULL if the batch is out of space

Signed-off-by: Jordan Justen <[email protected]>
Reviewed-by: Lionel Landwerlin <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25672>

---

 src/intel/vulkan/anv_batch_chain.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/intel/vulkan/anv_batch_chain.c 
b/src/intel/vulkan/anv_batch_chain.c
index fef06a78f0b..26597c06426 100644
--- a/src/intel/vulkan/anv_batch_chain.c
+++ b/src/intel/vulkan/anv_batch_chain.c
@@ -151,16 +151,23 @@ anv_reloc_list_append(struct anv_reloc_list *list,
  * Functions related to anv_batch
  *-----------------------------------------------------------------------*/
 
+static VkResult
+anv_extend_batch(struct anv_batch *batch, uint32_t size)
+{
+   assert(batch->extend_cb != NULL);
+   VkResult result = batch->extend_cb(batch, size, batch->user_data);
+   if (result != VK_SUCCESS)
+      return anv_batch_set_error(batch, result);
+   return result;
+}
+
 void *
 anv_batch_emit_dwords(struct anv_batch *batch, int num_dwords)
 {
    uint32_t size = num_dwords * 4;
    if (batch->next + size > batch->end) {
-      VkResult result = batch->extend_cb(batch, size, batch->user_data);
-      if (result != VK_SUCCESS) {
-         anv_batch_set_error(batch, result);
+      if (anv_extend_batch(batch, size) != VK_SUCCESS)
          return NULL;
-      }
    }
 
    void *p = batch->next;
@@ -176,11 +183,9 @@ VkResult
 anv_batch_emit_ensure_space(struct anv_batch *batch, uint32_t size)
 {
    if (batch->next + size > batch->end) {
-      VkResult result = batch->extend_cb(batch, size, batch->user_data);
-      if (result != VK_SUCCESS) {
-         anv_batch_set_error(batch, result);
+      VkResult result = anv_extend_batch(batch, size);
+      if (result != VK_SUCCESS)
          return result;
-      }
    }
 
    assert(batch->next + size <= batch->end);
@@ -214,11 +219,8 @@ anv_batch_emit_batch(struct anv_batch *batch, struct 
anv_batch *other)
    assert(size % 4 == 0);
 
    if (batch->next + size > batch->end) {
-      VkResult result = batch->extend_cb(batch, size, batch->user_data);
-      if (result != VK_SUCCESS) {
-         anv_batch_set_error(batch, result);
+      if (anv_extend_batch(batch, size) != VK_SUCCESS)
          return;
-      }
    }
 
    assert(batch->next + size <= batch->end);

Reply via email to