GPU: retain D3D12 object names in private data #541

Open
broccolize wants to merge 1 commit from upstream-pr/541 into main
broccolize commented 2026-11-24 04:41:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by broccolize on 2026-11-24T04:41:27Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5466204922 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/541). Originally posted by [broccolize](https://github.com/broccolize) on 2026-11-24T04:41:27Z. --- `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.
fromthemoonx commented 2026-11-24 11:04:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fromthemoonx on 2026-11-24T10:16:44Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7128559016 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/541#issuecomment-7128559016). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-11-24T10:16:44Z. --- 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.
fromthemoonx commented 2026-11-24 12:04:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fromthemoonx on 2026-11-24T11:45:22Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7130505510 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/541#issuecomment-7130505510). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-11-24T11:45:22Z. --- 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).
Marvisak commented 2026-11-25 02:05:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:16:37Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149383036 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/541#issuecomment-7149383036). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:16:37Z. --- <!-- 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)_
fuzeofficlal commented 2026-11-26 02:06:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:08:25Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179472645 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/541#issuecomment-7179472645). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:08:25Z. --- 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.
Dukestar69 commented 2026-11-27 00:51:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T00:51:32Z.

Review: APPROVED


LGTM — verified on Windows:

  • Storing wide names under WKPDID_D3DDebugObjectNameW ({4cca5fd8-921f-42c8-8566-70caf2a9b741}) with trailing NUL and u32::try_from bounds check is clean and matches D3D12 SetName/GetPrivateData semantics
  • cargo test -p victory-gpu --lib object::tests:: passed (6/6, including names_round_trip_as_wide_private_data)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6082079879 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/541#pullrequestreview-6082079879). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-27T00:51:32Z. **Review:** APPROVED --- LGTM — verified on Windows: - Storing wide names under `WKPDID_D3DDebugObjectNameW` (`{4cca5fd8-921f-42c8-8566-70caf2a9b741}`) with trailing NUL and `u32::try_from` bounds check is clean and matches D3D12 `SetName`/`GetPrivateData` semantics - `cargo test -p victory-gpu --lib object::tests::` passed (6/6, including `names_round_trip_as_wide_private_data`) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` passed with 0 warnings - `cargo xtask policy` passed (`191 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/541:upstream-pr/541'
git switch 'upstream-pr/541'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/541'
git switch 'upstream-pr/541'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/541'
git switch 'upstream-pr/541'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/541'
git switch 'main'
git merge --squash 'upstream-pr/541'
git switch 'main'
git merge --ff-only 'upstream-pr/541'
git switch 'main'
git merge 'upstream-pr/541'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!541
No description provided.