gallium/auxiliary/vl: Only map the shader constants buffer in render
authorDavid Rosca <nowrep@gmail.com>
Sat, 2 Sep 2023 08:00:09 +0000 (10:00 +0200)
committerMarge Bot <emma+marge@anholt.net>
Tue, 26 Sep 2023 13:03:46 +0000 (13:03 +0000)
Don't map the buffer in vl_compositor_set_csc_matrix.
This avoids mapping the buffer twice with compute shaders.

Acked-by: Leo Liu <leo.liu@amd.com>
Reviewed-by: Thong Thai <thong.thai@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25258>

src/gallium/auxiliary/vl/vl_compositor.c
src/gallium/auxiliary/vl/vl_compositor.h
src/gallium/auxiliary/vl/vl_compositor_cs.c
src/gallium/auxiliary/vl/vl_compositor_gfx.c

index ebb88fd..91a10a6 100644 (file)
@@ -479,24 +479,11 @@ vl_compositor_set_csc_matrix(struct vl_compositor_state *s,
                              vl_csc_matrix const *matrix,
                              float luma_min, float luma_max)
 {
-   struct pipe_transfer *buf_transfer;
-
    assert(s);
 
-   float *ptr = pipe_buffer_map(s->pipe, s->shader_params,
-                               PIPE_MAP_WRITE | PIPE_MAP_DISCARD_RANGE,
-                               &buf_transfer);
-
-   if (!ptr)
-      return false;
-
-   memcpy(ptr, matrix, sizeof(vl_csc_matrix));
-
-   ptr += sizeof(vl_csc_matrix)/sizeof(float);
-   ptr[0] = luma_min;
-   ptr[1] = luma_max;
-
-   pipe_buffer_unmap(s->pipe, buf_transfer);
+   memcpy(&s->csc_matrix, matrix, sizeof(vl_csc_matrix));
+   s->luma_min = luma_min;
+   s->luma_max = luma_max;
 
    return true;
 }
index c8f2515..8e49008 100644 (file)
@@ -114,6 +114,9 @@ struct vl_compositor_state
    struct vl_compositor_layer layers[VL_COMPOSITOR_MAX_LAYERS];
    bool interlaced;
    unsigned chroma_location;
+
+   vl_csc_matrix csc_matrix;
+   float luma_min, luma_max;
 };
 
 struct vl_compositor
index dec2b9c..3f4f0ce 100644 (file)
@@ -866,16 +866,19 @@ set_viewport(struct vl_compositor_state *s,
 
    assert(s && drawn);
 
-   void *ptr = pipe_buffer_map_range(s->pipe, s->shader_params,
-                                     sizeof(vl_csc_matrix) + sizeof(float) * 2,
-                                     sizeof(float) * 12 + sizeof(int) * 8,
-                                     PIPE_MAP_WRITE | PIPE_MAP_DISCARD_RANGE,
-                                     &buf_transfer);
+   void *ptr = pipe_buffer_map(s->pipe, s->shader_params,
+                               PIPE_MAP_WRITE | PIPE_MAP_DISCARD_WHOLE_RESOURCE,
+                               &buf_transfer);
 
    if (!ptr)
      return false;
 
+   memcpy(ptr, &s->csc_matrix, sizeof(vl_csc_matrix));
+
    float *ptr_float = (float *)ptr;
+   ptr_float += sizeof(vl_csc_matrix) / sizeof(float);
+   *ptr_float++ = s->luma_min;
+   *ptr_float++ = s->luma_max;
    *ptr_float++ = drawn->scale_x;
    *ptr_float++ = drawn->scale_y;
 
index 7244aeb..f6fef79 100644 (file)
@@ -646,6 +646,27 @@ gen_vertex_data(struct vl_compositor *c, struct vl_compositor_state *s, struct u
 }
 
 static void
+set_csc_matrix(struct vl_compositor_state *s)
+{
+   struct pipe_transfer *buf_transfer;
+
+   float *ptr = pipe_buffer_map(s->pipe, s->shader_params,
+                                PIPE_MAP_WRITE | PIPE_MAP_DISCARD_WHOLE_RESOURCE,
+                                &buf_transfer);
+
+   if (!ptr)
+     return;
+
+   memcpy(ptr, &s->csc_matrix, sizeof(vl_csc_matrix));
+
+   ptr += sizeof(vl_csc_matrix) / sizeof(float);
+   *ptr++ = s->luma_min;
+   *ptr++ = s->luma_max;
+
+   pipe_buffer_unmap(s->pipe, buf_transfer);
+}
+
+static void
 draw_layers(struct vl_compositor *c, struct vl_compositor_state *s, struct u_rect *dirty)
 {
    unsigned vb_index, i;
@@ -705,6 +726,7 @@ vl_compositor_gfx_render(struct vl_compositor_state *s,
    c->pipe->set_scissor_states(c->pipe, 0, 1, &s->scissor);
 
    gen_vertex_data(c, s, dirty_area);
+   set_csc_matrix(s);
 
    if (clear_dirty && dirty_area &&
        (dirty_area->x0 < dirty_area->x1 || dirty_area->y0 < dirty_area->y1)) {