Skip to content

dxil: emit InnerCoverage, ShadingRate, MeshDerivatives, and 64UAVs flags in graphics shaders - #2451

Merged
throny merged 1 commit into
xcl-dev:mainfrom
Decodere:fix-dxil-graphics-flags
Nov 29, 2026
Merged

throny merged 1 commit into
xcl-dev:mainfrom
Decodere:fix-dxil-graphics-flags

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

Emit four DXIL shader-flag and SFI0 feature bits in Shader::try_finish_graphics that dxil.dll requires when the corresponding graphics features are used: InnerCoverage, ShadingRate, DerivativesInMeshAndAmpShaders, and 64UAVs. Part of #1401. Part of #1833.

What is in it

  • crates/xcl/src/gpu/dxil/graphics.rs (Shader::try_finish_graphics):
    • Count static UAV bindings (self.bindings with ResClass::Uav) and emit 64UAVs (flags |= 1 << 15, sfi0 |= 0x8) across vertex, pixel, and mesh shaders whenever more than 8 static UAVs are bound (while preserving UavsAtEveryStage 1 << 16 / 0x4 for vertex shaders with any static UAV).
    • Emit ShadingRate (flags |= 1 << 24, sfi0 |= 0x8_0000) when Stage::Vertex outputs or Stage::Pixel inputs contain SemKind::ShadingRate (excluding Stage::Mesh primitive outputs, matching DXC).
    • Scan surviving post-optimize() instructions on Stage::Pixel and Stage::Mesh to emit InnerCoverage (flags |= 1 << 10, sfi0 |= 0x400) when dx.op.innerCoverage. (op 92) survives, and DerivativesInMeshAndAmpShaders (flags |= 1 << 29, sfi0 |= 0x100_0000) when mesh derivative or implicit-LOD ops (dx.op.unary. ops 83..=86, dx.op.sample. op 60, dx.op.sampleBias. op 61, dx.op.sampleCmp. op 64, dx.op.calculateLOD. op 81) survive; eliminated calls in unreachable blocks and dead-code-eliminated derivatives do not emit spurious flags.
  • crates/xcl/src/gpu/dxil/graphics_tests.rs:
    • Added four CPU/DXC-validated unit tests (ps_inner_coverage_sets_flag_only_when_live, shading_rate_sets_flag_for_vs_and_ps_but_not_ms, ms_derivatives_and_implicit_lod_set_flag_but_explicit_lod_does_not, graphics_64_uavs_flag_tracks_static_uav_count) asserting validate::validate, exact SFI0 values, disassembly metadata flags, and negative guards (unreachable inner coverage, mesh primitive shading rate, explicit sample_level and DCE'd mesh derivative, 8 static UAVs, and a single UAV at register u8).

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 4060 8 GB (driver 621.14, 32-lane waves), Intel Core i5-11400F, Windows 11 Home build 26200, Rust 1.100.0, DXC / dxil.dll 1.9.2609.5, release build.
  • Failing-first before the graphics.rs fix (on origin/main 943043e): all 4 new tests failed (0 passed, 4 failed on missing SFI0 bits).
  • Targeted cargo test --release -p xcl --lib -- gpu::dxil::graphics::tests:: --nocapture:
    • RTX 4060: 29 passed, 0 failed, 0 ignored (0.28 s, 0 skipped).
    • XCL_ADAPTER=warp: 29 passed, 0 failed, 0 ignored (0.03 s; 0 skipped on the 4 new tests, 2 pre-existing draw tests skipped: no wave64).
  • cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture (RTX 4060): 1367 passed, 0 failed, 46 ignored across 24 test binaries (184/184 gpu::dxil::* passed; 29 pre-existing SKIPPED GPU/environment checks: 21 no wave64, 3 per-lane wave32 refused, 3 no D3D12 debug layer, 1 no heap windows, 1 cannot disable driver cache; 0 skipped in gpu::dxil::graphics::tests).

Regression run
main:

xcl-smoke v1
commit: 2898511af1c038a2ef809719e9b6f89e5675c422
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1535 (PresentX 1536)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13996 MB

PR:

xcl-smoke v1
commit: 2e6e6ab8d6d8e453947020d777ca335630d85940
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1532 (PresentX 1532)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14013 MB

Not tested

  • Native wave64 GPU execution on wave64 hardware and D3D12 debug-layer tests requiring d3d12SDKLayers.dll.
  • Live runtime rendering of titles executing hardware VRS, conservative inner coverage, or mesh-shader implicit-LOD draws beyond DXC 1.9 validation and the 60 s title smoke test.

AI use

  • Google Antigravity (Gemini 4 Neon) implemented the flag emission in graphics.rs, wrote the DXC-validated tests in graphics_tests.rs, ran the test/smoke suites, and drafted this PR description.

…ags in graphics shaders

Shader::try_finish_graphics previously omitted four DXIL shader/SFI0 flag
bits required by dxil.dll when the corresponding graphics features are
present:

- InnerCoverage (1 << 10 / SFI0 0x400) for pixel shaders with a surviving
  post-optimize dx.op.innerCoverage (op 92) call.
- ShadingRate (1 << 24 / SFI0 0x8_0000) for vertex outputs and pixel inputs
  carrying SemKind::ShadingRate (not mesh primitive outputs).
- DerivativesInMeshAndAmpShaders (1 << 29 / SFI0 0x100_0000) for mesh
  shaders with surviving post-optimize derivatives or implicit-LOD ops
  (unary 83..=86, sample 60, sampleBias 61, sampleCmp 64, calculateLOD 81).
- 64UAVs (1 << 15 / SFI0 0x8) across vertex, pixel, and mesh stages when
  more than 8 static UAV bindings are declared.

Scan surviving post-optimize instructions for inner coverage and mesh
derivatives so eliminated calls in unreachable blocks or DCE'd derivatives
do not leave spurious flags, and add DXC-validated unit tests covering each
flag and its negative guards.

Part of xcl-dev#1401
Part of xcl-dev#1833

Assisted-by: Google Antigravity (Gemini 4 Neon)
@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head 2e6e6ab8d6d8e453947020d777ca335630d85940 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1365 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All gpu::dxil::graphics_tests and native wave64 GPU tests ran and passed.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: 2e6e6ab8d6d8e453947020d777ca335630d85940
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1544 (PresentX 1544)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14013 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@SlopTart

Copy link
Copy Markdown

gpu_ suite (cold cache): 160 passed / 4 failed, no crashes. The four are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, depth-buffer state refusal, and gpu_promoted_uav_clear_values_pass_create_committed_resource (report); none caused by this PR.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concrete source-level defect found. Post-opt scans, stage gates, and 64-UAV detection look correct; focused SFI0/metadata/container tests and current Windows CI are green, with AMD/NVIDIA evidence. Residual gap is only the disclosed absence of a live title exercising VRS, inner coverage, or mesh implicit-LOD rendering; I found no blocker.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
…ev#2446, xcl-dev#2503

Integrates direct DXIL graphics shader flags (xcl-dev#2451), PS live-lane
v_readfirstlane/SCC (xcl-dev#2501), MSG_GS_DONE emit/cut (xcl-dev#2485), VS/PS scalar
reload CSE (xcl-dev#2446), and per-lane V_CMP EXEC masking (xcl-dev#2503).

Assisted-by: Antigravity (Gemini 4 Neon)
@ClosetPie107

Copy link
Copy Markdown

Tested on AMD / Linux: 2e6e6ab8 (RX 9070 16 GB, RDNA4, Mesa 26.3.1 RADV; Ryzen 5 9600X, 32 GB; CachyOS; Proton Experimental experimental-11.0-20261112 with vkd3d-proton master ec207194 plus a local patch dropping the lpVtbl checks of command allocators and lists; DXC 1.9.2609.5; Rust 1.96.0, x86_64-pc-windows-gnu debug build, tests run under Wine)

The head as it is (not merged onto current main), with its base 2898511a the same session as the baseline.

Tests (XCL_REQUIRE_GPU=wave64)

  • cargo test -p xcl --lib -- ps_inner_coverage_sets_flag_only_when_live shading_rate_sets_flag_for_vs_and_ps_but_not_ms ms_derivatives_and_implicit_lod_set_flag_but_explicit_lod_does_not graphics_64_uavs_flag_tracks_static_uav_count --test-threads=1: 4 passed, 0 failed, 0 ignored.
  • cargo test -p xcl --lib -- gpu::dxil::graphics --test-threads=1: 29 passed, 0 failed, 0 ignored.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 with --skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole (the first loses the RADV device here, the other two run out of memory under Wine): lib 1277 passed, 10 failed, 26 ignored; base 2898511a lib (same flags): 1261 passed, 22 failed, 26 ignored. All of this head's failures are among the base's; the base fails 12 more (texture, sparse, vram and a few other tests). The other binaries fail the same 3 tests as on main here (e2e, pls_quota, predication_e2e).

Not tested

  • A retail title
  • Native Windows, NVIDIA / Intel

AI use

  • Claude Code (Claude Opus 5.5) wrote the test scripts, ran the builds and tests on my machine and wrote this report.

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 2e6e6ab

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 28, 2026
@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 851bf7f
head: 2e6e6ab
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2600 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at 851bf7f: 2596 passed, 0 failed, 49 ignored.
review: no blocking finding; all hunks read. The four flag bits match the compiler's numbering (64 UAVs, inner coverage, shading rate, derivatives in mesh shaders) and the opcodes that set them are the right ones. On current main only the 64-UAV flag can actually be set, because the direct translator builds no shader that emits the other three features; every GPU that runs this path has 64 UAVs, so no shader that worked before can be refused. To know for later: once the translator emits shading rate, inner coverage or mesh derivatives, a GPU without the matching feature will refuse such a shader, which is then the correct outcome. Not confirmed by me: that the validator checks declared flags against use (the tests compare our own output).
performance: a cheap instruction scan for pixel and mesh shaders. It changes a direct-DXIL source only: that path's cache entries are translated again once; the HLSL path is untouched.
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).

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 29, 2026
@iggyvilla

Copy link
Copy Markdown
Collaborator

merge-check
base: fa20459
head: 2e6e6ab
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2609 passed, 3 failed, 49 ignored; failing: the same three as on the base (fuzz_validate_and_gpu_1, test_title_runs_and_game_folder_is_untouched (e2e), two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs), each re-run on the base with the same failure. The first full run's lib test binary aborted before its summary (uma_driver coherent-window restore tests, Windows error 487); the totals are the -p xcl --lib re-run (2472 passed, 1 failed) plus the other targets of the full run (137 passed, 2 failed, 20 ignored).
review: no blocking finding. All hunks read. The four flag/SFI0 bit pairs (64UAVs 1<<15/0x8, InnerCoverage 1<<10/0x400, ShadingRate 1<<24/0x8_0000, DerivativesInMeshAndAmpShaders 1<<29/0x100_0000) match the opcodes/conditions checked; scan runs after optimize() so dead/unreachable uses do not set flags (covered by negative test guards). Heap handles never enter self.bindings (handle_from_heap path), so the UAV count is static-only as the comment claims. "dx.op.sample." prefix cannot collide with sampleBias/sampleCmp (trailing-dot mismatch) and those are checked separately. Mesh primitive ShadingRate outputs deliberately excluded, vertex/pixel covered. Minor only: the scan computes both inner_cov and mesh_deriv for both stages while each stage consumes one; first-arg opcode convention (args.first()) matches how these dx.op calls are built elsewhere. I did not independently re-derive the DXC flag numbers beyond the tests' exact-SFI0 + disassembly-metadata + validate assertions.
performance: a single linear scan over surviving call instructions at graphics-shader build time; negligible and not per-frame. Direct-DXIL cache entries retranslate once; HLSL path untouched.
verdict: safe to merge
hardware / tool and model: AMD Radeon RX 6650 XT, Windows 10.0.26300; Muse Spark 1.3 (via pi) ran the build and tests in a prepared trial-merge worktree and drafted the review/performance lines; Claude Sonnet 5.5 (Claude Code) prepared the merge worktrees, read every hunk of the diff, checked the test counts and that the PR's own tests ran and passed in the logs, edited this text and posted it.

AI use: the two models above did all of this; the account owner did not read the diff or write this text. Claude Sonnet 5.5 read the whole diff; Muse Spark 1.3 only ran the commands and drafted lines. What was not done: no game run, NVIDIA or Intel GPU, or Linux.

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 29, 2026
@throny
throny merged commit 2526fd7 into xcl-dev:main Nov 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants