d3d12: decode packed positions in title-memory BLAS builds (stacked on #375) #376

Merged
Jerkin42 merged 8 commits from upstream-pr/376 into main 2026-11-28 14:41:16 +00:00
Jerkin42 commented 2026-11-28 06:39:58 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-28T06:39:58Z.


Summary

Stacked on #375, which is stacked on #320. Only the last two commits, 02f9e10 and a474745, are new here; the rest is #320 and #375. I'll rebase as those land.

ProjectScarlett's own bottom-level builds also give their vertices as R32G32_FLOAT, as 8-byte records. These aren't two floats per vertex: the console's acceleration-structure builder has no two-component float position path. Its leaf kernel compares the vertex format against DXGI codes (6, 10, 11, 13, 16, 24, 28, 31, 34, 35). For 16 (R32G32_FLOAT) it loads a 32-byte header from just before the vertex buffer and decodes 8-byte records. It checks no stride and has no other path for that format. A host build reads the same bytes as two floats per vertex.

The layout:

  • header at StartAddress - 32: origin (3 floats), axis order (u32), scale (3 floats), one unused word;
  • each record: a = lo >> 8, b = (hi & 0xffff) << 8 | (lo & 0xff), c = hi >> 16;
  • each coordinate becomes q * scale + origin, then the axis order arranges them: 0 gives (c, b, a), 1 gives (b, c, a), others (a, b, c);
  • the build's Transform3x4 still applies afterwards.

This commit decodes them on the CPU (commands/build_raytracing/packed_positions.rs) into R32G32B32_FLOAT positions in an upload buffer the list retains. It does so only when the header and every record are title memory: as in #375, an address the host already knows is a GPU address, and the build is refused there. A header with a non-finite origin or scale, or a range that cannot be read, also refuses the build.

Stride (a474745). The title passes a vertex stride of 0x8008 for these 8-byte records; the builder reads the stride through a 14-bit field, so only the low 14 bits count. The import span and the decode both use StrideInBytes & 0x3fff. With the raw stride, a 180-vertex import spanned 5.8 MB and XMem refused it with ERROR_INVALID_ADDRESS, and a small mesh on mapped pages was decoded from the wrong bytes. @NickStallman measured this on an RTX 5090: at stride 8, 1,124 of 1,124 vertices of 36 logged geometries fall inside their scene bounds, and the 64 "geometry 0x800701e7" skips on the rehydration path went to 0.

Prebuild sizes do not change: the vertex format and stride only change how positions are fetched, not the number of primitives.

Validation: the same decoding put every one of 152 captured ProjectScarlett structures inside its scene bounds, checked offline before this port. This PR has not been run in game on its own.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: NVIDIA still needs to run them.

No Lanes scenario, for the same reason as #375: there is no title-memory BLAS case to extend. The decoder is a pure function over the header and record bytes, covered by unit tests in tests/commands/packed_positions.rs:

  • coordinates scale from the origin in each axis order;
  • a wider stride skips the bytes between records;
  • non-finite headers, a short header, a short range and a stride under 8 are refused.

These tests compile in the Windows typecheck. I also ran them on Linux by building the module on its own: 3 passed.

GPU, driver and backend: AMD RX 9060 XT, Mesa RADV 26.1.8, Linux 7.3.1, Proton Experimental (private rootful Xwayland)

Commands run and their results:

python tuxbox.py check
  passed   Build the shader compiler, Python tests, Shader compiler tests, DXBC tests,
           XG layout tests, D3D12 Windows typecheck, Build,
           D3D12 regression controls, Shader translator on the GPU
  FAILED   Lanes and fixtures on the GPU: 147 PASS, 1 FAIL (invalid-route, which fails the same way on main on this machine)

Checks

No evidence JSON changes.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5537538487 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/376). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-28T06:39:58Z. --- ## Summary **Stacked on #375, which is stacked on #320.** Only the last two commits, 02f9e10 and a474745, are new here; the rest is #320 and #375. I'll rebase as those land. ProjectScarlett's own bottom-level builds also give their vertices as R32G32_FLOAT, as 8-byte records. These aren't two floats per vertex: the console's acceleration-structure builder has no two-component float position path. Its leaf kernel compares the vertex format against DXGI codes (6, 10, 11, 13, 16, 24, 28, 31, 34, 35). For 16 (R32G32_FLOAT) it loads a 32-byte header from just before the vertex buffer and decodes 8-byte records. It checks no stride and has no other path for that format. A host build reads the same bytes as two floats per vertex. The layout: - header at `StartAddress - 32`: origin (3 floats), axis order (u32), scale (3 floats), one unused word; - each record: `a = lo >> 8`, `b = (hi & 0xffff) << 8 | (lo & 0xff)`, `c = hi >> 16`; - each coordinate becomes `q * scale + origin`, then the axis order arranges them: 0 gives (c, b, a), 1 gives (b, c, a), others (a, b, c); - the build's `Transform3x4` still applies afterwards. This commit decodes them on the CPU (`commands/build_raytracing/packed_positions.rs`) into R32G32B32_FLOAT positions in an upload buffer the list retains. It does so only when the header and every record are title memory: as in #375, an address the host already knows is a GPU address, and the build is refused there. A header with a non-finite origin or scale, or a range that cannot be read, also refuses the build. **Stride (a474745).** The title passes a vertex stride of `0x8008` for these 8-byte records; the builder reads the stride through a 14-bit field, so only the low 14 bits count. The import span and the decode both use `StrideInBytes & 0x3fff`. With the raw stride, a 180-vertex import spanned 5.8 MB and XMem refused it with `ERROR_INVALID_ADDRESS`, and a small mesh on mapped pages was decoded from the wrong bytes. @NickStallman measured this on an RTX 5090: at stride 8, 1,124 of 1,124 vertices of 36 logged geometries fall inside their scene bounds, and the 64 "geometry 0x800701e7" skips on the rehydration path went to 0. Prebuild sizes do not change: the vertex format and stride only change how positions are fetched, not the number of primitives. Validation: the same decoding put every one of 152 captured ProjectScarlett structures inside its scene bounds, checked offline before this port. This PR has not been run in game on its own. ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [ ] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: **NVIDIA still needs to run them.** No Lanes scenario, for the same reason as #375: there is no title-memory BLAS case to extend. The decoder is a pure function over the header and record bytes, covered by unit tests in `tests/commands/packed_positions.rs`: - coordinates scale from the origin in each axis order; - a wider stride skips the bytes between records; - non-finite headers, a short header, a short range and a stride under 8 are refused. These tests compile in the Windows typecheck. I also ran them on Linux by building the module on its own: 3 passed. GPU, driver and backend: AMD RX 9060 XT, Mesa RADV 26.1.8, Linux 7.3.1, Proton Experimental (private rootful Xwayland) Commands run and their results: ```text python tuxbox.py check passed Build the shader compiler, Python tests, Shader compiler tests, DXBC tests, XG layout tests, D3D12 Windows typecheck, Build, D3D12 regression controls, Shader translator on the GPU FAILED Lanes and fixtures on the GPU: 147 PASS, 1 FAIL (invalid-route, which fails the same way on main on this machine) ``` ## Checks No evidence JSON changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NickStallman commented 2026-11-28 09:45:45 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T09:45:45Z.


