Stop the placed-view leak; fixes from other forks #27

Manually merged
github merged 14 commits from github-bot/gh-27 into main 2026-11-26 12:37:16 +00:00 AGit
Owner

@⁠TaynanGT on GitHub · 2026-11-26 12:28 UTC · original
TaynanGT:fix/placed-view-leak → main · +656 −68 · 13 files · 14 commits · merged 2026-11-26 12:32 UTC

Stops the placed-view memory leak and brings in fixes from other forks.

The leak

Placed views (device methods 0x230/0x238) are keyed by address plus a shape number. The title leaves padding words unwritten, so the same view kept arriving with different garbage in them and minted a new shape each time. After about 30 minutes the shape space (2^22) filled up and every further view became a permanent view-table entry: 34.9 million entries and 16.7 GB after 70 minutes, private memory past physical RAM, frame preparation doubled, fps fell from ~20 to ~8–10.

A diagnostic build counted distinct values per word over the first million shapes. The noisy ones were all padding:

word distinct values
resource desc word 1 (padding after Dimension) 33,403
resource desc word 13 (padding after Flags) 12,846
SRV word 3 (padding after Shader4ComponentMapping) 131,392
view word 9 (unused tail of the union) 36,413

Fixes:

  • f07e54a2 zeroes resource-description words 1 and 13 before keying (same finding as avatarmanz PR #206).
  • ce914907 zeroes the union words each SRV/UAV dimension doesn't use, and SRV word 3; unknown dimensions keep every word.
  • d3626d25 caps view-table entries no resource releases at 1M (VICTORY_OWNERLESS_VIEWS, 0 keeps all), oldest first.
  • 40e9ea19 keeps per-kind counts so the periodic memory line no longer walks the whole table (it took up to 49 ms at 30M entries).
  • e7dee0fc logs the per-word counts at 1K/16K/128K/1M shapes (diagnostics builds only).

Other fixes

  • 31e8d23c, b883e5e0: dynamic descriptor slots go back to the pool when their flight lands (the pool of 2^18 ran dry under load and the picture turned white); the frame line reports slots taken.
  • d15d8e7b: BC7 dictionary entry 0 reads all 32 indices.
  • b7a99ac4 (Senchsus, upstream #682): v_mul_legacy_f32 treats denormal operands as zero.
  • d8247162 (PastiiJay): optional NaN guard on colour exports and typed stores (VICTORY_NAN_GUARD, part of the shader cache key).
  • 1bf62e10 (beloooo): magenta left in the ambient probes is not treated as light.
  • dbfb5a97 (Flare, upstream #2031): heap samplers keep point mips when anisotropic.
  • d8f70e3b, f1f52219: build and test follow-ups.

Measured

RTX 4090, Ryzen 9 9950X3D, Series S profile, 30 minutes in the world, compared with the 70-minute run on main:

main (70 min) this branch (30 min)
private memory, median / max 39.4 / 52.3 GB 27.2 / 27.4 GB
card memory max 18.4 GB 12.5 GB
placed-view shapes kept 4,194,304 (full) ~69,000
fps median / p10 / 1% low 12.9 / 8.3 / 5.0 20.5 / 17.6 / 11.2

Over the same first 30 minutes the median went from 18.1 fps on main to 20.6 here, and this branch no longer degrades with time. Square blocks in clouds are still there.

Checks

ci-local.ps1: clippy with and without all features, workspace tests.

🤖 Generated with Claude Code

**@⁠TaynanGT** on GitHub · 2026-11-26 12:28 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/27) `TaynanGT:fix/placed-view-leak` → `main` · +656 −68 · 13 files · 14 commits · merged 2026-11-26 12:32 UTC Stops the placed-view memory leak and brings in fixes from other forks. ## The leak Placed views (device methods 0x230/0x238) are keyed by address plus a shape number. The title leaves padding words unwritten, so the same view kept arriving with different garbage in them and minted a new shape each time. After about 30 minutes the shape space (2^22) filled up and every further view became a permanent view-table entry: 34.9 million entries and 16.7 GB after 70 minutes, private memory past physical RAM, frame preparation doubled, fps fell from ~20 to ~8–10. A diagnostic build counted distinct values per word over the first million shapes. The noisy ones were all padding: | word | distinct values | |---|---| | resource desc word 1 (padding after Dimension) | 33,403 | | resource desc word 13 (padding after Flags) | 12,846 | | SRV word 3 (padding after Shader4ComponentMapping) | 131,392 | | view word 9 (unused tail of the union) | 36,413 | Fixes: - `f07e54a2` zeroes resource-description words 1 and 13 before keying (same finding as avatarmanz PR #206). - `ce914907` zeroes the union words each SRV/UAV dimension doesn't use, and SRV word 3; unknown dimensions keep every word. - `d3626d25` caps view-table entries no resource releases at 1M (`VICTORY_OWNERLESS_VIEWS`, 0 keeps all), oldest first. - `40e9ea19` keeps per-kind counts so the periodic memory line no longer walks the whole table (it took up to 49 ms at 30M entries). - `e7dee0fc` logs the per-word counts at 1K/16K/128K/1M shapes (diagnostics builds only). ## Other fixes - `31e8d23c`, `b883e5e0`: dynamic descriptor slots go back to the pool when their flight lands (the pool of 2^18 ran dry under load and the picture turned white); the frame line reports slots taken. - `d15d8e7b`: BC7 dictionary entry 0 reads all 32 indices. - `b7a99ac4` (Senchsus, upstream #682): `v_mul_legacy_f32` treats denormal operands as zero. - `d8247162` (PastiiJay): optional NaN guard on colour exports and typed stores (`VICTORY_NAN_GUARD`, part of the shader cache key). - `1bf62e10` (beloooo): magenta left in the ambient probes is not treated as light. - `dbfb5a97` (Flare, upstream #2031): heap samplers keep point mips when anisotropic. - `d8f70e3b`, `f1f52219`: build and test follow-ups. ## Measured RTX 4090, Ryzen 9 9950X3D, Series S profile, 30 minutes in the world, compared with the 70-minute run on main: | | main (70 min) | this branch (30 min) | |---|---|---| | private memory, median / max | 39.4 / 52.3 GB | 27.2 / 27.4 GB | | card memory max | 18.4 GB | 12.5 GB | | placed-view shapes kept | 4,194,304 (full) | ~69,000 | | fps median / p10 / 1% low | 12.9 / 8.3 / 5.0 | 20.5 / 17.6 / 11.2 | Over the same first 30 minutes the median went from 18.1 fps on main to 20.6 here, and this branch no longer degrades with time. Square blocks in clouds are still there. ## Checks `ci-local.ps1`: clippy with and without all features, workspace tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
In the tables, BC7 entry 0 holds all 32 indices right after its two widths; entries 1..254 repeat the widths first and hold 31. Skipping the repeated widths on entry 0 too dropped its first index and shifted the rest ([1, 0, ...] instead of [2, 1, 0, ...]). Found and described by XCL (xcl-dev/xcl 7881dbc9, raylitebull); written here from that description.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The title may leave words 1 and 13 of the 56-byte resource description it passes to device methods 0x230/0x238 unwritten, so the same view came in with different bytes there and every one was a new shape: the 2^22 shapes were full after half an hour, after which each placed view was a table entry kept for the run (34.9 million, 16.7 GB after 70 minutes on Series S). Only the named fields are copied now; the padding is zero.

From JMAN730/project-flamingo b1e0cd1d (merged there through PR #620), with its test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RDNA2 flushes denormal operands of the legacy multiplies to zero, so
0 x anything = 0 also holds for them. The lowering only tested for an exact
float zero, whose result also depends on the host's denormal mode. Test the
exponent bits instead. Follow-up to #2.

(cherry picked from commit 704d25eddb6f0d1af19425bdec1855b9a9e09c29)
A float a pixel program exports to a colour target gets NaN as 0 and an
infinity as +-65504; typed image and buffer stores get the same for the NaN
the GPU makes (0x7FC00000) and infinities, so integer bits pass. One bad pixel
no longer stays in a history blended into every frame. VICTORY_NAN_GUARD=0
turns it off; part of the shader cache fingerprint.

(cherry picked from commit 0e5f4b2ad23e85bbfaafdcac3bb595a20d0ebc28)
The light stand-in (VICTORY_AMBIENT, set by scripts\play.ps1) blends what the title's probe program left into what it finds; magenta there (green far below red and blue) is stale memory, and it showed as flat purple and pink glows. Such values are dropped.

The ambient line of Belobug/VIctory-Belobug-AMD 81ebb7bd (rx9070xt branch); the rest of that commit (VRAM thresholds) is not taken.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Once the shapes of placed views are full (4,194,304 after half an hour of play), every placed view the title writes became a table entry kept for the run: 34.9 million entries and 16.7 GB after 70 minutes on Series S, with the frame rate halved as memory went past physical RAM. Such entries now sit in a queue, oldest first; past VICTORY_OWNERLESS_VIEWS (default 1,048,576; 0 keeps all) the oldest is freed under a new generation, so a descriptor still naming it reads as stale, as one naming a released resource's view does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lists that ran are kept 64 flights longer before they are reset
(VICTORY_BURY_LAG), and the dynamic descriptor slots of their tables
went back only at that reset. At about 17 flights a frame, almost four
frames of tables held slots no submission read any more. A host heap
capped at 1,000,000 views has 2^18 such slots; in busy scenes up to
9,000 of 21,000 tables a frame found none, and their draws and
dispatches were dropped (a median of 555 a frame).

The slots now go back as soon as the card has run the flight, as on the
paths that wait for their submissions. The host lists and their upload
memory still wait out the lag, and a resource a reused slot viewed is
still retired through it. One thread lands at a time, so the flights
kept stay in the order they landed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The recording line gave the tables asked for and refused, but not how
many slots they took, so a run could not tell how many frames of tables
the dynamic slots hold. It now adds the slots taken per frame
(diagnostics builds).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
* GPU: heap samplers keep point mips when anisotropic, as static samplers do

A sampler the title makes in a descriptor heap from the console's
description (`CreateSamplerX`, `sampler::console`) became D3D12's plain
anisotropic filter (0x55) whenever its magnification or minification was
anisotropic, whatever its mip filter: an anisotropic sampler with point
mips blended between mip levels on the host. Static samplers in shader
code keep point mips since #1337 (`StaticSampler::filter_for_host`), on
hosts with anisotropic point-mip filtering (`D3D12_OPTIONS19`).

Heap samplers now do the same: 0x54 (with the comparison and min/max
reduction bits) where the console asks for point mips, or none, and the
host has the feature; linear mips (0x55) otherwise, as before. The
feature is asked once (`sampler::aniso_point_mip`), and pipeline
creation uses the same answer instead of asking per pipeline.

Tests: `anisotropic_samplers_keep_point_mips_where_the_host_can` checks
the filter for point, linear and no mips with and without the feature,
and with comparison and maximum reduction (on main the point-mip case
gives 0x55); `the_host_takes_its_anisotropic_samplers` makes such a
sampler in a sampler heap on the host device and checks the device is
not removed (an RTX 5070 Ti reports the feature, so it takes 0x54).

* GPU tests: minimum-reduction anisotropic samplers, and whether a sampler was made

Review (#2031): the mapping test now also checks minimum reduction (0x154
with point-mip support, 0x155 without) and maximum reduction without it
(0x1d5). The device test prints whether it made its sampler (and with
which filter) or skipped for want of a device, so a green run shows
which it was.

(cherry picked from commit 94c1ead4ed8499f2ae3c05d4d5f99b28164cc2cf)
views_kept walked every table entry to count constant buffer and placed views; the report around it took a median 49 ms once the table passed 30 million entries. The two counts are now kept as entries are made and reused (a freed entry reused for another kind is counted out and in, so they match the walk).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The slot-return change came from a tree where the field was `_state`; here it is `state`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Run vt-shapes logged which words tell placed-view shapes apart. Past the resource description's padding (words 1 and 13), the view description's padding word 3 (shader resource views: the union starts on 8 bytes) took 131,392 values and word 9 (the union's unused tail) 36,413 in a million shapes: the title leaves them unwritten, so the same view was a new shape each time. Those words are now zero for each dimension (D3D12_BUFFER_SRV, D3D12_TEX2D_SRV and the like say which words of the union are used); an unknown dimension keeps every word.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Placed views now leave out the resource description's padding words, so a description with values there read back without them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:31:59 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 12:28 UTC · original · edited 2026-11-26 12:32 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T12:31:17.494287Z f1f5221 PR opened
🔒 Security Review ✅ Completed 2026-11-26T12:32:12.346198Z f1f5221 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 12:28 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/27#issuecomment-7192052876) · edited 2026-11-26 12:32 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"f1f52219ecbc1ed6750661871f7aab33f7d41b74","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":"f1f52219ecbc1ed6750661871f7aab33f7d41b74","has_any_findings":null,"has_unresolved_findings":null,"status":"completed"}} --> <!-- codex-security-review:v1 {"blockingSeverityThreshold":"P0","headSha":"f1f52219ecbc1ed6750661871f7aab33f7d41b74","mergeGateEnabled":false,"pullRequestNumber":27,"repository":"TaynanGT/Vice-Tay","status":"completed"} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T12:31:17.494287Z">2026-11-26T12:31:17.494287Z</relative-time> | `f1f5221` | PR opened | | 🔒 **Security Review** | ✅ **Completed** <relative-time datetime="2026-11-26T12:32:12.346198Z">2026-11-26T12:32:12.346198Z</relative-time> | `f1f5221` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 12:31 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1f52219ec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 12:31 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/27#pullrequestreview-6074160059) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `f1f52219ec` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
@ -11945,2 +11989,3 @@
for x in vals {
args.push(self.as_float(x));
let f = self.as_float(x);
args.push(self.nan_guard(f, false));
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 12:31 UTC · original

P2 Badge Bypass the NaN guard for integer-format typed stores

With the default-enabled guard, a non-d16 typed buffer store through a UINT/SINT view corrupts valid integer values whose bits resemble infinity or a canonical NaN. For example, storing 0x7FC00000 now writes zero, and 0x7F800000 becomes 0x477FE000. This path also serves integer views—the existing d16 handling explicitly preserves integer bits through the float-typed handle—so strict: false does not make the transformation safe. Use the existing integer_view metadata to bypass sanitization for integer formats rather than deciding from the stored bit pattern.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 12:31 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/27#discussion_r4708374618) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Bypass the NaN guard for integer-format typed stores** With the default-enabled guard, a non-d16 typed buffer store through a UINT/SINT view corrupts valid integer values whose bits resemble infinity or a canonical NaN. For example, storing `0x7FC00000` now writes zero, and `0x7F800000` becomes `0x477FE000`. This path also serves integer views—the existing d16 handling explicitly preserves integer bits through the float-typed handle—so `strict: false` does not make the transformation safe. Use the existing `integer_view` metadata to bypass sanitization for integer formats rather than deciding from the stored bit pattern. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
github manually merged commit 4223e93ba6 into main 2026-11-26 12:37:16 +00:00
@ -11945,2 +11989,3 @@
for x in vals {
args.push(self.as_float(x));
let f = self.as_float(x);
args.push(self.nan_guard(f, false));
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 01:34 UTC · original

Confirmed on cc9ed86. I opened draft #109 so typed buffer stores can keep UINT and SINT bits through the existing view-kind metadata. Float views still use the guard. The draft includes a synthetic readback test and advances the translation cache version so existing cached DXIL is replaced on use. The Windows workflow is pending.

**@⁠TaynanGT** on GitHub · 2026-11-27 01:34 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/27#discussion_r4714819539) Confirmed on `cc9ed86`. I opened draft #109 so typed buffer stores can keep UINT and SINT bits through the existing view-kind metadata. Float views still use the guard. The draft includes a synthetic readback test and advances the translation cache version so existing cached DXIL is replaced on use. The Windows workflow is pending.
This discussion has been locked. Commenting is limited to contributors.
No description provided.