Skip to content

Shaders: lower the pixel ordered section (POPS) as rasterizer-ordered UAVs - #215

Closed
arminkhaleghirod wants to merge 1 commit into
fxceless:mainfrom
arminkhaleghirod:shader/hardware-sgpr-input
Closed

arminkhaleghirod wants to merge 1 commit into
fxceless:mainfrom
arminkhaleghirod:shader/hardware-sgpr-input

Conversation

@arminkhaleghirod

Copy link
Copy Markdown

Fixes the 10 emit: a hardware SGPR input failures.

All 10 are one pixel-program shape that uses the console's primitive-ordered pixel shading (POPS). It reads s18, the entry word above the user data, sets the packer register (s_setreg to HW_REG_POPS_PACKER), spins until src_pops_exiting_wave_id passes the earlier wave, then does an ordered read-modify-write on UAV images.

The host equivalent is a rasterizer-ordered view. So for a pixel program that enters POPS:

  • s18 and the exiting-wave id lower to 0, which is the first-wave path: no earlier wave, so the wait is skipped.
  • The packer s_setreg is a no-op.
  • Every UAV handle the program opens is marked ROV, and the ROV shader flag and feature bit are set (dropped if no ROV handle survives optimisation).
  • Shortcut: all UAVs of the program are ROV, not only the ones the ordered section touches.

