mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-26 15:49:50 -06:00
fix formatting uglies introduced in glsl-master branch
This commit is contained in:

committed by
Sonicadvance1

parent
4a4833e617
commit
31a8424bcc
@ -20,7 +20,6 @@
|
||||
#include "GLUtil.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <assert.h>
|
||||
|
||||
#include "Statistics.h"
|
||||
#include "VideoConfig.h"
|
||||
@ -51,62 +50,63 @@ bool PixelShaderCache::ShaderEnabled;
|
||||
PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry = NULL;
|
||||
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*);
|
||||
void (*pSetPSConstant4f)(unsigned int, float, float, float, float);
|
||||
void (*pSetPSConstant4fv)(unsigned int, const float*);
|
||||
void (*pSetMultiPSConstant4fv)(unsigned int, unsigned int, const float*);
|
||||
bool (*pCompilePixelShader)(FRAGMENTSHADER&, const char*);
|
||||
|
||||
GLuint PixelShaderCache::GetDepthMatrixProgram()
|
||||
{
|
||||
return s_DepthMatrixProgram.glprogid;
|
||||
return s_DepthMatrixProgram.glprogid;
|
||||
}
|
||||
|
||||
GLuint PixelShaderCache::GetColorMatrixProgram()
|
||||
{
|
||||
return s_ColorMatrixProgram.glprogid;
|
||||
return s_ColorMatrixProgram.glprogid;
|
||||
}
|
||||
|
||||
void PixelShaderCache::Init()
|
||||
{
|
||||
ShaderEnabled = true;
|
||||
CurrentShader = 0;
|
||||
last_entry = NULL;
|
||||
GL_REPORT_ERRORD();
|
||||
ShaderEnabled = true;
|
||||
CurrentShader = 0;
|
||||
last_entry = NULL;
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
s_displayCompileAlert = true;
|
||||
s_displayCompileAlert = true;
|
||||
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
pSetPSConstant4f = SetGLSLPSConstant4f;
|
||||
pSetPSConstant4fv = SetGLSLPSConstant4fv;
|
||||
pSetMultiPSConstant4fv = SetMultiGLSLPSConstant4fv;
|
||||
pCompilePixelShader = CompileGLSLPixelShader;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
pSetPSConstant4f = SetCGPSConstant4f;
|
||||
pSetPSConstant4fv = SetCGPSConstant4fv;
|
||||
pSetMultiPSConstant4fv = SetMultiCGPSConstant4fv;
|
||||
pCompilePixelShader = CompileCGPixelShader;
|
||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
}
|
||||
}
|
||||
|
||||
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions);
|
||||
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 (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 (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
|
||||
{
|
||||
s_nMaxPixelInstructions = 4096;
|
||||
}
|
||||
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
|
||||
{
|
||||
s_nMaxPixelInstructions = 4096;
|
||||
}
|
||||
#endif
|
||||
|
||||
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_ATTRIBS_ARB, (GLint *)&maxattribs);
|
||||
INFO_LOG(VIDEO, "pixel max_alu=%d, max_inst=%d, max_attrib=%d", s_nMaxPixelInstructions, maxinst, maxattribs);
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
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_ATTRIBS_ARB, (GLint *)&maxattribs);
|
||||
INFO_LOG(VIDEO, "pixel max_alu=%d, max_inst=%d, max_attrib=%d", s_nMaxPixelInstructions, maxinst, maxattribs);
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
char pmatrixprog[2048];
|
||||
sprintf(pmatrixprog, "#version %s\n"
|
||||
@ -137,14 +137,14 @@ void PixelShaderCache::Init()
|
||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
|
||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
|
||||
C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
|
||||
|
||||
|
||||
|
||||
|
||||
if (!PixelShaderCache::CompilePixelShader(s_ColorMatrixProgram, pmatrixprog))
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
|
||||
s_ColorMatrixProgram.Destroy();
|
||||
}
|
||||
|
||||
|
||||
sprintf(pmatrixprog, "#version %s\n"
|
||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||
"%s\n"
|
||||
@ -183,7 +183,7 @@ void PixelShaderCache::Init()
|
||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
|
||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
|
||||
C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
|
||||
|
||||
|
||||
if (!PixelShaderCache::CompilePixelShader(s_DepthMatrixProgram, pmatrixprog))
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
|
||||
@ -194,20 +194,20 @@ void PixelShaderCache::Init()
|
||||
{
|
||||
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_COLORS+5,C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
|
||||
"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_COLORS+5,C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
|
||||
glGenProgramsARB(1, &s_ColorMatrixProgram.glprogid);
|
||||
SetCurrentShader(s_ColorMatrixProgram.glprogid);
|
||||
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
|
||||
@ -219,50 +219,50 @@ void PixelShaderCache::Init()
|
||||
}
|
||||
|
||||
sprintf(pmatrixprog, "!!ARBfp1.0\n"
|
||||
"TEMP R0;\n"
|
||||
"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"
|
||||
"TEMP R0;\n"
|
||||
"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"
|
||||
|
||||
//scale from [0*16777216..1*16777216] to
|
||||
//[0*16777215..1*16777215], multiply by 256
|
||||
"MUL R0, R2.x, K0.x;\n" // *16777215/16777216*256
|
||||
//scale from [0*16777216..1*16777216] to
|
||||
//[0*16777215..1*16777215], multiply by 256
|
||||
"MUL R0, R2.x, K0.x;\n" // *16777215/16777216*256
|
||||
|
||||
//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
|
||||
//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
|
||||
|
||||
"FLR R0.x,R0;\n" //bits 31..24
|
||||
"FLR R0.x,R0;\n" //bits 31..24
|
||||
|
||||
"SUB R0.yzw,R0,R0.x;\n" //subtract bits 31..24 from rest
|
||||
"MUL R0.yzw,R0,K0.z;\n" // *256
|
||||
"FLR R0.y,R0;\n" //bits 23..16
|
||||
"SUB R0.yzw,R0,R0.x;\n" //subtract bits 31..24 from rest
|
||||
"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
|
||||
"MUL R0.zw,R0,K0.z;\n" // *256
|
||||
"FLR R0.z,R0;\n" //bits 15..8
|
||||
"SUB R0.zw,R0,R0.y;\n" //subtract bits 23..16 from rest
|
||||
"MUL R0.zw,R0,K0.z;\n" // *256
|
||||
"FLR R0.z,R0;\n" //bits 15..8
|
||||
|
||||
"MOV R0.w,R0.x;\n" //duplicate bit 31..24
|
||||
"MOV R0.w,R0.x;\n" //duplicate bit 31..24
|
||||
|
||||
"MUL R0,R0,K0.y;\n" // /255
|
||||
"MUL R0,R0,K0.y;\n" // /255
|
||||
|
||||
"MUL R0.w,R0,K1.x;\n" // *15
|
||||
"FLR R0.w,R0;\n" //bits 31..28
|
||||
"MUL R0.w,R0,K1.y;\n" // /15
|
||||
"MUL R0.w,R0,K1.x;\n" // *15
|
||||
"FLR R0.w,R0;\n" //bits 31..28
|
||||
"MUL R0.w,R0,K1.y;\n" // /15
|
||||
|
||||
"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_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
|
||||
"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_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
|
||||
glGenProgramsARB(1, &s_DepthMatrixProgram.glprogid);
|
||||
SetCurrentShader(s_DepthMatrixProgram.glprogid);
|
||||
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
|
||||
@ -280,71 +280,71 @@ void PixelShaderCache::Shutdown()
|
||||
{
|
||||
s_ColorMatrixProgram.Destroy();
|
||||
s_DepthMatrixProgram.Destroy();
|
||||
PSCache::iterator iter = PixelShaders.begin();
|
||||
for (; iter != PixelShaders.end(); iter++)
|
||||
iter->second.Destroy();
|
||||
PixelShaders.clear();
|
||||
PSCache::iterator iter = PixelShaders.begin();
|
||||
for (; iter != PixelShaders.end(); iter++)
|
||||
iter->second.Destroy();
|
||||
PixelShaders.clear();
|
||||
}
|
||||
|
||||
FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
||||
{
|
||||
PIXELSHADERUID uid;
|
||||
GetPixelShaderId(&uid, dstAlphaMode, components);
|
||||
PIXELSHADERUID uid;
|
||||
GetPixelShaderId(&uid, dstAlphaMode, components);
|
||||
|
||||
// Check if the shader is already set
|
||||
if (last_entry)
|
||||
{
|
||||
if (uid == last_uid)
|
||||
// Check if the shader is already set
|
||||
if (last_entry)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
last_uid = uid;
|
||||
|
||||
PSCache::iterator iter = PixelShaders.find(uid);
|
||||
if (iter != PixelShaders.end())
|
||||
{
|
||||
PSCacheEntry &entry = iter->second;
|
||||
last_entry = &entry;
|
||||
PSCache::iterator iter = PixelShaders.find(uid);
|
||||
if (iter != PixelShaders.end())
|
||||
{
|
||||
PSCacheEntry &entry = iter->second;
|
||||
last_entry = &entry;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components);
|
||||
return &last_entry->shader;
|
||||
}
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components);
|
||||
return &last_entry->shader;
|
||||
}
|
||||
|
||||
// Make an entry in the table
|
||||
PSCacheEntry& newentry = PixelShaders[uid];
|
||||
last_entry = &newentry;
|
||||
const char *code = GeneratePixelShaderCode(dstAlphaMode, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL, components);
|
||||
// Make an entry in the table
|
||||
PSCacheEntry& newentry = PixelShaders[uid];
|
||||
last_entry = &newentry;
|
||||
const char *code = GeneratePixelShaderCode(dstAlphaMode, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL, components);
|
||||
|
||||
if (g_ActiveConfig.bEnableShaderDebugging && code)
|
||||
{
|
||||
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components);
|
||||
newentry.shader.strprog = code;
|
||||
}
|
||||
if (g_ActiveConfig.bEnableShaderDebugging && code)
|
||||
{
|
||||
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components);
|
||||
newentry.shader.strprog = code;
|
||||
}
|
||||
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
|
||||
static int counter = 0;
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
||||
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
|
||||
static int counter = 0;
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
||||
|
||||
SaveData(szTemp, code);
|
||||
}
|
||||
SaveData(szTemp, code);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!code || !CompilePixelShader(newentry.shader, code)) {
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
||||
return NULL;
|
||||
}
|
||||
if (!code || !CompilePixelShader(newentry.shader, code)) {
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
INCSTAT(stats.numPixelShadersCreated);
|
||||
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
return &last_entry->shader;
|
||||
INCSTAT(stats.numPixelShadersCreated);
|
||||
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
return &last_entry->shader;
|
||||
}
|
||||
|
||||
bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||
@ -352,35 +352,32 @@ bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrpr
|
||||
return pCompilePixelShader(ps, pstrprogram);
|
||||
}
|
||||
|
||||
//Disable Fragment programs and reset the selected Program
|
||||
// Disable Fragment programs and reset the selected Program
|
||||
void PixelShaderCache::DisableShader()
|
||||
{
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
assert(true);
|
||||
if(ShaderEnabled)
|
||||
{
|
||||
glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
ShaderEnabled = false;
|
||||
}
|
||||
if (ShaderEnabled)
|
||||
{
|
||||
glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
ShaderEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
//bind a program if is diferent from the binded oone
|
||||
// bind a program if is different from the binded oone
|
||||
void PixelShaderCache::SetCurrentShader(GLuint Shader)
|
||||
{
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
assert(true);
|
||||
if(!ShaderEnabled)
|
||||
{
|
||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
ShaderEnabled = true;
|
||||
}
|
||||
if(CurrentShader != Shader)
|
||||
{
|
||||
if(Shader != 0)
|
||||
CurrentShader = Shader;
|
||||
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
|
||||
}
|
||||
if (!ShaderEnabled)
|
||||
{
|
||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
ShaderEnabled = true;
|
||||
}
|
||||
if (CurrentShader != Shader)
|
||||
{
|
||||
if (Shader != 0)
|
||||
CurrentShader = Shader;
|
||||
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL Specific
|
||||
bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||
{
|
||||
@ -404,12 +401,12 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||
GLchar* infoLog = new GLchar[length];
|
||||
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
|
||||
WARN_LOG(VIDEO, "PS Shader info log:\n%s", infoLog);
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "ps_%d.txt", result);
|
||||
FILE *fp = fopen(szTemp, "wb");
|
||||
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
|
||||
fclose(fp);
|
||||
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "ps_%d.txt", result);
|
||||
FILE *fp = fopen(szTemp, "wb");
|
||||
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
|
||||
fclose(fp);
|
||||
|
||||
delete[] infoLog;
|
||||
}
|
||||
// Don't try to use this shader
|
||||
@ -422,40 +419,43 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||
ps.bGLSL = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
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]))
|
||||
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
||||
for (int a = 0; a < NUM_UNIFORMS; ++a)
|
||||
{
|
||||
if(tmp.UniformLocations[a] == -1)
|
||||
return;
|
||||
else
|
||||
{
|
||||
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
|
||||
return;
|
||||
}
|
||||
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 const f[4] = {f1, f2, f3, f4};
|
||||
|
||||
float const f[4] = {f1, f2, f3, f4};
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1);
|
||||
return;
|
||||
}
|
||||
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))
|
||||
for (unsigned int a = 0; a < 10; ++a)
|
||||
{
|
||||
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
||||
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
||||
return;
|
||||
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)
|
||||
@ -465,15 +465,15 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
|
||||
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1);
|
||||
return;
|
||||
}
|
||||
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))
|
||||
for (unsigned int a = 0; a < 10; ++a)
|
||||
{
|
||||
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
||||
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
||||
return;
|
||||
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)
|
||||
@ -483,115 +483,117 @@ void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, co
|
||||
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, count);
|
||||
return;
|
||||
}
|
||||
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))
|
||||
for (unsigned int a = 0; a < 10; ++a)
|
||||
{
|
||||
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
||||
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count);
|
||||
return;
|
||||
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
|
||||
|
||||
// CG Specific
|
||||
bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||
{
|
||||
GLenum err = GL_REPORT_ERROR();
|
||||
if (err != GL_NO_ERROR)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "glError %08x before PS!", err);
|
||||
}
|
||||
GLenum err = GL_REPORT_ERROR();
|
||||
if (err != GL_NO_ERROR)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "glError %08x before PS!", err);
|
||||
}
|
||||
|
||||
#if defined HAVE_CG && HAVE_CG
|
||||
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", NULL);
|
||||
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", NULL);
|
||||
|
||||
// handle errors
|
||||
if (!cgIsProgram(tempprog))
|
||||
{
|
||||
cgDestroyProgram(tempprog);
|
||||
// handle errors
|
||||
if (!cgIsProgram(tempprog))
|
||||
{
|
||||
cgDestroyProgram(tempprog);
|
||||
|
||||
static int num_failures = 0;
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "bad_ps_%04i.txt", num_failures++);
|
||||
std::ofstream file(szTemp);
|
||||
file << pstrprogram;
|
||||
file.close();
|
||||
static int num_failures = 0;
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "bad_ps_%04i.txt", num_failures++);
|
||||
std::ofstream file(szTemp);
|
||||
file << pstrprogram;
|
||||
file.close();
|
||||
|
||||
PanicAlert("Failed to compile pixel shader %d!\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",
|
||||
num_failures - 1, szTemp,
|
||||
g_cgfProf,
|
||||
cgGetLastListing(g_cgcontext));
|
||||
PanicAlert("Failed to compile pixel shader %d!\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",
|
||||
num_failures - 1, szTemp,
|
||||
g_cgfProf,
|
||||
cgGetLastListing(g_cgcontext));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// handle warnings
|
||||
if (cgGetError() != CG_NO_ERROR)
|
||||
{
|
||||
WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext));
|
||||
WARN_LOG(VIDEO, "%s", pstrprogram);
|
||||
}
|
||||
|
||||
// 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...
|
||||
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
|
||||
char *plocal = strstr(pcompiledprog, "program.local");
|
||||
while (plocal != NULL)
|
||||
{
|
||||
const char *penv = " program.env";
|
||||
memcpy(plocal, penv, 13);
|
||||
plocal = strstr(plocal+13, "program.local");
|
||||
}
|
||||
|
||||
glGenProgramsARB(1, &ps.glprogid);
|
||||
ps.bGLSL = false;
|
||||
PixelShaderCache::SetCurrentShader(ps.glprogid);
|
||||
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
|
||||
|
||||
err = GL_REPORT_ERROR();
|
||||
if (err != GL_NO_ERROR)
|
||||
{
|
||||
GLint error_pos, native_limit;
|
||||
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
|
||||
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit);
|
||||
// Error occur
|
||||
if (error_pos != -1) {
|
||||
const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
||||
char line[256];
|
||||
strncpy(line, (const char *)pcompiledprog + error_pos, 255);
|
||||
line[255] = 0;
|
||||
ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error);
|
||||
ERROR_LOG(VIDEO, "Line dump: \n%s", line);
|
||||
} else if (native_limit != -1) {
|
||||
ERROR_LOG(VIDEO, "Hit limit? %i", native_limit);
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
||||
ERROR_LOG(VIDEO, "%s", pcompiledprog);
|
||||
}
|
||||
|
||||
cgDestroyProgram(tempprog);
|
||||
// handle warnings
|
||||
if (cgGetError() != CG_NO_ERROR)
|
||||
{
|
||||
WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext));
|
||||
WARN_LOG(VIDEO, "%s", pstrprogram);
|
||||
}
|
||||
|
||||
// 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...
|
||||
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
|
||||
char *plocal = strstr(pcompiledprog, "program.local");
|
||||
while (plocal != NULL)
|
||||
{
|
||||
const char *penv = " program.env";
|
||||
memcpy(plocal, penv, 13);
|
||||
plocal = strstr(plocal+13, "program.local");
|
||||
}
|
||||
|
||||
glGenProgramsARB(1, &ps.glprogid);
|
||||
ps.bGLSL = false;
|
||||
PixelShaderCache::SetCurrentShader(ps.glprogid);
|
||||
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
|
||||
|
||||
err = GL_REPORT_ERROR();
|
||||
if (err != GL_NO_ERROR)
|
||||
{
|
||||
GLint error_pos, native_limit;
|
||||
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
|
||||
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit);
|
||||
// Error occur
|
||||
if (error_pos != -1) {
|
||||
const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
||||
char line[256];
|
||||
strncpy(line, (const char *)pcompiledprog + error_pos, 255);
|
||||
line[255] = 0;
|
||||
ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error);
|
||||
ERROR_LOG(VIDEO, "Line dump: \n%s", line);
|
||||
} else if (native_limit != -1) {
|
||||
ERROR_LOG(VIDEO, "Hit limit? %i", native_limit);
|
||||
// TODO
|
||||
}
|
||||
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
||||
ERROR_LOG(VIDEO, "%s", pcompiledprog);
|
||||
}
|
||||
|
||||
cgDestroyProgram(tempprog);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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)
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ struct FRAGMENTSHADER
|
||||
{
|
||||
if (glprogid)
|
||||
{
|
||||
if(bGLSL)
|
||||
if (bGLSL)
|
||||
glDeleteShader(glprogid);
|
||||
else
|
||||
glDeleteProgramsARB(1, &glprogid);
|
||||
|
@ -18,234 +18,247 @@
|
||||
#include "ProgramShaderCache.h"
|
||||
#include "MathUtil.h"
|
||||
|
||||
#include <assert.h>
|
||||
namespace OGL
|
||||
{
|
||||
GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0;
|
||||
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
||||
GLuint ProgramShaderCache::s_ps_vs_ubo;
|
||||
GLintptr ProgramShaderCache::s_vs_data_offset;
|
||||
|
||||
LinearDiskCache<PROGRAMUID, u8> g_program_disk_cache;
|
||||
GLenum ProgramFormat;
|
||||
GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0;
|
||||
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
||||
GLuint ProgramShaderCache::s_ps_vs_ubo;
|
||||
GLintptr ProgramShaderCache::s_vs_data_offset;
|
||||
|
||||
std::pair<u32, u32> 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,
|
||||
};
|
||||
LinearDiskCache<PROGRAMUID, u8> g_program_disk_cache;
|
||||
GLenum ProgramFormat;
|
||||
|
||||
void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry, const PROGRAMUID &uid)
|
||||
std::pair<u32, u32> 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::SetProgramVariables(PCacheEntry &entry, const PROGRAMUID &uid)
|
||||
{
|
||||
// Dunno why this is needed when I have the binding
|
||||
// points statically set in the shader source
|
||||
// We should only need these two functions when we don't support binding but do support UBO
|
||||
// Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
// Dunno why this is needed when I have the binding
|
||||
// points statically set in the shader source
|
||||
// We should only need these two functions when we don't support binding but do support UBO
|
||||
// Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
glUniformBlockBinding( entry.program.glprogid, 0, 1 );
|
||||
if(uid.uid.vsid != 0) // Some things have no vertex shader
|
||||
glUniformBlockBinding( entry.program.glprogid, 1, 2 );
|
||||
}
|
||||
|
||||
// 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.
|
||||
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
for(int a = 8; a < NUM_UNIFORMS; ++a)
|
||||
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
|
||||
if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||
for(int a = 0; a < 8; ++a)
|
||||
{
|
||||
// Still need to get sampler locations since we aren't binding them statically in the shaders
|
||||
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
|
||||
if(entry.program.UniformLocations[a] != -1)
|
||||
glUniform1i(entry.program.UniformLocations[a], a);
|
||||
}
|
||||
glUniformBlockBinding(entry.program.glprogid, 0, 1);
|
||||
// Some things have no vertex shader
|
||||
if (uid.uid.vsid != 0)
|
||||
glUniformBlockBinding(entry.program.glprogid, 1, 2);
|
||||
}
|
||||
|
||||
// Need to get some attribute locations
|
||||
if(uid.uid.vsid != 0 && !g_ActiveConfig.backend_info.bSupportsGLSLATTRBind) // We have no vertex Shader
|
||||
// We cache our uniform locations for now
|
||||
// Once we move up to a newer version of GLSL, ~1.30
|
||||
// We can remove this
|
||||
|
||||
// (Sonicadvance): 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.
|
||||
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
for (int a = 8; a < NUM_UNIFORMS; ++a)
|
||||
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
|
||||
|
||||
if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||
{
|
||||
for (int a = 0; a < 8; ++a)
|
||||
{
|
||||
glBindAttribLocation(entry.program.glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
|
||||
glBindAttribLocation(entry.program.glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
|
||||
glBindAttribLocation(entry.program.glprogid, SHADER_POSMTX_ATTRIB, "fposmtx");
|
||||
// Still need to get sampler locations since we aren't binding them statically in the shaders
|
||||
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
|
||||
if (entry.program.UniformLocations[a] != -1)
|
||||
glUniform1i(entry.program.UniformLocations[a], a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS)
|
||||
// Need to get some attribute locations
|
||||
if (uid.uid.vsid != 0 && !g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
|
||||
{
|
||||
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<u32, u32> 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.uid = uid;
|
||||
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);
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
|
||||
glProgramParameteri(entry.program.glprogid, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
|
||||
#endif
|
||||
|
||||
glLinkProgram(entry.program.glprogid);
|
||||
|
||||
glUseProgram(entry.program.glprogid);
|
||||
|
||||
SetProgramVariables(entry, uid);
|
||||
|
||||
pshaders[ShaderPair] = entry;
|
||||
CurrentShaderProgram = ShaderPair;
|
||||
CurrentProgram = entry.program.glprogid;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
||||
{
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4,
|
||||
count * sizeof(float) * 4, f);
|
||||
}
|
||||
|
||||
void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
||||
{
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, s_vs_data_offset + offset * sizeof(float) * 4,
|
||||
count * sizeof(float) * 4, f);
|
||||
}
|
||||
|
||||
GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; }
|
||||
|
||||
PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void)
|
||||
{
|
||||
return pshaders[CurrentShaderProgram].program;
|
||||
}
|
||||
void ProgramShaderCache::Init(void)
|
||||
{
|
||||
// We have to get the UBO alignment here because
|
||||
// if we generate a buffer that isn't aligned
|
||||
// then the UBO will fail.
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
GLint Align;
|
||||
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &Align);
|
||||
|
||||
GLintptr const ps_data_size = ROUND_UP(C_PENVCONST_END * sizeof(float) * 4, Align);
|
||||
GLintptr const vs_data_size = ROUND_UP(C_VENVCONST_END * sizeof(float) * 4, Align);
|
||||
s_vs_data_offset = ps_data_size;
|
||||
|
||||
// We multiply by *4*4 because we need to get down to basic machine units.
|
||||
// So multiply by four to get how many floats we have from vec4s
|
||||
// Then once more to get bytes
|
||||
glGenBuffers(1, &s_ps_vs_ubo);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, s_ps_vs_ubo);
|
||||
glBufferData(GL_UNIFORM_BUFFER, ps_data_size + vs_data_size, NULL, GL_DYNAMIC_DRAW);
|
||||
|
||||
// Now bind the buffer to the index point
|
||||
// We know PS is 0 since we have it statically set in the shader
|
||||
// Repeat for VS shader
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_ps_vs_ubo, 0, ps_data_size);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_ps_vs_ubo, s_vs_data_offset, vs_data_size);
|
||||
}
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
// Read our shader cache, only if supported
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
|
||||
{
|
||||
char cache_filename[MAX_PATH];
|
||||
sprintf(cache_filename, "%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
||||
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
|
||||
ProgramShaderCacheInserter inserter;
|
||||
g_program_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||
|
||||
GLint Supported;
|
||||
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &Supported);
|
||||
|
||||
GLint *Formats = new GLint[Supported];
|
||||
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, Formats);
|
||||
ProgramFormat = (GLenum)Formats[0]; // We don't really care about format
|
||||
delete[] Formats;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProgramShaderCache::Shutdown(void)
|
||||
{
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
|
||||
{
|
||||
PCache::iterator iter = pshaders.begin();
|
||||
for (; iter != pshaders.end(); ++iter)
|
||||
g_program_disk_cache.Append(iter->second.program.uid, iter->second.program.Data(), iter->second.program.Size());
|
||||
|
||||
g_program_disk_cache.Sync();
|
||||
g_program_disk_cache.Close();
|
||||
}
|
||||
|
||||
PCache::iterator iter = pshaders.begin();
|
||||
for (; iter != pshaders.end(); ++iter)
|
||||
iter->second.Destroy();
|
||||
pshaders.clear();
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
glDeleteBuffers(1, &s_ps_vs_ubo);
|
||||
s_ps_vs_ubo = 0;
|
||||
}
|
||||
// We have no vertex Shader
|
||||
glBindAttribLocation(entry.program.glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
|
||||
glBindAttribLocation(entry.program.glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
|
||||
glBindAttribLocation(entry.program.glprogid, SHADER_POSMTX_ATTRIB, "fposmtx");
|
||||
}
|
||||
}
|
||||
|
||||
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<u32, u32> 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.uid = uid;
|
||||
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);
|
||||
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
|
||||
glProgramParameteri(entry.program.glprogid, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
|
||||
#endif
|
||||
|
||||
glLinkProgram(entry.program.glprogid);
|
||||
|
||||
glUseProgram(entry.program.glprogid);
|
||||
|
||||
SetProgramVariables(entry, uid);
|
||||
|
||||
pshaders[ShaderPair] = entry;
|
||||
CurrentShaderProgram = ShaderPair;
|
||||
CurrentProgram = entry.program.glprogid;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
||||
{
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4,
|
||||
count * sizeof(float) * 4, f);
|
||||
}
|
||||
|
||||
void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
||||
{
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, s_vs_data_offset + offset * sizeof(float) * 4,
|
||||
count * sizeof(float) * 4, f);
|
||||
}
|
||||
|
||||
GLuint ProgramShaderCache::GetCurrentProgram(void)
|
||||
{
|
||||
return CurrentProgram;
|
||||
}
|
||||
|
||||
PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void)
|
||||
{
|
||||
return pshaders[CurrentShaderProgram].program;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::Init(void)
|
||||
{
|
||||
// We have to get the UBO alignment here because
|
||||
// if we generate a buffer that isn't aligned
|
||||
// then the UBO will fail.
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
GLint Align;
|
||||
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &Align);
|
||||
|
||||
GLintptr const ps_data_size = ROUND_UP(C_PENVCONST_END * sizeof(float) * 4, Align);
|
||||
GLintptr const vs_data_size = ROUND_UP(C_VENVCONST_END * sizeof(float) * 4, Align);
|
||||
s_vs_data_offset = ps_data_size;
|
||||
|
||||
// We multiply by *4*4 because we need to get down to basic machine units.
|
||||
// So multiply by four to get how many floats we have from vec4s
|
||||
// Then once more to get bytes
|
||||
glGenBuffers(1, &s_ps_vs_ubo);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, s_ps_vs_ubo);
|
||||
glBufferData(GL_UNIFORM_BUFFER, ps_data_size + vs_data_size, NULL, GL_DYNAMIC_DRAW);
|
||||
|
||||
// Now bind the buffer to the index point
|
||||
// We know PS is 0 since we have it statically set in the shader
|
||||
// Repeat for VS shader
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_ps_vs_ubo, 0, ps_data_size);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_ps_vs_ubo, s_vs_data_offset, vs_data_size);
|
||||
}
|
||||
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
// Read our shader cache, only if supported
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
|
||||
{
|
||||
char cache_filename[MAX_PATH];
|
||||
sprintf(cache_filename, "%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
||||
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
|
||||
ProgramShaderCacheInserter inserter;
|
||||
g_program_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||
|
||||
GLint Supported;
|
||||
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &Supported);
|
||||
|
||||
GLint *Formats = new GLint[Supported];
|
||||
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, Formats);
|
||||
// We don't really care about format
|
||||
ProgramFormat = (GLenum)Formats[0];
|
||||
delete[] Formats;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProgramShaderCache::Shutdown(void)
|
||||
{
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
|
||||
{
|
||||
PCache::iterator iter = pshaders.begin();
|
||||
for (; iter != pshaders.end(); ++iter)
|
||||
g_program_disk_cache.Append(iter->second.program.uid, iter->second.program.Data(), iter->second.program.Size());
|
||||
|
||||
g_program_disk_cache.Sync();
|
||||
g_program_disk_cache.Close();
|
||||
}
|
||||
|
||||
PCache::iterator iter = pshaders.begin();
|
||||
for (; iter != pshaders.end(); ++iter)
|
||||
iter->second.Destroy();
|
||||
pshaders.clear();
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
glDeleteBuffers(1, &s_ps_vs_ubo);
|
||||
s_ps_vs_ubo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OGL
|
||||
|
||||
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p)
|
||||
{
|
||||
uid->uid.vsid = _v;
|
||||
|
@ -15,8 +15,7 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#ifndef _ProgramShaderCache_H_
|
||||
#define _ProgramShaderCache_H_
|
||||
#pragma once
|
||||
|
||||
#include "GLUtil.h"
|
||||
|
||||
@ -28,18 +27,18 @@
|
||||
#include "LinearDiskCache.h"
|
||||
#include "ConfigManager.h"
|
||||
|
||||
union PID
|
||||
union PID
|
||||
{
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
GLuint vsid, psid;
|
||||
};
|
||||
u64 id;
|
||||
};
|
||||
u64 id;
|
||||
};
|
||||
|
||||
class PROGRAMUID
|
||||
{
|
||||
public:
|
||||
|
||||
PID uid;
|
||||
|
||||
PROGRAMUID()
|
||||
@ -51,57 +50,63 @@ public:
|
||||
{
|
||||
uid.id = r.uid.id;
|
||||
}
|
||||
|
||||
PROGRAMUID(GLuint _v, GLuint _p)
|
||||
{
|
||||
uid.vsid = _v;
|
||||
uid.psid = _p;
|
||||
}
|
||||
|
||||
int GetNumValues() const
|
||||
u64 GetNumValues() const
|
||||
{
|
||||
return uid.id;
|
||||
}
|
||||
};
|
||||
|
||||
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p);
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
#define NUM_UNIFORMS 27
|
||||
|
||||
const int NUM_UNIFORMS = 27;
|
||||
extern const char *UniformNames[NUM_UNIFORMS];
|
||||
extern GLenum ProgramFormat;
|
||||
|
||||
struct PROGRAMSHADER
|
||||
{
|
||||
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0), binaryLength(0){}
|
||||
GLuint glprogid; // opengl program id
|
||||
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0), binaryLength(0) {}
|
||||
// opengl program id
|
||||
GLuint glprogid;
|
||||
GLuint vsid, psid;
|
||||
PROGRAMUID uid;
|
||||
GLint UniformLocations[NUM_UNIFORMS];
|
||||
GLint binaryLength;
|
||||
|
||||
// TODO at first glance looks bad - malloc/no free/pointer not saved in instance...
|
||||
u8 *Data()
|
||||
{
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
|
||||
u8* binary = (u8*)malloc(binaryLength);
|
||||
glGetProgramBinary(glprogid, binaryLength, NULL, &ProgramFormat, binary);
|
||||
return binary;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
u8* binary = (u8*)malloc(binaryLength);
|
||||
glGetProgramBinary(glprogid, binaryLength, NULL, &ProgramFormat, binary);
|
||||
return binary;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
GLint Size()
|
||||
{
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
if(!binaryLength)
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
if (!binaryLength)
|
||||
glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
|
||||
return binaryLength;
|
||||
#else
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ProgramShaderCache
|
||||
{
|
||||
struct PCacheEntry
|
||||
@ -109,50 +114,54 @@ class ProgramShaderCache
|
||||
PROGRAMSHADER program;
|
||||
int frameCount;
|
||||
PCacheEntry() : frameCount(0) {}
|
||||
void Destroy() {
|
||||
|
||||
void Destroy()
|
||||
{
|
||||
glDeleteProgram(program.glprogid);
|
||||
program.glprogid = 0;
|
||||
}
|
||||
|
||||
u8* Data()
|
||||
{
|
||||
return program.Data();
|
||||
}
|
||||
|
||||
GLint Size()
|
||||
{
|
||||
return program.Size();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ProgramShaderCacheInserter : public LinearDiskCacheReader<PROGRAMUID, u8>
|
||||
{
|
||||
public:
|
||||
void Read(const PROGRAMUID &key, const u8 *value, u32 value_size)
|
||||
public:
|
||||
void Read(const PROGRAMUID &key, const u8 *value, u32 value_size)
|
||||
{
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
PCacheEntry entry;
|
||||
|
||||
// The two shaders might not even exist anymore
|
||||
// But it is fine, no need to worry about that
|
||||
entry.program.vsid = key.uid.vsid;
|
||||
entry.program.psid = key.uid.psid;
|
||||
|
||||
entry.program.glprogid = glCreateProgram();
|
||||
|
||||
glProgramBinary(entry.program.glprogid, ProgramFormat, value, value_size);
|
||||
|
||||
GLint success;
|
||||
glGetProgramiv(entry.program.glprogid, GL_LINK_STATUS, &success);
|
||||
|
||||
if (success)
|
||||
{
|
||||
#ifdef GLEW_VERSION_4_0
|
||||
PCacheEntry entry;
|
||||
|
||||
// The two shaders might not even exist anymore
|
||||
// But it is fine, no need to worry about that
|
||||
entry.program.vsid = key.uid.vsid;
|
||||
entry.program.psid = key.uid.psid;
|
||||
|
||||
entry.program.glprogid = glCreateProgram();
|
||||
|
||||
glProgramBinary(entry.program.glprogid, ProgramFormat, value, value_size);
|
||||
|
||||
GLint success;
|
||||
glGetProgramiv(entry.program.glprogid, GL_LINK_STATUS, &success);
|
||||
|
||||
if (success)
|
||||
{
|
||||
pshaders[std::make_pair(key.uid.psid, key.uid.vsid)] = entry;
|
||||
glUseProgram(entry.program.glprogid);
|
||||
SetProgramVariables(entry, key);
|
||||
}
|
||||
#endif
|
||||
pshaders[std::make_pair(key.uid.psid, key.uid.vsid)] = entry;
|
||||
glUseProgram(entry.program.glprogid);
|
||||
SetProgramVariables(entry, key);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef std::map<std::pair<u32, u32>, PCacheEntry> PCache;
|
||||
|
||||
static PCache pshaders;
|
||||
@ -162,7 +171,7 @@ class ProgramShaderCache
|
||||
static GLuint s_ps_vs_ubo;
|
||||
static GLintptr s_vs_data_offset;
|
||||
static void SetProgramVariables(PCacheEntry &entry, const PROGRAMUID &uid);
|
||||
|
||||
|
||||
public:
|
||||
static PROGRAMSHADER GetShaderProgram(void);
|
||||
static void SetBothShaders(GLuint PS, GLuint VS);
|
||||
@ -170,12 +179,9 @@ public:
|
||||
|
||||
static void SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count);
|
||||
static void SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count);
|
||||
|
||||
|
||||
static void Init(void);
|
||||
static void Shutdown(void);
|
||||
|
||||
};
|
||||
|
||||
} // namespace OGL
|
||||
|
||||
#endif
|
||||
|
@ -1419,7 +1419,7 @@ void Renderer::ResetAPIState()
|
||||
{
|
||||
// Gets us to a reasonably sane state where it's possible to do things like
|
||||
// image copies with textured quads, etc.
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
ProgramShaderCache::SetBothShaders(0, 0);
|
||||
else
|
||||
{
|
||||
|
@ -211,7 +211,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
|
||||
if (pcfmt != PC_TEX_FMT_DXT1)
|
||||
{
|
||||
if (expanded_width != width)
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
|
||||
|
||||
if (bHaveMipMaps && autogen_mips)
|
||||
{
|
||||
@ -225,7 +225,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
|
||||
}
|
||||
|
||||
if (expanded_width != width)
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -300,7 +300,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||
|
||||
glViewport(0, 0, virtual_width, virtual_height);
|
||||
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
ProgramShaderCache::SetBothShaders((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram(), 0);
|
||||
else
|
||||
PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
|
||||
@ -396,8 +396,8 @@ TextureCache::~TextureCache()
|
||||
{
|
||||
if (s_TempFramebuffer)
|
||||
{
|
||||
glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer);
|
||||
s_TempFramebuffer = 0;
|
||||
glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer);
|
||||
s_TempFramebuffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,9 +61,9 @@ static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS];
|
||||
void CreateRgbToYuyvProgram()
|
||||
{
|
||||
// Output is BGRA because that is slightly faster than RGBA.
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
if(g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||
{
|
||||
const char *FProgram =
|
||||
"#version 330 compatibility\n"
|
||||
@ -132,9 +132,9 @@ void CreateRgbToYuyvProgram()
|
||||
|
||||
void CreateYuyvToRgbProgram()
|
||||
{
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
if(g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||
{
|
||||
const char *FProgram =
|
||||
"#version 330 compatibility\n"
|
||||
@ -390,7 +390,7 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer,
|
||||
s32 expandedWidth = (width + blkW) & (~blkW);
|
||||
s32 expandedHeight = (height + blkH) & (~blkH);
|
||||
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
ProgramShaderCache::SetBothShaders(texconv_shader.glprogid, 0);
|
||||
else
|
||||
PixelShaderCache::SetCurrentShader(texconv_shader.glprogid);
|
||||
@ -425,7 +425,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des
|
||||
{
|
||||
g_renderer->ResetAPIState();
|
||||
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
ProgramShaderCache::SetBothShaders(s_rgbToYuyvProgram.glprogid, 0);
|
||||
else
|
||||
PixelShaderCache::SetCurrentShader(s_rgbToYuyvProgram.glprogid);
|
||||
@ -472,7 +472,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_srcTexture);
|
||||
|
||||
// TODO: make this less slow. (How?)
|
||||
if((GLsizei)s_srcTextureWidth == (GLsizei)srcFmtWidth && (GLsizei)s_srcTextureHeight == (GLsizei)srcHeight)
|
||||
if ((GLsizei)s_srcTextureWidth == (GLsizei)srcFmtWidth && (GLsizei)s_srcTextureHeight == (GLsizei)srcHeight)
|
||||
{
|
||||
glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,0,0,s_srcTextureWidth, s_srcTextureHeight,
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, srcAddr);
|
||||
@ -486,7 +486,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
|
||||
}
|
||||
|
||||
glViewport(0, 0, srcWidth, srcHeight);
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
ProgramShaderCache::SetBothShaders(s_yuyvToRgbProgram.glprogid, 0);
|
||||
else
|
||||
PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);
|
||||
|
@ -195,7 +195,7 @@ void VertexManager::vFlush()
|
||||
}
|
||||
VERTEXSHADER* vs = VertexShaderCache::SetShader(g_nativeVertexFmt->m_components);
|
||||
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid);
|
||||
else
|
||||
{
|
||||
@ -218,10 +218,10 @@ void VertexManager::vFlush()
|
||||
if (useDstAlpha && !dualSourcePossible)
|
||||
{
|
||||
ps = PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components);
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
ProgramShaderCache::SetBothShaders(ps->glprogid, 0);
|
||||
if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO
|
||||
if (g_nativeVertexFmt)
|
||||
g_nativeVertexFmt->SetupVertexPointers();
|
||||
|
@ -16,7 +16,6 @@
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "Globals.h"
|
||||
#include "VideoConfig.h"
|
||||
@ -55,98 +54,97 @@ bool (*pCompileVertexShader)(VERTEXSHADER&, const char*);
|
||||
|
||||
void VertexShaderCache::Init()
|
||||
{
|
||||
ShaderEnabled = true;
|
||||
CurrentShader = 0;
|
||||
last_entry = NULL;
|
||||
ShaderEnabled = true;
|
||||
CurrentShader = 0;
|
||||
last_entry = NULL;
|
||||
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
pSetVSConstant4f = SetGLSLVSConstant4f;
|
||||
pSetVSConstant4fv = SetGLSLVSConstant4fv;
|
||||
pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv;
|
||||
pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv;
|
||||
pCompileVertexShader = CompileGLSLVertexShader;
|
||||
}
|
||||
else
|
||||
{
|
||||
pSetVSConstant4f = SetCGVSConstant4f;
|
||||
pSetVSConstant4fv = SetCGVSConstant4fv;
|
||||
pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv;
|
||||
pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv;
|
||||
pCompileVertexShader = CompileCGVertexShader;
|
||||
glEnable(GL_VERTEX_PROGRAM_ARB);
|
||||
}
|
||||
if (g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
pSetVSConstant4f = SetGLSLVSConstant4f;
|
||||
pSetVSConstant4fv = SetGLSLVSConstant4fv;
|
||||
pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv;
|
||||
pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv;
|
||||
pCompileVertexShader = CompileGLSLVertexShader;
|
||||
}
|
||||
else
|
||||
{
|
||||
pSetVSConstant4f = SetCGVSConstant4f;
|
||||
pSetVSConstant4fv = SetCGVSConstant4fv;
|
||||
pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv;
|
||||
pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv;
|
||||
pCompileVertexShader = CompileCGVertexShader;
|
||||
glEnable(GL_VERTEX_PROGRAM_ARB);
|
||||
}
|
||||
|
||||
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;
|
||||
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 (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
|
||||
{
|
||||
s_nMaxVertexInstructions = 4096;
|
||||
}
|
||||
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
|
||||
{
|
||||
s_nMaxVertexInstructions = 4096;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void VertexShaderCache::Shutdown()
|
||||
{
|
||||
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter)
|
||||
iter->second.Destroy();
|
||||
vshaders.clear();
|
||||
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter)
|
||||
iter->second.Destroy();
|
||||
vshaders.clear();
|
||||
}
|
||||
|
||||
|
||||
VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
|
||||
{
|
||||
VERTEXSHADERUID uid;
|
||||
GetVertexShaderId(&uid, components);
|
||||
if (last_entry)
|
||||
{
|
||||
if (uid == last_uid)
|
||||
VERTEXSHADERUID uid;
|
||||
GetVertexShaderId(&uid, components);
|
||||
if (last_entry)
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
|
||||
return &last_entry->shader;
|
||||
if (uid == last_uid)
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
|
||||
return &last_entry->shader;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
last_uid = uid;
|
||||
last_uid = uid;
|
||||
|
||||
VSCache::iterator iter = vshaders.find(uid);
|
||||
if (iter != vshaders.end())
|
||||
{
|
||||
VSCacheEntry &entry = iter->second;
|
||||
VSCache::iterator iter = vshaders.find(uid);
|
||||
if (iter != vshaders.end())
|
||||
{
|
||||
VSCacheEntry &entry = iter->second;
|
||||
last_entry = &entry;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
|
||||
return &last_entry->shader;
|
||||
}
|
||||
|
||||
// Make an entry in the table
|
||||
VSCacheEntry& entry = vshaders[uid];
|
||||
last_entry = &entry;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
|
||||
return &last_entry->shader;
|
||||
}
|
||||
|
||||
// Make an entry in the table
|
||||
VSCacheEntry& entry = vshaders[uid];
|
||||
last_entry = &entry;
|
||||
const char *code = GenerateVertexShaderCode(components, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL);
|
||||
GetSafeVertexShaderId(&entry.safe_uid, components);
|
||||
const char *code = GenerateVertexShaderCode(components, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL);
|
||||
GetSafeVertexShaderId(&entry.safe_uid, components);
|
||||
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
|
||||
static int counter = 0;
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
||||
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
|
||||
static int counter = 0;
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
||||
|
||||
SaveData(szTemp, code);
|
||||
}
|
||||
SaveData(szTemp, code);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) {
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
||||
return NULL;
|
||||
}
|
||||
if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) {
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
INCSTAT(stats.numVertexShadersCreated);
|
||||
SETSTAT(stats.numVertexShadersAlive, vshaders.size());
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||
return &last_entry->shader;
|
||||
INCSTAT(stats.numVertexShadersCreated);
|
||||
SETSTAT(stats.numVertexShadersAlive, vshaders.size());
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||
return &last_entry->shader;
|
||||
}
|
||||
|
||||
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
||||
@ -156,32 +154,28 @@ bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrpr
|
||||
|
||||
void VertexShaderCache::DisableShader()
|
||||
{
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
assert(true);
|
||||
if (ShaderEnabled)
|
||||
{
|
||||
glDisable(GL_VERTEX_PROGRAM_ARB);
|
||||
ShaderEnabled = false;
|
||||
}
|
||||
if (ShaderEnabled)
|
||||
{
|
||||
glDisable(GL_VERTEX_PROGRAM_ARB);
|
||||
ShaderEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VertexShaderCache::SetCurrentShader(GLuint Shader)
|
||||
{
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
assert(true);
|
||||
if (!ShaderEnabled)
|
||||
{
|
||||
glEnable(GL_VERTEX_PROGRAM_ARB);
|
||||
ShaderEnabled= true;
|
||||
}
|
||||
if (CurrentShader != Shader)
|
||||
{
|
||||
if(Shader != 0)
|
||||
CurrentShader = Shader;
|
||||
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
|
||||
}
|
||||
if (!ShaderEnabled)
|
||||
{
|
||||
glEnable(GL_VERTEX_PROGRAM_ARB);
|
||||
ShaderEnabled= true;
|
||||
}
|
||||
if (CurrentShader != Shader)
|
||||
{
|
||||
if (Shader != 0)
|
||||
CurrentShader = Shader;
|
||||
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL Specific
|
||||
bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
||||
{
|
||||
@ -205,12 +199,12 @@ bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
||||
GLchar* infoLog = new GLchar[length];
|
||||
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
|
||||
WARN_LOG(VIDEO, "VS Shader info log:\n%s", infoLog);
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "vs_%d.txt", result);
|
||||
FILE *fp = fopen(szTemp, "wb");
|
||||
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
|
||||
fclose(fp);
|
||||
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "vs_%d.txt", result);
|
||||
FILE *fp = fopen(szTemp, "wb");
|
||||
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
|
||||
fclose(fp);
|
||||
|
||||
delete[] infoLog;
|
||||
}
|
||||
// Don't try to use this shader
|
||||
@ -223,39 +217,43 @@ bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
||||
vs.bGLSL = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetVSConstant4fvByName(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]))
|
||||
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
||||
for (int a = 0; a < NUM_UNIFORMS; ++a)
|
||||
{
|
||||
if(tmp.UniformLocations[a] == -1)
|
||||
return;
|
||||
else
|
||||
{
|
||||
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
|
||||
return;
|
||||
}
|
||||
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)
|
||||
{
|
||||
float const buf[4] = {f1, f2, f3, f4};
|
||||
|
||||
float const buf[4] = {f1, f2, f3, f4};
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, 1);
|
||||
return;
|
||||
}
|
||||
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))
|
||||
for (unsigned int a = 0; a < 9; ++a)
|
||||
{
|
||||
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
||||
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf);
|
||||
return;
|
||||
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 SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
|
||||
@ -265,15 +263,15 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
|
||||
ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, 1);
|
||||
return;
|
||||
}
|
||||
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))
|
||||
for (unsigned int a = 0; a < 9; ++a)
|
||||
{
|
||||
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
||||
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f);
|
||||
return;
|
||||
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)
|
||||
@ -283,157 +281,157 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co
|
||||
ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, count);
|
||||
return;
|
||||
}
|
||||
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))
|
||||
for (unsigned int a = 0; a < 9; ++a)
|
||||
{
|
||||
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
||||
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count);
|
||||
return;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, count);
|
||||
return;
|
||||
}
|
||||
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))
|
||||
for (unsigned int a = 0; a < 9; ++a)
|
||||
{
|
||||
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
||||
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count);
|
||||
return;
|
||||
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
|
||||
bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
||||
{
|
||||
// Reset GL error before compiling shaders. Yeah, we need to investigate the causes of these.
|
||||
GLenum err = GL_REPORT_ERROR();
|
||||
if (err != GL_NO_ERROR)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "glError %08x before VS!", err);
|
||||
}
|
||||
// Reset GL error before compiling shaders. Yeah, we need to investigate the causes of these.
|
||||
GLenum err = GL_REPORT_ERROR();
|
||||
if (err != GL_NO_ERROR)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "glError %08x before VS!", err);
|
||||
}
|
||||
|
||||
#if defined HAVE_CG && HAVE_CG
|
||||
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", NULL);
|
||||
if (!cgIsProgram(tempprog)) {
|
||||
static int num_failures = 0;
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "bad_vs_%04i.txt", num_failures++);
|
||||
std::ofstream file(szTemp);
|
||||
file << pstrprogram;
|
||||
file.close();
|
||||
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", NULL);
|
||||
if (!cgIsProgram(tempprog)) {
|
||||
static int num_failures = 0;
|
||||
char szTemp[MAX_PATH];
|
||||
sprintf(szTemp, "bad_vs_%04i.txt", num_failures++);
|
||||
std::ofstream file(szTemp);
|
||||
file << pstrprogram;
|
||||
file.close();
|
||||
|
||||
PanicAlert("Failed to compile vertex shader %d!\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",
|
||||
num_failures - 1, szTemp,
|
||||
g_cgfProf,
|
||||
cgGetLastListing(g_cgcontext));
|
||||
PanicAlert("Failed to compile vertex shader %d!\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",
|
||||
num_failures - 1, szTemp,
|
||||
g_cgfProf,
|
||||
cgGetLastListing(g_cgcontext));
|
||||
|
||||
cgDestroyProgram(tempprog);
|
||||
ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
|
||||
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cgGetError() != CG_NO_ERROR)
|
||||
{
|
||||
WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
|
||||
WARN_LOG(VIDEO, "%s", pstrprogram);
|
||||
}
|
||||
|
||||
// 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...
|
||||
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
|
||||
char *plocal = strstr(pcompiledprog, "program.local");
|
||||
while (plocal != NULL) {
|
||||
const char* penv = " program.env";
|
||||
memcpy(plocal, penv, 13);
|
||||
plocal = strstr(plocal + 13, "program.local");
|
||||
}
|
||||
glGenProgramsARB(1, &vs.glprogid);
|
||||
vs.bGLSL = false;
|
||||
VertexShaderCache::SetCurrentShader(vs.glprogid);
|
||||
|
||||
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
|
||||
err = GL_REPORT_ERROR();
|
||||
if (err != GL_NO_ERROR) {
|
||||
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
||||
ERROR_LOG(VIDEO, "%s", pcompiledprog);
|
||||
}
|
||||
|
||||
cgDestroyProgram(tempprog);
|
||||
ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
|
||||
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cgGetError() != CG_NO_ERROR)
|
||||
{
|
||||
WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
|
||||
WARN_LOG(VIDEO, "%s", pstrprogram);
|
||||
}
|
||||
|
||||
// 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...
|
||||
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
|
||||
char *plocal = strstr(pcompiledprog, "program.local");
|
||||
while (plocal != NULL) {
|
||||
const char* penv = " program.env";
|
||||
memcpy(plocal, penv, 13);
|
||||
plocal = strstr(plocal + 13, "program.local");
|
||||
}
|
||||
glGenProgramsARB(1, &vs.glprogid);
|
||||
vs.bGLSL = false;
|
||||
VertexShaderCache::SetCurrentShader(vs.glprogid);
|
||||
|
||||
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
|
||||
err = GL_REPORT_ERROR();
|
||||
if (err != GL_NO_ERROR) {
|
||||
ERROR_LOG(VIDEO, "%s", pstrprogram);
|
||||
ERROR_LOG(VIDEO, "%s", pcompiledprog);
|
||||
}
|
||||
|
||||
cgDestroyProgram(tempprog);
|
||||
#endif
|
||||
|
||||
if (g_ActiveConfig.bEnableShaderDebugging)
|
||||
vs.strprog = pstrprogram;
|
||||
if (g_ActiveConfig.bEnableShaderDebugging)
|
||||
vs.strprog = pstrprogram;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
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)
|
||||
{
|
||||
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = 0; i < count; i++,f+=4)
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f);
|
||||
}
|
||||
if (GLEW_EXT_gpu_program_parameters)
|
||||
{
|
||||
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = 0; i < count; i++,f+=4)
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f);
|
||||
}
|
||||
}
|
||||
|
||||
void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
|
||||
{
|
||||
if(GLEW_EXT_gpu_program_parameters)
|
||||
{
|
||||
float buf[4 * C_VENVCONST_END];
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (GLEW_EXT_gpu_program_parameters)
|
||||
{
|
||||
buf[4*i ] = *f++;
|
||||
buf[4*i+1] = *f++;
|
||||
buf[4*i+2] = *f++;
|
||||
buf[4*i+3] = 0.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;
|
||||
}
|
||||
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf);
|
||||
}
|
||||
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
else
|
||||
{
|
||||
float buf[4];
|
||||
buf[0] = *f++;
|
||||
buf[1] = *f++;
|
||||
buf[2] = *f++;
|
||||
buf[3] = 0.f;
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
float buf[4];
|
||||
buf[0] = *f++;
|
||||
buf[1] = *f++;
|
||||
buf[2] = *f++;
|
||||
buf[3] = 0.f;
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Renderer Functions
|
||||
@ -457,5 +455,4 @@ void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int cou
|
||||
pSetMultiVSConstant3fv(const_number, count, f);
|
||||
}
|
||||
|
||||
|
||||
} // namespace OGL
|
||||
|
@ -32,7 +32,7 @@ struct VERTEXSHADER
|
||||
VERTEXSHADER() : glprogid(0), bGLSL(0) {}
|
||||
void Destroy()
|
||||
{
|
||||
if(bGLSL)
|
||||
if (bGLSL)
|
||||
glDeleteShader(glprogid);
|
||||
else
|
||||
glDeleteProgramsARB(1, &glprogid);
|
||||
|
Reference in New Issue
Block a user