tombox-xshader: seed merged_wave_info, vertex and instance index for merged vertex shaders #278
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/278"
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?
Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T10:56:18Z.
Library / area:
tombox-xshader(hlsl.rsvertex-shader entry setup,tests/exec.rs)Exports changed (exports.txt rows): none
Source of the behaviour: RDNA2 ISA and console shader disassembly. Most vertex shaders of an RDNA2 Series title are compiled as the ES half of a merged ES/GS program. They start with
and take their inputs in the merged layout: the vertex index in
v5, the instance index inv8, and the fetched attributes fromv9on. In The Matrix Awakens (Xbox Series X build), a sample merged VS reads exactlyv5,v8,v9..v11(ATTRIBUTE0.xyz) andv13(ATTRIBUTE13.x) before writing them. That matches this layout: five GS VGPRs, then ESv5vertex id,v6/v7,v8instance id, then attribute groups of four.The translation never set
s3, soexecbecame 0 at the second instruction and every output write of these shaders was skipped. It also loaded the vertex and instance index intov0/v3(or, for vertex shaders that hand their outputs to a geometry shader through LDS, not at all), and the attributes intov4onwards.Changes:
s3withs_bfe_u32/s_bfe_i32, and which readss3before writing it, is treated as a merged ES:s3starts as0x40(a full wave, soexeccovers the vertex);SV_VertexIDgoes tov5andSV_InstanceIDtov8;v9instead ofv4.s3(0x100), and #200 uses the sames3/v5convention for mesh shaders; this PR does not touch either.Effect on The Matrix Awakens' shader archive (35382 translated shaders, HLSL compared with
main):main.v32that nothing initialises: 4263 before, 1475 after. 929 of the remaining ones read onlyv0, as the LDS address operand of their output writes, which the translation ignores.vs_6_0.Tests (
tests/exec.rs):merged_vertex_shader_prologue_keeps_the_vertex_active: the input-layout draw ofvertex_fetch_reads_sparse_attributes_from_a_vertex_bufferwith the merged prologue in front and the attributes read fromv9. Onmainnothing is drawn (the render target keeps its clear value); now the expected pixel is written (WARP).merged_vertex_shader_reads_vertex_and_instance_index_from_v5_and_v8:s3,v5,v8andv9are seeded,v0/v3are not, and DXC compiles the result.mainde1e1da:cargo test -p tombox-xshader --no-fail-fast346 passed, 0 failed (WARP);cargo test -p d3d12_xs --lib -- --test-threads=1(withTOMBOX_REMOVED_EXIT_MS=off) 659 passed, 4 failed, 71 ignored. The same 4 fail onmainhere (alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement,placed_offset::tests::uneven_views_get_exact_helpers_and_msaa_shares_the_alias_heap,title_shadow::tests::buffer_then_texture_migrates_to_one_local_heap_and_keeps_bytes,xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs).Not verified in a title: no title run with this change yet. The Matrix runs so far stop before the city geometry draws. The
v6/v7inputs of the merged layout are not seeded: no shader in the archive was seen reading them before writing them.cargo test -p tombox-xshaderpassesmissingwith a noteImported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T13:20:10Z.
Review: the merged-ES register layout is right (v5 vertex id, v8 instance id, attributes from v9). One change needed: s3 = 0x40 only works for wave64. In a wave32 program s_bfm_b32 uses width 64 & 31 = 0, so exec is 0 again. Please seed 0x20 for wave32 and 0x40 for wave64, and add a wave32 case to the test.
Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T13:54:50Z.
Thanks, agreed. Pushed
5b93ec3(rebased onto current main, so the first commit is nowcdd791e).mesh::wave_sizeover its instructions, stored aswave64on the emitter), so no new detection was added.merged_vertex_shader_seeds_wave_info_for_the_program_wave_sizebuilds the merged prologue twice: a wave32 form (s_bfm_b32,s_cmp_eq_u32 .., 32,s_cselect_b32 exec_lo) and a wave64 form (s_bfm_b64, compare with 64,s_cselect_b64). It checks that the wave32 shader getss3 = 0x20u;(and never 0x40) and the wave64 one getss3 = 0x40u;, that both compile with dxc, and that the vertex and instance id still come from v5 and v8. The check is on the generated HLSL, not on executed lanes: I did not run a wave32 draw on a GPU.cargo test --locked -p tombox-xshader(native Windows 11, GPU-gated suites off): 348 passed, 0 failed, 18 ignored. The PR gate reports 0 problems.Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T14:27:59Z.
Applied locally on main with your authorship kept (cherry-picked,
343c15a); the tombox-xshader suite passes in a sandbox (exec 158/158 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:07:33Z.
Applied on main in
343c15a(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.Pull request closed