Skip to main content

Module program

Module program 

Source
Expand description

A Shader’s compiled programs, as a player stores them: per pass, each stage’s program (vertex, fragment, geometry, hull, domain: the stages the pass has) with its variants (each a keyword set, a GPU program type and an entry of the compressed blob) and their parameters (constant buffers with each field’s name and byte offset, texture and sampler bind slots), read from m_ParsedForm; and a variant’s code from the platform’s LZ4-compressed blob. What the bindings mean for a material is the caller’s.

Players store the variants in one of two layouts, told apart by their fields: from 2021.2, m_PlayerSubPrograms (lists of variants, keywords indexing the form’s m_KeywordNames) with m_CommonParameters shared by them; before it, m_SubPrograms (one list, each variant with its hardware tier, its keywords as global and local indices into the pass’s name table, and its own parameters). Struct fields (instancing’s per-draw arrays) are read as StructFields.

The blob of one platform is split into segments (offsets, compressedLengths, decompressedLengths, one entry per segment). Segment 0 starts with the entry table: a count, then per entry its offset, length and segment. An entry of a program holds Unity’s program record: its version, GPU program type, then (from 2016.2) a header the reader skips, keyword strings (empty in current players: the parsed form names them), and the code as a byte array.

Structs§

ColourProperty
A colour property a shader declares (m_ParsedForm.m_PropInfo.m_Props, type 0) and its m_Flags (Unity’s ShaderPropertyFlags).
ConstantBuffer
A constant buffer: its name, the bind slot it is bound to (b<n>; None when no binding names it), its size in bytes, its fields and its struct fields (by offset).
Field
A constant-buffer field: its name, byte offset in the buffer, element type (Unity’s ShaderParamType: 0 float, 1 int, 2 bool, 3 half, 4 short, 5 uint), shape (a vector of columns lanes, or a matrix of rows rows) and array size (0: not an array).
Parameters
The parameters the variants of a program share.
PassProgram
One pass’s program of one stage: its variants and the parameters common to them (empty where each variant has its own).
PassStages
One pass’s programs, a PassProgram per stage (empty where the pass stores none for it).
Segments
Blob segments of a ShaderPrograms already decompressed (ShaderPrograms::code_with).
ShaderPrograms
A Shader’s compiled programs: passes[subshader][pass], and its per-platform blobs.
StructField
A constant-buffer field of a struct type (Unity’s instancing arrays): its name, byte offset, array size (0: not an array), the struct’s size in bytes and its members (offsets within the struct).
TextureParam
A texture parameter: its name, bind slot (t<n>), the sampler slot it samples with (None: none of its own) and dimension (Unity’s TextureDimension: 2 a 2D texture, 3 3D, 4 a cube).
Variant
One compiled variant: the blob entry holding its code, its keywords, its GPU program type (Unity’s ShaderGpuProgramType: 17 a D3D11 pixel program before 2021.2, 18 an SM 5.0 one after) and its shader requirements mask; group is the index of the player sub-program list it is in (from 2021.2) or its hardware tier (before); parameters its own, where the player stores them per variant (before 2021.2), else None: the pass’s.

Enums§

Shape
A field’s shape.
Stage
The stages Unity stores a pass’s programs for (progVertex, progFragment, progGeometry, progHull, progDomain), in that order.

Constants§

D3D11_PROGRAM_TYPES
Unity’s ShaderGpuProgramType of the D3D11 programs: vertex SM 4.0 and 5.0 (15, 16), pixel (17, 18), geometry (19, 20), hull (21), domain (22).
PROPERTY_HDR
Unity’s ShaderPropertyFlags.HDR: a colour property declared [HDR].

Functions§

colour_properties
The colour properties shader r declares, with their flags, in its order.
dxbc
The DXBC container in a D3D11 program record’s code: Unity stores a short header before it. None when the code holds no container (the first DXBC within its first 64 bytes, whole as its own header sizes it).
merge_parameters
A variant’s parameters from the pass’s common ones and its own blob: the buffers by name (fields and structs of both, the blob’s taking precedence; the larger size; the blob’s slot, else the common one), then the textures and samplers of both.
parameter_blob
A variant’s own parameters as a 2021.2 player stores them in the blob entry m_ParameterBlobIndices names: the magic word, a count of the constant buffers plus one, four zero words, then each constant buffer (name, size, its fields, its structs: name, offset, array size, size and fields) and a list of entries, each a name, a kind and a slot: kind 0 a texture (the sampler slot, u32::MAX for none, and a dimension word), kind 1 a constant buffer’s binding (a word, 0), kind 4 a sampler (its packed state; the name is empty). The layout was held to every one of the 3,280 entries of Sledding Game’s level1 shaders (3,272 read to the last byte; the 8 refused hold a kind 2, a structured buffer of the DOTS instancing, whose payload is not read).
texture_defaults
The default each texture property of shader r declares (m_ParsedForm.m_PropInfo.m_Props, type 4: m_DefTexture.m_DefaultName), by property.