From 3b9e8afd13ca1564e62abcd96d9fb91d3c9e9352 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: (cherry picked from commit d6ee12a4d72eeeafea423ff385b79647693983cc) --- .pick_status.json | 2 +- src/gallium/drivers/asahi/agx_state.c | 9 +++++++++ src/gallium/drivers/asahi/agx_uniforms.c | 4 +--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index b700d9151a6..ebf52622793 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2110,7 +2110,7 @@ "description": "asahi,agx: Upload constant buffers immediately", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "080b05e29e1f04f22a776057631f4061cf7c1824" }, diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 203b0145a0e..38af6c39c41 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -35,6 +35,7 @@ #include "util/u_prim.h" #include "util/u_resource.h" #include "util/u_transfer.h" +#include "util/u_upload_mgr.h" #include "agx_disk_cache.h" static struct pipe_stream_output_target * @@ -1143,9 +1144,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 ad946fc144b..87486ca841b 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; } }