WIP: perf(macos): batch the mesh fallback's draws of a pass on MoltenVK #783
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/upscaling
beanstalk: approved @ 1697603
beanstalk: approved @ 2c5a62e
beanstalk: approved @ 4fd82b7
beanstalk: approved @ 64d6d09
beanstalk: approved @ 6f91fae
beanstalk: approved @ 70a78f9
beanstalk: approved @ 8d361dc
beanstalk: approved @ 9d8356e
beanstalk: approved @ abf2227
beanstalk: approved @ d82f202
beanstalk: approved @ e5f1e40
beanstalk: approved @ ee8ab5f
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
testing wanted
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!783
Loading…
Reference in a new issue
No description provided.
Delete branch "mooki/Longshot:mac/mesh-batch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: perf · Risk: medium · Tested on: macOS 26.7.1, Apple M4 Max (MoltenVK main 5189f8de + argbuf-slots), arm64 and x86_64 under Rosetta · Needs: macOS, Apple silicon (the E-series runs and a start to play on the rebased stack); Windows and Linux, any GPU (build and start)
Why
The Mac has no mesh shaders, so the game's mesh programs are drawn through the compute fallback: a draw's task and mesh stages run as
dispatches (after an argument conversion for an indirect draw), then its triangles are drawn. Dispatches cannot run inside a render
pass, so each fallback draw ends the pass and begins it again, and on Apple's tile GPUs every such break stores and loads every
attachment. In run #31's field-dawn hold 74.8 of 76.9 fallback draws a frame broke their pass, 72.2 of them in runs one pass could
hold. This PR draws a run of fallback draws on the same targets in one pass on MoltenVK, their dispatches first, with the same results.
It is part of the macOS port's performance work (MacPerf §4 #8). See #420.
What changed
On MoltenVK the first fallback draw of a pass records its dispatches as before and opens the pass in a secondary command buffer. A
later fallback draw that may join (same targets, no draw of the pass that may write memory, its program writing none, no attachment
the pass wrote sampled, fewer members than the cap, a records set within the allowance) records its conversion and dispatches into
the recording's command buffer before that pass, into a records set of its own, and its draw into a new secondary: a segment. When the
pass ends, the recording begins its rendering with secondary contents and executes the segments, ending and beginning it again (after
LS's pass-start barrier) where a segment must be a pass of its own. Every pass end with batching is one the replay makes without it.
gpu/vk/mesh_batch.h(new, CPU only:State::join,split,draw,runs; the refusals by reason).gpu/vk/vk_draw.cppmesh_batch_open(frombegin_passfor a fallback draw's pass),mesh_batch_joinandmesh_batch_member(indraw()),mesh_batch_segment_begin,mesh_batch_emit(fromend_pass),desc_carryanddraw_binds_carry(what a draw keeps bound, carried into each new command buffer),MeshBatchOwed(the pass end a held-backconversion owes);
fallback_record,fallback_record_count(#707's count draws) andmesh_indirect_converthold back their pass endfor a joining member;
batch_records_ofmakes the members' records sets, each the size of the set the draw would use (the samearea, header and rotation: #708's
provoking_fallbackdecides alike), within the renderer's allowance (#707'smesh_area::affordable).gpu/vk/vk_loader.hloadsvkCmdExecuteCommands;vk_recorder.h/vk_work.hcarry it;vk_replay.cppprints the
vk: mesh batchline with the frame statistics.RX_VK_MESH_BATCH(0off,<n>members 2-64, default 8), MoltenVK's driver only, off with the recorder thread, theparallel replay, dumps, probes,
RX_VK_DRAW_STATSandRX_VK_BARRIER_EVERY_DRAW. The bench's B1 arm:RX_VK_BENCH_AB=mesh_batch(with
RX_VK_MESH_BATCH=0, so A is off).94fca509, tests only): a batch's pass begins from #780'sps.lead, a batch opens only for a fallback draw's begin and a begin is held only for a foldable clear's, so a pass is never both;end_passsettles a held begin, then emits the batch.test_load_clearruns the mesh batches in its fixture;test_widen8holdsthe widening at the draw before a batch's segment and the look ahead's stop at a mesh draw. With #780 and #782's look
ahead off by default (Integration 40), a batch's pass begins with its loads and a restart-off 8-bit draw ends a batch, as before.
docs/development.md(RX_VK_MESH_BATCH, the bench arm),gpu/vk/VULKAN.md. Tests:tests/test_mesh_batch.py+tests/mesh_batch_test.cpp(new); the fixtures that cut the touched code get stand-ins;test_mesh_provoking,test_mesh_count_fallback,test_mesh_fallback,test_fallback_depth_hold,test_perf_linesread the new forms.Measurements
Verdict: helps: in the field-dawn hold MeshBatch is worth −1.1 ms of GPU a frame (20.2 → 19.1 ms) and +1.1 fps (32.6 → 33.7),
1.0 ms of frame, against a run-to-run noise of 0.17 ms of frame, 0.0 ms of GPU and 0.2 fps (E7); it saves 56.9 pass ends a frame. It
is exact on the GPU where probed: in MB-01 every step drew byte for byte what the unbatched replay draws.
Baseline: main does not start on macOS. The E-series runs are the integration build I39
7a7726fe(this PR's code with#780's and #782's, and the other integrated macOS topics), arm64, one run each: before is E4, all on but MeshBatch
(
RX_VK_MESH_BATCH=0), after is E2, all three on (I39's defaults; #780 and #782's look ahead are off by default here,as Integration 40 made them, each measured under the noise). This head's MeshBatch, LoadClear and Widen8 functions are I39's text
exactly. For scale, E3 (all three off) ran 32.3 fps, GPU 20.5 ms: all three on are 1.29 ms of frame and 1.4 fps (+4.3%) faster
(
reports/2026-11-15-mac-perf-before-after.md).Hardware: macOS 26.7.1 (25G241), Apple M4 Max (40-core GPU), MoltenVK main 5189f8de + argbuf-slots (
c170a745), 16-core CPU, 64 GBScene: the field-dawn save, slot 00, entered by START and A×5, then 600 s held in play, windowless; the instrument set on in every run
(
RX_VK_PERF_LINES=1,RX_VK_GPU_TIMELINE=1, the present trace); quiet required before each start, the other lanes pausedMethod: the medians of the hold's 120-present periods from +20 s (E4 158 periods, E2 141; the bench's and the chain's periods left
out of E2); one run each, the noise from E7 (a repeat of E2: 0.17 ms of frame apart); runs
mac-arm64-7a7726fe-04(E4),-02(E2),-08(E7),-03(E3); reportsreports/2026-11-15-mac-perf-E4.md,-E2.md,-E7.md,-E3.mdHow to reproduce: the series'
ls-run.py prepare/runcommands and common switches (reports/2026-11-15-mac-perf-runs-i39.md§2-§3),with
RX_VK_MESH_BATCH=0for the before runvk: mesh batch: pass ends saved a frameMB-01 (exactness on the GPU; review
c7b37d4c…,LS_COMMIT29b93740;reports/MeshBatch-files/mb01/runs-mb01-arm64/result.json,35d1d2d5…, released once on arm64 by the parent,reports/2026-11-14-mesh-batch.md§5): each of 8 steps recorded unbatched (U)and batched (B) in one standalone MoltenVK process with the PR's own
mesh_batch.h; both colour attachments, a memory-writing draw'sbuffer and the occlusion results compared. Passes U → B: a run of 6 6 → 1, the cap 10 → 3, a target change 4 → 2, indirect 6 → 2;
B equal to U in 8 of 8 steps; both controls (merged without the real split, unsealed) differ from U, as predicted
(
all_as_predicted 1,batch_exact_on_moltenvk 1).Flags and settings
One new switch and one new arm of #704's bench switch; on by default on MoltenVK only.
RX_VK_MESH_BATCH=0or<n><n>members (2-64)0off; read onceRX_VK_BENCH_AB=mesh_batchRX_VK_BENCH(andRX_VK_MESH_BATCH=0)Testing
Tested: on macOS 26.7.1, Apple M4 Max:
94fca509, on #7827fd975fbwith #708 merged):test_mesh_batch(45 checks, 0 failures; 20,000 randomstreams, 465,859 pass ends down to 373,389; 13 of 13 mutants killed),
test_load_clearandtest_widen8(82,412 checks) pass onarm64 and x86_64; on the base
a4d99ff3with this head's tests all three fail, both arches (mesh_batch.hnot included; nopass_keeps; draw()'s widening not after the fallback's dispatches). Every check whose test or fixture this PR or its merged basechanges passes:
test_count_draws,test_draw_binds,test_draw_side_effects,test_draw_stream_visibility,test_drawid_direct,test_fallback_buffer_cleanup,test_fallback_depth_hold,test_fsr_uniform_ownership,test_index8_bind,test_mesh_area,test_mesh_census,test_mesh_count_fallback,test_mesh_drawid,test_mesh_fallback,test_mesh_provoking,test_null_descriptors,test_null_layout_push,test_perf_lines,test_provoking_first,test_recorder_sync,test_recording_admission,test_resolver_coverage,test_sampler_admission,test_seg_gathers,test_seg_xfer,test_texel_views_plan,test_tls_objects,test_vendor_fixes,test_vk_occlusion_queries(both arches wherethey build; source-only ones on arm64).
vk_draw.cpp,vk_replay.cpp, the four SPIR-V back-end files andhost/nvn_native.c#707 brings compiled whole for both arches, 0 warnings (
reports/PubWave-files/PubLate5/PerfTrio/proof/,compile/mesh-batch-94fca509/,-host/).macos/mesh-batch29b93740on the integration branch I383f872b0c):tests/test_mesh_batch.py+tests/mesh_batch_test.cpp(a model recorder mirroringvk_draw.cpp's decisions over a tile-GPU model; every write and read in GPUorder, batched against unbatched): 45 checks, 0 failures, 20,000 random streams (465,859 pass ends down to 373,389), 6 of 6
controls and 13 of 13 mutants caught; the 66 checks that touch the changed code and
test_tls_objectspass; 25 files compiled wholefor both arches; full suite 586 passed, 1 failed (
test_menu_i18n, as on I38), 16 skipped (reports/2026-11-14-mesh-batch.md§4).7a7726fe):test_mesh_batch,test_load_clear(6,000random sequences with 5,512 batches: each batch's begin loads every attachment, none opens inside a pass or on a held begin) and
test_widen8, both arches, among 103 of 103 checks; full suite 588 passed, 1 failed (test_menu_i18n), 16 skipped.unifdef -U__APPLE__, the basea4d99ff3against this head): every changed file differs, the change being gated by thedriver (
reports/PubWave-files/PubLate5/PerfTrio/offapple-mesh-batch-own.txt).Known gap, being fixed: draws that depend on the provoking vertex are left out when their list finds no room in the
recording's stream (
vk: a draw depending on the provoking vertex left out: no room for its list in the stream …).a frame.
A fix that never leaves a draw out for lack of stream room is in progress, and this PR stays WIP until it is in the stack.
Not tested: the three together on the GPU (a held begin next to a widening, a batch after leading clears on other targets:
reasoned and CPU-tested in Integration 39, not probed); MoltenVK 1.4.2 in MB-01; any driver but MoltenVK (never on there); not
built on Windows or Linux; its test request covers it.
Must be tested:
RX_VK_PERF_LINES=1, expecting thevk: mesh batchline to count batches and pass ends saved,L6's splits to fall as in E2, and the GPU time per frame near E2's(by hand: the parent's next runs).
94fca509, it carries #782, #708 andwhat they carry) and #782's head with #708 merged (
a4d99ff3) the same way, start each to the title, expecting novk: mesh batchline, every other line as there, and the same picture (by hand: test request T-XXXX).
Risks
What could break: on MoltenVK only: a batch's pass is recorded in secondary command buffers and executed at its end; a joining
member's dispatches run before the pass's earlier draws (never past a draw that may write memory, never reading an attachment the pass
wrote); up to 7 more records sets a recording thread, made as runs need them within the allowance (a member that cannot get one is
drawn as before). A restart-off 8-bit draw that needs a widening at the draw (#782) ends a batch.
Turning it off:
RX_VK_MESH_BATCH=0, or revert the PR.Compatibility: Nothing changes for players outside macOS. No file in the shader stamp changed; no
MKWVK_API_VERSIONchange.Reviewer notes
a4d99ff3..94fca509for this PR's own work (3 commits):cherry-pick -xofmacos/mesh-batche73a3a1fand29b93740, thenIntegration 39's fix B
7a7726fe(its change line for line).7fd975fb..a4d99ff3is its base:49b8ae6amerges #708 (mac/mesh-provoking881408f9, carrying #707 merged into #703): this PR holds back #707'sfallback_record_countpass end, sizes a member's records set as #707's growing area so #708's rotation decides alike, and itstests follow #708's. Conflicts resolved as Integration 36/37 has them (the includes;
count_rewrite_recordskeeps #704'swhy(CountDraw)before its end_pass; the report declarations; both lanes' blocks intest_resolver_coverage). Its change fromthe first parent is #708's change from #703, line for line, but for
merged_sites' list.a4d99ff3= Integration 36'sb4732392(-x): #707's count draws' own pass end saidMeshFallback(the line this PR then holdsback), and the two checks that follow #707's moves (
test_perf_lines,test_drawid_direct).70e25167resolved them:begin_passbuilds the rendering info from #780'sps.lead, gives it tomesh_batch_open, then holds the begin for a leading clear, else records it unless a batch opened; the twoclears keep #780's
begin_pass(…, lead)withmesh_batch_cmdright after it, the depth clear's batch note before thefold-or-clear;
end_passsettles, then emits, then ends the rendering; theRX_VK_BENCH_ABrow names the three arms. Left out asnot in this stack: #702's FanIndirect declaration and report block, #686's
memory_import_refusal_reportline, #705's quads paragraphin
VULKAN.md, #696's and #697's docs rows. These functions,load_clear.h,widen8.h,mesh_batch.hand the three tests areIntegration 39's text exactly.
#707 in main,
a4d99ff3is theirs (drop it if main has it).Linux GPUs without mesh shaders) is a separate PR.
e090cc48; main has moved since, and a delta sweep follows.Issues
See #420
Checklist
Everyone
type(scope): description) of the status line's type.main. (On maine090cc48through #782 and #708; main has moved since: a delta sweep follows.)python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (At this head94fca509(wave P): 585 passed, 31 failed, 18 skipped against main e090cc48's 544/32/17 on this Mac; the 31 failures are main's own and nothing that passes on main fails;test_collect_widenow passes; 40 new tests pass;reports/PubWave-files/PubLate5/wave/full-P-94fca509/.)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.tests/that reads changed source updated in this PR, not weakened.Every scan down vk_memory.cpp's import table by start (pool_lookup's covering import and merge plan, bg_drain, prefetch_chunks, import_in_background, memory_note_gpu_write and memory_guest_imported) stopped once an import ended more than 1 GiB below its address, on the belief that no import is larger than that. pool_lookup's own merge escape leaves an import above 1 GiB over the smaller ones inside it ("left overlapping"), and the device allows imports up to max_import_size: a scan stopped at a small import inside a large one, missed the large one, and the same bytes were imported again, two memories over the same bytes. import_reach.h counts the live imports by span class; its bound is above every live span, within twice the largest. imported_add and imported_take, now the table's only ways in and out, keep the count. A scan stops only where no import further down can reach its address, so it also stops sooner than before when the imports are small. The covering-import checks in pool_lookup and import_in_background look past the last import at or below the range for the same reason. Tests: test_import_reach.py runs the actual scans with a 4 GiB import over a 16 MiB chunk, left by the merge escape (imports are recorded ranges: no payload, no Vulkan, no game). Its lookup, query, note, drain, background and prefetch cases fail on main5e072fc8and pass here, and a source check keeps every change to the table in the two helpers. test_import_windows runs pool_lookup with the helpers; test_mirror_gpu_only names the new publication point. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]>A guest span larger than one device allocation (the cap on MoltenVK/M4 Max is 41,747,087,360 bytes) is bound as pieces: one descriptor per allocation segment, at the descriptor's own binding (reports/2026-11-14-full-range-design.md sections 4.1-4.4). This is the shader half; the draw side (descriptors, layout, gathers) comes later. - runtime_info.h: SegEntry {Storage|Table|TexBuf|ImgBuf, desc, pieces} and RuntimeInfo::segmented. - Back end: a segmented storage buffer is an array of pieces at its binding (a table count * pieces, entry k's piece j at k * pieces + j); its loads, stores and atomics call DontInline helpers made after main, which find the piece by the pieces' OpArrayLength in order, with constant indices. The global memory fallbacks sum the pieces' lengths for a segmented descriptor's bound end and branch to its piece (single, native candidate, table written out and in the loop). Texel and image buffers are arrays too, their fetches, reads, writes and atomics through helpers that pick the piece by OpImageQuerySize, and a texel buffer's size query sums the pieces. ImageQuery was declared for every module already. With RuntimeInfo::segmented empty nothing new is made: the SPIR-V is byte-identical. - vk_shader: SegSig (entries, hash) on Program, seg_sig and seg_variant; program_segmented finds or translates the variant of a plain program with plain's texture questions and answers and checks its descriptors are plain's; program_pick, mesh_program_locked, program_find_plain, loaded_variants and portable_variant keep the plain and segmented variants apart; every stage's RuntimeInfo::segmented comes from Program::seg. - vk_progcache: a segmented variant is never written to the program cache nor listed among the loaded programs. - tests/test_seg_shader.py + tests/seg_shader_ir.cpp: synthetic IR programs through the real back end, plain and segmented; structure checks, spirv-val (Vulkan 1.3, uniform buffer standard layout), and with --base-tree a byte comparison of the plain modules against an older tree. Five source-reading checks follow the new Program field and the atomics' new branch. The translator stamp changes with this (eden/, vk_shader.cpp, sizeof(Program)): every program cache is rebuilt once. Land it in the same release as the vk_api.h change that already does so. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit b7928876dab846485f667c1c934d34d25ecef035)044635ea added vma_startup_rollback (vk_vma.cpp, run after a failed replay_start), which calls vmaDestroyAllocator. vk_vma.cpp includes vk_work.h last so that RX_VK_RECORDER=defer/thread drains before its destructions, and every such boundary call in a vk_work.h file must be in RX_REC_BOUNDARIES with a drain-first macro. This one was not, and test_recorder_sync caught it ("vk_vma.cpp calls ['vmaDestroyAllocator'], which vk_work.h does not drain before"): it passes at 58c5c5aa (044635ea's parent) and fails at 044635ea. Add it to the list and to vk_work.h, next to vmaDestroyBuffer and vmaDestroyImage. With the recorder off (the default) boundary() is a relaxed load and a branch. Rollback runs before any image or buffer exists, so nothing should be held there today, but the allocator is no longer destroyed while a recorder could still hold packets. The test is unchanged (sources: 42 boundaries drained, was 41). Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]>The interfaces the four segmented-consumer lanes (SegBind, SegXfer, TexelDesc, NullShader; reports/2026-11-14-seg-consumer-plan.md section 3) code against, frozen before they fork. Inert: no caller of anything new, no SPIR-V, layout, push range or stream change, sizeof(Program) unchanged. - vk_internal.h / vk_memory.cpp, SegMem's consumer interface: gpu_span_any() (a relaxed count of the live domains, stored in seg_commit; domains are kept for the run), gpu_span (gpu_buffer's flavour of gpu_span_bind: import buffers, no written marks, no mirror), SpanLayout::bind_stamp (gpu_bind_stamp(): a segment can be imported again with its cuts kept, so cut_gen alone never keys piece buffers), span_unused_piece's semantics ({null_storage, 0, 1}), and the SegArena API (SegArenaRef, seg_arena_take, seg_gather, seg_scatter; stub bodies after stream_alloc that give no room and log, SegBind's to fill). - Review fixes in the same interface (renderer-core review P2-3, P3.2): every piece of gpu_span_bind carries its buffer's device address (the import's or the mirror's; 0 only with bufferDeviceAddress off), and its one-piece path stores the translated guest address, not a virtual one. - vk_texture.h/.cpp: texel_view_pieces / texel_piece_views, stubs that return 1 and false (TexelDesc's to fill). - vk_shader.h: Program::presence_words, in what was padding. - Back end: PRESENCE_PUSH_OFFSET (88), Profile::emulate_null_descriptors, Bindings::presence / presence_read with the bit numbering rule. - tests: test_resolver_coverage lists gpu_span_bind / gpu_span sites too (scoped to gpu/vk: gpu/render has an rx::gpu_span of its own), checks that gpu_span follows its own gpu_buffer, and splits SITES into SITES_BASE plus one block per lane. test_segmented_domains executes the contract (the count 0, 1, 2 -> 1 on a merge, 0; gpu_span's pieces; addresses with the fixture's gpu_buffer_bind returning none as the real one does; the bind stamp; a virtual address's guest). test_seg_shader accepts a base tree of this back end's generation and compares every module. - docs/segmented-binding.md: the gate (every new behaviour Apple-only, other platforms byte-identical) and one heading per lane. Conflict on this branch (not with main): tests/test_seg_shader.py's docstring, against the array_pointer_calls paragraph #P20's msl-arrayptr port added; both kept, this paragraph first. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 95fa06d4e6526601bd2e1bc88c2f8f5720855350)The segmented single storage array's case (plan 4.3 item 5) had no negative: the check always cut its own tree. With --source <B2 archive> it fails as required ("moltenvk.segmented_single want=set got=push"). Conflict with #P28 (read_write textures; not with main): the docstring keeps #P28's paragraph with this usage line, and main() cuts from --source's vk_draw.cpp with #P28's read_write count (as in the macOS integration, Integration 17). Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 5824f6828e21cf810dcceaa6be425a9224b15994)plain7a498e5865plain1e1a3b3e0dKosmicKrisp has no fillModeNonSolid and MoltenVK no POINT polygons, and Metal restarts an indexed strip or fan at the all-ones index whatever Vulkan's restart enable says. Before anything is fixed, count whether the game needs it (mode_census.h, Apple only; nothing built or drawn changes): - the graphics pipelines built, where st_pipelines counts them, and the draws recorded, where st_draws counts them, by NVN's polygon mode, with the first 8 LINE and POINT pipelines (program, pipeline key, topology) and programs named; - the indexed strip and fan draws with restart off; a direct one's indices are read whole, a page at a time, through memory_read_as_submitted for the index type's all-ones value (0xFF, 0xFFFF, 0xFFFFFFFF). An indirect one's range is the GPU's and a range the CPU cannot read is not guessed: both are counted as not scanned. Any other draw costs restart_off_strip's compares and its polygon mode's count on the thread's own counters. Printed with the frame statistics every 120 presents ("at present N") and at close ("at close"). The two tests that compile build_graphics and draw()'s binds from the source get a stand-in for the counts. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 1bd30dceb348909ca03c4cf12709dccbb0900f4a)DI-01 (reports/2026-11-14-drawid-direct.md) ran the direct and one-record indirect forms on MoltenVK 1.4.2: the indirect form was exact in every shape (0 stale of 3,744 draw indices), and the direct plain, indexed and quad draws read stale words, but tessellated direct draws read draw index 0 (64 of 64, with update tags in the pool) while their indirect form took about 135 MB of GPU memory and 3 ms of submit a draw. So 3f1ee3da's choice to keep them direct stands, and the error line it logged for each ("writes a direct draw's draw index to the wrong word") was wrong for them: they are now counted in the vk: direct draws line only, as fans are (0 of 64 stale direct in DI-01). drawid_direct.h and VULKAN.md give DI-01's numbers; the fixture expects an error line only for a first instance without drawIndirectFirstInstance. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 0a6956568f871c66b08c29dffc0a1b9614dfb5de)The mesh fallback draws one record a corner, in its mesh program's primitive order. On a device without provokingVertexLast, for a program that depends on the provoking vertex, its vertex draw is now vkCmdDrawIndexedIndirect of the same header through a static index list that reads each triangle's corners {2, 0, 1} and each line's {1, 0} (provoking::rotation): the last corner first, the winding kept. The list covers the program's record capacity (MESH_FALLBACK_RECORD_WORDS / fallback_record_words, the epilogue's fit), made once per corner count and larger when needed. The header {count, 1, 0, 0} reads as the indexed record; its fifth word, the allocator, is a first instance nothing reads (the generated vertex stage reads only its vertex index and the pipeline has no vertex input), so it needs drawIndirectFirstInstance, else the draw is drawn as before, logged. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 1aced9b7e8b5458befea4dfc38df305913332ebc)provoking_list wrote the list into the recording's stream before the pipeline was chosen, ahead of the memory admission. The admission can hand the draw to a new recording (vk_replay.cpp admission_handoff: the old one submitted and waited, a new slot begun), which then bound an index range in the old slot's stream; that stream is rewritten when the old slot is reused, possibly while the new recording still reads it. A draw left out after the decision (no pipeline yet, a segmented variant lost) also counted a list it never drew. - provoking_list decides (the same conditions; room for the list in the stream now, stream_reserve; the game's indices read on the CPU as submitted, held by the list in the thread's lent buffer) and writes nothing. - provoking_write, at the draw (after the admission and the pipeline), allocates the list in the stream of the recording the draw is in and converts into it; the draw binds that buffer. If the stream cannot grow there (device memory), the draw is left out, logged at error level and counted ("left out, no room for the list in the stream at the draw"), since its pipeline is the list's. - listed counts the lists drawn, at the draw. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 16216adc33ff7081bb3a0d3b687fbee947cb6519)PerfInstr's full_barrier asks perf_lines::bench_b("dedupe_off") (RX_VK_BENCH_AB's B arm; false unless the bench runs it). main's test_inline_write_order (#329) compiles full_barrier cut out of vk_texture.cpp, and did not compile at this head ("use of undeclared identifier 'perf_lines'"; found by the wave's full suite: the topic's base predates the test). It now includes perf_lines.h, as the topic did for test_dump_readback's fixture; its three variants (the current code and two negative controls) run as before, both compilers. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]>592cd8d3) into the provoking-vertex branch 87c384eb4fOn a GPU without VK_EXT_mesh_shader (MoltenVK, KosmicKrisp, AMD under Linux by default, Navi 21/22 task + mesh programs on Windows, GTX 10xx, RX 5000) task and mesh programs run as compute dispatches (issue 640), and fallback_record left every MultiDrawMeshTasksIndirectCount out: no dispatch takes a count, and each record needs its own draw index (reports/2026-11-14-mesh-gap.md 3.1-3.2). - count_draws.h and shaders/count_draws_record.glsl are generalized: a Layout reads copy_words words of a record and writes them, then `ones` words of 1. count_draws::plain(indexed) is the count draws' (every word copied, no ones: their records are byte for byte as before); count_draws::mesh() reads a record's count word and writes {count, 1, 1} under the count, {0, 0, 0} past it. The push block is eight words; the SPIR-V header is regenerated (glslang 16.6.0). - vk_draw.cpp count_rewrite_records holds the rewrite's commands (two full barriers, chunks, push descriptors); count_rewrite gives it the plain layout as before. - fallback_record_count: the records and count bound as draw_demands admits them (records across a segment's cut gathered into the arena), the header reset with the census row, the records rewritten into dispatch records, then per record i: its draw command emptied and its first vertex set to the allocator (i > 0; the allocator is never reset, so record i's draw command covers exactly the records its workgroups took), draw index i and its own record as the task's input pushed, the task (or mesh-only) dispatch indirect from dispatch record i, the mesh dispatch from the header, the command copied into the arena, a full barrier between steps. draw() then draws maxDrawCount commands with vkCmdDrawIndirect in one pass (one pass break a count draw), in record order, inside the occlusion query. Records at or past the count dispatch and draw nothing; records past maxDrawCount are never read. What cannot be bound or rewritten is left out loudly and counted. The fallback's records buffer is a transfer source too. - DrawID in a fallback task or mesh stage (a GLCompute entry point, where Vulkan has no BuiltIn DrawIndex) reads a pushed u32 at MESH_DRAW_ID_PUSH_OFFSET (76: the 4 bytes after a fallback task's u32 first, so no offset moves; PRESENCE_PUSH_OFFSET stays 88) and declares neither DrawIndex nor DrawParameters. Stages that do not load DrawID are emitted byte for byte as before. push_constants pushes 0 for single draws. - mesh_convert_bytes makes no 4096-record ring for a count draw where every mesh program takes the fallback. Every platform's fallback changes: count draws that were left out are drawn. Cost follows maxDrawCount: per record two dispatches, three transfers and four full barriers, then maxDrawCount draws (on MoltenVK encoded at submit). Tests: tests/count_draws_test.cpp runs the shader for both layouts (the mesh one over strides 8-20, count words 0-3, every count to past maxDrawCount); tests/test_mesh_count_fallback.py + mesh_count_fallback_test.cpp model the shader, the header steps and the epilogue's allocation under random workgroup orders (each record draws what it draws alone, in order; the census counts what a full area cuts) and check the source; tests/test_mesh_drawid.py + mesh_drawid_ir.cpp emit fallback stages with and without DrawID through the real back end (spirv-val, the pushed member, no builtin; the others byte for byte the base's); test_count_draws, test_resolver_coverage (SITES_MESH), test_mesh_fallback, test_mesh_census and seg_xfer_test follow. README and VULKAN.md say so. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit e9508f4b810c2e1859914c353b9a76cd2b8c4fa4)MeshCountDraws was written on the macOS integration branch, where fallback_record names each compute pipeline it binds for RX_VK_LMEM_LOG (private_memory_bound, MetalScratch). fallback_record_count's bind copied that line. This branch is on the count-draw rewrite, which has no RX_VK_LMEM_LOG, so vk_draw.cpp did not compile ("use of undeclared identifier 'private_memory_bound'"; the CPU tests cut the code out and passed). The line goes; the pipeline is bound as before. Whichever of this PR and the RX_VK_LMEM_LOG one lands second adds the line back, as fallback_record has it. vk_draw.cpp compiled whole for arm64 and x86_64 after the change. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]>0a61a9e7) into the provoking-vertex branch ac32b49599Semantic merge fix (Integration 37). tests/seg_xfer_test.cpp compiles fallback_record cut out of vk_draw.cpp with stand-ins for the thread's fallback draw state (fallback_draw_records, fallback_draw_offset, fallback_draw_count). eb4d0204 made fallback_record note the draw's records area in fallback_draw_area, so the fixture no longer compiled ("use of undeclared identifier 'fallback_draw_area'", i37-check-50-14/-15). It gets the same stand-in; nothing else changes. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 85675f30379af284a52f8f944bddad3f44e2400b)76cdd7a7) into the load-clear branch, for Widen8 ffb5dfbac18d552a6c) into the load-clear branch, for Widen8 dc500d80a3Widen8's draw() asks for a restart-off 8-bit draw's widening only where ProvokingFirst made no list for it (`!pv.made`: a converted draw binds its 32-bit list, no 8-bit indices), and test_widen8 reads draw()'s indirect branch up to ProvokingFirst's `} else if (pv.made) {`. #703 sits on #680 + #701 on #679, which this branch (#704 on #679) carries, so the merge brings in #680, #701 and #703. Conflicts, each kept both sides, as Integration 37 (macos/integrated 3f872b0c) has them: - vk_draw.cpp: the includes (drawid_direct.h, provoking.h, fan_key.h, then load_clear.h); #678's 8-bit tally and report, then FanKey's census report; DrawIdDirect's section and report, then PerfInstr's perf_drawn, then ProvokingFirst's section and report (right before draw(), as integrated); at draw()'s five counted draws ProvokingFirst's count line (and DrawIdDirect's record at the direct quads, FanKey's census at the quads and the rest), then PerfInstr's perf hook. - vk_draw.h: the DrawIdDirect, ProvokingFirst and FanKey report declarations, then draw_perf_op. - tests/seg_gathers_test.cpp: drawid_direct.h's include, then perf_lines.h's. The merge's change from the first parent is #703's change from #679, line for line. test_perf_lines' count of the draw sites follows in the next commit. Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]>881408f9) into the widen8 branch, for MeshBatch 49b8ae6a2d94fca509f77a196c0a99Folded into #852 (perf(macos): Mac performance on MoltenVK)
Pull request closed