Keep the per-sample pixel shader test triangle inside clip space #68

Closed
github-bot wants to merge 1 commit from gh-pr/68/head into gh-pr/68/base
Owner

@⁠philip-roy-jones on GitHub · 2026-11-21 22:39 UTC · original
test/per-sample-iteration-warp → main · +5 −2 · 1 files · 1 commits · closed without merging

Library / area: d3d12_xs pixel-shader option tests. Fixes the per-sample baseline failure reported in #59.

Exports changed (exports.txt rows): None.

Source of the behaviour: The fixture generates HLSL in the translator's output form, applies the production pixel-shader option edit, compiles with DXC, and reads the first 32-bit word of a UAV. The shader increments that word once whenever the interpolated X coordinate is nonnegative (true throughout this draw). Pixel-frequency shading runs once per rasterized primitive covering a pixel, while sample-frequency shading runs once per covered sample. D3D12 permits drivers to use a guard band when clipping X and Y. Microsoft multisample rasterization rules · D3D12 clipping rules

The original triangle extended past two clip planes. WARP reported one input primitive and three clipper output primitives. A handwritten HLSL control found 4,032 full-coverage invocations and 128 partial ones, all on the 64-pixel diagonal x + y == 63. The partial invocations split evenly between complementary sample masks 0x5 and 0xa. That accounts for 4,160 atomic increments and all 16,384 covered samples. The per-sample variant agreed with a direct SV_SampleIndex shader. The discrepancy comes from the test geometry.

The test now draws one triangle inside clip space and doubles the viewport. It reaches the same framebuffer coordinates (0,0), (128,0), (0,128) with the same 64×64 scissor. A single rasterized primitive covers all four samples of every test pixel. The test still requires exactly 4,096 base writes and 16,384 per-sample writes. #36 addresses interpolation linkage between shader stages. Both PSOs here were created and drew successfully on the baseline.

Windows verification

Windows 11 Pro 25H2 build 26200.9974, Rust 1.100.0 MSVC x64, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, system D3D12 and WARP 10.0.26100.9818. GetAdapterLuid and EnumAdapterByLuid identified the test's default device as Microsoft Basic Render Driver (1414:008c). Explicit EnumWarpAdapter produced the same results. Each measurement repeated three times on each device selection.

Measured per 64×64 draw, 4× MSAA Upstream cd08e9d Branch 757cc13
Fixture base / edited per-sample UAV increments 4,160 / 16,384 4,096 / 16,384
Direct pixel shader, full / partial masks 4,032 / 128 4,096 / 0
Sum of covered sample bits 16,384 16,384
Direct sample shader, writes per sample ID 0–3 4,096 each 4,096 each
Clipper output primitives from one input 3 1

Ran on upstream cd08e9da6c7d65cbc6b8cfb22541674871b02df6 and branch 757cc134a5e9452c17a719fb371aa00be038a39e from the repository root.

$env:TOMBOX_DXC_DIR = 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64'
$env:TOMBOX_DXC = Join-Path $env:TOMBOX_DXC_DIR 'dxc.exe'
$case = 'pso_ext::ps::tests::per_sample_iteration_runs_the_translated_ps_once_per_sample_like_ps_iter_sample'
cargo build --locked -p d3d12_xs
1..3 | ForEach-Object { cargo test --locked -p d3d12_xs --lib $case -- --exact --nocapture }
cargo test --locked -p d3d12_xs -- --test-threads=1

The focused test failed on all three baseline runs and passed on all three branch runs. With one test thread the unfiltered crate run went from 408 passed / 2 failed / 37 ignored to 409 passed / 1 failed / 37 ignored. The remaining failure is the pre-existing FXC uint64_t error tracked by #63. The default parallel crate run also aborted intermittently on both revisions. On upstream one run aborted in vmem_x and on the branch two runs exited 0xc0000005 after the per-sample test had passed.

cargo test --locked -p d3d12_xs --lib pso_ext::ps::tests::
cargo test --locked -p d3d12_xs -- --test-threads=1 --skip centroid_bind::tests::lowered_pixel_shader_compiles_with_fxc_in_both_variants
git diff --check upstream/main...HEAD

All six pixel-shader option tests passed. Filtering the FXC test passed the other 409 unit tests and both process-debug integration tests. The diff check passed. As a negative control, temporarily changing the variant's PerSampleIteration option from 1 to 2 made the exact assertion fail with (4096, 4096) against (4096, 16384).

Upstream advanced during verification. The same focused and unfiltered serial commands on e843998f0db8d59397eedd0df517b007a2b347a7 and GitHub's merge preview 90f02c41d20f36a857ef98b39531a75213cc4e24 reproduced the comparison above.

Reproduce the coverage and sample-ID measurements with standalone HLSL inputs

In a disposable checkout of either revision, append this test to crates/compat/d3d12_xs/src/pso_ext_ps_tests.rs. It uses the existing D3D12 draw and readback fixture. Each shader compiles directly with DXC.

#[test]
fn source_coverage_control() {
    unsafe {
        let r = rig();
        let draw = |inputs: &str, value: &str| {
            let h = format!("RWByteAddressBuffer c : register(u0);\nvoid main({inputs}) {{ c.InterlockedAdd(0, {value}); }}");
            let p = compile_ps(&h);
            run(&r, &[Draw { vs: &r.vs_hi, ps: &p, depth: false, write: false, func: 8 }], 4, 1.0)
        };
        let pixel = [
            "1u", "countbits(m & 15u)", "m == 15u", "m == 5u", "m == 10u",
            "(m != 15u && uint(p.x) + uint(p.y) == 63u)",
        ].map(|v| draw("float4 p : SV_Position, uint m : SV_Coverage", v));
        let samples = [0, 1, 2, 3].map(|i| draw("uint s : SV_SampleIndex", &format!("s == {i}u")));
        eprintln!("pixel={pixel:?} by_sample_id={samples:?}");
        for o in [r.rs, r.queue, r.dev] { call!(o, 2, () -> u32); }
    }
}
cargo test --locked -p d3d12_xs --lib pso_ext::ps::tests::source_coverage_control -- --exact --nocapture

The pixel counters are total increments, covered samples, full masks, mask 0x5, mask 0xa, and partial masks on the diagonal, in that order. The control printed [4160, 16384, 4032, 64, 64, 128] on upstream and [4096, 16384, 4096, 0, 0, 0] on the branch.

  • cargo test -p d3d12_xs passes (one independent baseline failure remains in #63).
  • No game or console files and no binaries included.
  • No fake success. The shader execution and readback determine the result.
**@⁠philip-roy-jones** on GitHub · 2026-11-21 22:39 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/68) `test/per-sample-iteration-warp` → `main` · +5 −2 · 1 files · 1 commits · closed without merging **Library / area:** `d3d12_xs` pixel-shader option tests. Fixes the per-sample baseline failure reported in #59. **Exports changed (exports.txt rows):** None. **Source of the behaviour:** The fixture generates HLSL in the translator's output form, applies the production pixel-shader option edit, compiles with DXC, and reads the first 32-bit word of a UAV. The shader increments that word once whenever the interpolated X coordinate is nonnegative (true throughout this draw). Pixel-frequency shading runs once per rasterized primitive covering a pixel, while sample-frequency shading runs once per covered sample. D3D12 permits drivers to use a guard band when clipping X and Y. [Microsoft multisample rasterization rules](https://learn.microsoft.com/en-us/windows/win32/direct3d11/d3d10-graphics-programming-guide-rasterizer-stage-rules) · [D3D12 clipping rules](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_rasterizer_desc) The original triangle extended past two clip planes. WARP reported one input primitive and three clipper output primitives. A handwritten HLSL control found 4,032 full-coverage invocations and 128 partial ones, all on the 64-pixel diagonal `x + y == 63`. The partial invocations split evenly between complementary sample masks `0x5` and `0xa`. That accounts for 4,160 atomic increments and all 16,384 covered samples. The per-sample variant agreed with a direct `SV_SampleIndex` shader. The discrepancy comes from the test geometry. The test now draws one triangle inside clip space and doubles the viewport. It reaches the same framebuffer coordinates `(0,0)`, `(128,0)`, `(0,128)` with the same 64×64 scissor. A single rasterized primitive covers all four samples of every test pixel. The test still requires exactly 4,096 base writes and 16,384 per-sample writes. #36 addresses interpolation linkage between shader stages. Both PSOs here were created and drew successfully on the baseline. ### Windows verification Windows 11 Pro 25H2 build 26200.9974, Rust 1.100.0 MSVC x64, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, system D3D12 and WARP 10.0.26100.9818. `GetAdapterLuid` and `EnumAdapterByLuid` identified the test's default device as Microsoft Basic Render Driver (`1414:008c`). Explicit `EnumWarpAdapter` produced the same results. Each measurement repeated three times on each device selection. | Measured per 64×64 draw, 4× MSAA | Upstream `cd08e9d` | Branch `757cc13` | | --- | ---: | ---: | | Fixture base / edited per-sample UAV increments | 4,160 / 16,384 | 4,096 / 16,384 | | Direct pixel shader, full / partial masks | 4,032 / 128 | 4,096 / 0 | | Sum of covered sample bits | 16,384 | 16,384 | | Direct sample shader, writes per sample ID 0–3 | 4,096 each | 4,096 each | | Clipper output primitives from one input | 3 | 1 | Ran on upstream `cd08e9da6c7d65cbc6b8cfb22541674871b02df6` and branch `757cc134a5e9452c17a719fb371aa00be038a39e` from the repository root. ```powershell $env:TOMBOX_DXC_DIR = 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64' $env:TOMBOX_DXC = Join-Path $env:TOMBOX_DXC_DIR 'dxc.exe' $case = 'pso_ext::ps::tests::per_sample_iteration_runs_the_translated_ps_once_per_sample_like_ps_iter_sample' cargo build --locked -p d3d12_xs 1..3 | ForEach-Object { cargo test --locked -p d3d12_xs --lib $case -- --exact --nocapture } cargo test --locked -p d3d12_xs -- --test-threads=1 ``` The focused test failed on all three baseline runs and passed on all three branch runs. With one test thread the unfiltered crate run went from 408 passed / 2 failed / 37 ignored to 409 passed / 1 failed / 37 ignored. The remaining failure is the pre-existing FXC `uint64_t` error tracked by #63. The default parallel crate run also aborted intermittently on both revisions. On upstream one run aborted in `vmem_x` and on the branch two runs exited `0xc0000005` after the per-sample test had passed. ```powershell cargo test --locked -p d3d12_xs --lib pso_ext::ps::tests:: cargo test --locked -p d3d12_xs -- --test-threads=1 --skip centroid_bind::tests::lowered_pixel_shader_compiles_with_fxc_in_both_variants git diff --check upstream/main...HEAD ``` All six pixel-shader option tests passed. Filtering the FXC test passed the other 409 unit tests and both process-debug integration tests. The diff check passed. As a negative control, temporarily changing the variant's `PerSampleIteration` option from `1` to `2` made the exact assertion fail with `(4096, 4096)` against `(4096, 16384)`. Upstream advanced during verification. The same focused and unfiltered serial commands on `e843998f0db8d59397eedd0df517b007a2b347a7` and GitHub's merge preview `90f02c41d20f36a857ef98b39531a75213cc4e24` reproduced the comparison above. <details> <summary>Reproduce the coverage and sample-ID measurements with standalone HLSL inputs</summary> In a disposable checkout of either revision, append this test to `crates/compat/d3d12_xs/src/pso_ext_ps_tests.rs`. It uses the existing D3D12 draw and readback fixture. Each shader compiles directly with DXC. ```rust #[test] fn source_coverage_control() { unsafe { let r = rig(); let draw = |inputs: &str, value: &str| { let h = format!("RWByteAddressBuffer c : register(u0);\nvoid main({inputs}) {{ c.InterlockedAdd(0, {value}); }}"); let p = compile_ps(&h); run(&r, &[Draw { vs: &r.vs_hi, ps: &p, depth: false, write: false, func: 8 }], 4, 1.0) }; let pixel = [ "1u", "countbits(m & 15u)", "m == 15u", "m == 5u", "m == 10u", "(m != 15u && uint(p.x) + uint(p.y) == 63u)", ].map(|v| draw("float4 p : SV_Position, uint m : SV_Coverage", v)); let samples = [0, 1, 2, 3].map(|i| draw("uint s : SV_SampleIndex", &format!("s == {i}u"))); eprintln!("pixel={pixel:?} by_sample_id={samples:?}"); for o in [r.rs, r.queue, r.dev] { call!(o, 2, () -> u32); } } } ``` ```powershell cargo test --locked -p d3d12_xs --lib pso_ext::ps::tests::source_coverage_control -- --exact --nocapture ``` The pixel counters are total increments, covered samples, full masks, mask `0x5`, mask `0xa`, and partial masks on the diagonal, in that order. The control printed `[4160, 16384, 4032, 64, 64, 128]` on upstream and `[4096, 16384, 4096, 0, 0, 0]` on the branch. </details> - [ ] `cargo test -p d3d12_xs` passes (one independent baseline failure remains in #63). - [x] No game or console files and no binaries included. - [x] No fake success. The shader execution and readback determine the result.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:09:10 +00:00
github-bot closed this pull request 2026-11-26 06:09:10 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-22 00:07 UTC · original

NVIDIA numbers for this, since the description covers WARP only. RTX 5090, driver 32.0.16.1742, default D3D12 device, --release. Main is 838f43f; "this PR" is your branch merged onto it.

main this PR
per_sample_iteration_runs_the_translated_ps_once_per_sample_like_ps_iter_sample, 3 runs pass, pass, pass pass, pass, pass
your source_coverage_control, pixel counters [4096, 16384, 4096, 0, 0, 0] [4096, 16384, 4096, 0, 0, 0]
same, by sample ID [4096, 4096, 4096, 4096] [4096, 4096, 4096, 4096]
the six pso_ext::ps::tests 6 pass 6 pass

So on this driver the original triangle already produces a single primitive per pixel (no partial masks on the diagonal), which fits your guard-band explanation: the failure is specific to a rasterizer that clips the triangle, and the new geometry gives the same counts on both. The branch merges cleanly with #36, #55 and #61.

Not checked: WARP on my side (the test takes the default adapter), AMD, Intel.

**@⁠QuentinDanblon** on GitHub · 2026-11-22 00:07 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/68#issuecomment-7071326328) NVIDIA numbers for this, since the description covers WARP only. RTX 5090, driver 32.0.16.1742, default D3D12 device, `--release`. Main is `838f43f`; "this PR" is your branch merged onto it. | | main | this PR | |---|---|---| | `per_sample_iteration_runs_the_translated_ps_once_per_sample_like_ps_iter_sample`, 3 runs | pass, pass, pass | pass, pass, pass | | your `source_coverage_control`, pixel counters | `[4096, 16384, 4096, 0, 0, 0]` | `[4096, 16384, 4096, 0, 0, 0]` | | same, by sample ID | `[4096, 4096, 4096, 4096]` | `[4096, 4096, 4096, 4096]` | | the six `pso_ext::ps::tests` | 6 pass | 6 pass | So on this driver the original triangle already produces a single primitive per pixel (no partial masks on the diagonal), which fits your guard-band explanation: the failure is specific to a rasterizer that clips the triangle, and the new geometry gives the same counts on both. The branch merges cleanly with #36, #55 and #61. Not checked: WARP on my side (the test takes the default adapter), AMD, Intel.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.