From a3e5445d4a4c7bfcf9d25e60fb0a915e3dc0af31 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 23 Nov 2022 21:34:22 -0500 Subject: [PATCH] agx: Don't depend sampler view on BO The BO can change when shadowing, fix up at drawtime. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/asahi/agx_state.c | 38 ++++++++++++++++++++------- src/gallium/drivers/asahi/agx_state.h | 4 +-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index df52b971d23..1fbb336f364 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -468,7 +468,8 @@ agx_translate_sample_count(unsigned samples) static void agx_pack_texture(void *out, struct agx_resource *rsrc, enum pipe_format format /* override */, - const struct pipe_sampler_view *state) + const struct pipe_sampler_view *state, + bool include_bo) { const struct util_format_description *desc = util_format_description(format); @@ -519,14 +520,20 @@ agx_pack_texture(void *out, struct agx_resource *rsrc, cfg.first_level = state->u.tex.first_level; cfg.last_level = state->u.tex.last_level; cfg.srgb = (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB); - cfg.address = agx_map_texture_gpu(rsrc, state->u.tex.first_layer); cfg.unk_mipmapped = rsrc->mipmapped; cfg.srgb_2_channel = cfg.srgb && util_format_colormask(desc) == 0x3; if (ail_is_compressed(&rsrc->layout)) { cfg.compressed_1 = true; cfg.compressed_2 = true; - cfg.acceleration_buffer = cfg.address + rsrc->layout.metadata_offset_B; + } + + if (include_bo) { + cfg.address = agx_map_texture_gpu(rsrc, state->u.tex.first_layer); + + if (ail_is_compressed(&rsrc->layout)) { + cfg.acceleration_buffer = cfg.address + rsrc->layout.metadata_offset_B; + } } if (state->target == PIPE_TEXTURE_3D) { @@ -575,10 +582,9 @@ agx_create_sampler_view(struct pipe_context *pctx, format = texture->format; } - agx_pack_texture(&so->desc, rsrc, format, state); - - /* Save off the BO that we actually use, with the stencil fixed up */ - so->bo = rsrc->bo; + /* Save off the resource that we actually use, with the stencil fixed up */ + so->rsrc = rsrc; + agx_pack_texture(&so->desc, rsrc, format, state, false); so->base = *state; so->base.texture = NULL; @@ -1359,7 +1365,21 @@ agx_build_pipeline(struct agx_batch *batch, struct agx_compiled_shader *cs, enum struct agx_sampler_view *tex = ctx->stage[stage].textures[i]; agx_batch_reads(batch, agx_resource(tex->base.texture)); - textures[i] = tex->desc; + /* Without the address */ + struct agx_texture_packed texture = tex->desc; + + /* Just the address */ + struct agx_texture_packed texture2; + agx_pack(&texture2, TEXTURE, cfg) { + cfg.address = agx_map_texture_gpu(tex->rsrc, tex->base.u.tex.first_layer); + + if (ail_is_compressed(&tex->rsrc->layout)) { + cfg.acceleration_buffer = cfg.address + tex->rsrc->layout.metadata_offset_B; + } + } + + agx_merge(texture, texture2, TEXTURE); + textures[i] = texture; } /* TODO: Dirty track me to save some CPU cycles and maybe improve caching */ @@ -1500,7 +1520,7 @@ agx_build_meta(struct agx_batch *batch, bool store, bool partial_render) .first_level = surf->u.tex.level, .last_level = surf->u.tex.level } - }); + }, true); agx_usc_pack(&b, TEXTURE, cfg) { cfg.start = rt; diff --git a/src/gallium/drivers/asahi/agx_state.h b/src/gallium/drivers/asahi/agx_state.h index ec88db411d4..83c6571d054 100644 --- a/src/gallium/drivers/asahi/agx_state.h +++ b/src/gallium/drivers/asahi/agx_state.h @@ -257,8 +257,8 @@ struct agx_sampler_state { struct agx_sampler_view { struct pipe_sampler_view base; - /* BO, may differ from base.texture's BO in case of separate stencil */ - struct agx_bo *bo; + /* Resource, may differ from base.texture in case of separate stencil */ + struct agx_resource *rsrc; /* Prepared descriptor */ struct agx_texture_packed desc;