2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2009-07-26 09:52:35 +00:00
|
|
|
#ifndef GCOGL_PIXELSHADER_H
|
|
|
|
#define GCOGL_PIXELSHADER_H
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2010-06-14 14:36:01 +00:00
|
|
|
#include "VideoCommon.h"
|
2012-08-06 23:02:04 +00:00
|
|
|
#include "ShaderGenCommon.h"
|
2013-01-28 21:51:15 +00:00
|
|
|
#include "BPMemory.h"
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2009-07-26 09:52:35 +00:00
|
|
|
#define I_COLORS "color"
|
|
|
|
#define I_KCOLORS "k"
|
|
|
|
#define I_ALPHA "alphaRef"
|
|
|
|
#define I_TEXDIMS "texdim"
|
|
|
|
#define I_ZBIAS "czbias"
|
2008-12-08 04:46:09 +00:00
|
|
|
#define I_INDTEXSCALE "cindscale"
|
2009-07-26 09:52:35 +00:00
|
|
|
#define I_INDTEXMTX "cindmtx"
|
|
|
|
#define I_FOG "cfog"
|
2013-03-20 01:51:12 +00:00
|
|
|
#define I_PLIGHTS "cPLights"
|
|
|
|
#define I_PMATERIALS "cPmtrl"
|
2010-09-23 02:17:48 +00:00
|
|
|
|
2011-01-07 19:23:57 +00:00
|
|
|
#define C_COLORMATRIX 0 // 0
|
|
|
|
#define C_COLORS 0 // 0
|
|
|
|
#define C_KCOLORS (C_COLORS + 4) // 4
|
|
|
|
#define C_ALPHA (C_KCOLORS + 4) // 8
|
|
|
|
#define C_TEXDIMS (C_ALPHA + 1) // 9
|
2012-03-24 03:47:28 +00:00
|
|
|
#define C_ZBIAS (C_TEXDIMS + 8) //17
|
|
|
|
#define C_INDTEXSCALE (C_ZBIAS + 2) //19
|
|
|
|
#define C_INDTEXMTX (C_INDTEXSCALE + 2) //21
|
|
|
|
#define C_FOG (C_INDTEXMTX + 6) //27
|
|
|
|
|
|
|
|
#define C_PLIGHTS (C_FOG + 3)
|
|
|
|
#define C_PMATERIALS (C_PLIGHTS + 40)
|
|
|
|
#define C_PENVCONST_END (C_PMATERIALS + 4)
|
2008-12-26 10:43:18 +00:00
|
|
|
|
2012-08-10 16:57:37 +00:00
|
|
|
// Different ways to achieve rendering with destination alpha
|
|
|
|
enum DSTALPHA_MODE
|
2010-10-21 05:22:18 +00:00
|
|
|
{
|
2012-08-10 16:57:37 +00:00
|
|
|
DSTALPHA_NONE, // Render normally, without destination alpha
|
|
|
|
DSTALPHA_ALPHA_PASS, // Render normally first, then render again for alpha
|
|
|
|
DSTALPHA_DUAL_SOURCE_BLEND // Use dual-source blending
|
2010-10-21 05:22:18 +00:00
|
|
|
};
|
|
|
|
|
2011-12-01 03:00:21 +00:00
|
|
|
// Annoying sure, can be removed once we get up to GLSL ~1.3
|
|
|
|
const s_svar PSVar_Loc[] = { {I_COLORS, C_COLORS, 4 },
|
2011-12-11 10:14:02 +00:00
|
|
|
{I_KCOLORS, C_KCOLORS, 4 },
|
|
|
|
{I_ALPHA, C_ALPHA, 1 },
|
|
|
|
{I_TEXDIMS, C_TEXDIMS, 8 },
|
|
|
|
{I_ZBIAS , C_ZBIAS, 2 },
|
|
|
|
{I_INDTEXSCALE , C_INDTEXSCALE, 2 },
|
|
|
|
{I_INDTEXMTX, C_INDTEXMTX, 6 },
|
|
|
|
{I_FOG, C_FOG, 3 },
|
|
|
|
{I_PLIGHTS, C_PLIGHTS, 40 },
|
|
|
|
{I_PMATERIALS, C_PMATERIALS, 4 },
|
|
|
|
};
|
2011-12-01 03:00:21 +00:00
|
|
|
|
2012-08-06 23:02:04 +00:00
|
|
|
struct pixel_shader_uid_data
|
|
|
|
{
|
|
|
|
u32 components;
|
|
|
|
DSTALPHA_MODE dstAlphaMode; // TODO: as u32 :2
|
2013-01-28 21:51:15 +00:00
|
|
|
AlphaTest::TEST_RESULT Pretest; // TODO: As :2
|
2012-08-06 23:02:04 +00:00
|
|
|
u32 nIndirectStagesUsed : 8;
|
|
|
|
struct {
|
|
|
|
u32 numtexgens : 4;
|
|
|
|
u32 numtevstages : 4;
|
|
|
|
u32 numindstages : 3;
|
|
|
|
} genMode;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 unknown : 1;
|
|
|
|
u32 projection : 1; // XF_TEXPROJ_X
|
|
|
|
u32 inputform : 2; // XF_TEXINPUT_X
|
|
|
|
u32 texgentype : 3; // XF_TEXGEN_X
|
|
|
|
u32 sourcerow : 5; // XF_SRCGEOM_X
|
|
|
|
u32 embosssourceshift : 3; // what generated texcoord to use
|
|
|
|
u32 embosslightshift : 3; // light index that is used
|
|
|
|
} texMtxInfo[8];
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 bi0 : 3; // indirect tex stage 0 ntexmap
|
|
|
|
u32 bc0 : 3; // indirect tex stage 0 ntexcoord
|
|
|
|
u32 bi1 : 3;
|
|
|
|
u32 bc1 : 3;
|
|
|
|
u32 bi2 : 3;
|
|
|
|
u32 bc3 : 3;
|
|
|
|
u32 bi4 : 3;
|
|
|
|
u32 bc4 : 3;
|
2013-04-29 17:37:32 +00:00
|
|
|
inline void SetValues(int index, u32 texcoord, u32 texmap)
|
2013-03-31 21:53:46 +00:00
|
|
|
{
|
|
|
|
if (index == 0) { bc0 = texcoord; bi0 = texmap; }
|
|
|
|
else if (index == 1) { bc1 = texcoord; bi1 = texmap; }
|
|
|
|
else if (index == 2) { bc3 = texcoord; bi2 = texmap; }
|
|
|
|
else if (index == 3) { bc4 = texcoord; bi4 = texmap; }
|
|
|
|
}
|
2012-08-06 23:02:04 +00:00
|
|
|
} tevindref;
|
2012-08-07 12:36:56 +00:00
|
|
|
|
|
|
|
u32 tevorders_n_texcoord1 : 24; // 8 x 3 bit
|
|
|
|
u32 tevorders_n_texcoord2 : 24; // 8 x 3 bit
|
2013-03-31 21:53:46 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 sw1 : 24; // 8 x 3 bit
|
|
|
|
u32 sw2 : 24; // 8 x 3 bit
|
|
|
|
u32 tw1 : 24; // 8 x 3 bit
|
|
|
|
u32 tw2 : 24; // 8 x 3 bit
|
|
|
|
u32 fb_addprev : 16; // 16 x 1 bit
|
|
|
|
u32 bs : 32; // 16 x 2 bit
|
|
|
|
u32 fmt : 32; // 16 x 2 bit
|
|
|
|
u32 bt : 32; // 16 x 2 bit
|
|
|
|
u32 bias1 : 24; // 8 x 3 bit
|
|
|
|
u32 bias2 : 24; // 8 x 3 bit
|
|
|
|
u32 mid1 : 32; // 8 x 4 bit
|
|
|
|
u32 mid2 : 32; // 8 x 4 bit
|
|
|
|
|
|
|
|
// NOTE: These assume that the affected bits are zero before calling
|
|
|
|
void Set_sw(int index, u32 val)
|
|
|
|
{
|
|
|
|
if (index < 8) sw1 |= val << (3*index);
|
|
|
|
else sw2 |= val << (3*index - 24);
|
|
|
|
}
|
|
|
|
void Set_tw(int index, u32 val)
|
|
|
|
{
|
|
|
|
if (index < 8) tw1 |= val << (3*index);
|
|
|
|
else tw2 |= val << (3*index - 24);
|
|
|
|
}
|
|
|
|
void Set_bias(int index, u32 val)
|
|
|
|
{
|
|
|
|
if (index < 8) bias1 |= val << (3*index);
|
|
|
|
else bias2 |= val << (3*index - 24);
|
|
|
|
}
|
|
|
|
void Set_mid(int index, u32 val)
|
|
|
|
{
|
|
|
|
if (index < 8) mid1 |= val << (4*index);
|
|
|
|
else mid2 |= val << (4*index - 32);
|
|
|
|
}
|
|
|
|
} tevind_n;
|
2012-08-07 12:36:56 +00:00
|
|
|
|
|
|
|
u32 tevksel_n_swap : 32; // 8 x 2 bit (swap1) + 8 x 2 bit (swap2)
|
|
|
|
struct
|
|
|
|
{
|
2012-09-02 16:30:21 +00:00
|
|
|
union {
|
|
|
|
struct //abc=8bit,d=10bit
|
|
|
|
{
|
|
|
|
u32 d : 4; // TEVSELCC_X
|
|
|
|
u32 c : 4; // TEVSELCC_X
|
|
|
|
u32 b : 4; // TEVSELCC_X
|
|
|
|
u32 a : 4; // TEVSELCC_X
|
|
|
|
|
|
|
|
u32 bias : 2;
|
|
|
|
u32 op : 1;
|
|
|
|
u32 clamp : 1;
|
|
|
|
|
|
|
|
u32 shift : 2;
|
|
|
|
u32 dest : 2; //1,2,3
|
|
|
|
};
|
|
|
|
u32 hex : 24;
|
2012-08-07 12:36:56 +00:00
|
|
|
} colorC;
|
2012-09-02 16:30:21 +00:00
|
|
|
union {
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 rswap : 2;
|
|
|
|
u32 tswap : 2;
|
|
|
|
u32 d : 3; // TEVSELCA_
|
|
|
|
u32 c : 3; // TEVSELCA_
|
|
|
|
u32 b : 3; // TEVSELCA_
|
|
|
|
u32 a : 3; // TEVSELCA_
|
|
|
|
|
|
|
|
u32 bias : 2; //GXTevBias
|
|
|
|
u32 op : 1;
|
|
|
|
u32 clamp : 1;
|
|
|
|
|
|
|
|
u32 shift : 2;
|
|
|
|
u32 dest : 2; //1,2,3
|
|
|
|
};
|
|
|
|
u32 hex : 24;
|
2012-08-07 12:36:56 +00:00
|
|
|
} alphaC;
|
|
|
|
} combiners[16];
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 comp0 : 3;
|
|
|
|
u32 comp1 : 3;
|
|
|
|
u32 logic : 2;
|
2013-03-29 13:51:54 +00:00
|
|
|
u32 use_zcomploc_hack : 1;
|
2012-08-07 12:36:56 +00:00
|
|
|
} alpha_test;
|
|
|
|
|
2012-09-02 16:30:21 +00:00
|
|
|
union {
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 proj : 1; // 0 - perspective, 1 - orthographic
|
|
|
|
u32 fsel : 3; // 0 - off, 2 - linear, 4 - exp, 5 - exp2, 6 - backward exp, 7 - backward exp2
|
|
|
|
u32 RangeBaseEnabled : 1;
|
|
|
|
};
|
|
|
|
u32 hex : 4;
|
|
|
|
} fog;
|
|
|
|
|
2013-04-29 17:37:32 +00:00
|
|
|
u32 ztex_op : 2;
|
2013-01-28 21:51:15 +00:00
|
|
|
|
2013-03-29 13:51:54 +00:00
|
|
|
u32 per_pixel_depth : 1;
|
2012-08-07 12:36:56 +00:00
|
|
|
u32 bHasIndStage : 16;
|
2012-09-02 12:31:37 +00:00
|
|
|
|
|
|
|
u32 xfregs_numTexGen_numTexGens : 4;
|
2013-03-31 21:29:33 +00:00
|
|
|
|
|
|
|
LightingUidData lighting;
|
2012-08-06 23:02:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
|
2013-03-29 21:24:49 +00:00
|
|
|
typedef ShaderCode PixelShaderCode; // TODO: Obsolete
|
|
|
|
typedef ShaderConstantProfile PixelShaderConstantProfile; // TODO: Obsolete
|
2011-09-07 18:20:29 +00:00
|
|
|
|
2012-08-06 23:02:04 +00:00
|
|
|
void GeneratePixelShaderCode(PixelShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);
|
2012-09-02 12:31:37 +00:00
|
|
|
void GetPixelShaderUid(PixelShaderUid& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);
|
2012-09-02 18:00:15 +00:00
|
|
|
void GetPixelShaderConstantProfile(PixelShaderConstantProfile& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);
|
2011-09-08 22:32:04 +00:00
|
|
|
|
2009-07-26 09:52:35 +00:00
|
|
|
#endif // GCOGL_PIXELSHADER_H
|