GPU: saturate COM AddRef instead of wrapping its reference count #1105
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1105
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1105/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?
@NethminaYasas on GitHub · 2026-11-24 15:47 UTC · original
fix/addref-saturation→main· +94 −7 · 1 files · 1 commits · closed without mergingProblem
add_refusedfetch_add(1) + 1, so a reference count atu32::MAXpanicked in debug builds and wrapped to zero in release builds. An object with outstanding references could then look dead and be released early. Refs #931.Change
add_refnow mirrorsrelease:fetch_updatewithchecked_add(1), returning the saturated count when the increment overflows. It never wraps to zero and never panics.releaseandrelease_boxed). Otherwise a reference handed out at the limit is not counted, and later releases could still drop the object while that reference is live (CodeRabbit finding, fixed in review). Normal increments and releases below saturation are unchanged.add_ref_saturates_at_u32_maxandrelease_boxed_keeps_a_saturated_object_alive.Verification
cargo test --workspaceon Windows with Rust 1.98.1: all crates pass;victory-gpuhas 45 passed, 1 ignored (benchmark), including both new tests.rustfmt --edition 2024 --check crates/victory-gpu/src/object.rs: clean. A workspace-widecargo fmtis not clean onmainwith this rustfmt version (it reformats 31 unrelated files), so those unrelated changes were deliberately left out.cargo clippy --workspace: no findings in this change. There is one pre-existing, unrelated warning invictory-hle/src/modules/xmem.rs:747(field_reassign_with_default), left untouched.This verifies reference-count behaviour only. I did not run the title. AI-assisted (OpenCode). No game data, game assets, or files from a game dump were used or committed; both tests use synthetic in-memory objects.
@Zipettte on GitHub · 2026-11-24 18:01 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
6273f06:cargo test -p victory-gpupasses, 45 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@Marvisak on GitHub · 2026-11-25 00:32 UTC · original
Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).
Saturates AddRef at u32::MAX and makes a saturated object immortal. Hardening against 4 billion unreleased references to one object, which no title reaches; it replaces a single atomic add on a hot path with compare-exchange loops in AddRef and Release.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed