UBO works for Pixel Shaders if Binding for UBO is zero, otherwise fails. Probably why Vertex shader UBO is failing. Too tired to investigate right now.
This commit is contained in:
parent
904adb9e3d
commit
1f75ee49bf
|
@ -527,9 +527,9 @@ const char* WriteBinding(API_TYPE ApiType, const u32 num)
|
|||
}
|
||||
const char *WriteLocation(API_TYPE ApiType)
|
||||
{
|
||||
static char result[64];
|
||||
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
return "";
|
||||
static char result[64];
|
||||
sprintf(result, "uniform ");
|
||||
return result;
|
||||
}
|
||||
|
@ -620,7 +620,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
|||
|
||||
WRITE(p, "\n");
|
||||
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
WRITE(p, "layout(std140, binding = 4) uniform PSBlock {\n");
|
||||
WRITE(p, "layout(std140, binding = 0) uniform PSBlock {\n");
|
||||
|
||||
WRITE(p, "%sfloat4 "I_COLORS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
|
||||
WRITE(p, "%sfloat4 "I_KCOLORS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_KCOLORS));
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
#define I_INDTEXSCALE "cindscale"
|
||||
#define I_INDTEXMTX "cindmtx"
|
||||
#define I_FOG "cfog"
|
||||
#define I_PLIGHTS "cLights"
|
||||
#define I_PMATERIALS "cmtrl"
|
||||
#define I_PLIGHTS "cPLights"
|
||||
#define I_PMATERIALS "cPmtrl"
|
||||
|
||||
#define C_COLORMATRIX 0 // 0
|
||||
#define C_COLORS 0 // 0
|
||||
|
|
|
@ -166,6 +166,12 @@ char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE ApiType)
|
|||
extern const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num);
|
||||
extern const char* WriteBinding(API_TYPE ApiType, const u32 num);
|
||||
const char *WriteLocation(API_TYPE ApiType);
|
||||
const char *WriteLocation2(API_TYPE ApiType)
|
||||
{
|
||||
static char result[64];
|
||||
sprintf(result, "uniform ");
|
||||
return result;
|
||||
}
|
||||
|
||||
const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
|
||||
{
|
||||
|
@ -216,21 +222,22 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
|
|||
}
|
||||
|
||||
// uniforms
|
||||
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
WRITE(p, "layout(std140, binding = 5) uniform VSBlock {\n");
|
||||
//if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
//WRITE(p, "layout(std140, binding = 2) uniform VSBlock {\n");
|
||||
|
||||
WRITE(p, "%sfloat4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
|
||||
//if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
//WRITE(p, "};\n");
|
||||
WRITE(p, "%sfloat4 "I_PROJECTION"[4] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_PROJECTION));
|
||||
WRITE(p, "%sfloat4 "I_MATERIALS"[4] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_MATERIALS));
|
||||
WRITE(p, "%sfloat4 "I_LIGHTS"[40] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_LIGHTS));
|
||||
WRITE(p, "%sfloat4 "I_TEXMATRICES"[24] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices
|
||||
WRITE(p, "%sfloat4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_TRANSFORMMATRICES));
|
||||
WRITE(p, "%sfloat4 "I_NORMALMATRICES"[32] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_NORMALMATRICES));
|
||||
WRITE(p, "%sfloat4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
|
||||
WRITE(p, "%sfloat4 "I_DEPTHPARAMS" %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS));
|
||||
|
||||
WRITE(p, "%sfloat4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
|
||||
WRITE(p, "%sfloat4 "I_PROJECTION"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PROJECTION));
|
||||
WRITE(p, "%sfloat4 "I_MATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_MATERIALS));
|
||||
WRITE(p, "%sfloat4 "I_LIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_LIGHTS));
|
||||
WRITE(p, "%sfloat4 "I_TEXMATRICES"[24] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices
|
||||
WRITE(p, "%sfloat4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_TRANSFORMMATRICES));
|
||||
WRITE(p, "%sfloat4 "I_NORMALMATRICES"[32] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_NORMALMATRICES));
|
||||
WRITE(p, "%sfloat4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
|
||||
WRITE(p, "%sfloat4 "I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS));
|
||||
|
||||
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
WRITE(p, "};\n");
|
||||
|
||||
p = GenerateVSOutputStruct(p, components, ApiType);
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
|
|||
{I_TRANSFORMMATRICES , C_TRANSFORMMATRICES, 64 },
|
||||
{I_NORMALMATRICES , C_NORMALMATRICES, 32 },
|
||||
{I_POSTTRANSFORMMATRICES, C_POSTTRANSFORMMATRICES, 64 },
|
||||
{I_DEPTHPARAMS, C_DEPTHPARAMS, 4 },
|
||||
{I_DEPTHPARAMS, C_DEPTHPARAMS, 1 },
|
||||
};
|
||||
template<bool safe>
|
||||
class _VERTEXSHADERUID
|
||||
|
|
|
@ -184,7 +184,7 @@ void VertexShaderManager::Dirty()
|
|||
// TODO: A cleaner way to control the matricies without making a mess in the parameters field
|
||||
void VertexShaderManager::SetConstants()
|
||||
{
|
||||
if (g_ActiveConfig.bUseGLSL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
//if (g_ActiveConfig.bUseGLSL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
Dirty();
|
||||
if (nTransformMatricesChanged[0] >= 0)
|
||||
{
|
||||
|
|
|
@ -496,6 +496,7 @@ void SetPSConstant4fvByName(const char * name, unsigned int offset, const float
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||
{
|
||||
float f[4] = { f1, f2, f3, f4 };
|
||||
|
|
|
@ -17,12 +17,15 @@
|
|||
|
||||
#include "ProgramShaderCache.h"
|
||||
#include <assert.h>
|
||||
static GLenum checkForGLError(const char * situation)
|
||||
GLuint GLERR(const char *function)
|
||||
{
|
||||
GLenum error = glGetError();
|
||||
if (error != GL_NO_ERROR)
|
||||
printf("Error: %d -- %s\n", error, situation);
|
||||
return error;
|
||||
GLint err = glGetError();
|
||||
if (err != GL_NO_ERROR)
|
||||
{
|
||||
printf( "(%s) OpenGL error 0x%x - %s\n",
|
||||
function, err, gluErrorString(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
namespace OGL
|
||||
{
|
||||
|
@ -98,10 +101,19 @@ namespace OGL
|
|||
glAttachShader(entry.program.glprogid, entry.program.psid);
|
||||
|
||||
glLinkProgram(entry.program.glprogid);
|
||||
GLsizei length = 0;
|
||||
|
||||
glGetProgramiv(entry.program.glprogid, GL_INFO_LOG_LENGTH, &length);
|
||||
if (length > 0)
|
||||
{
|
||||
GLsizei charsWritten;
|
||||
GLchar* infoLog = new GLchar[length];
|
||||
glGetProgramInfoLog(entry.program.glprogid, length, &charsWritten, infoLog);
|
||||
printf("Program info log:\n%s", infoLog);
|
||||
delete[] infoLog;
|
||||
}
|
||||
|
||||
glUseProgram(entry.program.glprogid);
|
||||
checkForGLError("User");
|
||||
|
||||
|
||||
// We cache our uniform locations for now
|
||||
// Once we move up to a newer version of GLSL, ~1.30
|
||||
|
@ -136,12 +148,22 @@ namespace OGL
|
|||
}
|
||||
void ProgramShaderCache::SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count)
|
||||
{
|
||||
GLERR("");
|
||||
assert(Buffer > 1);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[Buffer]);
|
||||
static int _Buffer = -1;
|
||||
if(_Buffer != Buffer)
|
||||
{
|
||||
_Buffer = Buffer;
|
||||
GLERR("bind");
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[_Buffer]);
|
||||
}
|
||||
// Query for the offsets of each block variable
|
||||
|
||||
// glBufferSubData expects data in bytes, so multiply count by four
|
||||
// Expects the offset in bytes as well, so multiply by *4 *4 since we are passing in a vec4 location
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, offset * 4 * 4, count * 4 * 4, f);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
GLERR("sub");
|
||||
|
||||
}
|
||||
GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; }
|
||||
|
||||
|
@ -156,20 +178,22 @@ namespace OGL
|
|||
void ProgramShaderCache::Init(void)
|
||||
{
|
||||
glGenBuffers(2, UBOBuffers);
|
||||
|
||||
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[0]);
|
||||
// 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
|
||||
glBufferData(GL_UNIFORM_BUFFER, 1024 *1024, NULL, GL_DYNAMIC_DRAW);
|
||||
glBufferData(GL_UNIFORM_BUFFER, C_PENVCONST_END * 4 * 4, 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
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 4, UBOBuffers[0]);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, UBOBuffers[0]);
|
||||
|
||||
// Repeat for VS shader
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[1]);
|
||||
glBufferData(GL_UNIFORM_BUFFER, 1024*1024, NULL, GL_DYNAMIC_DRAW);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 5, UBOBuffers[1]);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
checkForGLError("Init");
|
||||
//glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[1]);
|
||||
//glBufferData(GL_UNIFORM_BUFFER, C_PENVCONST_END * 4 * 4, NULL, GL_DYNAMIC_DRAW);
|
||||
//glBindBufferBase(GL_UNIFORM_BUFFER, 2, UBOBuffers[1]);
|
||||
GLERR("init");
|
||||
}
|
||||
void ProgramShaderCache::Shutdown(void)
|
||||
{
|
||||
|
|
|
@ -62,12 +62,34 @@ void CreateRgbToYuyvProgram()
|
|||
{
|
||||
// Output is BGRA because that is slightly faster than RGBA.
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
if(g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||
{
|
||||
const char *FProgram =
|
||||
"#version 330 compatibility\n"
|
||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
||||
"layout(binding = 0) uniform sampler2DRect samp0;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec2 uv1 = vec2(gl_TexCoord[0].x + 1.0f, gl_TexCoord[0].y);\n"
|
||||
" vec3 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgb;\n"
|
||||
" vec3 c1 = texture2DRect(samp0, uv1).rgb;\n"
|
||||
" vec3 y_const = vec3(0.257f,0.504f,0.098f);\n"
|
||||
" vec3 u_const = vec3(-0.148f,-0.291f,0.439f);\n"
|
||||
" vec3 v_const = vec3(0.439f,-0.368f,-0.071f);\n"
|
||||
" vec4 const3 = vec4(0.0625f,0.5f,0.0625f,0.5f);\n"
|
||||
" vec3 c01 = (c0 + c1) * 0.5f;\n"
|
||||
" gl_FragData[0] = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
|
||||
"}\n";
|
||||
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram))
|
||||
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *FProgram =
|
||||
"#version 120\n"
|
||||
"#ifdef GL_ARB_texture_rectangle\n"
|
||||
"#extension GL_ARB_texture_rectangle : require\n"
|
||||
"#endif\n"
|
||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||
"uniform sampler2DRect samp0;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
|
@ -84,6 +106,7 @@ void CreateRgbToYuyvProgram()
|
|||
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram))
|
||||
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *FProgram =
|
||||
|
@ -110,6 +133,33 @@ void CreateRgbToYuyvProgram()
|
|||
void CreateYuyvToRgbProgram()
|
||||
{
|
||||
if(g_ActiveConfig.bUseGLSL)
|
||||
{
|
||||
if(g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||
{
|
||||
const char *FProgram =
|
||||
"#version 330 compatibility\n"
|
||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
||||
"layout(binding = 0) uniform sampler2DRect samp0;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgba;\n"
|
||||
|
||||
" float f = step(0.5, fract(gl_TexCoord[0].x));\n"
|
||||
" float y = mix(c0.b, c0.r, f);\n"
|
||||
" float yComp = 1.164f * (y - 0.0625f);\n"
|
||||
" float uComp = c0.g - 0.5f;\n"
|
||||
" float vComp = c0.a - 0.5f;\n"
|
||||
|
||||
" gl_FragData[0] = vec4(yComp + (1.596f * vComp),\n"
|
||||
" yComp - (0.813f * vComp) - (0.391f * uComp),\n"
|
||||
" yComp + (2.018f * uComp),\n"
|
||||
" 1.0f);\n"
|
||||
"}\n";
|
||||
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram))
|
||||
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *FProgram =
|
||||
"#version 120\n"
|
||||
|
@ -135,6 +185,7 @@ void CreateYuyvToRgbProgram()
|
|||
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram))
|
||||
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *FProgram =
|
||||
|
|
|
@ -240,6 +240,7 @@ void SetVSConstant4fvByName(const char * name, unsigned int offset, const float
|
|||
}
|
||||
}
|
||||
}
|
||||
#define MAX_UNIFORM 0
|
||||
void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||
{
|
||||
float buf[4];
|
||||
|
@ -249,6 +250,7 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3
|
|||
buf[3] = f4;
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
if(const_number < MAX_UNIFORM)
|
||||
ProgramShaderCache::SetUniformObjects(1, const_number, buf);
|
||||
//return;
|
||||
}
|
||||
|
@ -267,6 +269,7 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
|
|||
{
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
if(const_number < MAX_UNIFORM)
|
||||
ProgramShaderCache::SetUniformObjects(1, const_number, f);
|
||||
//return;
|
||||
}
|
||||
|
@ -285,6 +288,7 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co
|
|||
{
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
if(const_number < MAX_UNIFORM)
|
||||
ProgramShaderCache::SetUniformObjects(1, const_number, f, count);
|
||||
//return;
|
||||
}
|
||||
|
@ -311,6 +315,7 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co
|
|||
}
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
{
|
||||
if(const_number < MAX_UNIFORM)
|
||||
ProgramShaderCache::SetUniformObjects(1, const_number, buf, count);
|
||||
//return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue