d3d12: size title-memory BLAS vertex ranges by their largest index #428

Merged
gtb-sbe merged 1 commit from upstream-pr/428 into main 2026-11-29 01:45:02 +00:00
gtb-sbe commented 2026-11-28 23:19:01 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-11-28T23:19:01Z.


Summary

A bottom-level build in title memory imports its vertex range sized by the geometry's VertexCount. Only index format 53 was sized by its largest index (#375). The console's builder reads whichever vertex an index names, and ProjectScarlett has R16 indices past VertexCount (Jerkin42 in #320: 3747 against 16). The host build then reads past the end of the vertex import, and the GPU faults if the next page isn't mapped.

DrArroway named this as one candidate for the in-place update fault in #403. That fault now has another explanation, an update whose source was never built, which ce620c7 in #409 handles. In my own game runs no geometry needed the larger range (see Tests). This change closes the over-read for titles and scenes that do need it, and the new Lanes scenario reproduces it on main.

Change

  • For R16 and R32 indices in title memory, the provider reads the indices on the CPU when the build is recorded. It raises the geometry's VertexCount to one more than the largest index. The vertex import, or the upload for packed positions, is sized by that count, and the host build gets the same count.
  • The count never drops below the title's own. Indices written after recording that stay within the title's VertexCount still fit, as on main.
  • An import of title memory already refuses a range with a page the title hasn't committed (validate_shared_range). A build whose indices name such a page is left out, like any other build the provider can't record. With #406, the scene's instances of that structure become inactive.
  • The build is refused if the indices can't be read on the CPU, or if there are more than 64 MiB of them. Indices in host memory pass through unchanged.
  • In-place updates (PERFORM_UPDATE) take the same path, so an update gets the same count as the build it updates.

Tests

  • New Lanes scenario ray-tracing-index-range. A structure in title memory has two geometries, one with 16-bit and one with 32-bit indices. Each triangle names a vertex pages past what its VertexCount of 3 covers (indices 11000 and 70000). Rays through a scene must hit both triangles where those vertices put them, then again after an in-place update moves the triangles. A second build's indices name a vertex in memory the title only reserved; it must be left out, so its size report stays empty.
    • On main (RX 9060 XT, RADV): GPU page fault in the first submission (TCP, WALKER_ERROR 0x5, PERMISSION_FAULTS 0x3, MAPPING_ERROR 0x1, RW 0x0), followed by a gfx ring timeout and reset. The scenario fails with "did not finish within 2 seconds".
    • With this change: passes, no kernel fault.
  • Unit tests for the index scan in src/tests/commands/guest_addresses.rs. I ran the crate's unit tests under Proton's Wine: the new ones pass, and so do the format-53 and packed-position tests next to them. In the full crate run, 288 passed and 10 failed. All 10 failures are memory_wait GPU tests that stop at D3D12XboxCreateDevice under plain Wine; they don't reach this code.

python tuxbox.py check on Linux, RX 9060 XT (1002:7590), RADV GFX1200, Mesa 26.2.6, kernel 6.18.60, Proton Experimental 20261112:

Summary
  passed   Build the shader compiler (0s)
  FAILED   Python tests (70s)
  passed   Shader compiler tests (1s)
  passed   DXBC tests (0s)
  passed   XG layout tests (13s)
  passed   Storage codec tests (0s)
  passed   D3D12 Windows typecheck (0s)
  passed   Build (50s)
  passed   Lanes and fixtures on the GPU (319s)
  passed   D3D12 regression controls (22s)
  passed   Shader translator on the GPU (81s)
  • Lanes and fixtures: 114 of 114 gates, lanes-selftest-ray-tracing-index-range included. Regression controls: 22 of 22.
  • The Python failure is test_stage_baseline.GuestWatch.test_a_guest_that_died_stops_the_sandbox_instead_of_waiting_out_the_timeout (0 != 'guest gone'). It also fails on main on my machine; the other 580 tests pass or are skipped.

ProjectScarlett 1.0.2.1 (offline, GE-Proton11-14, same card), two runs:

  • With #406: 32 rehydration calls with 492 structures, no refused builds. The run ended in the story intro after 9 min 40 s of Game Running, with a compute-ring read fault at a title address inside the allocation that holds the title's structures (MAPPING_ERROR 0x0). That fits the first cause in #403, not this over-read.
  • With #409 and #424, plus a temporary counter: between 256 and 511 geometries with 16-bit indices in title memory went through the new path, and none had an index at or past its VertexCount. So in this part of the game the change didn't alter anything, and I can't show a game fault it prevents. The run ended on a gfx-ring read of an unmapped native page during draws with one shader pair, with no raytracing command unfinished.

The case for the change is the Lanes reproduction and Jerkin42's observation in #320. The provider change applies cleanly on top of #409 as well. I haven't merged the Lanes lists with it.

NVIDIA: not run. I don't have an NVIDIA card; it would be good to have one run before merging, since this changes what the host build is given.

Not covered

  • Indices written after the build is recorded that exceed both the title's VertexCount and the indices seen at recording. The GPU still reads the title's index buffer directly. Copying the indices into an upload would close this gap. It would also cost one upload per geometry per build, including every per-frame update, and would miss indices written between recording and execution.
  • A VertexCount far larger than the indices need, whose range runs past committed memory, stays refused, as on main.
  • Host prebuild sizes are still queried with the title's inputs, so the host build's VertexCount can be larger than the prebuild's. The format-53 path on main already does this, and RADV sizes structures and scratch by primitive count. DrArroway plans to query prebuild info after geometry translation on top of #409 (see #409). That covers this case as well, so I left the prebuild query alone here.
  • #403: the BLAS lifetime and prebuild work is DrArroway's and NickStallman's (#409) and separate from this.
  • #406 and #409 both make the instances of a structure the host has no build for inactive. This change relies on that for builds whose indices name uncommitted memory. It conflicts with #406 only in the Lanes scenario lists.
  • #320: Jerkin42's audit of the title's build inputs.

AI use

I made this branch with an AI coding agent (Claude Code, following AGENTS.md). The agent read the build path, wrote the Lanes scenario, the change and the unit tests, and ran the checks above on my machine: the scenario against main's provider and against this branch, the d3d12 unit tests under Wine, the full check, and two ProjectScarlett runs (one with #406, one with #409, #424 and a temporary counter that isn't part of this branch). I reviewed the diff.

