Direct DXIL: audit metadata and legalization against DXC and LLVM references #2531

Open
opened 2026-11-25 22:24:36 +00:00 by mokkamokacaffe · 2 comments
mokkamokacaffe commented 2026-11-25 22:24:36 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by mokkamokacaffe on 2026-11-25T22:24:36Z.


Current status

At 9ebc4a21 on PR #2553, five sampled translations produced manifests that passed artifact verification. Shader validation was disabled for this sample. The workspace run reported 1,461 passed, 0 failed and 47 ignored. Paired 60-second RTX 4080 SUPER smokes completed without crashes or device removals. The minimal HLSL/DXC semantic comparison and AMD run remain pending for this sample. No metadata or legalization discrepancy was established. Revision-specific audit report

Summary

XCL directly emits DXIL in crates/xcl/src/gpu/dxil/. The current implementation is primarily checked through XCL unit tests, dxil.dll validation and hardware execution.

Add a structured audit comparing XCL’s emitted modules with minimal equivalent shaders produced by DXC, using LLVM’s DirectX backend as an independent architectural reference. The goal is not to replace XCL’s emitter or introduce LLVM as a dependency. It is to identify metadata, legalization and container inconsistencies that can cause validator-version differences, driver rejection or unnecessary driver compilation work.

Part of #1269.

Motivation

A module can be valid LLVM-derived bitcode while still violating DXIL-specific requirements. It can also pass one validator version yet expose inconsistent metadata or feature flags to another validator or GPU driver.

Recent work has encountered areas where exact DXIL declarations matter, including:

  • shader feature flags matching actual operation use;
  • compute initialization and entry-point metadata;
  • wave32/wave64 compatibility;
  • resource-handle properties;
  • validator-version differences.

DXC is the practical Microsoft reference. LLVM’s documented DirectX backend provides a useful independent model of the lowering stages and invariants:

Proposed scope

Audit these XCL areas:

  • crates/xcl/src/gpu/dxil/ops.rs

    • dx.op opcode, overload and argument signatures
    • shader-model and stage restrictions
  • crates/xcl/src/gpu/dxil/module.rs

    • target triple and data layout
    • function attributes
    • named metadata
    • module and validator version declarations
  • crates/xcl/src/gpu/dxil/shader.rs

    • entry-point metadata
    • shader feature flags
    • stage-specific properties
  • crates/xcl/src/gpu/dxil/kernel.rs

    • compute thread-group and wave information
    • resource and initialization metadata
  • crates/xcl/src/gpu/dxil/compact.rs

    • whether compaction preserves all referenced metadata and declarations
  • container/PSV/signature construction used by the direct emitter

    • agreement between entry signatures, PSV and declared resources

Proposed method

For each representative shader family:

  1. Write the smallest HLSL shader exercising one behavior.
  2. Compile it with a pinned DXC version.
  3. Dump the resulting DXIL and container metadata.
  4. Produce the equivalent shader through XCL’s direct emitter.
  5. Compare semantic properties rather than allocation names or instruction order.
  6. Validate both outputs with the supported dxil.dll versions.
  7. Run the XCL output on AMD and NVIDIA where hardware behavior is relevant.

Initial shader families:

  • empty compute shader and thread-group metadata;
  • raw, structured and typed buffer loads/stores;
  • static and dynamic resource handles;
  • descriptor-heap resource access;
  • wave operations under wave32 and wave64;
  • derivatives and helper-lane operations;
  • vertex/pixel signatures and interpolation modes;
  • mesh shader output and topology metadata;
  • operations requiring shader feature flags.

Test infrastructure

Add a semantic inspection helper that reports stable properties such as:

