diff --git a/src/asahi/layout/layout.h b/src/asahi/layout/layout.h index b94979cf98d..c0b148f8afc 100644 --- a/src/asahi/layout/layout.h +++ b/src/asahi/layout/layout.h @@ -412,6 +412,28 @@ ail_tile_mode_uncompressed(enum pipe_format format) return ail_tile_mode_replicated(ail_subtile_uncompressed_mode(format)); } +/* + * For compression, compatible formats must have the same number/size/order of + * channels, but may differ in data type. For example, R32_SINT is compatible + * with Z32_FLOAT, but not with R16G16_SINT. This is the relation given by the + * "channels" part of the decomposed format. + * + * This has not been exhaustively tested and might be missing some corner cases + * around XR formats, but is well-motivated and seems to work. + */ +static inline bool +ail_formats_compatible(enum pipe_format a, enum pipe_format b) +{ + return ail_pixel_format[a].channels == ail_pixel_format[b].channels; +} + +static inline bool +ail_is_view_compatible(struct ail_layout *layout, enum pipe_format view) +{ + return !ail_is_compressed(layout) || + ail_formats_compatible(layout->format, view); +} + #ifdef __cplusplus } /* extern C */ #endif diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 11d15009df1..552eac5e229 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -74,27 +74,9 @@ void agx_legalize_compression(struct agx_context *ctx, struct agx_resource *rsrc, enum pipe_format format) { - /* If the resource isn't compressed, we can reinterpret */ - if (rsrc->layout.tiling != AIL_TILING_TWIDDLED_COMPRESSED) - return; - - /* The physical format */ - enum pipe_format storage = rsrc->layout.format; - - /* If the formats are compatible, we don't have to decompress. Compatible - * formats have the same number/size/order of channels, but may differ in - * data type. For example, R32_SINT is compatible with Z32_FLOAT, but not - * with R16G16_SINT. This is the relation given by the "channels" part of the - * decomposed format. - * - * This has not been exhaustively tested and might be missing some corner - * cases around XR formats, but is well-motivated and seems to work. - */ - if (ail_pixel_format[storage].channels == ail_pixel_format[format].channels) - return; - - /* Otherwise, decompress. */ - agx_decompress(ctx, rsrc, "Incompatible formats"); + if (!ail_is_view_compatible(&rsrc->layout, format)) { + agx_decompress(ctx, rsrc, "Incompatible formats"); + } } static void