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

Author: David Rosca <[email protected]>
Date:   Sat Sep  2 10:00:09 2023 +0200

gallium/auxiliary/vl: Only map the shader constants buffer in render

Don't map the buffer in vl_compositor_set_csc_matrix.
This avoids mapping the buffer twice with compute shaders.

Acked-by: Leo Liu <[email protected]>
Reviewed-by: Thong Thai <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25258>

---

 src/gallium/auxiliary/vl/vl_compositor.c     | 19 +++----------------
 src/gallium/auxiliary/vl/vl_compositor.h     |  3 +++
 src/gallium/auxiliary/vl/vl_compositor_cs.c  | 13 ++++++++-----
 src/gallium/auxiliary/vl/vl_compositor_gfx.c | 22 ++++++++++++++++++++++
 4 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/src/gallium/auxiliary/vl/vl_compositor.c 
b/src/gallium/auxiliary/vl/vl_compositor.c
index ebb88fd4d34..91a10a678c4 100644
--- a/src/gallium/auxiliary/vl/vl_compositor.c
+++ b/src/gallium/auxiliary/vl/vl_compositor.c
@@ -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;
 }
diff --git a/src/gallium/auxiliary/vl/vl_compositor.h 
b/src/gallium/auxiliary/vl/vl_compositor.h
index c8f2515d5ea..8e49008be44 100644
--- a/src/gallium/auxiliary/vl/vl_compositor.h
+++ b/src/gallium/auxiliary/vl/vl_compositor.h
@@ -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
diff --git a/src/gallium/auxiliary/vl/vl_compositor_cs.c 
b/src/gallium/auxiliary/vl/vl_compositor_cs.c
index dec2b9c8f2b..3f4f0cee79c 100644
--- a/src/gallium/auxiliary/vl/vl_compositor_cs.c
+++ b/src/gallium/auxiliary/vl/vl_compositor_cs.c
@@ -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;
 
diff --git a/src/gallium/auxiliary/vl/vl_compositor_gfx.c 
b/src/gallium/auxiliary/vl/vl_compositor_gfx.c
index 7244aeb7a1d..f6fef79066f 100644
--- a/src/gallium/auxiliary/vl/vl_compositor_gfx.c
+++ b/src/gallium/auxiliary/vl/vl_compositor_gfx.c
@@ -645,6 +645,27 @@ gen_vertex_data(struct vl_compositor *c, struct 
vl_compositor_state *s, struct u
    u_upload_unmap(c->pipe->stream_uploader);
 }
 
+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)
 {
@@ -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)) {

Reply via email to