shader model and stage
validator/module versions
declared feature flags
dx.op names, opcodes and overloads
resource bindings and properties
entry-point properties
thread-group and wave-size metadata
input/output signatures
PSV resource and signature counts
<!-- greyfinch-sync:ivall/xcl:issue:6614993824 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2541). Originally posted by [mokkamokacaffe](https://github.com/mokkamokacaffe) on 2026-11-25T22:24:36Z. --- ## Current status At `9ebc4a21` on PR #2553, five sampled translations produced manifests that passed artifact verification. Shader validation was disabled for this sample. The workspace run reported 1,461 passed, 0 failed and 47 ignored. Paired 60-second RTX 4080 SUPER smokes completed without crashes or device removals. The minimal HLSL/DXC semantic comparison and AMD run remain pending for this sample. No metadata or legalization discrepancy was established. [Revision-specific audit report](https://github.com/xcl-dev/xcl/issues/2541#issuecomment-7216978030) ## Summary XCL directly emits DXIL in `crates/xcl/src/gpu/dxil/`. The current implementation is primarily checked through XCL unit tests, `dxil.dll` validation and hardware execution. Add a structured audit comparing XCL’s emitted modules with minimal equivalent shaders produced by DXC, using LLVM’s DirectX backend as an independent architectural reference. The goal is not to replace XCL’s emitter or introduce LLVM as a dependency. It is to identify metadata, legalization and container inconsistencies that can cause validator-version differences, driver rejection or unnecessary driver compilation work. Part of #1269. ## Motivation A module can be valid LLVM-derived bitcode while still violating DXIL-specific requirements. It can also pass one validator version yet expose inconsistent metadata or feature flags to another validator or GPU driver. Recent work has encountered areas where exact DXIL declarations matter, including: - shader feature flags matching actual operation use; - compute initialization and entry-point metadata; - wave32/wave64 compatibility; - resource-handle properties; - validator-version differences. DXC is the practical Microsoft reference. LLVM’s documented DirectX backend provides a useful independent model of the lowering stages and invariants: - Microsoft DXIL specification: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst - DXC operation database: https://github.com/microsoft/DirectXShaderCompiler/blob/main/utils/hct/hctdb.py - LLVM DXIL architecture: https://llvm.org/docs/DirectX/DXILArchitecture.html ## Proposed scope Audit these XCL areas: - `crates/xcl/src/gpu/dxil/ops.rs` - `dx.op` opcode, overload and argument signatures - shader-model and stage restrictions - `crates/xcl/src/gpu/dxil/module.rs` - target triple and data layout - function attributes - named metadata - module and validator version declarations - `crates/xcl/src/gpu/dxil/shader.rs` - entry-point metadata - shader feature flags - stage-specific properties - `crates/xcl/src/gpu/dxil/kernel.rs` - compute thread-group and wave information - resource and initialization metadata - `crates/xcl/src/gpu/dxil/compact.rs` - whether compaction preserves all referenced metadata and declarations - container/PSV/signature construction used by the direct emitter - agreement between entry signatures, PSV and declared resources ## Proposed method For each representative shader family: 1. Write the smallest HLSL shader exercising one behavior. 2. Compile it with a pinned DXC version. 3. Dump the resulting DXIL and container metadata. 4. Produce the equivalent shader through XCL’s direct emitter. 5. Compare semantic properties rather than allocation names or instruction order. 6. Validate both outputs with the supported `dxil.dll` versions. 7. Run the XCL output on AMD and NVIDIA where hardware behavior is relevant. Initial shader families: - empty compute shader and thread-group metadata; - raw, structured and typed buffer loads/stores; - static and dynamic resource handles; - descriptor-heap resource access; - wave operations under wave32 and wave64; - derivatives and helper-lane operations; - vertex/pixel signatures and interpolation modes; - mesh shader output and topology metadata; - operations requiring shader feature flags. ## Test infrastructure Add a semantic inspection helper that reports stable properties such as: ```text shader model and stage validator/module versions declared feature flags dx.op names, opcodes and overloads resource bindings and properties entry-point properties thread-group and wave-size metadata input/output signatures PSV resource and signature counts
mokkamokacaffe commented 2026-11-25 23:09:08 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by mokkamokacaffe on 2026-11-25T22:26:31Z.


Notes for AI-assisted contributors

Please treat this issue as an audit and coordination tracker, not as a proposal to replace XCL’s direct-DXIL emitter.

Reference priority

Use these sources in this order:

  1. Microsoft DXIL specification
  2. DXC operation database (hctdb.py)
  3. DXC DXIL headers and implementation
  4. Microsoft dxil.dll validator behavior
  5. LLVM DXIL architecture as an independent architectural reference
  6. Observed AMD and NVIDIA driver behavior

LLVM documentation is useful for comparing lowering stages and invariants, but it is not more authoritative than Microsoft’s specification, DXC or the validator.

Candidate XCL areas

  • crates/xcl/src/gpu/dxil/ops.rs
  • crates/xcl/src/gpu/dxil/module.rs
  • crates/xcl/src/gpu/dxil/shader.rs
  • crates/xcl/src/gpu/dxil/kernel.rs
  • crates/xcl/src/gpu/dxil/compact.rs
  • DXIL container, signature and PSV construction

Start with a small, read-only semantic inspection helper and one minimal compute-shader fixture covering:

  • shader stage and model;
  • validator and module versions;
  • entry-point metadata;
  • thread-group dimensions;
  • declared shader feature flags;
  • used dx.op operations and overloads;
  • resource bindings and annotations.

Avoid byte-for-byte DXIL comparisons. Declaration order, value numbering and instruction ordering may change without changing semantics.

Process

Before implementing a fix:

  1. Check whether an issue or PR already covers the discrepancy.
  2. Identify the exact XCL source file and function responsible.
  3. Produce the smallest equivalent HLSL reference shader.
  4. Record the exact XCL commit, DXC version and dxil.dll version.
  5. Compare semantic properties between the DXC and XCL outputs.
  6. Classify the result as:
    • Verified discrepancy
    • Expected implementation difference
    • Hypothesis requiring validation
  7. Submit each verified discrepancy as a separate, focused PR with regression coverage.

Evidence template

Status: Verified discrepancy / Expected difference / Hypothesis
XCL commit:
Source file and function:
Shader stage and model:
Minimal HLSL:
DXC version:
dxil.dll version:

XCL output:
DXC reference:
Validator result:

AMD result:
NVIDIA result:

Correctness risk:
Driver-compilation impact:
Reproduction commands:

Related issues:
Related PRs:
<!-- greyfinch-sync:ivall/xcl:comment:7176365825 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2541#issuecomment-7176365825). Originally posted by [mokkamokacaffe](https://github.com/mokkamokacaffe) on 2026-11-25T22:26:31Z. --- ## Notes for AI-assisted contributors Please treat this issue as an audit and coordination tracker, not as a proposal to replace XCL’s direct-DXIL emitter. ### Reference priority Use these sources in this order: 1. [Microsoft DXIL specification](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst) 2. [DXC operation database (`hctdb.py`)](https://github.com/microsoft/DirectXShaderCompiler/blob/main/utils/hct/hctdb.py) 3. [DXC DXIL headers](https://github.com/microsoft/DirectXShaderCompiler/tree/main/include/dxc/DXIL) and [implementation](https://github.com/microsoft/DirectXShaderCompiler/tree/main/lib/DXIL) 4. Microsoft `dxil.dll` validator behavior 5. [LLVM DXIL architecture](https://llvm.org/docs/DirectX/DXILArchitecture.html) as an independent architectural reference 6. Observed AMD and NVIDIA driver behavior LLVM documentation is useful for comparing lowering stages and invariants, but it is not more authoritative than Microsoft’s specification, DXC or the validator. ### Candidate XCL areas - `crates/xcl/src/gpu/dxil/ops.rs` - `crates/xcl/src/gpu/dxil/module.rs` - `crates/xcl/src/gpu/dxil/shader.rs` - `crates/xcl/src/gpu/dxil/kernel.rs` - `crates/xcl/src/gpu/dxil/compact.rs` - DXIL container, signature and PSV construction ### Recommended first contribution Start with a small, read-only semantic inspection helper and one minimal compute-shader fixture covering: - shader stage and model; - validator and module versions; - entry-point metadata; - thread-group dimensions; - declared shader feature flags; - used `dx.op` operations and overloads; - resource bindings and annotations. Avoid byte-for-byte DXIL comparisons. Declaration order, value numbering and instruction ordering may change without changing semantics. ### Process Before implementing a fix: 1. Check whether an issue or PR already covers the discrepancy. 2. Identify the exact XCL source file and function responsible. 3. Produce the smallest equivalent HLSL reference shader. 4. Record the exact XCL commit, DXC version and `dxil.dll` version. 5. Compare semantic properties between the DXC and XCL outputs. 6. Classify the result as: - **Verified discrepancy** - **Expected implementation difference** - **Hypothesis requiring validation** 7. Submit each verified discrepancy as a separate, focused PR with regression coverage. ### Evidence template ```text Status: Verified discrepancy / Expected difference / Hypothesis XCL commit: Source file and function: Shader stage and model: Minimal HLSL: DXC version: dxil.dll version: XCL output: DXC reference: Validator result: AMD result: NVIDIA result: Correctness risk: Driver-compilation impact: Reproduction commands: Related issues: Related PRs:
mokkamokacaffe commented 2026-11-27 11:21:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by mokkamokacaffe on 2026-11-27T11:21:23Z.


Status: Hypothesis requiring validation
XCL commit: 9ebc4a21e5442515a8fc6546d903928181dcd1f7
Source file and function:

  • crates/xcl/src/shaders.rs: write_direct_dump
  • crates/xcl/src/gpu/recomp/pso.rs: dump_direct and translated-cache identity checks
  • crates/xcl/src/gpu/recomp/dxc.rs: compile_here, compile_here_in, and store_symbol_bundle
    Shader stage and model: Bounded direct sample contained 4 pixel shaders and 1 vertex shader. An exact shader-model/metadata comparison against DXC remains pending.
    Minimal HLSL: Not produced yet. This update is evidence-enabling infrastructure, not a completed semantic comparison with a minimal DXC reference.
    DXC version: 1.9.2609.5
    dxil.dll version: 1.9.2609.5

XCL output:

  • #2553 gives each direct translation a versioned manifest tied to its guest bytes and emitted DXIL or exact rejection diagnostic.
  • The current-head bounded run sampled 8 records, skipped 3 over the size bound, translated 5, and produced 5 manifests. All 5 passed scripts/verify_shader_dump.py; no individual shader hashes or private artifacts are posted.
  • XCL_SHADER_DEBUG_DIR now preserves the exact stripped DXIL submitted by the HLSL path together with the full PDB returned by that same compilation, generated HLSL, a manifest, and a DXIL-to-symbol-bundle index.
  • Symbol mode rejects cache entries whose matching bundle is missing or incomplete. It compiles programs whole so the submitted DXIL and PDB remain from the same DXC compilation.
  • Exact-head workspace result: 1,461 passed, 0 failed, 47 ignored across 38 completed harness results. The direct-dump stale-manifest regression, exact-DXIL/full-PDB regression, and translated-cache symbol-identity regression each selected exactly one test and passed.

DXC reference:

  • No minimal equivalent HLSL has yet been compiled and semantically compared with the 5 sampled direct-DXIL modules.
  • The new HLSL symbol path provides exact DXIL/PDB/HLSL inputs for that comparison and for driver-crash analysis; it does not imply byte-for-byte equivalence with direct output.

Validator result:

  • The bounded 5-manifest direct sample recorded validation_requested: false, so it is not validator evidence.
  • The exact-head workspace suite passed using DXC/DXIL 1.9.2609.5.
  • Windows Graphics Tools is installed and the D3D12 debug layer activated in the workspace tests. The correct per-subresource-state path produced 0 debug-layer errors; its intentional negative control produced 1.

AMD result:
Not run on AMD hardware.

NVIDIA result:

  • Windows 11 Pro 24H2 build 26100.9711; RTX 4080 SUPER 16 GiB; driver 617.14.
  • Paired 60-second retail-local smokes used clean detached worktrees, separately built release binaries, and SHA-256-identical copies of the same 31,056-file warm cache.
  • Current main 623d02e465a17497a757a4ce867f482b0a6c8f3b: exit 0x0, 1,077 frames/PresentX calls, 0 device removals, 0 crashes.
  • PR 9ebc4a21e5442515a8fc6546d903928181dcd1f7: exit 0x0, 1,084 frames/PresentX calls, 0 device removals, 0 crashes.
  • These were standard comparable smokes; D3D12 debug, DRED, and shader-symbol capture were not enabled in the paired runs.

Correctness risk:
Before #2553, a saved direct-DXIL artifact or later GPU fault could not be reliably tied to the exact guest program and artifact generation that produced it. That weakens discrepancy reports and can misattribute stale or partial files. No metadata/legalization discrepancy has yet been verified by this evidence.

Driver-compilation impact:
Not isolated by this evidence. The paired warm-cache smokes were successful and similar, but one run per revision is not a performance benchmark. Symbol mode is diagnostic-only and intentionally compiles whole programs to keep DXIL/PDB identity exact.

Reproduction commands:

cargo build --workspace
cargo test --workspace --no-fail-fast -- --test-threads=4
cargo test -p xcl --lib shaders::tests::direct_dump_invalidates_an_old_manifest_before_replacing_artifacts -- --exact
cargo test -p xcl --lib gpu::recomp::dxc::cache_tests::shader_debug_bundle_keeps_the_exact_dxil_and_full_pdb -- --exact
cargo test -p xcl --lib gpu::recomp::pso::shader_cache_tests::translations_on_disk_need_the_same_bytes_and_identity -- --exact
python -B -m unittest discover -s scripts -p "test_*.py" -v

xcl shaders "<private-shader-pack>" --direct --sample 8 --seed 1 --threads 1 --dump "<private-output>"
python scripts/verify_shader_dump.py "<private-output>/<individual-manifest>.manifest.json"

.\scripts\smoke.ps1 -Game "<private-retail-title>" -Seconds 60

Related issues: #1269
Related PRs: #2553

<!-- greyfinch-sync:ivall/xcl:comment:7216978030 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2541#issuecomment-7216978030). Originally posted by [mokkamokacaffe](https://github.com/mokkamokacaffe) on 2026-11-27T11:21:23Z. --- Status: Hypothesis requiring validation XCL commit: `9ebc4a21e5442515a8fc6546d903928181dcd1f7` Source file and function: - `crates/xcl/src/shaders.rs`: `write_direct_dump` - `crates/xcl/src/gpu/recomp/pso.rs`: `dump_direct` and translated-cache identity checks - `crates/xcl/src/gpu/recomp/dxc.rs`: `compile_here`, `compile_here_in`, and `store_symbol_bundle` Shader stage and model: Bounded direct sample contained 4 pixel shaders and 1 vertex shader. An exact shader-model/metadata comparison against DXC remains pending. Minimal HLSL: Not produced yet. This update is evidence-enabling infrastructure, not a completed semantic comparison with a minimal DXC reference. DXC version: `1.9.2609.5` dxil.dll version: `1.9.2609.5` XCL output: - #2553 gives each direct translation a versioned manifest tied to its guest bytes and emitted DXIL or exact rejection diagnostic. - The current-head bounded run sampled 8 records, skipped 3 over the size bound, translated 5, and produced 5 manifests. All 5 passed `scripts/verify_shader_dump.py`; no individual shader hashes or private artifacts are posted. - `XCL_SHADER_DEBUG_DIR` now preserves the exact stripped DXIL submitted by the HLSL path together with the full PDB returned by that same compilation, generated HLSL, a manifest, and a DXIL-to-symbol-bundle index. - Symbol mode rejects cache entries whose matching bundle is missing or incomplete. It compiles programs whole so the submitted DXIL and PDB remain from the same DXC compilation. - Exact-head workspace result: 1,461 passed, 0 failed, 47 ignored across 38 completed harness results. The direct-dump stale-manifest regression, exact-DXIL/full-PDB regression, and translated-cache symbol-identity regression each selected exactly one test and passed. DXC reference: - No minimal equivalent HLSL has yet been compiled and semantically compared with the 5 sampled direct-DXIL modules. - The new HLSL symbol path provides exact DXIL/PDB/HLSL inputs for that comparison and for driver-crash analysis; it does not imply byte-for-byte equivalence with direct output. Validator result: - The bounded 5-manifest direct sample recorded `validation_requested: false`, so it is not validator evidence. - The exact-head workspace suite passed using DXC/DXIL `1.9.2609.5`. - Windows Graphics Tools is installed and the D3D12 debug layer activated in the workspace tests. The correct per-subresource-state path produced 0 debug-layer errors; its intentional negative control produced 1. AMD result: Not run on AMD hardware. NVIDIA result: - Windows 11 Pro 24H2 build `26100.9711`; RTX 4080 SUPER 16 GiB; driver `617.14`. - Paired 60-second retail-local smokes used clean detached worktrees, separately built release binaries, and SHA-256-identical copies of the same 31,056-file warm cache. - Current main `623d02e465a17497a757a4ce867f482b0a6c8f3b`: exit `0x0`, 1,077 frames/PresentX calls, 0 device removals, 0 crashes. - PR `9ebc4a21e5442515a8fc6546d903928181dcd1f7`: exit `0x0`, 1,084 frames/PresentX calls, 0 device removals, 0 crashes. - These were standard comparable smokes; D3D12 debug, DRED, and shader-symbol capture were not enabled in the paired runs. Correctness risk: Before #2553, a saved direct-DXIL artifact or later GPU fault could not be reliably tied to the exact guest program and artifact generation that produced it. That weakens discrepancy reports and can misattribute stale or partial files. No metadata/legalization discrepancy has yet been verified by this evidence. Driver-compilation impact: Not isolated by this evidence. The paired warm-cache smokes were successful and similar, but one run per revision is not a performance benchmark. Symbol mode is diagnostic-only and intentionally compiles whole programs to keep DXIL/PDB identity exact. Reproduction commands: ```powershell cargo build --workspace cargo test --workspace --no-fail-fast -- --test-threads=4 cargo test -p xcl --lib shaders::tests::direct_dump_invalidates_an_old_manifest_before_replacing_artifacts -- --exact cargo test -p xcl --lib gpu::recomp::dxc::cache_tests::shader_debug_bundle_keeps_the_exact_dxil_and_full_pdb -- --exact cargo test -p xcl --lib gpu::recomp::pso::shader_cache_tests::translations_on_disk_need_the_same_bytes_and_identity -- --exact python -B -m unittest discover -s scripts -p "test_*.py" -v xcl shaders "<private-shader-pack>" --direct --sample 8 --seed 1 --threads 1 --dump "<private-output>" python scripts/verify_shader_dump.py "<private-output>/<individual-manifest>.manifest.json" .\scripts\smoke.ps1 -Game "<private-retail-title>" -Seconds 60 ``` Related issues: #1269 Related PRs: #2553
Sign in to join this conversation.
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#2531
No description provided.