GPU: host descriptor heaps, depth twin copies, frame timing #2547

Closed
github-bot wants to merge 8 commits from gh-pr/2547/head into gh-pr/2547/base
Owner

@⁠Therecalloftheonion on GitHub · 2026-11-25 15:34 UTC · original
Therecalloftheonion:gpu/descriptor-heaps-and-depth-twins → main · +484 −101 · 9 files · 8 commits · closed without merging

Summary

GPU-host fixes found while working toward the world running on a host GPU.

  • View heaps. Host view heaps were requested at 2^21 descriptors, above D3D12's 1,000,000 limit, so every heap silently fell back to 65,536 slots. The shader clamp and the null buffer views pointed past the heap, and the dynamic slots for per-draw tables ran out (the #59 world device removal). Heaps are now made at the size the clamp uses, with the null views and dedicated copy-pair slots inside them. They are sized at 262,144 slots to keep the footprint down (about 8 MiB of descriptors and 3 MiB of tables per heap); raising HEAP_VIEWS restores more title descriptors at more memory.
  • Depth twins. Subresources of one format family copy directly between the depth texture and its writable twin instead of through a scratch buffer. A D32 twin takes one texture instead of two, and D32 twins now exist at all: the previous exact-format check rejected them, so shader writes to D32 depth were dropped. A hardware test performs a real copy, reads it back and checks every texel and the device state.
  • Frame pacing. The waitable timer was created with TIMER_MODIFY_STATE only, so WaitForSingleObject failed and sub-tick waits fell back to the 15.6 ms system sleep. It also tested INVALID_HANDLE_VALUE although the API returns NULL, and one timer was shared by every thread. It is now per-thread with TIMER_ALL_ACCESS.
  • Tests. The late page-list test no longer races a 2 ms sleep against the 8 ms retry window; it waits for the copy to report the empty list, then fills it. The memory tests now bind one 32-bit constant when a shader has no user data; the root signature always declares one, and passing a count of zero access-violates on the RX 6700 XT (WARP tolerates it), which aborted the shader suite.
  • Build. Thin LTO and one codegen unit for release; local *.log files are ignored so the asset-policy test is not tripped by a log left in the tree.

Testing

  • cargo test -p victory-gpu --lib: 196 passed, including the new hardware copy test
  • cargo test -p victory-shader --lib: 268 passed; two pre-existing hardware assertions on the RX 6700 XT still fail (emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, emit::synthetic_tests::gathers_at_a_level_match_the_hardware), outside the paths changed here. The suite no longer aborts at emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index; that zero-constant crash is fixed here.
  • cargo test -p victory-hle --lib: passed repeatedly
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo xtask policy: 182 files ok

No game files are included; all input remains the user's own dump.

This does not make the world playable yet. It removes descriptor/device-removal hazards, restores a depth feature that was silently dropped, and reduces avoidable GPU memory; the remaining world frame cost needs profiling on a real dump.

