GPU: drop raw shader container bytes after first translation #3658

Open
Luislariosss wants to merge 1 commit from upstream-pr/3658 into main
Luislariosss commented 2026-11-28 03:36:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-28T03:36:45Z.


SHADERS retains an Arc<Shader> for every unique shader container seen during a session, which previously kept the raw container: Vec<u8> allocated for the lifetime of the process even though no production path reads those bytes again after Shader::translated() populates its OnceLock (only bound() logged container.len()).

Changes

  • Store size: usize on Shader (from bytes.len()) and use it in bound().
  • Wrap Shader.container in Mutex<Option<Vec<u8>>> and .take() it inside Shader::translated()'s get_or_init closure so the raw container bytes are freed immediately after translation while preserving Translated and cache hits.
  • Update test helpers and add pipeline::tests::translating_drops_the_container.

Verification

  • cargo xtask policy (191 files ok)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics)
  • cargo test -p victory-gpu --lib pipeline:: (24 passed, 0 failed)
<!-- greyfinch-sync:Marvisak/VIctory:issue:5536292273 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3658). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-28T03:36:45Z. --- `SHADERS` retains an `Arc<Shader>` for every unique shader container seen during a session, which previously kept the raw `container: Vec<u8>` allocated for the lifetime of the process even though no production path reads those bytes again after `Shader::translated()` populates its `OnceLock` (only `bound()` logged `container.len()`). ### Changes - Store `size: usize` on `Shader` (from `bytes.len()`) and use it in `bound()`. - Wrap `Shader.container` in `Mutex<Option<Vec<u8>>>` and `.take()` it inside `Shader::translated()`'s `get_or_init` closure so the raw container bytes are freed immediately after translation while preserving `Translated` and cache hits. - Update test helpers and add `pipeline::tests::translating_drops_the_container`. ### Verification - `cargo xtask policy` (191 files ok) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`) - `cargo test -p victory-gpu --lib pipeline::` (24 passed, 0 failed)
oni-swr commented 2026-11-28 07:10:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T07:10:03Z.


Independent software WARP verification against main 63bcca43c6a00a758510398fa43096ce7e4f7df0 (clean merge with head 7055bded, merge tree e67c56fcc2e9bd96ae2f2ff66a42d008bc771c40).

Environment: Windows 11 x64, software WARP (VICTORY_WARP=1, VICTORY_D3D12_WARP=1, Microsoft Basic Render Driver), d3d10warp.dll 10.0.26100.9818 (WinBuild.160101.0800), dxil.dll 1.8.2502.11.

Results (victory-gpu):

  • Base 63bcca43: 246 passed, 0 failed, 1 ignored (translating_drops_the_container absent).
  • Merged #3658 (e67c56fc): 247 passed, 0 failed, 1 ignored; regression translating_drops_the_container (exercising failed translation) passed, and depth-bounds and placed-UAV tests passed.
  • Default-feature compilation, cargo clippy --workspace --all-targets -- -D warnings (both feature configurations), and asset policy check (191 files) all passed.

Code review notes:

  • Concurrent callers wait on the same OnceLock initializer, first-bind logging retains the original byte count, and the depth-bounds fixture keeps its preseeded bytes.
  • Non-blocking edge note: if the initializer unwinds after taking the bytes, a retry observes an empty container.
  • Combines cleanly with #3655 (1aae4335ef9c44cefa56951aa7d2be3715a035d0).

