Repository navigation
d3d12, d3d11: occlusion queries keep every draw's count on Apple7 when a pass has many large draws - #463
Merged
Conversation
…s has many large draws On an M1 Pro (Apple7), a render pass with many counting draws over a large target loses the counts of its first draws: they come back as 0. A plain Metal program shows it too, so it is outside Mullion. Render passes now add their counts to the visibility buffer (MTLVisibilityResultTypeAccumulate, macOS 26 and later) instead of storing them, so a count stored again as 0 is kept. Adding needs each slot to start at 0: VisibilitySlot zeroes a new window, and Close zeroes the slots the list counted in with blit fills after the sums and resolves read them. Each slot is still counted in by one pass only, so adding gives the same number as storing did. Older macOS stores as before; D3D11 is untouched.
partprogramming09
marked this pull request as ready for review
December 5, 2026 07:42
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…s has many large draws D3D11 counts occlusion like D3D12 and loses counts the same way on an M1 Pro (Apple7): in d3d11_occlusion_wide the 100 triangles over 8192x8192 count about 8% of their samples. Render passes now add their counts to the visibility buffer (macOS 26 and later), as D3D12 passes do. A VisibilityResultReadback window is made for one command buffer and never reused; it is now zeroed when created, since on i386 its memory comes from aligned_malloc. Each segment is still counted in by one pass only, so adding gives the same number as storing did.
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.
Part of a series that makes Mullion pass its suite on an M1 Pro (Apple7); #7 describes the setup.
What was wrong
On my M1 Pro
d3d12_occlusion_widefails every run, with both shader front ends: 2 of its 5 queries read fewer samples than they drew, and the counts change from run to run. The cause is outside Mullion: a plain Metal program with no Mullion in it shows it. When one render pass has many counting draws over a large target, the counts of its first draws come back as 0: over 2048x2048, a pass of 90 draws is fine and one of 92 or more loses the counts of its first 92 draws; over 1024x1024, 64 draws are fine and 100 or more lose the first 73. Every pass over that size loses them, not only the first. Only the counts are lost, not the drawing: in the same passes, a fragment-shader atomic counts every draw's fragments exactly once (none missing, none twice) and the pass timestamps read fine. Why the stored counts come back as 0 I cannot see from outside. D3D11 counts occlusion the same way and fails the same way: ind3d11_occlusion_widethe 100 triangles over 8192x8192 count about 539 M of their 6711 M samples.What this PR does
Render passes now add their counts to the slot (
MTLVisibilityResultTypeAccumulate) instead of storing them, and with that the same passes lose no count (measured below).Adding needs each slot to start at 0, and a list can run again with the same slots:
VisibilitySlotzeroes a window of slots when it creates one, as it already did when it reused one.Close, the list zeroes the slots it counted in with blit fills, after the sums and resolves have read them (ZeroVisibility), so the next run of the list starts from 0.visibilityResultTypeexists from macOS 26, so on older macOS the pass stores as before and the bug stays there. The MTL4 path, which is macOS 26 only, sets it too.D3D11 gets the same change in a second commit: its passes add too, and
VisibilityResultReadbackzeroes each window of slots it creates (on i386 the window's memory comes fromaligned_malloc, which does not zero it). A window is made for one command buffer and never reused, and each slot is counted in by one pass only, as before.What it changes, measured on the M1 Pro
In the plain Metal program, the same passes with accumulate lose nothing:
The occlusion scene of
tests/perf/perf_probe.pycosts the same within the noise: 0.81 ms of GPU time before, 0.81 to 0.84 ms after, about 0.30 ms of CPU in both.How to check
tests/run.py --build build --wine <wine> --family native,9,8,7,native-metal3,8-metal3 --repeat 3 d3d12_occlusion_far d3d12_occlusion_many d3d12_occlusion_passes d3d12_occlusion_replay d3d12_occlusion_wide d3d12_query_lists d3d12_query_memory d3d12_query_reruns d3d12_query_validation d3d12_query_cpu_resolve d3d12_visibility d3d12_predication d3d11_queries d3d11_occlusion_many d3d11_occlusion_wide d3d11_predicationd3d12_occlusion_wideandd3d11_occlusion_wideare the tests that fail without the change.d3d12_occlusion_replay,d3d12_query_rerunsandd3d12_query_listsrun a list more than once, so they fail if the slots are not zeroed again atClose(checked by leavingZeroVisibilityout).Evidence: test runs on the M1 Pro, before and after
MacBook Pro M1 Pro (Apple7), macOS 27.2.1, Wine 11.0, Microsoft's
d3dcompiler_47and DXC in the tests' prefix, built with-Dbuildtype=debugoptimized -Db_ndebug=false -Denable_tests=true; each run a fresh process. Commitd5a9d624: 5 files changed, 47 insertions(+), 2 deletions(-). Before and after were measured onmaina44d3c5con 2026-12-04; the commit was then rebased ontomainff7498a7(no conflicts) and the family runs repeated there on 2026-12-05.main)d3d12_occlusion_wide, dxil and dxbc, natived3d12_occlusion_widefails (the rest not run)occlusion_replay,query_reruns,query_listswithZeroVisibilityleft outa44d3c5c; 150 passed, 0 failed (×3) onff7498a7, which addsd3d12_query_cpu_resolved3d11_occlusion_wide, natived3d11_queries,d3d11_occlusion_many,d3d11_occlusion_wide,d3d11_predication, families native, 9, 8, 7, native-metal3, 8-metal3--validate--validated3d12_predicationdxil and dxbc time outd3d12_predicationdxil and dxbc time outSpeed:
tests/perf/perf_probe.py run --scenes occlusion --repeat 5 --keep median, builds alternated, GPU ms of each run: before 0.811 and 0.814, after 0.805, 0.838 and 0.833. D3D11, the occlusion scene ofd3d11_perf_probe(500 queries a frame), same settings, frame time: before 0.203 and 0.212 ms, after 0.201, 0.199 and 0.196 ms; its GPU timer read 0.000 ms in some runs with and without the change, so it is left out.The plain Metal program, 3 runs of each case, each case in its own process (counts that read wrong):
main)What was not run
--family. I left the change on for every family because adding gives the same result wherever a pass keeps its stored counts.--validate,d3d12_predicationtimes out with and without this change, so it could not be checked under validation.