SHBIN: Difference between revisions
Fill in missing DVLE sections based on information from picasso and libctru |
Update DVOJ section |
||
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:File formats]] | [[Category:File formats]] | ||
The SHBIN (SHader BINary) | The SHBIN (SHader BINary) format is used to contain compiled and linked shader programs. These can include vertex shaders and geometry shaders. In commercial applications, SHBIN files can be found as standalone files with the extension .shbin, or within container formats like, for example, [[CGFX]] (with the extension .bcsdr). They are typically compiled from .vsh files, .gsh files, and sometimes .asm files. | ||
A SHBIN's structure starts with a | A SHBIN's structure starts with a binary header (DVLB), then a single program header (DVLP), then one or more executable headers DVLE(s). The binary header specifies the number and location of DVLEs. The program header specifies the generic parts of the shader (i.e. the shader program data, the operand descriptor data, and a filename symbol table). The executable headers specify the contextual details (i.e. entry point, constant values, debug symbols, etc). There may be multiple executable headers, so in this sense multiple shaders sharing the same program code can be stored in a single SHBIN. Hence for the following, note the distinction between "program" and "executable". | ||
For a description of the instruction set, see the following page : [[Shader Instruction Set]] | For a description of the instruction set, see the following page : [[Shader Instruction Set]] | ||
Line 29: | Line 29: | ||
|} | |} | ||
The DVLP | The DVLP section comes directly after the binary header. | ||
== DVLP == | == DVLP == | ||
Line 45: | Line 45: | ||
| 0x4 | | 0x4 | ||
| 0x4 | | 0x4 | ||
| | | Unknown, same value as in DVLE. (Likely a version number) | ||
|- | |- | ||
| 0x8 | | 0x8 | ||
Line 57: | Line 57: | ||
| 0x10 | | 0x10 | ||
| 0x4 | | 0x4 | ||
| Offset (relative to DVLP start) to | | Offset (relative to DVLP start) to operand descriptor table | ||
|- | |- | ||
| 0x14 | | 0x14 | ||
| 0x4 | | 0x4 | ||
| Number of | | Number of operand descriptor table entries (each entry is 8-bytes long) | ||
|- | |- | ||
| 0x18 | | 0x18 | ||
| 0x4 | |||
| Unknown (Same value as offset to filename symbol table?) | |||
|- | |||
| 0x1C | |||
| 0x4 | |||
| Unknown (Always zero?) | |||
|- | |||
| 0x20 | |||
| 0x4 | | 0x4 | ||
| Offset (relative to DVLP start) to filename symbol table | | Offset (relative to DVLP start) to filename symbol table | ||
|- | |||
| 0x24 | |||
| 0x4 | |||
| Size of filename symbol table | |||
|- | |- | ||
|} | |} | ||
Line 83: | Line 95: | ||
| 0x4 | | 0x4 | ||
| 0x2 | | 0x2 | ||
| Unknown | | Unknown, same value as in DVLP. (Likely a version number) | ||
|- | |- | ||
| 0x6 | | 0x6 | ||
Line 91: | Line 103: | ||
| 0x7 | | 0x7 | ||
| 0x1 | | 0x1 | ||
| true = merge vertex | | true = merge vertex and geometry shader outmaps (geometry shader) | ||
|- | |- | ||
| 0x8 | | 0x8 | ||
Line 115: | Line 127: | ||
| 0x15 | | 0x15 | ||
| 0x1 | | 0x1 | ||
| Starting float | | Starting float constant register number for storing the fixed-size primitive vertex array (geometry shader, fixed mode) | ||
|- | |- | ||
| 0x16 | | 0x16 | ||
Line 175: | Line 187: | ||
|- | |- | ||
| 0x0 | | 0x0 | ||
| | | 0x2 | ||
| Label ID | | Label ID | ||
|- | |||
| 0x0 | |||
| 0x2 | |||
| Unknown (always 1?) | |||
|- | |- | ||
| 0x4 | | 0x4 | ||
Line 184: | Line 200: | ||
| 0x8 | | 0x8 | ||
| 0x4 | | 0x4 | ||
| | | Size of label's location (in words). 0xFFFFFFFF/(uint32_t)-1 if there is no size. | ||
|- | |- | ||
| 0xC | | 0xC | ||
Line 194: | Line 210: | ||
=== Constant Table Entry === | === Constant Table Entry === | ||
Each executable's constants are stored | Each executable's constants are stored in a constant table. This information is used by ctrulib's SHDR framework to automatically send those values to the GPU when changing to a given program. An entry is constituted by a header and the constant data, the latter of which uses a format specific to the constant type. | ||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
Line 208: | Line 224: | ||
| 0x2 | | 0x2 | ||
| 0x1 | | 0x1 | ||
| | | Constant register ID | ||
|} | |} | ||
Line 225: | Line 241: | ||
| 0x2 | | 0x2 | ||
| 0x1 | | 0x1 | ||
| | | Boolean constant register ID | ||
|- | |- | ||
| 0x4 | | 0x4 | ||
Line 244: | Line 260: | ||
| 0x2 | | 0x2 | ||
| 0x1 | | 0x1 | ||
| | | Integer constant register ID | ||
|- | |- | ||
| 0x4 | | 0x4 | ||
Line 275: | Line 291: | ||
| 0x2 | | 0x2 | ||
| 0x1 | | 0x1 | ||
| | | floating-point constant register ID | ||
|- | |- | ||
| 0x4 | | 0x4 | ||
Line 297: | Line 313: | ||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
|- | |- | ||
! | ! Offset | ||
! Size | |||
! Description | ! Description | ||
|- | |- | ||
| | | 0x0 | ||
| 0x2 | |||
| Output type (see table below) | | Output type (see table below) | ||
|- | |- | ||
| | | 0x2 | ||
| 0x2 | |||
| Register ID | | Register ID | ||
|- | |- | ||
| | | 0x4 | ||
| 0x2 | |||
| Output attribute component mask (e.g. 5=xz) | | Output attribute component mask (e.g. 5=xz) | ||
|- | |||
| 0x6 | |||
| 0x2 | |||
| Unknown (Consistently the same number throughout the DVLE, may vary between DVLEs?) | |||
|- | |||
|} | |} | ||
Line 313: | Line 338: | ||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
|- | |- | ||
! | ! Type | ||
! Description | ! Description | ||
|- | |- | ||
Line 345: | Line 370: | ||
=== Uniform Table Entry === | === Uniform Table Entry === | ||
Keep in mind that the usage of the term "Uniform" here is used as [https://developer.download.nvidia.com/CgTutorial/cg_tutorial_chapter03.html defined by Nvidia] (variable who obtains its initial value from an external environment) and not as defined by RenderMan/GLSL (variables whose values are constant over a shaded surface). | |||
The uniform table contains a list of all registers whose initial values are derived by an external source along with their layout and associated symbol. | |||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
|- | |- | ||
Line 357: | Line 387: | ||
| 0x4 | | 0x4 | ||
| 0x2 | | 0x2 | ||
| | | Register index of the start of the uniform | ||
|- | |- | ||
| 0x6 | | 0x6 | ||
| 0x2 | | 0x2 | ||
| | | Register index of the end of the uniform (equal to start register for non-arrays) | ||
|- | |- | ||
|} | |} | ||
Line 403: | Line 433: | ||
|- | |- | ||
| 0x04 | | 0x04 | ||
| | | 0x2 | ||
| Unknown. | | Unknown. (Likely a version number) | ||
|- | |||
| 0x06 | |||
| 0x1 | |||
| Shader type (0x0 = vertex shader, 0x1 = geometry shader; might contain other flags) | |||
|- | |||
| 0x07 | |||
| 0x1 | |||
| true = merge vertex and geometry shader outmaps (geometry shader) | |||
|- | |- | ||
| 0x08 | | 0x08 | ||
| | | 0x2 | ||
| | | Bitmask of used input registers. | ||
|- | |||
| 0x10 | |||
| 0x2 | |||
| Bitmask of used output registers. | |||
|- | |- | ||
| 0x0C | | 0x0C | ||
Line 440: | Line 482: | ||
| 0x28 | | 0x28 | ||
| 0x4 | | 0x4 | ||
| Offset | | Offset to operand descriptor table | ||
|- | |- | ||
| 0x2C | | 0x2C | ||
| 0x4 | | 0x4 | ||
| Number of | | Number of operand descriptor table entries (each entry is 8-bytes long) | ||
|- | |- | ||
| 0x30 | | 0x30 |