tombox-xshader: offline fallback for shaders without RTS0 / memory-based root ABI — would this be welcome? #142

Open
opened 2026-11-26 06:11:35 +00:00 by github-bot · 5 comments
Owner

@⁠AntonioEspana on GitHub · 2026-11-22 15:17 UTC · original

Hi! I'd like to contribute to the shader translator and want to check the direction with you before writing code.

Current state (as I understand it, main @ c95a909)

  • When a shader has no RTS0 chunk, translation stops at the first resource access:
    • hlsl.rs:1861: "mubuf ... missing root signature for descriptor table"
    • hlsl.rs:2152: "s_buffer_load ... missing root signature"
  • xshader_prelaunch.rs:99 marks MS/AS without RTS0 as RuntimeOnly, waiting for the PSO root signature at runtime.
  • BLOCKERS.md lists related open items:
    • 8749 of the 8765 GTA VI mesh programs stop at the first resource load.
    • FORCE_MEMORY_BASED_ABI root arguments read through s[0:1] are not modelled.
    • Global-memory accesses through a 64-bit GPU VA are refused (global_bind::refusal; no GPU-VA-to-resource map yet).

Idea

A fallback translation mode for shaders whose root signature is unknown, or which use the memory-based root ABI:

  • User SGPRs come from a root-constant / small buffer filled at bind time, instead of a static register mapping.
  • V#/T#/S# descriptors loaded with s_load* / s_buffer_load* are resolved at runtime (bindless ResourceDescriptorHeap index or a GPU-VA window lookup, extending global_abi.rs), instead of statically per HLSL register.
  • The existing static path stays the default. The fallback is used only when the static mapping fails, or for FORCE_MEMORY_BASED_ABI root signatures.

This would let offline/prelaunch translation (and the shader-compile hitches noted in BLOCKERS) cover shaders that are RuntimeOnly today. It would also give the memory-based root ABI a translation path.

Prior art

ivall/xcl takes a similar approach: user SGPRs and memory as generic runtime buffers, which lets it translate its whole sample pack. Its draw-time binding is unfinished too. XCL is GPL-2.0-only, so I would not copy any code. I would only use it as a reference for the approach and record it as "reference only" in THIRD_PARTY/CREDITS, like xvdtool.

Constraints on my side

I don't own a console or any dumps, so I can only validate with synthetic shaders (the RDNA2 assembler in the tests) and WARP tests. Real-title verification would be on your side.

Questions

  1. Does this fit the design, or is waiting for the runtime root signature the intended approach, so a fallback isn't wanted?
  2. If it fits: should it live in hlsl/rootmem.rs / hlsl/global.rs, or in a new module?
  3. Is there a smaller first step you'd prefer? For example, only the FORCE_MEMORY_BASED_ABI root-argument path, or one of the other refusals listed in BLOCKERS (ds_swizzle outside PS, atomic MUBUF with SGPR SOFFSET).
**@⁠AntonioEspana** on GitHub · 2026-11-22 15:17 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/142) Hi! I'd like to contribute to the shader translator and want to check the direction with you before writing code. ### Current state (as I understand it, main @ c95a909) - When a shader has no RTS0 chunk, translation stops at the first resource access: - `hlsl.rs:1861`: "mubuf ... missing root signature for descriptor table" - `hlsl.rs:2152`: "s_buffer_load ... missing root signature" - `xshader_prelaunch.rs:99` marks MS/AS without RTS0 as `RuntimeOnly`, waiting for the PSO root signature at runtime. - BLOCKERS.md lists related open items: - 8749 of the 8765 GTA VI mesh programs stop at the first resource load. - `FORCE_MEMORY_BASED_ABI` root arguments read through `s[0:1]` are not modelled. - Global-memory accesses through a 64-bit GPU VA are refused (`global_bind::refusal`; no GPU-VA-to-resource map yet). ### Idea A fallback translation mode for shaders whose root signature is unknown, or which use the memory-based root ABI: - User SGPRs come from a root-constant / small buffer filled at bind time, instead of a static register mapping. - V#/T#/S# descriptors loaded with `s_load*` / `s_buffer_load*` are resolved at runtime (bindless `ResourceDescriptorHeap` index or a GPU-VA window lookup, extending `global_abi.rs`), instead of statically per HLSL register. - The existing static path stays the default. The fallback is used only when the static mapping fails, or for `FORCE_MEMORY_BASED_ABI` root signatures. This would let offline/prelaunch translation (and the shader-compile hitches noted in BLOCKERS) cover shaders that are `RuntimeOnly` today. It would also give the memory-based root ABI a translation path. ### Prior art ivall/xcl takes a similar approach: user SGPRs and memory as generic runtime buffers, which lets it translate its whole sample pack. Its draw-time binding is unfinished too. XCL is GPL-2.0-only, so I would **not** copy any code. I would only use it as a reference for the approach and record it as "reference only" in THIRD_PARTY/CREDITS, like xvdtool. ### Constraints on my side I don't own a console or any dumps, so I can only validate with synthetic shaders (the RDNA2 assembler in the tests) and WARP tests. Real-title verification would be on your side. ### Questions 1. Does this fit the design, or is waiting for the runtime root signature the intended approach, so a fallback isn't wanted? 2. If it fits: should it live in `hlsl/rootmem.rs` / `hlsl/global.rs`, or in a new module? 3. Is there a smaller first step you'd prefer? For example, only the `FORCE_MEMORY_BASED_ABI` root-argument path, or one of the other refusals listed in BLOCKERS (`ds_swizzle` outside PS, atomic MUBUF with SGPR SOFFSET).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:11:35 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 15:19 UTC · original

Thanks for asking before writing code, and for keeping XCL as a reference only. I've passed this to the shader-translator owner and will follow up here with an answer on the direction, the module location and a good first step.

**@⁠omonkeyz** on GitHub · 2026-11-22 15:19 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/142#issuecomment-7081216879) Thanks for asking before writing code, and for keeping XCL as a reference only. I've passed this to the shader-translator owner and will follow up here with an answer on the direction, the module location and a good first step.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 15:22 UTC · original

Answer from the shader-translator owner:

This fits as long as it's an opt-in fallback. The static RTS0 path stays the default, and the fallback is selected only when a shader has no RTS0 or uses the memory root ABI.

  • Where: a new module, hlsl/rootmem.rs. Keep global_abi.rs for the shared GPU-VA window and heap-index plumbing, and don't grow global.rs.
  • First step: user SGPRs only, fed from a bind-time root constant buffer (one CBV per stage, filled at draw time by d3d12_xs). No runtime descriptor resolution yet. Add a synthetic test that runs on WARP and shows that a shader reading s[N] from that buffer gets the same values as the static path.
  • Second step: descriptor resolution through the existing bindless heap index, with a bounds-checked fetch. When an index can't be proven in range, the fetch should refuse with an error at translate time, not return a silent zero.
  • Licence: you're right that xcl/ivall are GPL-2.0-only, so they stay reference-only. No copied code, and no credit line is needed for ideas.

Looking forward to the PR!

**@⁠omonkeyz** on GitHub · 2026-11-22 15:22 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/142#issuecomment-7081259594) Answer from the shader-translator owner: This fits as long as it's an **opt-in fallback**. The static RTS0 path stays the default, and the fallback is selected only when a shader has no RTS0 or uses the memory root ABI. - **Where:** a new module, `hlsl/rootmem.rs`. Keep `global_abi.rs` for the shared GPU-VA window and heap-index plumbing, and don't grow `global.rs`. - **First step:** user SGPRs only, fed from a bind-time root constant buffer (one CBV per stage, filled at draw time by d3d12_xs). No runtime descriptor resolution yet. Add a synthetic test that runs on WARP and shows that a shader reading `s[N]` from that buffer gets the same values as the static path. - **Second step:** descriptor resolution through the existing bindless heap index, with a bounds-checked fetch. When an index can't be proven in range, the fetch should refuse with an error at translate time, not return a silent zero. - **Licence:** you're right that xcl/ivall are GPL-2.0-only, so they stay reference-only. No copied code, and no credit line is needed for ideas. Looking forward to the PR!
Author
Owner

@⁠enderrr9 on GitHub · 2026-11-23 18:05 UTC · original

I'd like to take step 2 for the memory-based root ABI, unless @⁠AntonioEspana is already on it.

Context: #313, #315 and #316 cover amplification shaders on the rootmem.rs path:

  • synthetic AS + MS pairs rendering on WARP;
  • the args-entry Z fix;
  • amplification shaders always using the memory-root path.

The next gap there is that rm_param gives up at the first Table root parameter, so any root signature with a descriptor table refuses everything after it.

Two questions before I write code:

  1. In root memory (FORCE_MEMORY_BASED_ABI, read through s[0:1]), what does a descriptor-table parameter occupy on the console? Is it one dword (a heap index or offset) or two (a GPU VA of the first descriptor)? And is its slot size the same as for a root descriptor? If it's in your xgs12_10d notes, the layout alone is enough.
  2. Should the bounds check use the heap size bound at draw time (the same index plumbing global_abi.rs uses)? And should anything not provable from the root signature's ranges be refused at translate time?

I'd keep it opt-in as you described, with synthetic WARP tests like the rootmem compute tests.

