Mesa (main): v3dv,v3d: don't store swizzle pointer in shader/pipeline keys

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Nov 10 11:50:41 UTC 2021


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

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Wed Nov 10 11:26:06 2021 +0100

v3dv,v3d: don't store swizzle pointer in shader/pipeline keys

We had been storing pointers to a driver owned swizzle table
rather than storing the actual swizzle value in various shader
and pipeline keys on both GL and Vulkan drivers.

This doesn't look very robust, particularly since we also
compute sha1 hashes from these values and we may store these
hashes to disk (for the disk cache).

Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13738>

---

 src/broadcom/compiler/v3d_compiler.h  |  2 +-
 src/broadcom/vulkan/v3dv_pipeline.c   | 10 ++++++----
 src/broadcom/vulkan/v3dv_private.h    |  2 +-
 src/gallium/drivers/v3d/v3d_program.c |  7 ++++---
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/broadcom/compiler/v3d_compiler.h b/src/broadcom/compiler/v3d_compiler.h
index 427b704071f..751e9d868b8 100644
--- a/src/broadcom/compiler/v3d_compiler.h
+++ b/src/broadcom/compiler/v3d_compiler.h
@@ -419,7 +419,7 @@ struct v3d_fs_key {
          */
         struct {
                 enum pipe_format format;
-                const uint8_t *swizzle;
+                uint8_t swizzle[4];
         } color_fmt[V3D_MAX_DRAW_BUFFERS];
 
         uint8_t logicop_func;
diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c
index daa6c75501b..9477087ae3a 100644
--- a/src/broadcom/vulkan/v3dv_pipeline.c
+++ b/src/broadcom/vulkan/v3dv_pipeline.c
@@ -1198,8 +1198,9 @@ pipeline_populate_v3d_fs_key(struct v3d_fs_key *key,
        */
       if (key->logicop_func != PIPE_LOGICOP_COPY) {
          key->color_fmt[i].format = fb_pipe_format;
-         key->color_fmt[i].swizzle =
-            v3dv_get_format_swizzle(p_stage->pipeline->device, fb_format);
+         memcpy(key->color_fmt[i].swizzle,
+                v3dv_get_format_swizzle(p_stage->pipeline->device, fb_format),
+                sizeof(key->color_fmt[i].swizzle));
       }
 
       const struct util_format_description *desc =
@@ -2039,8 +2040,9 @@ pipeline_populate_graphics_key(struct v3dv_pipeline *pipeline,
        */
       if (key->logicop_func != PIPE_LOGICOP_COPY) {
          key->color_fmt[i].format = fb_pipe_format;
-         key->color_fmt[i].swizzle = v3dv_get_format_swizzle(pipeline->device,
-                                                             fb_format);
+         memcpy(key->color_fmt[i].swizzle,
+                v3dv_get_format_swizzle(pipeline->device, fb_format),
+                sizeof(key->color_fmt[i].swizzle));
       }
 
       const struct util_format_description *desc =
diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h
index 2a0b8e48fa3..8fbb78eb739 100644
--- a/src/broadcom/vulkan/v3dv_private.h
+++ b/src/broadcom/vulkan/v3dv_private.h
@@ -274,7 +274,7 @@ struct v3dv_pipeline_key {
    uint8_t cbufs;
    struct {
       enum pipe_format format;
-      const uint8_t *swizzle;
+      uint8_t swizzle[4];
    } color_fmt[V3D_MAX_DRAW_BUFFERS];
    uint8_t f32_color_rb;
    uint32_t va_swap_rb_mask;
diff --git a/src/gallium/drivers/v3d/v3d_program.c b/src/gallium/drivers/v3d/v3d_program.c
index 3b2f9830b9b..1fbffbe2a22 100644
--- a/src/gallium/drivers/v3d/v3d_program.c
+++ b/src/gallium/drivers/v3d/v3d_program.c
@@ -576,9 +576,10 @@ v3d_update_compiled_fs(struct v3d_context *v3d, uint8_t prim_mode)
                  */
                 if (key->logicop_func != PIPE_LOGICOP_COPY) {
                         key->color_fmt[i].format = cbuf->format;
-                        key->color_fmt[i].swizzle =
-                                v3d_get_format_swizzle(&v3d->screen->devinfo,
-                                                       cbuf->format);
+                        memcpy(key->color_fmt[i].swizzle,
+                               v3d_get_format_swizzle(&v3d->screen->devinfo,
+                                                       cbuf->format),
+                               sizeof(key->color_fmt[i].swizzle));
                 }
 
                 const struct util_format_description *desc =



More information about the mesa-commit mailing list