@Jerkin42, a finding on the packed 8-byte positions this PR decodes. Measured in ProjectScarlett on an RTX 5090 (620.70.10), with this PR merged locally.

The title gives these geometries a vertex stride of 0x8008 (32,776), but the data is 8-byte records.

  • Test: for 36 logged geometries (R32G32_FLOAT, stride 0x8008), we decoded the positions at both the raw stride and its low 14 bits, and compared them with the structure header's scene bounds (+0x10/+0x1c).
    • At stride 8: 1,124 of 1,124 vertices fall inside the bounds.
    • At 0x8008: all 36 ranges run into pages the title never mapped.
  • The bug when the raw stride is used: for a 180-vertex mesh, the import spans 5.8 MB, so XMem refuses the whole range with 0x800701e7 (ERROR_INVALID_ADDRESS). A small mesh that stays on mapped pages is decoded silently from the wrong bytes instead.
  • With the stride masked (StrideInBytes & 0x3fff), the 64 "geometry 0x800701e7" skips we saw on the rehydration path in an earlier run went to 0.

Inferred, not verified: the console reads the stride through a 14-bit field, so the high bits are ignored there.

We'll include the mask, with a unit test that fails without it, in the rehydration PR we're stacking on this one. You may prefer to take it into this PR directly, since it affects ordinary builds too.

<!-- greyfinch-sync:brcly/TuxBox:comment:7237448592 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/376#issuecomment-7237448592). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-28T09:45:45Z. --- @Jerkin42, a finding on the packed 8-byte positions this PR decodes. Measured in ProjectScarlett on an RTX 5090 (620.70.10), with this PR merged locally. **The title gives these geometries a vertex stride of `0x8008` (32,776), but the data is 8-byte records.** - **Test:** for 36 logged geometries (R32G32_FLOAT, stride `0x8008`), we decoded the positions at both the raw stride and its low 14 bits, and compared them with the structure header's scene bounds (+0x10/+0x1c). - At stride 8: **1,124 of 1,124 vertices fall inside the bounds.** - At `0x8008`: all 36 ranges run into pages the title never mapped. - **The bug when the raw stride is used:** for a 180-vertex mesh, the import spans 5.8 MB, so XMem refuses the whole range with `0x800701e7` (ERROR_INVALID_ADDRESS). A small mesh that stays on mapped pages is decoded silently from the wrong bytes instead. - **With the stride masked** (`StrideInBytes & 0x3fff`), the 64 "geometry 0x800701e7" skips we saw on the rehydration path in an earlier run went to **0**. **Inferred, not verified:** the console reads the stride through a 14-bit field, so the high bits are ignored there. We'll include the mask, with a unit test that fails without it, in the rehydration PR we're stacking on this one. You may prefer to take it into this PR directly, since it affects ordinary builds too.
Jerkin42 commented 2026-11-28 09:55:21 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-28T09:55:21Z.


Thank you, @NickStallman, that's a clear result. I've taken the mask into this PR in a474745: the packed-position path now uses StrideInBytes & 0x3fff for both the import span and the decode. There's a unit test for 0x8008 → 8, and the decoder's tests pass. I left other formats' strides alone, since your measurement covers only this one.

Your rehydration PR can then rely on it from here. If you want a test that fails without the mask on your side, stride(0x8008) in packed_positions.rs is the place to hook it.

<!-- greyfinch-sync:brcly/TuxBox:comment:7237553368 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/376#issuecomment-7237553368). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-28T09:55:21Z. --- Thank you, @NickStallman, that's a clear result. I've taken the mask into this PR in a474745: the packed-position path now uses `StrideInBytes & 0x3fff` for both the import span and the decode. There's a unit test for `0x8008` → 8, and the decoder's tests pass. I left other formats' strides alone, since your measurement covers only this one. Your rehydration PR can then rely on it from here. If you want a test that fails without the mask on your side, `stride(0x8008)` in `packed_positions.rs` is the place to hook it.
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!376
No description provided.