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§
- Colour
Property - A colour property a shader declares (
m_ParsedForm.m_PropInfo.m_Props, type 0) and itsm_Flags(Unity’sShaderPropertyFlags). - Constant
Buffer - A constant buffer: its name, the bind slot it is bound to (
b<n>;Nonewhen 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 ofcolumnslanes, or a matrix ofrowsrows) and array size (0: not an array). - Parameters
- The parameters the variants of a program share.
- Pass
Program - One pass’s program of one stage: its variants and the parameters common to them (empty where each variant has its own).
- Pass
Stages - One pass’s programs, a
PassProgramper stage (empty where the pass stores none for it). - Segments
- Blob segments of a
ShaderProgramsalready decompressed (ShaderPrograms::code_with). - Shader
Programs - A Shader’s compiled programs:
passes[subshader][pass], and its per-platform blobs. - Struct
Field - 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).
- Texture
Param - A texture parameter: its name, bind slot (
t<n>), the sampler slot it samples with (None: none of its own) and dimension (Unity’sTextureDimension: 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;groupis the index of the player sub-program list it is in (from 2021.2) or its hardware tier (before);parametersits own, where the player stores them per variant (before 2021.2), elseNone: 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
ShaderGpuProgramTypeof 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
rdeclares, with their flags, in its order. - dxbc
- The DXBC container in a D3D11 program record’s code: Unity stores a short header before it.
Nonewhen the code holds no container (the firstDXBCwithin 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_ParameterBlobIndicesnames: 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::MAXfor 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’slevel1shaders (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
rdeclares (m_ParsedForm.m_PropInfo.m_Props, type 4:m_DefTexture.m_DefaultName), by property.