Recompiler: a pixel shader's ordered section uses rasterizer ordered views #1709

Open
github-bot wants to merge 1 commit from github-bot/gh-1709 into main AGit
Owner

@⁠Alexr03 on GitHub · 2026-11-24 19:31 UTC · original
Alexr03:feature/ordered-pixel-shading → main · +225 −15 · 5 files · 1 commits · draft

A pixel shader with an ordered section (POPS) writes HW_REG_POPS_PACKER, waits until the earlier pixels at its position have left, then reads and writes its images. The translation lets the wait pass at once ("no ROV ordering yet – known limitation" in emit.rs and HANDOFF.md), so overlapping primitives race. Ten pixel shaders of a retail game's pack do this: after the wait, three image loads and five stores to the same three images at the pixel's position.

This is the first of three parts: the translation and its tests, off by default (Options::ordered_views; nothing sets it at a title's run, so no title's shaders change). Next: D3D12.X turns it on where the device has ROVsSupported and gives those pipelines the root signature below; then the README.

With the option, image loads and stores from the write of the register on go through RasterizerOrderedTexture* views of the UAV descriptor. The loads too: through the SRV they are not ordered.

The views come from a descriptor table, not ResourceDescriptorHeap. XCL's other views are taken from the heap, and that was the first form tried here. It is not in this PR, because on NVIDIA it cannot be used:

  • A pixel shader with RasterizerOrderedTexture2D<uint4> R = ResourceDescriptorHeap[1] makes the draw fail with DXGI_ERROR_DEVICE_HUNG (0x887A0006; the test's D3D12 device is lost – "device removed" in D3D12's terms – and its process ends with the error). One triangle is enough. RTX 5080, driver 32.0.16.2124.
  • The driver logs nvlddmkm event 153 ("Error occurred on GPUID") at each such run – and event 13, "Graphics SM Warp Exception: MMU Fault", in some of the earlier ones – and the desktop flickered during them.
  • The same shader with RWTexture2D instead runs, with no driver event, before and after a failing run.
  • DXC compiles and signs the failing shader, and CreateGraphicsPipelineState accepts it; the AMD driver runs it and orders it.

From an unbounded array in a table over the same heap the ordered view works on both. So pso::abi_root_signature_ordered adds one parameter (6), a table to set to the heap's start, and Translation::ordered_views says a pipeline needs it.

That this is a driver fault and not a form D3D12 forbids is a conclusion from the four points above. It was not run under the D3D12 debug layer, and no statement in the specification was looked up either way.

Measured, 64 triangles over a 16² target in one draw, each pixel adding one to its texel, the value the last triangle reads (63 when ordered):

RTX 5080 AMD Radeon (integrated, 7900X3D)
unordered (as on main) 0 8
ordered view from ResourceDescriptorHeap (not in this PR) no value: the draw fails 63
ordered view from the table (this PR) 63 63

The RTX 5080 has no number in the second row because nothing can be read back: the draw that would give it ends with DXGI_ERROR_DEVICE_HUNG, so the target is never copied out.

What is in it

  • Recompiler: a pixel shader's ordered section uses rasterizer ordered views
    • crates/xcl/src/gpu/recomp/mod.rs: Options::ordered_views, Translation::ordered_views.
    • crates/xcl/src/gpu/recomp/emit.rs: the pc of the first HW_REG_POPS_PACKER write (pre-scan); image_load / image_store after it through the ordered arrays (xcl_ord<dim>_<f|u|i>, register u0 of space 2 + 3 · dimension + class), declared for the dimensions used. image_load_mip, multisampled loads and image atomics stay as they are.
    • crates/xcl/src/gpu/recomp/pso.rs: abi_root_signature_ordered (not called by the runtime yet).
    • crates/xcl/src/gpu/recomp/runner.rs (test runner): ordered_views() from ROVsSupported; a test texture with ALLOW_UNORDERED_ACCESS gets its UAV at 2·i + 1; the draws' root signature has the table.
    • crates/xcl/src/gpu/recomp/tests.rs: ordered_section_images_are_rasterizer_ordered_views (the HLSL with and without the option; no GPU) and gpu_ps_ordered_section_orders_overlapping_triangles (the draw above; skips with "no ordered views").

emit.rs is part of the translator source id, so translation caches rebuild once.

Tested

  • NVIDIA GeForce RTX 5080 (driver 32.0.16.2124, 32-lane waves) and AMD Radeon integrated graphics of a Ryzen 9 7900X3D (driver 32.0.21030.2001, XCL_ADAPTER=radeon); Windows 11 Pro 26200, Rust 1.100.0, DXC 1.8.2502.11; tests in debug, regression runs in release.
  • cargo test --workspace -- --test-threads=4 on the RTX 5080, head a57a76c: 860 passed, 0 failed, 42 ignored.
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • gpu_ps_ordered_section_orders_overlapping_triangles: passes in 10 of 10 runs on each adapter before the rebase onto c160d86 and in 3 of 3 on each after it. With the option forced off in the runner it fails on both (pixel (0, 0): 0 on the RTX 5080, 8 on the Radeon).
  • The table of three forms above: local variants of the test's shader, not in the PR. The failing form once more on its own, one triangle, between two runs of the RWTexture2D form: those gave 0 driver events each, it gave the error and two nvlddmkm 153 events in the same seconds.
  • The pack's ten shaders: found by a local scan with rdna2::decode (not in the PR).

Regression run

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 5080
title: a newer retail game
seconds: 60
exit: 0x0
frames shown: 1627 (PresentX 1627)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14864 MB

PR:

xcl-smoke v1
commit: a57a76cd4a9cca1abf4d52ca4b3615f895b3655c
gpu: NVIDIA GeForce RTX 5080
title: a newer retail game
seconds: 60
exit: 0x0
frames shown: 1637 (PresentX 1637)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14852 MB

The run does not reach the changed code: the option is off at a title's run.

Not tested

  • The pack's ten shaders through this translation on a GPU: that needs the runtime part.
  • Whether their three images' formats can be read through a UAV (typed UAV loads); the test uses R32_UINT, which always can.
  • Desktop AMD cards, Intel, Linux / Proton; other NVIDIA cards and drivers (the failure of the heap form was seen on one card with one driver).
  • The heap form under the D3D12 debug layer or GPU-based validation, and against the specification: whether it is a driver fault or invalid use is not established (see above). It was not reported to NVIDIA.
  • The direct DXIL path (XCL_DIRECT_DXIL): it has no ordered views.
  • 1D, 3D and array images in an ordered section (only 2D is drawn), and the 15 aliased ranges beyond the three the test's shader declares.

AI use

  • Claude Code with Mythos 5.2 (claude-mythos-5-2): found the shaders, wrote the change, the tests and this description, and ran the tests, the adapter comparison and the regression runs.
