Skip to content

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

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-dxil-graphics-flags
Open

Decodere wants to merge 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)
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.

5 participants