asahi,agx: Upload constant buffers immediately
authorJanne Grunau <j@jannau.net>
Sun, 30 Jul 2023 16:26:45 +0000 (18:26 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 11 Aug 2023 20:31:27 +0000 (20:31 +0000)
The lifetime of the constant buffer's user_buffer is not guaranteed
to last until agx_upload_uniforms.
Fixes the same ASAN issue mesa/mesa!21685 is trying to address.

Fixes: 080b05e29e1 ("asahi: Add Gallium driver")
Signed-off-by: Janne Grunau <j@jannau.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24635>

src/gallium/drivers/asahi/agx_state.c
src/gallium/drivers/asahi/agx_uniforms.c

index 15d39ab..62ca046 100644 (file)
@@ -39,6 +39,7 @@
 #include "util/u_prim.h"
 #include "util/u_resource.h"
 #include "util/u_transfer.h"
+#include "util/u_upload_mgr.h"
 #include "agx_device.h"
 #include "agx_disk_cache.h"
 #include "agx_tilebuffer.h"
@@ -1266,9 +1267,17 @@ agx_set_constant_buffer(struct pipe_context *pctx, enum pipe_shader_type shader,
 {
    struct agx_context *ctx = agx_context(pctx);
    struct agx_stage *s = &ctx->stage[shader];
+   struct pipe_constant_buffer *constants = &s->cb[index];
 
    util_copy_constant_buffer(&s->cb[index], cb, take_ownership);
 
+   /* Upload user buffer immediately */
+   if (constants->user_buffer && !constants->buffer) {
+      u_upload_data(ctx->base.const_uploader, 0, constants->buffer_size, 64,
+                    constants->user_buffer, &constants->buffer_offset,
+                    &constants->buffer);
+   }
+
    unsigned mask = (1 << index);
 
    if (cb)
index 4f6d02c..a9858ab 100644 (file)
@@ -15,9 +15,7 @@ agx_const_buffer_ptr(struct agx_batch *batch, struct pipe_constant_buffer *cb)
 
       return rsrc->bo->ptr.gpu + cb->buffer_offset;
    } else {
-      return agx_pool_upload_aligned(
-         &batch->pool, ((uint8_t *)cb->user_buffer) + cb->buffer_offset,
-         cb->buffer_size - cb->buffer_offset, 64);
+      return 0;
    }
 }