Repository navigation
Shaders: lower the pixel ordered section (POPS) as rasterizer-ordered UAVs - #215
arminkhaleghirod wants to merge 1 commit into
Conversation
|
Offline check on the retail shader pack: merged onto current Setup: RTX 5090, Windows 11.
AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it. |
|
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:
So the bytes differ in the bitcode encoding, probably from the AI use: Claude Code with Claude Opus 5.5 compared the dumps and wrote this. |
|
Tested on a combined tree, offline: the pixel programs that stopped with "a hardware SGPR input" all translate with this PR. Tree. Offline,
One conflict, easy: on that tree, #258 adds an 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. |
|
Tested ROV support (
|
| 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_pickandwhole_wave_f64_sum_and_cvt_f32_f64(compute pipelineE_INVALIDARG), pluswave64_tests::a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is. - Intel: the same 3
valu_tests, plus the 4intersect_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:
s_lshr_b32/s_and_b32of s18.s_setreg_b32 hwreg(HW_REG_POPS_PACKER).- A
s_cmp_eq_u32bit-31 gate. - A wait loop on
s_mov_b32 sN, src_pops_exiting_wave_id/s_cmp_lt_u32/s_cbranch_scc1. - A
buffer_load_dword … glc dlc→ add →buffer_store_dwordon a raw UAV from a descriptor table. s_sendmsg MSG_ORDERED_PS_DONEandexp 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)
- Correct (checked against the DXIL ABI):
props0bit 12 is IsUAV and bit 13 is IsROV, shader flag bit 18 is ROVs, and SFI00x1000is 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 areHW_REG_POPS_PACKERandsrc_pops_exiting_wave_idon GFX10. The other SOPP messages, includingMSG_ORDERED_PS_DONE, already lower to no-ops. - 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, andModule::md_valuealways pushes a new metadata entry with no dedup. That makes each root UAV one metadata record larger even whenrovis false. This fits "same-dumpbin, container 4–8 bytes larger". Fix: reusenowhen!self.rov, and build thetruevalue once outside the loop. - 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.
- 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 readssrc_pops_exiting_wave_idthrough 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). - 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.
- 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.
|
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 Two commits on top of
What the test checks (
|
| 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,rovfalse):main27, Shaders: lower the pixel ordered section (POPS) as rasterizer-ordered UAVs #215 28, with the fix 27. - Bytes: I dumped every DXIL that
lower::lowerreturns during the wholevictory-shaderlib suite (117 programs). Shaders: lower the pixel ordered section (POPS) as rasterizer-ordered UAVs #215 vsmain: the 2 programs with a root UAV are each +4 bytes, and the other 115 are identical. Fix vsmain: all 117 are byte-identical, container hash included.dxc -dumpbinre-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 tomain. 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).
|
Offline check on current Tested
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. |
…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).
|
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 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. |
Fixes the 10
emit: a hardware SGPR inputfailures.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_setregtoHW_REG_POPS_PACKER), spins untilsrc_pops_exiting_wave_idpasses 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:
s_setregis a no-op.Full-title
translate --validate, RTX 4080:a hardware SGPR input10 → 0. The 10 land in the blanket PSV mismatch, and no other count changes.--pipelinescreated 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.