**@⁠Therecalloftheonion** on GitHub · 2026-11-25 15:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2547) `Therecalloftheonion:gpu/descriptor-heaps-and-depth-twins` → `main` · +484 −101 · 9 files · 8 commits · closed without merging ## Summary GPU-host fixes found while working toward the world running on a host GPU. - **View heaps.** Host view heaps were requested at 2^21 descriptors, above D3D12's 1,000,000 limit, so every heap silently fell back to 65,536 slots. The shader clamp and the null buffer views pointed past the heap, and the dynamic slots for per-draw tables ran out (the #59 world device removal). Heaps are now made at the size the clamp uses, with the null views and dedicated copy-pair slots inside them. They are sized at 262,144 slots to keep the footprint down (about 8 MiB of descriptors and 3 MiB of tables per heap); raising `HEAP_VIEWS` restores more title descriptors at more memory. - **Depth twins.** Subresources of one format family copy directly between the depth texture and its writable twin instead of through a scratch buffer. A D32 twin takes one texture instead of two, and D32 twins now exist at all: the previous exact-format check rejected them, so shader writes to D32 depth were dropped. A hardware test performs a real copy, reads it back and checks every texel and the device state. - **Frame pacing.** The waitable timer was created with `TIMER_MODIFY_STATE` only, so `WaitForSingleObject` failed and sub-tick waits fell back to the 15.6 ms system sleep. It also tested `INVALID_HANDLE_VALUE` although the API returns NULL, and one timer was shared by every thread. It is now per-thread with `TIMER_ALL_ACCESS`. - **Tests.** The late page-list test no longer races a 2 ms sleep against the 8 ms retry window; it waits for the copy to report the empty list, then fills it. The memory tests now bind one 32-bit constant when a shader has no user data; the root signature always declares one, and passing a count of zero access-violates on the RX 6700 XT (WARP tolerates it), which aborted the shader suite. - **Build.** Thin LTO and one codegen unit for release; local `*.log` files are ignored so the asset-policy test is not tripped by a log left in the tree. ## Testing - `cargo test -p victory-gpu --lib`: 196 passed, including the new hardware copy test - `cargo test -p victory-shader --lib`: 268 passed; two pre-existing hardware assertions on the RX 6700 XT still fail (`emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `emit::synthetic_tests::gathers_at_a_level_match_the_hardware`), outside the paths changed here. The suite no longer aborts at `emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index`; that zero-constant crash is fixed here. - `cargo test -p victory-hle --lib`: passed repeatedly - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo xtask policy`: 182 files ok No game files are included; all input remains the user's own dump. This does not make the world playable yet. It removes descriptor/device-removal hazards, restores a depth feature that was silently dropped, and reduces avoidable GPU memory; the remaining world frame cost needs profiling on a real dump.
The host asked for 2^21 view descriptors, above D3D12's 1,000,000 limit, so every heap fell back to 65,536 slots: the shader clamp and the null buffer views pointed past the heap, and the dynamic slots for per-draw tables ran out (#59).

Make the heap the size the clamp uses (262,144 slots for now), keep the title slots, split the rest into dynamic slots and dedicated pairs for host copies, and create the null views inside the heap. Fall back to the smaller heap only if the host refuses the size. The stride and mark tables follow the same constant, and host copies' view pairs no longer consume dynamic slots.
A depth twin copied every subresource through a scratch buffer, so a D32 twin needed a full extra texture or two. Subresources of one format family now copy straight between the depth texture and the twin; the scratch is made only for converted 16-bit planes and only when one is needed. D32 twins now exist at all: the previous exact-format check rejected them, so shader writes to D32 depth were dropped.

Add a hardware test that copies a D32 depth texture into its twin, reads it back, and checks every texel and the device state.
Create the waitable timer with TIMER_ALL_ACCESS: WaitForSingleObject needs SYNCHRONIZE, and with TIMER_MODIFY_STATE alone every wait failed and fell back to the 15.6 ms system sleep. Check for NULL rather than INVALID_HANDLE_VALUE, and keep one timer per thread so two frame threads cannot reset each other's due time.
The test slept 2 ms and raced the 8 ms window in which a copy re-reads a page list the title has not filled yet; under load the fill could arrive after the window. Have the copy report when it found the list empty, then fill it, so the retry path is covered deterministically.
The translator and frame path run for as long as the title does. Let the optimizer see across the emulated runtime and the GPU crates in release builds; development and diagnostics profiles are unchanged.
Test and crash logs are not part of the repository or the asset policy allowlist; ignore them so a log left in the working tree does not trip the policy test.
Resolve the twin tests: keep both the direct-copy test and upstream's prelude-state test.
The host root signature always declares one 32-bit constant (Num32BitValues.max(1)), but four memory tests sized their user data from user_data_dwords() and could pass a count of 0 to SetComputeRoot32BitConstants. On the RX 6700 XT the driver access-violates on that call (WARP tolerates it), killing the shader test process; the other shader tests already use max(1). Memory tests now do the same.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:54 +00:00
github-bot closed this pull request 2026-11-26 05:08:54 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:35 UTC · original

Automated triage for the maintainers.

