Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/asahi/vulkan/hk_g17p_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/asahi/vulkan/hk_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/asahi/vulkan/tests/test-hk-g17p-compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
4 changes: 3 additions & 1 deletion src/asahi/vulkan/tests/vulkan_storage_compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down