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

Open
opened 2026-11-26 05:33:19 +00:00 by github-bot · 1 comment
Owner

@⁠mokkamokacaffe on GitHub · 2026-11-25 22:24 UTC · original

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
**@⁠mokkamokacaffe** on GitHub · 2026-11-25 22:24 UTC · [original](https://github.com/xcl-dev/xcl/issues/2541) ## 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:33:19 +00:00
Author
Owner

@⁠mokkamokacaffe on GitHub · 2026-11-25 22:26 UTC · original

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:
**@⁠mokkamokacaffe** on GitHub · 2026-11-25 22:26 UTC · [original](https://github.com/xcl-dev/xcl/issues/2541#issuecomment-7176365825) ## 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:
This discussion has been locked. Commenting is limited to contributors.
No description provided.