From 3582830cf1cb86bc132381ad7584fc354aadea44 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Mon, 30 Nov 2026 12:19:38 -0500 Subject: [PATCH] borealis: leave M5 R16 storage images uncompressed by default The M5 storage-compression rule admits shader-written images by format class, one ASAHI_M5_STORAGE_COMPRESSION bit per class, and its default selected every class. Clear the bit of the R16 UNORM, SNORM, UINT and SINT class (bit 10) in the default, so these images stay plain. R16F and the other classes are unchanged, and the environment variable still selects any mask (32767 restores the old default). A single-channel 16-bit texel saves little bandwidth compressed, while each shader store merges into a compressed tile and each read decodes one. In Cyberpunk 2077 the screen-space reflection march point-samples a 640x400 R16_UNORM image, written by a compute shader, about a hundred times per pixel. The class was admitted together with mipmapped storage images, and the one measurement behind the two (SCP: Secret Laboratory on an M5 Pro) was taken with both at once. Signed-off-by: Erik Bourget --- src/asahi/vulkan/hk_g17p_compression.h | 17 +++++++++++++++++ src/asahi/vulkan/hk_image.c | 5 +++-- .../vulkan/tests/test-hk-g17p-compression.c | 10 ++++++++++ .../vulkan/tests/vulkan_storage_compression.c | 4 +++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/asahi/vulkan/hk_g17p_compression.h b/src/asahi/vulkan/hk_g17p_compression.h index 5016bcf12f78..813f0798d83a 100644 --- a/src/asahi/vulkan/hk_g17p_compression.h +++ b/src/asahi/vulkan/hk_g17p_compression.h @@ -662,6 +662,23 @@ hk_m5_msaa_color_compression_eligible(enum agx_chip chip, unsigned plane, !(info->usage & ~allowed_usage); } +/* ASAHI_M5_STORAGE_COMPRESSION bit of the R16 UNORM, SNORM, UINT and SINT + * storage images (hk_m5_storage_compression_eligible() in hk_image.c). + * + * It is clear in the default, so these images stay plain. A single-channel + * 16-bit texel saves little bandwidth compressed, while every shader store + * merges into a compressed tile and every read decodes one. Images of this + * class are typically small screen-space targets that a shader writes and + * a later pass samples many times per pixel (Cyberpunk 2077's screen-space + * reflection march point-samples a 640x400 R16_UNORM image about a hundred + * times per pixel), and sampling a compressed image of this class that + * heavily is slow on this GPU. R16F (bit 2) is a separate class and keeps + * compressing. */ +#define HK_M5_STORAGE_R16 (1u << 10) + +/* Every class ASAHI_M5_STORAGE_COMPRESSION selects (bits 0-14), less R16. */ +#define HK_M5_STORAGE_COMPRESSION_DEFAULT (0x7fffu & ~HK_M5_STORAGE_R16) + /* M5 lossless compression of depth attachments. * * The native HAL300 framebuffer setup sets ZLS control bits 2 and diff --git a/src/asahi/vulkan/hk_image.c b/src/asahi/vulkan/hk_image.c index b35bd0be34b8..6020c444cba7 100644 --- a/src/asahi/vulkan/hk_image.c +++ b/src/asahi/vulkan/hk_image.c @@ -553,7 +553,8 @@ hk_can_compress(const struct agx_device *dev, VkFormat format, unsigned plane, * device does not expose. Zero retains the uncompressed diagnostic control. B10G11R11 is not compressed whatever the bit says: a compressed * tile of its class reads a NaN field back as zero. */ DEBUG_GET_ONCE_NUM_OPTION(m5_storage_compression, - "ASAHI_M5_STORAGE_COMPRESSION", 32767) + "ASAHI_M5_STORAGE_COMPRESSION", + HK_M5_STORAGE_COMPRESSION_DEFAULT) static bool hk_m5_storage_compression_eligible(const struct agx_device *dev, unsigned plane, @@ -659,7 +660,7 @@ hk_m5_storage_compression_eligible(const struct agx_device *dev, unsigned plane, case VK_FORMAT_R16_UNORM: case VK_FORMAT_R16_SNORM: case VK_FORMAT_R16_UINT: - case VK_FORMAT_R16_SINT: bit = 1024; break; + case VK_FORMAT_R16_SINT: bit = HK_M5_STORAGE_R16; break; case VK_FORMAT_B8G8R8A8_UNORM: bit = 8192; break; case VK_FORMAT_R8G8_UNORM: case VK_FORMAT_R8G8_SNORM: diff --git a/src/asahi/vulkan/tests/test-hk-g17p-compression.c b/src/asahi/vulkan/tests/test-hk-g17p-compression.c index e405af4ce3ed..4840d1d3d503 100644 --- a/src/asahi/vulkan/tests/test-hk-g17p-compression.c +++ b/src/asahi/vulkan/tests/test-hk-g17p-compression.c @@ -1218,6 +1218,15 @@ check_g16g_hal200_compression(void) CHECK(!hk_g17p_shared_compression_eligible(AGX_CHIP_G16G, 0, &shared)); } +/* The default storage mask (ASAHI_M5_STORAGE_COMPRESSION unset) selects + * every class but R16. */ +static void +check_m5_storage_default(void) +{ + CHECK(!(HK_M5_STORAGE_COMPRESSION_DEFAULT & HK_M5_STORAGE_R16)); + CHECK((HK_M5_STORAGE_COMPRESSION_DEFAULT | HK_M5_STORAGE_R16) == 0x7fff); +} + int main(void) { @@ -1244,6 +1253,7 @@ main(void) check_m5_color(); check_m5_msaa_color(); check_m5_depth_msaa(); + check_m5_storage_default(); printf("HAL200/M5 compression policy: %u checks passed\n", checks); return 0; } diff --git a/src/asahi/vulkan/tests/vulkan_storage_compression.c b/src/asahi/vulkan/tests/vulkan_storage_compression.c index f576e7b49253..18144eb2aa41 100644 --- a/src/asahi/vulkan/tests/vulkan_storage_compression.c +++ b/src/asahi/vulkan/tests/vulkan_storage_compression.c @@ -23,7 +23,9 @@ * predicts every result bit. * * Run it with and without the driver compressing the images (M5: - * ASAHI_M5_STORAGE_COMPRESSION; AGX_MESA_DEBUG=perf shows which are). + * ASAHI_M5_STORAGE_COMPRESSION; AGX_MESA_DEBUG=perf shows which are). The + * default leaves the R16 class (r16, r16_snorm, r16ui, r16i) plain; run + * those with ASAHI_M5_STORAGE_COMPRESSION=32767 to test them compressed. * * The M4 Pro cannot compress storage images this way (2026-11-05): with the * M5 selection admitted on G17P, every compressed format failed all three