This PR bundles eight unrelated changes. They need to be split, and the headline one is not right as it stands.

  • View heap size (8a4f310a). The commit message says every heap "fell back to 65,536 slots". That does not match main: HostHeap::new asks for (count + DYNAMIC).max(HEAP_VIEWS) and falls back to count + MIN_DYNAMIC, then to the PORTABLE_VIEWS cap. With this PR, HEAP_VIEWS becomes 2^18, and the new code sets count = count.min(NULL_BUFFER_VIEW - 1) and extra = room - count. For the title's 1,245,184-slot heap, that keeps 262,141 title slots and gives split_extra(0) = (0, 0): zero dynamic slots and zero copy pairs. Every draw that needs a dynamic table would then be dropped. Please drop this commit or rework it.
  • Release profile (84ae09ba). The change to Cargo.toml (lto = "thin", codegen-units = 1) needs the maintainer's decision. Please put it in a PR of its own, with measured numbers.
  • Frame waits (e4f59c9a). sleep_precise adds a per-thread high-resolution waitable timer. Recent Rust std::thread::sleep on Windows already uses a high-resolution waitable timer where one is available. Please show a measured difference against main, or drop this.
  • Smaller fixes. The depth-twin direct copy (4d200fa4), the deterministic dstorage late-list test (04ce281c) and the user_data_dwords().max(1) test fix (d22cef91) look like separate, reviewable fixes. Please open each as its own PR. The *.log .gitignore entry is not needed.

CI is passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2547#issuecomment-7171120262) <!-- victory-triage v1 head=d22cef91274622313dda5ad34f643793f41e8168 verdict=needs-work at=2026-11-25T18:35:18Z --> Automated triage for the maintainers. This PR bundles eight unrelated changes. They need to be split, and the headline one is not right as it stands. - **View heap size (`8a4f310a`).** The commit message says every heap "fell back to 65,536 slots". That does not match `main`: `HostHeap::new` asks for `(count + DYNAMIC).max(HEAP_VIEWS)` and falls back to `count + MIN_DYNAMIC`, then to the `PORTABLE_VIEWS` cap. With this PR, `HEAP_VIEWS` becomes 2^18, and the new code sets `count = count.min(NULL_BUFFER_VIEW - 1)` and `extra = room - count`. For the title's 1,245,184-slot heap, that keeps 262,141 title slots and gives `split_extra(0) = (0, 0)`: zero dynamic slots and zero copy pairs. Every draw that needs a dynamic table would then be dropped. Please drop this commit or rework it. - **Release profile (`84ae09ba`).** The change to `Cargo.toml` (`lto = "thin"`, `codegen-units = 1`) needs the maintainer's decision. Please put it in a PR of its own, with measured numbers. - **Frame waits (`e4f59c9a`).** `sleep_precise` adds a per-thread high-resolution waitable timer. Recent Rust `std::thread::sleep` on Windows already uses a high-resolution waitable timer where one is available. Please show a measured difference against `main`, or drop this. - **Smaller fixes.** The depth-twin direct copy (`4d200fa4`), the deterministic dstorage late-list test (`04ce281c`) and the `user_data_dwords().max(1)` test fix (`d22cef91`) look like separate, reviewable fixes. Please open each as its own PR. The `*.log` `.gitignore` entry is not needed. CI is passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠welisonzika14-jpg on GitHub · 2026-11-25 19:18 UTC · original

Measured sleep_precise against std::thread::sleep (rustc 1.98.1, the std that ships with it), as the triage asked. Windows 11 Pro, release build, 100 sleeps per row, run twice. "Late" is real elapsed time minus the requested time. The sleep_precise code from this PR is copied into a stand-alone program outside the repo; no VIctory build was involved.

sleep method mean late (ms) p95 late (ms) max late (ms)
1 ms std:🧵:sleep 0.506 0.661 0.986
1 ms sleep_precise 0.477 0.630 0.881
1 ms std:🧵:sleep 0.548 0.730 1.024
1 ms sleep_precise 0.523 0.676 0.814
2 ms std:🧵:sleep 0.404 0.730 0.892
2 ms sleep_precise 0.320 0.741 0.976
2 ms std:🧵:sleep 0.244 0.563 1.015
2 ms sleep_precise 0.256 0.579 0.889
4 ms std:🧵:sleep 0.407 0.606 0.691
4 ms sleep_precise 0.389 0.610 0.704
4 ms std:🧵:sleep 0.345 0.626 0.977
4 ms sleep_precise 0.318 0.584 0.616

