xshader: load the vertex and instance index into v0 and v3 of a vertex shader #125
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!125
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/125/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 mergingLibrary / 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
v0and the instance index fromv3, below the fetched attributes that start atv4. The translation declaresSV_VertexID/SV_InstanceIDas 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,
v0is loaded from theSV_VertexIDinput andv3from theSV_InstanceIDinput, 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 inhlsl.rs, one synthetic test.Evidence
Lobby backdrop, VS
afc1be9297ca088a. Its texcoord index is(v0 + cb1[0].w) * cb1[0].ywithv0never 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. Withv0loaded, the backdrop draws.Registers, over the 150 vertex shaders dumped from one lobby session:
v0at entrySV_VertexIDmarked readSV_VertexIDpresent, marked unreadSV_VertexIDAll 19 shaders whose signature marks
SV_InstanceIDas read usev3as an index before writing it (for examplestb4[s6 + v3]).v3is weaker evidence thanv0: the entry-live list also namesv3for 66 shaders withoutSV_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, shadersfail=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 syntheticon this branch (ond59ed23): 12 passed. The new testvertex_shader_receives_vertex_and_instance_index_in_v0_and_v3fails onmainwithout the change.cargo test -p tombox-xshader --no-fail-fast,mainat99f48e3against 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.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 currentmain.Not covered
Base vertex: it was 0 in every draw of the captured frames, so whether
v0includes 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
missingwith a noteAI-assisted (Claude Code).
🤖 Generated with Claude Code
@omonkeyz on GitHub · 2026-11-22 14:28 UTC · original
Applied in
208d630(merged inc8a8a8f) with your authorship kept, thanks!Pull request closed