Skip to content

borealis: enable read-only early-Z rejection ahead of discard on M5 - #791

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/borealis-m5-read-only-early-z-before-discard
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/borealis-m5-read-only-early-z-before-discard

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

Enables the read-only early-Z rejection prolog fast path ahead of fragment discard on M5 (agx_chip_native_or_m5()) in src/asahi/vulkan/hk_cmd_draw.c (hk_g17p_read_only_early_reject_in()) and src/asahi/vulkan/hk_shader.c (hk_g17p_static_no_early_reject() / hk_populate_fs_key()), matching native AGX3B.

For single-sample discarding fragment shaders with read-only depth tests (depthTestEnable && !depthWriteEnable, no side effects, no depth/stencil exports, no stencil/bounds test, no occlusion/statistics queries, no prolog discards), running the all-live depth-testing prolog ahead of the main fragment shader rejects occluded fragments before shader execution. Adds G17PMSAAEpilog.ReadOnlyEarlyRejectPrologCompilesForAGX3 in src/asahi/lib/tests/test-g17p-msaa-epilog.cpp.

Verification

  • Hardware: Apple M5 Pro (G17S B1), kernel 7.3.0-m5-n1keep-r3, MESA_SHADER_CACHE_DISABLE=1, no ASAHI_M5_BRINGUP
  • Verified Head SHA: bad129644642372eb032fc04e598e87c00ca625b (standalone exact-head build on b8b79e1fcff8, clean merge onto live aurora-wip efabab38502d)
  • Mirror asahi CI (DjDeveloperr/mesa): run 45103597007 PASS
Suite Result Faults / Notes
meson test (asahi compiler/lib/hk unit suite) 163/163 PASS 0 fail, 0 GPU faults
dEQP-VK.fragment_operations.early_fragment.* (full) 27/54 PASS (27 NotSupported) 0 fail, 0 GPU faults
dEQP-VK.glsl.discard.* (full) 25/25 PASS 0 fail, 0 GPU faults

For single-sample discarding fragment shaders with read-only depth tests
(depthTestEnable && !depthWriteEnable, no side effects, no depth/stencil
exports, no stencil/bounds test, no occlusion/statistics queries, no
prolog discards), native AGX3B runs an all-live depth-testing prolog ahead
of the fragment shader and clears no_epilog_discard so occluded fragments
are rejected before shader execution and discard.

M5 (AGX3C) already lowers deferred sample-mask tests with no_epilog_discard
and links ZS-testing fragment prologs. Enable hk_g17p_read_only_early_reject_in
and hk_g17p_static_no_early_reject on M5 (agx_chip_native_or_m5), and add a
compiler unit test verifying the all-live read-only early-reject prolog
packs cleanly on both AGX3B and AGX3C.

Signed-off-by: Diljit Singh <hey@djdev.me>

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict at bad129644642

Approve.

Blockers

None.

