Proposal: handle Xbox 16-byte CBV offsets inside TuxBox instead of the descriptor layer (follow-up to #212) #251

Open
opened 2026-11-26 17:07:23 +00:00 by NickStallman · 7 comments
NickStallman commented 2026-11-26 17:07:23 +00:00 (Migrated from github.com)
Contributor

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-26T17:07:23Z.


#212 keeps Xbox 16-byte CBV offsets working on NVIDIA by hiding VK_EXT_descriptor_buffer and VK_EXT_descriptor_heap through the layer, so vkd3d-proton falls back to storage-buffer CBVs. That's a stopgap: it depends on vkd3d-proton's descriptor model and a Vulkan layer, and the Proton fork's cbv_16_byte_alignment is another route to the same result. This proposes handling the offsets inside TuxBox instead. Before anyone builds it, does this fit the direction you want?

Today

  • Table CBVs: device/views/mirrors.rs:4-48 creates a native CBV at host VA + residue, keeping the 16-byte residue. That's what NVIDIA can't honour for uniform buffers, which need 64-byte alignment (docs/MATRIX_AWAKENS.md:61: 768 of 3,072 words read correctly without the layer).
  • Root CBVs: use the exact VA (commands/compute.rs).
  • Translated programs: read cbuffer CB{slot} { uint4 cb{slot}[N]; } (hlsl/emitter/output.rs:217).

Proposal

  1. A probed host-profile capability, cbv-offset=exact|rounded, next to wave and section-import in device/host_profile.rs. It's chosen by what the driver can do, not by vendor.
  2. On rounded hosts:
    • Translated programs read constant buffers as ByteAddressBuffer through a tb_cb(word) helper.
    • The provider creates table CBVs as exact-length raw R32 SRVs.
    • Root CBVs are also bound as an appended root SRV.
    • This is zero-copy, with no layer, and independent of vkd3d-proton's descriptor model.
  3. A cache-key variant, following the narrow_waves precedent.
  4. A Lanes scenario cbv-offsets:
    • 16 CBVs of 48 bytes at base + 16*k, half bound directly and half through CopyDescriptors.
    • Data rewritten between record and submit.
    • Static, dynamic and root reads.

Migration: add the probe and the storage path, tested with TUXBOX_HOST_PROFILE=cbv-offset=rounded; then have the launcher skip the layer when the provider has the path; then default the layer off; then remove the layer, the patch and the feature.

Open questions

  • Pass-through desktop DXIL with table cbuffers would see an SRV. That affects Lanes fixtures such as selftest.cpp and reclaim.hlsl. The fallback is to keep the layer for those.
  • Are misaligned root CBVs already wrong on NVIDIA today?
  • How does ahead-of-launch shader preparation learn the capability?
  • Raw SRVs at 16-byte offsets under VK_EXT_descriptor_heap haven't been verified in vkd3d-proton.

I'm happy to take this on if you want it, or to leave it if you'd rather keep the layer.

<!-- greyfinch-sync:brcly/TuxBox:issue:6631614925 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/251). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-26T17:07:23Z. --- #212 keeps Xbox 16-byte CBV offsets working on NVIDIA by hiding `VK_EXT_descriptor_buffer` and `VK_EXT_descriptor_heap` through the layer, so vkd3d-proton falls back to storage-buffer CBVs. That's a stopgap: it depends on vkd3d-proton's descriptor model and a Vulkan layer, and the Proton fork's `cbv_16_byte_alignment` is another route to the same result. This proposes handling the offsets inside TuxBox instead. **Before anyone builds it, does this fit the direction you want?** **Today** - **Table CBVs:** `device/views/mirrors.rs:4-48` creates a native CBV at `host VA + residue`, keeping the 16-byte residue. That's what NVIDIA can't honour for uniform buffers, which need 64-byte alignment (`docs/MATRIX_AWAKENS.md:61`: 768 of 3,072 words read correctly without the layer). - **Root CBVs:** use the exact VA (`commands/compute.rs`). - **Translated programs:** read `cbuffer CB{slot} { uint4 cb{slot}[N]; }` (`hlsl/emitter/output.rs:217`). **Proposal** 1. **A probed host-profile capability**, `cbv-offset=exact|rounded`, next to `wave` and `section-import` in `device/host_profile.rs`. It's chosen by what the driver can do, not by vendor. 2. **On `rounded` hosts:** - Translated programs read constant buffers as `ByteAddressBuffer` through a `tb_cb(word)` helper. - The provider creates table CBVs as exact-length raw R32 SRVs. - Root CBVs are also bound as an appended root SRV. - This is zero-copy, with no layer, and independent of vkd3d-proton's descriptor model. 3. **A cache-key variant**, following the `narrow_waves` precedent. 4. **A Lanes scenario `cbv-offsets`:** - 16 CBVs of 48 bytes at `base + 16*k`, half bound directly and half through CopyDescriptors. - Data rewritten between record and submit. - Static, dynamic and root reads. **Migration:** add the probe and the storage path, tested with `TUXBOX_HOST_PROFILE=cbv-offset=rounded`; then have the launcher skip the layer when the provider has the path; then default the layer off; then remove the layer, the patch and the feature. **Open questions** - Pass-through desktop DXIL with table cbuffers would see an SRV. That affects Lanes fixtures such as `selftest.cpp` and `reclaim.hlsl`. The fallback is to keep the layer for those. - Are misaligned root CBVs already wrong on NVIDIA today? - How does ahead-of-launch shader preparation learn the capability? - Raw SRVs at 16-byte offsets under `VK_EXT_descriptor_heap` haven't been verified in vkd3d-proton. I'm happy to take this on if you want it, or to leave it if you'd rather keep the layer.
brcly commented 2026-11-26 17:09:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-26T17:09:46Z.


