metal: a typed buffer view written back into a heap entry names the texture made for it before (#47) #398
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/398"
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 Tarraga on 2026-11-27T16:44:29Z.
Refs #47. This covers only the piece I claimed there: typed buffer views made again as new textures.
What this changes
Problem
The title writes the same records into its shader-visible heaps again and again (#43). Each record mirrored again is a raw view first.
materialize_typed_buffersthen promotes it again at the next draw that reads it typed. Every promotion callednewTextureWithDescriptorfor a texture buffer the heap had held before, on the submitting thread, under the host's lock.Evidence
From one run of main
4cf84c83(M4 Pro, 48 GB, Series S, headless, 425 s, reached the cell). The numbers come from main's own lines,typed_viewsonnative draws so farandnative typed buffer views:Our working branch also mirrors whole heaps at submission, so it mirrors more entries: 10,500 a frame there against about 160,000 live. Those numbers are not main's.
Cost of one view,
typed_view_cost(10,000 views, three runs each):At main's rate, that saves about 7 ms of a world frame under the lock. At about 1.3 fps, that is roughly 1% of the frame. It's a small gain, and I'm not claiming more.
Fix
Metal::write_typed_bufferkeeps the texture it makes, keyed by buffer, offset, width, pixel format and writability, and names it again when the same view is written back.VICTORY_TYPED_VIEW_CACHE=<entries>) the cache is emptied and starts again.Default
The cache is on by default, and this does change behaviour for others: a buffer the host has let go stays alive in the cache until the next reset, together with its texture objects. It does not change what any entry holds, and its cost doesn't depend on the GPU's speed. That is why I left it on.
VICTORY_TYPED_VIEW_CACHE=0makes a texture every time, as before. If you would rather have it off until someone with 16 GB has run it, I'll flip the default.How it was tested
gfx::typed_view_tests::a_typed_view_written_again_reuses_its_texture_and_others_get_their_own(victory-metal, on Metal). It writes the same view into two entries and back into the first, then views that differ in offset, width, format or writability. It also replaces an entry with a raw view and promotes it again, and checks the entry words andtyped_viewscounts throughout.VICTORY_TYPED_VIEW_CACHE=0(what main does) it fails:left: (3, 0) right: (1, 2), three textures made instead of one.cargo test -p victory-metal --lib --releaseon arm64: 43 pass, 2 ignored (benchmarks).cargo xtask policypasses.x86_64-pc-windows-gnullvmtarget); I'm leaving it to CI. Host clippy shows no warning in the changed lines.4cf84c83. The rebase ontob998bb65only bringscrates/victory-metal/tests/resources.rsinto victory-metal, not the library.Checklist
VICTORY_TYPED_VIEW_CACHEand documented in docs/native-host.md (diagnostics list and "Typed and structured buffer views lazily carry a Metaltexture_buffer")Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T17:14:54Z.
Review: APPROVED
Read the diff: typed buffer views re-promoted from a heap entry now name (cache) the texture made for that entry before, instead of calling
newTextureWithDescriptoragain on the submitting thread per re-promotion — 158/-19 ingfx.rs, smallmetal.rsaddition, docs paragraph added. Verified on the headbc4bdda:cargo test -p victory-metal --lib43 passed / 0 failed on this M3 Pro, and the workspace windows clippy with-D warningsis clean. Approving.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.