GPU: saturate COM AddRef instead of wrapping its reference count #1105

Closed
github-bot wants to merge 1 commit from gh-pr/1105/head into gh-pr/1105/base
Owner

@⁠NethminaYasas on GitHub · 2026-11-24 15:47 UTC · original
fix/addref-saturation → main · +94 −7 · 1 files · 1 commits · closed without merging

Problem

add_ref used fetch_add(1) + 1, so a reference count at u32::MAX panicked 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_ref now mirrors release: fetch_update with checked_add(1), returning the saturated count when the increment overflows. It never wraps to zero and never panics.
  • Saturation is permanent in both release paths (release and release_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.
  • Two synthetic unit tests: add_ref_saturates_at_u32_max and release_boxed_keeps_a_saturated_object_alive.

Verification

  • cargo test --workspace on Windows with Rust 1.98.1: all crates pass; victory-gpu has 45 passed, 1 ignored (benchmark), including both new tests.
  • rustfmt --edition 2024 --check crates/victory-gpu/src/object.rs: clean. A workspace-wide cargo fmt is not clean on main with 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 in victory-hle/src/modules/xmem.rs:747 (field_reassign_with_default), left untouched.
  • CodeRabbit CLI local review of the final diff: 0 findings.
  • The pre-commit asset-policy check passed for the staged file.

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.

**@⁠NethminaYasas** on GitHub · 2026-11-24 15:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1105) `fix/addref-saturation` → `main` · +94 −7 · 1 files · 1 commits · closed without merging ## Problem `add_ref` used `fetch_add(1) + 1`, so a reference count at `u32::MAX` panicked 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_ref` now mirrors `release`: `fetch_update` with `checked_add(1)`, returning the saturated count when the increment overflows. It never wraps to zero and never panics. - Saturation is permanent in both release paths (`release` and `release_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. - Two synthetic unit tests: `add_ref_saturates_at_u32_max` and `release_boxed_keeps_a_saturated_object_alive`. ## Verification - `cargo test --workspace` on Windows with Rust 1.98.1: all crates pass; `victory-gpu` has 45 passed, 1 ignored (benchmark), including both new tests. - `rustfmt --edition 2024 --check crates/victory-gpu/src/object.rs`: clean. A workspace-wide `cargo fmt` is not clean on `main` with 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 in `victory-hle/src/modules/xmem.rs:747` (`field_reassign_with_default`), left untouched. - CodeRabbit CLI local review of the final diff: 0 findings. - The pre-commit asset-policy check passed for the staged file. 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:20:04 +00:00
github-bot closed this pull request 2026-11-26 04:20:04 +00:00
Author
Owner

@⁠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-gpu passes, 45 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1105#issuecomment-7140056280) 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-gpu` passes, 45 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1105#issuecomment-7148610856) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1105
No description provided.