From d6ee12a4d72eeeafea423ff385b79647693983cc Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sun, 30 Jul 2023 18:26:45 +0200 Subject: [PATCH] asahi,agx: Upload constant buffers immediately 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 Part-of: --- src/gallium/drivers/asahi/agx_state.c | 9 +++++++++ src/gallium/drivers/asahi/agx_uniforms.c | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 15d39ab..62ca046 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -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) diff --git a/src/gallium/drivers/asahi/agx_uniforms.c b/src/gallium/drivers/asahi/agx_uniforms.c index 4f6d02c..a9858ab 100644 --- a/src/gallium/drivers/asahi/agx_uniforms.c +++ b/src/gallium/drivers/asahi/agx_uniforms.c @@ -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; } } -- 2.7.4