libctru  v2.4.1
shbin.h
Go to the documentation of this file.
1 /**
2  * @file shbin.h
3  * @brief Shader binary support.
4  */
5 #pragma once
6 
7 #include <3ds/gpu/gpu.h>
8 
9 /// DVLE type.
10 typedef enum{
11  VERTEX_SHDR=GPU_VERTEX_SHADER, ///< Vertex shader.
12  GEOMETRY_SHDR=GPU_GEOMETRY_SHADER ///< Geometry shader.
14 
15 /// Constant type.
16 typedef enum{
17  DVLE_CONST_BOOL=0x0, ///< Bool.
18  DVLE_CONST_u8=0x1, ///< Unsigned 8-bit integer.
19  DVLE_CONST_FLOAT24=0x2, ///< 24-bit float.
21 
22 /// Output attribute.
23 typedef enum{
24  RESULT_POSITION = 0x0, ///< Position.
25  RESULT_NORMALQUAT = 0x1, ///< Normal Quaternion.
26  RESULT_COLOR = 0x2, ///< Color.
27  RESULT_TEXCOORD0 = 0x3, ///< Texture coordinate 0.
28  RESULT_TEXCOORD0W = 0x4, ///< Texture coordinate 0 W.
29  RESULT_TEXCOORD1 = 0x5, ///< Texture coordinate 1.
30  RESULT_TEXCOORD2 = 0x6, ///< Texture coordinate 2.
31  RESULT_VIEW = 0x8, ///< View.
32  RESULT_DUMMY = 0x9, ///< Dummy attribute (used as passthrough for geometry shader input).
34 
35 /// Geometry shader operation modes.
36 typedef enum
37 {
38  GSH_POINT = 0, ///< Point processing mode.
39  GSH_VARIABLE_PRIM = 1, ///< Variable-size primitive processing mode.
40  GSH_FIXED_PRIM = 2, ///< Fixed-size primitive processing mode.
42 
43 /// DVLP data.
44 typedef struct{
45  u32 codeSize; ///< Code size.
46  u32* codeData; ///< Code data.
47  u32 opdescSize; ///< Operand description size.
48  u32* opcdescData; ///< Operand description data.
49 }DVLP_s;
50 
51 /// DVLE constant entry data.
52 typedef struct{
53  u16 type; ///< Constant type. See @ref DVLE_constantType
54  u16 id; ///< Constant ID.
55  u32 data[4]; ///< Constant data.
57 
58 /// DVLE output entry data.
59 typedef struct{
60  u16 type; ///< Output type. See @ref DVLE_outputAttribute_t
61  u16 regID; ///< Output register ID.
62  u8 mask; ///< Output mask.
63  u8 unk[3]; ///< Unknown.
65 
66 /// DVLE uniform entry data.
67 typedef struct{
68  u32 symbolOffset; ///< Symbol offset.
69  u16 startReg; ///< Start register.
70  u16 endReg; ///< End register.
72 
73 /// DVLE data.
74 typedef struct{
75  DVLE_type type; ///< DVLE type.
76  bool mergeOutmaps; ///< true = merge vertex/geometry shader outmaps ('dummy' output attribute is present).
77  DVLE_geoShaderMode gshMode; ///< Geometry shader operation mode.
78  u8 gshFixedVtxStart; ///< Starting float uniform register number for storing the fixed-size primitive vertex array.
79  u8 gshVariableVtxNum; ///< Number of fully-defined vertices in the variable-size primitive vertex array.
80  u8 gshFixedVtxNum; ///< Number of vertices in the fixed-size primitive vertex array.
81  DVLP_s* dvlp; ///< Contained DVLPs.
82  u32 mainOffset; ///< Offset of the start of the main function.
83  u32 endmainOffset; ///< Offset of the end of the main function.
84  u32 constTableSize; ///< Constant table size.
85  DVLE_constEntry_s* constTableData; ///< Constant table data.
86  u32 outTableSize; ///< Output table size.
87  DVLE_outEntry_s* outTableData; ///< Output table data.
88  u32 uniformTableSize; ///< Uniform table size.
89  DVLE_uniformEntry_s* uniformTableData; ///< Uniform table data.
90  char* symbolTableData; ///< Symbol table data.
91  u8 outmapMask; ///< Output map mask.
92  u32 outmapData[8]; ///< Output map data.
93  u32 outmapMode; ///< Output map mode.
94  u32 outmapClock; ///< Output map attribute clock.
95 }DVLE_s;
96 
97 /// DVLB data.
98 typedef struct{
99  u32 numDVLE; ///< DVLE count.
100  DVLP_s DVLP; ///< Primary DVLP.
101  DVLE_s* DVLE; ///< Contained DVLE.
102 }DVLB_s;
103 
104 /**
105  * @brief Parses a shader binary.
106  * @param shbinData Shader binary data.
107  * @param shbinSize Shader binary size.
108  * @return The parsed shader binary.
109  */
110 DVLB_s* DVLB_ParseFile(u32* shbinData, u32 shbinSize);
111 
112 /**
113  * @brief Frees shader binary data.
114  * @param dvlb DVLB to free.
115  */
116 void DVLB_Free(DVLB_s* dvlb);
117 
118 /**
119  * @brief Gets a uniform register index from a shader.
120  * @param dvle Shader to get the register from.
121  * @param name Name of the register.
122  * @return The uniform register index.
123  */
124 s8 DVLE_GetUniformRegister(DVLE_s* dvle, const char* name);
125 
126 /**
127  * @brief Generates a shader output map.
128  * @param dvle Shader to generate an output map for.
129  */
@ GPU_GEOMETRY_SHADER
Geometry shader.
Definition: enums.h:504
@ GPU_VERTEX_SHADER
Vertex shader.
Definition: enums.h:503
Barebones GPU communications driver.
DVLE_constantType
Constant type.
Definition: shbin.h:16
@ DVLE_CONST_BOOL
Bool.
Definition: shbin.h:17
@ DVLE_CONST_FLOAT24
24-bit float.
Definition: shbin.h:19
@ DVLE_CONST_u8
Unsigned 8-bit integer.
Definition: shbin.h:18
void DVLE_GenerateOutmap(DVLE_s *dvle)
Generates a shader output map.
void DVLB_Free(DVLB_s *dvlb)
Frees shader binary data.
s8 DVLE_GetUniformRegister(DVLE_s *dvle, const char *name)
Gets a uniform register index from a shader.
DVLE_outputAttribute_t
Output attribute.
Definition: shbin.h:23
@ RESULT_DUMMY
Dummy attribute (used as passthrough for geometry shader input).
Definition: shbin.h:32
@ RESULT_TEXCOORD2
Texture coordinate 2.
Definition: shbin.h:30
@ RESULT_VIEW
View.
Definition: shbin.h:31
@ RESULT_TEXCOORD1
Texture coordinate 1.
Definition: shbin.h:29
@ RESULT_POSITION
Position.
Definition: shbin.h:24
@ RESULT_TEXCOORD0
Texture coordinate 0.
Definition: shbin.h:27
@ RESULT_COLOR
Color.
Definition: shbin.h:26
@ RESULT_NORMALQUAT
Normal Quaternion.
Definition: shbin.h:25
@ RESULT_TEXCOORD0W
Texture coordinate 0 W.
Definition: shbin.h:28
DVLE_type
DVLE type.
Definition: shbin.h:10
@ GEOMETRY_SHDR
Geometry shader.
Definition: shbin.h:12
@ VERTEX_SHDR
Vertex shader.
Definition: shbin.h:11
DVLE_geoShaderMode
Geometry shader operation modes.
Definition: shbin.h:37
@ GSH_VARIABLE_PRIM
Variable-size primitive processing mode.
Definition: shbin.h:39
@ GSH_POINT
Point processing mode.
Definition: shbin.h:38
@ GSH_FIXED_PRIM
Fixed-size primitive processing mode.
Definition: shbin.h:40
DVLB_s * DVLB_ParseFile(u32 *shbinData, u32 shbinSize)
Parses a shader binary.
DVLB data.
Definition: shbin.h:98
DVLE_s * DVLE
Contained DVLE.
Definition: shbin.h:101
DVLP_s DVLP
Primary DVLP.
Definition: shbin.h:100
u32 numDVLE
DVLE count.
Definition: shbin.h:99
DVLE constant entry data.
Definition: shbin.h:52
u16 id
Constant ID.
Definition: shbin.h:54
u16 type
Constant type. See DVLE_constantType.
Definition: shbin.h:53
DVLE output entry data.
Definition: shbin.h:59
u8 mask
Output mask.
Definition: shbin.h:62
u16 type
Output type. See DVLE_outputAttribute_t.
Definition: shbin.h:60
u16 regID
Output register ID.
Definition: shbin.h:61
DVLE data.
Definition: shbin.h:74
DVLE_constEntry_s * constTableData
Constant table data.
Definition: shbin.h:85
u32 outmapMode
Output map mode.
Definition: shbin.h:93
DVLE_uniformEntry_s * uniformTableData
Uniform table data.
Definition: shbin.h:89
DVLE_geoShaderMode gshMode
Geometry shader operation mode.
Definition: shbin.h:77
DVLE_type type
DVLE type.
Definition: shbin.h:75
u32 mainOffset
Offset of the start of the main function.
Definition: shbin.h:82
u8 gshFixedVtxNum
Number of vertices in the fixed-size primitive vertex array.
Definition: shbin.h:80
u8 gshFixedVtxStart
Starting float uniform register number for storing the fixed-size primitive vertex array.
Definition: shbin.h:78
u32 outmapClock
Output map attribute clock.
Definition: shbin.h:94
DVLP_s * dvlp
Contained DVLPs.
Definition: shbin.h:81
u32 outTableSize
Output table size.
Definition: shbin.h:86
DVLE_outEntry_s * outTableData
Output table data.
Definition: shbin.h:87
char * symbolTableData
Symbol table data.
Definition: shbin.h:90
u8 outmapMask
Output map mask.
Definition: shbin.h:91
u32 endmainOffset
Offset of the end of the main function.
Definition: shbin.h:83
bool mergeOutmaps
true = merge vertex/geometry shader outmaps ('dummy' output attribute is present).
Definition: shbin.h:76
u8 gshVariableVtxNum
Number of fully-defined vertices in the variable-size primitive vertex array.
Definition: shbin.h:79
u32 constTableSize
Constant table size.
Definition: shbin.h:84
u32 uniformTableSize
Uniform table size.
Definition: shbin.h:88
DVLE uniform entry data.
Definition: shbin.h:67
u16 endReg
End register.
Definition: shbin.h:70
u32 symbolOffset
Symbol offset.
Definition: shbin.h:68
u16 startReg
Start register.
Definition: shbin.h:69
DVLP data.
Definition: shbin.h:44
u32 * opcdescData
Operand description data.
Definition: shbin.h:48
u32 * codeData
Code data.
Definition: shbin.h:46
u32 codeSize
Code size.
Definition: shbin.h:45
u32 opdescSize
Operand description size.
Definition: shbin.h:47
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
int8_t s8
8-bit signed integer
Definition: types.h:26
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
uint32_t u32
32-bit unsigned integer
Definition: types.h:23