xshader: load the vertex and instance index into v0 and v3 of a vertex shader #125

Closed
github-bot wants to merge 1 commit from gh-pr/125/head into gh-pr/125/base
Owner

@⁠bosseurdinternet on GitHub · 2026-11-22 13:39 UTC · original
bosseurdinternet:xshader/vs-vertex-instance-index → main · +40 −0 · 2 files · 1 commits · closed without merging

Library / area: tombox-xshader (RDNA2 to HLSL), vertex shader entry registers.

Exports changed (exports.txt rows): none.

Source of the behaviour: shaders of my own Fortnite 14.50 Series dump, read as translated HLSL and checked against a frame capture. No game data is included.

The defect

A Series vertex shader reads the vertex index from v0 and the instance index from v3, below the fetched attributes that start at v4. The translation declares SV_VertexID / SV_InstanceID as inputs but never loads them, so both registers stay 0. A shader that fetches its own attributes by index (Unreal's manual vertex fetch: texcoords, tangents and colours from buffers at the vertex index, per-instance data at the instance index) then reads element 0 for every vertex. On screen: one flat value per object, or black.

The change

In the vertex entry prologue, v0 is loaded from the SV_VertexID input and v3 from the SV_InstanceID input, each only when the signature has the system value and the code reads the register at entry. Left unchanged: vertex shaders that store their outputs to LDS for a geometry shader (their entry layout was not checked) and Durango shaders. 17 lines in hlsl.rs, one synthetic test.

Evidence

  • Lobby backdrop, VS afc1be9297ca088a. Its texcoord index is (v0 + cb1[0].w) * cb1[0].y with v0 never assigned. Decoding the mesh's texcoord buffer from a frame record, vertex 0 has a UV for which the pixel shader's edge fade is 0; the output then falls back to a texture that reads zero, so the whole backdrop drew black. With v0 loaded, the backdrop draws.

  • Registers, over the 150 vertex shaders dumped from one lobby session:

    Signature Shaders Read v0 at entry
    SV_VertexID marked read 51 51
    SV_VertexID present, marked unread 16 0
    no SV_VertexID 83 0

    All 19 shaders whose signature marks SV_InstanceID as read use v3 as an index before writing it (for example stb4[s6 + v3]). v3 is weaker evidence than v0: the entry-live list also names v3 for 66 shaders without SV_InstanceID, where the first use is a masked write (v3 = TB_WV(x, v3)), so I relied on the first use rather than on the list.

  • In game (lobby, PLAY and BATTLE PASS tabs): before, black backdrop, black floor pads, flat grey deck, blank screens and flat surfaces in the room; after, all of them textured. The draws are about the same (331 and 329 on one tab, 373 and 378 on the other; base pass 14 and 66 both times): the fix changes how draws come out, not which are made. pso_fail=0, shaders fail=0.

This may be the cause of #113: the "one flat value per environment object" symptom is what a constant texcoord gives, and the room became textured with no change to texture uploads. I did not test #113's own scene.

Verification

  • cargo test -p tombox-xshader --test synthetic on this branch (on d59ed23): 12 passed. The new test vertex_shader_receives_vertex_and_instance_index_in_v0_and_v3 fails on main without the change.
  • cargo test -p tombox-xshader --no-fail-fast, main at 99f48e3 against the same tree with this change: identical result lists except the new test (131 passed against 130; 83 failed and 15 ignored on both sides). The 83 failures are the tests that need a D3D12 device, which my environment does not have (Wine without a D3D12 adapter in a sandbox: CreateDXGIFactory1). So the WARP and hardware exec tests were not run; CI is the first run of those.
  • .github/scripts/pr_gate.py --base origin/main: 2 files checked, 0 problems.
  • The in-game result above was obtained on the tree before the history rewrite (4cb7a54) with the same change minus the Durango condition, under Wine 11 with vkd3d-proton on an RX 7800 XT. Not tested on Windows, and not tested in game on current main.

Not covered

  • Base vertex: it was 0 in every draw of the captured frames, so whether v0 includes it is untested.

  • Vertex shaders feeding a geometry shader, hull/domain, and Durango are untouched.

  • A changed HLSL means these shaders miss the disk cache once.

  • cargo test -p <crate> passes (the tests my environment can run; see above)

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠bosseurdinternet** on GitHub · 2026-11-22 13:39 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/125) `bosseurdinternet:xshader/vs-vertex-instance-index` → `main` · +40 −0 · 2 files · 1 commits · closed without merging **Library / area:** `tombox-xshader` (RDNA2 to HLSL), vertex shader entry registers. **Exports changed (exports.txt rows):** none. **Source of the behaviour:** shaders of my own Fortnite 14.50 Series dump, read as translated HLSL and checked against a frame capture. No game data is included. ## The defect A Series vertex shader reads the vertex index from `v0` and the instance index from `v3`, below the fetched attributes that start at `v4`. The translation declares `SV_VertexID` / `SV_InstanceID` as inputs but never loads them, so both registers stay 0. A shader that fetches its own attributes by index (Unreal's manual vertex fetch: texcoords, tangents and colours from buffers at the vertex index, per-instance data at the instance index) then reads element 0 for every vertex. On screen: one flat value per object, or black. ## The change In the vertex entry prologue, `v0` is loaded from the `SV_VertexID` input and `v3` from the `SV_InstanceID` input, each only when the signature has the system value and the code reads the register at entry. Left unchanged: vertex shaders that store their outputs to LDS for a geometry shader (their entry layout was not checked) and Durango shaders. 17 lines in `hlsl.rs`, one synthetic test. ## Evidence - **Lobby backdrop, VS `afc1be9297ca088a`.** Its texcoord index is `(v0 + cb1[0].w) * cb1[0].y` with `v0` never assigned. Decoding the mesh's texcoord buffer from a frame record, vertex 0 has a UV for which the pixel shader's edge fade is 0; the output then falls back to a texture that reads zero, so the whole backdrop drew black. With `v0` loaded, the backdrop draws. - **Registers, over the 150 vertex shaders dumped from one lobby session:** | Signature | Shaders | Read `v0` at entry | |---|---|---| | `SV_VertexID` marked read | 51 | 51 | | `SV_VertexID` present, marked unread | 16 | 0 | | no `SV_VertexID` | 83 | 0 | All 19 shaders whose signature marks `SV_InstanceID` as read use `v3` as an index before writing it (for example `stb4[s6 + v3]`). `v3` is weaker evidence than `v0`: the entry-live list also names `v3` for 66 shaders without `SV_InstanceID`, where the first use is a masked write (`v3 = TB_WV(x, v3)`), so I relied on the first use rather than on the list. - **In game** (lobby, PLAY and BATTLE PASS tabs): before, black backdrop, black floor pads, flat grey deck, blank screens and flat surfaces in the room; after, all of them textured. The draws are about the same (331 and 329 on one tab, 373 and 378 on the other; base pass 14 and 66 both times): the fix changes how draws come out, not which are made. `pso_fail=0`, shaders `fail=0`. This may be the cause of #113: the "one flat value per environment object" symptom is what a constant texcoord gives, and the room became textured with no change to texture uploads. I did not test #113's own scene. ## Verification - `cargo test -p tombox-xshader --test synthetic` on this branch (on `d59ed23`): 12 passed. The new test `vertex_shader_receives_vertex_and_instance_index_in_v0_and_v3` fails on `main` without the change. - `cargo test -p tombox-xshader --no-fail-fast`, `main` at `99f48e3` against the same tree with this change: identical result lists except the new test (131 passed against 130; 83 failed and 15 ignored on both sides). The 83 failures are the tests that need a D3D12 device, which my environment does not have (Wine without a D3D12 adapter in a sandbox: `CreateDXGIFactory1`). So the WARP and hardware exec tests were **not run**; CI is the first run of those. - `.github/scripts/pr_gate.py --base origin/main`: 2 files checked, 0 problems. - The in-game result above was obtained on the tree before the history rewrite (`4cb7a54`) with the same change minus the Durango condition, under Wine 11 with vkd3d-proton on an RX 7800 XT. Not tested on Windows, and not tested in game on current `main`. ## Not covered - Base vertex: it was 0 in every draw of the captured frames, so whether `v0` includes it is untested. - Vertex shaders feeding a geometry shader, hull/domain, and Durango are untouched. - A changed HLSL means these shaders miss the disk cache once. - [x] `cargo test -p <crate>` passes (the tests my environment can run; see above) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note _AI-assisted (Claude Code)._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A hardware vertex shader receives the vertex index in v0 and the instance
index in v3, below the fetched attributes that start at v4. The translation
declared SV_VertexID and SV_InstanceID as inputs but never loaded them, so
both registers stayed 0: a shader that fetches its own attributes by index
read element 0 for every vertex.

The registers are loaded only when the input signature has the system value
and the code reads the register at entry. Vertex shaders that store their
outputs to LDS for a geometry shader, and Durango shaders, are left as they
were.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_0191hZBwKXEiy34p5uomJYmt
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:10:53 +00:00
github-bot closed this pull request 2026-11-26 06:10:53 +00:00
Author
Owner

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

Applied in 208d630 (merged in c8a8a8f) with your authorship kept, thanks!

**@⁠omonkeyz** on GitHub · 2026-11-22 14:28 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/125#issuecomment-7080566754) Applied in 208d630 (merged in c8a8a8f) with your authorship kept, thanks!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.