gpu(native), metal: refused fills land in the GPU's order, not on the… #445
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!445
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-441"
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?
@ShivamCodesBS on GitHub · 2026-11-27 18:48 UTC · original
ShivamCodesBS:fix/cpu-fills-wait-for-earlier-passes→main· +227 −40 · 4 files · 1 commits · merged 2026-11-28 00:38 UTC… CPU at submit
A pass submit_passes cannot encode was dropped and the host paid its fills on the CPU at submit time. That let a queue the fence releases, or a value wait the CPU polls, go on before this command buffer's earlier GPU passes had run (#80): on the console the refused pass's value write ran in the GPU's order, after the earlier passes and before the fence signals.
Now the backend re-encodes a committed submission's refused fills as a blit pass of the same command buffer (a blit fill always encodes: no attachments, no pipeline), before the fence signals; copies are not re-encoded (a copy may have partly run, its source may have changed). When a piece boundary stops later passes from being encoded (next_piece failed), their fills are attached to the last committed piece's Owed and paid from its completion handler, after that piece's GPU passes have run, failed or not. The host pays fills on the CPU only when nothing of the submission committed (no GPU work in flight).
Tests: owed_tests::fills_attached_after_a_piece_commit_are_paid_by_the_completion; vertex_tests::a_committed_failure_leaves_the_fills_to_the_backend replaces only_the_fills_of_refused_passes_are_paid_on_the_cpu, and an_uncommitted_failure_pays_every_fill_on_the_cpu covers the uncommitted path.
What this changes
How it was tested
cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victorycargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warningsChecklist
VICTORY_*variable and documented@Olima34 on GitHub · 2026-11-27 21:00 UTC · original
A bug in this PR as it stands (head
e8399a9d), incrates/victory-metal/src/gfx.rs. The completion handler is now registered withcb.addCompletedHandler(&failed as *const _ as *mut _), where it was&*failedbefore.failedis ablock2::RcBlock, so&failedpasses the address of theRcBlockwrapper rather than of the block itself. Metal would then call into memory that isn't a block. It should stay&*failed.@Olima34 on GitHub · 2026-11-28 00:37 UTC · original · requested changes
Thanks for this, the idea is right: a refused pass's fill belongs in the GPU's order, not on the CPU at submit time (#80). We read the whole diff (head
e8399a9d) while helping the maintainer clear the queue, and two things need fixing before it can merge:crates/victory-metal/src/gfx.rs:1650(from our earlier comment, still there):cb.addCompletedHandler(&failed as *const _ as *mut _)passes the address of theblock2::RcBlockwrapper, not of the block. Metal would call into memory that isn't a block on every completed command buffer. It must stay&*failed, as on main (and as line 1509 still does). The new testfills_attached_after_a_piece_commit_are_paid_by_the_completioncallspay_refundby hand, so it doesn't reach the real handler; a test that commits a real piece and waits for its completion would have caught this.Owed::pay_refundcan pay twice. It readsrefundunder the lock but leaves it in place. If the completion handler runs betweenattach_refund's store and itscompletedload, the handler pays, thenattach_refundseescompletedand pays the same fills again, possibly over a newer value the title wrote in between. Taking the vector out under the lock (std::mem::take) inpay_refundmakes each fill paid exactly once; a test for "attach after completion, then a secondpay_refundwrites nothing" would pin it.Also, the PR description is empty: please fill in the template (what it fixes, how you checked it). Once these are in and CI is green on the new head, we'll look again.
@LakshanSivakumar on GitHub · 2026-11-28 00:39 UTC · original
Thanks, this is merged. One small fix went in on top (
45d90fe9): in commit_piece the block that builds the completion handler ended in a semicolon, so the handler was dropped at once and Metal was given a dangling pointer. It only showed with VICTORY_PASSES_PER_BUFFER set. The block now returns the handler and it is passed the same way submit does.@Olima34 on GitHub · 2026-11-28 00:40 UTC · original
My change request above crossed with the maintainer merging this PR. He fixed point 1, the completion handler, himself in
45d90fe9. Point 2 may still be worth a follow-up PR against main:Owed::pay_refundleavesrefundin place, so anattach_refundthat races the completion handler can pay the same fills twice. Taking the vector out under the lock (std::mem::take) would make each fill paid once.