Revert "gallium/hud: don't use user vertex buffers"
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Wed, 10 Jun 2020 17:56:49 +0000 (19:56 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 16 Jun 2020 08:02:29 +0000 (08:02 +0000)
The approach taken in this commit only works on drivers that expose
the PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT capability. For drivers
that don't, the buffer has been unmapped by the time we get to
hud_draw_colored_prims, leading to crashes.

It's not easy to fix the code, but drivers that do support coherent
mapping will most likely do the right think themseleves, so let's just
go back to using user-buffers here.

This reverts commit 4fe1fd4df40ac91b2783e3604fd81e6a6faf0cd2.

Fixes: 4fe1fd4df40 ("gallium/hud: don't use user vertex buffers")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3106
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5417>

src/gallium/auxiliary/hud/hud_context.c
src/gallium/auxiliary/hud/hud_private.h

index 57f577a3a9230e15ea5e25e37f76dbb31e131b4d..2b84e6f88e66199631b357dc2bd73aa495eacc3d 100644 (file)
@@ -73,13 +73,7 @@ hud_draw_colored_prims(struct hud_context *hud, unsigned prim,
                        int xoffset, int yoffset, float yscale)
 {
    struct cso_context *cso = hud->cso;
-   unsigned size = num_vertices * hud->color_prims.vbuf.stride;
-
-   /* If a recording context is inactive, don't draw anything. */
-   if (size > hud->color_prims.buffer_size)
-      return;
-
-   memcpy(hud->color_prims.vertices, buffer, size);
+   struct pipe_vertex_buffer vbuffer = {0};
 
    hud->constants.color[0] = r;
    hud->constants.color[1] = g;
@@ -91,13 +85,13 @@ hud_draw_colored_prims(struct hud_context *hud, unsigned prim,
    hud->constants.scale[1] = yscale * hud_scale;
    cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
 
-   cso_set_vertex_buffers(cso, 0, 1, &hud->color_prims.vbuf);
+   vbuffer.is_user_buffer = true;
+   vbuffer.buffer.user = buffer;
+   vbuffer.stride = 2 * sizeof(float);
+
+   cso_set_vertex_buffers(cso, 0, 1, &vbuffer);
    cso_set_fragment_shader_handle(hud->cso, hud->fs_color);
    cso_draw_arrays(cso, prim, 0, num_vertices);
-
-   hud->color_prims.vertices += size / sizeof(float);
-   hud->color_prims.vbuf.buffer_offset += size;
-   hud->color_prims.buffer_size -= size;
 }
 
 static void
@@ -645,7 +639,6 @@ hud_stop_queries(struct hud_context *hud, struct pipe_context *pipe)
    hud_prepare_vertices(hud, &hud->bg, 16 * 256, 2 * sizeof(float));
    hud_prepare_vertices(hud, &hud->whitelines, 4 * 256, 2 * sizeof(float));
    hud_prepare_vertices(hud, &hud->text, 16 * 1024, 4 * sizeof(float));
-   hud_prepare_vertices(hud, &hud->color_prims, 32 * 1024, 2 * sizeof(float));
 
    /* Allocate everything once and divide the storage into 3 portions
     * manually, because u_upload_alloc can unmap memory from previous calls.
@@ -653,8 +646,7 @@ hud_stop_queries(struct hud_context *hud, struct pipe_context *pipe)
    u_upload_alloc(pipe->stream_uploader, 0,
                   hud->bg.buffer_size +
                   hud->whitelines.buffer_size +
-                  hud->text.buffer_size +
-                  hud->color_prims.buffer_size,
+                  hud->text.buffer_size,
                   16, &hud->bg.vbuf.buffer_offset, &hud->bg.vbuf.buffer.resource,
                   (void**)&hud->bg.vertices);
    if (!hud->bg.vertices)
@@ -662,7 +654,6 @@ hud_stop_queries(struct hud_context *hud, struct pipe_context *pipe)
 
    pipe_resource_reference(&hud->whitelines.vbuf.buffer.resource, hud->bg.vbuf.buffer.resource);
    pipe_resource_reference(&hud->text.vbuf.buffer.resource, hud->bg.vbuf.buffer.resource);
-   pipe_resource_reference(&hud->color_prims.vbuf.buffer.resource, hud->bg.vbuf.buffer.resource);
 
    hud->whitelines.vbuf.buffer_offset = hud->bg.vbuf.buffer_offset +
                                         hud->bg.buffer_size;
@@ -674,11 +665,6 @@ hud_stop_queries(struct hud_context *hud, struct pipe_context *pipe)
    hud->text.vertices = hud->whitelines.vertices +
                         hud->whitelines.buffer_size / sizeof(float);
 
-   hud->color_prims.vbuf.buffer_offset = hud->text.vbuf.buffer_offset +
-                                         hud->text.buffer_size;
-   hud->color_prims.vertices = hud->text.vertices +
-                               hud->text.buffer_size / sizeof(float);
-
    /* prepare all graphs */
    hud_batch_query_update(hud->batch_query, pipe);
 
index da0b47e498dc8f4483738b2805a9516944f1252e..c95f4c42b44c3c7badfd6eda2977c2a2cd186a19 100644 (file)
@@ -90,7 +90,7 @@ struct hud_context {
       unsigned max_num_vertices;
       unsigned num_vertices;
       unsigned buffer_size;
-   } text, bg, whitelines, color_prims;
+   } text, bg, whitelines;
 
    bool has_srgb;
 };