A .cso file is one DirectX shader container, the binary form both of
Microsoft’s HLSL compilers produce: fxc for DXBC bytecode (shader model 5.1
and earlier) and dxc for DXIL (shader model 6 and later). The container is
also called the DXBC format or DXIL container.
What is documented
- Microsoft publishes the container header, the part header, the part FourCCs and the structures of most DXC parts as C++ headers in its open-source DirectXShaderCompiler repository (
DxilContainer.h,DxilConstants.h). - The LLVM project’s DirectX Container document describes the same format, part by part, for LLVM’s own DirectX back end.
- The 16-byte digest in the header is “computed with a proprietary algorithm” (LLVM’s words) and is not documented. Implementations outside Microsoft compute it by reverse engineering; this page does not describe it.
- The FXC-only parts (
RDEF,ISGN,OSGN,OSG5,PCSG,SHDR,SHEX) are named in LLVM’s list, but their inner layouts are not described in the sources read for this page.
Container header
All numbers are little-endian.
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 4 | HeaderFourCC | DXBC (44 58 42 43). |
4 | 16 | Hash | Digest of the whole container, written by the validator. Proprietary algorithm; DXC also defines a preview “bypass” value made of bytes all equal to 2. |
20 | 2 | Version.Major | Container version, currently 1. |
22 | 2 | Version.Minor | Currently 0. |
24 | 4 | ContainerSizeInBytes | Size of the whole container, from the start of the header. At most 0x80000000. |
28 | 4 | PartCount | Number of parts. |
32 | 4 × PartCount | PartOffset[] | Offset of each part’s header from the start of the container. |
Part header
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 4 | PartFourCC | Four-character code naming the part. |
4 | 4 | PartSize | Number of bytes of part data that follow. |
8 | PartSize | data | The part’s contents; see parts. |
The format does not require parts to be 32-bit aligned; LLVM’s writer aligns them and
its reader does not rely on it. PRIV is the one part whose size need not be
a multiple of four; it must be the last part, and there may be only one.
Part FourCCs
| FourCC | DXC name | Contents | Written by |
|---|---|---|---|
DXIL | DFCC_DXIL | DXIL program: program header and LLVM bitcode. | DXC |
ILDB | DFCC_ShaderDebugInfoDXIL | DXIL with debug information, not stripped. | DXC |
ILDN | DFCC_ShaderDebugName | Name of the debug file. | DXC |
HASH | DFCC_ShaderHash | Shader MD5 hash and flags. | DXC |
ISG1 | DFCC_InputSignature | Input signature. | shader model 5.1 and later |
OSG1 | DFCC_OutputSignature | Output signature. | shader model 5.1 and later |
PSG1 | DFCC_PatchConstantSignature | Patch-constant signature. | shader model 6 and later |
PSV0 | DFCC_PipelineStateValidation | Pipeline state validation data. | — |
RDAT | DFCC_RuntimeData | Runtime data. | DXC |
RTS0 | DFCC_RootSignature | Root signature. | — |
SFI0 | DFCC_FeatureInfo | 64-bit mask of optional features the shader needs. | — |
STAT | DFCC_ShaderStatistics | Shader statistics. | DXC |
PRIV | DFCC_PrivateData | Opaque private data, such as an embedded PDB. | DXC |
SRCI | DFCC_ShaderSourceInfo | Shader source information. | DXC |
PDBI | DFCC_ShaderPDBInfo | PDB information. | DXC |
VERS | DFCC_CompilerVersion | Compiler version. | DXC |
RDEF | DFCC_ResourceDef | Resource definitions. | FXC |
ISGN | — | Input signature. | FXC, shader model 4 and earlier |
OSGN | — | Output signature. | FXC, shader model 4 and earlier |
OSG5 | — | Output signature. | FXC, shader model 5 |
PCSG | — | Patch-constant signature. | FXC, shader model 5.1 and earlier |
SHDR | — | DXBC bytecode. | FXC |
SHEX | — | DXBC bytecode. | FXC |
DXBC itself is also the FourCC of the container (DFCC_Container);
LLVM’s list also names a DXBC part holding DXBC bytecode. “—” in the last
column means the sources do not tie the part to one compiler.
Worked example
Offset Bytes Field
0 44 58 42 43 "DXBC"
4 xx × 16 digest
20 01 00 00 00 version 1.0
24 (4 bytes) total size
28 03 00 00 00 3 parts
32 2C 00 00 00 part 0 at 0x2C
36 (4 bytes) part 1 offset
40 (4 bytes) part 2 offset
44 53 46 49 30 08 00 00 00 part 0: "SFI0", 8 bytes of data
52 (8 bytes) the 64-bit feature mask
…
Sources
- DxilContainer.h – Microsoft’s DirectXShaderCompiler:
DxilContainerHeader,DxilPartHeader, the version and size constants and the FourCC list - DirectX Container – LLVM documentation: the header, part alignment, the full part list with FXC/DXC markings, and the statement that the digest is proprietary