Mesh shaders on Metal: outputs stored after their values, and kept under Metal's 32 KiB output limit #33
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/33"
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T10:46:37Z.
What. Two Metal Shader Converter / Metal problems with mesh shaders, fixed in the translator.
Options::mesh_stores_laststores each export's outputs after all their values.container::metal_record).Options::mesh_pack_outputsorders the outputs of a mesh over the limit for the smallest record, found exactly (a search over the elements left of each size and the offset modulo 48), then leaves out clip distances that are +0.0 at every vertex. Left-out outputs keep the console's 16-bit slot map. TheemitAPI (Kept,translate_keeping,pixel_reads(_channels),stages_link) can leave out or narrow outputs a pixel shader doesn't read; the D3D12 host's per-pipeline pruning is not part of this PR.Measured on the Wine route (D3DMetal, the same converter): 30 of 302 mesh pipelines crashed the compiler before, none after with
mesh_stores_last. Of 797 mesh+pixel pairs over the limit, packing alone fixed 584 (measured with the earlier greedy order; the exact search can only fit more). On this tree with Apple's standalone converter, Metal's reported sizes match the count exactly.Where on. D3D12 host under Wine, where D3DMetal hits both problems (
VICTORY_MESH_STORES_LAST,VICTORY_MESH_PACK=0|1). Off on the native host until it has mesh pipelines, and on real Windows. Off, translations are byte-identical: through the native host's path, all 19,105 shaders of a capture give DXIL identical to main with the native defaults.Also.
lower::Parts::newgives tests a default, so a newPartsfield no longer touches every test. Tests use synthetic layouts only. Findings in docs/native-host.md.Tests: cache-key test (
host_workarounds_change_the_cache_key, Windows-only module: compiles under Windows clippy, not run on macOS); the reviewer's 32,768-byte packing case and two cases no order fits; the 16-bit slot map with an output left out. victory-shader 231 passed, victory-gpu 144 passed; Windows clippy andxtask policyclean.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:00:20Z.
Review: CHANGES_REQUESTED
Thanks, the analysis is thorough and the translator side (stores-last, packing,
Kept/translate_keeping) reads well, with good tests that run on macOS. Before this can merge:Parts { ... }initialiser incrates/victory-shader/src/emit/gfx_refusal_tests.rs(4e3689d), which lacksdropped_rows, socargo test -p victory-shaderand clippy--all-targetsfail with E0063. Please rebase and add the field. ADefaultor a constructor forPartswould stop this recurring.options_build/host_shader_keeping) changes withmesh_stores_last,mesh_pack_outputsandKept.pruned_mesh,Stage.own,Shader::kept,mesh_prune, the_keepingcache plumbing and the windows-only draw test. They are about 250 lines for a path this port is moving away from, and they keep every mesh and pixel container in memory under Wine. Please keep theemitAPI (Kept,translate_keeping,pixel_reads*,stages_link) and its tests.docs/macos.mdbullet, and put the findings indocs/native-host.md. Please also makeVICTORY_MESH_*parsing consistent between the two hosts: read once, exact "0"/"1".1c451759513efb4c,ac82b7984c664350,da22b2adfd4f76d3) with synthetic layouts. The project keeps nothing taken from the game in the repo, including metadata.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:22:19Z.
Review: CHANGES_REQUESTED
Thanks for fixing the fixture. The earlier requests are still open:
Kept's key concatenates name and index with no delimiter, so("ATTR", 12)and("ATTR1", 2)collide.docs/macos.md) with synthetic data.docs/native-host.md.0/1, read once.Also, please remove the AI
Co-Authored-Bytrailer from 1b0b393. This repo doesn't take AI attribution lines.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T11:53:33Z.
Thanks for the review. All six points are addressed:
lower::Parts::newgives tests a default, so newPartsfields no longer touch every test initialiser._keepingkey gone (point 4), the key logic is a plain function,options_key(same bytes as before).host_workarounds_change_the_cache_keychecks thatmesh_stores_last,mesh_pack_outputsand both together each change it. The module is Windows-only: the test passes Windows clippy but hasn't run on my Mac.pruned_mesh,Stage.own,Shader::kept,mesh_prune, the_keepingplumbing and the windows-only draw test. TheemitAPI (Kept,translate_keeping,pixel_reads*,stages_link) and its tests stay.VICTORY_MESH_*once and accept exactly "0"/"1".Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T11:56:48Z.
@LakshanSivakumar ready for another look when you have time. The review points are addressed above.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:01:51Z.
Review: CHANGES_REQUESTED
Thanks for switching the native defaults off, replacing the fixtures, and removing the pipeline-pruning path. Two correctness cases remain:
emit/mod.rs~782 vslower.rs~11877). If two FP16 elements share an export and the first is pruned, the kept one moves.container.rs~150 can miss a layout that fits. For example, position + twelve float4 + four float3 at 128 vertices gives 33,792 bytes, while placing the float3s after the first two float4s gives exactly 32,768. Please add that case.Please also remove or disambiguate
Kept::describe()(("ATTR", 12)vs("ATTR1", 2)), confirm whether the remaining Wine defaults inshader_cache.rs~123/138 are intended, and squash or rebase so the earlier title-derived layouts and IDs (in efdff7a and 8abe1d0) aren't in the landed history.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:36:39Z.
Thanks. All points:
Partsnow carries the left-out elements themselves (dropped: Vec<SigElement>) instead of only their rows, and the 16-bit slots inexport()are worked out from kept plus left-out elements, so the console's layout is kept.a_kept_16_bit_output_keeps_its_slots_when_one_before_it_is_left_outhas two FP16 elements sharing a row with only the second kept; it fails without the fix.Kept::describe(): removed. It had no callers outside tests, which now compareKeptvalues.mesh_stores_last()andmesh_pack_outputs()default tounder_wine(): on for the D3D12 host under Wine, where D3DMetal hits the crash and the 32 KiB limit, off on real Windows and on the native host.VICTORY_MESH_STORES_LAST/VICTORY_MESH_PACKoverride with 0/1.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:38:45Z.
@LakshanSivakumar ready for another look when you have time. The review points are addressed in the comment above, and the branch is squashed to one commit.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:46:42Z.
Review: APPROVED
Thanks, all five points check out. The kept-FP16 fixture fails without the
droppedchain, the exact packing finds the 32,768-byte case,describe()is gone, the Wine defaults and exact 0/1 parsing are clear, and the squashed commit has no title-derived IDs or layouts. The aggregate counts in the docs (pipeline and pass counts) are fine as observations. Approved.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T13:17:18Z.
Closing this: I'm continuing this work on my fork, 64bitMango/Native-Victory-macOS, where it's merged with the other open PRs (#33–#37). Thanks for the thorough reviews; the fixes from your latest feedback are included there.
Pull request closed