Result: no measurable difference. The two methods differ by under 0.1 ms in the mean and the order flips between runs. Plain std::thread::sleep is already about 0.3 to 0.5 ms late here, not 15.6 ms, so on this machine it already uses a high-resolution timer. That matches the triage note. (This machine only; I did not test an older std or an older Windows.)

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

**@⁠welisonzika14-jpg** on GitHub · 2026-11-25 19:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2547#issuecomment-7172112827) Measured `sleep_precise` against `std::thread::sleep` (rustc 1.98.1, the std that ships with it), as the triage asked. Windows 11 Pro, release build, 100 sleeps per row, run twice. "Late" is real elapsed time minus the requested time. The `sleep_precise` code from this PR is copied into a stand-alone program outside the repo; no VIctory build was involved. | sleep | method | mean late (ms) | p95 late (ms) | max late (ms) | |---|---|---|---|---| | 1 ms | std::thread::sleep | 0.506 | 0.661 | 0.986 | | 1 ms | sleep_precise | 0.477 | 0.630 | 0.881 | | 1 ms | std::thread::sleep | 0.548 | 0.730 | 1.024 | | 1 ms | sleep_precise | 0.523 | 0.676 | 0.814 | | 2 ms | std::thread::sleep | 0.404 | 0.730 | 0.892 | | 2 ms | sleep_precise | 0.320 | 0.741 | 0.976 | | 2 ms | std::thread::sleep | 0.244 | 0.563 | 1.015 | | 2 ms | sleep_precise | 0.256 | 0.579 | 0.889 | | 4 ms | std::thread::sleep | 0.407 | 0.606 | 0.691 | | 4 ms | sleep_precise | 0.389 | 0.610 | 0.704 | | 4 ms | std::thread::sleep | 0.345 | 0.626 | 0.977 | | 4 ms | sleep_precise | 0.318 | 0.584 | 0.616 | Result: no measurable difference. The two methods differ by under 0.1 ms in the mean and the order flips between runs. Plain `std::thread::sleep` is already about 0.3 to 0.5 ms late here, not 15.6 ms, so on this machine it already uses a high-resolution timer. That matches the triage note. (This machine only; I did not test an older std or an older Windows.) Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Author
Owner

@⁠Therecalloftheonion on GitHub · 2026-11-25 19:24 UTC · original

Thanks for the triage. Split and withdrawn as requested.

  • View heap: withdrawn. Confirmed the title's heap is 1,245,184 slots; with HEAP_VIEWS = 2^18 the cap leaves extra = 0, so zero dynamic slots and zero copy pairs, and every draw needing a dynamic table would be dropped. The 2^21 request and the 1M fallback need a separate design; not in this PR.
  • Frame waits: withdrawn. The measurement above matches: std::thread::sleep already uses a high-resolution timer on this Windows, so there is no measured gain.
  • Release profile (LTO / codegen-units): withdrawn; no measured numbers, and it is the maintainer's call.
  • *.log in .gitignore: withdrawn.

The three reviewable pieces are now separate:

  • #2737 GPU: copy depth twins directly instead of through a scratch
  • #2738 Tests: wait for the late page list instead of sleeping
  • #2739 Tests: bind a constant where a shader has no user data

Closing this one. Thanks.

**@⁠Therecalloftheonion** on GitHub · 2026-11-25 19:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2547#issuecomment-7172241347) Thanks for the triage. Split and withdrawn as requested. - **View heap:** withdrawn. Confirmed the title's heap is 1,245,184 slots; with `HEAP_VIEWS = 2^18` the cap leaves `extra = 0`, so zero dynamic slots and zero copy pairs, and every draw needing a dynamic table would be dropped. The 2^21 request and the 1M fallback need a separate design; not in this PR. - **Frame waits:** withdrawn. The measurement above matches: `std::thread::sleep` already uses a high-resolution timer on this Windows, so there is no measured gain. - **Release profile (LTO / codegen-units):** withdrawn; no measured numbers, and it is the maintainer's call. - **`*.log` in `.gitignore`:** withdrawn. The three reviewable pieces are now separate: - #2737 GPU: copy depth twins directly instead of through a scratch - #2738 Tests: wait for the late page list instead of sleeping - #2739 Tests: bind a constant where a shader has no user data Closing this one. Thanks.

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!2547
No description provided.