I'm gonna investigate, thanks for the research

<!-- greyfinch-sync:brcly/TuxBox:comment:7198586608 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/251#issuecomment-7198586608). Originally posted by [brcly](https://github.com/brcly) on 2026-11-26T17:09:46Z. --- I'm gonna investigate, thanks for the research
brcly commented 2026-11-26 18:42:22 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-26T18:42:22Z.


I've made a "temporary" commit to help with this issue, but further validation is needed for the direction taken.

<!-- greyfinch-sync:brcly/TuxBox:comment:7200760858 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/251#issuecomment-7200760858). Originally posted by [brcly](https://github.com/brcly) on 2026-11-26T18:42:22Z. --- I've made a "temporary" commit to help with this issue, but further validation is needed for the direction taken.
NickStallman commented 2026-11-26 20:25:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-26T20:25:20Z.


I measured 5c5677b with a root CBV control. The guest binds one root CBV at every 16-byte offset from 0 to 256 and reads 24 words at each. Same provider build (facfaab), GE-Proton11-14, vkd3d-proton v3.1-83 (cae8353).

RTX 5090, 620.70.10 AMD Raphael iGPU, RADV 26.0.8
stock (the log shows VK_EXT_descriptor_heap enabled) 5/17 17/17
stock + force_raw_va_cbv 5/17
VKD3D_CONFIG=no_descriptor_heap 5/17
no_descriptor_heap + force_raw_va_cbv 17/17
console CBV layer 5/17 17/17
layer + force_raw_va_cbv (what tuxbox.py run sets) 17/17 17/17

On NVIDIA the wrong offsets are 16, 32, 48, 80, … 240, so every offset that isn't a multiple of 64 reads wrong. That fits a uniform buffer rounded down to 64 bytes.

