merge Vertex and PixelShaderCache into ProgramShaderCache
this is the first step, uniform handling is still missing
This commit is contained in:
parent
818a376bd4
commit
bbc292c210
|
@ -224,7 +224,6 @@
|
||||||
<ClInclude Include="Src\Globals.h" />
|
<ClInclude Include="Src\Globals.h" />
|
||||||
<ClInclude Include="Src\GLUtil.h" />
|
<ClInclude Include="Src\GLUtil.h" />
|
||||||
<ClInclude Include="Src\main.h" />
|
<ClInclude Include="Src\main.h" />
|
||||||
<ClInclude Include="Src\PixelShaderCache.h" />
|
|
||||||
<ClInclude Include="Src\PostProcessing.h" />
|
<ClInclude Include="Src\PostProcessing.h" />
|
||||||
<ClInclude Include="Src\ProgramShaderCache.h" />
|
<ClInclude Include="Src\ProgramShaderCache.h" />
|
||||||
<ClInclude Include="Src\RasterFont.h" />
|
<ClInclude Include="Src\RasterFont.h" />
|
||||||
|
@ -234,7 +233,6 @@
|
||||||
<ClInclude Include="Src\TextureCache.h" />
|
<ClInclude Include="Src\TextureCache.h" />
|
||||||
<ClInclude Include="Src\TextureConverter.h" />
|
<ClInclude Include="Src\TextureConverter.h" />
|
||||||
<ClInclude Include="Src\VertexManager.h" />
|
<ClInclude Include="Src\VertexManager.h" />
|
||||||
<ClInclude Include="Src\VertexShaderCache.h" />
|
|
||||||
<ClInclude Include="Src\VideoBackend.h" />
|
<ClInclude Include="Src\VideoBackend.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -63,9 +63,6 @@
|
||||||
<ClInclude Include="Src\FramebufferManager.h">
|
<ClInclude Include="Src\FramebufferManager.h">
|
||||||
<Filter>Render</Filter>
|
<Filter>Render</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Src\PixelShaderCache.h">
|
|
||||||
<Filter>Render</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Src\PostProcessing.h">
|
<ClInclude Include="Src\PostProcessing.h">
|
||||||
<Filter>Render</Filter>
|
<Filter>Render</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -78,9 +75,6 @@
|
||||||
<ClInclude Include="Src\TextureCache.h">
|
<ClInclude Include="Src\TextureCache.h">
|
||||||
<Filter>Render</Filter>
|
<Filter>Render</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Src\VertexShaderCache.h">
|
|
||||||
<Filter>Render</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="CMakeLists.txt" />
|
<None Include="CMakeLists.txt" />
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include "Render.h"
|
#include "Render.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
#include "PixelShaderCache.h"
|
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "OnScreenDisplay.h"
|
#include "OnScreenDisplay.h"
|
||||||
#include "StringUtil.h"
|
#include "StringUtil.h"
|
||||||
|
@ -38,136 +37,6 @@
|
||||||
namespace OGL
|
namespace OGL
|
||||||
{
|
{
|
||||||
|
|
||||||
static int s_nMaxPixelInstructions;
|
|
||||||
PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
|
|
||||||
PIXELSHADERUID PixelShaderCache::s_curuid;
|
|
||||||
bool PixelShaderCache::s_displayCompileAlert;
|
|
||||||
GLuint PixelShaderCache::CurrentShader;
|
|
||||||
bool PixelShaderCache::ShaderEnabled;
|
|
||||||
|
|
||||||
PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry = NULL;
|
|
||||||
PIXELSHADERUID PixelShaderCache::last_uid;
|
|
||||||
|
|
||||||
void PixelShaderCache::Init()
|
|
||||||
{
|
|
||||||
ShaderEnabled = true;
|
|
||||||
CurrentShader = 0;
|
|
||||||
last_entry = NULL;
|
|
||||||
GL_REPORT_ERRORD();
|
|
||||||
|
|
||||||
s_displayCompileAlert = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PixelShaderCache::Shutdown()
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make an entry in the table
|
|
||||||
PSCacheEntry& newentry = PixelShaders[uid];
|
|
||||||
last_entry = &newentry;
|
|
||||||
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 (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);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
|
||||||
{
|
|
||||||
GLuint result = glCreateShader(GL_FRAGMENT_SHADER);
|
|
||||||
|
|
||||||
glShaderSource(result, 1, &pstrprogram, NULL);
|
|
||||||
glCompileShader(result);
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
|
||||||
GLsizei length = 0;
|
|
||||||
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length);
|
|
||||||
if (length > 1)
|
|
||||||
{
|
|
||||||
GLsizei charsWritten;
|
|
||||||
GLchar* infoLog = new GLchar[length];
|
|
||||||
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
|
|
||||||
ERROR_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(infoLog, strlen(infoLog), 1, fp);
|
|
||||||
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
|
|
||||||
fclose(fp);
|
|
||||||
delete[] infoLog;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLint compileStatus;
|
|
||||||
glGetShaderiv(result, GL_COMPILE_STATUS, &compileStatus);
|
|
||||||
if (compileStatus != GL_TRUE)
|
|
||||||
{
|
|
||||||
// Compile failed
|
|
||||||
ERROR_LOG(VIDEO, "Shader compilation failed; see info log");
|
|
||||||
|
|
||||||
// Don't try to use this shader
|
|
||||||
glDeleteShader(result);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
(void)GL_REPORT_ERROR();
|
|
||||||
ps.glprogid = result;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
||||||
{
|
{
|
||||||
ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram();
|
ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
|
@ -175,11 +44,11 @@ void SetPSConstant4fvByName(const char * name, unsigned int offset, const float
|
||||||
{
|
{
|
||||||
if (!strcmp(name, UniformNames[a]))
|
if (!strcmp(name, UniformNames[a]))
|
||||||
{
|
{
|
||||||
if (tmp.UniformLocations[a] == -1)
|
if (tmp.shader.UniformLocations[a] == -1)
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
|
glUniform4fv(tmp.shader.UniformLocations[a] + offset, count, f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
// 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 _PIXELSHADERCACHE_H_
|
|
||||||
#define _PIXELSHADERCACHE_H_
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "BPMemory.h"
|
|
||||||
#include "PixelShaderGen.h"
|
|
||||||
|
|
||||||
namespace OGL
|
|
||||||
{
|
|
||||||
|
|
||||||
struct FRAGMENTSHADER
|
|
||||||
{
|
|
||||||
FRAGMENTSHADER() : glprogid(0) { }
|
|
||||||
void Destroy()
|
|
||||||
{
|
|
||||||
if (glprogid)
|
|
||||||
{
|
|
||||||
glDeleteShader(glprogid);
|
|
||||||
glprogid = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GLuint glprogid; // opengl program id
|
|
||||||
|
|
||||||
std::string strprog;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PixelShaderCache
|
|
||||||
{
|
|
||||||
struct PSCacheEntry
|
|
||||||
{
|
|
||||||
FRAGMENTSHADER shader;
|
|
||||||
PSCacheEntry() {}
|
|
||||||
~PSCacheEntry() {}
|
|
||||||
void Destroy()
|
|
||||||
{
|
|
||||||
shader.Destroy();
|
|
||||||
}
|
|
||||||
PIXELSHADERUIDSAFE safe_uid;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::map<PIXELSHADERUID, PSCacheEntry> PSCache;
|
|
||||||
|
|
||||||
static PSCache PixelShaders;
|
|
||||||
|
|
||||||
static PIXELSHADERUID s_curuid; // the current pixel shader uid (progressively changed as memory is written)
|
|
||||||
|
|
||||||
static bool s_displayCompileAlert;
|
|
||||||
|
|
||||||
static GLuint CurrentShader;
|
|
||||||
static PSCacheEntry* last_entry;
|
|
||||||
static PIXELSHADERUID last_uid;
|
|
||||||
|
|
||||||
static bool ShaderEnabled;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void Init();
|
|
||||||
static void Shutdown();
|
|
||||||
|
|
||||||
static FRAGMENTSHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
|
|
||||||
static bool CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram);
|
|
||||||
};
|
|
||||||
} // namespace OGL
|
|
||||||
|
|
||||||
#endif // _PIXELSHADERCACHE_H_
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "VideoConfig.h"
|
#include "VideoConfig.h"
|
||||||
#include "GLUtil.h"
|
#include "GLUtil.h"
|
||||||
#include "PostProcessing.h"
|
#include "PostProcessing.h"
|
||||||
#include "PixelShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
|
|
||||||
namespace OGL
|
namespace OGL
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@ namespace PostProcessing
|
||||||
{
|
{
|
||||||
|
|
||||||
static std::string s_currentShader;
|
static std::string s_currentShader;
|
||||||
static FRAGMENTSHADER s_shader;
|
static SHADER s_shader;
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
|
@ -63,10 +63,10 @@ bool ApplyShader()
|
||||||
std::string code;
|
std::string code;
|
||||||
if (File::ReadFileToString(true, s_currentShader.c_str(), code))
|
if (File::ReadFileToString(true, s_currentShader.c_str(), code))
|
||||||
{
|
{
|
||||||
if (!PixelShaderCache::CompilePixelShader(s_shader, code.c_str()))
|
//if (!ProgramShaderCache::CompileShader(s_shader, "#version130\n...", code.c_str()))
|
||||||
{
|
//{
|
||||||
ERROR_LOG(VIDEO, "Failed to compile post-processing shader %s", s_currentShader.c_str());
|
// ERROR_LOG(VIDEO, "Failed to compile post-processing shader %s", s_currentShader.c_str());
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -78,7 +78,7 @@ bool ApplyShader()
|
||||||
// TODO: Convert PP shaders to GLSL
|
// TODO: Convert PP shaders to GLSL
|
||||||
if (s_shader.glprogid != 0)
|
if (s_shader.glprogid != 0)
|
||||||
{
|
{
|
||||||
// SetBothShaders(s_shader, 0);
|
s_shader.Bind();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -18,37 +18,30 @@
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
#include "MathUtil.h"
|
#include "MathUtil.h"
|
||||||
#include "StreamBuffer.h"
|
#include "StreamBuffer.h"
|
||||||
|
#include "Debugger.h"
|
||||||
|
#include "Statistics.h"
|
||||||
|
|
||||||
namespace OGL
|
namespace OGL
|
||||||
{
|
{
|
||||||
|
|
||||||
static const u32 UBO_LENGTH = 4*1024*1024;
|
static const u32 UBO_LENGTH = 4*1024*1024;
|
||||||
|
|
||||||
GLuint ProgramShaderCache::CurrentProgram = 0;
|
static GLuint CurrentProgram = 0;
|
||||||
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
||||||
GLintptr ProgramShaderCache::s_vs_data_offset;
|
GLintptr ProgramShaderCache::s_vs_data_offset;
|
||||||
u8 *ProgramShaderCache::s_ubo_buffer;
|
u8 *ProgramShaderCache::s_ubo_buffer;
|
||||||
u32 ProgramShaderCache::s_ubo_buffer_size;
|
u32 ProgramShaderCache::s_ubo_buffer_size;
|
||||||
bool ProgramShaderCache::s_ubo_dirty;
|
bool ProgramShaderCache::s_ubo_dirty;
|
||||||
|
|
||||||
LinearDiskCache<u64, u8> g_program_disk_cache;
|
LinearDiskCache<SHADERUID, u8> g_program_disk_cache;
|
||||||
GLenum ProgramFormat;
|
GLenum ProgramFormat;
|
||||||
|
|
||||||
GLuint ProgramShaderCache::PCacheEntry::prog_format = 0;
|
GLuint ProgramShaderCache::PCacheEntry::prog_format = 0;
|
||||||
|
|
||||||
u64 ProgramShaderCache::CurrentShaderProgram;
|
|
||||||
|
|
||||||
static StreamBuffer *s_buffer;
|
static StreamBuffer *s_buffer;
|
||||||
|
|
||||||
u64 Create_Pair(u32 key1, u32 key2)
|
ProgramShaderCache::PCacheEntry* ProgramShaderCache::last_entry;
|
||||||
{
|
SHADERUID ProgramShaderCache::last_uid;
|
||||||
return (((u64)key1) << 32) | key2;
|
|
||||||
}
|
|
||||||
void Get_Pair(u64 key, u32 *key1, u32 *key2)
|
|
||||||
{
|
|
||||||
*key1 = (key & 0xFFFFFFFF00000000) >> 32;
|
|
||||||
*key2 = key & 0xFFFFFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *UniformNames[NUM_UNIFORMS] =
|
const char *UniformNames[NUM_UNIFORMS] =
|
||||||
{
|
{
|
||||||
|
@ -75,18 +68,21 @@ const char *UniformNames[NUM_UNIFORMS] =
|
||||||
I_DEPTHPARAMS,
|
I_DEPTHPARAMS,
|
||||||
};
|
};
|
||||||
|
|
||||||
void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry)
|
void SHADER::SetProgramVariables()
|
||||||
{
|
{
|
||||||
|
// glsl shader must be bind to set samplers
|
||||||
|
Bind();
|
||||||
|
|
||||||
// Bind UBO
|
// Bind UBO
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
{
|
{
|
||||||
GLint PSBlock_id = glGetUniformBlockIndex(entry.prog_id, "PSBlock");
|
GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock");
|
||||||
GLint VSBlock_id = glGetUniformBlockIndex(entry.prog_id, "VSBlock");
|
GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock");
|
||||||
|
|
||||||
if(PSBlock_id != -1)
|
if(PSBlock_id != -1)
|
||||||
glUniformBlockBinding(entry.prog_id, PSBlock_id, 1);
|
glUniformBlockBinding(glprogid, PSBlock_id, 1);
|
||||||
if(VSBlock_id != -1)
|
if(VSBlock_id != -1)
|
||||||
glUniformBlockBinding(entry.prog_id, VSBlock_id, 2);
|
glUniformBlockBinding(glprogid, VSBlock_id, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We cache our uniform locations for now
|
// We cache our uniform locations for now
|
||||||
|
@ -94,12 +90,12 @@ void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry)
|
||||||
// We can remove this
|
// We can remove this
|
||||||
|
|
||||||
// (Sonicadvance): For some reason this fails on my hardware
|
// (Sonicadvance): For some reason this fails on my hardware
|
||||||
//glGetUniformIndices(entry.prog_id, NUM_UNIFORMS, UniformNames, entry.UniformLocations);
|
//glGetUniformIndices(glprogid, NUM_UNIFORMS, UniformNames, UniformLocations);
|
||||||
// Got to do it this crappy way.
|
// Got to do it this crappy way.
|
||||||
entry.UniformLocations[0] = glGetUniformLocation(entry.prog_id, UniformNames[0]);
|
UniformLocations[0] = glGetUniformLocation(glprogid, UniformNames[0]);
|
||||||
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
for (int a = 1; a < NUM_UNIFORMS; ++a)
|
for (int a = 1; a < NUM_UNIFORMS; ++a)
|
||||||
entry.UniformLocations[a] = glGetUniformLocation(entry.prog_id, UniformNames[a]);
|
UniformLocations[a] = glGetUniformLocation(glprogid, UniformNames[a]);
|
||||||
|
|
||||||
// Bind Texture Sampler
|
// Bind Texture Sampler
|
||||||
for (int a = 0; a <= 9; ++a)
|
for (int a = 0; a <= 9; ++a)
|
||||||
|
@ -108,134 +104,55 @@ void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry)
|
||||||
snprintf(name, 8, "samp%d", a);
|
snprintf(name, 8, "samp%d", a);
|
||||||
|
|
||||||
// Still need to get sampler locations since we aren't binding them statically in the shaders
|
// Still need to get sampler locations since we aren't binding them statically in the shaders
|
||||||
int loc = glGetUniformLocation(entry.prog_id, name);
|
int loc = glGetUniformLocation(glprogid, name);
|
||||||
if (loc != -1)
|
if (loc != -1)
|
||||||
glUniform1i(loc, a);
|
glUniform1i(loc, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramShaderCache::SetProgramBindings ( ProgramShaderCache::PCacheEntry& entry )
|
void SHADER::SetProgramBindings()
|
||||||
{
|
{
|
||||||
if (g_ActiveConfig.backend_info.bSupportsDualSourceBlend)
|
if (g_ActiveConfig.backend_info.bSupportsDualSourceBlend)
|
||||||
{
|
{
|
||||||
// So we do support extended blending
|
// So we do support extended blending
|
||||||
// So we need to set a few more things here.
|
// So we need to set a few more things here.
|
||||||
// Bind our out locations
|
// Bind our out locations
|
||||||
glBindFragDataLocationIndexed(entry.prog_id, 0, 0, "ocol0");
|
glBindFragDataLocationIndexed(glprogid, 0, 0, "ocol0");
|
||||||
glBindFragDataLocationIndexed(entry.prog_id, 0, 1, "ocol1");
|
glBindFragDataLocationIndexed(glprogid, 0, 1, "ocol1");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glBindFragDataLocation(entry.prog_id, 0, "ocol0");
|
glBindFragDataLocation(glprogid, 0, "ocol0");
|
||||||
|
|
||||||
// Need to set some attribute locations
|
// Need to set some attribute locations
|
||||||
glBindAttribLocation(entry.prog_id, SHADER_POSITION_ATTRIB, "rawpos");
|
glBindAttribLocation(glprogid, SHADER_POSITION_ATTRIB, "rawpos");
|
||||||
|
|
||||||
glBindAttribLocation(entry.prog_id, SHADER_POSMTX_ATTRIB, "fposmtx");
|
glBindAttribLocation(glprogid, SHADER_POSMTX_ATTRIB, "fposmtx");
|
||||||
|
|
||||||
glBindAttribLocation(entry.prog_id, SHADER_COLOR0_ATTRIB, "color0");
|
glBindAttribLocation(glprogid, SHADER_COLOR0_ATTRIB, "color0");
|
||||||
glBindAttribLocation(entry.prog_id, SHADER_COLOR1_ATTRIB, "color1");
|
glBindAttribLocation(glprogid, SHADER_COLOR1_ATTRIB, "color1");
|
||||||
|
|
||||||
glBindAttribLocation(entry.prog_id, SHADER_NORM0_ATTRIB, "rawnorm0");
|
glBindAttribLocation(glprogid, SHADER_NORM0_ATTRIB, "rawnorm0");
|
||||||
glBindAttribLocation(entry.prog_id, SHADER_NORM1_ATTRIB, "rawnorm1");
|
glBindAttribLocation(glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
|
||||||
glBindAttribLocation(entry.prog_id, SHADER_NORM2_ATTRIB, "rawnorm2");
|
glBindAttribLocation(glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
|
||||||
|
|
||||||
for(int i=0; i<8; i++) {
|
for(int i=0; i<8; i++) {
|
||||||
char attrib_name[8];
|
char attrib_name[8];
|
||||||
snprintf(attrib_name, 8, "tex%d", i);
|
snprintf(attrib_name, 8, "tex%d", i);
|
||||||
glBindAttribLocation(entry.prog_id, SHADER_TEXTURE0_ATTRIB+i, attrib_name);
|
glBindAttribLocation(glprogid, SHADER_TEXTURE0_ATTRIB+i, attrib_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHADER::Bind()
|
||||||
void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS)
|
|
||||||
{
|
{
|
||||||
if(!PS || !VS) {
|
if(CurrentProgram != glprogid)
|
||||||
ERROR_LOG(VIDEO, "tried to bind a zero shader");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 ShaderPair = Create_Pair(PS, VS);
|
|
||||||
|
|
||||||
// program is already bound
|
|
||||||
if(ShaderPair == CurrentShaderProgram) return;
|
|
||||||
|
|
||||||
PCache::iterator iter = pshaders.find(ShaderPair);
|
|
||||||
if (iter != pshaders.end())
|
|
||||||
{
|
{
|
||||||
PCacheEntry &entry = iter->second;
|
glUseProgram(glprogid);
|
||||||
glUseProgram(entry.prog_id);
|
CurrentProgram = glprogid;
|
||||||
CurrentProgram = entry.prog_id;
|
|
||||||
CurrentShaderProgram = ShaderPair;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PCacheEntry entry;
|
|
||||||
entry.Create(PS, VS);
|
|
||||||
|
|
||||||
// Right, the program is created now
|
|
||||||
// Let's attach everything
|
|
||||||
glAttachShader(entry.prog_id, entry.vsid);
|
|
||||||
glAttachShader(entry.prog_id, entry.psid);
|
|
||||||
|
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
|
|
||||||
glProgramParameteri(entry.prog_id, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
|
|
||||||
|
|
||||||
SetProgramBindings(entry);
|
|
||||||
|
|
||||||
glLinkProgram(entry.prog_id);
|
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
|
||||||
GLsizei length = 0;
|
|
||||||
glGetProgramiv(entry.prog_id, GL_INFO_LOG_LENGTH, &length);
|
|
||||||
if (length > 1)
|
|
||||||
{
|
|
||||||
GLsizei charsWritten;
|
|
||||||
GLchar* infoLog = new GLchar[length];
|
|
||||||
glGetProgramInfoLog(entry.prog_id, length, &charsWritten, infoLog);
|
|
||||||
ERROR_LOG(VIDEO, "Program info log:\n%s", infoLog);
|
|
||||||
char szTemp[MAX_PATH];
|
|
||||||
sprintf(szTemp, "p_%d.txt", entry.prog_id);
|
|
||||||
FILE *fp = fopen(szTemp, "wb");
|
|
||||||
fwrite(infoLog, length, 1, fp);
|
|
||||||
delete[] infoLog;
|
|
||||||
|
|
||||||
glGetShaderiv(VS, GL_SHADER_SOURCE_LENGTH, &length);
|
|
||||||
GLchar* src = new GLchar[length];
|
|
||||||
glGetShaderSource(VS, length, &charsWritten, src);
|
|
||||||
fwrite(src, strlen(src), 1, fp);
|
|
||||||
delete [] src;
|
|
||||||
|
|
||||||
glGetShaderiv(PS, GL_SHADER_SOURCE_LENGTH, &length);
|
|
||||||
src = new GLchar[length];
|
|
||||||
glGetShaderSource(PS, length, &charsWritten, src);
|
|
||||||
fwrite(src, strlen(src), 1, fp);
|
|
||||||
delete [] src;
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
GLint linkStatus;
|
|
||||||
glGetProgramiv(entry.prog_id, GL_LINK_STATUS, &linkStatus);
|
|
||||||
if (linkStatus != GL_TRUE)
|
|
||||||
{
|
|
||||||
// Compile failed
|
|
||||||
ERROR_LOG(VIDEO, "Program linking failed; see info log");
|
|
||||||
|
|
||||||
// Don't try to use this shader
|
|
||||||
glDeleteProgram(entry.prog_id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
glUseProgram(entry.prog_id);
|
|
||||||
|
|
||||||
SetProgramVariables(entry);
|
|
||||||
|
|
||||||
pshaders[ShaderPair] = entry;
|
|
||||||
CurrentShaderProgram = ShaderPair;
|
|
||||||
CurrentProgram = entry.prog_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
|
||||||
{
|
{
|
||||||
s_ubo_dirty = true;
|
s_ubo_dirty = true;
|
||||||
|
@ -264,9 +181,207 @@ GLuint ProgramShaderCache::GetCurrentProgram(void)
|
||||||
return CurrentProgram;
|
return CurrentProgram;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHADER* ProgramShaderCache::SetShader ( DSTALPHA_MODE dstAlphaMode, u32 components )
|
||||||
|
{
|
||||||
|
SHADERUID uid;
|
||||||
|
GetShaderId(&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);
|
||||||
|
ValidateShaderIDs(last_entry, dstAlphaMode, components);
|
||||||
|
last_entry->shader.Bind();
|
||||||
|
return &last_entry->shader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
last_uid = uid;
|
||||||
|
|
||||||
|
// Check if shader is already in cache
|
||||||
|
PCache::iterator iter = pshaders.find(uid);
|
||||||
|
if (iter != pshaders.end())
|
||||||
|
{
|
||||||
|
PCacheEntry *entry = &iter->second;
|
||||||
|
last_entry = entry;
|
||||||
|
|
||||||
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
|
ValidateShaderIDs(entry, dstAlphaMode, components);
|
||||||
|
last_entry->shader.Bind();
|
||||||
|
return &last_entry->shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make an entry in the table
|
||||||
|
PCacheEntry& newentry = pshaders[uid];
|
||||||
|
last_entry = &newentry;
|
||||||
|
|
||||||
|
const char *vcode = GenerateVertexShaderCode(components, API_OPENGL);
|
||||||
|
const char *pcode = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components);
|
||||||
|
|
||||||
|
if (g_ActiveConfig.bEnableShaderDebugging)
|
||||||
|
{
|
||||||
|
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components);
|
||||||
|
newentry.shader.strvprog = vcode;
|
||||||
|
newentry.shader.strpprog = pcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
|
if (g_ActiveConfig.iLog & CONF_SAVESHADERS) {
|
||||||
|
static int counter = 0;
|
||||||
|
char szTemp[MAX_PATH];
|
||||||
|
sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
||||||
|
SaveData(szTemp, vcode);
|
||||||
|
sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
||||||
|
SaveData(szTemp, pcode);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!CompileShader(newentry.shader, vcode, pcode)) {
|
||||||
|
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
INCSTAT(stats.numPixelShadersCreated);
|
||||||
|
SETSTAT(stats.numPixelShadersAlive, pshaders.size());
|
||||||
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
|
|
||||||
|
last_entry->shader.Bind();
|
||||||
|
return &last_entry->shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProgramShaderCache::CompileShader ( SHADER& shader, const char* vcode, const char* pcode )
|
||||||
|
{
|
||||||
|
GLuint vsid = CompileSingleShader(GL_VERTEX_SHADER, vcode);
|
||||||
|
GLuint psid = CompileSingleShader(GL_FRAGMENT_SHADER, pcode);
|
||||||
|
|
||||||
|
if(!vsid || !psid)
|
||||||
|
{
|
||||||
|
glDeleteShader(vsid);
|
||||||
|
glDeleteShader(psid);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint pid = shader.glprogid = glCreateProgram();;
|
||||||
|
|
||||||
|
glAttachShader(pid, vsid);
|
||||||
|
glAttachShader(pid, psid);
|
||||||
|
|
||||||
|
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
|
||||||
|
glProgramParameteri(pid, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
|
||||||
|
|
||||||
|
shader.SetProgramBindings();
|
||||||
|
|
||||||
|
glLinkProgram(pid);
|
||||||
|
|
||||||
|
// original shaders aren't needed any more
|
||||||
|
glDeleteShader(vsid);
|
||||||
|
glDeleteShader(psid);
|
||||||
|
|
||||||
|
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
||||||
|
GLsizei length = 0;
|
||||||
|
glGetProgramiv(pid, GL_INFO_LOG_LENGTH, &length);
|
||||||
|
if (length > 1)
|
||||||
|
{
|
||||||
|
GLsizei charsWritten;
|
||||||
|
GLchar* infoLog = new GLchar[length];
|
||||||
|
glGetProgramInfoLog(pid, length, &charsWritten, infoLog);
|
||||||
|
ERROR_LOG(VIDEO, "Program info log:\n%s", infoLog);
|
||||||
|
char szTemp[MAX_PATH];
|
||||||
|
sprintf(szTemp, "p_%d.txt", pid);
|
||||||
|
FILE *fp = fopen(szTemp, "wb");
|
||||||
|
fwrite(infoLog, length, 1, fp);
|
||||||
|
delete[] infoLog;
|
||||||
|
fwrite(vcode, strlen(vcode), 1, fp);
|
||||||
|
fwrite(pcode, strlen(pcode), 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLint linkStatus;
|
||||||
|
glGetProgramiv(pid, GL_LINK_STATUS, &linkStatus);
|
||||||
|
if (linkStatus != GL_TRUE)
|
||||||
|
{
|
||||||
|
// Compile failed
|
||||||
|
ERROR_LOG(VIDEO, "Program linking failed; see info log");
|
||||||
|
|
||||||
|
// Don't try to use this shader
|
||||||
|
glDeleteProgram(pid);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
shader.SetProgramVariables();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint ProgramShaderCache::CompileSingleShader (GLuint type, const char* code )
|
||||||
|
{
|
||||||
|
GLuint result = glCreateShader(type);
|
||||||
|
|
||||||
|
const char *src[] = {code};
|
||||||
|
|
||||||
|
glShaderSource(result, 1, src, NULL);
|
||||||
|
glCompileShader(result);
|
||||||
|
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
||||||
|
GLsizei length = 0;
|
||||||
|
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length);
|
||||||
|
if (length > 1)
|
||||||
|
{
|
||||||
|
GLsizei charsWritten;
|
||||||
|
GLchar* infoLog = new GLchar[length];
|
||||||
|
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
|
||||||
|
ERROR_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(infoLog, strlen(infoLog), 1, fp);
|
||||||
|
fwrite(code, strlen(code), 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
delete[] infoLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLint compileStatus;
|
||||||
|
glGetShaderiv(result, GL_COMPILE_STATUS, &compileStatus);
|
||||||
|
if (compileStatus != GL_TRUE)
|
||||||
|
{
|
||||||
|
// Compile failed
|
||||||
|
ERROR_LOG(VIDEO, "Shader compilation failed; see info log");
|
||||||
|
|
||||||
|
// Don't try to use this shader
|
||||||
|
glDeleteShader(result);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
(void)GL_REPORT_ERROR();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ProgramShaderCache::GetShaderId ( SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 components )
|
||||||
|
{
|
||||||
|
GetPixelShaderId(&uid->puid, dstAlphaMode, components);
|
||||||
|
GetVertexShaderId(&uid->vuid, components);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramShaderCache::GetSafeShaderId ( SHADERUIDSAFE* uid, DSTALPHA_MODE dstAlphaMode, u32 components )
|
||||||
|
{
|
||||||
|
GetSafePixelShaderId(&uid->puid, dstAlphaMode, components);
|
||||||
|
GetSafeVertexShaderId(&uid->vuid, components);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramShaderCache::ValidateShaderIDs ( PCacheEntry *entry, DSTALPHA_MODE dstAlphaMode, u32 components )
|
||||||
|
{
|
||||||
|
//ValidatePixelShaderIDs(API_OPENGL, entry->safe_uid, entry->shader.strprog, dstAlphaMode, components);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ProgramShaderCache::PCacheEntry ProgramShaderCache::GetShaderProgram(void)
|
ProgramShaderCache::PCacheEntry ProgramShaderCache::GetShaderProgram(void)
|
||||||
{
|
{
|
||||||
return pshaders[CurrentShaderProgram];
|
return *last_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramShaderCache::Init(void)
|
void ProgramShaderCache::Init(void)
|
||||||
|
@ -308,7 +423,7 @@ void ProgramShaderCache::Init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentProgram = 0;
|
CurrentProgram = 0;
|
||||||
CurrentShaderProgram = 0;
|
last_entry = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramShaderCache::Shutdown(void)
|
void ProgramShaderCache::Shutdown(void)
|
||||||
|
@ -318,7 +433,7 @@ void ProgramShaderCache::Shutdown(void)
|
||||||
PCache::iterator iter = pshaders.begin();
|
PCache::iterator iter = pshaders.begin();
|
||||||
for (; iter != pshaders.end(); ++iter)
|
for (; iter != pshaders.end(); ++iter)
|
||||||
{
|
{
|
||||||
g_program_disk_cache.Append(iter->second.uid, iter->second.GetProgram(), iter->second.Size());
|
g_program_disk_cache.Append(iter->first, iter->second.GetProgram(), iter->second.Size());
|
||||||
iter->second.FreeProgram();
|
iter->second.FreeProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,4 +457,23 @@ void ProgramShaderCache::Shutdown(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProgramShaderCache::ProgramShaderCacheInserter::Read ( const SHADERUID& key, const u8* value, u32 value_size )
|
||||||
|
{
|
||||||
|
// The two shaders might not even exist anymore
|
||||||
|
// But it is fine, no need to worry about that
|
||||||
|
PCacheEntry entry;
|
||||||
|
entry.shader.glprogid = glCreateProgram();
|
||||||
|
glProgramBinary(entry.shader.glprogid, entry.prog_format, value, value_size);
|
||||||
|
|
||||||
|
GLint success;
|
||||||
|
glGetProgramiv(entry.shader.glprogid, GL_LINK_STATUS, &success);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
pshaders[key] = entry;
|
||||||
|
entry.shader.SetProgramVariables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace OGL
|
} // namespace OGL
|
||||||
|
|
|
@ -20,28 +20,63 @@
|
||||||
|
|
||||||
#include "GLUtil.h"
|
#include "GLUtil.h"
|
||||||
|
|
||||||
#include "VertexShaderCache.h"
|
|
||||||
#include "PixelShaderCache.h"
|
|
||||||
#include "PixelShaderGen.h"
|
#include "PixelShaderGen.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
|
|
||||||
#include "LinearDiskCache.h"
|
#include "LinearDiskCache.h"
|
||||||
#include "ConfigManager.h"
|
#include "ConfigManager.h"
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include <tr1/unordered_map>
|
|
||||||
using namespace std::tr1;
|
|
||||||
#else
|
|
||||||
#include <unordered_map>
|
|
||||||
using namespace std;
|
|
||||||
#endif
|
|
||||||
namespace OGL
|
namespace OGL
|
||||||
{
|
{
|
||||||
|
|
||||||
|
template<bool safe>
|
||||||
|
class _SHADERUID
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
_VERTEXSHADERUID<safe> vuid;
|
||||||
|
_PIXELSHADERUID<safe> puid;
|
||||||
|
|
||||||
|
_SHADERUID() {}
|
||||||
|
|
||||||
|
_SHADERUID(const _SHADERUID& r) : vuid(r.vuid), puid(r.puid) {}
|
||||||
|
|
||||||
|
bool operator <(const _SHADERUID& r) const
|
||||||
|
{
|
||||||
|
if(puid < r.puid) return true;
|
||||||
|
if(r.puid < puid) return false;
|
||||||
|
if(vuid < r.vuid) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator ==(const _SHADERUID& r) const
|
||||||
|
{
|
||||||
|
return puid == r.puid && vuid == r.vuid;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
typedef _SHADERUID<false> SHADERUID;
|
||||||
|
typedef _SHADERUID<true> SHADERUIDSAFE;
|
||||||
|
|
||||||
|
|
||||||
const int NUM_UNIFORMS = 19;
|
const int NUM_UNIFORMS = 19;
|
||||||
extern const char *UniformNames[NUM_UNIFORMS];
|
extern const char *UniformNames[NUM_UNIFORMS];
|
||||||
u64 Create_Pair(u32 key1, u32 key2);
|
|
||||||
void Get_Pair(u64 key, u32 *key1, u32 *key2);
|
struct SHADER
|
||||||
|
{
|
||||||
|
SHADER() : glprogid(0) { }
|
||||||
|
void Destroy()
|
||||||
|
{
|
||||||
|
glDeleteProgram(glprogid);
|
||||||
|
glprogid = 0;
|
||||||
|
}
|
||||||
|
GLuint glprogid; // opengl program id
|
||||||
|
|
||||||
|
std::string strvprog, strpprog;
|
||||||
|
GLint UniformLocations[NUM_UNIFORMS];
|
||||||
|
|
||||||
|
void SetProgramVariables();
|
||||||
|
void SetProgramBindings();
|
||||||
|
void Bind();
|
||||||
|
};
|
||||||
|
|
||||||
class ProgramShaderCache
|
class ProgramShaderCache
|
||||||
{
|
{
|
||||||
|
@ -49,39 +84,27 @@ public:
|
||||||
|
|
||||||
struct PCacheEntry
|
struct PCacheEntry
|
||||||
{
|
{
|
||||||
GLuint prog_id;
|
SHADER shader;
|
||||||
|
PIXELSHADERUIDSAFE safe_uid;
|
||||||
|
|
||||||
static GLenum prog_format;
|
static GLenum prog_format;
|
||||||
u8 *binary;
|
u8 *binary;
|
||||||
GLint binary_size;
|
GLint binary_size;
|
||||||
GLuint vsid, psid;
|
|
||||||
u64 uid;
|
|
||||||
GLint UniformLocations[NUM_UNIFORMS];
|
|
||||||
|
|
||||||
PCacheEntry() : prog_id(0), binary(NULL), binary_size(0), vsid(0), psid(0) { }
|
PCacheEntry() :binary(NULL), binary_size(0) { }
|
||||||
|
|
||||||
~PCacheEntry()
|
~PCacheEntry() {}
|
||||||
{
|
|
||||||
FreeProgram();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Create(const GLuint pix_id, const GLuint vert_id)
|
|
||||||
{
|
|
||||||
psid = pix_id;
|
|
||||||
vsid = vert_id;
|
|
||||||
uid = Create_Pair(psid, vsid);
|
|
||||||
prog_id = glCreateProgram();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Destroy()
|
void Destroy()
|
||||||
{
|
{
|
||||||
glDeleteProgram(prog_id);
|
shader.Destroy();
|
||||||
prog_id = 0;
|
FreeProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateSize()
|
void UpdateSize()
|
||||||
{
|
{
|
||||||
if (binary_size == 0)
|
if (binary_size == 0)
|
||||||
glGetProgramiv(prog_id, GL_PROGRAM_BINARY_LENGTH, &binary_size);
|
glGetProgramiv(shader.glprogid, GL_PROGRAM_BINARY_LENGTH, &binary_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No idea how necessary this is
|
// No idea how necessary this is
|
||||||
|
@ -103,7 +126,7 @@ public:
|
||||||
UpdateSize();
|
UpdateSize();
|
||||||
FreeProgram();
|
FreeProgram();
|
||||||
binary = new u8[binary_size];
|
binary = new u8[binary_size];
|
||||||
glGetProgramBinary(prog_id, binary_size, NULL, &prog_format, binary);
|
glGetProgramBinary(shader.glprogid, binary_size, NULL, &prog_format, binary);
|
||||||
return binary;
|
return binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +144,14 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
static PCacheEntry GetShaderProgram(void);
|
static PCacheEntry GetShaderProgram(void);
|
||||||
static void SetBothShaders(GLuint PS, GLuint VS);
|
|
||||||
static GLuint GetCurrentProgram(void);
|
static GLuint GetCurrentProgram(void);
|
||||||
|
static SHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
|
static void GetShaderId(SHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
|
static void GetSafeShaderId(SHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
|
static void ValidateShaderIDs(PCacheEntry *entry, DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
|
|
||||||
|
static bool CompileShader(SHADER &shader, const char* vcode, const char* pcode);
|
||||||
|
static GLuint CompileSingleShader(GLuint type, const char *code);
|
||||||
|
|
||||||
static void SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count);
|
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 SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count);
|
||||||
|
@ -132,44 +161,22 @@ public:
|
||||||
static void Shutdown(void);
|
static void Shutdown(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class ProgramShaderCacheInserter : public LinearDiskCacheReader<u64, u8>
|
class ProgramShaderCacheInserter : public LinearDiskCacheReader<SHADERUID, u8>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Read(const u64 &key, const u8 *value, u32 value_size)
|
void Read(const SHADERUID &key, const u8 *value, u32 value_size);
|
||||||
{
|
|
||||||
// The two shaders might not even exist anymore
|
|
||||||
// But it is fine, no need to worry about that
|
|
||||||
PCacheEntry entry;
|
|
||||||
u32 key1, key2;
|
|
||||||
Get_Pair(key, &key1, &key2);
|
|
||||||
entry.Create(key1, key2);
|
|
||||||
|
|
||||||
glProgramBinary(entry.prog_id, entry.prog_format, value, value_size);
|
|
||||||
|
|
||||||
GLint success;
|
|
||||||
glGetProgramiv(entry.prog_id, GL_LINK_STATUS, &success);
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
pshaders[key] = entry;
|
|
||||||
glUseProgram(entry.prog_id);
|
|
||||||
SetProgramVariables(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef unordered_map<u64, PCacheEntry> PCache;
|
typedef std::map<SHADERUID, PCacheEntry> PCache;
|
||||||
|
|
||||||
static PCache pshaders;
|
static PCache pshaders;
|
||||||
static GLuint CurrentProgram;
|
static PCacheEntry* last_entry;
|
||||||
static u64 CurrentShaderProgram;
|
static SHADERUID last_uid;
|
||||||
|
|
||||||
static GLintptr s_vs_data_offset;
|
static GLintptr s_vs_data_offset;
|
||||||
static u8 *s_ubo_buffer;
|
static u8 *s_ubo_buffer;
|
||||||
static u32 s_ubo_buffer_size;
|
static u32 s_ubo_buffer_size;
|
||||||
static bool s_ubo_dirty;
|
static bool s_ubo_dirty;
|
||||||
static void SetProgramVariables(PCacheEntry &entry);
|
|
||||||
static void SetProgramBindings(PCacheEntry &entry);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace OGL
|
} // namespace OGL
|
||||||
|
|
|
@ -18,9 +18,7 @@
|
||||||
#include "GLUtil.h"
|
#include "GLUtil.h"
|
||||||
|
|
||||||
#include "RasterFont.h"
|
#include "RasterFont.h"
|
||||||
#include "PixelShaderCache.h"
|
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
#include "VertexShaderCache.h"
|
|
||||||
// globals
|
// globals
|
||||||
|
|
||||||
namespace OGL {
|
namespace OGL {
|
||||||
|
@ -149,9 +147,7 @@ static const char *s_fragmentShaderSrc =
|
||||||
" ocol0 = texture(samp8,uv0) * color;\n"
|
" ocol0 = texture(samp8,uv0) * color;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
static SHADER s_shader;
|
||||||
static FRAGMENTSHADER s_fragmentShader;
|
|
||||||
static VERTEXSHADER s_vertexShader;
|
|
||||||
|
|
||||||
RasterFont::RasterFont()
|
RasterFont::RasterFont()
|
||||||
{
|
{
|
||||||
|
@ -174,14 +170,11 @@ RasterFont::RasterFont()
|
||||||
delete [] texture_data;
|
delete [] texture_data;
|
||||||
|
|
||||||
// generate shader
|
// generate shader
|
||||||
VertexShaderCache::CompileVertexShader(s_vertexShader, s_vertexShaderSrc);
|
ProgramShaderCache::CompileShader(s_shader, s_vertexShaderSrc, s_fragmentShaderSrc);
|
||||||
PixelShaderCache::CompilePixelShader(s_fragmentShader, s_fragmentShaderSrc);
|
|
||||||
ProgramShaderCache::SetBothShaders(s_fragmentShader.glprogid, s_vertexShader.glprogid);
|
|
||||||
GLuint shader_program = ProgramShaderCache::GetCurrentProgram();
|
|
||||||
|
|
||||||
// bound uniforms
|
// bound uniforms
|
||||||
glUniform2f(glGetUniformLocation(shader_program,"charSize"), 1.0f / GLfloat(char_count), 1.0f);
|
glUniform2f(glGetUniformLocation(s_shader.glprogid,"charSize"), 1.0f / GLfloat(char_count), 1.0f);
|
||||||
uniform_color_id = glGetUniformLocation(shader_program,"color");
|
uniform_color_id = glGetUniformLocation(s_shader.glprogid,"color");
|
||||||
glUniform4f(uniform_color_id, 1.0f, 1.0f, 1.0f, 1.0f);
|
glUniform4f(uniform_color_id, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
cached_color = -1;
|
cached_color = -1;
|
||||||
|
|
||||||
|
@ -201,8 +194,7 @@ RasterFont::~RasterFont()
|
||||||
glDeleteTextures(1, &texture);
|
glDeleteTextures(1, &texture);
|
||||||
glDeleteBuffers(1, &VBO);
|
glDeleteBuffers(1, &VBO);
|
||||||
glDeleteVertexArrays(1, &VAO);
|
glDeleteVertexArrays(1, &VAO);
|
||||||
s_fragmentShader.Destroy();
|
s_shader.Destroy();
|
||||||
s_vertexShader.Destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color)
|
void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color)
|
||||||
|
@ -280,7 +272,7 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
|
||||||
|
|
||||||
delete [] vertices;
|
delete [] vertices;
|
||||||
|
|
||||||
ProgramShaderCache::SetBothShaders(s_fragmentShader.glprogid, s_vertexShader.glprogid);
|
s_shader.Bind();
|
||||||
|
|
||||||
if(color != cached_color) {
|
if(color != cached_color) {
|
||||||
glUniform4f(uniform_color_id, GLfloat((color>>16)&0xff)/255.f,GLfloat((color>>8)&0xff)/255.f,GLfloat((color>>0)&0xff)/255.f,GLfloat((color>>24)&0xff)/255.f);
|
glUniform4f(uniform_color_id, GLfloat((color>>16)&0xff)/255.f,GLfloat((color>>8)&0xff)/255.f,GLfloat((color>>0)&0xff)/255.f,GLfloat((color>>24)&0xff)/255.f);
|
||||||
|
|
|
@ -43,10 +43,8 @@
|
||||||
#include "RasterFont.h"
|
#include "RasterFont.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
#include "DLCache.h"
|
#include "DLCache.h"
|
||||||
#include "PixelShaderCache.h"
|
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
#include "VertexShaderCache.h"
|
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
#include "VertexLoaderManager.h"
|
#include "VertexLoaderManager.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
|
@ -107,8 +105,7 @@ namespace OGL
|
||||||
static int s_fps = 0;
|
static int s_fps = 0;
|
||||||
static GLuint s_ShowEFBCopyRegions_VBO = 0;
|
static GLuint s_ShowEFBCopyRegions_VBO = 0;
|
||||||
static GLuint s_ShowEFBCopyRegions_VAO = 0;
|
static GLuint s_ShowEFBCopyRegions_VAO = 0;
|
||||||
static FRAGMENTSHADER s_ShowEFBCopyRegions_PS;
|
static SHADER s_ShowEFBCopyRegions;
|
||||||
static VERTEXSHADER s_ShowEFBCopyRegions_VS;
|
|
||||||
|
|
||||||
static RasterFont* s_pfont = NULL;
|
static RasterFont* s_pfont = NULL;
|
||||||
|
|
||||||
|
@ -433,23 +430,14 @@ void Renderer::Shutdown()
|
||||||
|
|
||||||
delete s_pfont;
|
delete s_pfont;
|
||||||
s_pfont = 0;
|
s_pfont = 0;
|
||||||
s_ShowEFBCopyRegions_PS.Destroy();
|
s_ShowEFBCopyRegions.Destroy();
|
||||||
s_ShowEFBCopyRegions_VS.Destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Init()
|
void Renderer::Init()
|
||||||
{
|
{
|
||||||
s_pfont = new RasterFont();
|
s_pfont = new RasterFont();
|
||||||
|
|
||||||
PixelShaderCache::CompilePixelShader(s_ShowEFBCopyRegions_PS,
|
ProgramShaderCache::CompileShader(s_ShowEFBCopyRegions,
|
||||||
"#version 130\n"
|
|
||||||
"in vec4 c;\n"
|
|
||||||
"out vec4 ocol0;\n"
|
|
||||||
"void main(void) {\n"
|
|
||||||
" ocol0 = c;\n"
|
|
||||||
"}\n"
|
|
||||||
);
|
|
||||||
VertexShaderCache::CompileVertexShader(s_ShowEFBCopyRegions_VS,
|
|
||||||
"#version 130\n"
|
"#version 130\n"
|
||||||
"in vec2 rawpos;\n"
|
"in vec2 rawpos;\n"
|
||||||
"in vec3 color0;\n"
|
"in vec3 color0;\n"
|
||||||
|
@ -457,8 +445,13 @@ void Renderer::Init()
|
||||||
"void main(void) {\n"
|
"void main(void) {\n"
|
||||||
" gl_Position = vec4(rawpos,0,1);\n"
|
" gl_Position = vec4(rawpos,0,1);\n"
|
||||||
" c = vec4(color0, 1.0);\n"
|
" c = vec4(color0, 1.0);\n"
|
||||||
"}\n"
|
"}\n",
|
||||||
);
|
"#version 130\n"
|
||||||
|
"in vec4 c;\n"
|
||||||
|
"out vec4 ocol0;\n"
|
||||||
|
"void main(void) {\n"
|
||||||
|
" ocol0 = c;\n"
|
||||||
|
"}\n");
|
||||||
|
|
||||||
// creating buffers
|
// creating buffers
|
||||||
glGenBuffers(1, &s_ShowEFBCopyRegions_VBO);
|
glGenBuffers(1, &s_ShowEFBCopyRegions_VBO);
|
||||||
|
@ -603,7 +596,7 @@ void Renderer::DrawDebugInfo()
|
||||||
}
|
}
|
||||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||||
|
|
||||||
ProgramShaderCache::SetBothShaders(s_ShowEFBCopyRegions_PS.glprogid, s_ShowEFBCopyRegions_VS.glprogid);
|
s_ShowEFBCopyRegions.Bind();
|
||||||
glBindVertexArray( s_ShowEFBCopyRegions_VAO );
|
glBindVertexArray( s_ShowEFBCopyRegions_VAO );
|
||||||
glDrawArrays(GL_LINES, 0, stats.efb_regions.size() * 2*6);
|
glDrawArrays(GL_LINES, 0, stats.efb_regions.size() * 2*6);
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include "HW/Memmap.h"
|
#include "HW/Memmap.h"
|
||||||
#include "ImageWrite.h"
|
#include "ImageWrite.h"
|
||||||
#include "MemoryUtil.h"
|
#include "MemoryUtil.h"
|
||||||
#include "PixelShaderCache.h"
|
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "Render.h"
|
#include "Render.h"
|
||||||
|
@ -57,13 +56,12 @@
|
||||||
namespace OGL
|
namespace OGL
|
||||||
{
|
{
|
||||||
|
|
||||||
static FRAGMENTSHADER s_ColorMatrixProgram;
|
static SHADER s_ColorMatrixProgram;
|
||||||
static FRAGMENTSHADER s_DepthMatrixProgram;
|
static SHADER s_DepthMatrixProgram;
|
||||||
static GLuint s_ColorMatrixUniform;
|
static GLuint s_ColorMatrixUniform;
|
||||||
static GLuint s_DepthMatrixUniform;
|
static GLuint s_DepthMatrixUniform;
|
||||||
static u32 s_ColorCbufid;
|
static u32 s_ColorCbufid;
|
||||||
static u32 s_DepthCbufid;
|
static u32 s_DepthCbufid;
|
||||||
static VERTEXSHADER s_vProgram;
|
|
||||||
|
|
||||||
static u32 s_Textures[8];
|
static u32 s_Textures[8];
|
||||||
static u32 s_ActiveTexture;
|
static u32 s_ActiveTexture;
|
||||||
|
@ -335,12 +333,12 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||||
glViewport(0, 0, virtual_width, virtual_height);
|
glViewport(0, 0, virtual_width, virtual_height);
|
||||||
|
|
||||||
if(srcFormat == PIXELFMT_Z24) {
|
if(srcFormat == PIXELFMT_Z24) {
|
||||||
ProgramShaderCache::SetBothShaders(s_DepthMatrixProgram.glprogid, s_vProgram.glprogid);
|
s_DepthMatrixProgram.Bind();
|
||||||
if(s_DepthCbufid != cbufid)
|
if(s_DepthCbufid != cbufid)
|
||||||
glUniform4fv(s_DepthMatrixUniform, 5, colmat);
|
glUniform4fv(s_DepthMatrixUniform, 5, colmat);
|
||||||
s_DepthCbufid = cbufid;
|
s_DepthCbufid = cbufid;
|
||||||
} else {
|
} else {
|
||||||
ProgramShaderCache::SetBothShaders(s_ColorMatrixProgram.glprogid, s_vProgram.glprogid);
|
s_ColorMatrixProgram.Bind();
|
||||||
if(s_ColorCbufid != cbufid)
|
if(s_ColorCbufid != cbufid)
|
||||||
glUniform4fv(s_ColorMatrixUniform, 7, colmat);
|
glUniform4fv(s_ColorMatrixUniform, 7, colmat);
|
||||||
s_ColorCbufid = cbufid;
|
s_ColorCbufid = cbufid;
|
||||||
|
@ -499,11 +497,6 @@ TextureCache::TextureCache()
|
||||||
" Temp1.w = dot(Temp0, colmat[3]);\n"
|
" Temp1.w = dot(Temp0, colmat[3]);\n"
|
||||||
" ocol0 = Temp1 + colmat[4];\n"
|
" ocol0 = Temp1 + colmat[4];\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
if (!PixelShaderCache::CompilePixelShader(s_ColorMatrixProgram, pColorMatrixProg))
|
|
||||||
{
|
|
||||||
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
|
|
||||||
s_ColorMatrixProgram.Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *pDepthMatrixProg =
|
const char *pDepthMatrixProg =
|
||||||
"#version 130\n"
|
"#version 130\n"
|
||||||
|
@ -538,11 +531,6 @@ TextureCache::TextureCache()
|
||||||
" ocol0 = R1 * colmat[4];\n"
|
" ocol0 = R1 * colmat[4];\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
if (!PixelShaderCache::CompilePixelShader(s_DepthMatrixProgram, pDepthMatrixProg))
|
|
||||||
{
|
|
||||||
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
|
|
||||||
s_DepthMatrixProgram.Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *VProgram =
|
const char *VProgram =
|
||||||
"#version 130\n"
|
"#version 130\n"
|
||||||
|
@ -554,13 +542,12 @@ TextureCache::TextureCache()
|
||||||
" uv0 = tex0;\n"
|
" uv0 = tex0;\n"
|
||||||
" gl_Position = vec4(rawpos,0,1);\n"
|
" gl_Position = vec4(rawpos,0,1);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
if (!VertexShaderCache::CompileVertexShader(s_vProgram, VProgram))
|
|
||||||
ERROR_LOG(VIDEO, "Failed to create texture converter vertex program.");
|
|
||||||
|
|
||||||
ProgramShaderCache::SetBothShaders(s_ColorMatrixProgram.glprogid, s_vProgram.glprogid);
|
ProgramShaderCache::CompileShader(s_ColorMatrixProgram, VProgram, pColorMatrixProg);
|
||||||
s_ColorMatrixUniform = glGetUniformLocation(ProgramShaderCache::GetCurrentProgram(), "colmat");
|
ProgramShaderCache::CompileShader(s_DepthMatrixProgram, VProgram, pDepthMatrixProg);
|
||||||
ProgramShaderCache::SetBothShaders(s_DepthMatrixProgram.glprogid, s_vProgram.glprogid);
|
|
||||||
s_DepthMatrixUniform = glGetUniformLocation(ProgramShaderCache::GetCurrentProgram(), "colmat");
|
s_ColorMatrixUniform = glGetUniformLocation(s_ColorMatrixProgram.glprogid, "colmat");
|
||||||
|
s_DepthMatrixUniform = glGetUniformLocation(s_DepthMatrixProgram.glprogid, "colmat");
|
||||||
s_ColorCbufid = -1;
|
s_ColorCbufid = -1;
|
||||||
s_DepthCbufid = -1;
|
s_DepthCbufid = -1;
|
||||||
|
|
||||||
|
@ -574,7 +561,6 @@ TextureCache::~TextureCache()
|
||||||
{
|
{
|
||||||
s_ColorMatrixProgram.Destroy();
|
s_ColorMatrixProgram.Destroy();
|
||||||
s_DepthMatrixProgram.Destroy();
|
s_DepthMatrixProgram.Destroy();
|
||||||
s_vProgram.Destroy();
|
|
||||||
|
|
||||||
for(std::map<u64, VBOCache>::iterator it = s_VBO.begin(); it != s_VBO.end(); it++) {
|
for(std::map<u64, VBOCache>::iterator it = s_VBO.begin(); it != s_VBO.end(); it++) {
|
||||||
glDeleteBuffers(1, &it->second.vbo);
|
glDeleteBuffers(1, &it->second.vbo);
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "TextureConverter.h"
|
#include "TextureConverter.h"
|
||||||
#include "TextureConversionShader.h"
|
#include "TextureConversionShader.h"
|
||||||
#include "TextureCache.h"
|
#include "TextureCache.h"
|
||||||
#include "PixelShaderCache.h"
|
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
#include "FramebufferManager.h"
|
#include "FramebufferManager.h"
|
||||||
|
@ -51,13 +50,12 @@ static GLuint s_dstRenderBuffer = 0; // for encoding to RAM
|
||||||
const int renderBufferWidth = 1024;
|
const int renderBufferWidth = 1024;
|
||||||
const int renderBufferHeight = 1024;
|
const int renderBufferHeight = 1024;
|
||||||
|
|
||||||
static FRAGMENTSHADER s_rgbToYuyvProgram;
|
static SHADER s_rgbToYuyvProgram;
|
||||||
static FRAGMENTSHADER s_yuyvToRgbProgram;
|
static SHADER s_yuyvToRgbProgram;
|
||||||
static VERTEXSHADER s_vProgram;
|
|
||||||
|
|
||||||
// Not all slots are taken - but who cares.
|
// Not all slots are taken - but who cares.
|
||||||
const u32 NUM_ENCODING_PROGRAMS = 64;
|
const u32 NUM_ENCODING_PROGRAMS = 64;
|
||||||
static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS];
|
static SHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS];
|
||||||
|
|
||||||
static GLuint s_encode_VBO = 0;
|
static GLuint s_encode_VBO = 0;
|
||||||
static GLuint s_encode_VAO = 0;
|
static GLuint s_encode_VAO = 0;
|
||||||
|
@ -67,6 +65,17 @@ static TargetRectangle s_cached_sourceRc;
|
||||||
static int s_cached_srcWidth = 0;
|
static int s_cached_srcWidth = 0;
|
||||||
static int s_cached_srcHeight = 0;
|
static int s_cached_srcHeight = 0;
|
||||||
|
|
||||||
|
static const char *VProgram =
|
||||||
|
"#version 130\n"
|
||||||
|
"in vec2 rawpos;\n"
|
||||||
|
"in vec2 tex0;\n"
|
||||||
|
"out vec2 uv0;\n"
|
||||||
|
"void main()\n"
|
||||||
|
"{\n"
|
||||||
|
" uv0 = tex0;\n"
|
||||||
|
" gl_Position = vec4(rawpos,0,1);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
void CreatePrograms()
|
void CreatePrograms()
|
||||||
{
|
{
|
||||||
// Output is BGRA because that is slightly faster than RGBA.
|
// Output is BGRA because that is slightly faster than RGBA.
|
||||||
|
@ -87,8 +96,6 @@ void CreatePrograms()
|
||||||
" vec4 const3 = vec4(0.0625,0.5,0.0625f,0.5);\n"
|
" vec4 const3 = vec4(0.0625,0.5,0.0625f,0.5);\n"
|
||||||
" ocol0 = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
|
" ocol0 = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgramRgbToYuyv))
|
|
||||||
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
|
|
||||||
|
|
||||||
const char *FProgramYuyvToRgb =
|
const char *FProgramYuyvToRgb =
|
||||||
"#version 130\n"
|
"#version 130\n"
|
||||||
|
@ -109,24 +116,12 @@ void CreatePrograms()
|
||||||
" yComp + (2.018f * uComp),\n"
|
" yComp + (2.018f * uComp),\n"
|
||||||
" 1.0f);\n"
|
" 1.0f);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgramYuyvToRgb))
|
|
||||||
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
|
|
||||||
|
|
||||||
const char *VProgram =
|
ProgramShaderCache::CompileShader(s_rgbToYuyvProgram, VProgram, FProgramRgbToYuyv);
|
||||||
"#version 130\n"
|
ProgramShaderCache::CompileShader(s_yuyvToRgbProgram, VProgram, FProgramYuyvToRgb);
|
||||||
"in vec2 rawpos;\n"
|
|
||||||
"in vec2 tex0;\n"
|
|
||||||
"out vec2 uv0;\n"
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
" uv0 = tex0;\n"
|
|
||||||
" gl_Position = vec4(rawpos,0,1);\n"
|
|
||||||
"}\n";
|
|
||||||
if (!VertexShaderCache::CompileVertexShader(s_vProgram, VProgram))
|
|
||||||
ERROR_LOG(VIDEO, "Failed to create texture converter vertex program.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FRAGMENTSHADER &GetOrCreateEncodingShader(u32 format)
|
SHADER &GetOrCreateEncodingShader(u32 format)
|
||||||
{
|
{
|
||||||
if (format > NUM_ENCODING_PROGRAMS)
|
if (format > NUM_ENCODING_PROGRAMS)
|
||||||
{
|
{
|
||||||
|
@ -149,9 +144,7 @@ FRAGMENTSHADER &GetOrCreateEncodingShader(u32 format)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!PixelShaderCache::CompilePixelShader(s_encodingPrograms[format], shader)) {
|
ProgramShaderCache::CompileShader(s_encodingPrograms[format], VProgram, shader);
|
||||||
ERROR_LOG(VIDEO, "Failed to create encoding fragment program");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return s_encodingPrograms[format];
|
return s_encodingPrograms[format];
|
||||||
}
|
}
|
||||||
|
@ -213,7 +206,6 @@ void Shutdown()
|
||||||
|
|
||||||
s_rgbToYuyvProgram.Destroy();
|
s_rgbToYuyvProgram.Destroy();
|
||||||
s_yuyvToRgbProgram.Destroy();
|
s_yuyvToRgbProgram.Destroy();
|
||||||
s_vProgram.Destroy();
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < NUM_ENCODING_PROGRAMS; i++)
|
for (unsigned int i = 0; i < NUM_ENCODING_PROGRAMS; i++)
|
||||||
s_encodingPrograms[i].Destroy();
|
s_encodingPrograms[i].Destroy();
|
||||||
|
@ -325,9 +317,7 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer,
|
||||||
if (copyfmt > GX_TF_RGBA8 || (copyfmt < GX_TF_RGB565 && !bIsIntensityFmt))
|
if (copyfmt > GX_TF_RGBA8 || (copyfmt < GX_TF_RGB565 && !bIsIntensityFmt))
|
||||||
format |= _GX_TF_CTF;
|
format |= _GX_TF_CTF;
|
||||||
|
|
||||||
FRAGMENTSHADER& texconv_shader = GetOrCreateEncodingShader(format);
|
SHADER& texconv_shader = GetOrCreateEncodingShader(format);
|
||||||
if (texconv_shader.glprogid == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
u8 *dest_ptr = Memory::GetPointer(address);
|
u8 *dest_ptr = Memory::GetPointer(address);
|
||||||
|
|
||||||
|
@ -345,8 +335,6 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer,
|
||||||
s32 expandedWidth = (width + blkW) & (~blkW);
|
s32 expandedWidth = (width + blkW) & (~blkW);
|
||||||
s32 expandedHeight = (height + blkH) & (~blkH);
|
s32 expandedHeight = (height + blkH) & (~blkH);
|
||||||
|
|
||||||
ProgramShaderCache::SetBothShaders(texconv_shader.glprogid, s_vProgram.glprogid);
|
|
||||||
|
|
||||||
float sampleStride = bScaleByHalf ? 2.f : 1.f;
|
float sampleStride = bScaleByHalf ? 2.f : 1.f;
|
||||||
|
|
||||||
float params[] = {
|
float params[] = {
|
||||||
|
@ -355,7 +343,9 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer,
|
||||||
(float)expandedWidth, (float)Renderer::EFBToScaledY(expandedHeight)-1,
|
(float)expandedWidth, (float)Renderer::EFBToScaledY(expandedHeight)-1,
|
||||||
(float)Renderer::EFBToScaledX(source.left), (float)Renderer::EFBToScaledY(EFB_HEIGHT - source.top - expandedHeight)
|
(float)Renderer::EFBToScaledX(source.left), (float)Renderer::EFBToScaledY(EFB_HEIGHT - source.top - expandedHeight)
|
||||||
};
|
};
|
||||||
glUniform4fv(ProgramShaderCache::GetShaderProgram().UniformLocations[C_COLORS], 2, params);
|
|
||||||
|
texconv_shader.Bind();
|
||||||
|
glUniform4fv(texconv_shader.UniformLocations[C_COLORS], 2, params);
|
||||||
|
|
||||||
TargetRectangle scaledSource;
|
TargetRectangle scaledSource;
|
||||||
scaledSource.top = 0;
|
scaledSource.top = 0;
|
||||||
|
@ -379,7 +369,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des
|
||||||
{
|
{
|
||||||
g_renderer->ResetAPIState();
|
g_renderer->ResetAPIState();
|
||||||
|
|
||||||
ProgramShaderCache::SetBothShaders(s_rgbToYuyvProgram.glprogid, s_vProgram.glprogid);
|
s_rgbToYuyvProgram.Bind();
|
||||||
|
|
||||||
EncodeToRamUsingShader(srcTexture, sourceRc, destAddr, dstWidth / 2, dstHeight, 0, false, false);
|
EncodeToRamUsingShader(srcTexture, sourceRc, destAddr, dstWidth / 2, dstHeight, 0, false, false);
|
||||||
FramebufferManager::SetFramebuffer(0);
|
FramebufferManager::SetFramebuffer(0);
|
||||||
|
@ -431,7 +421,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRender
|
||||||
}
|
}
|
||||||
|
|
||||||
glViewport(0, 0, srcWidth, srcHeight);
|
glViewport(0, 0, srcWidth, srcHeight);
|
||||||
ProgramShaderCache::SetBothShaders(s_yuyvToRgbProgram.glprogid, s_vProgram.glprogid);
|
s_yuyvToRgbProgram.Bind();
|
||||||
|
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,7 @@
|
||||||
#include "ImageWrite.h"
|
#include "ImageWrite.h"
|
||||||
#include "BPMemory.h"
|
#include "BPMemory.h"
|
||||||
#include "TextureCache.h"
|
#include "TextureCache.h"
|
||||||
#include "PixelShaderCache.h"
|
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "VertexShaderCache.h"
|
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
|
@ -246,28 +244,23 @@ void VertexManager::vFlush()
|
||||||
bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend;
|
bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend;
|
||||||
|
|
||||||
// finally bind
|
// finally bind
|
||||||
FRAGMENTSHADER* ps;
|
|
||||||
if (dualSourcePossible)
|
if (dualSourcePossible)
|
||||||
{
|
{
|
||||||
if (useDstAlpha)
|
if (useDstAlpha)
|
||||||
{
|
{
|
||||||
// If host supports GL_ARB_blend_func_extended, we can do dst alpha in
|
// If host supports GL_ARB_blend_func_extended, we can do dst alpha in
|
||||||
// the same pass as regular rendering.
|
// the same pass as regular rendering.
|
||||||
ps = PixelShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, g_nativeVertexFmt->m_components);
|
ProgramShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, g_nativeVertexFmt->m_components);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ps = PixelShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components);
|
ProgramShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ps = PixelShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components);
|
ProgramShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components);
|
||||||
}
|
}
|
||||||
VERTEXSHADER* vs = VertexShaderCache::SetShader(g_nativeVertexFmt->m_components);
|
|
||||||
|
|
||||||
if(ps && vs)
|
|
||||||
ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid);
|
|
||||||
|
|
||||||
// set global constants
|
// set global constants
|
||||||
VertexShaderManager::SetConstants();
|
VertexShaderManager::SetConstants();
|
||||||
|
@ -284,9 +277,7 @@ void VertexManager::vFlush()
|
||||||
// run through vertex groups again to set alpha
|
// run through vertex groups again to set alpha
|
||||||
if (useDstAlpha && !dualSourcePossible)
|
if (useDstAlpha && !dualSourcePossible)
|
||||||
{
|
{
|
||||||
ps = PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components);
|
ProgramShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components);
|
||||||
if(ps && vs)
|
|
||||||
ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid);
|
|
||||||
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
{
|
{
|
||||||
// Need to set these again, if we don't support UBO
|
// Need to set these again, if we don't support UBO
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
#include "VertexShaderCache.h"
|
|
||||||
#include "VertexManager.h"
|
#include "VertexManager.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
#include "XFMemory.h"
|
#include "XFMemory.h"
|
||||||
|
@ -38,122 +37,6 @@
|
||||||
namespace OGL
|
namespace OGL
|
||||||
{
|
{
|
||||||
|
|
||||||
VertexShaderCache::VSCache VertexShaderCache::vshaders;
|
|
||||||
GLuint VertexShaderCache::CurrentShader;
|
|
||||||
bool VertexShaderCache::ShaderEnabled;
|
|
||||||
|
|
||||||
VertexShaderCache::VSCacheEntry* VertexShaderCache::last_entry = NULL;
|
|
||||||
VERTEXSHADERUID VertexShaderCache::last_uid;
|
|
||||||
|
|
||||||
void VertexShaderCache::Init()
|
|
||||||
{
|
|
||||||
ShaderEnabled = true;
|
|
||||||
CurrentShader = 0;
|
|
||||||
last_entry = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VertexShaderCache::Shutdown()
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
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;
|
|
||||||
const char *code = GenerateVertexShaderCode(components, 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++);
|
|
||||||
|
|
||||||
SaveData(szTemp, code);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
|
||||||
{
|
|
||||||
GLuint result = glCreateShader(GL_VERTEX_SHADER);
|
|
||||||
|
|
||||||
glShaderSource(result, 1, &pstrprogram, NULL);
|
|
||||||
glCompileShader(result);
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
|
||||||
GLsizei length = 0;
|
|
||||||
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length);
|
|
||||||
if (length > 1)
|
|
||||||
{
|
|
||||||
GLsizei charsWritten;
|
|
||||||
GLchar* infoLog = new GLchar[length];
|
|
||||||
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
|
|
||||||
ERROR_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(infoLog, strlen(infoLog), 1, fp);
|
|
||||||
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
|
|
||||||
fclose(fp);
|
|
||||||
delete[] infoLog;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLint compileStatus;
|
|
||||||
glGetShaderiv(result, GL_COMPILE_STATUS, &compileStatus);
|
|
||||||
if (compileStatus != GL_TRUE)
|
|
||||||
{
|
|
||||||
// Compile failed
|
|
||||||
ERROR_LOG(VIDEO, "Shader compilation failed; see info log");
|
|
||||||
|
|
||||||
// Don't try to use this shader
|
|
||||||
glDeleteShader(result);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
(void)GL_REPORT_ERROR();
|
|
||||||
vs.glprogid = result;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetVSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
void SetVSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
||||||
{
|
{
|
||||||
ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram();
|
ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
|
@ -161,11 +44,11 @@ void SetVSConstant4fvByName(const char * name, unsigned int offset, const float
|
||||||
{
|
{
|
||||||
if (!strcmp(name, UniformNames[a]))
|
if (!strcmp(name, UniformNames[a]))
|
||||||
{
|
{
|
||||||
if (tmp.UniformLocations[a] == -1)
|
if (tmp.shader.UniformLocations[a] == -1)
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
|
glUniform4fv(tmp.shader.UniformLocations[a] + offset, count, f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
// 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 _VERTEXSHADERCACHE_H_
|
|
||||||
#define _VERTEXSHADERCACHE_H_
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "BPMemory.h"
|
|
||||||
#include "VertexShaderGen.h"
|
|
||||||
|
|
||||||
namespace OGL
|
|
||||||
{
|
|
||||||
|
|
||||||
struct VERTEXSHADER
|
|
||||||
{
|
|
||||||
VERTEXSHADER() : glprogid(0) {}
|
|
||||||
void Destroy()
|
|
||||||
{
|
|
||||||
glDeleteShader(glprogid);
|
|
||||||
glprogid = 0;
|
|
||||||
}
|
|
||||||
GLuint glprogid; // opengl program id
|
|
||||||
|
|
||||||
std::string strprog;
|
|
||||||
};
|
|
||||||
|
|
||||||
class VertexShaderCache
|
|
||||||
{
|
|
||||||
struct VSCacheEntry
|
|
||||||
{
|
|
||||||
VERTEXSHADER shader;
|
|
||||||
VERTEXSHADERUIDSAFE safe_uid;
|
|
||||||
VSCacheEntry() {}
|
|
||||||
void Destroy() {
|
|
||||||
shader.Destroy();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::map<VERTEXSHADERUID, VSCacheEntry> VSCache;
|
|
||||||
|
|
||||||
static VSCache vshaders;
|
|
||||||
|
|
||||||
static VSCacheEntry* last_entry;
|
|
||||||
static VERTEXSHADERUID last_uid;
|
|
||||||
|
|
||||||
static GLuint CurrentShader;
|
|
||||||
static bool ShaderEnabled;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void Init();
|
|
||||||
static void Shutdown();
|
|
||||||
|
|
||||||
static VERTEXSHADER* SetShader(u32 components);
|
|
||||||
static bool CompileVertexShader(VERTEXSHADER& ps, const char* pstrprogram);
|
|
||||||
|
|
||||||
};
|
|
||||||
} // namespace OGL
|
|
||||||
|
|
||||||
#endif // _VERTEXSHADERCACHE_H_
|
|
|
@ -79,9 +79,7 @@ Make AA apply instantly during gameplay if possible
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
#include "VertexLoaderManager.h"
|
#include "VertexLoaderManager.h"
|
||||||
#include "VertexManager.h"
|
#include "VertexManager.h"
|
||||||
#include "PixelShaderCache.h"
|
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "VertexShaderCache.h"
|
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
#include "CommandProcessor.h"
|
#include "CommandProcessor.h"
|
||||||
|
@ -194,9 +192,7 @@ void VideoBackend::Video_Prepare()
|
||||||
g_vertex_manager = new VertexManager;
|
g_vertex_manager = new VertexManager;
|
||||||
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
||||||
OpcodeDecoder_Init();
|
OpcodeDecoder_Init();
|
||||||
VertexShaderCache::Init();
|
|
||||||
VertexShaderManager::Init();
|
VertexShaderManager::Init();
|
||||||
PixelShaderCache::Init();
|
|
||||||
PixelShaderManager::Init();
|
PixelShaderManager::Init();
|
||||||
ProgramShaderCache::Init();
|
ProgramShaderCache::Init();
|
||||||
g_texture_cache = new TextureCache;
|
g_texture_cache = new TextureCache;
|
||||||
|
@ -232,10 +228,8 @@ void VideoBackend::Shutdown()
|
||||||
delete g_texture_cache;
|
delete g_texture_cache;
|
||||||
g_texture_cache = NULL;
|
g_texture_cache = NULL;
|
||||||
ProgramShaderCache::Shutdown();
|
ProgramShaderCache::Shutdown();
|
||||||
VertexShaderCache::Shutdown();
|
|
||||||
VertexShaderManager::Shutdown();
|
VertexShaderManager::Shutdown();
|
||||||
PixelShaderManager::Shutdown();
|
PixelShaderManager::Shutdown();
|
||||||
PixelShaderCache::Shutdown();
|
|
||||||
delete g_vertex_manager;
|
delete g_vertex_manager;
|
||||||
g_vertex_manager = NULL;
|
g_vertex_manager = NULL;
|
||||||
OpcodeDecoder_Shutdown();
|
OpcodeDecoder_Shutdown();
|
||||||
|
|
Loading…
Reference in New Issue