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

Author: Icecream95 <[email protected]>
Date:   Thu May  5 13:06:28 2022 +1200

panfrost: Move patched_s out of the pan_blitter_views struct

The struct is returned from a function, so in debug builds the address
may change after returning, and pointers to patched_s will be broken.

Pass the pointer to the patched stencil view as a parameter to
pan_preload_get_views to avoid this.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16343>

---

 src/panfrost/lib/pan_blitter.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/panfrost/lib/pan_blitter.c b/src/panfrost/lib/pan_blitter.c
index 4eb761342ff..72261fd2c71 100644
--- a/src/panfrost/lib/pan_blitter.c
+++ b/src/panfrost/lib/pan_blitter.c
@@ -187,11 +187,6 @@ struct pan_blitter_views {
         const struct pan_image_view *dst_z;
         const struct pan_image_view *src_s;
         const struct pan_image_view *dst_s;
-
-        /* Image view used when patching stencil formats for combined
-         * depth/stencil preloads.
-         */
-        struct pan_image_view patched_s;
 };
 
 static bool
@@ -802,7 +797,7 @@ pan_blit_get_rsd(struct panfrost_device *dev,
 #endif
 
 static struct pan_blitter_views
-pan_preload_get_views(const struct pan_fb_info *fb, bool zs)
+pan_preload_get_views(const struct pan_fb_info *fb, bool zs, struct 
pan_image_view *patched_s)
 {
         struct pan_blitter_views views = { 0 };
 
@@ -821,9 +816,9 @@ pan_preload_get_views(const struct pan_fb_info *fb, bool zs)
                         }
 
                         if (fmt != view->format) {
-                                views.patched_s = *view;
-                                views.patched_s.format = fmt;
-                                views.src_s = views.dst_s = &views.patched_s;
+                                *patched_s = *view;
+                                patched_s->format = fmt;
+                                views.src_s = views.dst_s = patched_s;
                         } else {
                                 views.src_s = views.dst_s = view;
                         }
@@ -1086,7 +1081,13 @@ pan_preload_emit_dcd(struct pan_pool *pool,
          * for colour and Z/S), allowing us to suppress unnecessary writeback
          */
         UNUSED bool clean_fragment_write = !always_write;
-        struct pan_blitter_views views = pan_preload_get_views(fb, zs);
+
+        /* Image view used when patching stencil formats for combined
+         * depth/stencil preloads.
+         */
+        struct pan_image_view patched_s;
+
+        struct pan_blitter_views views = pan_preload_get_views(fb, zs, 
&patched_s);
 
 #if PAN_ARCH <= 7
         pan_pack(out, DRAW, cfg) {

Reply via email to