The contents of the parts of a shader
container, as Microsoft’s DirectXShaderCompiler headers and the LLVM project’s
DirectX Container document describe them. All numbers are little-endian. Parts written
only by the older fxc compiler (RDEF, ISGN,
OSGN, OSG5, PCSG, SHDR,
SHEX) and the STAT, RDAT and PDBI
parts are not described in those sources and are not covered here.
DXIL and ILDB: program header
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 4 | ProgramVersion | Shader kind in bits 16–31, shader model major version in bits 4–7, minor in bits 0–3. |
4 | 4 | SizeInUint32 | Size of the program in 32-bit words, including this header. |
8 | 4 | DxilMagic | 0x4C495844, the text DXIL. |
12 | 4 | DxilVersion | DXIL version. |
16 | 4 | BitcodeOffset | Offset of the LLVM bitcode, counted from the start of DxilMagic (the bitcode header). |
20 | 4 | BitcodeSize | Size of the LLVM bitcode. |
The bitcode is an LLVM 3.7 IR module (see LLVM
bitcode). ILDB has the same layout but keeps debug information, which
the stripped DXIL part leaves out.
| Shader kind | Value | Shader kind | Value |
|---|---|---|---|
| Pixel | 0 | Intersection | 8 |
| Vertex | 1 | AnyHit | 9 |
| Geometry | 2 | ClosestHit | 10 |
| Hull | 3 | Miss | 11 |
| Domain | 4 | Callable | 12 |
| Compute | 5 | Mesh | 13 |
| Library | 6 | Amplification | 14 |
| RayGeneration | 7 | Node | 15 |
Value 16 is Invalid. For example a shader model 6.5 compute shader has
ProgramVersion 0x00050065.
ISG1, OSG1 and PSG1: signatures
A signature part starts with a header, then an array of 32-byte elements, then a string table holding the semantic names.
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 4 | ParamCount | Number of elements. |
4 | 4 | ParamOffset | Offset of the first element from the start of the part data. |
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 4 | Stream | Stream index; elements appear in non-decreasing stream order. |
4 | 4 | SemanticName | Offset of the name string from the start of the part data; 0 means no name. |
8 | 4 | SemanticIndex | Semantic index. |
12 | 4 | SystemValue | System-value semantic; see below. |
16 | 4 | CompType | Component type; see below. |
20 | 4 | Register | Register (row) index. |
24 | 1 | Mask | Components (columns) the element uses. |
25 | 1 | NeverWrites_Mask / AlwaysReads_Mask | For an output signature, components the shader never writes; for an input signature, components it always reads. |
26 | 2 | Pad | Padding. |
28 | 4 | MinPrecision | Minimum precision; see below. |
| SystemValue | Name | SystemValue | Name |
|---|---|---|---|
| 0 | Undefined | 14 | FinalTriInsideTessfactor |
| 1 | Position | 15 | FinalLineDetailTessfactor |
| 2 | ClipDistance | 16 | FinalLineDensityTessfactor |
| 3 | CullDistance | 23 | Barycentrics |
| 4 | RenderTargetArrayIndex | 24 | ShadingRate |
| 5 | ViewPortArrayIndex | 25 | CullPrimitive |
| 6 | VertexID | 64 | Target |
| 7 | PrimitiveID | 65 | Depth |
| 8 | InstanceID | 66 | Coverage |
| 9 | IsFrontFace | 67 | DepthGE |
| 10 | SampleIndex | 68 | DepthLE |
| 11 | FinalQuadEdgeTessfactor | 69 | StencilRef |
| 12 | FinalQuadInsideTessfactor | 70 | InnerCoverage |
| 13 | FinalTriEdgeTessfactor |
The header file notes that these values correspond to Direct3D’s
D3D_NAME and D3D10_SB_NAME codes.
| CompType | Name | MinPrecision | Name |
|---|---|---|---|
| 0 | Unknown | 0x00 | Default |
| 1 | UInt32 | 0x01 | Float16 |
| 2 | SInt32 | 0x02 | Float2_8 |
| 3 | Float32 | 0x03 | Reserved |
| 4 | UInt16 | 0x04 | SInt16 |
| 5 | SInt16 | 0x05 | UInt16 |
| 6 | Float16 | 0xF0 | Any16 |
| 7 | UInt64 | 0xF1 | Any10 |
| 8 | SInt64 | ||
| 9 | Float64 |
SFI0: feature flags
One 64-bit mask of optional features the shader needs.
| Bit value | Name | Since |
|---|---|---|
0x0001 | Doubles | |
0x0002 | ComputeShadersPlusRawAndStructuredBuffersViaShader4X | |
0x0004 | UAVsAtEveryStage | |
0x0008 | 64UAVs | |
0x0010 | MinimumPrecision | |
0x0020 | 11_1_DoubleExtensions | |
0x0040 | 11_1_ShaderExtensions | |
0x0080 | LEVEL9ComparisonFiltering | |
0x0100 | TiledResources | |
0x0200 | StencilRef | |
0x0400 | InnerCoverage | |
0x0800 | TypedUAVLoadAdditionalFormats | |
0x1000 | ROVs | |
0x2000 | ViewportAndRTArrayIndexFromAnyShaderFeedingRasterizer | |
0x4000 | WaveOps | |
0x8000 | Int64Ops | |
0x10000 | ViewID | SM 6.1 |
0x20000 | Barycentrics | SM 6.1 |
0x40000 | NativeLowPrecision | SM 6.2 |
0x80000 | ShadingRate | SM 6.4 |
0x100000 | Raytracing_Tier_1_1 | SM 6.5 |
0x200000 | SamplerFeedback | SM 6.5 |
0x400000 | AtomicInt64OnTypedResource | SM 6.6 |
0x800000 | AtomicInt64OnGroupShared | SM 6.6 |
0x1000000 | DerivativesInMeshAndAmpShaders | SM 6.6 |
0x2000000 | ResourceDescriptorHeapIndexing | SM 6.6 |
0x4000000 | SamplerDescriptorHeapIndexing | SM 6.6 |
0x8000000 | Reserved | experimental SM 6.9 |
0x10000000 | AtomicInt64OnHeapResource | SM 6.6 |
0x20000000 | AdvancedTextureOps | SM 6.7 |
0x40000000 | WriteableMSAATextures | SM 6.7 |
0x80000000 | SampleCmpGradientOrBias | SM 6.8 |
0x100000000 | ExtendedCommandInfo | SM 6.8 |
0x200000000 | LinearAlgebra | SM 6.10 |
These are the container’s feature bits; the DXIL module itself carries a separate
64-bit “shader flags” value in its metadata, documented in DXC’s
DXIL.rst.
HASH, ILDN and VERS
| Part | Offset | Size | Field | Meaning |
|---|---|---|---|---|
HASH | 0 | 4 | Flags | 0 none; 1 IncludesSource: the hash takes source information into account (-Zss). |
4 | 16 | Digest | MD5 hash of the shader. | |
ILDN | 0 | 2 | Flags | Reserved, zero. |
2 | 2 | NameLength | Length of the name, without its NUL. | |
4 | NameLength + 1 | name | UTF-8 name of the debug file (by default <MD5>.pdb) and a NUL, then 0–3 zero bytes to a 4-byte boundary. | |
VERS | 0 | 2 | Major | Compiler major version. |
2 | 2 | Minor | Compiler minor version. | |
4 | 4 | Flags | 0 default, 1 debug, 2 internal. | |
8 | 4 | CommitCount | LLVM always writes 0. | |
12 | 4 | ContentSizeInBytes | Size of the strings that follow. | |
16 | — | strings | The commit SHA and a custom version string, each ending in NUL. |
SRCI: source information
A header (a 32-bit aligned size, 16-bit flags and a 16-bit section count, which must be 3), then three sections, each with its own header and 4-byte aligned entries:
| Section type | Contents |
|---|---|
| 0 | Source contents; may be compressed with zlib (compression type 1). |
| 1 | Source file names. |
| 2 | Compiler arguments, as NUL-terminated name and value string pairs. |
RTS0: root signature
| Structure | Size | Fields |
|---|---|---|
| Header | 24 bytes | Six 32-bit values: Version, NumParameters, ParametersOffset, NumStaticSamplers, StaticSamplerOffset, Flags. |
| Parameter header | 12 bytes | ParameterType, ShaderVisibility, ParameterOffset. |
| Root constants | 12 bytes | — |
| Root descriptor | 8 bytes (version 1.0), 12 bytes (1.1, adds flags) | — |
| Descriptor range | 20 bytes (1.0), 24 bytes (1.1) | — |
| Static sampler | 52 bytes | — |
The field lists of the smaller structures and the code values they use are defined in
LLVM’s DXContainerConstants.def and Direct3D 12’s root signature
documentation, which were not among the sources read for this page.
PSV0: pipeline state validation
A versioned set of structures, told apart by their encoded size rather than a version
number. In order: a RuntimeInfo structure; the resource bindings (a count,
then the element size when the count is not zero); the signature elements (a string
table, an index table and lists per kind); and mask vectors, which pack 8 elements into
each 32-bit word starting from the least significant bit. Output, patch-constant and
input-to-output dependency tables follow depending on the shader stage and whether it
uses the view ID. The inner layouts are not given in the sources read.
PRIV
Opaque bytes, such as an embedded PDB. It must be the last part, there may be only one, and its size need not be a multiple of four.
Sources
- DxilContainer.h – Microsoft: program and bitcode headers, signature structures and their enums,
HASHandILDNstructures, version helpers - DxilConstants.h – Microsoft:
ShaderFeatureInfoflags and theShaderKindvalues - DirectX Container – LLVM:
VERS,SRCI,RTS0,PSV0,PRIVand the bitcode version - DXIL.rst – Microsoft: the DXIL module’s own shader flags