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