From 1b94686bb1021c953696ddd17af93dbe5472d310 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Wed, 25 Nov 2026 01:33:26 -0500 Subject: [PATCH 1/2] borealis: enable HAL200 lossless compression on G16G Select private colour and depth compression, shared compressed modifiers and compressed mip blits by the native HAL200 hardware capability. G16G uses the classic submission crossover and G17P keeps the dual-submission crossover. Use effective stencil usage for split depth/stencil layouts. Check shared modifier queries with the allocation policy, reject unusable modifier lists and validate compressed import strides. Probe supported image dimensions for host copy layout compatibility. Exercise capability selection, compressed layouts and image creation with separate stencil usage, modifier lists and explicit DMA-BUF layouts. Use a sampled-image layout for samplerless graphics resolves. The compressed source takes this path, and its push writes must match the pipeline layout even when blits use combined image samplers. Split a 2D-array VkCmdResolveImage into per-layer passes on native HAL200 whenever either image is compressed. The qualified BG/EOT contract is single-layer, and image copies and blits already split their 2D-array regions this way (hk_g17p_image_copy_slice, hk_g17p_image_blit_slice); the generic vk_meta resolve otherwise reaches the compressed array through a layered render pass whose per-layer metadata stride is derived by the hardware and is unreliable under concurrent GPU use. Gate 1-8B 2x/4x MSAA colour compression on a separate AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION capability, enabled only on G17P. The Gen9 PBE/texture/ZLS/AIL encodings are identical across G16G and G17P, and 1x colour (2D, arrays, cube, 3D), 16-byte single-sample 2D colour, and 1x/2x/4x depth (single-layer and arrays, both stencil planes) all pass the --jobs 4 full CTS on G16G at 0 failures. The 1-8B 2x/4x MSAA colour variants still hit intermittent PBE unmapped reads on a handful of diff_layout_copy_before_resolving cases on G16G (the qualified path on G17P), so the separate capability keeps those shapes plain on G16G while the HAL200 contract for every other shape ships. Follow-up on the MSAA colour side keyed on the same cap. Signed-off-by: Diljit Singh --- src/asahi/lib/agx_chip_caps.h | 31 ++- src/asahi/lib/tests/test-chip-caps.c | 40 ++- src/asahi/meson.build | 3 +- src/asahi/vulkan/hk_cmd_meta.c | 53 +++- src/asahi/vulkan/hk_format.c | 5 +- src/asahi/vulkan/hk_g17p_compression.h | 119 ++++---- src/asahi/vulkan/hk_g17p_meta_copy_core.c | 27 ++ src/asahi/vulkan/hk_g17p_meta_copy_core.h | 12 + src/asahi/vulkan/hk_image.c | 78 ++++-- .../hal200_vulkan_msaa_depth_compression.c | 4 +- .../tests/hk_vulkan_explicit_plane_layout.c | 9 +- .../tests/test-hk-compression-contract.c | 260 +++++++++++++++++- .../vulkan/tests/test-hk-g16s-compression.c | 13 +- .../vulkan/tests/test-hk-g17p-compression.c | 164 +++++++++-- .../vulkan/tests/test-hk-g17p-decompress.c | 76 ++++- .../vulkan/tests/test-hk-g17p-metadata-grid.c | 64 +++++ src/vulkan/runtime/vk_meta_blit_resolve.c | 29 +- 17 files changed, 847 insertions(+), 140 deletions(-) diff --git a/src/asahi/lib/agx_chip_caps.h b/src/asahi/lib/agx_chip_caps.h index 500604cec47b..f0197aab24a4 100644 --- a/src/asahi/lib/agx_chip_caps.h +++ b/src/asahi/lib/agx_chip_caps.h @@ -103,6 +103,28 @@ enum agx_chip_cap { * (libagx_agx3_decompress); measured on G17S. Off on G18G until measured * there. */ AGX_CAP_GEN10_2D_COMPRESSION = 1u << 14, + + /* HAL200/Gen9 lossless colour and depth/stencil compression in Borealis: + * single-sample 1-8B colour (2D, arrays, cubemaps, single-mip 3D), 16B + * colour (single-sample 2D, arrays, cubemaps), single-level 1x/2x/4x depth + * and 1x stencil, shared DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED colour + * images, in-place spill decompression via libagx_agx3_decompress, and Gen9 + * compressed compute mip blits. Enabled across native HAL200 AGX3B parts + * (G16G and G17P), which share the Gen9 PBE/texture/ZLS/AIL metadata + * contract; off on G15* (M3, G15/RTKit 2419 CS generation), M5 HAL300 + * (Gen10, gated separately), G18G, and AGX2. 2x/4x MSAA colour compression + * on these parts is gated separately by AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION + * so a measurement on one AGX3B part does not imply the other. */ + AGX_CAP_HAL200_LOSSLESS_COMPRESSION = 1u << 15, + + /* HAL200/Gen9 lossless 2x/4x MSAA colour compression in Borealis: 1-8B + * colour attachments (including arrays, input attachments, multiview, and + * MRT spills decompressed in place by libagx_agx3_decompress). Qualified on + * G17P (A18 Pro, M4 Pro, M4 Max) by the --jobs 4 full-case resolve_image + * run; off on G16G until its remaining diff_layout_copy_before_resolving + * variants are triaged and qualified. Off on every chip without + * AGX_CAP_HAL200_LOSSLESS_COMPRESSION. */ + AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION = 1u << 16, }; /* What the admitted AGX2 chips (G13G, G13X, G14G, G14X) share. */ @@ -121,7 +143,9 @@ enum agx_chip_cap { AGX_CAP_VDM_INDIRECT_INDEX_BOUNDS | \ AGX_CAP_TRI_MERGE_ACROSS_SIDE_EFFECTS | AGX_CAP_SPARSE_RESIDENCY_3D | \ AGX_CAP_COALESCE_PURE_GLOBAL_WORKGROUPS | AGX_CAP_CDM_WAR_WEAK_BARRIER | \ - AGX_CAP_GEN9_2D_COMPRESSION | AGX_CAP_MOD3_REG_BANK_RA) + AGX_CAP_GEN9_2D_COMPRESSION | AGX_CAP_MOD3_REG_BANK_RA | \ + AGX_CAP_HAL200_LOSSLESS_COMPRESSION | \ + AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION) /* What the M5 parts (G17G, G17S, G17C) share. */ #define AGX_CAPS_M5 \ @@ -148,7 +172,10 @@ enum agx_chip_cap { X(G15C, AGX_CAPS_NATIVE, __VA_ARGS__) \ X(G15D, AGX_CAP_COOPERATIVE_MATRIX, __VA_ARGS__) \ X(G16P, AGX_CAP_COOPERATIVE_MATRIX, __VA_ARGS__) \ - X(G16G, AGX_CAPS_NATIVE | AGX_CAP_NATIVE_PREAMBLE, __VA_ARGS__) \ + X(G16G, \ + AGX_CAPS_NATIVE | AGX_CAP_NATIVE_PREAMBLE | \ + AGX_CAP_HAL200_LOSSLESS_COMPRESSION, \ + __VA_ARGS__) \ X(G16S, AGX_CAP_COOPERATIVE_MATRIX, __VA_ARGS__) \ X(G16C, AGX_CAP_COOPERATIVE_MATRIX, __VA_ARGS__) \ X(G17P, AGX_CAPS_G17P, __VA_ARGS__) \ diff --git a/src/asahi/lib/tests/test-chip-caps.c b/src/asahi/lib/tests/test-chip-caps.c index 8e4e6a11b02b..b215a273fef7 100644 --- a/src/asahi/lib/tests/test-chip-caps.c +++ b/src/asahi/lib/tests/test-chip-caps.c @@ -46,7 +46,8 @@ static const unsigned all_caps = (0 CAPS(CAP_BIT)) | AGX_CAP_SPARSE_RESIDENCY_3D | AGX_CAP_DESCRIPTOR_BUFFER | AGX_CAP_COALESCE_PURE_GLOBAL_WORKGROUPS | AGX_CAP_CDM_WAR_WEAK_BARRIER | AGX_CAP_GEN9_2D_COMPRESSION | AGX_CAP_MOD3_REG_BANK_RA | - AGX_CAP_GEN10_2D_COMPRESSION; + AGX_CAP_GEN10_2D_COMPRESSION | AGX_CAP_HAL200_LOSSLESS_COMPRESSION | + AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION; #undef CAP_BIT /* Each chip of AGX_CHIPS has exactly one row, and the rows are in its @@ -160,6 +161,41 @@ test_gen10_2d_compression(void) } } +/* AGX_CAP_HAL200_LOSSLESS_COMPRESSION is enabled across native HAL200 AGX3B + * parts (G16G and G17P) and off on G15* (M3), M5 HAL300 (Gen10), G18G, AGX2, + * and unadmitted parts. */ +static void +test_hal200_lossless_compression(void) +{ + for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) { + const enum agx_chip c = (enum agx_chip)i; + const bool expected = c == AGX_CHIP_G16G || c == AGX_CHIP_G17P; + CHECK_CHIP(agx_chip_has_cap(c, AGX_CAP_HAL200_LOSSLESS_COMPRESSION) == + expected, + c); + CHECK_CHIP(agx_chip_has_cap(c, AGX_CAP_HAL200_LOSSLESS_COMPRESSION) == + agx_chip_native_hal200(c), + c); + } +} + +/* AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION is enabled only on G17P: G16G shares + * the HAL200 PBE/texture/ZLS contract but its 1-8B 2x/4x MSAA colour variants + * are not qualified yet. */ +static void +test_hal200_msaa_color_compression(void) +{ + for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) { + const enum agx_chip c = (enum agx_chip)i; + CHECK_CHIP(agx_chip_has_cap(c, AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION) == + (c == AGX_CHIP_G17P), + c); + /* MSAA colour never enables without the base HAL200 cap. */ + if (agx_chip_has_cap(c, AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION)) + CHECK_CHIP(agx_chip_has_cap(c, AGX_CAP_HAL200_LOSSLESS_COMPRESSION), c); + } +} + int main(void) { @@ -170,6 +206,8 @@ main(void) test_cdm_war_weak_barrier(); test_mod3_reg_bank_ra(); test_gen10_2d_compression(); + test_hal200_lossless_compression(); + test_hal200_msaa_color_compression(); if (failures) { fprintf(stderr, "agx_chip_caps: %u of %u checks failed\n", failures, diff --git a/src/asahi/meson.build b/src/asahi/meson.build index 1cb70cd47c71..fcc18abbab44 100644 --- a/src/asahi/meson.build +++ b/src/asahi/meson.build @@ -133,7 +133,8 @@ if with_tools.contains('drm-shim') and with_asahi_vk and with_tests files('../gallium/drivers/asahi/tests/run-shim.py'), libasahi_noop_drm_shim, hal200_vulkan_msaa_depth_compression, - ] + (chip == 'g17p' ? ['--expect-1x-compressed'] : []), + '--expect-1x-compressed', + ], env : [ 'ASAHI_SHIM_CHIP=' + chip, 'VK_DRIVER_FILES=' + _dev_icd.full_path(), diff --git a/src/asahi/vulkan/hk_cmd_meta.c b/src/asahi/vulkan/hk_cmd_meta.c index 44e4b19293fa..62c5e994ffee 100644 --- a/src/asahi/vulkan/hk_cmd_meta.c +++ b/src/asahi/vulkan/hk_cmd_meta.c @@ -2234,7 +2234,8 @@ hk_g17p_compressed_blit_supported(const struct hk_device *dev, const struct hk_image *dst, const VkBlitImageInfo2 *info) { - if (dev->dev.chip != AGX_CHIP_G17P || info->regionCount == 0 || + if (!agx_chip_has_cap(dev->dev.chip, AGX_CAP_HAL200_LOSSLESS_COMPRESSION) || + info->regionCount == 0 || !(src->planes[0].layout.compressed || dst->planes[0].layout.compressed)) return false; @@ -2259,7 +2260,7 @@ hk_g17p_compressed_blit_supported(const struct hk_device *dev, if (ail_is_level_logically_compressed(&dst->planes[0].layout, level) && ((uint32_t)region->dstOffsets[1].x != width || (uint32_t)region->dstOffsets[1].y != height || - hk_g17p_mip_level_through_pbe(width, height))) + hk_mip_level_through_pbe(dev->dev.chip, width, height))) return false; } return true; @@ -3482,7 +3483,53 @@ hk_xfer_resolveimage2(VkCommandBuffer commandBuffer, struct hk_meta_save save; hk_meta_begin(cmd, &save, VK_PIPELINE_BIND_POINT_GRAPHICS); - vk_meta_resolve_image2(&cmd->vk, &dev->meta, pResolveImageInfo); + /* HAL200 writes a compressed colour array one layer at a time: the + * qualified BG/EOT contract is single-layer, so a layered render through + * the generic resolve path reaches a compressed source array's + * per-layer metadata through hardware stride derivation that is not + * reliable at --jobs 4 concurrency. hk_CmdCopyImage and + * hk_CmdBlitImage split 2D-array regions into per-slice passes on the + * same contract; apply the same split here so the generic resolve runs + * one layer at a time whenever either image is a compressed 2D + * array. */ + if (agx_chip_native_agx3(dev->dev.chip) && + src_image->vk.image_type == VK_IMAGE_TYPE_2D && + dst_image->vk.image_type == VK_IMAGE_TYPE_2D && + (src_layout->compressed || dst_layout->compressed)) { + for (uint32_t r = 0; r < pResolveImageInfo->regionCount; ++r) { + const VkImageResolve2 *region = &pResolveImageInfo->pRegions[r]; + const uint32_t src_slices = + vk_image_subresource_layer_count(&src_image->vk, + ®ion->srcSubresource); + const uint32_t dst_slices = + vk_image_subresource_layer_count(&dst_image->vk, + ®ion->dstSubresource); + + for (uint32_t slice = 0; slice < src_slices; ++slice) { + VkImageResolve2 one; + if (!hk_g17p_image_resolve_slice( + dev->dev.chip, src_image->vk.image_type, + dst_image->vk.image_type, src_slices, dst_slices, + region, slice, &one)) { + vk_command_buffer_set_error(&cmd->vk, + VK_ERROR_FEATURE_NOT_PRESENT); + break; + } + + VkResolveImageInfo2 info = *pResolveImageInfo; + info.regionCount = 1; + info.pRegions = &one; + vk_meta_resolve_image2(&cmd->vk, &dev->meta, &info); + if (vk_command_buffer_has_error(&cmd->vk)) + break; + } + + if (vk_command_buffer_has_error(&cmd->vk)) + break; + } + } else { + vk_meta_resolve_image2(&cmd->vk, &dev->meta, pResolveImageInfo); + } hk_meta_end(cmd, &save, VK_PIPELINE_BIND_POINT_GRAPHICS); } diff --git a/src/asahi/vulkan/hk_format.c b/src/asahi/vulkan/hk_format.c index 9f109f62ce55..65b7b9cf5493 100644 --- a/src/asahi/vulkan/hk_format.c +++ b/src/asahi/vulkan/hk_format.c @@ -12,6 +12,7 @@ #include "hk_buffer_view.h" #include "hk_entrypoints.h" +#include "hk_g17p_compression.h" #include "hk_image.h" #include "hk_physical_device.h" @@ -46,9 +47,9 @@ hk_modifier_features(const struct agx_device *dev, uint64_t mod, if (!hk_can_compress_format(dev, vk_format)) return 0; - /* G17P and M5 share compressed images without storage or host-copy + /* HAL200 and M5 share compressed images without storage or host-copy * access (hk_g17p_shared_compression_shape()). */ - if (agx_chip_g17p_or_m5(dev->chip)) + if (hk_chip_shared_compression_supported(dev->chip)) return props->optimalTilingFeatures & ~(VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT | VK_FORMAT_FEATURE_2_STORAGE_IMAGE_ATOMIC_BIT | diff --git a/src/asahi/vulkan/hk_g17p_compression.h b/src/asahi/vulkan/hk_g17p_compression.h index aa9e1db153e3..cc76624202a2 100644 --- a/src/asahi/vulkan/hk_g17p_compression.h +++ b/src/asahi/vulkan/hk_g17p_compression.h @@ -12,24 +12,29 @@ #include #include -/* HAL200 lossless compression policy (G17P full policy, plus 2x/4x MSAA depth - * across native HAL200). +/* HAL200 lossless compression policy across native HAL200 AGX3B parts + * (AGX_CAP_HAL200_LOSSLESS_COMPRESSION: G16G and G17P). * * The compressed Gen9 PBE (write) packet matches Apple's HAL200 StateFields * encoder byte-for-byte for GPU-tiled one-layer 2D images, the read * descriptor carries the same compression bit and metadata address, and the - * G17P ZLS control word Apple's Framebuffer builds uses the same load/store + * HAL200 ZLS control word Apple's Framebuffer builds uses the same load/store * compression bits (2/4/6/8), 16-bit depth format bit and metadata stride * encoding as Mesa's agx_pack_zls_control. The shapes below are the ones - * whose every write path in hk goes through one of those three units or the - * libagx_fast_clear metadata kernel: + * whose every write path in Borealis goes through one of those three units or + * the libagx_fast_clear metadata kernel: * - * - Color: single-plane, 1-8 byte texels, 2D (single-layer or arrays), cube, - * 3D, and 2x/4x MSAA (including attachments, arrays, input attachments, and - * multiview), plus across G17P 16-byte texels + * - Color: single-plane, 1-8 byte texels, 2D (single-layer or arrays), cube + * and 3D single-sample, plus 16-byte texels * (R32G32B32A32_{UINT,SINT,SFLOAT}) for single-sample 2D (single-layer, - * arrays, and cubemaps). Any spilled compressed colour attachment is - * decompressed in-place before the render pass via libagx_agx3_decompress / + * arrays, and cubemaps). The 1-8 byte 2x/4x MSAA variants (attachments, + * arrays, input attachments, multiview) are gated separately by + * AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION (G17P): their Gen9 encodings are + * identical across G16G and G17P but the --jobs 4 full CTS still witnesses + * intermittent PBE unmapped reads under diff_layout_copy_before_resolving + * on G16G, so a measurement on one AGX3B part does not imply the other. + * Any spilled compressed colour attachment is decompressed in-place before + * the render pass via libagx_agx3_decompress / * libagx_reset_compression_metadata (with emrt_texture packed uncompressed * on HAL200). * - Not R11G11B10F: attachments store through the format's own class @@ -37,21 +42,19 @@ * field back as zero, however it was written. Rendering NaN into an * R11G11B10F attachment has to keep it, so they stay plain. * - Depth: D16_UNORM, D32_SFLOAT and both planes of D32_SFLOAT_S8_UINT, - * one level, one sample (single-layer or arrays) on G17P; across HAL200 - * (G16G and G17P) also the depth plane at 2x and 4x (one level, plane 0 - * only; single-layer on G16G, single-layer or arrays on G17P). Multisampled + * one level, one sample (single-layer or arrays), plus the depth plane at + * 2x and 4x (one level, plane 0 only, single-layer or arrays). Multisampled * depth goes through ZLS rather than the colour tilebuffer's background * reload program, so it is unaffected by * AGX_QUIRK_UNCOVERED_TILE_MS_DEFECT. The 2x/4x depth plane excludes * input-attachment use (its S8 plane stays plain); it admits the * feedback-loop usage and sample-location flag zink sets on every depth - * attachment, as single-sample depth does. The ZLS unit compresses the S8 stencil plane with the same - * metadata layout as depth (stencil - * load/store compression bits 4/8), it is read through its R8_UINT - * alias, and its clears are metadata fast clears. Zink stores GL Z24S8 - * as D32S8, so these planes carry every GL depth/stencil buffer's ZLS - * traffic; buffer uploads into them take the graphics copy (R32_UINT - * and R8_UINT PBEs). + * attachment, as single-sample depth does. The ZLS unit compresses the S8 + * stencil plane with the same metadata layout as depth (stencil load/store + * compression bits 4/8), it is read through its R8_UINT alias, and its + * clears are metadata fast clears. Zink stores GL Z24S8 as D32S8, so these + * planes carry every GL depth/stencil buffer's ZLS traffic; buffer uploads + * into them take the graphics copy (R32_UINT and R8_UINT PBEs). * * Images that may be shared with another process or device (external * memory, WSI, DRM modifiers) stay plain under this private policy. Colour @@ -178,7 +181,7 @@ static inline bool hk_hal200_compression_eligible(enum agx_chip chip, uint32_t chip_id, unsigned plane, const VkImageCreateInfo *info) { - if (!agx_chip_native_hal200(chip) || !info || + if (!agx_chip_has_cap(chip, AGX_CAP_HAL200_LOSSLESS_COMPRESSION) || !info || (plane != 0 && !(plane == 1 && info->format == VK_FORMAT_D32_SFLOAT_S8_UINT))) return false; @@ -186,19 +189,18 @@ hk_hal200_compression_eligible(enum agx_chip chip, uint32_t chip_id, /* Keep depth/stencil off the extended colour shapes: their mip chains and * standalone S8 reach colour-alias transfer paths that refuse them, which * makes legal commands fail at EndCommandBuffer. Single-level depth arrays - * are admitted below. Colour's layered/MSAA packet support is independent - * of this restriction. + * are admitted below. Colour's layered packet support is independent of + * this restriction; 2x/4x MSAA colour is gated by + * AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION further below. * - * All G17P SoCs share the Gen9 PBE, ZLS and texture encodings for layered, - * cube and 3D colour, 2x/4x MSAA colour (including attachments, arrays, - * input attachments, and multiview), and single-level depth arrays. Any - * spilled compressed colour target (including 2x/4x MSAA targets spilled by + * All native HAL200 AGX3B parts (G16G, G17P) share the Gen9 PBE, ZLS, + * texture, and AIL compression metadata encodings for layered, cube, and 3D + * colour, 16-byte single-sample 2D/array/cube colour, and single-level + * 1x/2x/4x depth (single-layer and arrays). Any spilled compressed colour + * target (including 2x/4x MSAA targets spilled by * AGX_QUIRK_UNCOVERED_TILE_MS_DEFECT or MRT/multiview tilebuffer pressure) * is decompressed in-place before the render pass by * libagx_agx3_decompress / libagx_reset_compression_metadata. */ - /* 16-byte colour (single-sample 2D, arrays, and cubemaps): all G17P SoCs - * share the same HAL200/Gen9 PBE, texture, compression metadata encoding, - * and libagx_agx3_decompress spill path. */ (void)chip_id; const bool color_16b = hk_g17p_compression_color_format_16b(info->format); /* Not B10G11R11_UFLOAT: a compressed tile of its class reads NaN back as @@ -283,19 +285,14 @@ hk_hal200_compression_eligible(enum agx_chip chip, uint32_t chip_id, (info->samples == VK_SAMPLE_COUNT_2_BIT || info->samples == VK_SAMPLE_COUNT_4_BIT) && depth && !(info->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT); - /* Non-G17P HAL200 parts (G16G) only take 2x/4x MSAA depth here; - * single-sample depth stays plain until verified separately on G16G. */ - if (chip != AGX_CHIP_G17P && !depth_ms) - return false; - /* Single-level depth arrays across G17P (single-sample both planes, and - * 2x/4x MSAA plane 0). Every access to one layer addresses its metadata - * at compression_layer_stride_B: ZLS (with the metadata layer stride for - * layered rendering), the metadata fast clear, the texture and PBE - * descriptors. The graphics copies, uploads and blits split into - * single-layer passes (hk_cmd_meta.c). */ + /* Single-level depth arrays across native HAL200 (single-sample both + * planes, and 2x/4x MSAA plane 0). Every access to one layer addresses + * its metadata at compression_layer_stride_B: ZLS (with the metadata + * layer stride for layered rendering), the metadata fast clear, the + * texture and PBE descriptors. The graphics copies, uploads and blits + * split into single-layer passes (hk_cmd_meta.c). */ const bool depth_array = - (info->samples == VK_SAMPLE_COUNT_1_BIT || - (chip == AGX_CHIP_G17P && depth_ms)) && + (info->samples == VK_SAMPLE_COUNT_1_BIT || depth_ms) && info->mipLevels == 1 && depth; if (info->imageType != VK_IMAGE_TYPE_2D || info->extent.depth != 1 || !info->arrayLayers || (info->arrayLayers != 1 && !depth_array) || @@ -308,11 +305,6 @@ hk_hal200_compression_eligible(enum agx_chip chip, uint32_t chip_id, return depth && info->mipLevels == 1; } - /* Non-G17P HAL200 parts (G16G) keep colour plain here; G16G single-sample - * colour compression is gated separately (#638). */ - if (chip != AGX_CHIP_G17P) - return false; - /* 16-byte texels stay on single-sample 2D shapes (single-layer, arrays, * and cubemaps): 3D targets cannot use libagx_agx3_decompress on 8-MRT * spill, and multisampled 16-byte targets exceed the uncovered-tile MSAA @@ -320,6 +312,14 @@ hk_hal200_compression_eligible(enum agx_chip chip, uint32_t chip_id, if (color_16b && (three_d || multisampled)) return false; + /* 1-8B 2x/4x MSAA colour is gated by AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION + * (G17P), separately from the 1x and depth shapes above: the --jobs 4 full + * CTS witnesses intermittent diff_layout_copy_before_resolving PBE unmapped + * reads on G16G which stay unresolved pending triage. */ + if (color && multisampled && + !agx_chip_has_cap(chip, AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION)) + return false; + if ((info->imageType != VK_IMAGE_TYPE_2D && !three_d) || !info->extent.depth || !info->arrayLayers || (three_d ? (info->arrayLayers != 1 || multisampled) @@ -363,14 +363,15 @@ hk_hal200_compression_eligible(enum agx_chip chip, uint32_t chip_id, if (!(info->usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) && - !hk_g17p_mip_level_through_pbe(info->extent.width, - info->extent.height)) + !hk_mip_level_through_pbe(chip, info->extent.width, + info->extent.height)) return false; return true; } -/* G17P compression policy without a specific chip id: admits all architectural - * G17P shapes uniformly across A18 Pro, M4 Pro, and M4 Max. */ +/* HAL200 compression policy without a specific chip id: admits all + * architectural HAL200 shapes uniformly across G16G and G17P (M4, A18 Pro, + * M4 Pro, and M4 Max). */ static inline bool hk_g17p_compression_eligible(enum agx_chip chip, unsigned plane, const VkImageCreateInfo *info) @@ -378,11 +379,21 @@ hk_g17p_compression_eligible(enum agx_chip chip, unsigned plane, return hk_hal200_compression_eligible(chip, 0, plane, info); } -/* G17P and M5 colour images shared through +/* Whether an AGX3 chip shares single-level colour images compressed through + * DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED (native HAL200 via + * AGX_CAP_HAL200_LOSSLESS_COMPRESSION, or M5 HAL300). */ +static inline bool +hk_chip_shared_compression_supported(enum agx_chip chip) +{ + return agx_chip_has_cap(chip, AGX_CAP_HAL200_LOSSLESS_COMPRESSION) || + agx_chip_g17_m5(chip); +} + +/* HAL200 and M5 colour images shared through * DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED. * * The modifier is the sharing contract. With one level, one layer and one - * sample, the G17P (legacy AIL policy) compressed allocation is a function of + * sample, the HAL200 (legacy AIL policy) compressed allocation is a function of * the format's block size and the extent alone: GPU tiling, the image, then * its metadata, in one memory plane. The M5 allocation (AIL_LAYOUT_POLICY_M5 * and its metadata, one memory plane) is too. Exporter and importer therefore derive @@ -418,7 +429,7 @@ hk_g17p_shared_compression_shape(enum agx_chip chip, VkFormat format, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | VK_IMAGE_USAGE_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT; - return agx_chip_g17p_or_m5(chip) && + return hk_chip_shared_compression_supported(chip) && type == VK_IMAGE_TYPE_2D && !(flags & ~allowed_flags) && !(usage & ~allowed_usage) && hk_g17p_compression_color_format(format); diff --git a/src/asahi/vulkan/hk_g17p_meta_copy_core.c b/src/asahi/vulkan/hk_g17p_meta_copy_core.c index 56fed8fdb638..600a595d5180 100644 --- a/src/asahi/vulkan/hk_g17p_meta_copy_core.c +++ b/src/asahi/vulkan/hk_g17p_meta_copy_core.c @@ -705,6 +705,33 @@ hk_g17p_image_blit_slice(enum agx_chip chip, VkImageType src_type, return true; } +bool +hk_g17p_image_resolve_slice(enum agx_chip chip, VkImageType src_type, + VkImageType dst_type, uint32_t src_layers, + uint32_t dst_layers, + const VkImageResolve2 *region, uint32_t slice, + VkImageResolve2 *out) +{ + if (out) + *out = (VkImageResolve2){0}; + + if (!agx_chip_native_agx3(chip) || !region || !out || + src_type != VK_IMAGE_TYPE_2D || dst_type != VK_IMAGE_TYPE_2D || + src_layers == 0 || src_layers != dst_layers || slice >= src_layers || + region->srcOffset.z != 0 || region->dstOffset.z != 0 || + region->extent.depth != 1 || + slice > UINT32_MAX - region->srcSubresource.baseArrayLayer || + slice > UINT32_MAX - region->dstSubresource.baseArrayLayer) + return false; + + *out = *region; + out->srcSubresource.baseArrayLayer += slice; + out->srcSubresource.layerCount = 1; + out->dstSubresource.baseArrayLayer += slice; + out->dstSubresource.layerCount = 1; + return true; +} + bool hk_g17p_metadata_grid_init(uint32_t width_tl, uint32_t height_tl, struct hk_g17p_metadata_grid *grid) diff --git a/src/asahi/vulkan/hk_g17p_meta_copy_core.h b/src/asahi/vulkan/hk_g17p_meta_copy_core.h index 474067cf3ec1..17b1ddf0e9a9 100644 --- a/src/asahi/vulkan/hk_g17p_meta_copy_core.h +++ b/src/asahi/vulkan/hk_g17p_meta_copy_core.h @@ -207,6 +207,18 @@ bool hk_g17p_image_blit_slice(enum agx_chip chip, VkImageType src_type, const VkImageBlit2 *region, uint32_t slice, VkImageBlit2 *out); +/* Convert one 2D array slice of a valid resolve region into a single-layer + * region. HAL200 writes compressed arrays one layer at a time (the BG/EOT + * contract is single-layer), and the generic vk_meta_resolve_image path + * otherwise reaches a compressed array through a layered render pass. The + * resolved source/destination layer counts must match, and the layer count + * must be at least one. */ +bool hk_g17p_image_resolve_slice(enum agx_chip chip, VkImageType src_type, + VkImageType dst_type, uint32_t src_layers, + uint32_t dst_layers, + const VkImageResolve2 *region, uint32_t slice, + VkImageResolve2 *out); + /* One destination coordinate's exact G17P linear-filter footprint. The low * half is the lower source coordinate and bits 16..23 are the Q8 upper-texel * weight. A carried weight of 256 is normalized to the following source diff --git a/src/asahi/vulkan/hk_image.c b/src/asahi/vulkan/hk_image.c index 1c56f907304f..2523eec820ff 100644 --- a/src/asahi/vulkan/hk_image.c +++ b/src/asahi/vulkan/hk_image.c @@ -558,8 +558,8 @@ hk_m5_storage_compression_eligible(const struct agx_device *dev, unsigned plane, ext->sType == VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO && !ext->pNext; - /* G17P storage images stay uncompressed: a shader image store through - * the G17P PBE does not merge into a compressed block or update its + /* HAL200/Gen9 storage images stay uncompressed: a shader image store through + * the Gen9 PBE does not merge into a compressed block or update its * metadata. It writes the block as the block's existing metadata says, * so the image decodes wrong whatever that metadata is: * - tiles a render pass or fast clear left compressed: with this rule @@ -575,7 +575,7 @@ hk_m5_storage_compression_eligible(const struct agx_device *dev, unsigned plane, * correct once any other writer compresses its tiles. The storage PBE * descriptor is byte-identical to the end-of-tile one, so there is no * descriptor bit to fix this with. */ - if (dev->chip == AGX_CHIP_G17P) + if (agx_chip_has_cap(dev->chip, AGX_CAP_HAL200_LOSSLESS_COMPRESSION)) return false; if (!hk_chip_supports_compressed_storage_pbe(dev->chip) || plane || @@ -958,17 +958,30 @@ hk_GetPhysicalDeviceImageFormatProperties2( return VK_ERROR_FORMAT_NOT_SUPPORTED; const bool g17p_compressed = - agx_chip_g17p_or_m5(pdev->dev.chip) && + hk_chip_shared_compression_supported(pdev->dev.chip) && pImageFormatInfo->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT && drm_mod_info && drm_mod_info->drmFormatModifier == DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED; - if (g17p_compressed && - !hk_g17p_shared_compression_supported( - &pdev->dev, pImageFormatInfo->format, pImageFormatInfo->type, - pImageFormatInfo->flags, pImageFormatInfo->usage, - pImageFormatInfo->pNext)) - return VK_ERROR_FORMAT_NOT_SUPPORTED; + if (g17p_compressed) { + /* Modifier queries have no extent. Use an eligible extent and the + * same creation policy as modifier-list selection. */ + const VkImageCreateInfo probe = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, + .pNext = pImageFormatInfo->pNext, + .flags = pImageFormatInfo->flags, + .imageType = pImageFormatInfo->type, + .format = pImageFormatInfo->format, + .extent = {16, 16, 1}, + .mipLevels = 1, + .arrayLayers = 1, + .samples = VK_SAMPLE_COUNT_1_BIT, + .tiling = pImageFormatInfo->tiling, + .usage = pImageFormatInfo->usage, + }; + if (!hk_can_compress_create_info(&pdev->dev, 0, &probe, false, false)) + return VK_ERROR_FORMAT_NOT_SUPPORTED; + } const uint32_t max_dim = pImageFormatInfo->type == VK_IMAGE_TYPE_3D ? pdev->vk.properties.maxImageDimension3D @@ -1188,8 +1201,8 @@ hk_GetPhysicalDeviceImageFormatProperties2( * shape that permits compression: if any such image can compress, * host-transfer images cannot promise the same layout. Probe every * supported sample count, since a policy may compress only the - * multisampled images of a format (G16G compresses 2x/4x depth but - * not single-sample depth). + * multisampled images of a format. Use the largest supported width + * and height to reach size-dependent compression crossovers. */ const VkExternalMemoryImageCreateInfo external_create_info = { .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, @@ -1202,12 +1215,16 @@ hk_GetPhysicalDeviceImageFormatProperties2( .flags = pImageFormatInfo->flags, .imageType = pImageFormatInfo->type, .format = pImageFormatInfo->format, - .extent = {64, 64, 1}, + .extent = {maxExtent.width, maxExtent.height, 1}, .mipLevels = 1, - .arrayLayers = pdev->dev.chip == AGX_CHIP_G17P && - (pImageFormatInfo->flags & - VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) - ? 6 : 1, + .arrayLayers = + (agx_chip_has_cap(pdev->dev.chip, + AGX_CAP_HAL200_LOSSLESS_COMPRESSION) || + agx_chip_g17_m5(pdev->dev.chip)) && + (pImageFormatInfo->flags & + VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) + ? 6 + : 1, .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = pImageFormatInfo->tiling, .usage = (pImageFormatInfo->usage & @@ -1325,9 +1342,9 @@ hk_can_compress_create_info(const struct agx_device *dev, unsigned plane, const VkImageCreateInfo *info, bool float_image_atomics, bool srgb_pair_views) { - /* AGX3: HAL200 (G17P and, for 2x/4x MSAA depth, G16G) and M5 compress every - * image hk_g17p_compression.h admits. Other AGX3 chips stay plain until - * their packets are recovered. */ + /* AGX3: native HAL200 (AGX_CAP_HAL200_LOSSLESS_COMPRESSION: G16G, G17P) + * and M5 compress every image hk_g17p_compression.h admits. Other AGX3 + * chips stay plain until their packets are recovered. */ const bool m5_storage = hk_m5_storage_compression_eligible(dev, plane, info, float_image_atomics); bool allow_agx3 = @@ -1531,7 +1548,9 @@ hk_image_init(struct hk_device *dev, struct hk_image *image, } - assert(modifier != DRM_FORMAT_MOD_INVALID); + if (modifier == DRM_FORMAT_MOD_INVALID) + return vk_errorf(dev, VK_ERROR_UNKNOWN, + "no compatible DRM format modifier for image"); assert(image->vk.drm_format_mod == DRM_FORMAT_MOD_INVALID); image->vk.drm_format_mod = modifier; } @@ -1562,10 +1581,10 @@ hk_image_init(struct hk_device *dev, struct hk_image *image, mod_explicit_info->pPlaneLayouts[0].rowPitch, pitch_B); } - /* G17P and M5 share compressed colour images only in the shape both sides + /* HAL200 and M5 share compressed colour images only in the shape both sides * allocate identically (hk_g17p_shared_compression_eligible()). */ if (image->vk.drm_format_mod == DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED && - agx_chip_g17p_or_m5(dev->dev.chip) && + hk_chip_shared_compression_supported(dev->dev.chip) && !(hk_g17p_shared_compression_supported( &dev->dev, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->flags, pCreateInfo->usage, pCreateInfo->pNext) && @@ -1609,8 +1628,12 @@ hk_image_init(struct hk_device *dev, struct hk_image *image, } } + VkImageCreateInfo plane_info = *pCreateInfo; + if (plane == 1 && hk_split_depth_stencil(image->vk.format)) + plane_info.usage = image->vk.stencil_usage; + bool compressed = - hk_map_compression(dev, pCreateInfo, plane, image->vk.drm_format_mod); + hk_map_compression(dev, &plane_info, plane, image->vk.drm_format_mod); image->planes[plane].layout = (struct ail_layout){ .policy = ail_layout_policy_for_descriptor_generation( @@ -1640,6 +1663,13 @@ hk_image_init(struct hk_device *dev, struct hk_image *image, uint64_t plane_end_B; if (mod_explicit_info) { + if (image->vk.drm_format_mod == DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED && + mod_explicit_info->pPlaneLayouts[plane].rowPitch != + ail_get_wsi_stride_B(&image->planes[plane].layout, 0)) + return vk_errorf(dev, VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT, + "invalid compressed DRM plane %u row pitch 0x%" PRIx64, + plane, mod_explicit_info->pPlaneLayouts[plane].rowPitch); + const uint64_t plane_offset_B = mod_explicit_info->pPlaneLayouts[plane].offset; if (!hk_image_explicit_plane_range(plane_offset_B, diff --git a/src/asahi/vulkan/tests/hal200_vulkan_msaa_depth_compression.c b/src/asahi/vulkan/tests/hal200_vulkan_msaa_depth_compression.c index edf8700b2178..e595adc15455 100644 --- a/src/asahi/vulkan/tests/hal200_vulkan_msaa_depth_compression.c +++ b/src/asahi/vulkan/tests/hal200_vulkan_msaa_depth_compression.c @@ -13,8 +13,8 @@ * HAL200 part and checks that baseline. * * usage: hal200-vulkan-msaa-depth-compression [--expect-1x-compressed] - * --expect-1x-compressed single-sample depth compresses too (G17P); without - * it, single-sample depth must stay plain (G16G) + * --expect-1x-compressed single-sample depth compresses too (G16G, G17P); without + * it, single-sample depth must stay plain */ #include #include diff --git a/src/asahi/vulkan/tests/hk_vulkan_explicit_plane_layout.c b/src/asahi/vulkan/tests/hk_vulkan_explicit_plane_layout.c index 23d17403a6f0..4347e3548c8b 100644 --- a/src/asahi/vulkan/tests/hk_vulkan_explicit_plane_layout.c +++ b/src/asahi/vulkan/tests/hk_vulkan_explicit_plane_layout.c @@ -121,9 +121,14 @@ create_modifier_image(uint64_t modifier, VkFormat format, uint32_t w, .drmFormatModifierPlaneCount = planes, .pPlaneLayouts = layouts, }; + const VkImageDrmFormatModifierListCreateInfoEXT list_info = { + .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT, + .drmFormatModifierCount = 1, + .pDrmFormatModifiers = &modifier, + }; const VkImageCreateInfo info = { .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, - .pNext = &explicit_info, + .pNext = layouts ? (const void *)&explicit_info : (const void *)&list_info, .flags = flags, .imageType = VK_IMAGE_TYPE_2D, .format = format, @@ -420,7 +425,7 @@ check_tiled_modifiers(void) VkSubresourceLayout layout = {0}; VkImage image0, image1; CHECK(create_modifier_image(mods[m].modifier, format, 256, 256, 0, - usage, 1, &layout, &image0)); + usage, 0, NULL, &image0)); layout.rowPitch = subresource_layout(image0, VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT) .rowPitch; diff --git a/src/asahi/vulkan/tests/test-hk-compression-contract.c b/src/asahi/vulkan/tests/test-hk-compression-contract.c index a6f277ae802c..08eac82168c8 100644 --- a/src/asahi/vulkan/tests/test-hk-compression-contract.c +++ b/src/asahi/vulkan/tests/test-hk-compression-contract.c @@ -8,7 +8,11 @@ #include "asahi/lib/agx_chip_caps.h" #include "drm-uapi/drm_fourcc.h" +#include "hk_device.h" #include "hk_entrypoints.h" +#include "hk_instance.h" +#include "vk_alloc.h" +#include "hk_g17p_compression.h" #include "hk_image.h" #include "hk_physical_device.h" @@ -197,6 +201,225 @@ query_feedback_disables_color_compression(struct hk_physical_device *pdev) feedback_hic.identicalMemoryLayout; } +static bool +query_hic_detects_compression(struct hk_physical_device *pdev, VkFormat format, + VkImageCreateFlags flags, + VkImageUsageFlags usage) +{ + VkPhysicalDevice handle = hk_physical_device_to_handle(pdev); + VkHostImageCopyDevicePerformanceQueryEXT hic = { + .sType = VK_STRUCTURE_TYPE_HOST_IMAGE_COPY_DEVICE_PERFORMANCE_QUERY_EXT, + }; + VkImageFormatProperties2 props = { + .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, + .pNext = &hic, + }; + VkPhysicalDeviceImageFormatInfo2 info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, + .flags = flags, + .format = format, + .type = VK_IMAGE_TYPE_2D, + .tiling = VK_IMAGE_TILING_OPTIMAL, + .usage = usage | VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT, + }; + assert(hk_GetPhysicalDeviceImageFormatProperties2(handle, &info, &props) == + VK_SUCCESS); + assert(hic.identicalMemoryLayout == hic.optimalDeviceAccess); + return !hic.identicalMemoryLayout; +} + +static bool +format_list_has_modifier(struct hk_physical_device *pdev, VkFormat format, + uint64_t modifier, + VkFormatFeatureFlags2 *features_out) +{ + VkPhysicalDevice handle = hk_physical_device_to_handle(pdev); + VkDrmFormatModifierProperties2EXT mods[8]; + VkDrmFormatModifierPropertiesList2EXT list = { + .sType = VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_2_EXT, + .drmFormatModifierCount = ARRAY_SIZE(mods), + .pDrmFormatModifierProperties = mods, + }; + VkFormatProperties2 props = { + .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, + .pNext = &list, + }; + hk_GetPhysicalDeviceFormatProperties2(handle, format, &props); + for (uint32_t i = 0; i < list.drmFormatModifierCount; ++i) { + if (mods[i].drmFormatModifier == modifier) { + if (features_out) + *features_out = mods[i].drmFormatModifierTilingFeatures; + return true; + } + } + return false; +} + +static void +check_hal200_format_and_modifier_contracts(struct hk_physical_device *pdev) +{ + const enum agx_chip chip = pdev->dev.chip; + const bool nocompress = (pdev->dev.debug & AGX_DBG_NOCOMPRESS) != 0; + const bool hal200 = + !nocompress && + agx_chip_has_cap(chip, AGX_CAP_HAL200_LOSSLESS_COMPRESSION); + const bool m5 = !nocompress && agx_chip_g17_m5(chip); + const VkImageUsageFlags color_rt = + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + const VkImageUsageFlags depth_rt = + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + + /* 16-byte rgba32f colour compresses on native HAL200 (G16G and G17P) and + * on single-layer 2D M5 (hk_m5_color_compression_eligible); its cube form + * compresses on HAL200 alone (M5 rejects 16B cube-compat). 1-8B + * cube-compatible colour compresses on HAL200 and M5. All three stay plain + * on G15*, G18G, AGX2 and unadmitted parts. */ + assert(query_hic_detects_compression(pdev, VK_FORMAT_R32G32B32A32_SFLOAT, 0, + color_rt) == (hal200 || m5)); + assert(query_hic_detects_compression( + pdev, VK_FORMAT_R32G32B32A32_SFLOAT, + VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, color_rt) == hal200); + assert(query_hic_detects_compression( + pdev, VK_FORMAT_R8G8B8A8_UNORM, + VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, color_rt) == + (hal200 || m5)); + + assert(query_hic_detects_compression(pdev, VK_FORMAT_R8G8B8A8_UNORM, 0, + VK_IMAGE_USAGE_SAMPLED_BIT) == + (hal200 || m5)); + + /* Single-sample depth (d32f, d32s8) compresses across HAL200 and M5. */ + assert(query_hic_detects_compression(pdev, VK_FORMAT_D32_SFLOAT, 0, + depth_rt) == (hal200 || m5)); + assert(query_hic_detects_compression(pdev, VK_FORMAT_D32_SFLOAT_S8_UINT, 0, + depth_rt) == (hal200 || m5)); + + /* DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED advertisement and feature + * stripping (no storage/host-transfer) follow + * hk_chip_shared_compression_supported() across HAL200 (G16G/G17P) and M5. */ + const bool want_shared = + !nocompress && hk_chip_shared_compression_supported(chip); + VkFormatFeatureFlags2 feats = 0; + assert(format_list_has_modifier(pdev, VK_FORMAT_R8G8B8A8_UNORM, + DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED, + &feats) == want_shared); + if (want_shared) { + assert(feats & VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT); + assert(feats & VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT); + assert(!(feats & (VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT | + VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT))); + } + assert(!format_list_has_modifier(pdev, VK_FORMAT_R32G32B32A32_SFLOAT, + DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED, + NULL)); +} + +static void +check_image_creation(struct hk_physical_device *pdev) +{ + struct hk_device *dev = calloc(1, sizeof(*dev)); + struct hk_instance instance = {0}; + assert(dev); + vk_object_base_init(NULL, &instance.vk.base, VK_OBJECT_TYPE_INSTANCE); + instance.vk.base.client_visible = true; + list_inithead(&instance.vk.debug_utils.callbacks); + list_inithead(&instance.vk.debug_report.callbacks); + pdev->vk.instance = &instance.vk; + dev->vk.physical = &pdev->vk; + dev->vk.alloc = *vk_default_allocator(); + dev->dev.chip = pdev->dev.chip; + vk_object_base_init(&dev->vk, &dev->vk.base, VK_OBJECT_TYPE_DEVICE); + VkDevice device = hk_device_to_handle(dev); + + VkImageStencilUsageCreateInfo stencil = { + .sType = VK_STRUCTURE_TYPE_IMAGE_STENCIL_USAGE_CREATE_INFO, + .stencilUsage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | + VK_IMAGE_USAGE_HOST_TRANSFER_BIT, + }; + VkImageCreateInfo info = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, + .pNext = &stencil, + .imageType = VK_IMAGE_TYPE_2D, + .format = VK_FORMAT_D32_SFLOAT_S8_UINT, + .extent = {64, 64, 1}, + .mipLevels = 1, + .arrayLayers = 1, + .samples = VK_SAMPLE_COUNT_1_BIT, + .tiling = VK_IMAGE_TILING_OPTIMAL, + .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, + }; + VkImage image; + assert(hk_CreateImage(device, &info, NULL, &image) == VK_SUCCESS); + assert(hk_image_from_handle(image)->planes[0].layout.compressed); + assert(!hk_image_from_handle(image)->planes[1].layout.compressed); + hk_DestroyImage(device, image, NULL); + + const uint64_t modifier = DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED; + VkImageDrmFormatModifierListCreateInfoEXT list = { + .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT, + .drmFormatModifierCount = 1, + .pDrmFormatModifiers = &modifier, + }; + info.pNext = &list; + info.format = VK_FORMAT_R8G8B8A8_UNORM; + info.tiling = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT; + info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; + info.extent = (VkExtent3D){8, 8, 1}; + assert(hk_CreateImage(device, &info, NULL, &image) == VK_ERROR_UNKNOWN); + info.extent = (VkExtent3D){64, 64, 1}; + assert(hk_CreateImage(device, &info, NULL, &image) == VK_SUCCESS); + hk_DestroyImage(device, image, NULL); + info.usage |= VK_IMAGE_USAGE_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT; + assert(hk_CreateImage(device, &info, NULL, &image) == VK_ERROR_UNKNOWN); + + VkPhysicalDeviceImageDrmFormatModifierInfoEXT query_mod = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT, + .drmFormatModifier = modifier, + }; + VkPhysicalDeviceImageFormatInfo2 query = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, + .pNext = &query_mod, + .format = info.format, + .type = info.imageType, + .tiling = info.tiling, + .usage = info.usage, + }; + VkImageFormatProperties2 props = { + .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, + }; + assert(hk_GetPhysicalDeviceImageFormatProperties2( + hk_physical_device_to_handle(pdev), &query, &props) == + VK_ERROR_FORMAT_NOT_SUPPORTED); + + VkSubresourceLayout layout = {.rowPitch = 64 * 4}; + VkImageDrmFormatModifierExplicitCreateInfoEXT import = { + .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT, + .drmFormatModifier = modifier, + .drmFormatModifierPlaneCount = 1, + .pPlaneLayouts = &layout, + }; + VkExternalMemoryImageCreateInfo external = { + .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, + .pNext = &import, + .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + }; + info.pNext = &external; + info.usage &= ~VK_IMAGE_USAGE_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT; + assert(hk_CreateImage(device, &info, NULL, &image) == VK_SUCCESS); + assert(hk_image_from_handle(image)->planes[0].layout.compressed); + hk_DestroyImage(device, image, NULL); + layout.rowPitch += 64; + assert(hk_CreateImage(device, &info, NULL, &image) == + VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT); + + vk_object_base_finish(&dev->vk.base); + vk_object_base_finish(&instance.vk.base); + pdev->vk.instance = NULL; + free(dev); +} + int main(void) { @@ -205,16 +428,21 @@ main(void) pdev->vk.base.type = VK_OBJECT_TYPE_PHYSICAL_DEVICE; pdev->vk.properties.maxImageDimension3D = 2048; pdev->vk.properties.framebufferColorSampleCounts = 1 | 2 | 4; + pdev->vk.properties.framebufferDepthSampleCounts = 1 | 2 | 4; + pdev->vk.properties.framebufferStencilSampleCounts = 1 | 2 | 4; - /* G17P and every M5 SKU compress normal 2D colour render targets and drop - * compression when ATTACHMENT_FEEDBACK_LOOP_BIT_EXT is present. G15/G16/G18G - * keep 2D colour render targets plain in both queries. */ + /* Native HAL200 (G16G, G17P) and every M5 SKU compress normal 2D colour + * render targets and drop compression when + * ATTACHMENT_FEEDBACK_LOOP_BIT_EXT is present. G15* (M3) and G18G keep 2D + * colour render targets plain in both queries. */ const struct { enum agx_chip chip; bool expect_feedback_disables; } cases[] = { { AGX_CHIP_G15G, false }, - { AGX_CHIP_G16G, false }, + { AGX_CHIP_G15S, false }, + { AGX_CHIP_G15C, false }, + { AGX_CHIP_G16G, true }, { AGX_CHIP_G17P, true }, { AGX_CHIP_G17G, true }, { AGX_CHIP_G17S, true }, @@ -228,15 +456,25 @@ main(void) assert(query_feedback_disables_color_compression(pdev) == cases[i].expect_feedback_disables); check_interchange_modifiers(pdev); + if (agx_chip_has_cap(pdev->dev.chip, AGX_CAP_HAL200_LOSSLESS_COMPRESSION)) + check_image_creation(pdev); + check_hal200_format_and_modifier_contracts(pdev); } - /* Disabling compression disables the contract query and Interchange too. */ - pdev->dev.chip = AGX_CHIP_G17S; - pdev->dev.debug = AGX_DBG_NOCOMPRESS; - assert(!query_feedback_disables_color_compression(pdev)); - pdev->dev.chip = AGX_CHIP_G17P; - pdev->dev.debug = AGX_DBG_NOCOMPRESS; - check_interchange_modifiers(pdev); + /* Disabling compression disables the contract query, shared modifier, and + * Interchange on HAL200 and M5 alike. */ + const enum agx_chip nocompress_chips[] = { + AGX_CHIP_G16G, + AGX_CHIP_G17P, + AGX_CHIP_G17S, + }; + for (unsigned i = 0; i < ARRAY_SIZE(nocompress_chips); ++i) { + pdev->dev.chip = nocompress_chips[i]; + pdev->dev.debug = AGX_DBG_NOCOMPRESS; + assert(!query_feedback_disables_color_compression(pdev)); + check_interchange_modifiers(pdev); + check_hal200_format_and_modifier_contracts(pdev); + } free(pdev); return 0; diff --git a/src/asahi/vulkan/tests/test-hk-g16s-compression.c b/src/asahi/vulkan/tests/test-hk-g16s-compression.c index e32a8c6c8ebb..14ebc6ff879d 100644 --- a/src/asahi/vulkan/tests/test-hk-g16s-compression.c +++ b/src/asahi/vulkan/tests/test-hk-g16s-compression.c @@ -120,7 +120,8 @@ check_shape(VkFormat format, bool is_zs) /* Chip and plane. */ for (unsigned chip = 0; chip <= AGX_CHIP_UNKNOWN; ++chip) CHECK(g16s_eligible((enum agx_chip)chip, 0, &base) == - (chip == AGX_CHIP_G17P)); + agx_chip_has_cap((enum agx_chip)chip, + AGX_CAP_HAL200_LOSSLESS_COMPRESSION)); /* Plane 1 is the stencil plane of D32_SFLOAT_S8_UINT alone. */ CHECK(g16s_eligible(AGX_CHIP_G17P, 1, &base) == (format == VK_FORMAT_D32_SFLOAT_S8_UINT)); @@ -672,11 +673,11 @@ check_shared(void) VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); CHECK(SHARED(base)); - /* G17P only, plane 0 only. */ + /* Native HAL200 (G16G, G17P) and M5 only, plane 0 only. */ for (unsigned chip = 0; chip <= AGX_CHIP_UNKNOWN; ++chip) CHECK(hk_g17p_shared_compression_eligible((enum agx_chip)chip, 0, &base) == - (chip == AGX_CHIP_G17P || agx_chip_g17_m5((enum agx_chip)chip))); + hk_chip_shared_compression_supported((enum agx_chip)chip)); CHECK(!hk_g17p_shared_compression_eligible(AGX_CHIP_G17P, 1, &base)); CHECK(!hk_g17p_shared_compression_eligible(AGX_CHIP_G17P, 0, NULL)); @@ -839,10 +840,12 @@ check_m4_max(void) d.arrayLayers = 4; CHECK(M4_MAX(d) && NEO(d)); - /* Other chips never (except native HAL200 G16G for 2x/4x MSAA depth). */ + /* Native HAL200 (G16G, G17P) compress colour and 1x/2x/4x depth; non-HAL200 + * parts (AGX2, G15* M3, M5 HAL300, G18G) stay out of the HAL200 policy. */ CHECK(!runtime_m4_max(AGX_CHIP_G14G, 0, &c)); d = image(VK_FORMAT_D32_SFLOAT, 1920, 1080, 1, ds); - CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &d)); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &d)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G15G, 0, 0, &d)); d.samples = VK_SAMPLE_COUNT_2_BIT; CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &d)); CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G15G, 0, 0, &d)); diff --git a/src/asahi/vulkan/tests/test-hk-g17p-compression.c b/src/asahi/vulkan/tests/test-hk-g17p-compression.c index 2c2837071f05..c1b81bcdb487 100644 --- a/src/asahi/vulkan/tests/test-hk-g17p-compression.c +++ b/src/asahi/vulkan/tests/test-hk-g17p-compression.c @@ -110,7 +110,8 @@ check_shape_for_chip(VkFormat format, bool is_depth, uint32_t chip_id) for (unsigned chip = 0; chip <= AGX_CHIP_UNKNOWN; ++chip) CHECK(hk_hal200_compression_eligible((enum agx_chip)chip, chip_id, 0, &base) == - (chip == AGX_CHIP_G17P)); + agx_chip_has_cap((enum agx_chip)chip, + AGX_CAP_HAL200_LOSSLESS_COMPRESSION)); /* Plane 1 is the stencil plane of D32_SFLOAT_S8_UINT alone. */ CHECK(hk_hal200_compression_eligible(AGX_CHIP_G17P, chip_id, 1, &base) == (format == VK_FORMAT_D32_SFLOAT_S8_UINT)); @@ -450,12 +451,11 @@ check_shared(void) VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); CHECK(SHARED(base)); - /* G17P and M5 only, plane 0 only. */ + /* Native HAL200 (G16G, G17P) and M5 only, plane 0 only. */ for (unsigned chip = 0; chip <= AGX_CHIP_UNKNOWN; ++chip) CHECK(hk_g17p_shared_compression_eligible((enum agx_chip)chip, 0, &base) == - (chip == AGX_CHIP_G17P || chip == AGX_CHIP_G17G || - chip == AGX_CHIP_G17S || chip == AGX_CHIP_G17C)); + hk_chip_shared_compression_supported((enum agx_chip)chip)); CHECK(!hk_g17p_shared_compression_eligible(AGX_CHIP_G17P, 1, &base)); CHECK(!hk_g17p_shared_compression_eligible(AGX_CHIP_G17P, 0, NULL)); @@ -941,7 +941,7 @@ check_m5_msaa_color(void) } static void -check_g16g_msaa_depth(void) +check_g16g_hal200_compression(void) { const VkImageUsageFlags depth_usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | @@ -949,15 +949,65 @@ check_g16g_msaa_depth(void) const VkImageUsageFlags color_usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + const VkImageUsageFlags texture_usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | + VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; static const VkFormat depth_formats[] = { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D16_UNORM, VK_FORMAT_D32_SFLOAT_S8_UINT, }; + static const VkFormat color_16b_formats[] = { + VK_FORMAT_R32G32B32A32_SFLOAT, + VK_FORMAT_R32G32B32A32_UINT, + VK_FORMAT_R32G32B32A32_SINT, + }; + static const VkFormat mrt4_formats[] = { + VK_FORMAT_R8G8B8A8_UNORM, + VK_FORMAT_R8G8B8A8_SRGB, + VK_FORMAT_R16G16B16A16_SFLOAT, + VK_FORMAT_A2B10G10R10_UNORM_PACK32, + VK_FORMAT_R32_SFLOAT, + VK_FORMAT_R8_UNORM, + }; + /* Full format sweep on G16G (M4) matches G17P: all 46 1-8B colour formats, + * all 3 16B colour formats, and all 3 depth formats compress; R11G11B10F + * and standalone S8 stay plain. */ + for (unsigned f = 1; f <= VK_FORMAT_ASTC_12x12_SRGB_BLOCK; ++f) { + const VkFormat fmt = (VkFormat)f; + const bool expect = hk_g17p_compression_color_format(fmt) || + hk_g17p_compression_color_format_16b(fmt) || + hk_g17p_compression_depth_format(fmt); + VkImageCreateInfo i = image(fmt, 64, 64, 1, color_usage); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &i) == + expect); + CHECK(hk_g17p_compression_eligible(AGX_CHIP_G16G, 0, &i) == expect); + /* Non-HAL200 native AGX3 (M3 G15*), M5 (HAL300), G18G, and AGX2 never + * enter the HAL200 policy. */ + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G15G, 0, 0, &i)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G15S, 0, 0, &i)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G15C, 0, 0, &i)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G17G, 0, 0, &i)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G17S, 0, 0, &i)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G17C, 0, 0, &i)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G18G, 0, 0, &i)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G14G, 0, 0, &i)); + } + + /* Depth (1x and 2x/4x MSAA, single-layer and single-level arrays). */ for (unsigned f = 0; f < sizeof(depth_formats) / sizeof(depth_formats[0]); ++f) { VkImageCreateInfo d = image(depth_formats[f], 1920, 1080, 1, depth_usage); - CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &d)); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &d)); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 1, &d) == + (depth_formats[f] == VK_FORMAT_D32_SFLOAT_S8_UINT)); + /* Single-level depth arrays (shadow maps / cascades). */ + VkImageCreateInfo arr = d; + arr.arrayLayers = 4; + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &arr)); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 1, &arr) == + (depth_formats[f] == VK_FORMAT_D32_SFLOAT_S8_UINT)); + arr.mipLevels = 2; + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &arr)); for (unsigned s = 2; s <= 4; s <<= 1) { d.samples = (VkSampleCountFlagBits)s; @@ -979,11 +1029,9 @@ check_g16g_msaa_depth(void) CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &x)); CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 1, &x)); x = d; - x.flags |= VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT; + x.arrayLayers = 4; CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &x)); - x = d; - x.arrayLayers = 2; - CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &x)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 1, &x)); x = d; x.mipLevels = 2; CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &x)); @@ -993,13 +1041,91 @@ check_g16g_msaa_depth(void) CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &d)); } - /* Colour images stay plain on G16G in this standalone depth-only policy. */ - VkImageCreateInfo c = image(VK_FORMAT_R8G8B8A8_UNORM, 1920, 1080, 1, color_usage); - CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c)); - c.samples = VK_SAMPLE_COUNT_2_BIT; - CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c)); - c.samples = VK_SAMPLE_COUNT_4_BIT; - CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c)); + /* 16-byte colour targets (rgba32f / rgba32u / rgba32i): single-sample 2D, + * mip chains, 2D arrays, and cubemaps compress on G16G; MSAA and 3D stay + * plain (matching G17P). */ + for (unsigned f = 0; + f < sizeof(color_16b_formats) / sizeof(color_16b_formats[0]); ++f) { + VkImageCreateInfo c16 = + image(color_16b_formats[f], 1920, 1080, 1, color_usage); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c16)); + c16.mipLevels = 8; + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c16)); + c16.arrayLayers = 4; + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c16)); + VkImageCreateInfo cube = + image(color_16b_formats[f], 256, 256, 4, color_usage); + cube.arrayLayers = 6; + cube.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &cube)); + + VkImageCreateInfo bad = + image(color_16b_formats[f], 1920, 1080, 1, color_usage); + bad.samples = VK_SAMPLE_COUNT_2_BIT; + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &bad)); + bad.samples = VK_SAMPLE_COUNT_4_BIT; + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &bad)); + bad = image(color_16b_formats[f], 64, 64, 1, color_usage); + bad.imageType = VK_IMAGE_TYPE_3D; + bad.extent.depth = 4; + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &bad)); + } + + /* 1-8 byte MRT/colour targets: 1x, layered, cube, 3D, and input attachments + * compress on G16G; 2x/4x MSAA colour stays plain on G16G and compresses on + * G17P (AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION); R11G11B10F and storage stay + * plain on both. */ + for (unsigned f = 0; f < sizeof(mrt4_formats) / sizeof(mrt4_formats[0]); ++f) { + VkImageCreateInfo c = image(mrt4_formats[f], 1920, 1080, 1, color_usage); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c)); + c.usage |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c)); + c.samples = VK_SAMPLE_COUNT_2_BIT; + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c)); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G17P, AGX_CHIP_ID_A18_PRO, + 0, &c)); + c.samples = VK_SAMPLE_COUNT_4_BIT; + c.arrayLayers = 4; + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c)); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G17P, AGX_CHIP_ID_A18_PRO, + 0, &c)); + c.usage |= VK_IMAGE_USAGE_STORAGE_BIT; + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &c)); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G17P, AGX_CHIP_ID_A18_PRO, + 0, &c)); + + VkImageCreateInfo vol = image(mrt4_formats[f], 64, 64, 1, color_usage); + vol.imageType = VK_IMAGE_TYPE_3D; + vol.extent.depth = 8; + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &vol)); + } + VkImageCreateInfo r11 = + image(VK_FORMAT_B10G11R11_UFLOAT_PACK32, 1920, 1080, 1, color_usage); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &r11)); + + /* Classic-submission non-attachment crossover on G16G: textures never used as + * attachments stay plain below HK_CLASSIC_MIP_PBE_MIN_TEXELS (1 << 20 = + * 1024x1024) and compress at or above it; attachments compress at any size + * >= 16x16. */ + VkImageCreateInfo tex = image(VK_FORMAT_R8G8B8A8_UNORM, 512, 256, 1, texture_usage); + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &tex)); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G17P, AGX_CHIP_ID_A18_PRO, 0, &tex)); + tex.extent.width = 768; + tex.extent.height = 768; + CHECK(!hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &tex)); + tex.extent.width = 1024; + tex.extent.height = 1024; + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &tex)); + tex = image(VK_FORMAT_R8G8B8A8_UNORM, 64, 64, 1, color_usage); + CHECK(hk_hal200_compression_eligible(AGX_CHIP_G16G, 0x8132, 0, &tex)); + + /* Shared DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED contract on G16G. */ + VkImageCreateInfo shared = + swapchain_image(VK_FORMAT_B8G8R8A8_SRGB, 1920, 1080, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); + CHECK(hk_g17p_shared_compression_eligible(AGX_CHIP_G16G, 0, &shared)); + shared.format = VK_FORMAT_R32G32B32A32_SFLOAT; + CHECK(!hk_g17p_shared_compression_eligible(AGX_CHIP_G16G, 0, &shared)); } int @@ -1022,11 +1148,11 @@ main(void) check_minecraft(); check_zink(); check_shared(); - check_g16g_msaa_depth(); + check_g16g_hal200_compression(); check_m5_depth(); check_m5_color(); check_m5_msaa_color(); check_m5_depth_msaa(); - printf("G17P compression policy: %u checks passed\n", checks); + printf("HAL200/M5 compression policy: %u checks passed\n", checks); return 0; } diff --git a/src/asahi/vulkan/tests/test-hk-g17p-decompress.c b/src/asahi/vulkan/tests/test-hk-g17p-decompress.c index 1e419c8f2f32..07dc06548472 100644 --- a/src/asahi/vulkan/tests/test-hk-g17p-decompress.c +++ b/src/asahi/vulkan/tests/test-hk-g17p-decompress.c @@ -36,6 +36,14 @@ texture_header(void) return cfg; } +/* As texture_header(), for a PBE packet. */ +static struct AGX_PBE +pbe_header(void) +{ + struct AGX_PBE cfg = {AGX_PBE_header}; + return cfg; +} + static void check_kernel(const uint32_t *bin, const char *name) { @@ -208,8 +216,72 @@ main(void) assert(hk_g17p_decompress_image_type_supported(VK_IMAGE_TYPE_2D)); assert(!hk_g17p_decompress_image_type_supported(VK_IMAGE_TYPE_3D)); + /* Verify Gen9 compressed AIL layout + PBE descriptor emission for the key + * HAL200 targets (rgba8, rgba16f, rgba32f 1x 2D/array, d32f via R32_UINT + * copy alias). 2x/4x MSAA colour compression on native HAL200 is gated by + * AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION (G17P only); a plain MSAA layout + * on G16G is covered by the chip-caps row test. */ + static const struct { + enum pipe_format format; + unsigned layers; + } pbe_cases[] = { + { PIPE_FORMAT_R8G8B8A8_UNORM, 1 }, + { PIPE_FORMAT_R8G8B8A8_UNORM, 4 }, + { PIPE_FORMAT_R16G16B16A16_FLOAT, 1 }, + { PIPE_FORMAT_R32G32B32A32_FLOAT, 1 }, + { PIPE_FORMAT_R32G32B32A32_FLOAT, 6 }, + { PIPE_FORMAT_R32_UINT, 1 }, + { PIPE_FORMAT_R32_UINT, 4 }, + }; + for (unsigned i = 0; i < ARRAY_SIZE(pbe_cases); ++i) { + struct ail_layout layout = { + .policy = ail_layout_policy_for_descriptor_generation( + agx_chip_descriptor_generation(AGX_CHIP_G16G)), + .tiling = AIL_TILING_GPU, + .compressed = true, + .format = pbe_cases[i].format, + .width_px = 512, + .height_px = 512, + .depth_px = pbe_cases[i].layers, + .levels = 1, + .sample_count_sa = 1, + .renderable = true, + }; + ail_make_miptree(&layout); + assert(layout.policy == AIL_LAYOUT_POLICY_LEGACY); + assert(layout.metadata_offset_B > 0); + assert(layout.compression_layer_stride_B > 0); + assert(layout.compression_layer_stride_B % AIL_CACHELINE == 0); + assert(ail_is_level_logically_compressed(&layout, 0)); + + const bool layered = pbe_cases[i].layers > 1; + struct AGX_PBE pbe = pbe_header(); + pbe.dimension = layered ? AGX_TEXTURE_DIMENSION_2D_ARRAY + : AGX_TEXTURE_DIMENSION_2D; + pbe.layout = AGX_LAYOUT_GPU; + pbe.channels = ail_pixel_format[pbe_cases[i].format].channels; + pbe.type = ail_pixel_format[pbe_cases[i].format].type; + pbe.swizzle_r = AGX_CHANNEL_R; + pbe.swizzle_g = AGX_CHANNEL_G; + pbe.swizzle_b = AGX_CHANNEL_B; + pbe.swizzle_a = AGX_CHANNEL_A; + pbe.buffer = 0x100000; + pbe.width = layout.width_px; + pbe.height = layout.height_px; + pbe.layers = pbe_cases[i].layers; + pbe.levels = 1; + pbe.level = 0; + pbe.page_aligned_layers = layout.page_aligned_layers; + pbe.compressed = true; + pbe.extended = true; + pbe.acceleration_buffer = 0x100000 + layout.metadata_offset_B; + struct hk_native_pbe_descriptor packed_pbe; + assert(hk_pack_native_pbe( + agx_chip_descriptor_generation(AGX_CHIP_G16G), &packed_pbe, &pbe)); + } + printf("AGX3 decompression: 21 kernels (G17P+G16G+G17G) + %u formats x 6 " - "shapes + M5 16-byte spill passed\n", - format_count); + "shapes + M5 16-byte spill + %zu HAL200 1x PBE layouts passed\n", + format_count, ARRAY_SIZE(pbe_cases)); return 0; } diff --git a/src/asahi/vulkan/tests/test-hk-g17p-metadata-grid.c b/src/asahi/vulkan/tests/test-hk-g17p-metadata-grid.c index 19af59d0eb61..bcf0347cbc41 100644 --- a/src/asahi/vulkan/tests/test-hk-g17p-metadata-grid.c +++ b/src/asahi/vulkan/tests/test-hk-g17p-metadata-grid.c @@ -389,10 +389,74 @@ check_g18g_meta_copy_admission(void) "G18G 3D image copy slice helper refused"); } +static void +check_resolve_slice(void) +{ + /* Multi-layer 2D array resolve on native AGX3: splits into single-layer + * passes. The sample count comes from srcSubresource.layerCount. */ + const VkImageResolve2 region = { + .sType = VK_STRUCTURE_TYPE_IMAGE_RESOLVE_2, + .srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 2, 3}, + .srcOffset = {0, 0, 0}, + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 2, 3}, + .dstOffset = {0, 0, 0}, + .extent = {64, 64, 1}, + }; + VkImageResolve2 out; + + EXPECT(hk_g17p_image_resolve_slice(AGX_CHIP_G16G, VK_IMAGE_TYPE_2D, + VK_IMAGE_TYPE_2D, 3, 3, ®ion, 0, + &out) && + out.srcSubresource.baseArrayLayer == 2 && + out.srcSubresource.layerCount == 1 && + out.dstSubresource.baseArrayLayer == 2 && + out.dstSubresource.layerCount == 1 && + out.extent.width == 64 && out.extent.height == 64, + "G16G resolve slice helper refused slice 0"); + + EXPECT(hk_g17p_image_resolve_slice(AGX_CHIP_G17P, VK_IMAGE_TYPE_2D, + VK_IMAGE_TYPE_2D, 5, 5, ®ion, 2, + &out) && + out.srcSubresource.baseArrayLayer == 4 && + out.srcSubresource.layerCount == 1 && + out.dstSubresource.baseArrayLayer == 4 && + out.dstSubresource.layerCount == 1, + "G17P resolve slice helper refused slice 2"); + + /* Non-native-AGX3 chips, 3D image types, mismatched layer counts and + * out-of-range slices are refused. */ + EXPECT(!hk_g17p_image_resolve_slice(AGX_CHIP_G13G, VK_IMAGE_TYPE_2D, + VK_IMAGE_TYPE_2D, 3, 3, ®ion, 0, + &out), + "AGX2 should refuse resolve slice helper"); + EXPECT(!hk_g17p_image_resolve_slice(AGX_CHIP_G17P, VK_IMAGE_TYPE_3D, + VK_IMAGE_TYPE_2D, 3, 3, ®ion, 0, + &out), + "3D source should refuse resolve slice helper"); + EXPECT(!hk_g17p_image_resolve_slice(AGX_CHIP_G17P, VK_IMAGE_TYPE_2D, + VK_IMAGE_TYPE_2D, 3, 4, ®ion, 0, + &out), + "mismatched layer counts should refuse resolve slice helper"); + EXPECT(!hk_g17p_image_resolve_slice(AGX_CHIP_G17P, VK_IMAGE_TYPE_2D, + VK_IMAGE_TYPE_2D, 3, 3, ®ion, 3, + &out), + "slice past layer count should refuse resolve slice helper"); + + /* Non-zero z offsets are refused: VkImageResolve addresses 2D arrays + * through baseArrayLayer, not z. */ + VkImageResolve2 bad_z_src = region; + bad_z_src.srcOffset.z = 1; + EXPECT(!hk_g17p_image_resolve_slice(AGX_CHIP_G17P, VK_IMAGE_TYPE_2D, + VK_IMAGE_TYPE_2D, 3, 3, &bad_z_src, 0, + &out), + "non-zero srcOffset.z should refuse resolve slice helper"); +} + int main(void) { check_g18g_meta_copy_admission(); + check_resolve_slice(); check_layered_layouts(); check_mip_split(); check_exact_2x2_rounding(); diff --git a/src/vulkan/runtime/vk_meta_blit_resolve.c b/src/vulkan/runtime/vk_meta_blit_resolve.c index 7c19f02e030b..431b3dbbc57b 100644 --- a/src/vulkan/runtime/vk_meta_blit_resolve.c +++ b/src/vulkan/runtime/vk_meta_blit_resolve.c @@ -356,11 +356,15 @@ build_blit_shader(const struct vk_meta_blit_key *key) static VkResult get_blit_pipeline_layout(struct vk_device *device, struct vk_meta_device *meta, + bool combined_descriptors, VkPipelineLayout *layout_out) { - enum vk_meta_object_key_type key = VK_META_OBJECT_KEY_BLIT; + const struct { + enum vk_meta_object_key_type key_type; + uint32_t combined_descriptors; + } key = { VK_META_OBJECT_KEY_BLIT, combined_descriptors }; - if (vk_meta_use_combined_blit_descriptors(meta)) { + if (combined_descriptors) { /* One combined binding per aspect. A depth/stencil blit pushes two * descriptors in the same call, so they cannot share a binding. */ const VkDescriptorSetLayoutBinding binding[] = {{ @@ -573,7 +577,13 @@ do_blit(struct vk_command_buffer *cmd, VkResult result; VkPipelineLayout pipeline_layout; - result = get_blit_pipeline_layout(device, meta, &pipeline_layout); + /* Resolves use multisample texel fetches without a sampler. Match the + * layout to the descriptor type pushed for this operation. + */ + const bool combined_descriptors = + vk_meta_use_combined_blit_descriptors(meta) && sampler != VK_NULL_HANDLE; + result = get_blit_pipeline_layout(device, meta, combined_descriptors, + &pipeline_layout); if (unlikely(result != VK_SUCCESS)) { vk_command_buffer_set_error(cmd, result); return; @@ -582,13 +592,8 @@ do_blit(struct vk_command_buffer *cmd, uint32_t desc_count = 0; VkDescriptorImageInfo image_infos[3]; VkWriteDescriptorSet desc_writes[3]; - /* Every aspect must agree with the layout, which declares one combined - * binding per aspect. Restricting this to colour left a depth/stencil - * blit pushing plain sampled images into combined bindings. */ - const bool combined_push_diagnostic = - vk_meta_use_combined_blit_descriptors(meta) && sampler != VK_NULL_HANDLE; - if (sampler != VK_NULL_HANDLE && !combined_push_diagnostic) { + if (sampler != VK_NULL_HANDLE && !combined_descriptors) { image_infos[desc_count] = (VkDescriptorImageInfo) { .sampler = sampler, }; @@ -635,13 +640,13 @@ do_blit(struct vk_command_buffer *cmd, assert(desc_count < ARRAY_SIZE(image_infos)); assert(desc_count < ARRAY_SIZE(desc_writes)); image_infos[desc_count] = (VkDescriptorImageInfo) { - .sampler = combined_push_diagnostic ? sampler : VK_NULL_HANDLE, + .sampler = combined_descriptors ? sampler : VK_NULL_HANDLE, .imageView = src_view, }; desc_writes[desc_count] = (VkWriteDescriptorSet) { .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .dstBinding = aspect_to_tex_binding(aspect), - .descriptorType = combined_push_diagnostic + .descriptorType = combined_descriptors ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, .descriptorCount = 1, @@ -660,7 +665,7 @@ do_blit(struct vk_command_buffer *cmd, while (aspects_left) { key->aspects = aspects_left; - key->combined_descriptors = combined_push_diagnostic; + key->combined_descriptors = combined_descriptors; /* If we need to write stencil via iterative discard, it has to be * written by itself because otherwise the discards would also throw From 4d95804089cb3a5b6f20a808241c6d95f32a2bb0 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Wed, 25 Nov 2026 08:18:55 -0500 Subject: [PATCH 2/2] borealis: preserve compressed dma-buf import queries Use the shared modifier predicate when reporting image format support. A compatible compressed dma-buf can be imported with attachment feedback even though modifier-list allocation declines compression for that usage. Exercise the query, explicit plane layout and modifier list with the same RGBA8 dma-buf usage on G16G and G17P. Signed-off-by: Diljit Singh --- src/asahi/vulkan/hk_image.c | 28 ++++++----------- .../tests/test-hk-compression-contract.c | 30 ++++++++++++------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/asahi/vulkan/hk_image.c b/src/asahi/vulkan/hk_image.c index 2523eec820ff..e2e0ce6f06cd 100644 --- a/src/asahi/vulkan/hk_image.c +++ b/src/asahi/vulkan/hk_image.c @@ -963,25 +963,15 @@ hk_GetPhysicalDeviceImageFormatProperties2( drm_mod_info && drm_mod_info->drmFormatModifier == DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED; - if (g17p_compressed) { - /* Modifier queries have no extent. Use an eligible extent and the - * same creation policy as modifier-list selection. */ - const VkImageCreateInfo probe = { - .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, - .pNext = pImageFormatInfo->pNext, - .flags = pImageFormatInfo->flags, - .imageType = pImageFormatInfo->type, - .format = pImageFormatInfo->format, - .extent = {16, 16, 1}, - .mipLevels = 1, - .arrayLayers = 1, - .samples = VK_SAMPLE_COUNT_1_BIT, - .tiling = pImageFormatInfo->tiling, - .usage = pImageFormatInfo->usage, - }; - if (!hk_can_compress_create_info(&pdev->dev, 0, &probe, false, false)) - return VK_ERROR_FORMAT_NOT_SUPPORTED; - } + /* This query also describes explicit imports. Only modifier-list + * allocation applies the policy for choosing compression on new images. + */ + if (g17p_compressed && + !hk_g17p_shared_compression_supported( + &pdev->dev, pImageFormatInfo->format, pImageFormatInfo->type, + pImageFormatInfo->flags, pImageFormatInfo->usage, + pImageFormatInfo->pNext)) + return VK_ERROR_FORMAT_NOT_SUPPORTED; const uint32_t max_dim = pImageFormatInfo->type == VK_IMAGE_TYPE_3D ? pdev->vk.properties.maxImageDimension3D diff --git a/src/asahi/vulkan/tests/test-hk-compression-contract.c b/src/asahi/vulkan/tests/test-hk-compression-contract.c index 08eac82168c8..5298d106cc37 100644 --- a/src/asahi/vulkan/tests/test-hk-compression-contract.c +++ b/src/asahi/vulkan/tests/test-hk-compression-contract.c @@ -362,7 +362,12 @@ check_image_creation(struct hk_physical_device *pdev) .drmFormatModifierCount = 1, .pDrmFormatModifiers = &modifier, }; - info.pNext = &list; + VkExternalMemoryImageCreateInfo external = { + .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, + .pNext = &list, + .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + }; + info.pNext = &external; info.format = VK_FORMAT_R8G8B8A8_UNORM; info.tiling = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT; info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; @@ -378,20 +383,31 @@ check_image_creation(struct hk_physical_device *pdev) .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT, .drmFormatModifier = modifier, }; + VkPhysicalDeviceExternalImageFormatInfo query_external = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO, + .pNext = &query_mod, + .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + }; VkPhysicalDeviceImageFormatInfo2 query = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, - .pNext = &query_mod, + .pNext = &query_external, .format = info.format, .type = info.imageType, .tiling = info.tiling, .usage = info.usage, }; + VkExternalImageFormatProperties external_props = { + .sType = VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES, + }; VkImageFormatProperties2 props = { .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, + .pNext = &external_props, }; assert(hk_GetPhysicalDeviceImageFormatProperties2( hk_physical_device_to_handle(pdev), &query, &props) == - VK_ERROR_FORMAT_NOT_SUPPORTED); + VK_SUCCESS); + assert(external_props.externalMemoryProperties.externalMemoryFeatures & + VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT); VkSubresourceLayout layout = {.rowPitch = 64 * 4}; VkImageDrmFormatModifierExplicitCreateInfoEXT import = { @@ -400,13 +416,7 @@ check_image_creation(struct hk_physical_device *pdev) .drmFormatModifierPlaneCount = 1, .pPlaneLayouts = &layout, }; - VkExternalMemoryImageCreateInfo external = { - .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, - .pNext = &import, - .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, - }; - info.pNext = &external; - info.usage &= ~VK_IMAGE_USAGE_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT; + external.pNext = &import; assert(hk_CreateImage(device, &info, NULL, &image) == VK_SUCCESS); assert(hk_image_from_handle(image)->planes[0].layout.compressed); hk_DestroyImage(device, image, NULL);