**@⁠Alexr03** on GitHub · 2026-11-24 19:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/1709) `Alexr03:feature/ordered-pixel-shading` → `main` · +225 −15 · 5 files · 1 commits · draft A pixel shader with an ordered section (POPS) writes `HW_REG_POPS_PACKER`, waits until the earlier pixels at its position have left, then reads and writes its images. The translation lets the wait pass at once ("no ROV ordering yet – known limitation" in `emit.rs` and `HANDOFF.md`), so overlapping primitives race. Ten pixel shaders of a retail game's pack do this: after the wait, three image loads and five stores to the same three images at the pixel's position. This is the first of three parts: the translation and its tests, **off by default** (`Options::ordered_views`; nothing sets it at a title's run, so no title's shaders change). Next: D3D12.X turns it on where the device has `ROVsSupported` and gives those pipelines the root signature below; then the README. With the option, image loads and stores from the write of the register on go through `RasterizerOrderedTexture*` views of the UAV descriptor. The loads too: through the SRV they are not ordered. **The views come from a descriptor table, not `ResourceDescriptorHeap`.** XCL's other views are taken from the heap, and that was the first form tried here. It is not in this PR, because on NVIDIA it cannot be used: - A pixel shader with `RasterizerOrderedTexture2D<uint4> R = ResourceDescriptorHeap[1]` makes the draw fail with `DXGI_ERROR_DEVICE_HUNG` (0x887A0006; the test's D3D12 device is lost – "device removed" in D3D12's terms – and its process ends with the error). One triangle is enough. RTX 5080, driver 32.0.16.2124. - The driver logs `nvlddmkm` event 153 ("Error occurred on GPUID") at each such run – and event 13, "Graphics SM Warp Exception: MMU Fault", in some of the earlier ones – and the desktop flickered during them. - The same shader with `RWTexture2D` instead runs, with no driver event, before and after a failing run. - DXC compiles and signs the failing shader, and `CreateGraphicsPipelineState` accepts it; the AMD driver runs it and orders it. From an unbounded array in a table over the same heap the ordered view works on both. So `pso::abi_root_signature_ordered` adds one parameter (6), a table to set to the heap's start, and `Translation::ordered_views` says a pipeline needs it. That this is a driver fault and not a form D3D12 forbids is a conclusion from the four points above. It was not run under the D3D12 debug layer, and no statement in the specification was looked up either way. Measured, 64 triangles over a 16² target in one draw, each pixel adding one to its texel, the value the last triangle reads (63 when ordered): | | RTX 5080 | AMD Radeon (integrated, 7900X3D) | |---|---|---| | unordered (as on `main`) | 0 | 8 | | ordered view from `ResourceDescriptorHeap` (not in this PR) | no value: the draw fails | 63 | | ordered view from the table (this PR) | 63 | 63 | The RTX 5080 has no number in the second row because nothing can be read back: the draw that would give it ends with `DXGI_ERROR_DEVICE_HUNG`, so the target is never copied out. **What is in it** - `Recompiler: a pixel shader's ordered section uses rasterizer ordered views` - `crates/xcl/src/gpu/recomp/mod.rs`: `Options::ordered_views`, `Translation::ordered_views`. - `crates/xcl/src/gpu/recomp/emit.rs`: the pc of the first `HW_REG_POPS_PACKER` write (pre-scan); `image_load` / `image_store` after it through the ordered arrays (`xcl_ord<dim>_<f|u|i>`, register u0 of space 2 + 3 · dimension + class), declared for the dimensions used. `image_load_mip`, multisampled loads and image atomics stay as they are. - `crates/xcl/src/gpu/recomp/pso.rs`: `abi_root_signature_ordered` (not called by the runtime yet). - `crates/xcl/src/gpu/recomp/runner.rs` (test runner): `ordered_views()` from `ROVsSupported`; a test texture with `ALLOW_UNORDERED_ACCESS` gets its UAV at 2·i + 1; the draws' root signature has the table. - `crates/xcl/src/gpu/recomp/tests.rs`: `ordered_section_images_are_rasterizer_ordered_views` (the HLSL with and without the option; no GPU) and `gpu_ps_ordered_section_orders_overlapping_triangles` (the draw above; skips with "no ordered views"). `emit.rs` is part of the translator source id, so translation caches rebuild once. **Tested** - NVIDIA GeForce RTX 5080 (driver 32.0.16.2124, 32-lane waves) and AMD Radeon integrated graphics of a Ryzen 9 7900X3D (driver 32.0.21030.2001, `XCL_ADAPTER=radeon`); Windows 11 Pro 26200, Rust 1.100.0, DXC 1.8.2502.11; tests in debug, regression runs in release. - `cargo test --workspace -- --test-threads=4` on the RTX 5080, head `a57a76c`: 860 passed, 0 failed, 42 ignored. - SKIPPED: `gpu_geometry_wave32_prefix_count_over_a_mask` (no wave64), `gpu_wave32_program_in_wave64_hardware` (no wave64), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `gpu_ps_ordered_section_orders_overlapping_triangles`: passes in 10 of 10 runs on each adapter before the rebase onto `c160d86` and in 3 of 3 on each after it. With the option forced off in the runner it fails on both (pixel (0, 0): 0 on the RTX 5080, 8 on the Radeon). - The table of three forms above: local variants of the test's shader, not in the PR. The failing form once more on its own, one triangle, between two runs of the `RWTexture2D` form: those gave 0 driver events each, it gave the error and two `nvlddmkm` 153 events in the same seconds. - The pack's ten shaders: found by a local scan with `rdna2::decode` (not in the PR). **Regression run** main: ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: NVIDIA GeForce RTX 5080 title: a newer retail game seconds: 60 exit: 0x0 frames shown: 1627 (PresentX 1627) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14864 MB ``` PR: ``` xcl-smoke v1 commit: a57a76cd4a9cca1abf4d52ca4b3615f895b3655c gpu: NVIDIA GeForce RTX 5080 title: a newer retail game seconds: 60 exit: 0x0 frames shown: 1637 (PresentX 1637) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14852 MB ``` The run does not reach the changed code: the option is off at a title's run. **Not tested** - The pack's ten shaders through this translation on a GPU: that needs the runtime part. - Whether their three images' formats can be read through a UAV (typed UAV loads); the test uses `R32_UINT`, which always can. - Desktop AMD cards, Intel, Linux / Proton; other NVIDIA cards and drivers (the failure of the heap form was seen on one card with one driver). - The heap form under the D3D12 debug layer or GPU-based validation, and against the specification: whether it is a driver fault or invalid use is not established (see above). It was not reported to NVIDIA. - The direct DXIL path (`XCL_DIRECT_DXIL`): it has no ordered views. - 1D, 3D and array images in an ordered section (only 2D is drawn), and the 15 aliased ranges beyond the three the test's shader declares. **AI use** - Claude Code with Mythos 5.2 (`claude-mythos-5-2`): found the shaders, wrote the change, the tests and this description, and ran the tests, the adapter comparison and the regression runs.
A pixel shader with an ordered section (POPS) writes HW_REG_POPS_PACKER,
waits until the earlier pixels at its position have left, then reads and
writes its images. The translation let the wait pass at once, so
overlapping primitives raced. Ten pixel shaders of a retail pack do this:
after the wait, three image loads and five stores to the same three
images at the pixel's position.

