Repository navigation
borealis: enable read-only early-Z rejection ahead of discard on M5 - #791
Merged
DjDeveloperr merged 1 commit intoNov 24, 2026
Merged
Conversation
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
approved these changes
Nov 24, 2026
satchlj
left a comment
Member
There was a problem hiding this comment.
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 fromagx_chip_native_agx3()toagx_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 withcompare_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 unconditionalagx_chip_g17_m5(chip)bypass so M5 foldskey->static_testsonly whenhk_g17p_static_no_early_reject(state)statically rules out read-only early reject, keeping the draw-timeno_epilog_discardselector consistent with thehk_cmd_draw.c:11458invariant.- Verified
hk_fs_link_key_build()andhk_flush_graphics_state()agree ondefer_api_sample_mask/early_reject_defer_api_maskandnative_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 whenprolog != NULL, disables main-part Z/S testing viano_epilog_discard = 0, and setsepilog.link.already_ran_zs = true. G17PMSAAEpilog.ReadOnlyEarlyRejectPrologCompilesForAGX3(src/asahi/lib/tests/test-g17p-msaa-epilog.cpp:741-769) verifies compilation andpart.info.writes_sample_maskfor bothAGX_CHIP_G17P(AGX3B) andAGX_CHIP_G17S(AGX3C).
- Unit & drm-shim tests:
235/235non-layoutasahisuite tests PASS under GCC 16debugoptimized(assertions enabled), including12/12G17PMSAAEpilog.*tests (ReadOnlyEarlyRejectPrologCompilesForAGX3PASS). - Live hardware (Apple M5 Max, G17C B1, Linux 7.3, Borealis,
MESA_SHADER_CACHE_DISABLE=1):337Vulkan CTS early-fragment, discard, occlusion-query, and depth compare-op runs PASS across normal andASAHI_MESA_DEBUG=verifymodes (0FAIL,0GPU 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 byG17PMSAAEpilog.ReadOnlyEarlyRejectPrologCompilesForAGX3). asahi_layout_testsskipped due to an unrelated pre-existing GCC 16 designated-initializer order error in basesrc/asahi/layout/tests/test-layout.cpp:374.
- Live G15/G17P silicon (live execution verified on Apple M5 Max
Evidence
- Meson
asahitest suite (excludingasahi_layout_tests):235/235OK,0FAIL - Targeted
libasahi_tests(--gtest_filter='*ReadOnlyEarlyReject*:*G17PMSAAEpilog*'):12/12PASSED (includingG17PMSAAEpilog.ReadOnlyEarlyRejectPrologCompilesForAGX3) - Live Borealis Vulkan CTS (
Apple M5 Max, G17C B1,MESA_SHADER_CACHE_DISABLE=1):dEQP-VK.fragment_operations.early_fragment.*:27/54PASS (27NotSupported forVK_AMD_shader_early_and_late_fragment_tests,0FAIL)dEQP-VK.fragment_operations.early_fragment.*(ASAHI_MESA_DEBUG=verify):27/54PASS (27NotSupported,0FAIL)dEQP-VK.fragment_operations.early_fragment.discard_*:4/6PASS (2NotSupported,0FAIL)dEQP-VK.glsl.discard.*:25/25PASS (0FAIL)dEQP-VK.glsl.discard.*(ASAHI_MESA_DEBUG=verify):25/25PASS (0FAIL)dEQP-VK.query_pool.occlusion_query.basic_conservative:1/1PASSdEQP-VK.query_pool.occlusion_query.basic_precise:1/1PASSdEQP-VK.pipeline.monolithic.depth.format.d32_sfloat.compare_ops.*:222/466PASS (244NotSupported fordepthBounds,0FAIL)dEQP-VK.pipeline.monolithic.early_destroy.*:9/9PASS (0FAIL)
- Kernel log (
dmesg):0GPU faults / resets / errors
Author
|
Merged into Verified gates:
|
RyanTheTide
deleted the
perf/borealis-m5-read-only-early-z-before-discard
branch
November 27, 2026 13:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enables the read-only early-Z rejection prolog fast path ahead of fragment discard on M5 (
agx_chip_native_or_m5()) insrc/asahi/vulkan/hk_cmd_draw.c(hk_g17p_read_only_early_reject_in()) andsrc/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. AddsG17PMSAAEpilog.ReadOnlyEarlyRejectPrologCompilesForAGX3insrc/asahi/lib/tests/test-g17p-msaa-epilog.cpp.Verification
G17S B1), kernel7.3.0-m5-n1keep-r3,MESA_SHADER_CACHE_DISABLE=1, noASAHI_M5_BRINGUPbad129644642372eb032fc04e598e87c00ca625b(standalone exact-head build onb8b79e1fcff8, clean merge onto liveaurora-wipefabab38502d)asahiCI (DjDeveloperr/mesa): run 45103597007 PASSmeson test(asahi compiler/lib/hk unit suite)163/163PASS0fail,0GPU faultsdEQP-VK.fragment_operations.early_fragment.*(full)27/54PASS (27NotSupported)0fail,0GPU faultsdEQP-VK.glsl.discard.*(full)25/25PASS0fail,0GPU faults