From 2ff67083e5ae4fa58693d600a11946506096ad27 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Wed, 16 Oct 2024 10:54:32 +0200 Subject: [PATCH] radeonsi: refuse to import texture with family_overriden being set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the gfx version is overriden by the exporter process, the surface layout might not be compatible with the importer process (which uses the real gfx version). So fail early, except if the layout is LINEAR (because it should work on all gen) or a modifier is used (which should be rejected elsewhere if not supported). Reviewed-by: Marek Olšák Part-of: --- src/gallium/drivers/radeonsi/si_texture.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gallium/drivers/radeonsi/si_texture.c b/src/gallium/drivers/radeonsi/si_texture.c index 2dea0e680c3..3587c2b82ea 100644 --- a/src/gallium/drivers/radeonsi/si_texture.c +++ b/src/gallium/drivers/radeonsi/si_texture.c @@ -1691,6 +1691,7 @@ static struct pipe_resource *si_texture_from_winsys_buffer(struct si_screen *ssc { struct radeon_surf surface = {}; struct radeon_bo_metadata metadata = {}; + uint32_t md_version, md_flags; struct si_texture *tex; int r; @@ -1700,6 +1701,21 @@ static struct pipe_resource *si_texture_from_winsys_buffer(struct si_screen *ssc if (dedicated) { sscreen->ws->buffer_get_metadata(sscreen->ws, buf, &metadata, &surface); + + /* Refuse to import texture allocated with a overriden gfx family since + * the data will be garbage. + */ + md_version = metadata.metadata[0] & 0xffff; + md_flags = metadata.metadata[0] >> 16; + + if (metadata.mode != RADEON_SURF_MODE_LINEAR_ALIGNED && + modifier == DRM_FORMAT_MOD_INVALID && + md_version >= 3 && + md_flags & (1u << AC_SURF_METADATA_FLAG_FAMILY_OVERRIDEN_BIT)) { + fprintf(stderr, "si_texture_from_winsys_buffer: fail texture import due to " + "AC_SURF_METADATA_FLAG_FAMILY_OVERRIDEN_BIT being set.\n"); + return NULL; + } } else { /** * The bo metadata is unset for un-dedicated images. So we fall