Recompiler: a VS's layer and viewport index reach the rasteriser #1340
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1350"
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 ivall/xcl. Originally posted by emirduran707 on 2026-11-24T15:08:29Z.
A vertex shader's
SV_RenderTargetArrayIndexandSV_ViewportArrayIndexwere dropped:export_graphicsignores the VS's position exports 13–15.SV_Position, the params and clip/cull distances.On RDNA the compiler writes these two through the "misc vector" export (
exp pos1): the layer in bits [10:0] of its z, the viewport index in bits [19:16]. Mesa'sac_nir_export_position(src/amd/common/nir/ac_nir_prerast_utils.c) hasvec[2] = out->outputs[VARYING_SLOT_LAYER][0]and the comment "GFX9 has the layer in [10:0] and the viewport index in [19:16]". The misc vector is exported only when one of those (or point size / edge flag / shading rate) is written. So every primitive of an instanced cubemap or shadow-cascade pass went to slice 0 and viewport 0.When the VS's output signature has system value 4 (
SV_RenderTargetArrayIndex) or 5 (SV_ViewportArrayIndex), target 13 is now read as the misc vector:xcl_layer = z & 0x7FFandxcl_viewport = (z >> 16) & 0xF, declared after the params so the params keep their places. The rect-list GS, which uses the same struct, passes them on. A VS without these outputs gets exactly the HLSL it got before.What is in it
crates/xcl/src/gpu/recomp/emit.rs: the misc-vector arm and the two struct members.crates/xcl/src/gpu/recomp/tests.rs:vs_layer_and_viewport_index_from_the_misc_vector: layer, viewport, and both, compiled through DXC with the rect-list GS;vs_pos1_without_layer_or_viewport_index_writes_nothing: a VS with clip distances exporting pos1 writes only what it did before.Tested
cargo test --workspace -- --test-threads=4on216c317: 753 passed, 0 failed, 41 ignored; no SKIPPED GPU testsemit.rsfails (noSV_RenderTargetArrayIndex, no assignment from v5); with it both passRegression run
main:
this PR:
Not tested
VPAndRTArrayIndexFromAnyShaderFeedingRasterizerSupportedWithoutGSEmulation; NVIDIA and Intel GPUs.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:14:59Z.
Full-suite run, since this PR has no test report yet. Tested exact head
216c317(on its base930e8b4).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.vs_layer_and_viewport_index_from_the_misc_vector,vs_pos1_without_layer_or_viewport_index_writes_nothing.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T16:17:58Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (One run showed a single flaky failure / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-25T09:01:11Z.
Independent native Windows check on 216c317, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, DXC 1.8.2502.11.
The clean
cargo build --workspace --offline --locked -j 4passed.cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4finished with 753 passed, 0 failed, 41 ignored. Cargo's pass count includes two runtime skips for unavailable native wave64. Both stock VS misc-vector tests passed.A separate scratch fixture used the PR's unmodified translator to draw into a two-slice 16×16 float render target with two viewports. It checked all 512 texels per draw. Slice/viewport pairs (1,0), (0,1), and (1,1) each colored exactly the intended 128 texels, leaving 384 clear. Disabling the misc-vector z export sent the same packed (1,1) input to (0,0), as expected. The adapter reported native VS array/viewport index support. With
XCL_LOCAL_ARRAY_PROBE=1,cargo test --offline --locked -j 4 -p xcl --lib local_vs_pos1_routes_array_slice_and_viewport -- --nocapture --test-threads=1passed, zero skips.Synthetic direct VS rasterization only. This run did not draw through the rect-list GS or run a retail title. AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture, ran both checks and drafted this report.
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T14:57:06Z.
merge-check claim
head:
216c3171edImported from ivall/xcl. Originally posted by throny on 2026-11-28T15:17:10Z.
merge-check
base:
309c3ec5head:
216c3171edmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2144 passed, 0 failed, 48 ignored (26 SKIPPED lines). Base alone at
309c3ec5: 2142 passed, 0 failed, 48 ignored.review: no blocking finding; all hunks read. The PR's base is old (the file moved by about 600 lines since) but the merge is clean and everything it uses exists on main. The changed output struct is used by vertex shaders and the rect-list geometry shader only, so nothing new reaches a mesh shader. Not covered: the mesh path still drops this export, nobody checked a pixel shader that reads the two values as inputs, and the packing of layer and viewport index is taken from the PR's citation, not verified by me.
performance: none expected at run time. It changes a translator source: every tester re-translates all shaders once.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T01:58:40Z.
merge-check claim
head:
216c3171edImported from ivall/xcl. Originally posted by relativespace2K on 2026-11-30T02:01:27Z.
merge-check
base:
53e85fb1head:
216c3171edmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2790 passed, 6 failed, 49 ignored; failing: gpu::dxil::compact_tests::gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form, gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk, hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, ram_budget::tests::windows_takes_a_working_set_maximum_and_lifts_it, and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (in
--test gpu_two_pass_cache_e2e, so 5 failing tests give 6 failures). The same five fail on base53e85fb1alone (2788 passed, 6 failed, 49 ignored there), so none comes from this PR; its two new tests passed, and both compile their HLSL with DXC on this machine, so the VS and the rect-list GS were really built.review: no blocking finding; three files, every hunk read. The new
exp pos1arm sits before the13..=15 => {}catch-all and only fires when the VS declares a layer or viewport index, so a program that uses pos1 for clip/cull distances keeps the old path; it reads component z (EN bit 2) and splits it as z[10:0] for the layer and z[19:16] for the viewport index, which is what the cited Mesaac_nir_export_positiondoes. The two fields are appended to the output struct after the params, so everyp{k}keeps its place and no offset moves, andrect_list_gscopies whole structs (XClOut k = v[c],s.Append(v[0])), so the GS carries both fields on without assigning them by hand. The negative test pins that without a layer or viewport index nothing is read from pos1 whatever its EN bits. No duplicate: nothing else open or merged carries layer/viewport index from the misc vector.performance: two extra comparisons per translated VS and a couple of output registers; nothing per frame or per draw at run time.
verdict: safe to merge
hardware / tool and model: AMD Radeon RX 6800 XT 16 GB (RDNA2, wave64), driver 32.0.21045.29003; Ryzen 5 5600, 32 GB RAM; Windows 10 IoT Enterprise LTSC 2024, 10.0.26100 build 26100.9974; Rust 1.100.0; DXC 1.9.2602.17; debug build. DeepSeek Harness coding agent, model DeepSeek V4.1 Flash.
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T02:06:09Z.
@relativespace2K Please make sure you're checking if a claim has already been made on the PR (I made it 3 minutes before) as I'm already in the middle of running mine.