Path: blob/21.2-virgl/src/gallium/drivers/svga/include/svga3d_shaderdefs.h
4574 views
/**********************************************************1* Copyright 2007-2014 VMware, Inc. All rights reserved.2*3* Permission is hereby granted, free of charge, to any person4* obtaining a copy of this software and associated documentation5* files (the "Software"), to deal in the Software without6* restriction, including without limitation the rights to use, copy,7* modify, merge, publish, distribute, sublicense, and/or sell copies8* of the Software, and to permit persons to whom the Software is9* furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23**********************************************************/2425/*26* svga3d_shaderdefs.h --27*28* SVGA3D byte code format and limit definitions.29*30* The format of the byte code directly corresponds to that defined31* by Microsoft DirectX SDK 9.0c (file d3d9types.h). The format can32* also be extended so that different shader formats can be supported33* for example GLSL, ARB vp/fp, NV/ATI shader formats, etc.34*35*/3637#ifndef __SVGA3D_SHADER_DEFS__38#define __SVGA3D_SHADER_DEFS__3940/* SVGA3D shader hardware limits. */4142#define SVGA3D_INPUTREG_MAX 1643#define SVGA3D_OUTPUTREG_MAX 1244#define SVGA3D_VERTEX_SAMPLERREG_MAX 445#define SVGA3D_PIXEL_SAMPLERREG_MAX 1646#define SVGA3D_SAMPLERREG_MAX (SVGA3D_PIXEL_SAMPLERREG_MAX+\47SVGA3D_VERTEX_SAMPLERREG_MAX)48#define SVGA3D_TEMPREG_MAX 3249#define SVGA3D_CONSTREG_MAX 25650#define SVGA3D_CONSTINTREG_MAX 1651#define SVGA3D_CONSTBOOLREG_MAX 1652#define SVGA3D_ADDRREG_MAX 153#define SVGA3D_PREDREG_MAX 15455/* SVGA3D byte code specific limits */5657#define SVGA3D_MAX_SRC_REGS 458#define SVGA3D_MAX_NESTING_LEVEL 325960/* SVGA3D version information. */6162#define SVGA3D_VS_TYPE 0xFFFE63#define SVGA3D_PS_TYPE 0xFFFF6465typedef struct {66union {67struct {68uint32 minor : 8;69uint32 major : 8;70uint32 type : 16;71};7273uint32 value;74};75} SVGA3dShaderVersion;7677#define SVGA3D_VS_10 ((SVGA3D_VS_TYPE << 16) | 1 << 8)78#define SVGA3D_VS_11 (SVGA3D_VS_10 | 1)79#define SVGA3D_VS_20 ((SVGA3D_VS_TYPE << 16) | 2 << 8)80#define SVGA3D_VS_21 (SVGA3D_VS_20 | 1)81#define SVGA3D_VS_30 ((SVGA3D_VS_TYPE << 16) | 3 << 8)8283#define SVGA3D_PS_10 ((SVGA3D_PS_TYPE << 16) | 1 << 8)84#define SVGA3D_PS_11 (SVGA3D_PS_10 | 1)85#define SVGA3D_PS_12 (SVGA3D_PS_10 | 2)86#define SVGA3D_PS_13 (SVGA3D_PS_10 | 3)87#define SVGA3D_PS_14 (SVGA3D_PS_10 | 4)88#define SVGA3D_PS_20 ((SVGA3D_PS_TYPE << 16) | 2 << 8)89#define SVGA3D_PS_21 (SVGA3D_PS_20 | 1)90#define SVGA3D_PS_30 ((SVGA3D_PS_TYPE << 16) | 3 << 8)9192/* The *_ENABLED are for backwards compatibility with old drivers */93typedef enum {94SVGA3DPSVERSION_NONE = 0,95SVGA3DPSVERSION_ENABLED = 1,96SVGA3DPSVERSION_11 = 3,97SVGA3DPSVERSION_12 = 5,98SVGA3DPSVERSION_13 = 7,99SVGA3DPSVERSION_14 = 9,100SVGA3DPSVERSION_20 = 11,101SVGA3DPSVERSION_30 = 13,102SVGA3DPSVERSION_40 = 15,103SVGA3DPSVERSION_MAX104} SVGA3dPixelShaderVersion;105106typedef enum {107SVGA3DVSVERSION_NONE = 0,108SVGA3DVSVERSION_ENABLED = 1,109SVGA3DVSVERSION_11 = 3,110SVGA3DVSVERSION_20 = 5,111SVGA3DVSVERSION_30 = 7,112SVGA3DVSVERSION_40 = 9,113SVGA3DVSVERSION_MAX114} SVGA3dVertexShaderVersion;115116/* SVGA3D instruction op codes. */117118typedef enum {119SVGA3DOP_NOP = 0,120SVGA3DOP_MOV,121SVGA3DOP_ADD,122SVGA3DOP_SUB,123SVGA3DOP_MAD,124SVGA3DOP_MUL,125SVGA3DOP_RCP,126SVGA3DOP_RSQ,127SVGA3DOP_DP3,128SVGA3DOP_DP4,129SVGA3DOP_MIN,130SVGA3DOP_MAX,131SVGA3DOP_SLT,132SVGA3DOP_SGE,133SVGA3DOP_EXP,134SVGA3DOP_LOG,135SVGA3DOP_LIT,136SVGA3DOP_DST,137SVGA3DOP_LRP,138SVGA3DOP_FRC,139SVGA3DOP_M4x4,140SVGA3DOP_M4x3,141SVGA3DOP_M3x4,142SVGA3DOP_M3x3,143SVGA3DOP_M3x2,144SVGA3DOP_CALL,145SVGA3DOP_CALLNZ,146SVGA3DOP_LOOP,147SVGA3DOP_RET,148SVGA3DOP_ENDLOOP,149SVGA3DOP_LABEL,150SVGA3DOP_DCL,151SVGA3DOP_POW,152SVGA3DOP_CRS,153SVGA3DOP_SGN,154SVGA3DOP_ABS,155SVGA3DOP_NRM,156SVGA3DOP_SINCOS,157SVGA3DOP_REP,158SVGA3DOP_ENDREP,159SVGA3DOP_IF,160SVGA3DOP_IFC,161SVGA3DOP_ELSE,162SVGA3DOP_ENDIF,163SVGA3DOP_BREAK,164SVGA3DOP_BREAKC,165SVGA3DOP_MOVA,166SVGA3DOP_DEFB,167SVGA3DOP_DEFI,168SVGA3DOP_TEXCOORD = 64,169SVGA3DOP_TEXKILL,170SVGA3DOP_TEX,171SVGA3DOP_TEXBEM,172SVGA3DOP_TEXBEML,173SVGA3DOP_TEXREG2AR,174SVGA3DOP_TEXREG2GB = 70,175SVGA3DOP_TEXM3x2PAD,176SVGA3DOP_TEXM3x2TEX,177SVGA3DOP_TEXM3x3PAD,178SVGA3DOP_TEXM3x3TEX,179SVGA3DOP_RESERVED0,180SVGA3DOP_TEXM3x3SPEC,181SVGA3DOP_TEXM3x3VSPEC,182SVGA3DOP_EXPP,183SVGA3DOP_LOGP,184SVGA3DOP_CND = 80,185SVGA3DOP_DEF,186SVGA3DOP_TEXREG2RGB,187SVGA3DOP_TEXDP3TEX,188SVGA3DOP_TEXM3x2DEPTH,189SVGA3DOP_TEXDP3,190SVGA3DOP_TEXM3x3,191SVGA3DOP_TEXDEPTH,192SVGA3DOP_CMP,193SVGA3DOP_BEM,194SVGA3DOP_DP2ADD = 90,195SVGA3DOP_DSX,196SVGA3DOP_DSY,197SVGA3DOP_TEXLDD,198SVGA3DOP_SETP,199SVGA3DOP_TEXLDL,200SVGA3DOP_BREAKP = 96,201SVGA3DOP_LAST_INST,202SVGA3DOP_PHASE = 0xFFFD,203SVGA3DOP_COMMENT = 0xFFFE,204SVGA3DOP_END = 0xFFFF,205} SVGA3dShaderOpCodeType;206207/* SVGA3D operation control/comparison function types */208209typedef enum {210SVGA3DOPCONT_NONE,211SVGA3DOPCONT_PROJECT, /* Projective texturing */212SVGA3DOPCONT_BIAS, /* Texturing with a LOD bias */213} SVGA3dShaderOpCodeControlFnType;214215typedef enum {216SVGA3DOPCOMP_RESERVED0 = 0,217SVGA3DOPCOMP_GT,218SVGA3DOPCOMP_EQ,219SVGA3DOPCOMP_GE,220SVGA3DOPCOMP_LT,221SVGA3DOPCOMPC_NE,222SVGA3DOPCOMP_LE,223SVGA3DOPCOMP_RESERVED1224} SVGA3dShaderOpCodeCompFnType;225226/* SVGA3D register types */227228typedef enum {229SVGA3DREG_TEMP = 0, /* Temporary register file */230SVGA3DREG_INPUT, /* Input register file */231SVGA3DREG_CONST, /* Constant register file */232SVGA3DREG_ADDR, /* Address register for VS */233SVGA3DREG_TEXTURE = 3, /* Texture register file for PS */234SVGA3DREG_RASTOUT, /* Rasterizer register file */235SVGA3DREG_ATTROUT, /* Attribute output register file */236SVGA3DREG_TEXCRDOUT, /* Texture coordinate output register file */237SVGA3DREG_OUTPUT = 6, /* Output register file for VS 3.0+ */238SVGA3DREG_CONSTINT, /* Constant integer vector register file */239SVGA3DREG_COLOROUT, /* Color output register file */240SVGA3DREG_DEPTHOUT, /* Depth output register file */241SVGA3DREG_SAMPLER, /* Sampler state register file */242SVGA3DREG_CONST2, /* Constant register file 2048 - 4095 */243SVGA3DREG_CONST3, /* Constant register file 4096 - 6143 */244SVGA3DREG_CONST4, /* Constant register file 6144 - 8191 */245SVGA3DREG_CONSTBOOL, /* Constant boolean register file */246SVGA3DREG_LOOP, /* Loop counter register file */247SVGA3DREG_TEMPFLOAT16, /* 16-bit float temp register file */248SVGA3DREG_MISCTYPE, /* Miscellaneous (single) registers */249SVGA3DREG_LABEL, /* Label */250SVGA3DREG_PREDICATE, /* Predicate register */251} SVGA3dShaderRegType;252253/* SVGA3D rasterizer output register types */254255typedef enum {256SVGA3DRASTOUT_POSITION = 0,257SVGA3DRASTOUT_FOG,258SVGA3DRASTOUT_PSIZE259} SVGA3dShaderRastOutRegType;260261/* SVGA3D miscellaneous register types */262263typedef enum {264SVGA3DMISCREG_POSITION = 0, /* Input position x,y,z,rhw (PS) */265SVGA3DMISCREG_FACE /* Floating point primitive area (PS) */266} SVGA3DShaderMiscRegType;267268/* SVGA3D sampler types */269270typedef enum {271SVGA3DSAMP_UNKNOWN = 0, /* Uninitialized value */272SVGA3DSAMP_2D = 2, /* dcl_2d s# (for declaring a 2D texture) */273SVGA3DSAMP_CUBE, /* dcl_cube s# (for declaring a cube texture) */274SVGA3DSAMP_VOLUME, /* dcl_volume s# (for declaring a volume texture) */275SVGA3DSAMP_2D_SHADOW, /* dcl_2d s# (for declaring a 2D shadow texture) */276SVGA3DSAMP_MAX,277} SVGA3dShaderSamplerType;278279/* SVGA3D write mask */280281#define SVGA3DWRITEMASK_0 1 /* Component 0 (X;Red) */282#define SVGA3DWRITEMASK_1 2 /* Component 1 (Y;Green) */283#define SVGA3DWRITEMASK_2 4 /* Component 2 (Z;Blue) */284#define SVGA3DWRITEMASK_3 8 /* Component 3 (W;Alpha) */285#define SVGA3DWRITEMASK_ALL 15 /* All components */286287/* SVGA3D destination modifiers */288289#define SVGA3DDSTMOD_NONE 0 /* nop */290#define SVGA3DDSTMOD_SATURATE 1 /* clamp to [0, 1] */291#define SVGA3DDSTMOD_PARTIALPRECISION 2 /* Partial precision hint */292293/*294* Relevant to multisampling only:295* When the pixel center is not covered, sample296* attribute or compute gradients/LOD297* using multisample "centroid" location.298* "Centroid" is some location within the covered299* region of the pixel.300*/301302#define SVGA3DDSTMOD_MSAMPCENTROID 4303304/* SVGA3D destination shift scale */305306typedef enum {307SVGA3DDSTSHFSCALE_X1 = 0, /* 1.0 */308SVGA3DDSTSHFSCALE_X2 = 1, /* 2.0 */309SVGA3DDSTSHFSCALE_X4 = 2, /* 4.0 */310SVGA3DDSTSHFSCALE_X8 = 3, /* 8.0 */311SVGA3DDSTSHFSCALE_D8 = 13, /* 0.125 */312SVGA3DDSTSHFSCALE_D4 = 14, /* 0.25 */313SVGA3DDSTSHFSCALE_D2 = 15 /* 0.5 */314} SVGA3dShaderDstShfScaleType;315316/* SVGA3D source swizzle */317318#define SVGA3DSWIZZLE_REPLICATEX 0x00319#define SVGA3DSWIZZLE_REPLICATEY 0x55320#define SVGA3DSWIZZLE_REPLICATEZ 0xAA321#define SVGA3DSWIZZLE_REPLICATEW 0xFF322#define SVGA3DSWIZZLE_NONE 0xE4323#define SVGA3DSWIZZLE_YZXW 0xC9324#define SVGA3DSWIZZLE_ZXYW 0xD2325#define SVGA3DSWIZZLE_WXYZ 0x1B326327/* SVGA3D source modifiers */328329typedef enum {330SVGA3DSRCMOD_NONE = 0, /* nop */331SVGA3DSRCMOD_NEG, /* negate */332SVGA3DSRCMOD_BIAS, /* bias */333SVGA3DSRCMOD_BIASNEG, /* bias and negate */334SVGA3DSRCMOD_SIGN, /* sign */335SVGA3DSRCMOD_SIGNNEG, /* sign and negate */336SVGA3DSRCMOD_COMP, /* complement */337SVGA3DSRCMOD_X2, /* x2 */338SVGA3DSRCMOD_X2NEG, /* x2 and negate */339SVGA3DSRCMOD_DZ, /* divide through by z component */340SVGA3DSRCMOD_DW, /* divide through by w component */341SVGA3DSRCMOD_ABS, /* abs() */342SVGA3DSRCMOD_ABSNEG, /* -abs() */343SVGA3DSRCMOD_NOT, /* ! (for predicate register) */344} SVGA3dShaderSrcModType;345346/* SVGA3D instruction token */347348typedef struct {349union {350struct {351uint32 comment_op : 16;352uint32 comment_size : 16;353};354355struct {356uint32 op : 16;357uint32 control : 3;358uint32 reserved2 : 5;359uint32 size : 4;360uint32 predicated : 1;361uint32 reserved1 : 1;362uint32 coissue : 1;363uint32 reserved0 : 1;364};365366uint32 value;367};368} SVGA3dShaderInstToken;369370/* SVGA3D destination parameter token */371372typedef struct {373union {374struct {375uint32 num : 11;376uint32 type_upper : 2;377uint32 relAddr : 1;378uint32 reserved1 : 2;379uint32 mask : 4;380uint32 dstMod : 4;381uint32 shfScale : 4;382uint32 type_lower : 3;383uint32 reserved0 : 1;384};385386uint32 value;387};388} SVGA3dShaderDestToken;389390/* SVGA3D source parameter token */391392typedef struct {393union {394struct {395uint32 num : 11;396uint32 type_upper : 2;397uint32 relAddr : 1;398uint32 reserved1 : 2;399uint32 swizzle : 8;400uint32 srcMod : 4;401uint32 type_lower : 3;402uint32 reserved0 : 1;403};404405uint32 value;406};407} SVGA3dShaderSrcToken;408409/* SVGA3DOP_DCL parameter tokens */410411typedef struct {412union {413struct {414union {415struct {416uint32 usage : 5;417uint32 reserved1 : 11;418uint32 index : 4;419uint32 reserved0 : 12;420}; /* input / output declaration */421422struct {423uint32 reserved3 : 27;424uint32 type : 4;425uint32 reserved2 : 1;426}; /* sampler declaration */427};428429SVGA3dShaderDestToken dst;430};431432uint32 values[2];433};434} SVGA3DOpDclArgs;435436/* SVGA3DOP_DEF parameter tokens */437438typedef struct {439union {440struct {441SVGA3dShaderDestToken dst;442443union {444float constValues[4];445int constIValues[4];446Bool constBValue;447};448};449450uint32 values[5];451};452} SVGA3DOpDefArgs;453454/* SVGA3D shader token */455456typedef union {457uint32 value;458SVGA3dShaderInstToken inst;459SVGA3dShaderDestToken dest;460SVGA3dShaderSrcToken src;461} SVGA3dShaderToken;462463/* SVGA3D shader program */464465typedef struct {466SVGA3dShaderVersion version;467/* SVGA3dShaderToken stream */468} SVGA3dShaderProgram;469470/* SVGA3D version specific register assignments */471472static const uint32 SVGA3D_INPUT_REG_POSITION_VS11 = 0;473static const uint32 SVGA3D_INPUT_REG_PSIZE_VS11 = 1;474static const uint32 SVGA3D_INPUT_REG_FOG_VS11 = 3;475static const uint32 SVGA3D_INPUT_REG_FOG_MASK_VS11 = SVGA3DWRITEMASK_3;476static const uint32 SVGA3D_INPUT_REG_COLOR_BASE_VS11 = 2;477static const uint32 SVGA3D_INPUT_REG_TEXCOORD_BASE_VS11 = 4;478479static const uint32 SVGA3D_INPUT_REG_COLOR_BASE_PS11 = 0;480static const uint32 SVGA3D_INPUT_REG_TEXCOORD_BASE_PS11 = 2;481static const uint32 SVGA3D_OUTPUT_REG_DEPTH_PS11 = 0;482static const uint32 SVGA3D_OUTPUT_REG_COLOR_PS11 = 1;483484static const uint32 SVGA3D_INPUT_REG_COLOR_BASE_PS20 = 0;485static const uint32 SVGA3D_INPUT_REG_COLOR_NUM_PS20 = 2;486static const uint32 SVGA3D_INPUT_REG_TEXCOORD_BASE_PS20 = 2;487static const uint32 SVGA3D_INPUT_REG_TEXCOORD_NUM_PS20 = 8;488static const uint32 SVGA3D_OUTPUT_REG_COLOR_BASE_PS20 = 1;489static const uint32 SVGA3D_OUTPUT_REG_COLOR_NUM_PS20 = 4;490static const uint32 SVGA3D_OUTPUT_REG_DEPTH_BASE_PS20 = 0;491static const uint32 SVGA3D_OUTPUT_REG_DEPTH_NUM_PS20 = 1;492493/*494*----------------------------------------------------------------------495*496* SVGA3dShaderGetRegType --497*498* As the register type is split into two non sequential fields,499* this function provides an useful way of accessing the actual500* register type without having to manually concatenate the501* type_upper and type_lower fields.502*503* Results:504* Returns the register type.505*506*----------------------------------------------------------------------507*/508509static inline SVGA3dShaderRegType510SVGA3dShaderGetRegType(uint32 token)511{512SVGA3dShaderSrcToken src;513src.value = token;514return (SVGA3dShaderRegType)(src.type_upper << 3 | src.type_lower);515}516517#endif /* __SVGA3D_SHADER_DEFS__ */518519520