zink: replace unset buffer with a dummy-buffer
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Sat, 1 Feb 2020 16:38:30 +0000 (17:38 +0100)
committerMarge Bot <eric+marge@anholt.net>
Mon, 10 Feb 2020 10:40:19 +0000 (10:40 +0000)
This fixes a crash in spec@!opengl 1.1@ppgtt_memory_alignment

Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3673>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3673>

src/gallium/drivers/zink/zink_context.c
src/gallium/drivers/zink/zink_context.h
src/gallium/drivers/zink/zink_draw.c

index f2b9044bc2bc7e471bca40a53913c90fdf654490..d6d3f33b115e844acda7cf2d0e924b5d807f49f5 100644 (file)
@@ -1172,6 +1172,12 @@ zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
        !ctx->framebuffer_cache)
       goto fail;
 
+   const uint8_t data[] = { 0 };
+   ctx->dummy_buffer = pipe_buffer_create_with_data(&ctx->base,
+      PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_IMMUTABLE, sizeof(data), data);
+   if (!ctx->dummy_buffer)
+      goto fail;
+
    ctx->dirty_program = true;
 
    /* start the first batch */
index e46cb8017daae46fc41e7add3da25db31563715c..3aeef31e3d36c18bcb4265e96cf15ca411a15e0d 100644 (file)
@@ -110,6 +110,8 @@ struct zink_context {
 
    struct list_head active_queries;
    bool queries_disabled;
+
+   struct pipe_resource *dummy_buffer;
 };
 
 static inline struct zink_context *
index 76dcd30783d995ff26c9ffe694d88e45a06af579..553579acf64affdc1c17b1e39a69eb4c7263fd66 100644 (file)
@@ -44,11 +44,16 @@ zink_bind_vertex_buffers(struct zink_batch *batch, struct zink_context *ctx)
    const struct zink_vertex_elements_state *elems = ctx->element_state;
    for (unsigned i = 0; i < elems->hw_state.num_bindings; i++) {
       struct pipe_vertex_buffer *vb = ctx->buffers + ctx->element_state->binding_map[i];
-      assert(vb && vb->buffer.resource);
-      struct zink_resource *res = zink_resource(vb->buffer.resource);
-      buffers[i] = res->buffer;
-      buffer_offsets[i] = vb->buffer_offset;
-      zink_batch_reference_resoure(batch, res);
+      assert(vb);
+      if (vb->buffer.resource) {
+         struct zink_resource *res = zink_resource(vb->buffer.resource);
+         buffers[i] = res->buffer;
+         buffer_offsets[i] = vb->buffer_offset;
+         zink_batch_reference_resoure(batch, res);
+      } else {
+         buffers[i] = zink_resource(ctx->dummy_buffer)->buffer;
+         buffer_offsets[i] = 0;
+      }
    }
 
    if (elems->hw_state.num_bindings > 0)