First-upload admission: size View::Shader textures and skip non-texture/placed-buffer slots #1771

Merged
Luca121 merged 1 commit from upstream-pr/1771 into main 2026-11-29 08:16:53 +00:00
Luca121 commented 2026-11-29 00:01:53 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Luca121 on 2026-11-29T00:01:53Z.


What it changes

Fixes two bugs in the heap_textures first-upload admission path (crates/victory-gpu/src/draw.rs) when VRAM is over the room line (!room):

  1. Size View::Shader first uploads accurately (resource::texture_bytes):

    • Previously placed_len stayed at its initial 1u64 for title-filled View::Shader textures (it was only updated for View::Placed), so room_for_first_upload(memory, reserve) and first_upload_reserve(reserve, memory, reserve) charged 1 byte instead of the texture's real footprint.
    • This let megabytes of View::Shader textures bypass both the 5-second first-upload window cap and free-range size checks (including open PRs #1677 / #1544).
    • Added resource::texture_bytes(this) (paralleling placed_bytes) and set placed_len for title-filled View::Shader textures.
  2. Exclude placed buffers and non-texture slots from !room first-upload admission:

    • Guarded View::Placed(false, resource, desc) with resource[0] != 1 (matching draw.rs:3309, 6386, and descriptor/host.rs:1855) so placed buffers don't enter the placed-texture mapped-bytes path.
    • Tracked is_texture and guarded if !room && is_texture so empty/overwritten/buffer/UAV/CBV slots reaching !room retire cleanly downstream instead of passing reserve = 1 into room_for_first_upload, spamming HEAP_TEXTURES_FIRST_FULL, burning the refused pass-abort cap, or re-holding dead slots via Told::Held.

How it was tested

  • GPU and profile: RTX 4070 Ti 12 GB, 32 GB RAM, Windows 11 — Series S (626 Balanced & 720 Quality), DLSS 2x Frame Generation.
  • Before: 25-minute open-world session logged 736,542 room-line admissions (over 10,000 per 5 s with bytes = 1 from non-texture/placed-buffer slots and unsized View::Shader textures).
  • After: Zero bogus bytes = 1 room-line admissions on non-texture/placed-buffer slots; View::Shader textures are budgeted by their actual footprint(&r.desc).size.
  • For shader changes, the wave sizes tested: N/A (no shader changes).
  • cargo test passed for the crates it touches: yes (cargo test --locked -p victory-gpu --lib -- --test-threads=4 — 552 passed, 0 failed, including new unit tests texture_bytes_sizes_textures_and_skips_buffers_and_null and placed_buffer_is_excluded_from_texture_check).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1496, #1677, #1544 (orthogonal: #1677/#1544 harden first_upload_decision in resource.rs, whereas this fixes reserve = 1 and non-texture admission in draw.rs that otherwise bypasses those checks).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5545851501 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1771). Originally posted by [Luca121](https://github.com/Luca121) on 2026-11-29T00:01:53Z. --- ## What it changes Fixes two bugs in the `heap_textures` first-upload admission path (`crates/victory-gpu/src/draw.rs`) when VRAM is over the room line (`!room`): 1. **Size `View::Shader` first uploads accurately (`resource::texture_bytes`):** - Previously `placed_len` stayed at its initial `1u64` for title-filled `View::Shader` textures (it was only updated for `View::Placed`), so `room_for_first_upload(memory, reserve)` and `first_upload_reserve(reserve, memory, reserve)` charged **1 byte** instead of the texture's real footprint. - This let megabytes of `View::Shader` textures bypass both the 5-second first-upload window cap and free-range size checks (including open PRs `#1677` / `#1544`). - Added `resource::texture_bytes(this)` (paralleling `placed_bytes`) and set `placed_len` for title-filled `View::Shader` textures. 2. **Exclude placed buffers and non-texture slots from `!room` first-upload admission:** - Guarded `View::Placed(false, resource, desc)` with `resource[0] != 1` (matching `draw.rs:3309`, `6386`, and `descriptor/host.rs:1855`) so placed buffers don't enter the placed-texture mapped-bytes path. - Tracked `is_texture` and guarded `if !room && is_texture` so empty/overwritten/buffer/UAV/CBV slots reaching `!room` retire cleanly downstream instead of passing `reserve = 1` into `room_for_first_upload`, spamming `HEAP_TEXTURES_FIRST_FULL`, burning the `refused` pass-abort cap, or re-holding dead slots via `Told::Held`. ## How it was tested - **GPU and profile:** RTX 4070 Ti 12 GB, 32 GB RAM, Windows 11 — Series S (`626` Balanced & `720` Quality), DLSS 2x Frame Generation. - **Before:** 25-minute open-world session logged `736,542` room-line admissions (over 10,000 per 5 s with `bytes = 1` from non-texture/placed-buffer slots and unsized `View::Shader` textures). - **After:** Zero bogus `bytes = 1` room-line admissions on non-texture/placed-buffer slots; `View::Shader` textures are budgeted by their actual `footprint(&r.desc).size`. - **For shader changes, the wave sizes tested:** N/A (no shader changes). - **`cargo test` passed for the crates it touches:** yes (`cargo test --locked -p victory-gpu --lib -- --test-threads=4` — 552 passed, 0 failed, including new unit tests `texture_bytes_sizes_textures_and_skips_buffers_and_null` and `placed_buffer_is_excluded_from_texture_check`). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1496, #1677, #1544 (orthogonal: `#1677`/`#1544` harden `first_upload_decision` in `resource.rs`, whereas this fixes `reserve = 1` and non-texture admission in `draw.rs` that otherwise bypasses those checks).
upipibi commented 2026-11-29 00:59:36 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by upipibi on 2026-11-29T00:59:36Z.


Test report for #1771 (head f0c5d597), merged --no-ff onto main f9dfb76. Synthetic tests only: no title run, no game files.

Setup: RTX 3070, driver 616.56, Windows 11 (10.0.26100), rustc 1.98.1. WARP runs use VICTORY_D3D12_WARP=1
with --features diagnostics.

The PR's tests, 3x on hardware and 3x on WARP: all pass.

  • resource::tests::texture_bytes_sizes_textures_and_skips_buffers_and_null: 6/6.
  • draw::first_upload_window_tests::placed_buffer_is_excluded_from_texture_check: 6/6.

Both are CPU-only. create_committed goes through Memory::for_resource (title memory), and neither test makes a
D3D12 device call, so the hardware and WARP runs test the same thing.

Negative controls

  • Main with only the tests added does not compile: E0425: cannot find function texture_bytes. The helper is
    part of the fix, so its test cannot run against the old code.
  • Keeping texture_bytes but reverting the draw.rs change (the resource[0] != 1 guard, is_texture, and
    placed_len for View::Shader): both tests still pass, on hardware and on WARP.
    • placed_buffer_is_excluded_from_texture_check checks the existing placed_bytes on a buffer description and
      that 1 != 3. It does not exercise the new guard in heap_textures.
    • So neither test would catch a regression in the admission path this PR changes. A test that runs that branch
      (a View::Shader title-filled texture under !room reaching room_for_first_upload with its real size, and a
      placed buffer or empty slot not reaching it) would cover the fix itself.

Temporary device probe (not committed). I created title textures through create_committed and compared
texture_bytes with the host device's GetResourceAllocationInfo for the same description. The results were the
same on hardware and on WARP, 3/3 each:

Texture texture_bytes Host allocation
RGBA8 64x64, 1 mip 16,384 65,536
RGBA8 1024x1024, 11 mips 5,595,136 5,636,096
RGBA16F 256x256, 1 mip 524,288 524,288
BC1 512x512, 10 mips 176,128 196,608
BC7 2048x2048, 12 mips 5,595,136 5,636,096

So the first upload of these textures is now charged its real size instead of 1 byte. The charge is the title's
footprint, which is at or under what the host device allocates: equal for RGBA16F 256x256, under 1% below for the
two large chains, about 10% below for the BC1 chain, and 16 KiB of a 64 KiB allocation for the 64x64 texture (the
host's 64 KiB alignment).

cargo test -p victory-gpu --lib --locked

Run PR Main f9dfb76
default 591 passed, 0 failed, 44 ignored 589 passed, 0 failed, 44 ignored
--features diagnostics 645 passed, 0 failed, 44 ignored 643 passed, 0 failed, 44 ignored
  • The two extra tests over main are the PR's own. (The suites ran with the temporary probe in place, 592 and 646;
    the table leaves the probe out.)
  • One of four default PR runs failed watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view.
    That test is unrelated to this PR and shares static state with other watch tests. It passed in the other three
    full runs, and 5/5 alone on the PR and 5/5 alone on main.

Not tested: the effect in a title (the admission counts and the room line).

Tested with the help of Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7248487821 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1771#issuecomment-7248487821). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-29T00:59:36Z. --- Test report for #1771 (head f0c5d597), merged `--no-ff` onto main f9dfb76. Synthetic tests only: no title run, no game files. **Setup:** RTX 3070, driver 616.56, Windows 11 (10.0.26100), rustc 1.98.1. WARP runs use `VICTORY_D3D12_WARP=1` with `--features diagnostics`. **The PR's tests, 3x on hardware and 3x on WARP: all pass.** - `resource::tests::texture_bytes_sizes_textures_and_skips_buffers_and_null`: 6/6. - `draw::first_upload_window_tests::placed_buffer_is_excluded_from_texture_check`: 6/6. Both are CPU-only. `create_committed` goes through `Memory::for_resource` (title memory), and neither test makes a D3D12 device call, so the hardware and WARP runs test the same thing. **Negative controls** - Main with only the tests added does not compile: `E0425: cannot find function texture_bytes`. The helper is part of the fix, so its test cannot run against the old code. - Keeping `texture_bytes` but reverting the `draw.rs` change (the `resource[0] != 1` guard, `is_texture`, and `placed_len` for `View::Shader`): both tests still pass, on hardware and on WARP. - `placed_buffer_is_excluded_from_texture_check` checks the existing `placed_bytes` on a buffer description and that `1 != 3`. It does not exercise the new guard in `heap_textures`. - So neither test would catch a regression in the admission path this PR changes. A test that runs that branch (a `View::Shader` title-filled texture under `!room` reaching `room_for_first_upload` with its real size, and a placed buffer or empty slot not reaching it) would cover the fix itself. **Temporary device probe** (not committed). I created title textures through `create_committed` and compared `texture_bytes` with the host device's `GetResourceAllocationInfo` for the same description. The results were the same on hardware and on WARP, 3/3 each: | Texture | `texture_bytes` | Host allocation | |---|---|---| | RGBA8 64x64, 1 mip | 16,384 | 65,536 | | RGBA8 1024x1024, 11 mips | 5,595,136 | 5,636,096 | | RGBA16F 256x256, 1 mip | 524,288 | 524,288 | | BC1 512x512, 10 mips | 176,128 | 196,608 | | BC7 2048x2048, 12 mips | 5,595,136 | 5,636,096 | So the first upload of these textures is now charged its real size instead of 1 byte. The charge is the title's footprint, which is at or under what the host device allocates: equal for RGBA16F 256x256, under 1% below for the two large chains, about 10% below for the BC1 chain, and 16 KiB of a 64 KiB allocation for the 64x64 texture (the host's 64 KiB alignment). **`cargo test -p victory-gpu --lib --locked`** | Run | PR | Main f9dfb76 | |---|---|---| | default | 591 passed, 0 failed, 44 ignored | 589 passed, 0 failed, 44 ignored | | `--features diagnostics` | 645 passed, 0 failed, 44 ignored | 643 passed, 0 failed, 44 ignored | - The two extra tests over main are the PR's own. (The suites ran with the temporary probe in place, 592 and 646; the table leaves the probe out.) - One of four default PR runs failed `watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view`. That test is unrelated to this PR and shares static state with other `watch` tests. It passed in the other three full runs, and 5/5 alone on the PR and 5/5 alone on main. Not tested: the effect in a title (the admission counts and the room line). *Tested with the help of Claude Code (Claude Opus 5.5).*
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
trustno1-coder/VIctory-NVIDIA!1771
No description provided.