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: 080b05e29e ("asahi: Add Gallium driver")
Signed-off-by: Janne Grunau <j@jannau.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24635>
(cherry picked from commit d6ee12a4d7)
This commit is contained in:
Janne Grunau 2023-07-30 18:26:45 +02:00 committed by Eric Engestrom
parent bf2ec0fc51
commit 3b9e8afd13
3 changed files with 11 additions and 4 deletions

View file

@ -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"
},

View file

@ -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)

View 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;
}
}