AI disclosure: Verification run by Codex (gpt-6.2-sol); report posted by orchestrator.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7235759305 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3658#issuecomment-7235759305). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-28T07:10:03Z. --- Independent software WARP verification against `main` `63bcca43c6a00a758510398fa43096ce7e4f7df0` (clean merge with head `7055bded`, merge tree `e67c56fcc2e9bd96ae2f2ff66a42d008bc771c40`). **Environment:** Windows 11 x64, software WARP (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, Microsoft Basic Render Driver), `d3d10warp.dll` `10.0.26100.9818 (WinBuild.160101.0800)`, `dxil.dll` `1.8.2502.11`. **Results (`victory-gpu`):** - Base `63bcca43`: `246 passed, 0 failed, 1 ignored` (`translating_drops_the_container` absent). - Merged `#3658` (`e67c56fc`): `247 passed, 0 failed, 1 ignored`; regression `translating_drops_the_container` (exercising failed translation) passed, and depth-bounds and placed-UAV tests passed. - Default-feature compilation, `cargo clippy --workspace --all-targets -- -D warnings` (both feature configurations), and asset policy check (191 files) all passed. **Code review notes:** - Concurrent callers wait on the same `OnceLock` initializer, first-bind logging retains the original byte count, and the depth-bounds fixture keeps its preseeded bytes. - Non-blocking edge note: if the initializer unwinds after taking the bytes, a retry observes an empty container. - Combines cleanly with `#3655` (`1aae4335ef9c44cefa56951aa7d2be3715a035d0`). AI disclosure: Verification run by Codex (gpt-6.2-sol); report posted by orchestrator.
futurepro62 commented 2026-11-29 22:50:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-29T22:50:29Z.


NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head 7055bde (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: translating_drops_the_container.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7263991018 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3658#issuecomment-7263991018). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-29T22:50:29Z. --- NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head `7055bde` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `translating_drops_the_container`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
passerbyyhx commented 2026-11-30 23:26:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-30T23:26:35Z.


I measured retained container capacity and Windows process memory at 7055bdedc1823d31141737f7d6e3de108cbd97ff against its parent 63bcca43c6a00a758510398fa43096ce7e4f7df0. Five alternating pairs of fresh processes interned and translated the same 1,024 distinct, valid 308-byte compute shaders with the disk cache disabled. All ten runs produced the same 2,830,336 bytes of DXIL and reused every translation on lookup.

Source capacity After interning After 512 translations After all 1,024
Parent 308 KiB 308 KiB 308 KiB
PR 308 KiB 154 KiB 0 KiB

For each pair I also compared the change from interning to full translation in Windows PrivateUsage and WorkingSetSize. The head-minus-parent median was +8 KiB for private commit (range −104 to +40) and +28 KiB for working set (−48 to +256). The source release was reproducible in every run. These process counters showed no consistent reduction at this workload size.

Separately, the eight-shader dispatch fixture on RTX 4090 Laptop and WARP produced matching UAV outputs on both revisions, including the second bind.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7295122207 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3658#issuecomment-7295122207). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-30T23:26:35Z. --- I measured retained container capacity and Windows process memory at `7055bdedc1823d31141737f7d6e3de108cbd97ff` against its parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. Five alternating pairs of fresh processes interned and translated the same 1,024 distinct, valid 308-byte compute shaders with the disk cache disabled. All ten runs produced the same 2,830,336 bytes of DXIL and reused every translation on lookup. | Source capacity | After interning | After 512 translations | After all 1,024 | |---|---:|---:|---:| | Parent | 308 KiB | 308 KiB | 308 KiB | | PR | 308 KiB | 154 KiB | 0 KiB | For each pair I also compared the change from interning to full translation in Windows `PrivateUsage` and `WorkingSetSize`. The head-minus-parent median was +8 KiB for private commit (range −104 to +40) and +28 KiB for working set (−48 to +256). The source release was reproducible in every run. These process counters showed no consistent reduction at this workload size. Separately, the eight-shader dispatch fixture on RTX 4090 Laptop and WARP produced matching UAV outputs on both revisions, including the second bind.
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/3658:upstream-pr/3658'
git switch 'upstream-pr/3658'

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/3658'
git switch 'upstream-pr/3658'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3658'
git switch 'upstream-pr/3658'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3658'
git switch 'main'
git merge --squash 'upstream-pr/3658'
git switch 'main'
git merge --ff-only 'upstream-pr/3658'
git switch 'main'
git merge 'upstream-pr/3658'
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!3658
No description provided.