<!-- greyfinch-sync:brcly/TuxBox:issue:5545559427 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/428). Originally posted by [gtb-sbe](https://github.com/gtb-sbe) on 2026-11-28T23:19:01Z. --- ## Summary A bottom-level build in title memory imports its vertex range sized by the geometry's `VertexCount`. Only index format 53 was sized by its largest index (#375). The console's builder reads whichever vertex an index names, and ProjectScarlett has R16 indices past `VertexCount` (Jerkin42 in #320: 3747 against 16). The host build then reads past the end of the vertex import, and the GPU faults if the next page isn't mapped. DrArroway named this as one candidate for the in-place update fault in #403. That fault now has another explanation, an update whose source was never built, which `ce620c7` in #409 handles. In my own game runs no geometry needed the larger range (see Tests). This change closes the over-read for titles and scenes that do need it, and the new Lanes scenario reproduces it on `main`. ## Change - For R16 and R32 indices in title memory, the provider reads the indices on the CPU when the build is recorded. It raises the geometry's `VertexCount` to one more than the largest index. The vertex import, or the upload for packed positions, is sized by that count, and the host build gets the same count. - The count never drops below the title's own. Indices written after recording that stay within the title's `VertexCount` still fit, as on `main`. - An import of title memory already refuses a range with a page the title hasn't committed (`validate_shared_range`). A build whose indices name such a page is left out, like any other build the provider can't record. With #406, the scene's instances of that structure become inactive. - The build is refused if the indices can't be read on the CPU, or if there are more than 64 MiB of them. Indices in host memory pass through unchanged. - In-place updates (`PERFORM_UPDATE`) take the same path, so an update gets the same count as the build it updates. ## Tests - New Lanes scenario `ray-tracing-index-range`. A structure in title memory has two geometries, one with 16-bit and one with 32-bit indices. Each triangle names a vertex pages past what its `VertexCount` of 3 covers (indices 11000 and 70000). Rays through a scene must hit both triangles where those vertices put them, then again after an in-place update moves the triangles. A second build's indices name a vertex in memory the title only reserved; it must be left out, so its size report stays empty. - On `main` (RX 9060 XT, RADV): GPU page fault in the first submission (`TCP`, `WALKER_ERROR 0x5`, `PERMISSION_FAULTS 0x3`, `MAPPING_ERROR 0x1`, `RW 0x0`), followed by a gfx ring timeout and reset. The scenario fails with "did not finish within 2 seconds". - With this change: passes, no kernel fault. - Unit tests for the index scan in `src/tests/commands/guest_addresses.rs`. I ran the crate's unit tests under Proton's Wine: the new ones pass, and so do the format-53 and packed-position tests next to them. In the full crate run, 288 passed and 10 failed. All 10 failures are `memory_wait` GPU tests that stop at `D3D12XboxCreateDevice` under plain Wine; they don't reach this code. `python tuxbox.py check` on Linux, RX 9060 XT (1002:7590), RADV GFX1200, Mesa 26.2.6, kernel 6.18.60, Proton Experimental 20261112: ``` Summary passed Build the shader compiler (0s) FAILED Python tests (70s) passed Shader compiler tests (1s) passed DXBC tests (0s) passed XG layout tests (13s) passed Storage codec tests (0s) passed D3D12 Windows typecheck (0s) passed Build (50s) passed Lanes and fixtures on the GPU (319s) passed D3D12 regression controls (22s) passed Shader translator on the GPU (81s) ``` - Lanes and fixtures: 114 of 114 gates, `lanes-selftest-ray-tracing-index-range` included. Regression controls: 22 of 22. - The Python failure is `test_stage_baseline.GuestWatch.test_a_guest_that_died_stops_the_sandbox_instead_of_waiting_out_the_timeout` (`0 != 'guest gone'`). It also fails on `main` on my machine; the other 580 tests pass or are skipped. ProjectScarlett 1.0.2.1 (offline, GE-Proton11-14, same card), two runs: - With #406: 32 rehydration calls with 492 structures, no refused builds. The run ended in the story intro after 9 min 40 s of `Game Running`, with a compute-ring read fault at a title address inside the allocation that holds the title's structures (`MAPPING_ERROR 0x0`). That fits the first cause in #403, not this over-read. - With #409 and #424, plus a temporary counter: between 256 and 511 geometries with 16-bit indices in title memory went through the new path, and none had an index at or past its `VertexCount`. So in this part of the game the change didn't alter anything, and I can't show a game fault it prevents. The run ended on a gfx-ring read of an unmapped native page during draws with one shader pair, with no raytracing command unfinished. The case for the change is the Lanes reproduction and Jerkin42's observation in #320. The provider change applies cleanly on top of #409 as well. I haven't merged the Lanes lists with it. NVIDIA: not run. I don't have an NVIDIA card; it would be good to have one run before merging, since this changes what the host build is given. ## Not covered - Indices written after the build is recorded that exceed both the title's `VertexCount` and the indices seen at recording. The GPU still reads the title's index buffer directly. Copying the indices into an upload would close this gap. It would also cost one upload per geometry per build, including every per-frame update, and would miss indices written between recording and execution. - A `VertexCount` far larger than the indices need, whose range runs past committed memory, stays refused, as on `main`. - Host prebuild sizes are still queried with the title's inputs, so the host build's `VertexCount` can be larger than the prebuild's. The format-53 path on `main` already does this, and RADV sizes structures and scratch by primitive count. DrArroway plans to query prebuild info after geometry translation on top of #409 (see #409). That covers this case as well, so I left the prebuild query alone here. ## Related - #403: the BLAS lifetime and prebuild work is DrArroway's and NickStallman's (#409) and separate from this. - #406 and #409 both make the instances of a structure the host has no build for inactive. This change relies on that for builds whose indices name uncommitted memory. It conflicts with #406 only in the Lanes scenario lists. - #320: Jerkin42's audit of the title's build inputs. ## AI use I made this branch with an AI coding agent (Claude Code, following `AGENTS.md`). The agent read the build path, wrote the Lanes scenario, the change and the unit tests, and ran the checks above on my machine: the scenario against `main`'s provider and against this branch, the d3d12 unit tests under Wine, the full `check`, and two ProjectScarlett runs (one with #406, one with #409, #424 and a temporary counter that isn't part of this branch). I reviewed the diff.
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
brcly/TuxBox!428
No description provided.