merge glsl headers into one place

This commit is contained in:
degasus 2013-02-13 21:34:48 +01:00
parent 3392562501
commit 0325e37bfb
9 changed files with 43 additions and 82 deletions

View File

@ -528,24 +528,6 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
if (ApiType == API_OPENGL) if (ApiType == API_OPENGL)
{ {
// A few required defines and ones that will make our lives a lot easier
WRITE(p, "#version 130\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
WRITE(p, "#define VARYIN in\n");
WRITE(p, "#define VARYOUT out\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
WRITE(p, "#define float4 vec4\n");
// cg to glsl function translation
WRITE(p, "#define frac(x) fract(x)\n");
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
// A function here // A function here
// Fmod implementation gleaned from Nvidia // Fmod implementation gleaned from Nvidia

View File

@ -822,27 +822,6 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
char *p = text; char *p = text;
if (ApiType == API_OPENGL)
{
// A few required defines and ones that will make our lives a lot easier
WRITE(p, "#version 130\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
WRITE(p, "#define float4 vec4\n");
// cg to glsl function translation
WRITE(p, "#define frac(x) fract(x)\n");
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
// We require this here
WRITE(p, "#ifdef GL_ARB_texture_rectangle\n #extension GL_ARB_texture_rectangle : require\n#endif\n");
}
switch (format) switch (format)
{ {
case GX_TF_I4: case GX_TF_I4:

View File

@ -184,29 +184,6 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
char *p = text; char *p = text;
WRITE(p, "//Vertex Shader: comp:%x, \n", components); WRITE(p, "//Vertex Shader: comp:%x, \n", components);
if (ApiType == API_OPENGL)
{
// A few required defines and ones that will make our lives a lot easier
WRITE(p, "#version 130\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
WRITE(p, "#define VARYIN in\n");
WRITE(p, "#define VARYOUT out\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
WRITE(p, "#define float4 vec4\n");
// cg to glsl function translation
WRITE(p, "#define frac(x) fract(x)\n");
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
}
// uniforms // uniforms
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140) uniform VSBlock {\n"); WRITE(p, "layout(std140) uniform VSBlock {\n");

View File

@ -26,20 +26,21 @@ namespace OGL
static const u32 UBO_LENGTH = 4*1024*1024; static const u32 UBO_LENGTH = 4*1024*1024;
static GLuint CurrentProgram = 0;
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<SHADERUID, u8> g_program_disk_cache;
static StreamBuffer *s_buffer; static StreamBuffer *s_buffer;
LinearDiskCache<SHADERUID, u8> g_program_disk_cache;
static GLuint CurrentProgram = 0;
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
ProgramShaderCache::PCacheEntry* ProgramShaderCache::last_entry; ProgramShaderCache::PCacheEntry* ProgramShaderCache::last_entry;
SHADERUID ProgramShaderCache::last_uid; SHADERUID ProgramShaderCache::last_uid;
static char s_glsl_header[1024] = "";
const char *UniformNames[NUM_UNIFORMS] = const char *UniformNames[NUM_UNIFORMS] =
{ {
// PIXEL SHADER UNIFORMS // PIXEL SHADER UNIFORMS
@ -291,7 +292,9 @@ bool ProgramShaderCache::CompileShader ( SHADER& shader, const char* vcode, cons
FILE *fp = fopen(szTemp, "wb"); FILE *fp = fopen(szTemp, "wb");
fwrite(infoLog, length, 1, fp); fwrite(infoLog, length, 1, fp);
delete[] infoLog; delete[] infoLog;
fwrite(s_glsl_header, strlen(s_glsl_header), 1, fp);
fwrite(vcode, strlen(vcode), 1, fp); fwrite(vcode, strlen(vcode), 1, fp);
fwrite(s_glsl_header, strlen(s_glsl_header), 1, fp);
fwrite(pcode, strlen(pcode), 1, fp); fwrite(pcode, strlen(pcode), 1, fp);
fclose(fp); fclose(fp);
} }
@ -318,9 +321,9 @@ GLuint ProgramShaderCache::CompileSingleShader (GLuint type, const char* code )
{ {
GLuint result = glCreateShader(type); GLuint result = glCreateShader(type);
const char *src[] = {code}; const char *src[] = {s_glsl_header, code};
glShaderSource(result, 1, src, NULL); glShaderSource(result, 2, src, NULL);
glCompileShader(result); glCompileShader(result);
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL) #if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
GLsizei length = 0; GLsizei length = 0;
@ -335,6 +338,7 @@ GLuint ProgramShaderCache::CompileSingleShader (GLuint type, const char* code )
sprintf(szTemp, "ps_%d.txt", result); sprintf(szTemp, "ps_%d.txt", result);
FILE *fp = fopen(szTemp, "wb"); FILE *fp = fopen(szTemp, "wb");
fwrite(infoLog, strlen(infoLog), 1, fp); fwrite(infoLog, strlen(infoLog), 1, fp);
fwrite(s_glsl_header, strlen(s_glsl_header), 1, fp);
fwrite(code, strlen(code), 1, fp); fwrite(code, strlen(code), 1, fp);
fclose(fp); fclose(fp);
delete[] infoLog; delete[] infoLog;
@ -433,6 +437,8 @@ void ProgramShaderCache::Init(void)
SETSTAT(stats.numPixelShadersAlive, pshaders.size()); SETSTAT(stats.numPixelShadersAlive, pshaders.size());
} }
CreateHeader();
CurrentProgram = 0; CurrentProgram = 0;
last_entry = NULL; last_entry = NULL;
} }
@ -480,6 +486,36 @@ void ProgramShaderCache::Shutdown(void)
} }
} }
void ProgramShaderCache::CreateHeader ( void )
{
snprintf(s_glsl_header, sizeof(s_glsl_header),
"#version %s\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"%s\n" // ubo
"\n"// A few required defines and ones that will make our lives a lot easier
"#define ATTRIN in\n"
"#define ATTROUT out\n"
"#define VARYIN in\n"
"#define VARYOUT out\n"
// Silly differences
"#define float2 vec2\n"
"#define float3 vec3\n"
"#define float4 vec4\n"
// hlsl to glsl function translation
"#define frac(x) fract(x)\n"
"#define saturate(x) clamp(x, 0.0f, 1.0f)\n"
"#define lerp(x, y, z) mix(x, y, z)\n"
, "130"
, g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "#extension GL_ARB_uniform_buffer_object : enable" : "// ubo disabled"
);
}
void ProgramShaderCache::ProgramShaderCacheInserter::Read ( const SHADERUID& key, const u8* value, u32 value_size ) void ProgramShaderCache::ProgramShaderCacheInserter::Read ( const SHADERUID& key, const u8* value, u32 value_size )
{ {
const u8 *binary = value+sizeof(GLenum); const u8 *binary = value+sizeof(GLenum);

View File

@ -110,6 +110,7 @@ public:
static void Init(void); static void Init(void);
static void Shutdown(void); static void Shutdown(void);
static void CreateHeader(void);
private: private:
class ProgramShaderCacheInserter : public LinearDiskCacheReader<SHADERUID, u8> class ProgramShaderCacheInserter : public LinearDiskCacheReader<SHADERUID, u8>

View File

@ -127,7 +127,6 @@ const u8 rasters[char_count][char_height] = {
}; };
static const char *s_vertexShaderSrc = static const char *s_vertexShaderSrc =
"#version 130\n"
"uniform vec2 charSize;\n" "uniform vec2 charSize;\n"
"in vec2 rawpos;\n" "in vec2 rawpos;\n"
"in vec2 tex0;\n" "in vec2 tex0;\n"
@ -138,7 +137,6 @@ static const char *s_vertexShaderSrc =
"}\n"; "}\n";
static const char *s_fragmentShaderSrc = static const char *s_fragmentShaderSrc =
"#version 130\n"
"uniform sampler2D samp8;\n" "uniform sampler2D samp8;\n"
"uniform vec4 color;\n" "uniform vec4 color;\n"
"in vec2 uv0;\n" "in vec2 uv0;\n"

View File

@ -438,7 +438,6 @@ void Renderer::Init()
s_pfont = new RasterFont(); s_pfont = new RasterFont();
ProgramShaderCache::CompileShader(s_ShowEFBCopyRegions, ProgramShaderCache::CompileShader(s_ShowEFBCopyRegions,
"#version 130\n"
"in vec2 rawpos;\n" "in vec2 rawpos;\n"
"in vec3 color0;\n" "in vec3 color0;\n"
"out vec4 c;\n" "out vec4 c;\n"
@ -446,7 +445,6 @@ void Renderer::Init()
" 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" "in vec4 c;\n"
"out vec4 ocol0;\n" "out vec4 ocol0;\n"
"void main(void) {\n" "void main(void) {\n"

View File

@ -476,8 +476,6 @@ void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, co
TextureCache::TextureCache() TextureCache::TextureCache()
{ {
const char *pColorMatrixProg = const char *pColorMatrixProg =
"#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp9;\n" "uniform sampler2DRect samp9;\n"
"uniform vec4 colmat[7];\n" "uniform vec4 colmat[7];\n"
"in vec2 uv0;\n" "in vec2 uv0;\n"
@ -490,8 +488,6 @@ TextureCache::TextureCache()
"}\n"; "}\n";
const char *pDepthMatrixProg = const char *pDepthMatrixProg =
"#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp9;\n" "uniform sampler2DRect samp9;\n"
"uniform vec4 colmat[5];\n" "uniform vec4 colmat[5];\n"
"in vec2 uv0;\n" "in vec2 uv0;\n"
@ -506,7 +502,6 @@ TextureCache::TextureCache()
const char *VProgram = const char *VProgram =
"#version 130\n"
"in vec2 rawpos;\n" "in vec2 rawpos;\n"
"in vec2 tex0;\n" "in vec2 tex0;\n"
"out vec2 uv0;\n" "out vec2 uv0;\n"

View File

@ -66,7 +66,6 @@ static int s_cached_srcWidth = 0;
static int s_cached_srcHeight = 0; static int s_cached_srcHeight = 0;
static const char *VProgram = static const char *VProgram =
"#version 130\n"
"in vec2 rawpos;\n" "in vec2 rawpos;\n"
"in vec2 tex0;\n" "in vec2 tex0;\n"
"out vec2 uv0;\n" "out vec2 uv0;\n"
@ -80,8 +79,6 @@ void CreatePrograms()
{ {
// Output is BGRA because that is slightly faster than RGBA. // Output is BGRA because that is slightly faster than RGBA.
const char *FProgramRgbToYuyv = const char *FProgramRgbToYuyv =
"#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp9;\n" "uniform sampler2DRect samp9;\n"
"in vec2 uv0;\n" "in vec2 uv0;\n"
"out vec4 ocol0;\n" "out vec4 ocol0;\n"
@ -98,8 +95,6 @@ void CreatePrograms()
"}\n"; "}\n";
const char *FProgramYuyvToRgb = const char *FProgramYuyvToRgb =
"#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp9;\n" "uniform sampler2DRect samp9;\n"
"in vec2 uv0;\n" "in vec2 uv0;\n"
"out vec4 ocol0;\n" "out vec4 ocol0;\n"