GPU: retain D3D12 object names in private data #541

Open
github-bot wants to merge 1 commit from github-bot/gh-541 into main AGit
Owner

@⁠broccolize on GitHub · 2026-11-24 04:41 UTC · original
broccolize:gpu/persist-d3d12-object-names → main · +53 −6 · 1 files · 1 commits · open

SetName now stores the original UTF-16 name, including its terminating NUL, under WKPDID_D3DDebugObjectNameW. Callers can retrieve the name through GetPrivateData.

The regression covers Unicode names, replacement, and empty names. It failed on main and passes with this change. Native Direct3D returned matching bytes on the GTX 1650, Intel UHD Graphics, and WARP.

On Windows with Rust 1.98.1 (GNU), the GPU suite passed 44 tests by default and 46 with diagnostics. Both runs had zero failures and one ignored benchmark. The asset policy and git diff --check passed.

AI-assisted with Codex. The tests used synthetic inputs.

**@⁠broccolize** on GitHub · 2026-11-24 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/541) `broccolize:gpu/persist-d3d12-object-names` → `main` · +53 −6 · 1 files · 1 commits · open `SetName` now stores the original UTF-16 name, including its terminating NUL, under `WKPDID_D3DDebugObjectNameW`. Callers can retrieve the name through `GetPrivateData`. The regression covers Unicode names, replacement, and empty names. It failed on `main` and passes with this change. Native Direct3D returned matching bytes on the GTX 1650, Intel UHD Graphics, and WARP. On Windows with Rust 1.98.1 (GNU), the GPU suite passed 44 tests by default and 46 with diagnostics. Both runs had zero failures and one ignored benchmark. The asset policy and `git diff --check` passed. AI-assisted with Codex. The tests used synthetic inputs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:07:44 +00:00
Author
Owner

@⁠fromthemoonx on GitHub · 2026-11-24 10:16 UTC · original

Tested 51fc0d3 merged onto current main (ffe310e, merges cleanly) on NVIDIA.

Environment: Windows 11 Pro build 26300, AMD Ryzen 7 5700X, 16 GB, NVIDIA GeForce RTX 3060 12 GB (driver 610.88), Rust 1.98.1 x86_64-pc-windows-msvc.

CI's commands, on the merge: both clippy runs (-D warnings, with and without --all-features) clean; cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored.

Against native D3D12. A throwaway test (not pushed) made a native ID3D12Fence on the RTX 3060 and on WARP and one of ours, then called SetName and read back with GetPrivateData:

