Introduction
A .cso file is a compiled shader object: an HLSL
shader compiled ahead of time for Microsoft’s
Direct3D.
Visual Studio writes one per shader when it builds a project, and a program reads the
file and passes its bytes to Direct3D, which hands them to the graphics driver to turn
into code for the particular GPU.
Shaders for shader model 5 and earlier, compiled with fxc, hold DXBC
bytecode. Shader model 6 shaders, compiled with dxc, hold DXIL, a form of
LLVM bitcode. Both use the same container.
Structure
The file starts with the four characters DXBC, a 16-byte checksum of the
rest of the file, a version number, the total size and the number of
chunks, followed by a table of offsets to each chunk. Every chunk has a four-character
name and a size. Typical chunks are RDEF (resources the shader uses),
ISGN and OSGN (input and output signatures),
SHDR or SHEX (DXBC bytecode), DXIL (DXIL
bytecode) and STAT (statistics). All numbers are little-endian. The
header, part table and every part code are on the
container page, which also says what
Microsoft documents and what is proprietary; the layouts of the documented parts are on
parts.
0magicDXBC4 bytes4hash16 bytes20version, total size, chunk count12 bytes32chunk offsets4 bytes each…chunks, each a name, a size and its datavaries
Not described
Known, not yet covered
- Reference: the operand and per-instruction token layouts of the
SHDRandSHEXprograms (in Microsoft’s driver-kit headerd3d11TokenizedProgramFormat.hpp; only the opcode numbers and first tokens are on the parts page); theRDATruntime data part and theRTS0andPSV0field lists (LLVM’s DirectX container document and the DXC headers);DxilVersionencodings. - Viewer: there is no viewer for DirectX containers yet.
Unknown
- Reference: the 16-byte container digest (Microsoft’s proprietary algorithm);
OSG5,PCSG, the shader model 5 additions toRDEF, the fullSTATlayout,PDBIand the last two bytes of each signature element: no source read describes them. The FXC layouts rest on a 2015 reverse-engineering article, not on Microsoft documentation.
Links
Software
- DirectX Shader Compiler – Microsoft’s
dxc, which compiles and disassembles shader model 6 shaders (Windows, Linux) fxc– the older compiler in the Windows SDK, which compiles and disassembles DXBC shaders (Windows)- Visual Studio – Microsoft’s IDE, which writes them when it builds HLSL (Windows)
- RenderDoc – graphics debugger that shows the shaders of a running program (Windows, Linux)