What this shows

  • On NVIDIA, misaligned root CBVs read wrong under both of vkd3d's descriptor models, not only with the layer.
  • force_raw_va_cbv fixes them only on the descriptor-set path, which is the one the layer forces. On the descriptor-heap path it changes nothing, which matches "without the layer the setting had no effect".
  • So 5c5677b is right for tuxbox.py run, because there the setting always comes with the layer or the fork feature. A run without the layer (for example TUXBOX_REFERENCE_CBV unset with a provider that doesn't match the build, or Windows) still reads root CBVs at the rounded address.

Not covered by any check today

  • tuxbox.py check starts the Lanes, the fixtures and the D3D12 controls through Host.run, which sets neither the layer nor the setting.
  • The existing root-cbv-window control only uses offsets that are multiples of 256, so it passes either way.
  • The test in tests/test_host.py checks the variable, not a read.

I have the 17-offset control as an --offsets mode for root_cbv_guest.cpp, plus a root-cbv-offsets case for check_d3d12_regressions.py, left out of the default set. Happy to open it as a PR. As a default case it would fail on NVIDIA under tuxbox.py check until checks run with the launcher's CBV setup, or until the offsets are handled in the provider as #251 proposes. That route doesn't depend on which descriptor model vkd3d picks, which these numbers make more attractive.

Not measured yet: root CBVs in a graphics or mesh pipeline, and frame time with the setting on a retail scene.

<!-- greyfinch-sync:brcly/TuxBox:comment:7202659809 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/251#issuecomment-7202659809). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-26T20:25:20Z. --- I measured 5c5677b with a root CBV control. The guest binds one root CBV at every 16-byte offset from 0 to 256 and reads 24 words at each. Same provider build (facfaab), GE-Proton11-14, vkd3d-proton v3.1-83 (cae8353). | | RTX 5090, 620.70.10 | AMD Raphael iGPU, RADV 26.0.8 | |---|---:|---:| | stock (the log shows `VK_EXT_descriptor_heap enabled`) | 5/17 | 17/17 | | stock + `force_raw_va_cbv` | 5/17 | | | `VKD3D_CONFIG=no_descriptor_heap` | 5/17 | | | `no_descriptor_heap` + `force_raw_va_cbv` | **17/17** | | | console CBV layer | 5/17 | 17/17 | | layer + `force_raw_va_cbv` (what `tuxbox.py run` sets) | **17/17** | 17/17 | On NVIDIA the wrong offsets are 16, 32, 48, 80, … 240, so every offset that isn't a multiple of 64 reads wrong. That fits a uniform buffer rounded down to 64 bytes. **What this shows** - On NVIDIA, misaligned root CBVs read wrong under both of vkd3d's descriptor models, not only with the layer. - `force_raw_va_cbv` fixes them only on the descriptor-set path, which is the one the layer forces. On the descriptor-heap path it changes nothing, which matches "without the layer the setting had no effect". - So 5c5677b is right for `tuxbox.py run`, because there the setting always comes with the layer or the fork feature. A run without the layer (for example `TUXBOX_REFERENCE_CBV` unset with a provider that doesn't match the build, or Windows) still reads root CBVs at the rounded address. **Not covered by any check today** - `tuxbox.py check` starts the Lanes, the fixtures and the D3D12 controls through `Host.run`, which sets neither the layer nor the setting. - The existing `root-cbv-window` control only uses offsets that are multiples of 256, so it passes either way. - The test in `tests/test_host.py` checks the variable, not a read. I have the 17-offset control as an `--offsets` mode for `root_cbv_guest.cpp`, plus a `root-cbv-offsets` case for `check_d3d12_regressions.py`, left out of the default set. Happy to open it as a PR. As a default case it would fail on NVIDIA under `tuxbox.py check` until checks run with the launcher's CBV setup, or until the offsets are handled in the provider as #251 proposes. That route doesn't depend on which descriptor model vkd3d picks, which these numbers make more attractive. Not measured yet: root CBVs in a graphics or mesh pipeline, and frame time with the setting on a retail scene.
Valdi320 commented 2026-11-26 20:37:16 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by Valdi320 on 2026-11-26T20:37:16Z.


@NickStallman thanks for the 17-offset control and measurements. Rather than duplicate your fixture or preempt the provider architecture discussion, I added explicit comparison modes to the existing isolated regression runner in https://github.com/brcly/TuxBox/pull/271: --cbv-mode stock / launcher. Same provider/guest/Proton fingerprints, sanitized relevant inherited settings, actual vkd3d info logs. Both root-cbv-window and tables pass in both modes on RTX 4080; stock uses descriptor_heap, launcher reports force_raw_va_cbv. These existing tests do not cover the bad 16-byte offsets. Your proposed offsets mode would fit this runner and could use both modes to compare the workaround with the eventual provider fix. No changes to the default checks or provider itself.

<!-- greyfinch-sync:brcly/TuxBox:comment:7202898792 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/251#issuecomment-7202898792). Originally posted by [Valdi320](https://github.com/Valdi320) on 2026-11-26T20:37:16Z. --- @NickStallman thanks for the 17-offset control and measurements. Rather than duplicate your fixture or preempt the provider architecture discussion, I added explicit comparison modes to the existing isolated regression runner in https://github.com/brcly/TuxBox/pull/271: --cbv-mode stock / launcher. Same provider/guest/Proton fingerprints, sanitized relevant inherited settings, actual vkd3d info logs. Both root-cbv-window and tables pass in both modes on RTX 4080; stock uses descriptor_heap, launcher reports force_raw_va_cbv. These existing tests do not cover the bad 16-byte offsets. Your proposed offsets mode would fit this runner and could use both modes to compare the workaround with the eventual provider fix. No changes to the default checks or provider itself.
akimfomin commented 2026-11-27 00:22:28 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by akimfomin on 2026-11-27T00:22:28Z.


Your 17-offset fixture supplies a useful aligned/misaligned control. For the proposed root-SRV route there is one additional acceptance check beyond offsets. Microsoft's resource-binding spec says a root descriptor carries a GPU virtual address but no view length. An exact-length table SRV and the root-SRV replacement therefore need separate evidence for their read boundary.

A synthetic control is to allocate physically padded data for both variants, put a sentinel just after the logical CBV window, and assert that it is not returned when the guest semantics say the read is out of range. Keep all host accesses within the allocation. If you add that case to the existing runner, PortBridge Test Lab can carry the same public fixture on a second backend and return the credited result here. AI-assisted specification comparison.

<!-- greyfinch-sync:brcly/TuxBox:comment:7206406775 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/251#issuecomment-7206406775). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-27T00:22:28Z. --- Your [17-offset fixture](https://github.com/brcly/TuxBox/pull/282) supplies a useful aligned/misaligned control. For the proposed root-SRV route there is one additional acceptance check beyond offsets. [Microsoft's resource-binding spec](https://microsoft.github.io/DirectX-Specs/d3d/ResourceBinding.html) says a root descriptor carries a GPU virtual address but no view length. An exact-length table SRV and the root-SRV replacement therefore need separate evidence for their read boundary. A synthetic control is to allocate physically padded data for both variants, put a sentinel just after the logical CBV window, and assert that it is not returned when the guest semantics say the read is out of range. Keep all host accesses within the allocation. If you add that case to the existing runner, [PortBridge Test Lab](https://akimfomin.github.io/PortBridge/#/lab) can carry the same public fixture on a second backend and return the credited result here. AI-assisted specification comparison.
brcly commented 2026-11-29 21:58:24 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T21:58:24Z.


Sorry this sat unanswered. Yes, this fits the direction: AGENTS.md asks us to choose paths by what the driver can do, and handling the 16-byte offsets inside TuxBox removes the dependency on a Vulkan layer and on vkd3d-proton's descriptor model. Today the launcher still relies on force_raw_va_cbv, and NVIDIA rounds root CBV offsets to 64 bytes even with the layer.

What I'd want before it replaces the layer:

  • the 17-offset control (#282) passing in both the aligned and misaligned cases, on NVIDIA and AMD;
  • @akimfomin's read-boundary check for the root-SRV replacement, since a root descriptor carries no length;
  • root-cbv-window and the table controls still passing, and one game run that reaches the world;
  • the layer kept until all of that passes, then removed in its own PR.

Please say on #533 if you start on it.

<!-- greyfinch-sync:brcly/TuxBox:comment:7263301086 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/251#issuecomment-7263301086). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T21:58:24Z. --- Sorry this sat unanswered. Yes, this fits the direction: AGENTS.md asks us to choose paths by what the driver can do, and handling the 16-byte offsets inside TuxBox removes the dependency on a Vulkan layer and on vkd3d-proton's descriptor model. Today the launcher still relies on `force_raw_va_cbv`, and NVIDIA rounds root CBV offsets to 64 bytes even with the layer. What I'd want before it replaces the layer: - the 17-offset control (#282) passing in both the aligned and misaligned cases, on NVIDIA and AMD; - @akimfomin's read-boundary check for the root-SRV replacement, since a root descriptor carries no length; - `root-cbv-window` and the table controls still passing, and one game run that reaches the world; - the layer kept until all of that passes, then removed in its own PR. Please say on #533 if you start on it.
NickStallman commented 2026-11-29 22:29:47 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T22:29:47Z.


I explored the smallest first step; no implementation started. Controls are in #552.

Viability. On an RTX 5090 (620.70.10, stock settings, VK_EXT_descriptor_heap enabled) raw table SRVs read right at 17 of 17 offsets (root SRVs too), where table and root CBVs read 5 of 17, and a table SRV returns zero past its end, so it can carry the guest's exact length. On the AMD iGPU everything is 17/17. Under the launcher's settings, root CBVs in vertex, mesh and pixel shaders read 17/17 on both; with stock settings they read 5/17 on the 5090.

Scope narrows for ProjectScarlett. Of 47,509 recorded requests, 45,783 carry a root signature and none has a root CBV; 44,695 have a CBV table range. So the appended-root-SRV half of the proposal isn't needed for this title on that evidence (.link requests not parsed; one title's recording).

Cost. A table-only change would alter about 85–91% of translated programs on hosts that round (2,500-request sample; that's a recompile for NVIDIA users) and none elsewhere. On 75 of them, replacing table cbuffers with ByteAddressBuffer in the HLSL text and compiling with DXC 1.9.2609 gave no crashes with or without -fnew-inlining-behavior, about 1% more DXIL and the same compile time. That's a text experiment, without the runtime's cs_6_6 flags, not checked on a GPU.

Open before asking to start on the translator: how preparation learns the capability (the provider can't be asked before launch; a first-run fallback is needed), desktop DXIL with table cbuffers (Lanes and fixtures keep the layer), and NVIDIA frame cost (a guess: similar, since the layer already makes them storage buffers).

<!-- greyfinch-sync:brcly/TuxBox:comment:7263717955 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/251#issuecomment-7263717955). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T22:29:47Z. --- I explored the smallest first step; **no implementation started.** Controls are in #552. **Viability.** On an RTX 5090 (620.70.10, stock settings, `VK_EXT_descriptor_heap enabled`) raw table SRVs read right at 17 of 17 offsets (root SRVs too), where table and root CBVs read 5 of 17, and a table SRV returns zero past its end, so it can carry the guest's exact length. On the AMD iGPU everything is 17/17. Under the launcher's settings, root CBVs in vertex, mesh and pixel shaders read 17/17 on both; with stock settings they read 5/17 on the 5090. **Scope narrows for ProjectScarlett.** Of 47,509 recorded requests, 45,783 carry a root signature and none has a root CBV; 44,695 have a CBV table range. So the appended-root-SRV half of the proposal isn't needed for this title on that evidence (`.link` requests not parsed; one title's recording). **Cost.** A table-only change would alter about 85–91% of translated programs on hosts that round (2,500-request sample; that's a recompile for NVIDIA users) and none elsewhere. On 75 of them, replacing table cbuffers with ByteAddressBuffer in the HLSL text and compiling with DXC 1.9.2609 gave no crashes with or without `-fnew-inlining-behavior`, about 1% more DXIL and the same compile time. That's a text experiment, without the runtime's cs_6_6 flags, not checked on a GPU. **Open before asking to start on the translator:** how preparation learns the capability (the provider can't be asked before launch; a first-run fallback is needed), desktop DXIL with table cbuffers (Lanes and fixtures keep the layer), and NVIDIA frame cost (a guess: similar, since the layer already makes them storage buffers).
Sign in to join this conversation.
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#251
No description provided.