documentation updates

This commit is contained in:
Peterino2 2026-11-04 08:51:40 -07:00
parent eeb5a3fcd1
commit 0ba9de16fa
7 changed files with 127 additions and 28 deletions

View File

@ -7,7 +7,7 @@
</p> </p>
<p align="center"> <p align="center">
HLSL 2021 → DXIL / SPIR-V · Written in Zig · No LLVM dependency HLSL 2018 / 2021 → DXIL / SPIR-V · Written in Zig · No LLVM dependency
</p> </p>
<p align="center"> <p align="center">
@ -19,9 +19,9 @@
--- ---
zdxc is an HLSL 2021 compiler written from scratch in Zig. It emits DXIL and zdxc is an HLSL compiler written from scratch in Zig. It supports HLSL 2018
SPIR-V, supports DXC-style command lines, and provides a DXC-compatible COM and 2021, emits DXIL and SPIR-V, supports DXC-style command lines, and
interface for existing engine integrations. provides a DXC-compatible COM interface for existing engine integrations.
Use it as a development drop-in replacement for DXC, link its small C API directly, Use it as a development drop-in replacement for DXC, link its small C API directly,
or import it as a Zig module. The compiler has no package dependencies and or import it as a Zig module. The compiler has no package dependencies and
@ -77,8 +77,14 @@ Unreal Engine 5.8's editor compiled its 11,156 startup shaders **4.3× faster**.
## Status ## Status
zdxc is **alpha software**, focused on HLSL 2021 (`-HV 2021`). DXC compatibility zdxc is **alpha software**. HLSL 2021 is the default; use `-HV 2018` for
is still being developed; not every DXC interface or feature is implemented. HLSL 2018 shaders. DXIL supports work graph node shaders in `lib_6_8`
libraries, SM 6.8 `Barrier()`, and `[WaveSize]` metadata. Work graph nodes
are not supported by the SPIR-V backend. See the
[command-line guide](docs/manual/03-command-line.md) for examples.
DXC compatibility is still being developed; not every interface or feature
is implemented.
The [drop-in manual](https://zdxc.org/manual.html#section-dxc-drop-in) documents The [drop-in manual](https://zdxc.org/manual.html#section-dxc-drop-in) documents
the current interface coverage. the current interface coverage.

View File

@ -24,8 +24,10 @@ no `dxil.dll`: zdxc signs DXIL itself.
| Class | Interfaces | | Class | Interfaces |
|---|---| |---|---|
| `CLSID_DxcCompiler` | `IDxcCompiler3` (`Compile`), `IDxcVersionInfo` (reports 1.11) | | `CLSID_DxcCompiler` | `IDxcCompiler3` (`Compile`), `IDxcCompiler` (`Compile`, `Preprocess`), `IDxcCompiler2` (`CompileWithDebug`), `IDxcVersionInfo` (reports 1.11) |
| `CLSID_DxcUtils` (also reached as `CLSID_DxcLibrary`) | `IDxcUtils`: blob creation, `LoadFile`, `CreateDefaultIncludeHandler`, `GetBlobAsUtf8` / `GetBlobAsWide`, `GetDxilContainerPart` | | `CLSID_DxcUtils` (also reached as `CLSID_DxcLibrary`) | `IDxcUtils`: blob creation, `LoadFile`, `CreateDefaultIncludeHandler`, `GetBlobAsUtf8` / `GetBlobAsWide`, `GetDxilContainerPart`, `CreateReflection` |
| `CLSID_DxcContainerReflection` | `IDxcContainerReflection`: load and inspect container parts, `GetPartReflection` |
| `CLSID_DxcContainerBuilder` | `IDxcContainerBuilder`: load, add/remove parts, serialize a signed container |
`Compile` takes the same arguments as the command line and follows DXC: `Compile` takes the same arguments as the command line and follows DXC:
@ -44,13 +46,21 @@ no `dxil.dll`: zdxc signs DXIL itself.
Classes and methods that are not implemented return `REGDB_E_CLASSNOTREG` Classes and methods that are not implemented return `REGDB_E_CLASSNOTREG`
or `E_NOTIMPL`. These include: or `E_NOTIMPL`. These include:
- the legacy `IDxcCompiler` and `IDxcCompiler2` interfaces;
- `Disassemble`; - `Disassemble`;
- `CreateReflection`, `BuildArguments` and `GetPDBContents`; - `BuildArguments` and `GetPDBContents`;
- the validator, linker, container and PDB classes. - the validator, linker, and PDB classes.
The result has no `DXC_OUT_REFLECTION` output (the reflection container DXIL results include `DXC_OUT_REFLECTION`. `CreateReflection` reads zdxc
that `CreateReflection` reads). reflection blobs and exposes `ID3D12ShaderReflection` or
`ID3D12LibraryReflection`. `CompileWithDebug` compiles the shader but returns
no separate debug name or blob; zdxc does not write PDBs.
Language support is zdxc's own: HLSL 2021, with `-HV 2021` as the only Language support is zdxc's own. HLSL 2021 is the default; pass `-HV 2018`
version. for HLSL 2018's component-wise `&&`, `||`, and numeric `?:`, which evaluate
both operands or branches. `-HV 2016` and `-HV 2017` use the same legacy
operator semantics. These options apply to both executable and library calls.
DXIL supports work graph node shaders compiled as `lib_6_8`, including
node input/output records and the `broadcasting`, `coalescing`, and `thread`
launch modes. Work graph nodes are not supported with `-spirv`.

View File

@ -4,7 +4,7 @@ order: 1
title: Introduction title: Introduction
--- ---
zdxc is a from-scratch HLSL 2021 compiler written in Zig. It emits DXIL and zdxc is a from-scratch HLSL compiler written in Zig. It emits DXIL and
SPIR-V and has no package dependencies. The same compiler is available through SPIR-V and has no package dependencies. The same compiler is available through
four interfaces: four interfaces:
@ -15,5 +15,14 @@ four interfaces:
| `zdxc` Zig module | Direct access to the compiler from a Zig build. | | `zdxc` Zig module | Direct access to the compiler from a Zig build. |
| `dxc` / `dxcompiler` | Drop-in names and entry points for existing DXC clients. | | `dxc` / `dxcompiler` | Drop-in names and entry points for existing DXC clients. |
The source language is HLSL 2021; `-HV 2021` is the only language version. HLSL 2021 is the default language version. Select HLSL 2018 with `-HV 2018`;
`-HV 2016` and `-HV 2017` are also accepted with the same legacy operator
semantics. The language version is independent of the target shader model.
Compute shaders support thread groups, `groupshared` storage, and group
barriers. The DXIL backend also supports work graph node shaders in
`lib_6_8` libraries, SM 6.8 `Barrier()`, and `[WaveSize]` metadata. Work graph
nodes are not supported in SPIR-V. See the
[command-line guide](03-command-line.md) for language and work graph examples.
DXIL output is signed by zdxc itself, so no separate `dxil` library is needed. DXIL output is signed by zdxc itself, so no separate `dxil` library is needed.

View File

@ -11,6 +11,7 @@ a file or, through the library interfaces, from memory.
| --- | --- | | --- | --- |
| `-T <profile>` | Target profile, such as `vs_6_0`, `ps_6_0`, or `cs_6_0`. | | `-T <profile>` | Target profile, such as `vs_6_0`, `ps_6_0`, or `cs_6_0`. |
| `-E <name>` | Shader entry point. | | `-E <name>` | Shader entry point. |
| `-HV <version>` | HLSL language version: `2021` (default), `2018`, `2017`, or `2016`. |
| `-D <name[=value]>` | Define a preprocessor macro. | | `-D <name[=value]>` | Define a preprocessor macro. |
| `-I <directory>` | Add an include search directory. | | `-I <directory>` | Add an include search directory. |
| `-Fo <file>` | Write the object to a file. | | `-Fo <file>` | Write the object to a file. |
@ -25,6 +26,69 @@ a file or, through the library interfaces, from memory.
DXIL is the default backend. Add `-spirv` for SPIR-V, with the `-fvk-*` and DXIL is the default backend. Add `-spirv` for SPIR-V, with the `-fvk-*` and
`-fspv-*` options controlling Vulkan bindings, layout, and target environment. `-fspv-*` options controlling Vulkan bindings, layout, and target environment.
## HLSL language versions
Use `-HV 2018` when compiling shaders written for HLSL 2018:
```sh
zdxc -HV 2018 -T ps_6_0 -E main shader.hlsl -Fo shader.dxil
zdxc -HV 2018 -spirv -T ps_6_0 -E main shader.hlsl -Fo shader.spv
```
The default is `-HV 2021`. In the legacy modes (`2016`, `2017`, and `2018`),
`&&` and `||` evaluate both operands and operate component-wise on vectors;
numeric `?:` evaluates both branches and permits a vector condition to
select per component. In 2021 mode, logical operands and the conditional
test are scalar, and evaluation short-circuits. Code that relies on an
unevaluated expression to avoid side effects needs particular care when
switching to a legacy mode.
The preprocessor macro `__HLSL_VERSION` reflects the selected version.
`-HV` selects language semantics; `-T` independently selects the shader
stage and shader model. These options also work in batch jobs and through
the C API and DXC drop-in.
## Compute thread groups and work graphs
Compute shaders use `[numthreads(x, y, z)]` to declare their thread group
size, `groupshared` for group-local storage, and intrinsics such as
`GroupMemoryBarrierWithGroupSync()` for synchronization. Compile them with
a compute profile, for example `-T cs_6_0 -E main`, for DXIL or SPIR-V.
For DXIL, `[WaveSize]` is emitted in entry-point and runtime metadata,
including the minimum, maximum, and preferred sizes for SM 6.8 wave-size
ranges. SM 6.8's `Barrier()` supports memory flags, UAVs, and node records.
Work graphs use node shaders in a shader library. Compile with `-T lib_6_8`
and mark each node with `[Shader("node")]` and its `[NodeLaunch]` mode;
there is no single `-E` entry point for the library. The supported launch
modes are `broadcasting`, `coalescing`, and `thread`. Node input/output
records, record allocation and completion, dispatch grids, node IDs, and
`GetRemainingRecursionLevels()` are supported by the DXIL backend.
For example, save this broadcasting node as `node.hlsl`:
```hlsl
RWStructuredBuffer<uint> values : register(u0);
[Shader("node")]
[NodeLaunch("broadcasting")]
[NodeDispatchGrid(1, 1, 1)]
[numthreads(64, 1, 1)]
void Fill(uint3 id : SV_DispatchThreadID)
{
values[id.x] = id.x;
}
```
```sh
zdxc -T lib_6_8 node.hlsl -Fo node.dxil
```
This produces a node shader library for a host application's work graph.
Work graph nodes are DXIL-only; compiling them with `-spirv` reports an
unsupported-feature error.
## Diagnostics and exit status ## Diagnostics and exit status
Diagnostics follow dxc's command-line format. Exit status is 0 for success, Diagnostics follow dxc's command-line format. Exit status is 0 for success,

View File

@ -28,8 +28,10 @@ no `dxil.dll`: zdxc signs DXIL itself.
| Class | Interfaces | | Class | Interfaces |
|---|---| |---|---|
| `CLSID_DxcCompiler` | `IDxcCompiler3` (`Compile`), `IDxcVersionInfo` (reports 1.11) | | `CLSID_DxcCompiler` | `IDxcCompiler3` (`Compile`), `IDxcCompiler` (`Compile`, `Preprocess`), `IDxcCompiler2` (`CompileWithDebug`), `IDxcVersionInfo` (reports 1.11) |
| `CLSID_DxcUtils` (also reached as `CLSID_DxcLibrary`) | `IDxcUtils`: blob creation, `LoadFile`, `CreateDefaultIncludeHandler`, `GetBlobAsUtf8` / `GetBlobAsWide`, `GetDxilContainerPart` | | `CLSID_DxcUtils` (also reached as `CLSID_DxcLibrary`) | `IDxcUtils`: blob creation, `LoadFile`, `CreateDefaultIncludeHandler`, `GetBlobAsUtf8` / `GetBlobAsWide`, `GetDxilContainerPart`, `CreateReflection` |
| `CLSID_DxcContainerReflection` | `IDxcContainerReflection`: load and inspect container parts, `GetPartReflection` |
| `CLSID_DxcContainerBuilder` | `IDxcContainerBuilder`: load, add/remove parts, serialize a signed container |
`Compile` takes the same arguments as the command line and follows DXC: `Compile` takes the same arguments as the command line and follows DXC:
@ -48,13 +50,21 @@ no `dxil.dll`: zdxc signs DXIL itself.
Classes and methods that are not implemented return `REGDB_E_CLASSNOTREG` Classes and methods that are not implemented return `REGDB_E_CLASSNOTREG`
or `E_NOTIMPL`. These include: or `E_NOTIMPL`. These include:
- the legacy `IDxcCompiler` and `IDxcCompiler2` interfaces;
- `Disassemble`; - `Disassemble`;
- `CreateReflection`, `BuildArguments` and `GetPDBContents`; - `BuildArguments` and `GetPDBContents`;
- the validator, linker, container and PDB classes. - the validator, linker, and PDB classes.
The result has no `DXC_OUT_REFLECTION` output (the reflection container DXIL results include `DXC_OUT_REFLECTION`. `CreateReflection` reads zdxc
that `CreateReflection` reads). reflection blobs and exposes `ID3D12ShaderReflection` or
`ID3D12LibraryReflection`. `CompileWithDebug` compiles the shader but returns
no separate debug name or blob; zdxc does not write PDBs.
Language support is zdxc's own: HLSL 2021, with `-HV 2021` as the only Language support is zdxc's own. HLSL 2021 is the default; pass `-HV 2018`
version. for HLSL 2018's component-wise `&&`, `||`, and numeric `?:`, which evaluate
both operands or branches. `-HV 2016` and `-HV 2017` use the same legacy
operator semantics. These options apply to both executable and library calls.
DXIL supports work graph node shaders compiled as `lib_6_8`, including
node input/output records and the `broadcasting`, `coalescing`, and `thread`
launch modes. Work graph nodes are not supported with `-spirv`.

View File

@ -1,5 +1,5 @@
/* /*
* zdxc: an HLSL 2021 to DXIL and SPIR-V compiler. * zdxc: an HLSL 2018 / 2021 to DXIL and SPIR-V compiler.
* *
* The C API. Link libzdxc statically (zig build -Dlinkage=static, the * The C API. Link libzdxc statically (zig build -Dlinkage=static, the
* default) or dynamically (-Dlinkage=dynamic); it needs nothing besides * default) or dynamically (-Dlinkage=dynamic); it needs nothing besides

View File

@ -1,4 +1,4 @@
//! zdxc: an HLSL 2021 compiler targeting DXIL and SPIR-V. //! zdxc: an HLSL 2018 / 2021 compiler targeting DXIL and SPIR-V.
pub const diag = @import("diag.zig"); pub const diag = @import("diag.zig");
pub const options = @import("options.zig"); pub const options = @import("options.zig");