Checked

  • Code audit (hk_cmd_draw.c, hk_shader.c, test-g17p-msaa-epilog.cpp):
    • hk_g17p_read_only_early_reject_in() (src/asahi/vulkan/hk_cmd_draw.c:10418) switches its chip gate from agx_chip_native_agx3() to agx_chip_native_or_m5(), keeping all side-effect and coverage-ordering preconditions intact (writes_sample_mask, !static_tests, !early_fragment_tests, !writes_memory, !write_z, !write_s, samples == 1, read-only depth test with compare_op != VK_COMPARE_OP_ALWAYS, no depth bounds test, no stencil test on a stencil attachment, no occlusion query, no fragment shader invocation statistics, and !prolog_discards).
    • hk_populate_fs_key() (src/asahi/vulkan/hk_shader.c:660-666) removes the unconditional agx_chip_g17_m5(chip) bypass so M5 folds key->static_tests only when hk_g17p_static_no_early_reject(state) statically rules out read-only early reject, keeping the draw-time no_epilog_discard selector consistent with the hk_cmd_draw.c:11458 invariant.
    • Verified hk_fs_link_key_build() and hk_flush_graphics_state() agree on defer_api_sample_mask / early_reject_defer_api_mask and native_samples (agx_chip_native_or_m5), so M5 links the all-live read-only early-reject prolog (run_zs_tests = true, nr_samples = 1), skips the monolithic inline-blend shortcut when prolog != NULL, disables main-part Z/S testing via no_epilog_discard = 0, and sets epilog.link.already_ran_zs = true.
    • G17PMSAAEpilog.ReadOnlyEarlyRejectPrologCompilesForAGX3 (src/asahi/lib/tests/test-g17p-msaa-epilog.cpp:741-769) verifies compilation and part.info.writes_sample_mask for both AGX_CHIP_G17P (AGX3B) and AGX_CHIP_G17S (AGX3C).
  • Unit & drm-shim tests: 235/235 non-layout asahi suite tests PASS under GCC 16 debugoptimized (assertions enabled), including 12/12 G17PMSAAEpilog.* tests (ReadOnlyEarlyRejectPrologCompilesForAGX3 PASS).
  • Live hardware (Apple M5 Max, G17C B1, Linux 7.3, Borealis, MESA_SHADER_CACHE_DISABLE=1): 337 Vulkan CTS early-fragment, discard, occlusion-query, and depth compare-op runs PASS across normal and ASAHI_MESA_DEBUG=verify modes (0 FAIL, 0 GPU faults in kernel log).
  • Untested scope:
    • Live G15/G17P silicon (live execution verified on Apple M5 Max G17C B1; G17P and G17S prolog compilation covered by G17PMSAAEpilog.ReadOnlyEarlyRejectPrologCompilesForAGX3).
    • asahi_layout_tests skipped due to an unrelated pre-existing GCC 16 designated-initializer order error in base src/asahi/layout/tests/test-layout.cpp:374.
Evidence
  • Meson asahi test suite (excluding asahi_layout_tests): 235/235 OK, 0 FAIL
  • Targeted libasahi_tests (--gtest_filter='*ReadOnlyEarlyReject*:*G17PMSAAEpilog*'): 12/12 PASSED (including G17PMSAAEpilog.ReadOnlyEarlyRejectPrologCompilesForAGX3)
  • Live Borealis Vulkan CTS (Apple M5 Max, G17C B1, MESA_SHADER_CACHE_DISABLE=1):
    • dEQP-VK.fragment_operations.early_fragment.*: 27/54 PASS (27 NotSupported for VK_AMD_shader_early_and_late_fragment_tests, 0 FAIL)
    • dEQP-VK.fragment_operations.early_fragment.* (ASAHI_MESA_DEBUG=verify): 27/54 PASS (27 NotSupported, 0 FAIL)
    • dEQP-VK.fragment_operations.early_fragment.discard_*: 4/6 PASS (2 NotSupported, 0 FAIL)
    • dEQP-VK.glsl.discard.*: 25/25 PASS (0 FAIL)
    • dEQP-VK.glsl.discard.* (ASAHI_MESA_DEBUG=verify): 25/25 PASS (0 FAIL)
    • dEQP-VK.query_pool.occlusion_query.basic_conservative: 1/1 PASS
    • dEQP-VK.query_pool.occlusion_query.basic_precise: 1/1 PASS
    • dEQP-VK.pipeline.monolithic.depth.format.d32_sfloat.compare_ops.*: 222/466 PASS (244 NotSupported for depthBounds, 0 FAIL)
    • dEQP-VK.pipeline.monolithic.early_destroy.*: 9/9 PASS (0 FAIL)
  • Kernel log (dmesg): 0 GPU faults / resets / errors

@DjDeveloperr
DjDeveloperr merged commit f8726e3 into aurora-wip Nov 24, 2026
@DjDeveloperr

Copy link
Copy Markdown
Author

Merged into aurora-wip at f8726e3bd86fdbf8dea7a5852f9cc3305b1fecf1 (exact head bad129644642372eb032fc04e598e87c00ca625b, tree bd87f1658393c7a4676a4a02641f402c33d6a057).

Verified gates:

  • Independent exact-head approval from @satchlj (235/235 unit/drm-shim tests incl. 12/12 G17PMSAAEpilog.* + 337 live M5 Max Borealis Vulkan early-fragment/discard/occlusion/depth CTS PASS with ASAHI_MESA_DEBUG=verify, zero GPU faults), plus M5 Pro G17S verification.
  • Exact-head mirror CI: asahi (45113997379) and aurora-agent-policy (45113997273) PASS.
  • Commit hygiene & policy check clean (1/1 Signed-off-by, empty .github/ diff).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants