Shaders: add DXIL CFG, PHI, DCE, compaction, and feature-sync passes #1535

Closed
Roroca-1 wants to merge 2 commits from upstream-pr/1545 into main
Roroca-1 commented 2026-11-24 17:28:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Roroca-1 on 2026-11-24T17:28:50Z.


Retired after #1426 merged. Main now handles unreachable blocks, trivial PHIs, dominator CSE and dead instructions during shader finalization. The additional CFG rewrites, compaction and feature synchronization in this draft have no isolated result here against the merged optimizer. The original branch is preserved for follow-up measurements.

Core DXIL SSA IR optimization and compaction passes (Shader::optimize / opt::optimize_module), left unwired from kernel translation until the stacked InstCombine/CSE and enablement PRs land.

Part of #1269.
Stacked on #1544; only the top commit belongs here.

This PR adds ~1,230 non-test lines (~256 test lines) because the iterative CFG/PHI/DCE fixpoint loop, compact_module, and sync_features share operand-rewriting and dominator helpers and together keep Shader::features consistent after dead code removal; InstCombine/CSE and kernel.rs wiring are split into the follow-up PRs.

The merged #1426 already performs unreachable-block cleanup, trivial PHI elimination and DCE in module/opt.rs. This branch predates that implementation and conflicts with main.

What is in it

  • crates/xcl/src/gpu/dxil/opt.rs: add Stats, module_stats, optimize, optimize_module, iterative simplify_cfg (terminator folding, iterative RPO traversal, PHI edge trimming, empty jump-block bypass, single-predecessor merging, dense RPO re-indexing), dominance-checked simplify_phis (via iterative Cooper-Harvey-Kennedy compute_idom), iterative mark-and-sweep dce (dead PHI cycles, unused readnone/readonly and pure wave/quad calls), dense compact_module, and sync_features plus 5 unit/GPU tests.
  • crates/xcl/src/gpu/dxil/mod.rs, crates/xcl/src/gpu/dxil/shader.rs: export pub mod opt and add Shader::optimize(&mut self).

Tested

  • AMD Radeon RX 9070 XT (RADV GFX1201, radv 26.3.1) under Wine + vkd3d-proton (proton-cachyos-slr) + DXVK, cross-built from Linux to x86_64-pc-windows-msvc via cargo-xwin, debug, commit 32facfe36b73:
  • TARGET_CFLAGS="/FIstring.h" cargo xwin build --tests -p xcl --target x86_64-pc-windows-msvc: 0 errors, 0 warnings
  • wine xcl.exe gpu::dxil::opt --nocapture --test-threads=1: 5 passed, 0 failed, 0 ignored (809 filtered out; 0 SKIPPED, includes GPU execution on RX 9070 XT)

Regression run

Pending native Windows GPU workspace tests and paired scripts/smoke.ps1 runs on the same retail title and duration at clean main and PR head. Path coverage must be recorded with the results. The new pass is unwired on this branch.

Not tested

  • Windows native MSVC build and full .\scripts\test.ps1 workspace test suite
  • dxcompiler.dll DXIL validation and disassembly (unavailable locally under Wine)
  • scripts/smoke.ps1 regression run on retail game titles

AI use

  • T3 Code (Antigravity harness, gemini-pro-orchestrator-neon): designed and wrote opt.rs passes and tests, wired Shader::optimize, drafted this description, and ran the cargo-xwin / Wine + RX 9070 XT tests.
  • T3 Code (Codex, gpt-6.2-astra) checked upstream overlap and updated the review status.
<!-- greyfinch-sync:ivall/xcl:issue:6587621664 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1545). Originally posted by [Roroca-1](https://github.com/Roroca-1) on 2026-11-24T17:28:50Z. --- Retired after #1426 merged. Main now handles unreachable blocks, trivial PHIs, dominator CSE and dead instructions during shader finalization. The additional CFG rewrites, compaction and feature synchronization in this draft have no isolated result here against the merged optimizer. The original branch is preserved for follow-up measurements. Core DXIL SSA IR optimization and compaction passes (`Shader::optimize` / `opt::optimize_module`), left unwired from kernel translation until the stacked InstCombine/CSE and enablement PRs land. Part of #1269. Stacked on #1544; only the top commit belongs here. This PR adds ~1,230 non-test lines (~256 test lines) because the iterative CFG/PHI/DCE fixpoint loop, `compact_module`, and `sync_features` share operand-rewriting and dominator helpers and together keep `Shader::features` consistent after dead code removal; InstCombine/CSE and `kernel.rs` wiring are split into the follow-up PRs. The merged #1426 already performs unreachable-block cleanup, trivial PHI elimination and DCE in `module/opt.rs`. This branch predates that implementation and conflicts with `main`. **What is in it** - `crates/xcl/src/gpu/dxil/opt.rs`: add `Stats`, `module_stats`, `optimize`, `optimize_module`, iterative `simplify_cfg` (terminator folding, iterative RPO traversal, PHI edge trimming, empty jump-block bypass, single-predecessor merging, dense RPO re-indexing), dominance-checked `simplify_phis` (via iterative Cooper-Harvey-Kennedy `compute_idom`), iterative mark-and-sweep `dce` (dead PHI cycles, unused `readnone`/`readonly` and pure wave/quad calls), dense `compact_module`, and `sync_features` plus 5 unit/GPU tests. - `crates/xcl/src/gpu/dxil/mod.rs`, `crates/xcl/src/gpu/dxil/shader.rs`: export `pub mod opt` and add `Shader::optimize(&mut self)`. **Tested** - AMD Radeon RX 9070 XT (RADV GFX1201, radv 26.3.1) under Wine + vkd3d-proton (`proton-cachyos-slr`) + DXVK, cross-built from Linux to `x86_64-pc-windows-msvc` via `cargo-xwin`, debug, commit `32facfe36b73`: - `TARGET_CFLAGS="/FIstring.h" cargo xwin build --tests -p xcl --target x86_64-pc-windows-msvc`: 0 errors, 0 warnings - `wine xcl.exe gpu::dxil::opt --nocapture --test-threads=1`: 5 passed, 0 failed, 0 ignored (`809 filtered out`; 0 `SKIPPED`, includes GPU execution on RX 9070 XT) **Regression run** Pending native Windows GPU workspace tests and paired `scripts/smoke.ps1` runs on the same retail title and duration at clean `main` and PR head. Path coverage must be recorded with the results. The new pass is unwired on this branch. **Not tested** - Windows native MSVC build and full `.\scripts\test.ps1` workspace test suite - `dxcompiler.dll` DXIL validation and disassembly (unavailable locally under Wine) - `scripts/smoke.ps1` regression run on retail game titles **AI use** - T3 Code (Antigravity harness, gemini-pro-orchestrator-neon): designed and wrote `opt.rs` passes and tests, wired `Shader::optimize`, drafted this description, and ran the `cargo-xwin` / Wine + RX 9070 XT tests. - T3 Code (Codex, gpt-6.2-astra) checked upstream overlap and updated the review status.
gut0to commented 2026-11-24 19:06:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:42:52Z.

Review: COMMENTED


The targeted DXIL tests are helpful, and leaving the optimizer unwired avoids enabling it prematurely. CONTRIBUTING.md still requires the full workspace suite on Windows; the current report says that was not run natively. It also requires a paired real-title smoke run for changes under crates/xcl/src, even when the title does not reach the new path. Please add those results before merge, documenting the path coverage. AI-assisted review; I checked the applicable requirements against the guide.

<!-- greyfinch-sync:ivall/xcl:review:6045242492 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1545#pullrequestreview-6045242492). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-24T18:42:52Z. **Review:** COMMENTED --- The targeted DXIL tests are helpful, and leaving the optimizer unwired avoids enabling it prematurely. CONTRIBUTING.md still requires the full workspace suite on Windows; the current report says that was not run natively. It also requires a paired real-title smoke run for changes under `crates/xcl/src`, even when the title does not reach the new path. Please add those results before merge, documenting the path coverage. AI-assisted review; I checked the applicable requirements against the guide.
upstream-sync closed this pull request 2026-11-24 21:06:32 +00:00
DavidM1911 commented 2026-11-24 21:08:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T19:19:10Z.


Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7141921490 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1545#issuecomment-7141921490). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T19:19:10Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1535
No description provided.