Full-title translate --validate, RTX 4080:

  • On main: a hardware SGPR input 10 → 0. The 10 land in the blanket PSV mismatch, and no other count changes.
  • On main + Shaders: write every PSV0 semantic name again, as DXC does (fixes #12) #61, where the validator really checks them: all 10 validate. Validated programs 14,057 → 14,067, failures 548 → 538, no new reason.
  • --pipelines created a host pipeline for one of them.

Not checked in the game yet (I don't know where these programs draw). cargo test -p victory-shader --lib: same as main (the two rectangle tests that fail on main still fail). Clippy is clean.

@JRamos1993

Copy link
Copy Markdown

Offline check on the retail shader pack: merged onto current main 310c6eb, this PR fixes all 10 POPS pixel programs (the "a hardware SGPR input" ones) and loses none. 59 compute programs' DXIL changes, and all of them still validate.

Setup: RTX 5090, Windows 11. victory translate --validate --list over the title's full shader pack (26,084 programs), with a local DXIL hash on each validated line.

main 310c6eb + this PR
validated 25,382 25,392
newly validated 10: exactly the 10 programs that stop with "a hardware SGPR input" on main (the collision-wave SGPR of the ordered section)
lost 0
DXIL changed among programs validating on both 59, all compute

AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.

@JRamos1993

Copy link
Copy Markdown

Follow-up on the 59 compute programs whose DXIL changes. The module is the same; only its encoding differs. I checked 5 of the 59:

  • dxc -dumpbin gives the same text for main's DXIL and this PR's: IR, metadata and the header comments.
  • This PR's containers are 4–8 bytes larger.

So the bytes differ in the bitcode encoding, probably from the bitcode/opt.rs part, not in the program. Nothing for this title's compute shaders changes in behaviour.

AI use: Claude Code with Claude Opus 5.5 compared the dumps and wrote this.

@MKmajster

Copy link
Copy Markdown

Tested on a combined tree, offline: the pixel programs that stopped with "a hardware SGPR input" all translate with this PR.

Tree. skornuta/victory-fork main (this repo's 310c6eb plus ZSlayerHQ next), with the LooperSalty/victory lot, #188, #258, #806 and #739 of this repo, then this PR (776ec56).

Offline, victory translate --list over the title's shader pack (26,084 programs; counts are refusals at emission). "Before" is the tree without #806, #739 and this PR; "after" has all three:

Reason Before After
a hardware SGPR input 10 0

cargo test -p victory-shader --lib: 238 passed, 0 failed, 3 ignored (235 on the tree before the three PRs).

One conflict, easy: on that tree, #258 adds an Operand::Const(253) arm (src_scc read as an operand) in the same match where this PR adds Operand::Const(POPS_EXITING_WAVE_ID) (239). Both arms stay; the constants differ, so neither shadows the other.

Not verified: a game run with this tree, and the ordering itself on the GPU (no rasterizer-ordered output was compared against a reference). The numbers above are the offline pack and the unit tests only.

AI-assisted (Claude Code). No game data attached.

@KainanP

KainanP commented Nov 25, 2026

Copy link
Copy Markdown

Tested 776ec56 merged onto main 0b0074e (clean merge) on three adapters. The upstream victory-shader tests give the same results as main on each adapter. A local synthetic POPS program translates, validates and gets a host pipeline on all three with this PR, and is refused on main. Ordering itself is still untested: no test draws overlapping primitives.

ROV support (D3D12_OPTIONS.ROVsSupported, queried per adapter)

Adapter Driver ROVs SM Barycentrics (OPTIONS3)
RTX 4060 Laptop 10de:28a0 32.0.16.1047 1 6.8 1
Intel UHD 8086:a78b 31.0.101.5445 1 6.7 0
WARP 1414:008c 10.0.26100.9818 1 6.8 1

All three support ROVs, so I could not test an adapter without them. From reading the code (not measured): the PR has no host-side check for ROV support. On such a device the translated shader would carry the ROV feature bit, CreateGraphicsPipelineState would fail, and pipeline/host.rs would log "host pipeline refused" and drop the draw. That fails cleanly: those draws are dropped today anyway. Separately, the guest-facing device.rs reports ROVs as supported regardless of the host.

Upstream tests, cargo test -p victory-shader --lib --locked --no-fail-fast (Windows 11, rustc 1.98.1)

victory-gpu is not touched by the PR, so I didn't run it.

Adapter (how selected) main 0b0074e main + #215
RTX 4060 (default) 215 passed, 0 failed 215 passed, 0 failed
WARP (VICTORY_WARP=1) 211 passed, 4 failed 211 passed, 4 failed (same 4)
Intel UHD (local adapter-by-name hook in emit/host.rs, not committed) 208 passed, 7 failed 208 passed, 7 failed (same 7)

The failures already happen on main, so none are new:

  • WARP: ds_min_max_f32_order_floats_and_return_the_old_value, v_permlane16_and_x16_read_the_lanes_their_selectors_pick and whole_wave_f64_sum_and_cvt_f32_f64 (compute pipeline E_INVALIDARG), plus wave64_tests::a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is.
  • Intel: the same 3 valu_tests, plus the 4 intersect_tests::the_{32,64}_bit_node_test_*.

The PR adds no tests. The two rectangle tests the PR body says fail on main pass on current main on the RTX.

Synthetic POPS program (local test, not committed)

The GFX10 words follow the shape #721 describes:

  1. s_lshr_b32/s_and_b32 of s18.
  2. s_setreg_b32 hwreg(HW_REG_POPS_PACKER).
  3. A s_cmp_eq_u32 bit-31 gate.
  4. A wait loop on s_mov_b32 sN, src_pops_exiting_wave_id / s_cmp_lt_u32 / s_cbranch_scc1.
  5. A buffer_load_dword … glc dlc → add → buffer_store_dword on a raw UAV from a descriptor table.
  6. s_sendmsg MSG_ORDERED_PS_DONE and exp mrt0.
main + #215 (RTX / WARP / Intel)
POPS program refused, a hardware SGPR input translates; SFI0 has 0x1000 (ROVs); dxil.dll validates; Host::pipeline creates the PSO on all 3
Same s18 use without the setreg and wait (control) refused still refused (POPS detection works as a gate)

dxc -dumpbin of the output: "Raster Ordered UAVs" is listed in the required features, the handle is annotated { i32 12299, … } (ROVByteAddressBuffer), and the wait loop folds away entirely (no spin remains).

One pitfall I hit: my first version read barycentrics, and Intel UHD refused that PSO because it has no barycentrics support. It was not an ROV problem. Without barycentrics, Intel takes the ROV pipeline.

What a real ordering test would need (missing)

This only proves the program translates, validates and gets a pipeline. Nothing checks that accesses happen in primitive order. A test that does needs:

  • One draw of N overlapping full-screen primitives (instanced, or a triangle list).
  • Each primitive does a non-commutative read-modify-write on a per-pixel RWTexture2D/raw UAV, e.g. v = v*3 + primitive_id.
  • A readback compared with the serial result.
  • Ideally a non-ROV control, which may race on hardware.

The test host's Draw only draws one triangle and binds no UAVs, so this needs harness work first.

Review (code reading; hypotheses unless marked)

  1. Correct (checked against the DXIL ABI): props0 bit 12 is IsUAV and bit 13 is IsROV, shader flag bit 18 is ROVs, and SFI0 0x1000 is ROVs. The flags are re-derived from usage after optimisation, so a ROV handle that gets optimised away also drops its flag. HW_REG id 25 and source 239 are HW_REG_POPS_PACKER and src_pops_exiting_wave_id on GFX10. The other SOPP messages, including MSG_ORDERED_PS_DONE, already lower to no-ops.
  2. The 59 compute DXIL changes JRamos1993 measured probably come from the root-UAV metadata, not opt.rs. let ordered = self.m.md_value(self.m.bool(self.rov)) is created inside the root-UAV loop for every shader, and Module::md_value always pushes a new metadata entry with no dedup. That makes each root UAV one metadata record larger even when rov is false. This fits "same -dumpbin, container 4–8 bytes larger". Fix: reuse no when !self.rov, and build the true value once outside the loop.
  3. s18 is hard-coded. The collision-wave-ID SGPR comes after the user SGPRs and PRIM_MASK. It is s18 for these programs (user data up to s16), but a POPS program with another user-SGPR count would have it elsewhere. That fails closed (still "a hardware SGPR input"), so it is not a miscompile. Deriving it from the layout (last user SGPR + 2) would be more robust.
  4. Detection is by instruction pattern only. The container already carries DB_SHADER_CONTROL (native.rs, PS_DB_SHADER_CONTROL). If I have the GFX9/10 layout right, its bit 16 (PRIMITIVE_ORDERED_PIXEL_SHADER) is the authoritative flag, and bits 22:20 (POPS_OVERLAP_NUM_SAMPLES) give the overlap granularity. Cross-checking against it would catch a POPS program whose wait reads src_pops_exiting_wave_id through a VALU (that fails closed today). It would also catch the case where s18 is zeroed for a non-POPS program that happens to set reg 25 (unlikely).
  5. Ordering scope:
    • The console orders the whole section per overlapping wave. ROV orders each ROV access per pixel (or per sample at sample rate). That is equivalent when the section only touches its own pixel's data, which is the usual RMW.
    • Marking every UAV of the program ROV is stricter than needed: a performance cost, not a correctness one.
    • MSAA: with a pixel-rate shader and per-sample overlap on the console, host ordering is per pixel. That is stricter, so still correct.
    • The one looser case: a sample-rate shader whose console overlap is per pixel. There, two samples of one pixel are unordered on the host but ordered on the console. I don't know whether these 10 programs run at sample rate.
    • Reads through descriptors the container declares SRV stay unordered. That matches the source declaration, so it is fine.
  6. Nothing checked in game. Shaders: PS_PedTex* fails with "a hardware SGPR input is not supported" — characters' skin and faces are missing #923 reports these programs were not reached in the first scenes either, so whether this fixes the missing skin is still open.

Commands: git fetch origin '+refs/pull/*/head:refs/remotes/pr/*', a worktree at origin/main + git merge pr/215, CARGO_BUILD_JOBS=6, the cargo test above once per adapter, and dxc.exe -dumpbin (Windows SDK 10.0.26100). No game data used.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

@KainanP

KainanP commented Nov 25, 2026

Copy link
Copy Markdown

Follow-up: an ordering test for this PR. It fails on the RTX 4060 and on Intel UHD. Both drivers leave a rasterizer-ordered view unordered when the shader opens it from the descriptor heap, and that is how this PR's UAVs reach the shader. On WARP it passes, but there it proves nothing (see the control). I also fixed the extra root-UAV metadata entry: the DXIL is now byte-identical to main for every program the tests translate.

Two commits on top of 776ec56, so you can pick either one alone:

git fetch https://github.com/KainanP/victory-fork.git test/rov-ordering-215
git cherry-pick fe3262e   # test host: N triangles + a read-back UAV; the ordering test
git cherry-pick 293d117   # root UAV metadata: no extra entry without ordering

fe3262e makes cargo test fail on NVIDIA and Intel until the ordering works. If you want to keep the suite green for now, take only 293d117.

What the test checks (emit/pops_tests.rs)

Harness (emit/host.rs):

  • Draw now takes triangles (N triangles in one DrawInstanced) and uav_dwords (a zeroed raw UAV placed after the textures in the heap).
  • draw_with_uav returns that UAV's contents.
  • passthrough_vs feeds the pixel shader's inputs from the vertex buffer.
  • The existing draw callers are unchanged apart from the two new fields set to 0.

Program: a synthetic GFX10 pixel program with the same shape as #721:

  1. The s18 entry word.
  2. s_setreg_b32 hwreg(HW_REG_POPS_PACKER).
  3. The wait loop on src_pops_exiting_wave_id.
  4. v_interp_mov_f32 of a flat attribute (k, the triangle's number).
  5. The pixel position turned into an address, then buffer_load_dword … offen glc dlc.
  6. v = v*31 + k, then buffer_store_dword.
  7. s_sendmsg MSG_ORDERED_PS_DONE, exp mrt0.

The UAV comes from a descriptor table, so the translation opens it with createHandleFromHeap and annotates it ROVByteAddressBuffer (props0 12299). SFI0 has the ROVs bit, and dxil.dll validates it.

Draw: 64 full-screen triangles numbered 1..64 in one draw on a 32×32 target, run 4 times. Every pixel must equal the serial result fold(0, v*31+k) = 0x94504420. The update does not commute, so any race or reordering shows up.

Results (main 0b0074e + #215 + these two commits; RTX and WARP give the same at bare 776ec56 + the two commits)

Adapter with #215 (ROV) control: same program, ROV flag off locally
RTX 4060 Laptop 10de:28a0 fails: 1024/1024 pixels wrong in each of 4 draws 1024/1024 wrong in each of 4 draws
Intel UHD 8086:a78b (local adapter hook, not committed) fails: 1024/1024 wrong in each of 4 draws 1024/1024 wrong in each of 4 draws
WARP passes, 0/1024 also 0/1024

With 2 triangles, RTX ends with 1 or 2 instead of 0x21. Both triangles read 0, so their sections overlap completely. With #215, the program behaves on the hardware exactly like the control without ROV. WARP runs overlapping pixels one after another anyway, so it cannot tell the two apart.

Why: heap-indexed ROVs are not ordered on these drivers (checked with dxc, not the translator)

Next I wanted to know whether the problem is the translation or the hardware. I compiled the same RMW from HLSL with dxc -T ps_6_6 (Windows SDK 10.0.26100) and ran it in the same harness (n = 64; wrong pixels out of 1024 in each of 3 draws):

HLSL variant RTX Intel WARP
RasterizerOrderedByteAddressBuffer b = ResourceDescriptorHeap[0] all wrong all wrong 0
RWByteAddressBuffer from the heap (no ROV) all wrong all wrong 0
RasterizerOrderedByteAddressBuffer b : register(u0, space1) (root UAV) 0 0 (not run)
RWByteAddressBuffer : register(u0, space1) all wrong all wrong (not run)
heap ROV RMW + a declared root ROV loaded before it 0 0 (not run)
same, declared ROV loaded after the RMW 0 0 (not run)
same, declared ROV loaded only under if (t.y == 12345.0) (never true) 0 0 (not run)

rov_heap is what this PR emits, and dxc emits the same handle (annotateHandle … { i32 12299, i32 0 }). It carries the ROVs feature flag and is still unordered on both drivers. As soon as the shader references any ROV declared in dx.resources, the heap ROV accesses are ordered, even if that reference never runs. My reading is that both drivers turn on pixel-shader interlock based on the declared resources, not on the annotate props or the SFI0 flag. I don't know whether the D3D12 spec promises ordering for heap-indexed ROVs. Either way, these two drivers don't provide it.

That suggests a fix, which I have not implemented because it touches the host's bindings. When rov is set, give the program one declared ROV and reference it in a branch that never runs. The root UAV path already writes the "rasterizer ordered" field in its metadata, from this PR. SLOT_FAULTS is a candidate, but victory-gpu binds it only when the program also reads SLOT_MEMORY (draw.rs, memory), so the binding would have to be guaranteed for these programs. The test above would show whether the fix works.

Metadata fix (293d117)

md_value adds an entry on every call, so the per-root-UAV ordered added one metadata entry to every program with root UAVs, even with rov false. The fix reuses no when rov is false and builds the true value once. Evidence:

  • Count (Module::mds.len() after the root-UAV list, intersect_tests::a_descriptor_of_numbers…, 1 root UAV, rov false): main 27, Shaders: lower the pixel ordered section (POPS) as rasterizer-ordered UAVs #215 28, with the fix 27.
  • Bytes: I dumped every DXIL that lower::lower returns during the whole victory-shader lib suite (117 programs). Shaders: lower the pixel ordered section (POPS) as rasterizer-ordered UAVs #215 vs main: the 2 programs with a root UAV are each +4 bytes, and the other 115 are identical. Fix vs main: all 117 are byte-identical, container hash included. dxc -dumpbin re-uniques the metadata, so the listing looks the same either way. That matches JRamos1993's finding of the "same module, encoding differs" for the 59 compute programs, which should now be identical to main. I can't check that without the pack.

Full suite and lint

cargo test -p victory-shader --lib --locked --no-fail-fast:

Adapter before (main + #215) main + #215 + both commits
RTX 4060 215 passed, 0 failed 215 passed, 1 failed (the new test)
WARP 211 passed, 4 failed 212 passed, 4 failed (the same 4)
Intel UHD 208 passed, 7 failed 208 passed, 8 failed (the same 7 + the new test)

At bare 776ec56 + both commits, RTX gives 210 passed and 1 failed (the new test). cargo clippy -p victory-shader --all-targets --locked -- -D warnings is clean, with and without --all-features on the merged tree, and with --all-features at bare 776ec56. No game data used. The adapter hook, the ROV-off control, the DXIL dumps and the HLSL variants were local only and are not in the commits.

AI use: Claude Code (Claude Opus 5.5).

@m335671

m335671 commented Nov 25, 2026

Copy link
Copy Markdown

Offline check on current main: this PR brings up the 10 programs that fail with a hardware SGPR input. All 10 are PS_PedTexturedCutOutTint_Zero variants, the ones #923 is about. No other program changes.

Tested

  • RTX 4070 12 GB (32-lane waves), driver 32.0.16.2124, Windows 11 Pro 26300, release build.
  • main 9c184b3 with this PR's head 776ec56 merged in. The merge was clean, even though the PR is based on 2119b0e.
  • VICTORY_HOST_MAX_WAVE=32 victory translate --list --pipelines over the title's whole shader pack, compared program by program by hash with my earlier listing of main 3973179. The same 10 still failed on 9c184b3 (with Name unsupported hardware SGPR inputs in shader diagnostics #941 merged, to name the register). The 10 were also run alone with --validate.
pipelines created a hardware SGPR input
main 3973179 25,608 10
main 9c184b3 + this PR 25,618 0
  • With Name unsupported hardware SGPR inputs in shader diagnostics #941's naming, the input is s18 in all 10.
  • The disassembly matches what this PR expects: in f0296ce9fbe481cb around 0x2d3c, s18 is split with s_bfe_u32 (bits 0–9, 16–25, 28–29 and 31), followed by s_setreg hwreg(HW_REG_POPS_PACKER), src_pops_exiting_wave_id and an s_sleep wait loop: the POPS collision wave ID.
  • All 10 now emit, pass dxil.dll validation, and the driver creates their pipelines. None of the other 25,608 is lost.

Not tested in the title: none of these 10 hashes appears in my logs from the first room or the following café scene, so I haven't seen them draw. #923's black faces may come from a later scene or a cutscene.

AI use: Claude Code (Claude Opus 5.5) built and ran the check on my machine, read the disassembly and wrote this comment.

Lynkes pushed a commit to Lynkes/victory-fork that referenced this pull request Nov 26, 2026
…ption for lower.rs alone)

lower.rs outgrew the common 512 KiB limit with the shader fixes taken in
(PRs fxceless#1112, fxceless#215), so repository_passes_policy failed and the pre-commit
hook refused any commit touching it. It now has a limit of its own, as the
RX 7900 XTX fork gives it; every other file keeps 512 KiB (tested).

Copy link
Copy Markdown

On an RX 7900 XT (RADV 26.3.1, Wine and vkd3d-proton) I tested the 280 character-texture pixel programs in my local package. Before the ordered-pixel change, 270 emitted DXIL and ten stopped on a hardware SGPR input. With the change, all 280 emitted. I ran just those ten through translate --pipelines on the same card and all ten created a host pipeline.

None of those ten shader identities appeared in the first-bind logs from the opening diner runs where the server's face drew black. This fixes a reproducible translation failure on AMD. That particular scene still has a separate rendering problem.

Tested branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants