lavapipe: add a zeroed buffer that can be bound in place of an index buffer
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 31 May 2023 16:01:24 +0000 (12:01 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 8 Jun 2023 01:22:01 +0000 (01:22 +0000)
technically this is illegal in vulkan semantics, but some extensions have
their own definition of "illegal" when it comes to binding index buffers

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23394>

src/gallium/frontends/lavapipe/lvp_device.c
src/gallium/frontends/lavapipe/lvp_execute.c
src/gallium/frontends/lavapipe/lvp_private.h

index 90be3bd..f6f6a1c 100644 (file)
@@ -1530,6 +1530,9 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDevice(
    _mesa_hash_table_init(&device->bda, NULL, _mesa_hash_pointer, _mesa_key_pointer_equal);
    simple_mtx_init(&device->bda_lock, mtx_plain);
 
+   uint32_t zero = 0;
+   device->zero_buffer = pipe_buffer_create_with_data(device->queue.ctx, 0, PIPE_USAGE_IMMUTABLE, sizeof(uint32_t), &zero);
+
    *pDevice = lvp_device_to_handle(device);
 
    return VK_SUCCESS;
@@ -1548,6 +1551,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_DestroyDevice(
       device->pscreen->fence_reference(device->pscreen, &device->queue.last_fence, NULL);
    ralloc_free(device->bda.table);
    simple_mtx_destroy(&device->bda_lock);
+   pipe_resource_reference(&device->zero_buffer, NULL);
 
    lvp_queue_finish(&device->queue);
    vk_device_finish(&device->vk);
index 36e4d19..2c0c2a2 100644 (file)
@@ -2833,7 +2833,7 @@ static void handle_index_buffer(struct vk_cmd_queue_entry *cmd,
    if (ib->buffer)
       state->index_buffer = lvp_buffer_from_handle(ib->buffer)->bo;
    else
-      state->index_buffer = NULL;
+      state->index_buffer = state->device->zero_buffer;
 
    state->ib_dirty = true;
 }
index 97da27b..fbbf315 100644 (file)
@@ -193,6 +193,7 @@ struct lvp_device {
    void *noop_fs;
    simple_mtx_t bda_lock;
    struct hash_table bda;
+   struct pipe_resource *zero_buffer; /* for zeroed bda */
    bool poison_mem;
    bool print_cmds;
 };