native: copy textures compute writes back into title memory (VICTORY_TEXTURE_BACK=1) #151
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!151
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/151/head"
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?
@m0rff on GitHub · 2026-11-26 21:41 UTC · original
m0rff:m0rff/gpu-compute-texture-readback→main· +430 −10 · 9 files · 3 commits · merged 2026-11-26 22:38 UTCRefs #46.
This overlaps @Olima34's design on #46, which was approved and assigned there. I found no branch or PR for it yet. If one is in progress, I'm happy to rebase onto it, fold this into it, or drop this.
What
Textures a compute pass writes are retiled back into title memory, so CPU reads (the ocean height and displacement maps) see the GPU's result. Off unless
VICTORY_TEXTURE_BACK=1.Native Metal host only. The Windows path (
src/texture.rs,watch.rs) is unchanged.As in the proposed design:
Layout::tiledoes the retiling;Where it differs: there is no separate step 1 trace. Written textures are found from the unordered access views in the tables each dispatch binds, and each one copied or skipped for size is logged once, which gives the data step 1 was after.
If the title itself wrote the memory since the last upload, its bytes are kept.
Tested (M2 Pro, native arm64)
tex_fill.hlsl) writes a 64x64 RGBA8 texture inLINEAR,SW_4KB_SandSW_64KB_D_X. Once the fence value shows, title memory equals the retiled texels. The test fails with the copy-back off.cargo test -p victory-hle -p victory -p victory-gpu -p xtask, the Windows-target clippy andcargo xtask policypass.tex_fill.dxilis added to the policy allowlist, like the other fixtures compiled from our own HLSL.Not tested / not covered
@Olima34 on GitHub · 2026-11-26 21:43 UTC · original
Thanks @m0rff, and for asking. Nothing of mine is in progress on #46, so no overlap: please carry it on. Finding the written textures from the UAVs each dispatch binds is a good replacement for the step-1 trace.
One ordering point, from reading the diff (not run):
submitted()signals our fence with a separateexecuteafter the title's submission, which already carries the title's own signals.completed()(and the poll path) reads the title fences first, then runscopy_back(), which only copies once our fence has its value.So the title's fence can show a value one beat before ours does.
completed()then returns that value whilecopy_back()skips the submission as not reached yet, and a title waiting on that fence reads title memory before the copy. Two ways I see to close it:completed()and the poll, don't show a title fence value past a submission whose copy-back is still pending (clamp it to the last value whose writes are copied).A test that holds our fence back while letting the title's complete would pin it.
I now have the game running locally (M5 Pro). Once a run reaches the world I'll try
VICTORY_TEXTURE_BACK=1and post which textures get named and the frame cost.@m0rff on GitHub · 2026-11-26 22:09 UTC · original
Checked the ordering: the work's
executecarried no title signals. Those go out in later command buffers (the heldsignalaction orsignal_gpu), after the one that signalled our fence, so on one queue the title's value shouldn't show before ours unless command buffers complete out of order.I've still taken your first option: our fence is now signalled in the work's own command buffer, so it doesn't depend on that. No hold-back test, since the two can't be separated now.
Still open: a queue that waits on a GPU-written memory label and then signals could get ahead of the copy. It's noted in
docs/native-host.md.Looking forward to your world run: which textures get named, and the frame cost.
@Olima34 on GitHub · 2026-11-26 22:10 UTC · original
Thanks, @m0rff. You're right that the title's signals go out in later command buffers, and signalling our fence in the work's own buffer removes the question either way. Agreed on the memory-label case being documented rather than solved here.
On the world run: my runs reach the first world frame here (Series S, frame ~2500–4140) and then crash at the known
image+0x55e56f8, so I'll only see what gets written up to that frame. I'll build your branch withVICTORY_TEXTURE_BACK=1and post which textures it names and what it costs per frame there.@Olima34 on GitHub · 2026-11-26 22:16 UTC · original
World run with this branch (
fa7f1148),VICTORY_TEXTURE_BACK=1. Apple M5 Pro, 48 GB, Series S, windowed. It reaches the first world frame and then the knownimage+0x55e56f8crash (frame 2671, +140 s), the same as without the branch.Textures named: 22 copied back, each logged once. Nothing was reported as skipped for size.
Cost: no measurable change in frame rate over the same stretch. Frames 2048–2560 run at 28.0 / 24.0 / 9.3 / 21.2 / 19.3 fps with the branch, against 28.0 / 26.9 / 11.0 / 19.8 / 17.4 fps on the same Mac without it, within run-to-run noise.
One thing to check: the PR says mip chains and 3D textures aren't covered, but the log reports 4 Tex3d and 3 mipped textures as copied back. If only mip 0 / slice 0 is retiled, those may be partly written back. Either skip them (log once), or make sure every mip and slice goes through
Layout::tile.Whether boats float can't be seen yet: the crash comes first. I'll rerun once we get past it.
@m0rff on GitHub · 2026-11-26 22:24 UTC · original
No partial write-back:
downloadgoes over every mip and array slice, and reads a 3D mip with its full depth. "Not covered" meant untested, which was unclear.06b5e46adds an upload/download round trip for 1D, mipped 2D (5 and 9 mips), a 2D array, and 3D with and without mips, inLINEAR,SW_4KB_S,SW_64KB_SandSW_64KB_D_X; all match. It shows nothing is dropped, not that the layout equations match the console, since both directions use them. A dispatch writing those shapes is still untested.Also fixed: a texture skipped on its first completion was never logged afterwards, so your 22 may be an undercount.
Thanks for the run. I've added the numbers to
docs/native-host.md.@Olima34 on GitHub · 2026-11-26 22:28 UTC · original
Thanks, that settles it: every mip and slice goes through the download, and the round trip test pins it. I'll rerun with this branch once we get past the world frame here.
@LakshanSivakumar on GitHub · 2026-11-26 22:38 UTC · original · approved these changes
Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!