**@⁠enderrr9** on GitHub · 2026-11-23 18:05 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/142#issuecomment-7109647539) I'd like to take **step 2** for the memory-based root ABI, unless @⁠AntonioEspana is already on it. Context: #313, #315 and #316 cover amplification shaders on the `rootmem.rs` path: - synthetic AS + MS pairs rendering on WARP; - the args-entry Z fix; - amplification shaders always using the memory-root path. The next gap there is that `rm_param` gives up at the first `Table` root parameter, so any root signature with a descriptor table refuses everything after it. Two questions before I write code: 1. In root memory (`FORCE_MEMORY_BASED_ABI`, read through `s[0:1]`), what does a descriptor-table parameter occupy on the console? Is it one dword (a heap index or offset) or two (a GPU VA of the first descriptor)? And is its slot size the same as for a root descriptor? If it's in your xgs12_10d notes, the layout alone is enough. 2. Should the bounds check use the heap size bound at draw time (the same index plumbing `global_abi.rs` uses)? And should anything not provable from the root signature's ranges be refused at translate time? I'd keep it opt-in as you described, with synthetic WARP tests like the rootmem compute tests.
Author
Owner

@⁠AntonioEspana on GitHub · 2026-11-23 18:38 UTC · original

Not on it. Go ahead.

Those two questions are for omonkey: I don't have the console notes and can't answer the layout. One thing in case it helps: user_data_abi::pack in my PR counts a table as one dword and a root descriptor as two. That mirrors the static user-SGPR mapping (root_param_at), not anything verified for root memory, so please don't take it as evidence for the root-memory layout.

**@⁠AntonioEspana** on GitHub · 2026-11-23 18:38 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/142#issuecomment-7110456526) Not on it. Go ahead. Those two questions are for omonkey: I don't have the console notes and can't answer the layout. One thing in case it helps: `user_data_abi::pack` in my PR counts a table as one dword and a root descriptor as two. That mirrors the static user-SGPR mapping (`root_param_at`), not anything verified for root memory, so please don't take it as evidence for the root-memory layout.
Author
Owner

@⁠nineforge0 on GitHub · 2026-11-24 08:12 UTC · original · edited 2026-11-24 23:13 UTC

Regarding the open question about descriptor-table parameter sizes in console root memory:

We parsed the FSSM root layouts of all 9,282 mesh shader programs and 2,647 compute shaders from the retail shader database (shaders.rpf entry 0). The data confirms:

  • Descriptor-table parameters take 1 SGPR (1 dword) in root memory.
  • Root descriptors (CBV/SRV/UAV) take 2 SGPRs (2 dwords) — a 64-bit GPU virtual address.
  • Root constants take 1 SGPR per dword (95% use 2dw, 5% use 1dw).
  • ResourceHeap and SamplerHeap take 1 SGPR each.

This matches the assumption in user_data_abi::pack (table = 1 dword, root descriptor = 2).

All mesh shaders start their root parameters at s8 (graphics) or s4 (compute). The layout is highly uniform: a single rootmem implementation handling 7 parameter types (Table, Descriptor, Constants, ResourceHeap, SamplerHeap, plus the two shadow variants) covers 100% of mesh shaders.

Full analysis and reproduction instructions: https://github.com/nineforge0/forge9/blob/main/docs/mesh_shader_binding_model.md

Tool: forge9 fssm shaders.rpf 0 --roots (from forge9).

Edit: the source is the title's shader database (shaders.rpf entry 0), not the pipeline cache (entry 1). The numbers are unchanged.

**@⁠nineforge0** on GitHub · 2026-11-24 08:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/142#issuecomment-7125863017) · edited 2026-11-24 23:13 UTC Regarding the open question about descriptor-table parameter sizes in console root memory: We parsed the FSSM root layouts of all 9,282 mesh shader programs and 2,647 compute shaders from the retail shader database (`shaders.rpf` entry 0). The data confirms: - **Descriptor-table parameters take 1 SGPR (1 dword)** in root memory. - **Root descriptors (CBV/SRV/UAV) take 2 SGPRs (2 dwords)** — a 64-bit GPU virtual address. - **Root constants take 1 SGPR per dword** (95% use 2dw, 5% use 1dw). - **ResourceHeap and SamplerHeap take 1 SGPR each.** This matches the assumption in `user_data_abi::pack` (table = 1 dword, root descriptor = 2). All mesh shaders start their root parameters at s8 (graphics) or s4 (compute). The layout is highly uniform: a single rootmem implementation handling 7 parameter types (Table, Descriptor, Constants, ResourceHeap, SamplerHeap, plus the two shadow variants) covers 100% of mesh shaders. Full analysis and reproduction instructions: https://github.com/nineforge0/forge9/blob/main/docs/mesh_shader_binding_model.md Tool: `forge9 fssm shaders.rpf 0 --roots` (from [forge9](https://github.com/nineforge0/forge9)). _Edit: the source is the title's shader database (`shaders.rpf` entry 0), not the pipeline cache (entry 1). The numbers are unchanged._
This discussion has been locked. Commenting is limited to contributors.
No description provided.