With Options::ordered_views (off by default; nothing sets it at a title's
run yet), image loads and stores from the write of the register on go
through RasterizerOrderedTexture* views of the UAV descriptor. The loads
too: through the SRV they are not ordered. Translation::ordered_views
tells the pipeline it needs pso::abi_root_signature_ordered.

The views are unbounded arrays in a descriptor table over the
shader-visible heap, not ResourceDescriptorHeap: taken from the heap, a
rasterizer ordered view removes the device on NVIDIA (RTX 5080, driver
32.0.16.2124) at the first draw, even for one triangle and one store.
From a table it works there and on AMD (Radeon integrated).

Measured with gpu_ps_ordered_section_orders_overlapping_triangles (64
triangles over the target, each pixel adds one to its texel): the last
triangle reads 63 at every pixel on both adapters in 10 of 10 runs;
without the option it reads 0 (NVIDIA) and 8 (AMD).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:02:17 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 22:18 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 22:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/1709#issuecomment-7146077073) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/gpu/recomp/emit.rs
  • crates/xcl/src/gpu/recomp/pso.rs
  • crates/xcl/src/gpu/recomp/tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1709/head:github-bot/gh-1709'
git switch 'github-bot/gh-1709'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1709'
git switch 'github-bot/gh-1709'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1709'
git switch 'github-bot/gh-1709'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1709'
git switch 'main'
git merge --squash 'github-bot/gh-1709'
git switch 'main'
git merge --ff-only 'github-bot/gh-1709'
git switch 'main'
git merge 'github-bot/gh-1709'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.