Add in GLSL setting again.
PS and VS making. Untested and won't work for now. Add in program shader cache files. Readd NativeVertexFormat stuffs. Add in PS and VS cache things. SetShaders in places. Fixed EFB cache index computations in OpenGL renderer. The previous computation was very likely to go out of array bounds, which could result in crashes on EFB access. Also, the cache size was rounded down instead of up. This is a problem since EFB_HEIGHT (528) is not a multiple of EFB_CACHE_RECT_SIZE (64).
This commit is contained in:
parent
cda94290f5
commit
b20176b74f
|
@ -500,6 +500,15 @@ static void BuildSwapModeTable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
|
||||||
|
{
|
||||||
|
if(ApiType == API_GLSL)
|
||||||
|
return ""; // Nothing to do here
|
||||||
|
static char result[64];
|
||||||
|
sprintf(result, " : register(%s%d)", prefix, num);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
||||||
{
|
{
|
||||||
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
||||||
|
@ -524,6 +533,21 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ;
|
DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ;
|
||||||
|
|
||||||
|
if(ApiType == API_GLSL)
|
||||||
|
{
|
||||||
|
// A few required defines and ones that will make our lives a lot easier
|
||||||
|
WRITE(p, "#version 120\n");
|
||||||
|
// Silly differences
|
||||||
|
WRITE(p, "#define float2 vec2\n");
|
||||||
|
WRITE(p, "#define float3 vec3\n");
|
||||||
|
WRITE(p, "#define float4 vec4\n");
|
||||||
|
|
||||||
|
// cg to glsl function translation
|
||||||
|
WRITE(p, "#define frac(x) fract(x)\n");
|
||||||
|
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
|
||||||
|
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
|
||||||
|
}
|
||||||
// Declare samplers
|
// Declare samplers
|
||||||
|
|
||||||
if(ApiType != API_D3D11)
|
if(ApiType != API_D3D11)
|
||||||
|
@ -538,7 +562,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
||||||
bool bfirst = true;
|
bool bfirst = true;
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
WRITE(p, "%s samp%d : register(s%d)", bfirst?"":",", i, i);
|
WRITE(p, "%s samp%d %s", bfirst?"":",", i, WriteRegister(ApiType, "s", i));
|
||||||
bfirst = false;
|
bfirst = false;
|
||||||
}
|
}
|
||||||
WRITE(p, ";\n");
|
WRITE(p, ";\n");
|
||||||
|
@ -555,67 +579,107 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, "\n");
|
WRITE(p, "\n");
|
||||||
|
|
||||||
WRITE(p, "uniform float4 "I_COLORS"[4] : register(c%d);\n", C_COLORS);
|
WRITE(p, "uniform float4 "I_COLORS"[4] %s;\n", WriteRegister(ApiType, "c", C_COLORS));
|
||||||
WRITE(p, "uniform float4 "I_KCOLORS"[4] : register(c%d);\n", C_KCOLORS);
|
WRITE(p, "uniform float4 "I_KCOLORS"[4] %s;\n", WriteRegister(ApiType, "c", C_KCOLORS));
|
||||||
WRITE(p, "uniform float4 "I_ALPHA"[1] : register(c%d);\n", C_ALPHA);
|
WRITE(p, "uniform float4 "I_ALPHA"[1] %s;\n", WriteRegister(ApiType, "c", C_ALPHA));
|
||||||
WRITE(p, "uniform float4 "I_TEXDIMS"[8] : register(c%d);\n", C_TEXDIMS);
|
WRITE(p, "uniform float4 "I_TEXDIMS"[8] %s;\n", WriteRegister(ApiType, "c", C_TEXDIMS));
|
||||||
WRITE(p, "uniform float4 "I_ZBIAS"[2] : register(c%d);\n", C_ZBIAS);
|
WRITE(p, "uniform float4 "I_ZBIAS"[2] %s;\n", WriteRegister(ApiType, "c", C_ZBIAS));
|
||||||
WRITE(p, "uniform float4 "I_INDTEXSCALE"[2] : register(c%d);\n", C_INDTEXSCALE);
|
WRITE(p, "uniform float4 "I_INDTEXSCALE"[2] %s;\n", WriteRegister(ApiType, "c", C_INDTEXSCALE));
|
||||||
WRITE(p, "uniform float4 "I_INDTEXMTX"[6] : register(c%d);\n", C_INDTEXMTX);
|
WRITE(p, "uniform float4 "I_INDTEXMTX"[6] %s;\n", WriteRegister(ApiType, "c", C_INDTEXMTX));
|
||||||
WRITE(p, "uniform float4 "I_FOG"[3] : register(c%d);\n", C_FOG);
|
WRITE(p, "uniform float4 "I_FOG"[3] %s;\n", WriteRegister(ApiType, "c", C_FOG));
|
||||||
|
|
||||||
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
||||||
{
|
{
|
||||||
WRITE(p,"typedef struct { float4 col; float4 cosatt; float4 distatt; float4 pos; float4 dir; } Light;\n");
|
WRITE(p, "uniform float4 "I_PLIGHTS"[40] %s;\n", WriteRegister(ApiType, "c", C_PLIGHTS));
|
||||||
WRITE(p,"typedef struct { Light lights[8]; } s_"I_PLIGHTS";\n");
|
WRITE(p, "uniform float4 "I_PMATERIALS"[4] %s;\n", WriteRegister(ApiType, "c", C_PMATERIALS));
|
||||||
WRITE(p, "uniform s_"I_PLIGHTS" "I_PLIGHTS" : register(c%d);\n", C_PLIGHTS);
|
|
||||||
WRITE(p, "typedef struct { float4 C0, C1, C2, C3; } s_"I_PMATERIALS";\n");
|
|
||||||
WRITE(p, "uniform s_"I_PMATERIALS" "I_PMATERIALS" : register(c%d);\n", C_PMATERIALS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, "void main(\n");
|
if(ApiType != API_GLSL)
|
||||||
if(ApiType != API_D3D11)
|
{
|
||||||
{
|
WRITE(p, "void main(\n");
|
||||||
WRITE(p, " out float4 ocol0 : COLOR0,%s%s\n in float4 rawpos : %s,\n",
|
if(ApiType != API_D3D11)
|
||||||
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : COLOR1," : "",
|
|
||||||
DepthTextureEnable ? "\n out float depth : DEPTH," : "",
|
|
||||||
ApiType & API_OPENGL ? "WPOS" : ApiType & API_D3D9_SM20 ? "POSITION" : "VPOS");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
WRITE(p, " out float4 ocol0 : SV_Target0,%s%s\n in float4 rawpos : SV_Position,\n",
|
|
||||||
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : SV_Target1," : "",
|
|
||||||
DepthTextureEnable ? "\n out float depth : SV_Depth," : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
WRITE(p, " in float4 colors_0 : COLOR0,\n");
|
|
||||||
WRITE(p, " in float4 colors_1 : COLOR1");
|
|
||||||
|
|
||||||
// compute window position if needed because binding semantic WPOS is not widely supported
|
|
||||||
if (numTexgen < 7)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < numTexgen; ++i)
|
|
||||||
WRITE(p, ",\n in float3 uv%d : TEXCOORD%d", i, i);
|
|
||||||
WRITE(p, ",\n in float4 clipPos : TEXCOORD%d", numTexgen);
|
|
||||||
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
|
||||||
WRITE(p, ",\n in float4 Normal : TEXCOORD%d", numTexgen + 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// wpos is in w of first 4 texcoords
|
|
||||||
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; ++i)
|
WRITE(p, " out float4 ocol0 : COLOR0,%s%s\n in float4 rawpos : %s,\n",
|
||||||
WRITE(p, ",\n in float4 uv%d : TEXCOORD%d", i, i);
|
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : COLOR1," : "",
|
||||||
|
DepthTextureEnable ? "\n out float depth : DEPTH," : "",
|
||||||
|
ApiType & API_OPENGL ? "WPOS" : ApiType & API_D3D9_SM20 ? "POSITION" : "VPOS");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
|
WRITE(p, " out float4 ocol0 : SV_Target0,%s%s\n in float4 rawpos : SV_Position,\n",
|
||||||
WRITE(p, ",\n in float%d uv%d : TEXCOORD%d", i < 4 ? 4 : 3 , i, i);
|
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : SV_Target1," : "",
|
||||||
|
DepthTextureEnable ? "\n out float depth : SV_Depth," : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WRITE(p, " in float4 colors_0 : COLOR0,\n");
|
||||||
|
WRITE(p, " in float4 colors_1 : COLOR1");
|
||||||
|
|
||||||
|
// compute window position if needed because binding semantic WPOS is not widely supported
|
||||||
|
if (numTexgen < 7)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < numTexgen; ++i)
|
||||||
|
WRITE(p, ",\n in float3 uv%d : TEXCOORD%d", i, i);
|
||||||
|
WRITE(p, ",\n in float4 clipPos : TEXCOORD%d", numTexgen);
|
||||||
|
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
||||||
|
WRITE(p, ",\n in float4 Normal : TEXCOORD%d", numTexgen + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// wpos is in w of first 4 texcoords
|
||||||
|
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; ++i)
|
||||||
|
WRITE(p, ",\n in float4 uv%d : TEXCOORD%d", i, i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
|
||||||
|
WRITE(p, ",\n in float%d uv%d : TEXCOORD%d", i < 4 ? 4 : 3 , i, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WRITE(p, " ) {\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// GLSL doesn't do main arguments
|
||||||
|
// Once we switch to GLSL 1.3 we will bind a lot of these.
|
||||||
|
|
||||||
|
WRITE(p, " float4 ocol0;\n");
|
||||||
|
if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||||
|
WRITE(p, " float4 ocol1;\n"); // Will be supported later
|
||||||
|
if(DepthTextureEnable)
|
||||||
|
WRITE(p, " float depth;\n"); // TODO: Passed to Vertex Shader right?
|
||||||
|
WRITE(p, " float4 rawpos = gl_FragCoord;\n");
|
||||||
|
|
||||||
|
WRITE(p, " float4 colors_0 = gl_Color;\n");
|
||||||
|
WRITE(p, " float4 colors_1 = gl_SecondaryColor;\n");
|
||||||
|
|
||||||
|
// compute window position if needed because binding semantic WPOS is not widely supported
|
||||||
|
if (numTexgen < 7)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < numTexgen; ++i)
|
||||||
|
WRITE(p, " float3 uv%d = gl_TexCoord[%d].xyz;\n", i, i);
|
||||||
|
WRITE(p, " float4 clipPos = gl_TexCoord[%d];\n", numTexgen);
|
||||||
|
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
||||||
|
WRITE(p, " float4 Normal = gl_TexCoord[%d];\n", numTexgen + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// wpos is in w of first 4 texcoords
|
||||||
|
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; ++i)
|
||||||
|
WRITE(p, " float4 uv%d = gl_TexCoord[%d];\n", i, i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
|
||||||
|
WRITE(p, " float%d uv%d = gl_TexCoord[%d]%s;\n", i < 4 ? 4 : 3 , i, i, i < 4 ? ".xyz" : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WRITE(p, "void main()\n{\n");
|
||||||
}
|
}
|
||||||
WRITE(p, " ) {\n");
|
|
||||||
|
|
||||||
char* pmainstart = p;
|
char* pmainstart = p;
|
||||||
int Pretest = AlphaPreTest();
|
int Pretest = AlphaPreTest();
|
||||||
|
@ -624,8 +688,10 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
||||||
if (!Pretest)
|
if (!Pretest)
|
||||||
{
|
{
|
||||||
// alpha test will always fail, so restart the shader and just make it an empty function
|
// alpha test will always fail, so restart the shader and just make it an empty function
|
||||||
WRITE(p, "ocol0 = 0;\n");
|
WRITE(p, "ocol0 = float4(0);\n");
|
||||||
WRITE(p, "discard;\n");
|
WRITE(p, "discard;\n");
|
||||||
|
if(ApiType == API_GLSL)
|
||||||
|
WRITE(p, "gl_FragData[0] = ocol0;\n");
|
||||||
if(ApiType != API_D3D11)
|
if(ApiType != API_D3D11)
|
||||||
WRITE(p, "return;\n");
|
WRITE(p, "return;\n");
|
||||||
}
|
}
|
||||||
|
@ -733,6 +799,15 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
||||||
WRITE(p, "depth = 1.f;\n");
|
WRITE(p, "depth = 1.f;\n");
|
||||||
if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||||
WRITE(p, "ocol1 = 0;\n");
|
WRITE(p, "ocol1 = 0;\n");
|
||||||
|
if(ApiType == API_GLSL)
|
||||||
|
{
|
||||||
|
// Once we switch to GLSL 1.3 and bind variables, we won't need to do this
|
||||||
|
WRITE(p, "gl_FragData[0] = ocol0;\n");
|
||||||
|
if(DepthTextureEnable)
|
||||||
|
WRITE(p, "gl_FragDepth = depth;\n");
|
||||||
|
if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||||
|
; // TODO: Will do this later
|
||||||
|
}
|
||||||
WRITE(p, "discard;\n");
|
WRITE(p, "discard;\n");
|
||||||
if(ApiType != API_D3D11)
|
if(ApiType != API_D3D11)
|
||||||
WRITE(p, "return;\n");
|
WRITE(p, "return;\n");
|
||||||
|
@ -781,6 +856,13 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
||||||
// ...and the alpha from ocol0 will be written to the framebuffer.
|
// ...and the alpha from ocol0 will be written to the framebuffer.
|
||||||
WRITE(p, " ocol0.a = "I_ALPHA"[0].a;\n");
|
WRITE(p, " ocol0.a = "I_ALPHA"[0].a;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ApiType == API_GLSL)
|
||||||
|
{
|
||||||
|
if(DepthTextureEnable)
|
||||||
|
WRITE(p, "gl_FragDepth = depth;\n");
|
||||||
|
WRITE(p, "gl_FragData[0] = ocol0;\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
WRITE(p, "}\n");
|
WRITE(p, "}\n");
|
||||||
if (text[sizeof(text) - 1] != 0x7C)
|
if (text[sizeof(text) - 1] != 0x7C)
|
||||||
|
@ -1242,4 +1324,4 @@ static void WriteFog(char *&p)
|
||||||
WRITE(p, " prev.rgb = lerp(prev.rgb,"I_FOG"[0].rgb,fog);\n");
|
WRITE(p, " prev.rgb = lerp(prev.rgb,"I_FOG"[0].rgb,fog);\n");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,19 @@
|
||||||
#define PIXELSHADERUID_MAX_VALUES 70
|
#define PIXELSHADERUID_MAX_VALUES 70
|
||||||
#define PIXELSHADERUID_MAX_VALUES_SAFE 120
|
#define PIXELSHADERUID_MAX_VALUES_SAFE 120
|
||||||
|
|
||||||
|
// Annoying sure, can be removed once we get up to GLSL ~1.3
|
||||||
|
const s_svar PSVar_Loc[] = { {I_COLORS, C_COLORS, 4 },
|
||||||
|
{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 },
|
||||||
|
};
|
||||||
|
|
||||||
// DO NOT make anything in this class virtual.
|
// DO NOT make anything in this class virtual.
|
||||||
template<bool safe>
|
template<bool safe>
|
||||||
class _PIXELSHADERUID
|
class _PIXELSHADERUID
|
||||||
|
|
|
@ -130,7 +130,7 @@ static char text[16384];
|
||||||
|
|
||||||
#define WRITE p+=sprintf
|
#define WRITE p+=sprintf
|
||||||
|
|
||||||
char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE api_type)
|
char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE ApiType)
|
||||||
{
|
{
|
||||||
WRITE(p, "struct VS_OUTPUT {\n");
|
WRITE(p, "struct VS_OUTPUT {\n");
|
||||||
WRITE(p, " float4 pos : POSITION;\n");
|
WRITE(p, " float4 pos : POSITION;\n");
|
||||||
|
@ -161,7 +161,10 @@ char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE api_type)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
|
extern const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num);
|
||||||
|
|
||||||
|
|
||||||
|
const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
|
||||||
{
|
{
|
||||||
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
||||||
text[sizeof(text) - 1] = 0x7C; // canary
|
text[sizeof(text) - 1] = 0x7C; // canary
|
||||||
|
@ -169,7 +172,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
|
||||||
_assert_(bpmem.genMode.numtexgens == xfregs.numTexGen.numTexGens);
|
_assert_(bpmem.genMode.numtexgens == xfregs.numTexGen.numTexGens);
|
||||||
_assert_(bpmem.genMode.numcolchans == xfregs.numChan.numColorChans);
|
_assert_(bpmem.genMode.numcolchans == xfregs.numChan.numColorChans);
|
||||||
|
|
||||||
bool is_d3d = (api_type & API_D3D9 || api_type == API_D3D11);
|
bool is_d3d = (ApiType & API_D3D9 || ApiType == API_D3D11);
|
||||||
u32 lightMask = 0;
|
u32 lightMask = 0;
|
||||||
if (xfregs.numChan.numColorChans > 0)
|
if (xfregs.numChan.numColorChans > 0)
|
||||||
lightMask |= xfregs.color[0].GetFullLightMask() | xfregs.alpha[0].GetFullLightMask();
|
lightMask |= xfregs.color[0].GetFullLightMask() | xfregs.alpha[0].GetFullLightMask();
|
||||||
|
@ -178,78 +181,109 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
|
||||||
|
|
||||||
char *p = text;
|
char *p = text;
|
||||||
WRITE(p, "//Vertex Shader: comp:%x, \n", components);
|
WRITE(p, "//Vertex Shader: comp:%x, \n", components);
|
||||||
WRITE(p, "typedef struct { float4 T0, T1, T2; float4 N0, N1, N2; } s_"I_POSNORMALMATRIX";\n"
|
|
||||||
"typedef struct { float4 t; } FLT4;\n"
|
|
||||||
"typedef struct { FLT4 T[24]; } s_"I_TEXMATRICES";\n"
|
|
||||||
"typedef struct { FLT4 T[64]; } s_"I_TRANSFORMMATRICES";\n"
|
|
||||||
"typedef struct { FLT4 T[32]; } s_"I_NORMALMATRICES";\n"
|
|
||||||
"typedef struct { FLT4 T[64]; } s_"I_POSTTRANSFORMMATRICES";\n"
|
|
||||||
"typedef struct { float4 col; float4 cosatt; float4 distatt; float4 pos; float4 dir; } Light;\n"
|
|
||||||
"typedef struct { Light lights[8]; } s_"I_LIGHTS";\n"
|
|
||||||
"typedef struct { float4 C0, C1, C2, C3; } s_"I_MATERIALS";\n"
|
|
||||||
"typedef struct { float4 T0, T1, T2, T3; } s_"I_PROJECTION";\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
p = GenerateVSOutputStruct(p, components, api_type);
|
|
||||||
|
|
||||||
// uniforms
|
|
||||||
|
|
||||||
WRITE(p, "uniform s_"I_TRANSFORMMATRICES" "I_TRANSFORMMATRICES" : register(c%d);\n", C_TRANSFORMMATRICES);
|
|
||||||
WRITE(p, "uniform s_"I_TEXMATRICES" "I_TEXMATRICES" : register(c%d);\n", C_TEXMATRICES); // also using tex matrices
|
|
||||||
WRITE(p, "uniform s_"I_NORMALMATRICES" "I_NORMALMATRICES" : register(c%d);\n", C_NORMALMATRICES);
|
|
||||||
WRITE(p, "uniform s_"I_POSNORMALMATRIX" "I_POSNORMALMATRIX" : register(c%d);\n", C_POSNORMALMATRIX);
|
|
||||||
WRITE(p, "uniform s_"I_POSTTRANSFORMMATRICES" "I_POSTTRANSFORMMATRICES" : register(c%d);\n", C_POSTTRANSFORMMATRICES);
|
|
||||||
WRITE(p, "uniform s_"I_LIGHTS" "I_LIGHTS" : register(c%d);\n", C_LIGHTS);
|
|
||||||
WRITE(p, "uniform s_"I_MATERIALS" "I_MATERIALS" : register(c%d);\n", C_MATERIALS);
|
|
||||||
WRITE(p, "uniform s_"I_PROJECTION" "I_PROJECTION" : register(c%d);\n", C_PROJECTION);
|
|
||||||
WRITE(p, "uniform float4 "I_DEPTHPARAMS" : register(c%d);\n", C_DEPTHPARAMS);
|
|
||||||
|
|
||||||
WRITE(p, "VS_OUTPUT main(\n");
|
|
||||||
|
|
||||||
// inputs
|
if(ApiType == API_GLSL)
|
||||||
if (components & VB_HAS_NRM0)
|
{
|
||||||
WRITE(p, " float3 rawnorm0 : NORMAL0,\n");
|
// A few required defines and ones that will make our lives a lot easier
|
||||||
if (components & VB_HAS_NRM1) {
|
WRITE(p, "#version 120\n");
|
||||||
if (is_d3d)
|
// Silly differences
|
||||||
WRITE(p, " float3 rawnorm1 : NORMAL1,\n");
|
WRITE(p, "#define float2 vec2\n");
|
||||||
else
|
WRITE(p, "#define float3 vec3\n");
|
||||||
WRITE(p, " float3 rawnorm1 : ATTR%d,\n", SHADER_NORM1_ATTRIB);
|
WRITE(p, "#define float4 vec4\n");
|
||||||
|
|
||||||
|
// cg to glsl function translation
|
||||||
|
WRITE(p, "#define frac(x) fract(x)\n");
|
||||||
|
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
|
||||||
|
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
|
||||||
}
|
}
|
||||||
if (components & VB_HAS_NRM2) {
|
// uniforms
|
||||||
if (is_d3d)
|
WRITE(p, "uniform float4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteRegister(ApiType, "c", C_TRANSFORMMATRICES));
|
||||||
WRITE(p, " float3 rawnorm2 : NORMAL2,\n");
|
WRITE(p, "uniform float4 "I_TEXMATRICES"[24] %s;\n", WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices
|
||||||
else
|
WRITE(p, "uniform float4 "I_NORMALMATRICES"[32] %s;\n", WriteRegister(ApiType, "c", C_NORMALMATRICES));
|
||||||
WRITE(p, " float3 rawnorm2 : ATTR%d,\n", SHADER_NORM2_ATTRIB);
|
WRITE(p, "uniform float4 "I_POSNORMALMATRIX"[6] %s;\n", WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
|
||||||
}
|
WRITE(p, "uniform float4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
|
||||||
if (components & VB_HAS_COL0)
|
WRITE(p, "uniform float4 "I_LIGHTS"[40] %s;\n", WriteRegister(ApiType, "c", C_LIGHTS));
|
||||||
WRITE(p, " float4 color0 : COLOR0,\n");
|
WRITE(p, "uniform float4 "I_MATERIALS"[4] %s;\n", WriteRegister(ApiType, "c", C_MATERIALS));
|
||||||
if (components & VB_HAS_COL1)
|
WRITE(p, "uniform float4 "I_PROJECTION"[4] %s;\n", WriteRegister(ApiType, "c", C_PROJECTION));
|
||||||
WRITE(p, " float4 color1 : COLOR1,\n");
|
WRITE(p, "uniform float4 "I_DEPTHPARAMS" %s;\n", WriteRegister(ApiType, "c", C_DEPTHPARAMS));
|
||||||
for (int i = 0; i < 8; ++i) {
|
|
||||||
u32 hastexmtx = (components & (VB_HAS_TEXMTXIDX0<<i));
|
p = GenerateVSOutputStruct(p, components, ApiType);
|
||||||
if ((components & (VB_HAS_UV0<<i)) || hastexmtx)
|
|
||||||
WRITE(p, " float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i, i);
|
if(ApiType == API_GLSL)
|
||||||
}
|
{
|
||||||
if (components & VB_HAS_POSMTXIDX) {
|
if (components & VB_HAS_NRM0)
|
||||||
if (is_d3d)
|
WRITE(p, " float3 rawnorm0 = gl_Normal; // NORMAL0,\n");
|
||||||
{
|
|
||||||
WRITE(p, " float4 blend_indices : BLENDINDICES,\n");
|
if (components & VB_HAS_POSMTXIDX)
|
||||||
|
WRITE(p, "attribute float fposmtx; // ATTR%d,\n", SHADER_POSMTX_ATTRIB);
|
||||||
|
if (components & VB_HAS_NRM1)
|
||||||
|
WRITE(p, "attribute float3 rawnorm1; // ATTR%d,\n", SHADER_NORM1_ATTRIB);
|
||||||
|
if (components & VB_HAS_NRM2)
|
||||||
|
WRITE(p, "attribute float3 rawnorm2; // ATTR%d,\n", SHADER_NORM2_ATTRIB);
|
||||||
|
|
||||||
|
if (components & VB_HAS_COL0)
|
||||||
|
WRITE(p, " float4 color0 = gl_Color; // COLOR0,\n");
|
||||||
|
if (components & VB_HAS_COL1)
|
||||||
|
WRITE(p, " float4 color1 = gl_SecondaryColor; // COLOR1,\n");
|
||||||
|
for (int i = 0; i < 8; ++i) {
|
||||||
|
u32 hastexmtx = (components & (VB_HAS_TEXMTXIDX0<<i));
|
||||||
|
if ((components & (VB_HAS_UV0<<i)) || hastexmtx)
|
||||||
|
WRITE(p, " float%d tex%d = gl_MultiTexCoord%d.xy%s; // TEXCOORD%d,\n", hastexmtx ? 3 : 2, i, i, hastexmtx ? "z" : "", i);
|
||||||
}
|
}
|
||||||
else
|
WRITE(p, " float4 rawpos = gl_Vertex;\n") ;
|
||||||
WRITE(p, " float fposmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
|
|
||||||
|
WRITE(p, "void main()\n{\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
WRITE(p, "VS_OUTPUT main(\n");
|
||||||
|
|
||||||
|
// inputs
|
||||||
|
if (components & VB_HAS_NRM0)
|
||||||
|
WRITE(p, " float3 rawnorm0 : NORMAL0,\n");
|
||||||
|
if (components & VB_HAS_NRM1) {
|
||||||
|
if (is_d3d)
|
||||||
|
WRITE(p, " float3 rawnorm1 : NORMAL1,\n");
|
||||||
|
else
|
||||||
|
WRITE(p, " float3 rawnorm1 : ATTR%d,\n", SHADER_NORM1_ATTRIB);
|
||||||
|
}
|
||||||
|
if (components & VB_HAS_NRM2) {
|
||||||
|
if (is_d3d)
|
||||||
|
WRITE(p, " float3 rawnorm2 : NORMAL2,\n");
|
||||||
|
else
|
||||||
|
WRITE(p, " float3 rawnorm2 : ATTR%d,\n", SHADER_NORM2_ATTRIB);
|
||||||
|
}
|
||||||
|
if (components & VB_HAS_COL0)
|
||||||
|
WRITE(p, " float4 color0 : COLOR0,\n");
|
||||||
|
if (components & VB_HAS_COL1)
|
||||||
|
WRITE(p, " float4 color1 : COLOR1,\n");
|
||||||
|
for (int i = 0; i < 8; ++i) {
|
||||||
|
u32 hastexmtx = (components & (VB_HAS_TEXMTXIDX0<<i));
|
||||||
|
if ((components & (VB_HAS_UV0<<i)) || hastexmtx)
|
||||||
|
WRITE(p, " float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i, i);
|
||||||
|
}
|
||||||
|
if (components & VB_HAS_POSMTXIDX) {
|
||||||
|
if (is_d3d)
|
||||||
|
{
|
||||||
|
WRITE(p, " float4 blend_indices : BLENDINDICES,\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
WRITE(p, " float fposmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
|
||||||
|
}
|
||||||
|
WRITE(p, " float4 rawpos : POSITION) {\n");
|
||||||
}
|
}
|
||||||
WRITE(p, " float4 rawpos : POSITION) {\n");
|
|
||||||
WRITE(p, "VS_OUTPUT o;\n");
|
WRITE(p, "VS_OUTPUT o;\n");
|
||||||
|
|
||||||
// transforms
|
// transforms
|
||||||
if (components & VB_HAS_POSMTXIDX)
|
if (components & VB_HAS_POSMTXIDX)
|
||||||
{
|
{
|
||||||
if (api_type & API_D3D9)
|
if (ApiType & API_D3D9)
|
||||||
{
|
{
|
||||||
WRITE(p, "int4 indices = D3DCOLORtoUBYTE4(blend_indices);\n");
|
WRITE(p, "int4 indices = D3DCOLORtoUBYTE4(blend_indices);\n");
|
||||||
WRITE(p, "int posmtx = indices.x;\n");
|
WRITE(p, "int posmtx = indices.x;\n");
|
||||||
}
|
}
|
||||||
else if (api_type == API_D3D11)
|
else if (ApiType == API_D3D11)
|
||||||
{
|
{
|
||||||
WRITE(p, "int posmtx = blend_indices.x * 255.0f;\n");
|
WRITE(p, "int posmtx = blend_indices.x * 255.0f;\n");
|
||||||
}
|
}
|
||||||
|
@ -493,7 +527,38 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
|
||||||
//seems to get rather complicated
|
//seems to get rather complicated
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, "return o;\n}\n");
|
if(ApiType == API_GLSL)
|
||||||
|
{
|
||||||
|
// Bit ugly here
|
||||||
|
// Will look better when we bind uniforms in GLSL 1.3
|
||||||
|
// clipPos/w needs to be done in pixel shader, not here
|
||||||
|
|
||||||
|
if (xfregs.numTexGen.numTexGens < 7) {
|
||||||
|
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
|
||||||
|
WRITE(p, " gl_TexCoord[%d].xyz = o.tex%d;\n", i, i);
|
||||||
|
WRITE(p, " gl_TexCoord[%d] = o.clipPos;\n", xfregs.numTexGen.numTexGens);
|
||||||
|
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
||||||
|
WRITE(p, " gl_TexCoord[%d] = o.Normal;\n", xfregs.numTexGen.numTexGens + 1);
|
||||||
|
} else {
|
||||||
|
// clip position is in w of first 4 texcoords
|
||||||
|
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; ++i)
|
||||||
|
WRITE(p, " gl_TexCoord[%d] = o.tex%d;\n", i, i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
|
||||||
|
WRITE(p, " gl_TexCoord[%d]%s = o.tex%d;\n", i, i < 4 ? ".xyzw" : ".xyz" , i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WRITE(p, "gl_FrontColor = o.colors_0;\n");
|
||||||
|
WRITE(p, "gl_FrontSecondaryColor = o.colors_1;\n");
|
||||||
|
WRITE(p, "gl_Position = o.pos;\n");
|
||||||
|
WRITE(p, "}\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
WRITE(p, "return o;\n}\n");
|
||||||
|
|
||||||
|
|
||||||
if (text[sizeof(text) - 1] != 0x7C)
|
if (text[sizeof(text) - 1] != 0x7C)
|
||||||
|
|
|
@ -47,7 +47,16 @@
|
||||||
#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES + 32)
|
#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES + 32)
|
||||||
#define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64)
|
#define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64)
|
||||||
#define C_VENVCONST_END (C_DEPTHPARAMS + 4)
|
#define C_VENVCONST_END (C_DEPTHPARAMS + 4)
|
||||||
|
const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
|
||||||
|
{I_PROJECTION , C_PROJECTION, 4 },
|
||||||
|
{I_MATERIALS, C_MATERIALS, 4 },
|
||||||
|
{I_LIGHTS, C_LIGHTS, 40 },
|
||||||
|
{I_TEXMATRICES, C_TEXMATRICES, 24 },
|
||||||
|
{I_TRANSFORMMATRICES , C_TRANSFORMMATRICES, 64 },
|
||||||
|
{I_NORMALMATRICES , C_NORMALMATRICES, 32 },
|
||||||
|
{I_POSTTRANSFORMMATRICES, C_POSTTRANSFORMMATRICES, 64 },
|
||||||
|
{I_DEPTHPARAMS, C_DEPTHPARAMS, 4 },
|
||||||
|
};
|
||||||
template<bool safe>
|
template<bool safe>
|
||||||
class _VERTEXSHADERUID
|
class _VERTEXSHADERUID
|
||||||
{
|
{
|
||||||
|
|
|
@ -152,5 +152,11 @@ inline unsigned int GetPow2(unsigned int val)
|
||||||
++ret;
|
++ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
struct s_svar
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
const unsigned int reg;
|
||||||
|
const unsigned int size;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // _VIDEOCOMMON_H
|
#endif // _VIDEOCOMMON_H
|
||||||
|
|
|
@ -151,6 +151,7 @@ void VideoConfig::GameIniLoad(const char *ini_file)
|
||||||
iniFile.GetIfExists("Video_Settings", "DisableFog", &bDisableFog);
|
iniFile.GetIfExists("Video_Settings", "DisableFog", &bDisableFog);
|
||||||
iniFile.GetIfExists("Video_Settings", "EnableOpenCL", &bEnableOpenCL);
|
iniFile.GetIfExists("Video_Settings", "EnableOpenCL", &bEnableOpenCL);
|
||||||
iniFile.GetIfExists("Video_Settings", "OMPDecoder", &bOMPDecoder);
|
iniFile.GetIfExists("Video_Settings", "OMPDecoder", &bOMPDecoder);
|
||||||
|
iniFile.GetIfExists("Video_Settings", "UseGLSL", &bUseGLSL);
|
||||||
|
|
||||||
iniFile.GetIfExists("Video_Enhancements", "ForceFiltering", &bForceFiltering);
|
iniFile.GetIfExists("Video_Enhancements", "ForceFiltering", &bForceFiltering);
|
||||||
iniFile.GetIfExists("Video_Enhancements", "MaxAnisotropy", &iMaxAnisotropy); // NOTE - this is x in (1 << x)
|
iniFile.GetIfExists("Video_Enhancements", "MaxAnisotropy", &iMaxAnisotropy); // NOTE - this is x in (1 << x)
|
||||||
|
@ -183,6 +184,7 @@ void VideoConfig::VerifyValidity()
|
||||||
if (!backend_info.bSupports3DVision) b3DVision = false;
|
if (!backend_info.bSupports3DVision) b3DVision = false;
|
||||||
if (!backend_info.bSupportsFormatReinterpretation) bEFBEmulateFormatChanges = false;
|
if (!backend_info.bSupportsFormatReinterpretation) bEFBEmulateFormatChanges = false;
|
||||||
if (!backend_info.bSupportsPixelLighting) bEnablePixelLighting = false;
|
if (!backend_info.bSupportsPixelLighting) bEnablePixelLighting = false;
|
||||||
|
if (!backend_info.bSupportsGLSL) bUseGLSL = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoConfig::Save(const char *ini_file)
|
void VideoConfig::Save(const char *ini_file)
|
||||||
|
@ -230,6 +232,7 @@ void VideoConfig::Save(const char *ini_file)
|
||||||
iniFile.Set("Settings", "DisableTexturing", bDisableTexturing);
|
iniFile.Set("Settings", "DisableTexturing", bDisableTexturing);
|
||||||
iniFile.Set("Settings", "DstAlphaPass", bDstAlphaPass);
|
iniFile.Set("Settings", "DstAlphaPass", bDstAlphaPass);
|
||||||
iniFile.Set("Settings", "DisableFog", bDisableFog);
|
iniFile.Set("Settings", "DisableFog", bDisableFog);
|
||||||
|
iniFile.Set("Settings", "bUseGLSL", bUseGLSL);
|
||||||
|
|
||||||
iniFile.Set("Settings", "EnableOpenCL", bEnableOpenCL);
|
iniFile.Set("Settings", "EnableOpenCL", bEnableOpenCL);
|
||||||
iniFile.Set("Settings", "OMPDecoder", bOMPDecoder);
|
iniFile.Set("Settings", "OMPDecoder", bOMPDecoder);
|
||||||
|
@ -296,6 +299,7 @@ void VideoConfig::GameIniSave(const char* default_ini, const char* game_ini)
|
||||||
SET_IF_DIFFERS("Video_Settings", "DisableFog", bDisableFog);
|
SET_IF_DIFFERS("Video_Settings", "DisableFog", bDisableFog);
|
||||||
SET_IF_DIFFERS("Video_Settings", "EnableOpenCL", bEnableOpenCL);
|
SET_IF_DIFFERS("Video_Settings", "EnableOpenCL", bEnableOpenCL);
|
||||||
SET_IF_DIFFERS("Video_Settings", "OMPDecoder", bOMPDecoder);
|
SET_IF_DIFFERS("Video_Settings", "OMPDecoder", bOMPDecoder);
|
||||||
|
SET_IF_DIFFERS("Video_Settings", "UseGLSL", bUseGLSL);
|
||||||
|
|
||||||
SET_IF_DIFFERS("Video_Enhancements", "ForceFiltering", bForceFiltering);
|
SET_IF_DIFFERS("Video_Enhancements", "ForceFiltering", bForceFiltering);
|
||||||
SET_IF_DIFFERS("Video_Enhancements", "MaxAnisotropy", iMaxAnisotropy); // NOTE - this is x in (1 << x)
|
SET_IF_DIFFERS("Video_Enhancements", "MaxAnisotropy", iMaxAnisotropy); // NOTE - this is x in (1 << x)
|
||||||
|
|
|
@ -106,6 +106,7 @@ struct VideoConfig
|
||||||
bool bDisableTexturing;
|
bool bDisableTexturing;
|
||||||
bool bDstAlphaPass;
|
bool bDstAlphaPass;
|
||||||
bool bDisableFog;
|
bool bDisableFog;
|
||||||
|
bool bUseGLSL;
|
||||||
|
|
||||||
// Utility
|
// Utility
|
||||||
bool bDumpTextures;
|
bool bDumpTextures;
|
||||||
|
@ -166,6 +167,7 @@ struct VideoConfig
|
||||||
bool bSupportsDualSourceBlend; // only supported by D3D11 and OpenGL
|
bool bSupportsDualSourceBlend; // only supported by D3D11 and OpenGL
|
||||||
bool bSupportsFormatReinterpretation;
|
bool bSupportsFormatReinterpretation;
|
||||||
bool bSupportsPixelLighting;
|
bool bSupportsPixelLighting;
|
||||||
|
bool bSupportsGLSL;
|
||||||
} backend_info;
|
} backend_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ void InitBackendInfo()
|
||||||
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
||||||
g_Config.backend_info.bSupportsFormatReinterpretation = true;
|
g_Config.backend_info.bSupportsFormatReinterpretation = true;
|
||||||
g_Config.backend_info.bSupportsPixelLighting = true;
|
g_Config.backend_info.bSupportsPixelLighting = true;
|
||||||
|
g_Config.backend_info.bSupportsGLSL = false;
|
||||||
|
|
||||||
IDXGIFactory* factory;
|
IDXGIFactory* factory;
|
||||||
IDXGIAdapter* ad;
|
IDXGIAdapter* ad;
|
||||||
|
|
|
@ -96,6 +96,7 @@ void InitBackendInfo()
|
||||||
g_Config.backend_info.bSupports3DVision = true;
|
g_Config.backend_info.bSupports3DVision = true;
|
||||||
g_Config.backend_info.bSupportsDualSourceBlend = false;
|
g_Config.backend_info.bSupportsDualSourceBlend = false;
|
||||||
g_Config.backend_info.bSupportsFormatReinterpretation = true;
|
g_Config.backend_info.bSupportsFormatReinterpretation = true;
|
||||||
|
g_Config.backend_info.bSupportsGLSL = false;
|
||||||
|
|
||||||
|
|
||||||
g_Config.backend_info.bSupportsPixelLighting = C_PLIGHTS + 40 <= maxConstants && C_PMATERIALS + 4 <= maxConstants;
|
g_Config.backend_info.bSupportsPixelLighting = C_PLIGHTS + 40 <= maxConstants && C_PMATERIALS + 4 <= maxConstants;
|
||||||
|
|
|
@ -4,6 +4,7 @@ set(SRCS Src/FramebufferManager.cpp
|
||||||
Src/NativeVertexFormat.cpp
|
Src/NativeVertexFormat.cpp
|
||||||
Src/PixelShaderCache.cpp
|
Src/PixelShaderCache.cpp
|
||||||
Src/PostProcessing.cpp
|
Src/PostProcessing.cpp
|
||||||
|
Src/ProgramShaderCache.cpp
|
||||||
Src/RasterFont.cpp
|
Src/RasterFont.cpp
|
||||||
Src/Render.cpp
|
Src/Render.cpp
|
||||||
Src/TextureCache.cpp
|
Src/TextureCache.cpp
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "x64Emitter.h"
|
#include "x64Emitter.h"
|
||||||
#include "ABI.h"
|
#include "ABI.h"
|
||||||
#include "MemoryUtil.h"
|
#include "MemoryUtil.h"
|
||||||
|
#include "ProgramShaderCache.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
|
|
||||||
#include "CPMemory.h"
|
#include "CPMemory.h"
|
||||||
|
@ -191,8 +192,15 @@ void GLVertexFormat::SetupVertexPointers() {
|
||||||
if (vtx_decl.num_normals >= 1) {
|
if (vtx_decl.num_normals >= 1) {
|
||||||
glNormalPointer(VarToGL(vtx_decl.normal_gl_type), vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[0]));
|
glNormalPointer(VarToGL(vtx_decl.normal_gl_type), vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[0]));
|
||||||
if (vtx_decl.num_normals == 3) {
|
if (vtx_decl.num_normals == 3) {
|
||||||
glVertexAttribPointer(SHADER_NORM1_ATTRIB, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[1]));
|
GLint varLocation1 = SHADER_NORM1_ATTRIB, varLocation2 = SHADER_NORM2_ATTRIB;
|
||||||
glVertexAttribPointer(SHADER_NORM2_ATTRIB, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[2]));
|
if(g_ActiveConfig.bUseGLSL){
|
||||||
|
varLocation1 = OGL::ProgramShaderCache::GetAttr(0);
|
||||||
|
varLocation2 = OGL::ProgramShaderCache::GetAttr(1);
|
||||||
|
}
|
||||||
|
if(varLocation1 > 0)
|
||||||
|
glVertexAttribPointer(varLocation1, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[1]));
|
||||||
|
if(varLocation2 > 0)
|
||||||
|
glVertexAttribPointer(varLocation2, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.normal_offset[2]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +224,11 @@ void GLVertexFormat::SetupVertexPointers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vtx_decl.posmtx_offset != -1) {
|
if (vtx_decl.posmtx_offset != -1) {
|
||||||
glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.posmtx_offset));
|
GLint varLocation = SHADER_POSMTX_ATTRIB;
|
||||||
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
|
varLocation = OGL::ProgramShaderCache::GetAttr(2);
|
||||||
|
if(varLocation > 0)
|
||||||
|
glVertexAttribPointer(varLocation, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (void *)(VertexManager::s_pBaseBufferPointer + vtx_decl.posmtx_offset));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Render.h"
|
#include "Render.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
|
#include "ProgramShaderCache.h"
|
||||||
#include "PixelShaderCache.h"
|
#include "PixelShaderCache.h"
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "FileUtil.h"
|
#include "FileUtil.h"
|
||||||
|
@ -47,326 +48,427 @@ bool PixelShaderCache::ShaderEnabled;
|
||||||
PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry = NULL;
|
PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry = NULL;
|
||||||
PIXELSHADERUID PixelShaderCache::last_uid;
|
PIXELSHADERUID PixelShaderCache::last_uid;
|
||||||
|
|
||||||
|
void(*pSetPSConstant4f)(unsigned int, float, float, float, float);
|
||||||
|
void(*pSetPSConstant4fv)(unsigned int, const float*);
|
||||||
|
void(*pSetMultiPSConstant4fv)(unsigned int, unsigned int, const float*);
|
||||||
|
|
||||||
GLuint PixelShaderCache::GetDepthMatrixProgram()
|
GLuint PixelShaderCache::GetDepthMatrixProgram()
|
||||||
{
|
{
|
||||||
return s_DepthMatrixProgram;
|
return s_DepthMatrixProgram;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint PixelShaderCache::GetColorMatrixProgram()
|
GLuint PixelShaderCache::GetColorMatrixProgram()
|
||||||
{
|
{
|
||||||
return s_ColorMatrixProgram;
|
return s_ColorMatrixProgram;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelShaderCache::Init()
|
void PixelShaderCache::Init()
|
||||||
{
|
{
|
||||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||||
ShaderEnabled = true;
|
ShaderEnabled = true;
|
||||||
CurrentShader = 0;
|
CurrentShader = 0;
|
||||||
last_entry = NULL;
|
last_entry = NULL;
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
|
|
||||||
s_displayCompileAlert = true;
|
s_displayCompileAlert = true;
|
||||||
|
|
||||||
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions);
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
|
{
|
||||||
if(s_nMaxPixelInstructions == 0) // Some combination of drivers and hardware returns zero for some reason.
|
pSetPSConstant4f = SetGLSLPSConstant4f;
|
||||||
s_nMaxPixelInstructions = 4096;
|
pSetPSConstant4fv = SetGLSLPSConstant4fv;
|
||||||
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096;
|
pSetMultiPSConstant4fv = SetMultiGLSLPSConstant4fv;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pSetPSConstant4f = SetCGPSConstant4f;
|
||||||
|
pSetPSConstant4fv = SetCGPSConstant4fv;
|
||||||
|
pSetMultiPSConstant4fv = SetMultiCGPSConstant4fv;
|
||||||
|
}
|
||||||
|
|
||||||
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions);
|
||||||
|
|
||||||
|
if(s_nMaxPixelInstructions == 0) // Some combination of drivers and hardware returns zero for some reason.
|
||||||
|
s_nMaxPixelInstructions = 4096;
|
||||||
|
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096;
|
||||||
#if CG_VERSION_NUM == 2100
|
#if CG_VERSION_NUM == 2100
|
||||||
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
|
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
|
||||||
{
|
{
|
||||||
s_nMaxPixelInstructions = 4096;
|
s_nMaxPixelInstructions = 4096;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int maxinst, maxattribs;
|
int maxinst, maxattribs;
|
||||||
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&maxinst);
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&maxinst);
|
||||||
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, (GLint *)&maxattribs);
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, (GLint *)&maxattribs);
|
||||||
INFO_LOG(VIDEO, "pixel max_alu=%d, max_inst=%d, max_attrib=%d", s_nMaxPixelInstructions, maxinst, maxattribs);
|
INFO_LOG(VIDEO, "pixel max_alu=%d, max_inst=%d, max_attrib=%d", s_nMaxPixelInstructions, maxinst, maxattribs);
|
||||||
|
|
||||||
char pmatrixprog[2048];
|
|
||||||
sprintf(pmatrixprog, "!!ARBfp1.0"
|
|
||||||
"TEMP R0;\n"
|
|
||||||
"TEMP R1;\n"
|
|
||||||
"PARAM K0 = { 0.5, 0.5, 0.5, 0.5};\n"
|
|
||||||
"TEX R0, fragment.texcoord[0], texture[0], RECT;\n"
|
|
||||||
"MUL R0, R0, program.env[%d];\n"
|
|
||||||
"ADD R0, R0, K0;\n"
|
|
||||||
"FLR R0, R0;\n"
|
|
||||||
"MUL R0, R0, program.env[%d];\n"
|
|
||||||
"DP4 R1.x, R0, program.env[%d];\n"
|
|
||||||
"DP4 R1.y, R0, program.env[%d];\n"
|
|
||||||
"DP4 R1.z, R0, program.env[%d];\n"
|
|
||||||
"DP4 R1.w, R0, program.env[%d];\n"
|
|
||||||
"ADD result.color, R1, program.env[%d];\n"
|
|
||||||
"END\n",C_COLORMATRIX+5,C_COLORMATRIX+6, C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+2, C_COLORMATRIX+3, C_COLORMATRIX+4);
|
|
||||||
glGenProgramsARB(1, &s_ColorMatrixProgram);
|
|
||||||
SetCurrentShader(s_ColorMatrixProgram);
|
|
||||||
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
|
|
||||||
|
|
||||||
GLenum err = GL_REPORT_ERROR();
|
char pmatrixprog[2048];
|
||||||
if (err != GL_NO_ERROR) {
|
sprintf(pmatrixprog, "!!ARBfp1.0"
|
||||||
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
|
"TEMP R0;\n"
|
||||||
glDeleteProgramsARB(1, &s_ColorMatrixProgram);
|
"TEMP R1;\n"
|
||||||
s_ColorMatrixProgram = 0;
|
"PARAM K0 = { 0.5, 0.5, 0.5, 0.5};\n"
|
||||||
}
|
"TEX R0, fragment.texcoord[0], texture[0], RECT;\n"
|
||||||
|
"MUL R0, R0, program.env[%d];\n"
|
||||||
|
"ADD R0, R0, K0;\n"
|
||||||
|
"FLR R0, R0;\n"
|
||||||
|
"MUL R0, R0, program.env[%d];\n"
|
||||||
|
"DP4 R1.x, R0, program.env[%d];\n"
|
||||||
|
"DP4 R1.y, R0, program.env[%d];\n"
|
||||||
|
"DP4 R1.z, R0, program.env[%d];\n"
|
||||||
|
"DP4 R1.w, R0, program.env[%d];\n"
|
||||||
|
"ADD result.color, R1, program.env[%d];\n"
|
||||||
|
"END\n",C_COLORMATRIX+5,C_COLORMATRIX+6, C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+2, C_COLORMATRIX+3, C_COLORMATRIX+4);
|
||||||
|
glGenProgramsARB(1, &s_ColorMatrixProgram);
|
||||||
|
SetCurrentShader(s_ColorMatrixProgram);
|
||||||
|
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
|
||||||
|
|
||||||
sprintf(pmatrixprog, "!!ARBfp1.0\n"
|
GLenum err = GL_REPORT_ERROR();
|
||||||
"TEMP R0;\n"
|
if (err != GL_NO_ERROR) {
|
||||||
"TEMP R1;\n"
|
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
|
||||||
"TEMP R2;\n"
|
glDeleteProgramsARB(1, &s_ColorMatrixProgram);
|
||||||
//16777215/16777216*256, 1/255, 256, 0
|
s_ColorMatrixProgram = 0;
|
||||||
"PARAM K0 = { 255.99998474121, 0.003921568627451, 256.0, 0.0};\n"
|
}
|
||||||
"PARAM K1 = { 15.0, 0.066666666666, 0.0, 0.0};\n"
|
|
||||||
//sample the depth value
|
|
||||||
"TEX R2, fragment.texcoord[0], texture[0], RECT;\n"
|
|
||||||
|
|
||||||
//scale from [0*16777216..1*16777216] to
|
sprintf(pmatrixprog, "!!ARBfp1.0\n"
|
||||||
//[0*16777215..1*16777215], multiply by 256
|
"TEMP R0;\n"
|
||||||
"MUL R0, R2.x, K0.x;\n" // *16777215/16777216*256
|
"TEMP R1;\n"
|
||||||
|
"TEMP R2;\n"
|
||||||
|
//16777215/16777216*256, 1/255, 256, 0
|
||||||
|
"PARAM K0 = { 255.99998474121, 0.003921568627451, 256.0, 0.0};\n"
|
||||||
|
"PARAM K1 = { 15.0, 0.066666666666, 0.0, 0.0};\n"
|
||||||
|
//sample the depth value
|
||||||
|
"TEX R2, fragment.texcoord[0], texture[0], RECT;\n"
|
||||||
|
|
||||||
//It is easy to get bad results due to low precision
|
//scale from [0*16777216..1*16777216] to
|
||||||
//here, for example converting like this:
|
//[0*16777215..1*16777215], multiply by 256
|
||||||
//MUL R0,R0,{ 65536, 256, 1, 16777216 }
|
"MUL R0, R2.x, K0.x;\n" // *16777215/16777216*256
|
||||||
//FRC R0,R0
|
|
||||||
//gives {?, 128/255, 254/255, ?} for depth value 254/255
|
|
||||||
//on some gpus
|
|
||||||
|
|
||||||
"FLR R0.x,R0;\n" //bits 31..24
|
//It is easy to get bad results due to low precision
|
||||||
|
//here, for example converting like this:
|
||||||
|
//MUL R0,R0,{ 65536, 256, 1, 16777216 }
|
||||||
|
//FRC R0,R0
|
||||||
|
//gives {?, 128/255, 254/255, ?} for depth value 254/255
|
||||||
|
//on some gpus
|
||||||
|
|
||||||
"SUB R0.yzw,R0,R0.x;\n" //subtract bits 31..24 from rest
|
"FLR R0.x,R0;\n" //bits 31..24
|
||||||
"MUL R0.yzw,R0,K0.z;\n" // *256
|
|
||||||
"FLR R0.y,R0;\n" //bits 23..16
|
|
||||||
|
|
||||||
"SUB R0.zw,R0,R0.y;\n" //subtract bits 23..16 from rest
|
"SUB R0.yzw,R0,R0.x;\n" //subtract bits 31..24 from rest
|
||||||
"MUL R0.zw,R0,K0.z;\n" // *256
|
"MUL R0.yzw,R0,K0.z;\n" // *256
|
||||||
"FLR R0.z,R0;\n" //bits 15..8
|
"FLR R0.y,R0;\n" //bits 23..16
|
||||||
|
|
||||||
"MOV R0.w,R0.x;\n" //duplicate bit 31..24
|
"SUB R0.zw,R0,R0.y;\n" //subtract bits 23..16 from rest
|
||||||
|
"MUL R0.zw,R0,K0.z;\n" // *256
|
||||||
"MUL R0,R0,K0.y;\n" // /255
|
"FLR R0.z,R0;\n" //bits 15..8
|
||||||
|
|
||||||
"MUL R0.w,R0,K1.x;\n" // *15
|
"MOV R0.w,R0.x;\n" //duplicate bit 31..24
|
||||||
"FLR R0.w,R0;\n" //bits 31..28
|
|
||||||
"MUL R0.w,R0,K1.y;\n" // /15
|
|
||||||
|
|
||||||
"DP4 R1.x, R0, program.env[%d];\n"
|
"MUL R0,R0,K0.y;\n" // /255
|
||||||
"DP4 R1.y, R0, program.env[%d];\n"
|
|
||||||
"DP4 R1.z, R0, program.env[%d];\n"
|
"MUL R0.w,R0,K1.x;\n" // *15
|
||||||
"DP4 R1.w, R0, program.env[%d];\n"
|
"FLR R0.w,R0;\n" //bits 31..28
|
||||||
"ADD result.color, R1, program.env[%d];\n"
|
"MUL R0.w,R0,K1.y;\n" // /15
|
||||||
"END\n", C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+2, C_COLORMATRIX+3, C_COLORMATRIX+4);
|
|
||||||
glGenProgramsARB(1, &s_DepthMatrixProgram);
|
"DP4 R1.x, R0, program.env[%d];\n"
|
||||||
SetCurrentShader(s_DepthMatrixProgram);
|
"DP4 R1.y, R0, program.env[%d];\n"
|
||||||
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
|
"DP4 R1.z, R0, program.env[%d];\n"
|
||||||
|
"DP4 R1.w, R0, program.env[%d];\n"
|
||||||
|
"ADD result.color, R1, program.env[%d];\n"
|
||||||
|
"END\n", C_COLORMATRIX, C_COLORMATRIX+1, C_COLORMATRIX+2, C_COLORMATRIX+3, C_COLORMATRIX+4);
|
||||||
|
glGenProgramsARB(1, &s_DepthMatrixProgram);
|
||||||
|
SetCurrentShader(s_DepthMatrixProgram);
|
||||||
|
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
|
||||||
|
|
||||||
|
err = GL_REPORT_ERROR();
|
||||||
|
if (err != GL_NO_ERROR) {
|
||||||
|
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
|
||||||
|
glDeleteProgramsARB(1, &s_DepthMatrixProgram);
|
||||||
|
s_DepthMatrixProgram = 0;
|
||||||
|
}
|
||||||
|
|
||||||
err = GL_REPORT_ERROR();
|
|
||||||
if (err != GL_NO_ERROR) {
|
|
||||||
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
|
|
||||||
glDeleteProgramsARB(1, &s_DepthMatrixProgram);
|
|
||||||
s_DepthMatrixProgram = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelShaderCache::Shutdown()
|
void PixelShaderCache::Shutdown()
|
||||||
{
|
{
|
||||||
glDeleteProgramsARB(1, &s_ColorMatrixProgram);
|
glDeleteProgramsARB(1, &s_ColorMatrixProgram);
|
||||||
s_ColorMatrixProgram = 0;
|
s_ColorMatrixProgram = 0;
|
||||||
glDeleteProgramsARB(1, &s_DepthMatrixProgram);
|
glDeleteProgramsARB(1, &s_DepthMatrixProgram);
|
||||||
s_DepthMatrixProgram = 0;
|
s_DepthMatrixProgram = 0;
|
||||||
PSCache::iterator iter = PixelShaders.begin();
|
PSCache::iterator iter = PixelShaders.begin();
|
||||||
for (; iter != PixelShaders.end(); iter++)
|
for (; iter != PixelShaders.end(); iter++)
|
||||||
iter->second.Destroy();
|
iter->second.Destroy();
|
||||||
PixelShaders.clear();
|
PixelShaders.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
||||||
{
|
{
|
||||||
PIXELSHADERUID uid;
|
PIXELSHADERUID uid;
|
||||||
GetPixelShaderId(&uid, dstAlphaMode, components);
|
GetPixelShaderId(&uid, dstAlphaMode, components);
|
||||||
|
|
||||||
// Check if the shader is already set
|
|
||||||
if (last_entry)
|
|
||||||
{
|
|
||||||
if (uid == last_uid)
|
|
||||||
{
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
|
||||||
ValidatePixelShaderIDs(API_OPENGL, last_entry->safe_uid, last_entry->shader.strprog, dstAlphaMode, components);
|
|
||||||
return &last_entry->shader;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
last_uid = uid;
|
// Check if the shader is already set
|
||||||
|
if (last_entry)
|
||||||
|
{
|
||||||
|
if (uid == last_uid)
|
||||||
|
{
|
||||||
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
|
ValidatePixelShaderIDs(API_OPENGL, last_entry->safe_uid, last_entry->shader.strprog, dstAlphaMode, components);
|
||||||
|
return &last_entry->shader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PSCache::iterator iter = PixelShaders.find(uid);
|
last_uid = uid;
|
||||||
if (iter != PixelShaders.end())
|
|
||||||
{
|
|
||||||
PSCacheEntry &entry = iter->second;
|
|
||||||
last_entry = &entry;
|
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
PSCache::iterator iter = PixelShaders.find(uid);
|
||||||
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components);
|
if (iter != PixelShaders.end())
|
||||||
return &last_entry->shader;
|
{
|
||||||
}
|
PSCacheEntry &entry = iter->second;
|
||||||
|
last_entry = &entry;
|
||||||
|
|
||||||
// Make an entry in the table
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
PSCacheEntry& newentry = PixelShaders[uid];
|
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components);
|
||||||
last_entry = &newentry;
|
return &last_entry->shader;
|
||||||
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components);
|
}
|
||||||
|
|
||||||
if (g_ActiveConfig.bEnableShaderDebugging && code)
|
// Make an entry in the table
|
||||||
{
|
PSCacheEntry& newentry = PixelShaders[uid];
|
||||||
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components);
|
last_entry = &newentry;
|
||||||
newentry.shader.strprog = code;
|
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components);
|
||||||
}
|
|
||||||
|
if (g_ActiveConfig.bEnableShaderDebugging && code)
|
||||||
|
{
|
||||||
|
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components);
|
||||||
|
newentry.shader.strprog = code;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
|
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
char szTemp[MAX_PATH];
|
char szTemp[MAX_PATH];
|
||||||
sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
||||||
|
|
||||||
SaveData(szTemp, code);
|
SaveData(szTemp, code);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!code || !CompilePixelShader(newentry.shader, code)) {
|
if (!code || !CompilePixelShader(newentry.shader, code)) {
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
INCSTAT(stats.numPixelShadersCreated);
|
INCSTAT(stats.numPixelShadersCreated);
|
||||||
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
|
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
return &last_entry->shader;
|
return &last_entry->shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||||
{
|
{
|
||||||
GLenum err = GL_REPORT_ERROR();
|
GLenum err = GL_REPORT_ERROR();
|
||||||
if (err != GL_NO_ERROR)
|
if (err != GL_NO_ERROR)
|
||||||
{
|
{
|
||||||
ERROR_LOG(VIDEO, "glError %08x before PS!", err);
|
ERROR_LOG(VIDEO, "glError %08x before PS!", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined HAVE_CG && HAVE_CG
|
#if defined HAVE_CG && HAVE_CG
|
||||||
char stropt[128];
|
char stropt[128];
|
||||||
sprintf(stropt, "MaxLocalParams=32,NumInstructionSlots=%d", s_nMaxPixelInstructions);
|
sprintf(stropt, "MaxLocalParams=32,NumInstructionSlots=%d", s_nMaxPixelInstructions);
|
||||||
const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
|
const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
|
||||||
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", opts);
|
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", opts);
|
||||||
|
|
||||||
// handle errors
|
// handle errors
|
||||||
if (!cgIsProgram(tempprog))
|
if (!cgIsProgram(tempprog))
|
||||||
{
|
{
|
||||||
cgDestroyProgram(tempprog);
|
cgDestroyProgram(tempprog);
|
||||||
|
|
||||||
static int num_failures = 0;
|
static int num_failures = 0;
|
||||||
char szTemp[MAX_PATH];
|
char szTemp[MAX_PATH];
|
||||||
sprintf(szTemp, "%sbad_ps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
|
sprintf(szTemp, "%sbad_ps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
|
||||||
std::ofstream file(szTemp);
|
std::ofstream file(szTemp);
|
||||||
file << pstrprogram;
|
file << pstrprogram;
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
PanicAlert("Failed to compile pixel shader!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
|
PanicAlert("Failed to compile pixel shader!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
|
||||||
szTemp,
|
szTemp,
|
||||||
g_cgfProf,
|
g_cgfProf,
|
||||||
cgGetLastListing(g_cgcontext));
|
cgGetLastListing(g_cgcontext));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle warnings
|
// handle warnings
|
||||||
if (cgGetError() != CG_NO_ERROR)
|
if (cgGetError() != CG_NO_ERROR)
|
||||||
{
|
{
|
||||||
WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext));
|
WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext));
|
||||||
WARN_LOG(VIDEO, "%s", pstrprogram);
|
WARN_LOG(VIDEO, "%s", pstrprogram);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
|
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
|
||||||
// It SHOULD not have any nasty side effects though - but you never know...
|
// It SHOULD not have any nasty side effects though - but you never know...
|
||||||
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
|
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
|
||||||
char *plocal = strstr(pcompiledprog, "program.local");
|
char *plocal = strstr(pcompiledprog, "program.local");
|
||||||
while (plocal != NULL)
|
while (plocal != NULL)
|
||||||
{
|
{
|
||||||
const char *penv = " program.env";
|
const char *penv = " program.env";
|
||||||
memcpy(plocal, penv, 13);
|
memcpy(plocal, penv, 13);
|
||||||
plocal = strstr(plocal+13, "program.local");
|
plocal = strstr(plocal+13, "program.local");
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenProgramsARB(1, &ps.glprogid);
|
glGenProgramsARB(1, &ps.glprogid);
|
||||||
SetCurrentShader(ps.glprogid);
|
SetCurrentShader(ps.glprogid);
|
||||||
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
|
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
|
||||||
|
|
||||||
err = GL_REPORT_ERROR();
|
err = GL_REPORT_ERROR();
|
||||||
if (err != GL_NO_ERROR)
|
if (err != GL_NO_ERROR)
|
||||||
{
|
{
|
||||||
GLint error_pos, native_limit;
|
GLint error_pos, native_limit;
|
||||||
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
|
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
|
||||||
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit);
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit);
|
||||||
// Error occur
|
// Error occur
|
||||||
if (error_pos != -1) {
|
if (error_pos != -1) {
|
||||||
const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
||||||
char line[256];
|
char line[256];
|
||||||
strncpy(line, (const char *)pcompiledprog + error_pos, 255);
|
strncpy(line, (const char *)pcompiledprog + error_pos, 255);
|
||||||
line[255] = 0;
|
line[255] = 0;
|
||||||
ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error);
|
ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error);
|
||||||
ERROR_LOG(VIDEO, "Line dump: \n%s", line);
|
ERROR_LOG(VIDEO, "Line dump: \n%s", line);
|
||||||
} else if (native_limit != -1) {
|
} else if (native_limit != -1) {
|
||||||
ERROR_LOG(VIDEO, "Hit limit? %i", native_limit);
|
ERROR_LOG(VIDEO, "Hit limit? %i", native_limit);
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
||||||
ERROR_LOG(VIDEO, "%s", pcompiledprog);
|
ERROR_LOG(VIDEO, "%s", pcompiledprog);
|
||||||
}
|
}
|
||||||
|
|
||||||
cgDestroyProgram(tempprog);
|
cgDestroyProgram(tempprog);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Disable Fragment programs and reset the selected Program
|
//Disable Fragment programs and reset the selected Program
|
||||||
void PixelShaderCache::DisableShader()
|
void PixelShaderCache::DisableShader()
|
||||||
{
|
{
|
||||||
if(ShaderEnabled)
|
if(ShaderEnabled)
|
||||||
{
|
{
|
||||||
glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
||||||
ShaderEnabled = false;
|
ShaderEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//bind a program if is diferent from the binded oone
|
//bind a program if is diferent from the binded oone
|
||||||
void PixelShaderCache::SetCurrentShader(GLuint Shader)
|
void PixelShaderCache::SetCurrentShader(GLuint Shader)
|
||||||
{
|
{
|
||||||
if(!ShaderEnabled)
|
if(!ShaderEnabled)
|
||||||
{
|
{
|
||||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||||
ShaderEnabled = true;
|
ShaderEnabled = true;
|
||||||
}
|
}
|
||||||
if(CurrentShader != Shader)
|
if(CurrentShader != Shader)
|
||||||
{
|
{
|
||||||
if(Shader != 0)
|
if(Shader != 0)
|
||||||
CurrentShader = Shader;
|
CurrentShader = Shader;
|
||||||
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
|
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// GLSL Specific
|
||||||
|
void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex)
|
||||||
|
{
|
||||||
|
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
|
for(int a = 0; a < NUM_UNIFORMS; ++a)
|
||||||
|
if(!strcmp(name, UniformNames[a]))
|
||||||
|
{
|
||||||
|
if(tmp.UniformLocations[a] == -1)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glUniform1i(tmp.UniformLocations[a], Tex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
||||||
|
{
|
||||||
|
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
|
for(int a = 0; a < NUM_UNIFORMS; ++a)
|
||||||
|
if(!strcmp(name, UniformNames[a]))
|
||||||
|
{
|
||||||
|
if(tmp.UniformLocations[a] == -1)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||||
|
{
|
||||||
|
float f[4] = { f1, f2, f3, f4 };
|
||||||
|
for( unsigned int a = 0; a < 10; ++a)
|
||||||
|
{
|
||||||
|
if( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
||||||
|
{
|
||||||
|
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
||||||
|
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
|
||||||
|
{
|
||||||
|
for( unsigned int a = 0; a < 10; ++a)
|
||||||
|
{
|
||||||
|
if( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
||||||
|
{
|
||||||
|
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
||||||
|
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
|
{
|
||||||
|
for( unsigned int a = 0; a < 10; ++a)
|
||||||
|
{
|
||||||
|
if( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
||||||
|
{
|
||||||
|
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
||||||
|
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// CG Specific
|
||||||
|
void SetCGPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||||
|
{
|
||||||
|
float f[4] = { f1, f2, f3, f4 };
|
||||||
|
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetCGPSConstant4fv(unsigned int const_number, const float *f)
|
||||||
|
{
|
||||||
|
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetMultiCGPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < count; i++,f+=4)
|
||||||
|
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f);
|
||||||
|
}
|
||||||
|
// Renderer functions
|
||||||
void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||||
{
|
{
|
||||||
float f[4] = { f1, f2, f3, f4 };
|
pSetPSConstant4f(const_number, f1, f2, f3, f4);
|
||||||
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetPSConstant4fv(unsigned int const_number, const float *f)
|
void Renderer::SetPSConstant4fv(unsigned int const_number, const float *f)
|
||||||
{
|
{
|
||||||
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
|
pSetPSConstant4fv(const_number, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < count; i++,f+=4)
|
pSetMultiPSConstant4fv(const_number, count, f);
|
||||||
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace OGL
|
} // namespace OGL
|
||||||
|
|
|
@ -73,6 +73,8 @@ class PixelShaderCache
|
||||||
public:
|
public:
|
||||||
static void Init();
|
static void Init();
|
||||||
static void Shutdown();
|
static void Shutdown();
|
||||||
|
// This is a GLSL only function
|
||||||
|
static void SetPSSampler(const char * name, unsigned int Tex);
|
||||||
|
|
||||||
static FRAGMENTSHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
|
static FRAGMENTSHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
static bool CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram);
|
static bool CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram);
|
||||||
|
@ -85,7 +87,15 @@ public:
|
||||||
|
|
||||||
static void DisableShader();
|
static void DisableShader();
|
||||||
};
|
};
|
||||||
|
// GLSL Specific
|
||||||
|
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
|
||||||
|
void SetGLSLPSConstant4fv(unsigned int const_number, const float *f);
|
||||||
|
void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
|
|
||||||
|
//CG Specific
|
||||||
|
void SetCGPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
|
||||||
|
void SetCGPSConstant4fv(unsigned int const_number, const float *f);
|
||||||
|
void SetMultiCGPSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
} // namespace OGL
|
} // namespace OGL
|
||||||
|
|
||||||
#endif // _PIXELSHADERCACHE_H_
|
#endif // _PIXELSHADERCACHE_H_
|
||||||
|
|
|
@ -0,0 +1,150 @@
|
||||||
|
// Copyright (C) 2003 Dolphin Project.
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, version 2.0.
|
||||||
|
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License 2.0 for more details.
|
||||||
|
|
||||||
|
// A copy of the GPL 2.0 should have been included with the program.
|
||||||
|
// If not, see http://www.gnu.org/licenses/
|
||||||
|
|
||||||
|
// Official SVN repository and contact information can be found at
|
||||||
|
// http://code.google.com/p/dolphin-emu/
|
||||||
|
#include "ProgramShaderCache.h"
|
||||||
|
|
||||||
|
namespace OGL
|
||||||
|
{
|
||||||
|
GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0;
|
||||||
|
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
||||||
|
|
||||||
|
std::pair<u64, u64> ProgramShaderCache::CurrentShaderProgram;
|
||||||
|
const char *UniformNames[NUM_UNIFORMS] = {
|
||||||
|
// SAMPLERS
|
||||||
|
"samp0","samp1","samp2","samp3","samp4","samp5","samp6","samp7",
|
||||||
|
// PIXEL SHADER UNIFORMS
|
||||||
|
I_COLORS,
|
||||||
|
I_KCOLORS,
|
||||||
|
I_ALPHA,
|
||||||
|
I_TEXDIMS,
|
||||||
|
I_ZBIAS ,
|
||||||
|
I_INDTEXSCALE ,
|
||||||
|
I_INDTEXMTX,
|
||||||
|
I_FOG,
|
||||||
|
I_PLIGHTS,
|
||||||
|
I_PMATERIALS,
|
||||||
|
// VERTEX SHADER UNIFORMS
|
||||||
|
I_POSNORMALMATRIX,
|
||||||
|
I_PROJECTION ,
|
||||||
|
I_MATERIALS,
|
||||||
|
I_LIGHTS,
|
||||||
|
I_TEXMATRICES,
|
||||||
|
I_TRANSFORMMATRICES ,
|
||||||
|
I_NORMALMATRICES ,
|
||||||
|
I_POSTTRANSFORMMATRICES,
|
||||||
|
I_DEPTHPARAMS,
|
||||||
|
};
|
||||||
|
|
||||||
|
void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS)
|
||||||
|
{
|
||||||
|
PROGRAMUID uid;
|
||||||
|
CurrentFShader = PS;
|
||||||
|
CurrentVShader = VS;
|
||||||
|
|
||||||
|
|
||||||
|
GetProgramShaderId(&uid, CurrentVShader, CurrentFShader);
|
||||||
|
|
||||||
|
if(uid.uid.id == 0)
|
||||||
|
{
|
||||||
|
CurrentProgram = 0;
|
||||||
|
glUseProgram(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fragment shaders can survive without Vertex Shaders
|
||||||
|
// We have a valid fragment shader, let's create our program
|
||||||
|
std::pair<u64, u64> ShaderPair = std::make_pair(uid.uid.psid, uid.uid.vsid);
|
||||||
|
PCache::iterator iter = pshaders.find(ShaderPair);
|
||||||
|
if (iter != pshaders.end())
|
||||||
|
{
|
||||||
|
PCacheEntry &entry = iter->second;
|
||||||
|
glUseProgram(entry.program.glprogid);
|
||||||
|
CurrentShaderProgram = ShaderPair;
|
||||||
|
CurrentProgram = entry.program.glprogid;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PCacheEntry entry;
|
||||||
|
entry.program.vsid = CurrentVShader;
|
||||||
|
entry.program.psid = CurrentFShader;
|
||||||
|
entry.program.glprogid = glCreateProgram();
|
||||||
|
|
||||||
|
// Right, the program is created now
|
||||||
|
// Let's attach everything
|
||||||
|
if(entry.program.vsid != 0) // attaching zero vertex shader makes it freak out
|
||||||
|
glAttachShader(entry.program.glprogid, entry.program.vsid);
|
||||||
|
glAttachShader(entry.program.glprogid, entry.program.psid);
|
||||||
|
glLinkProgram(entry.program.glprogid);
|
||||||
|
//checkForGLError("linking program");
|
||||||
|
glUseProgram(entry.program.glprogid);
|
||||||
|
//checkForGLError("using program");
|
||||||
|
|
||||||
|
// We cache our uniform locations for now
|
||||||
|
// Once we move up to a newer version of GLSL, ~1.30
|
||||||
|
// We can remove this
|
||||||
|
|
||||||
|
//For some reason this fails on my hardware
|
||||||
|
//glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations);
|
||||||
|
//Got to do it this crappy way.
|
||||||
|
for(int a = 0; a < NUM_UNIFORMS; ++a)
|
||||||
|
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
|
||||||
|
|
||||||
|
// Need to get some attribute locations
|
||||||
|
if(uid.uid.vsid != 0) // We have no vertex Shader
|
||||||
|
{
|
||||||
|
entry.program.attrLoc[0] = glGetAttribLocation(entry.program.glprogid, "rawnorm1");
|
||||||
|
entry.program.attrLoc[1] = glGetAttribLocation(entry.program.glprogid, "rawnorm2");
|
||||||
|
entry.program.attrLoc[2] = glGetAttribLocation(entry.program.glprogid, "fposmtx");
|
||||||
|
if(entry.program.attrLoc[0] > 0)
|
||||||
|
glEnableVertexAttribArray(entry.program.attrLoc[0]);
|
||||||
|
if(entry.program.attrLoc[1] > 0)
|
||||||
|
glEnableVertexAttribArray(entry.program.attrLoc[1]);
|
||||||
|
if(entry.program.attrLoc[2] > 0)
|
||||||
|
glEnableVertexAttribArray(entry.program.attrLoc[2]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
entry.program.attrLoc[0] = entry.program.attrLoc[1] = entry.program.attrLoc[2] = 0;
|
||||||
|
|
||||||
|
|
||||||
|
pshaders[ShaderPair] = entry;
|
||||||
|
CurrentShaderProgram = ShaderPair;
|
||||||
|
CurrentProgram = entry.program.glprogid;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; }
|
||||||
|
|
||||||
|
GLint ProgramShaderCache::GetAttr(int num)
|
||||||
|
{
|
||||||
|
return pshaders[CurrentShaderProgram].program.attrLoc[num];
|
||||||
|
}
|
||||||
|
PROGRAMSHADER ProgramShaderCache::GetShaderProgram()
|
||||||
|
{
|
||||||
|
return pshaders[CurrentShaderProgram].program;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramShaderCache::Shutdown(void)
|
||||||
|
{
|
||||||
|
PCache::iterator iter = pshaders.begin();
|
||||||
|
for (; iter != pshaders.end(); iter++)
|
||||||
|
iter->second.Destroy();
|
||||||
|
pshaders.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p)
|
||||||
|
{
|
||||||
|
uid->uid.vsid = _v;
|
||||||
|
uid->uid.psid = _p;
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
// Copyright (C) 2003 Dolphin Project.
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, version 2.0.
|
||||||
|
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License 2.0 for more details.
|
||||||
|
|
||||||
|
// A copy of the GPL 2.0 should have been included with the program.
|
||||||
|
// If not, see http://www.gnu.org/licenses/
|
||||||
|
|
||||||
|
// Official SVN repository and contact information can be found at
|
||||||
|
// http://code.google.com/p/dolphin-emu/
|
||||||
|
|
||||||
|
#ifndef _ProgramShaderCache_H_
|
||||||
|
#define _ProgramShaderCache_H_
|
||||||
|
|
||||||
|
#include "GLUtil.h"
|
||||||
|
|
||||||
|
#include "VertexShaderCache.h"
|
||||||
|
#include "PixelShaderCache.h"
|
||||||
|
#include "PixelShaderGen.h"
|
||||||
|
#include "VertexShaderGen.h"
|
||||||
|
|
||||||
|
union PID
|
||||||
|
{
|
||||||
|
struct {
|
||||||
|
GLuint vsid, psid;
|
||||||
|
};
|
||||||
|
u64 id;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PROGRAMUID
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
PID uid;
|
||||||
|
|
||||||
|
PROGRAMUID()
|
||||||
|
{
|
||||||
|
uid.id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PROGRAMUID(const PROGRAMUID& r)
|
||||||
|
{
|
||||||
|
uid.id = r.uid.id;
|
||||||
|
}
|
||||||
|
PROGRAMUID(GLuint _v, GLuint _p)
|
||||||
|
{
|
||||||
|
uid.vsid = _v;
|
||||||
|
uid.psid = _p;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetNumValues() const
|
||||||
|
{
|
||||||
|
return uid.id;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p);
|
||||||
|
|
||||||
|
namespace OGL
|
||||||
|
{
|
||||||
|
#define NUM_UNIFORMS 27
|
||||||
|
extern const char *UniformNames[NUM_UNIFORMS];
|
||||||
|
|
||||||
|
|
||||||
|
struct PROGRAMSHADER
|
||||||
|
{
|
||||||
|
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0){}
|
||||||
|
GLuint glprogid; // opengl program id
|
||||||
|
GLuint vsid, psid;
|
||||||
|
GLint attrLoc[3];
|
||||||
|
GLint UniformLocations[NUM_UNIFORMS];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ProgramShaderCache
|
||||||
|
{
|
||||||
|
struct PCacheEntry
|
||||||
|
{
|
||||||
|
PROGRAMSHADER program;
|
||||||
|
int frameCount;
|
||||||
|
PCacheEntry() : frameCount(0) {}
|
||||||
|
void Destroy() {
|
||||||
|
glDeleteProgram(program.glprogid);
|
||||||
|
program.glprogid = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
typedef std::map<std::pair<u64, u64>, PCacheEntry> PCache;
|
||||||
|
|
||||||
|
static PCache pshaders;
|
||||||
|
static GLuint CurrentFShader, CurrentVShader, CurrentProgram;
|
||||||
|
static std::pair<u64, u64> CurrentShaderProgram;
|
||||||
|
public:
|
||||||
|
static PROGRAMSHADER GetShaderProgram();
|
||||||
|
static GLint GetAttr(int num);
|
||||||
|
static void SetBothShaders(GLuint PS, GLuint VS);
|
||||||
|
static GLuint GetCurrentProgram(void);
|
||||||
|
static void Shutdown(void);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace OGL
|
||||||
|
|
||||||
|
#endif
|
|
@ -45,6 +45,7 @@
|
||||||
#include "DLCache.h"
|
#include "DLCache.h"
|
||||||
#include "PixelShaderCache.h"
|
#include "PixelShaderCache.h"
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
|
#include "ProgramShaderCache.h"
|
||||||
#include "VertexShaderCache.h"
|
#include "VertexShaderCache.h"
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
#include "VertexLoaderManager.h"
|
#include "VertexLoaderManager.h"
|
||||||
|
@ -125,8 +126,8 @@ static std::thread scrshotThread;
|
||||||
|
|
||||||
// EFB cache related
|
// EFB cache related
|
||||||
const u32 EFB_CACHE_RECT_SIZE = 64; // Cache 64x64 blocks.
|
const u32 EFB_CACHE_RECT_SIZE = 64; // Cache 64x64 blocks.
|
||||||
const u32 EFB_CACHE_WIDTH = EFB_WIDTH / EFB_CACHE_RECT_SIZE;
|
const u32 EFB_CACHE_WIDTH = (EFB_WIDTH + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; // round up
|
||||||
const u32 EFB_CACHE_HEIGHT = EFB_HEIGHT / EFB_CACHE_RECT_SIZE;
|
const u32 EFB_CACHE_HEIGHT = (EFB_HEIGHT + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE;
|
||||||
static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT];
|
static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT];
|
||||||
static std::vector<u32> s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR
|
static std::vector<u32> s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR
|
||||||
|
|
||||||
|
@ -698,7 +699,8 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
|
||||||
if (!g_ActiveConfig.bEFBAccessEnable)
|
if (!g_ActiveConfig.bEFBAccessEnable)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
u32 cacheRectIdx = ((x / EFB_CACHE_RECT_SIZE) << 16) | (y / EFB_CACHE_RECT_SIZE);
|
u32 cacheRectIdx = (y / EFB_CACHE_RECT_SIZE) * EFB_CACHE_WIDTH
|
||||||
|
+ (x / EFB_CACHE_RECT_SIZE);
|
||||||
|
|
||||||
// Get the rectangular target region containing the EFB pixel
|
// Get the rectangular target region containing the EFB pixel
|
||||||
EFBRectangle efbPixelRc;
|
EFBRectangle efbPixelRc;
|
||||||
|
@ -1426,8 +1428,13 @@ void Renderer::ResetAPIState()
|
||||||
{
|
{
|
||||||
// Gets us to a reasonably sane state where it's possible to do things like
|
// Gets us to a reasonably sane state where it's possible to do things like
|
||||||
// image copies with textured quads, etc.
|
// image copies with textured quads, etc.
|
||||||
VertexShaderCache::DisableShader();
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
PixelShaderCache::DisableShader();
|
ProgramShaderCache::SetBothShaders(0, 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VertexShaderCache::DisableShader();
|
||||||
|
PixelShaderCache::DisableShader();
|
||||||
|
}
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
@ -1452,9 +1459,14 @@ void Renderer::RestoreAPIState()
|
||||||
|
|
||||||
if (g_ActiveConfig.bWireFrame)
|
if (g_ActiveConfig.bWireFrame)
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
|
||||||
VertexShaderCache::SetCurrentShader(0);
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
PixelShaderCache::SetCurrentShader(0);
|
ProgramShaderCache::SetBothShaders(0, 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VertexShaderCache::SetCurrentShader(0);
|
||||||
|
PixelShaderCache::SetCurrentShader(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetGenerationMode()
|
void Renderer::SetGenerationMode()
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "VertexShaderCache.h"
|
#include "VertexShaderCache.h"
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
|
#include "ProgramShaderCache.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
#include "VertexManager.h"
|
#include "VertexManager.h"
|
||||||
|
@ -176,10 +177,6 @@ void VertexManager::vFlush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set global constants
|
|
||||||
VertexShaderManager::SetConstants();
|
|
||||||
PixelShaderManager::SetConstants();
|
|
||||||
|
|
||||||
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate
|
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate
|
||||||
&& bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
&& bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||||
|
|
||||||
|
@ -212,8 +209,18 @@ void VertexManager::vFlush()
|
||||||
FRAGMENTSHADER* ps = PixelShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components);
|
FRAGMENTSHADER* ps = PixelShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components);
|
||||||
#endif
|
#endif
|
||||||
VERTEXSHADER* vs = VertexShaderCache::SetShader(g_nativeVertexFmt->m_components);
|
VERTEXSHADER* vs = VertexShaderCache::SetShader(g_nativeVertexFmt->m_components);
|
||||||
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // Lego Star Wars crashes here.
|
|
||||||
if (vs) VertexShaderCache::SetCurrentShader(vs->glprogid);
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
|
ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // Lego Star Wars crashes here.
|
||||||
|
if (vs) VertexShaderCache::SetCurrentShader(vs->glprogid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set global constants
|
||||||
|
VertexShaderManager::SetConstants();
|
||||||
|
PixelShaderManager::SetConstants();
|
||||||
|
|
||||||
Draw();
|
Draw();
|
||||||
|
|
||||||
|
@ -221,7 +228,13 @@ void VertexManager::vFlush()
|
||||||
if (useDstAlpha && !dualSourcePossible)
|
if (useDstAlpha && !dualSourcePossible)
|
||||||
{
|
{
|
||||||
ps = PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components);
|
ps = PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components);
|
||||||
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid);
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
|
{
|
||||||
|
ProgramShaderCache::SetBothShaders(ps->glprogid, 0);
|
||||||
|
PixelShaderManager::SetConstants(); // Need to set these again
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid);
|
||||||
|
|
||||||
// only update alpha
|
// only update alpha
|
||||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "Render.h"
|
#include "Render.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
|
#include "ProgramShaderCache.h"
|
||||||
#include "VertexShaderCache.h"
|
#include "VertexShaderCache.h"
|
||||||
#include "VertexManager.h"
|
#include "VertexManager.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
|
@ -45,194 +46,293 @@ VertexShaderCache::VSCacheEntry* VertexShaderCache::last_entry = NULL;
|
||||||
VERTEXSHADERUID VertexShaderCache::last_uid;
|
VERTEXSHADERUID VertexShaderCache::last_uid;
|
||||||
|
|
||||||
static int s_nMaxVertexInstructions;
|
static int s_nMaxVertexInstructions;
|
||||||
|
void (*pSetVSConstant4f)(unsigned int, float, float, float, float);
|
||||||
|
void (*pSetVSConstant4fv)(unsigned int, const float*);
|
||||||
|
void (*pSetMultiVSConstant4fv)(unsigned int, unsigned int, const float*);
|
||||||
|
void (*pSetMultiVSConstant3fv)(unsigned int, unsigned int, const float*);
|
||||||
|
|
||||||
void VertexShaderCache::Init()
|
void VertexShaderCache::Init()
|
||||||
{
|
{
|
||||||
glEnable(GL_VERTEX_PROGRAM_ARB);
|
glEnable(GL_VERTEX_PROGRAM_ARB);
|
||||||
ShaderEnabled = true;
|
ShaderEnabled = true;
|
||||||
CurrentShader = 0;
|
CurrentShader = 0;
|
||||||
last_entry = NULL;
|
last_entry = NULL;
|
||||||
|
|
||||||
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions);
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxVertexInstructions = 4096;
|
{
|
||||||
|
pSetVSConstant4f = SetGLSLVSConstant4f;
|
||||||
|
pSetVSConstant4fv = SetGLSLVSConstant4fv;
|
||||||
|
pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv;
|
||||||
|
pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pSetVSConstant4f = SetCGVSConstant4f;
|
||||||
|
pSetVSConstant4fv = SetCGVSConstant4fv;
|
||||||
|
pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv;
|
||||||
|
pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv;
|
||||||
|
}
|
||||||
|
|
||||||
|
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions);
|
||||||
|
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxVertexInstructions = 4096;
|
||||||
#if CG_VERSION_NUM == 2100
|
#if CG_VERSION_NUM == 2100
|
||||||
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
|
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
|
||||||
{
|
{
|
||||||
s_nMaxVertexInstructions = 4096;
|
s_nMaxVertexInstructions = 4096;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexShaderCache::Shutdown()
|
void VertexShaderCache::Shutdown()
|
||||||
{
|
{
|
||||||
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter)
|
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter)
|
||||||
iter->second.Destroy();
|
iter->second.Destroy();
|
||||||
vshaders.clear();
|
vshaders.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
|
VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
|
||||||
{
|
{
|
||||||
VERTEXSHADERUID uid;
|
VERTEXSHADERUID uid;
|
||||||
GetVertexShaderId(&uid, components);
|
GetVertexShaderId(&uid, components);
|
||||||
if (last_entry)
|
if (last_entry)
|
||||||
{
|
{
|
||||||
if (uid == last_uid)
|
if (uid == last_uid)
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
|
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
|
||||||
return &last_entry->shader;
|
return &last_entry->shader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
last_uid = uid;
|
last_uid = uid;
|
||||||
|
|
||||||
VSCache::iterator iter = vshaders.find(uid);
|
VSCache::iterator iter = vshaders.find(uid);
|
||||||
if (iter != vshaders.end())
|
if (iter != vshaders.end())
|
||||||
{
|
{
|
||||||
VSCacheEntry &entry = iter->second;
|
VSCacheEntry &entry = iter->second;
|
||||||
last_entry = &entry;
|
last_entry = &entry;
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
|
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
|
||||||
return &last_entry->shader;
|
return &last_entry->shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make an entry in the table
|
// Make an entry in the table
|
||||||
VSCacheEntry& entry = vshaders[uid];
|
VSCacheEntry& entry = vshaders[uid];
|
||||||
last_entry = &entry;
|
last_entry = &entry;
|
||||||
const char *code = GenerateVertexShaderCode(components, API_OPENGL);
|
const char *code = GenerateVertexShaderCode(components, API_OPENGL);
|
||||||
GetSafeVertexShaderId(&entry.safe_uid, components);
|
GetSafeVertexShaderId(&entry.safe_uid, components);
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
|
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
char szTemp[MAX_PATH];
|
char szTemp[MAX_PATH];
|
||||||
sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
||||||
|
|
||||||
SaveData(szTemp, code);
|
SaveData(szTemp, code);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) {
|
if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) {
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
INCSTAT(stats.numVertexShadersCreated);
|
INCSTAT(stats.numVertexShadersCreated);
|
||||||
SETSTAT(stats.numVertexShadersAlive, vshaders.size());
|
SETSTAT(stats.numVertexShadersAlive, vshaders.size());
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
return &last_entry->shader;
|
return &last_entry->shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
||||||
{
|
{
|
||||||
// Reset GL error before compiling shaders. Yeah, we need to investigate the causes of these.
|
// Reset GL error before compiling shaders. Yeah, we need to investigate the causes of these.
|
||||||
GLenum err = GL_REPORT_ERROR();
|
GLenum err = GL_REPORT_ERROR();
|
||||||
if (err != GL_NO_ERROR)
|
if (err != GL_NO_ERROR)
|
||||||
{
|
{
|
||||||
ERROR_LOG(VIDEO, "glError %08x before VS!", err);
|
ERROR_LOG(VIDEO, "glError %08x before VS!", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined HAVE_CG && HAVE_CG
|
#if defined HAVE_CG && HAVE_CG
|
||||||
char stropt[64];
|
char stropt[64];
|
||||||
sprintf(stropt, "MaxLocalParams=256,MaxInstructions=%d", s_nMaxVertexInstructions);
|
sprintf(stropt, "MaxLocalParams=256,MaxInstructions=%d", s_nMaxVertexInstructions);
|
||||||
const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
|
const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
|
||||||
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", opts);
|
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", opts);
|
||||||
if (!cgIsProgram(tempprog)) {
|
if (!cgIsProgram(tempprog)) {
|
||||||
static int num_failures = 0;
|
static int num_failures = 0;
|
||||||
char szTemp[MAX_PATH];
|
char szTemp[MAX_PATH];
|
||||||
sprintf(szTemp, "%sbad_vs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
|
sprintf(szTemp, "%sbad_vs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
|
||||||
std::ofstream file(szTemp);
|
std::ofstream file(szTemp);
|
||||||
file << pstrprogram;
|
file << pstrprogram;
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
PanicAlert("Failed to compile vertex shader!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
|
PanicAlert("Failed to compile vertex shader!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
|
||||||
szTemp,
|
szTemp,
|
||||||
g_cgfProf,
|
g_cgfProf,
|
||||||
cgGetLastListing(g_cgcontext));
|
cgGetLastListing(g_cgcontext));
|
||||||
|
|
||||||
cgDestroyProgram(tempprog);
|
cgDestroyProgram(tempprog);
|
||||||
ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
|
ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
|
||||||
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cgGetError() != CG_NO_ERROR)
|
if (cgGetError() != CG_NO_ERROR)
|
||||||
{
|
{
|
||||||
WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
|
WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
|
||||||
WARN_LOG(VIDEO, "%s", pstrprogram);
|
WARN_LOG(VIDEO, "%s", pstrprogram);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
|
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
|
||||||
// It SHOULD not have any nasty side effects though - but you never know...
|
// It SHOULD not have any nasty side effects though - but you never know...
|
||||||
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
|
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
|
||||||
char *plocal = strstr(pcompiledprog, "program.local");
|
char *plocal = strstr(pcompiledprog, "program.local");
|
||||||
while (plocal != NULL) {
|
while (plocal != NULL) {
|
||||||
const char* penv = " program.env";
|
const char* penv = " program.env";
|
||||||
memcpy(plocal, penv, 13);
|
memcpy(plocal, penv, 13);
|
||||||
plocal = strstr(plocal + 13, "program.local");
|
plocal = strstr(plocal + 13, "program.local");
|
||||||
}
|
}
|
||||||
glGenProgramsARB(1, &vs.glprogid);
|
glGenProgramsARB(1, &vs.glprogid);
|
||||||
SetCurrentShader(vs.glprogid);
|
SetCurrentShader(vs.glprogid);
|
||||||
|
|
||||||
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
|
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
|
||||||
err = GL_REPORT_ERROR();
|
err = GL_REPORT_ERROR();
|
||||||
if (err != GL_NO_ERROR) {
|
if (err != GL_NO_ERROR) {
|
||||||
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
||||||
ERROR_LOG(VIDEO, "%s", pcompiledprog);
|
ERROR_LOG(VIDEO, "%s", pcompiledprog);
|
||||||
}
|
}
|
||||||
|
|
||||||
cgDestroyProgram(tempprog);
|
cgDestroyProgram(tempprog);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (g_ActiveConfig.bEnableShaderDebugging)
|
if (g_ActiveConfig.bEnableShaderDebugging)
|
||||||
vs.strprog = pstrprogram;
|
vs.strprog = pstrprogram;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexShaderCache::DisableShader()
|
void VertexShaderCache::DisableShader()
|
||||||
{
|
{
|
||||||
if (ShaderEnabled)
|
if (ShaderEnabled)
|
||||||
{
|
{
|
||||||
glDisable(GL_VERTEX_PROGRAM_ARB);
|
glDisable(GL_VERTEX_PROGRAM_ARB);
|
||||||
ShaderEnabled = false;
|
ShaderEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VertexShaderCache::SetCurrentShader(GLuint Shader)
|
void VertexShaderCache::SetCurrentShader(GLuint Shader)
|
||||||
{
|
{
|
||||||
if (!ShaderEnabled)
|
if (!ShaderEnabled)
|
||||||
{
|
{
|
||||||
glEnable(GL_VERTEX_PROGRAM_ARB);
|
glEnable(GL_VERTEX_PROGRAM_ARB);
|
||||||
ShaderEnabled= true;
|
ShaderEnabled= true;
|
||||||
}
|
}
|
||||||
if (CurrentShader != Shader)
|
if (CurrentShader != Shader)
|
||||||
{
|
{
|
||||||
if(Shader != 0)
|
if(Shader != 0)
|
||||||
CurrentShader = Shader;
|
CurrentShader = Shader;
|
||||||
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
|
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// GLSL Specific
|
||||||
void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
void SetVSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
||||||
{
|
{
|
||||||
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, const_number, f1, f2, f3, f4);
|
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
|
for(int a = 0; a < NUM_UNIFORMS; ++a)
|
||||||
|
if(!strcmp(name, UniformNames[a]))
|
||||||
|
{
|
||||||
|
if(tmp.UniformLocations[a] == -1)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||||
void Renderer::SetVSConstant4fv(unsigned int const_number, const float *f)
|
|
||||||
{
|
{
|
||||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number, f);
|
float buf[4];
|
||||||
|
buf[0] = f1;
|
||||||
|
buf[1] = f2;
|
||||||
|
buf[2] = f3;
|
||||||
|
buf[3] = f4;
|
||||||
|
for( unsigned int a = 0; a < 9; ++a)
|
||||||
|
{
|
||||||
|
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
||||||
|
{
|
||||||
|
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
||||||
|
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
|
||||||
|
{
|
||||||
|
for( unsigned int a = 0; a < 9; ++a)
|
||||||
|
{
|
||||||
|
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
||||||
|
{
|
||||||
|
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
||||||
|
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
|
{
|
||||||
|
for( unsigned int a = 0; a < 9; ++a)
|
||||||
|
{
|
||||||
|
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
||||||
|
{
|
||||||
|
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
||||||
|
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
|
{
|
||||||
|
float buf[4 * C_VENVCONST_END];
|
||||||
|
for (unsigned int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
buf[4*i ] = *f++;
|
||||||
|
buf[4*i+1] = *f++;
|
||||||
|
buf[4*i+2] = *f++;
|
||||||
|
buf[4*i+3] = 0.f;
|
||||||
|
}
|
||||||
|
for( unsigned int a = 0; a < 9; ++a)
|
||||||
|
{
|
||||||
|
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
||||||
|
{
|
||||||
|
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
||||||
|
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CG Specific
|
||||||
|
void SetCGVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||||
|
{
|
||||||
|
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, const_number, f1, f2, f3, f4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetCGVSConstant4fv(unsigned int const_number, const float *f)
|
||||||
|
{
|
||||||
|
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
{
|
{
|
||||||
if(GLEW_EXT_gpu_program_parameters)
|
if(GLEW_EXT_gpu_program_parameters)
|
||||||
{
|
{
|
||||||
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f);
|
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -241,32 +341,54 @@ void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int cou
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
|
void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
{
|
{
|
||||||
if(GLEW_EXT_gpu_program_parameters)
|
if(GLEW_EXT_gpu_program_parameters)
|
||||||
{
|
{
|
||||||
float buf[4 * C_VENVCONST_END];
|
float buf[4 * C_VENVCONST_END];
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
buf[4*i ] = *f++;
|
buf[4*i ] = *f++;
|
||||||
buf[4*i+1] = *f++;
|
buf[4*i+1] = *f++;
|
||||||
buf[4*i+2] = *f++;
|
buf[4*i+2] = *f++;
|
||||||
buf[4*i+3] = 0.f;
|
buf[4*i+3] = 0.f;
|
||||||
}
|
}
|
||||||
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf);
|
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
float buf[4];
|
float buf[4];
|
||||||
buf[0] = *f++;
|
buf[0] = *f++;
|
||||||
buf[1] = *f++;
|
buf[1] = *f++;
|
||||||
buf[2] = *f++;
|
buf[2] = *f++;
|
||||||
buf[3] = 0.f;
|
buf[3] = 0.f;
|
||||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf);
|
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renderer Functions
|
||||||
|
void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||||
|
{
|
||||||
|
pSetVSConstant4f(const_number, f1, f2, f3, f4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::SetVSConstant4fv(unsigned int const_number, const float *f)
|
||||||
|
{
|
||||||
|
pSetVSConstant4fv(const_number, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
|
{
|
||||||
|
pSetMultiVSConstant4fv(const_number, count, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
|
{
|
||||||
|
pSetMultiVSConstant3fv(const_number, count, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace OGL
|
} // namespace OGL
|
||||||
|
|
|
@ -70,7 +70,17 @@ public:
|
||||||
static void DisableShader();
|
static void DisableShader();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
// GLSL Specific
|
||||||
|
void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
|
||||||
|
void SetGLSLVSConstant4fv(unsigned int const_number, const float *f);
|
||||||
|
void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
|
void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
|
|
||||||
|
// CG Specific
|
||||||
|
void SetCGVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
|
||||||
|
void SetCGVSConstant4fv(unsigned int const_number, const float *f);
|
||||||
|
void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
|
void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
} // namespace OGL
|
} // namespace OGL
|
||||||
|
|
||||||
#endif // _VERTEXSHADERCACHE_H_
|
#endif // _VERTEXSHADERCACHE_H_
|
||||||
|
|
|
@ -135,6 +135,7 @@ void InitBackendInfo()
|
||||||
g_Config.backend_info.bSupportsDualSourceBlend = false; // supported, but broken
|
g_Config.backend_info.bSupportsDualSourceBlend = false; // supported, but broken
|
||||||
g_Config.backend_info.bSupportsFormatReinterpretation = false;
|
g_Config.backend_info.bSupportsFormatReinterpretation = false;
|
||||||
g_Config.backend_info.bSupportsPixelLighting = true;
|
g_Config.backend_info.bSupportsPixelLighting = true;
|
||||||
|
g_Config.backend_info.bSupportsGLSL = true;
|
||||||
|
|
||||||
// aamodes
|
// aamodes
|
||||||
const char* caamodes[] = {"None", "2x", "4x", "8x", "8x CSAA", "8xQ CSAA", "16x CSAA", "16xQ CSAA"};
|
const char* caamodes[] = {"None", "2x", "4x", "8x", "8x CSAA", "8xQ CSAA", "16x CSAA", "16xQ CSAA"};
|
||||||
|
|
Loading…
Reference in New Issue