Merge branch 'ue-workgroups'
This commit is contained in:
commit
76a41b790b
18
README.md
18
README.md
|
|
@ -7,7 +7,7 @@
|
|||
</p>
|
||||
|
||||
<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 align="center">
|
||||
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
---
|
||||
|
||||
zdxc is an HLSL 2021 compiler written from scratch in Zig. It emits DXIL and
|
||||
SPIR-V, supports DXC-style command lines, and provides a DXC-compatible COM
|
||||
interface for existing engine integrations.
|
||||
zdxc is an HLSL compiler written from scratch in Zig. It supports HLSL 2018
|
||||
and 2021, emits DXIL and SPIR-V, supports DXC-style command lines, and
|
||||
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,
|
||||
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
|
||||
|
||||
zdxc is **alpha software**, focused on HLSL 2021 (`-HV 2021`). DXC compatibility
|
||||
is still being developed; not every DXC interface or feature is implemented.
|
||||
zdxc is **alpha software**. HLSL 2021 is the default; use `-HV 2018` for
|
||||
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 current interface coverage.
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,10 @@ no `dxil.dll`: zdxc signs DXIL itself.
|
|||
|
||||
| Class | Interfaces |
|
||||
|---|---|
|
||||
| `CLSID_DxcCompiler` | `IDxcCompiler3` (`Compile`), `IDxcVersionInfo` (reports 1.11) |
|
||||
| `CLSID_DxcUtils` (also reached as `CLSID_DxcLibrary`) | `IDxcUtils`: blob creation, `LoadFile`, `CreateDefaultIncludeHandler`, `GetBlobAsUtf8` / `GetBlobAsWide`, `GetDxilContainerPart` |
|
||||
| `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`, `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:
|
||||
|
||||
|
|
@ -44,13 +46,21 @@ no `dxil.dll`: zdxc signs DXIL itself.
|
|||
|
||||
Classes and methods that are not implemented return `REGDB_E_CLASSNOTREG`
|
||||
or `E_NOTIMPL`. These include:
|
||||
- the legacy `IDxcCompiler` and `IDxcCompiler2` interfaces;
|
||||
|
||||
- `Disassemble`;
|
||||
- `CreateReflection`, `BuildArguments` and `GetPDBContents`;
|
||||
- the validator, linker, container and PDB classes.
|
||||
- `BuildArguments` and `GetPDBContents`;
|
||||
- the validator, linker, and PDB classes.
|
||||
|
||||
The result has no `DXC_OUT_REFLECTION` output (the reflection container
|
||||
that `CreateReflection` reads).
|
||||
DXIL results include `DXC_OUT_REFLECTION`. `CreateReflection` reads zdxc
|
||||
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
|
||||
version.
|
||||
Language support is zdxc's own. HLSL 2021 is the default; pass `-HV 2018`
|
||||
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`.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ order: 1
|
|||
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
|
||||
four interfaces:
|
||||
|
||||
|
|
@ -15,5 +15,14 @@ four interfaces:
|
|||
| `zdxc` Zig module | Direct access to the compiler from a Zig build. |
|
||||
| `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.
|
||||
|
|
|
|||
|
|
@ -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`. |
|
||||
| `-E <name>` | Shader entry point. |
|
||||
| `-HV <version>` | HLSL language version: `2021` (default), `2018`, `2017`, or `2016`. |
|
||||
| `-D <name[=value]>` | Define a preprocessor macro. |
|
||||
| `-I <directory>` | Add an include search directory. |
|
||||
| `-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
|
||||
`-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 follow dxc's command-line format. Exit status is 0 for success,
|
||||
|
|
|
|||
|
|
@ -28,8 +28,10 @@ no `dxil.dll`: zdxc signs DXIL itself.
|
|||
|
||||
| Class | Interfaces |
|
||||
|---|---|
|
||||
| `CLSID_DxcCompiler` | `IDxcCompiler3` (`Compile`), `IDxcVersionInfo` (reports 1.11) |
|
||||
| `CLSID_DxcUtils` (also reached as `CLSID_DxcLibrary`) | `IDxcUtils`: blob creation, `LoadFile`, `CreateDefaultIncludeHandler`, `GetBlobAsUtf8` / `GetBlobAsWide`, `GetDxilContainerPart` |
|
||||
| `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`, `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:
|
||||
|
||||
|
|
@ -48,13 +50,21 @@ no `dxil.dll`: zdxc signs DXIL itself.
|
|||
|
||||
Classes and methods that are not implemented return `REGDB_E_CLASSNOTREG`
|
||||
or `E_NOTIMPL`. These include:
|
||||
- the legacy `IDxcCompiler` and `IDxcCompiler2` interfaces;
|
||||
|
||||
- `Disassemble`;
|
||||
- `CreateReflection`, `BuildArguments` and `GetPDBContents`;
|
||||
- the validator, linker, container and PDB classes.
|
||||
- `BuildArguments` and `GetPDBContents`;
|
||||
- the validator, linker, and PDB classes.
|
||||
|
||||
The result has no `DXC_OUT_REFLECTION` output (the reflection container
|
||||
that `CreateReflection` reads).
|
||||
DXIL results include `DXC_OUT_REFLECTION`. `CreateReflection` reads zdxc
|
||||
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
|
||||
version.
|
||||
Language support is zdxc's own. HLSL 2021 is the default; pass `-HV 2018`
|
||||
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`.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
* default) or dynamically (-Dlinkage=dynamic); it needs nothing besides
|
||||
|
|
|
|||
|
|
@ -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 options = @import("options.zig");
|
||||
|
|
|
|||
Loading…
Reference in New Issue