hwrt: bound the title's BLAS counts before a copy is allocated for them #644

Open
qnjk wants to merge 1 commit from qnjk/Darner:hwrt-input-buffers into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: the decoders that read the title's BLAS inputs from copies size their buffer from the title's own descriptor fields before asking whether its pages are there — read_title does vec![0u8; len] and only then host::read_into. Those fields are read without validation (read_geometries does a read_unaligned of the title's descriptors), and the lengths they produce are far past any mesh: the quant24 vertex count and stride ask for up to ~140 TB, icount for ~17 GB, and the meshlet header's num_packed_tris for 5.7 GB. vec![0u8; len] on such a length is not a panic a caller can answer — the default allocator aborts the process, on the title's recording thread, where the layer's failure path never sees it. The in-place twins of the same two decoders already answer a range that is not there by dropping the geometry (title_readable), so a count read wrong should cost the mesh, not the run.

  • This change refuses a length past READ_MOST (256 MiB — a few times the 64 MiB a frame's builds are given, and well under the largest live BLAS budget) and makes both copy decoders answer Some(None), the "drop this geometry" answer their callers already give an unreadable buffer, so the mapped twin is not tried on a count that cannot be a mesh.

How it was tested

  • Tested revision: 8c7a81c (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-gpu --lib -- hwrt — 30 passed, 0 failed.
    • New test hwrt::tests::copy_decoders_refuse_a_count_that_is_not_a_mesh asks the two decoders for 131 TB and 5.7 GB of copies from a local buffer. Fail-before, with the bound removed: the test process aborts with memory allocation of 131067999967273 bytes failed (0xc0000409); it passes now, with the geometry dropped.
    • cargo clippy --locked -p darner-gpu --all-targets -- -D warnings passes.
  • Changes a default: no. A count a real mesh produces is accepted exactly as before.
  • A/B result: not applicable — no default change and no speed claim.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3: the crate's hwrt tests are green; the whole-workspace run is not green on this machine for the pre-existing darner-gpu reasons (#224, #150), which this does not touch.
  • Gameplay, when relevant: no gameplay run. The path needs a title whose BLAS descriptor is misread; the test supplies the counts directly. No visual or frame-rate claim is made.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: only the two copy decoders are bounded; the mapped (in-place) twins and the meshlet decode's own arithmetic are untouched, and READ_MOST is a policy number chosen from the budgets, not measured from a real title's largest mesh.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay: the fault needs a descriptor the title does not legitimately produce; the test reproduces the abort deterministically. No gameplay claim is made.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: passes).
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #268, #452, #453 and #57 change crates/darner-gpu/src/hwrt.rs; none of their descriptions mentions the copy decoders' allocation. No open or closed issue mentions read_title or a BLAS count that cannot be a mesh.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: the decoders that read the title's BLAS inputs from copies size their buffer from the title's own descriptor fields before asking whether its pages are there — `read_title` does `vec![0u8; len]` and only then `host::read_into`. Those fields are read without validation (`read_geometries` does a `read_unaligned` of the title's descriptors), and the lengths they produce are far past any mesh: the quant24 vertex count and stride ask for up to ~140 TB, `icount` for ~17 GB, and the meshlet header's `num_packed_tris` for 5.7 GB. `vec![0u8; len]` on such a length is not a panic a caller can answer — the default allocator aborts the process, on the title's recording thread, where the layer's failure path never sees it. The in-place twins of the same two decoders already answer a range that is not there by dropping the geometry (`title_readable`), so a count read wrong should cost the mesh, not the run. - This change refuses a length past `READ_MOST` (256 MiB — a few times the 64 MiB a frame's builds are given, and well under the largest live BLAS budget) and makes both copy decoders answer `Some(None)`, the "drop this geometry" answer their callers already give an unreadable buffer, so the mapped twin is not tried on a count that cannot be a mesh. ## How it was tested - Tested revision: `8c7a81c` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-gpu --lib -- hwrt` — 30 passed, 0 failed. - New test `hwrt::tests::copy_decoders_refuse_a_count_that_is_not_a_mesh` asks the two decoders for 131 TB and 5.7 GB of copies from a local buffer. Fail-before, with the bound removed: the test process aborts with `memory allocation of 131067999967273 bytes failed` (`0xc0000409`); it passes now, with the geometry dropped. - `cargo clippy --locked -p darner-gpu --all-targets -- -D warnings` passes. - Changes a default: no. A count a real mesh produces is accepted exactly as before. - A/B result: not applicable — no default change and no speed claim. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3: the crate's `hwrt` tests are green; the whole-workspace run is not green on this machine for the pre-existing `darner-gpu` reasons (#224, #150), which this does not touch. - Gameplay, when relevant: no gameplay run. The path needs a title whose BLAS descriptor is misread; the test supplies the counts directly. No visual or frame-rate claim is made. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: only the two copy decoders are bounded; the mapped (in-place) twins and the meshlet decode's own arithmetic are untouched, and `READ_MOST` is a policy number chosen from the budgets, not measured from a real title's largest mesh. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay: the fault needs a descriptor the title does not legitimately produce; the test reproduces the abort deterministically. No gameplay claim is made. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: passes). - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #268, #452, #453 and #57 change `crates/darner-gpu/src/hwrt.rs`; none of their descriptions mentions the copy decoders' allocation. No open or closed issue mentions `read_title` or a BLAS count that cannot be a mesh. - Replaces or overlaps: none found
The decoders that read the title's BLAS inputs from copies size their
buffer from the title's own descriptor fields before asking whether its
pages are there: `read_title` does `vec![0u8; len]` and only then
`host::read_into`. Those fields are read without validation
(`read_geometries` does a `read_unaligned` of the title's descriptors),
and the lengths they produce are far past any mesh: the quant24 vertex
count and stride ask for up to ~140 TB, `icount` for ~17 GB and the
meshlet header's `num_packed_tris` for 5.7 GB. `vec![0u8; len]` on such
a length is not a panic a caller can answer: the default allocator
aborts the process, on the title's recording thread, where the layer's
failure path never sees it. The in-place twins of the same two decoders
already answer a range that is not there by dropping the geometry
(`title_readable`), so a count read wrong should cost the mesh, not the
run.

`read_title` now refuses a length past `READ_MOST` (256 MiB: a few
times the 64 MiB a frame's builds are given, and well under the largest
live BLAS budget), and both copy decoders answer `Some(None)` — the
"drop this geometry" answer their callers already give an unreadable
buffer — so the mapped twin is not tried on a count that cannot be a
mesh.

`hwrt::tests::copy_decoders_refuse_a_count_that_is_not_a_mesh` asks the
two decoders for 131 TB and 5.7 GB of copies from a local buffer. With
the old code the test process aborts (`memory allocation of
131067999967273 bytes failed`, 0xc0000409) instead of reporting; it
passes now.
TrustNo1 changed title from [pr-fix][memory][RAYTRACING] hwrt: bound the title's BLAS counts before a copy is allocated for them to hwrt: bound the title's BLAS counts before a copy is allocated for them 2026-12-06 03:25:38 +00:00
Owner

Test needed — commit 8c7a81ce; what to check:

  • The problem on main: the decoders that read the title's BLAS inputs from copies size their buffer from the title's own descriptor fields before asking whether its pages are there — read_title does vec![0u8; len] and only then host::read_into. Those fields are read without validation (read_geometries does a read_unaligned of the title's descriptors), and the lengths they produce are far past any mesh: the quant24 vertex count and stride ask for up to ~140 TB, icount for ~17 GB, and the meshlet header's num_packed_tris for 5.7 GB. vec![0u8; len] on such a length is not a panic a caller can answer — the default allocator aborts the process, on the title's recording thread, where the layer's failure path never sees it. The in-place twins of the same two decoders already answer a range that is not there by dropping the geometry (title_readable), so a count read wrong should cost the mesh, not the run.

  • This change refuses a length past READ_MOST (256 MiB — a few times the 64 MiB a frame's builds are given, and well under the largest live BLAS budget) and makes both copy decoders answer Some(None), the "drop this geometry" answer their callers already give an un

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `8c7a81ce`; what to check: - The problem on main: the decoders that read the title's BLAS inputs from copies size their buffer from the title's own descriptor fields before asking whether its pages are there — `read_title` does `vec![0u8; len]` and only then `host::read_into`. Those fields are read without validation (`read_geometries` does a `read_unaligned` of the title's descriptors), and the lengths they produce are far past any mesh: the quant24 vertex count and stride ask for up to ~140 TB, `icount` for ~17 GB, and the meshlet header's `num_packed_tris` for 5.7 GB. `vec![0u8; len]` on such a length is not a panic a caller can answer — the default allocator aborts the process, on the title's recording thread, where the layer's failure path never sees it. The in-place twins of the same two decoders already answer a range that is not there by dropping the geometry (`title_readable`), so a count read wrong should cost the mesh, not the run. - This change refuses a length past `READ_MOST` (256 MiB — a few times the 64 MiB a frame's builds are given, and well under the largest live BLAS budget) and makes both copy decoders answer `Some(None)`, the "drop this geometry" answer their callers already give an un Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'hwrt-input-buffers:qnjk-hwrt-input-buffers'
git switch 'qnjk-hwrt-input-buffers'

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 'qnjk-hwrt-input-buffers'
git switch 'qnjk-hwrt-input-buffers'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-hwrt-input-buffers'
git switch 'qnjk-hwrt-input-buffers'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-hwrt-input-buffers'
git switch 'Main'
git merge --squash 'qnjk-hwrt-input-buffers'
git switch 'Main'
git merge --ff-only 'qnjk-hwrt-input-buffers'
git switch 'Main'
git merge 'qnjk-hwrt-input-buffers'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!644
No description provided.