call native RTX 3060 / WARP this PR
SetName("abc"), wide key S_OK, 8 bytes, abc\0 S_OK, 8 bytes, abc\0
… narrow key (WKPDID_D3DDebugObjectName) DXGI_ERROR_NOT_FOUND DXGI_ERROR_NOT_FOUND
SetName("") S_OK, 2 bytes, \0 S_OK, 2 bytes, \0
SetName(null) access violation (the runtime doesn't accept it) S_OK, previous name kept

So the stored bytes match native exactly. The more lenient null is fine. The regression test also catches dropping the terminating NUL (with from_raw_parts(name, len), it fails at object.rs:419).

One cost this introduces: release becomes O(named objects). release_boxed clears an object's private data with private_data().retain(...) over the whole map. That was cheap while only explicit SetPrivateData put anything there; now every named object adds an entry, so each release scans every live name. Releasing N named fences (release build, names like texture 123 1024x1024 f98 flags 0x0):

live named objects main this PR this PR + range removal (below)
1,000 0.05 µs / release 1.7 µs 0.22 µs
10,000 0.05 µs 19.7 µs 0.27 µs
30,000 0.06 µs 65.5 µs (2.0 s for all) 0.36 µs (10.8 ms for all)

The world creates and releases many named resources and pipelines, so this would show up as streaming and release cost. Since the key is (address, Iid), the object's entries are one contiguous range of the BTreeMap. Removing just that range keeps release logarithmic. This is what I measured above, and the object tests still pass with it:

let mut map = private_data();
let at = this as usize;
let keys: Vec<_> = map.range((at, [0u8; 16])..=(at, [0xffu8; 16])).map(|(k, _)| *k).collect();
for k in keys {
    map.remove(&k);
}

Not tested: tools reading the names (PIX, the debug layer's messages); no game data used.

AI-assisted (Claude Code) ran the checks and drafted this comment.

**@⁠fromthemoonx** on GitHub · 2026-11-24 10:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/541#issuecomment-7128559016) Tested `51fc0d3` merged onto current `main` (`ffe310e`, merges cleanly) on NVIDIA. **Environment:** Windows 11 Pro build 26300, AMD Ryzen 7 5700X, 16 GB, NVIDIA GeForce RTX 3060 12 GB (driver 610.88), Rust 1.98.1 `x86_64-pc-windows-msvc`. **CI's commands, on the merge:** both clippy runs (`-D warnings`, with and without `--all-features`) clean; `cargo test --workspace --locked`: 343 passed, 0 failed, 6 ignored. **Against native D3D12.** A throwaway test (not pushed) made a native `ID3D12Fence` on the RTX 3060 and on WARP and one of ours, then called `SetName` and read back with `GetPrivateData`: | call | native RTX 3060 / WARP | this PR | |---|---|---| | `SetName("abc")`, wide key | `S_OK`, 8 bytes, `abc\0` | `S_OK`, 8 bytes, `abc\0` | | … narrow key (`WKPDID_D3DDebugObjectName`) | `DXGI_ERROR_NOT_FOUND` | `DXGI_ERROR_NOT_FOUND` | | `SetName("")` | `S_OK`, 2 bytes, `\0` | `S_OK`, 2 bytes, `\0` | | `SetName(null)` | access violation (the runtime doesn't accept it) | `S_OK`, previous name kept | So the stored bytes match native exactly. The more lenient `null` is fine. The regression test also catches dropping the terminating NUL (with `from_raw_parts(name, len)`, it fails at `object.rs:419`). **One cost this introduces: release becomes O(named objects).** `release_boxed` clears an object's private data with `private_data().retain(...)` over the whole map. That was cheap while only explicit `SetPrivateData` put anything there; now every named object adds an entry, so each release scans every live name. Releasing N named fences (release build, names like `texture 123 1024x1024 f98 flags 0x0`): | live named objects | `main` | this PR | this PR + range removal (below) | |---:|---:|---:|---:| | 1,000 | 0.05 µs / release | 1.7 µs | 0.22 µs | | 10,000 | 0.05 µs | 19.7 µs | 0.27 µs | | 30,000 | 0.06 µs | **65.5 µs** (2.0 s for all) | 0.36 µs (10.8 ms for all) | The world creates and releases many named resources and pipelines, so this would show up as streaming and release cost. Since the key is `(address, Iid)`, the object's entries are one contiguous range of the `BTreeMap`. Removing just that range keeps release logarithmic. This is what I measured above, and the object tests still pass with it: ```rust let mut map = private_data(); let at = this as usize; let keys: Vec<_> = map.range((at, [0u8; 16])..=(at, [0xffu8; 16])).map(|(k, _)| *k).collect(); for k in keys { map.remove(&k); } ``` **Not tested:** tools reading the names (PIX, the debug layer's messages); no game data used. AI-assisted (Claude Code) ran the checks and drafted this comment.
Author
Owner

@⁠fromthemoonx on GitHub · 2026-11-24 11:45 UTC · original

Re-tested cbd8426 (it already contains main ffe310e) on the same RTX 3060 machine.

  • Release cost, same benchmark as before (release build, N named fences released):

    live named objects before (51fc0d3) now (cbd8426)
    1,000 1.7 µs / release 0.22 µs
    10,000 19.7 µs 0.24 µs
    30,000 65.5 µs 0.37 µs (11.2 ms for all)
  • last_release_clears_only_the_released_objects_private_data guards the change: with the cleanup loop disabled locally, it fails at object.rs:435.

  • CI's commands: both clippy runs (-D warnings, with and without --all-features) clean; cargo test --workspace --locked: 344 passed, 0 failed, 6 ignored.

Thanks for taking it in.

AI-assisted (Claude Code).

**@⁠fromthemoonx** on GitHub · 2026-11-24 11:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/541#issuecomment-7130505510) Re-tested `cbd8426` (it already contains `main` `ffe310e`) on the same RTX 3060 machine. - **Release cost**, same benchmark as before (release build, N named fences released): | live named objects | before (`51fc0d3`) | now (`cbd8426`) | |---:|---:|---:| | 1,000 | 1.7 µs / release | 0.22 µs | | 10,000 | 19.7 µs | 0.24 µs | | 30,000 | 65.5 µs | 0.37 µs (11.2 ms for all) | - `last_release_clears_only_the_released_objects_private_data` guards the change: with the cleanup loop disabled locally, it fails at `object.rs:435`. - CI's commands: both clippy runs (`-D warnings`, with and without `--all-features`) clean; `cargo test --workspace --locked`: 344 passed, 0 failed, 6 ignored. Thanks for taking it in. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:16 UTC · original · edited 2026-11-25 06:27 UTC

Automated triage for the maintainers.

Merge candidate. set_name in crates/victory-gpu/src/object.rs now also stores the NUL-terminated UTF-16 name under WKPDID_D3DDebugObjectNameW (the public PC key), through main's own set_private_data, so GetPrivateData returns it as native D3D12 does. A tester's comparison above shows byte-identical results for normal and empty names on hardware and WARP. Main's release_boxed already removes an object's private data by key range, so the per-release cost raised earlier does not come back. The new test round-trips Unicode, replacement and empty names. It is a small conformance change; nothing shows yet that the title reads names back.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/541#issuecomment-7149383036) · edited 2026-11-25 06:27 UTC <!-- victory-triage v1 head=9999e2d1e8955d16991bf393cb23388c01581921 verdict=merge-candidate at=2026-11-25T06:27:43Z --> Automated triage for the maintainers. **Merge candidate.** `set_name` in `crates/victory-gpu/src/object.rs` now also stores the NUL-terminated UTF-16 name under `WKPDID_D3DDebugObjectNameW` (the public PC key), through main's own `set_private_data`, so `GetPrivateData` returns it as native D3D12 does. A tester's comparison above shows byte-identical results for normal and empty names on hardware and WARP. Main's `release_boxed` already removes an object's private data by key range, so the per-release cost raised earlier does not come back. The new test round-trips Unicode, replacement and empty names. It is a small conformance change; nothing shows yet that the title reads names back. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:08 UTC · original

Code review and RTX 5090 + WARP verification at head 9999e2d1e895 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-gpu/src/object.rs:239-255):
    • set_name scans non-null *const u16 to the null terminator, checks u32::try_from(size_of_val(units)), and stores the UTF-16LE bytes (including ␀) via set_private_data(this, &DEBUG_OBJECT_NAME_W, ...) (deep-copied under PRIVATE mutex and cleaned up on release_boxed).
    • Minor non-blocking note: calling SetName(nullptr) currently logs and returns S_OK without clearing a previously stored DEBUG_OBJECT_NAME_W entry (set_private_data(..., 0, null())), whereas SetName(L"") overwrites with [0u16].
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-gpu --tests -- -D warnings (default + --features diagnostics): 0 warnings
    • victory-gpu --lib -- object::: 6/6 passed (1 ignored bench) on default RTX 5090, --features diagnostics RTX 5090, and WARP (including names_round_trip_as_wide_private_data).

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/541#issuecomment-7179472645) Code review and RTX 5090 + WARP verification at head `9999e2d1e895` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-gpu/src/object.rs:239-255`)**: - `set_name` scans non-null `*const u16` to the null terminator, checks `u32::try_from(size_of_val(units))`, and stores the UTF-16LE bytes (including `␀`) via `set_private_data(this, &DEBUG_OBJECT_NAME_W, ...)` (deep-copied under `PRIVATE` mutex and cleaned up on `release_boxed`). - Minor non-blocking note: calling `SetName(nullptr)` currently logs and returns `S_OK` without clearing a previously stored `DEBUG_OBJECT_NAME_W` entry (`set_private_data(..., 0, null())`), whereas `SetName(L"")` overwrites with `[0u16]`. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-gpu --tests -- -D warnings` (default + `--features diagnostics`): 0 warnings - `victory-gpu --lib -- object::`: **6/6 passed** (1 ignored bench) on default RTX 5090, `--features diagnostics` RTX 5090, and WARP (including `names_round_trip_as_wide_private_data`). LGTM.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/541/head:github-bot/gh-541'
git switch 'github-bot/gh-541'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-541'
git switch 'github-bot/gh-541'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-541'
git switch 'github-bot/gh-541'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-541'
git switch 'main'
git merge --squash 'github-bot/gh-541'
git switch 'main'
git merge --ff-only 'github-bot/gh-541'
git switch 'main'
git merge 'github-bot/gh-541'
git push origin 'main'
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!541
No description provided.