gsdx (ogl):

* Use bigger index for Uniform buffer to avoid any collision with sampler. 
* add a new config to disable openGL 4.2 requirement. Would be done at runtime later.


git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5620 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2013-04-19 19:16:26 +00:00
parent 796bdb8f37
commit 08329122aa
8 changed files with 81 additions and 31 deletions

View File

@ -32,6 +32,10 @@
static uint32 g_draw_count = 0; static uint32 g_draw_count = 0;
static uint32 g_frame_count = 1; static uint32 g_frame_count = 1;
static const uint32 g_merge_cb_index = 10;
static const uint32 g_interlace_cb_index = 11;
static const uint32 g_shadeboost_cb_index = 12;
static const uint32 g_fxaa_cb_index = 13;
GSDeviceOGL::GSDeviceOGL() GSDeviceOGL::GSDeviceOGL()
: m_free_window(false) : m_free_window(false)
@ -287,7 +291,7 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
// **************************************************************** // ****************************************************************
// merge // merge
// **************************************************************** // ****************************************************************
m_merge_obj.cb = new GSUniformBufferOGL(1, sizeof(MergeConstantBuffer)); m_merge_obj.cb = new GSUniformBufferOGL(g_merge_cb_index, sizeof(MergeConstantBuffer));
for(uint i = 0; i < countof(m_merge_obj.ps); i++) for(uint i = 0; i < countof(m_merge_obj.ps); i++)
CompileShaderFromSource("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_merge_obj.ps[i]); CompileShaderFromSource("merge.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_merge_obj.ps[i]);
@ -299,14 +303,14 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
// **************************************************************** // ****************************************************************
// interlace // interlace
// **************************************************************** // ****************************************************************
m_interlace.cb = new GSUniformBufferOGL(2, sizeof(InterlaceConstantBuffer)); m_interlace.cb = new GSUniformBufferOGL(g_interlace_cb_index, sizeof(InterlaceConstantBuffer));
for(uint i = 0; i < countof(m_interlace.ps); i++) for(uint i = 0; i < countof(m_interlace.ps); i++)
CompileShaderFromSource("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_interlace.ps[i]); CompileShaderFromSource("interlace.glsl", format("ps_main%d", i), GL_FRAGMENT_SHADER, &m_interlace.ps[i]);
// **************************************************************** // ****************************************************************
// Shade boost // Shade boost
// **************************************************************** // ****************************************************************
m_shadeboost.cb = new GSUniformBufferOGL(6, sizeof(ShadeBoostConstantBuffer)); m_shadeboost.cb = new GSUniformBufferOGL(g_shadeboost_cb_index, sizeof(ShadeBoostConstantBuffer));
int ShadeBoost_Contrast = theApp.GetConfig("ShadeBoost_Contrast", 50); int ShadeBoost_Contrast = theApp.GetConfig("ShadeBoost_Contrast", 50);
int ShadeBoost_Brightness = theApp.GetConfig("ShadeBoost_Brightness", 50); int ShadeBoost_Brightness = theApp.GetConfig("ShadeBoost_Brightness", 50);
@ -347,7 +351,7 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
// FIXME need to define FXAA_GLSL_130 for the shader // FIXME need to define FXAA_GLSL_130 for the shader
// FIXME need to manually set the index... // FIXME need to manually set the index...
// FIXME need dofxaa interface too // FIXME need dofxaa interface too
// m_fxaa.cb = new GSUniformBufferOGL(3, sizeof(FXAAConstantBuffer)); // m_fxaa.cb = new GSUniformBufferOGL(g_fxaa_cb_index, sizeof(FXAAConstantBuffer));
//CompileShaderFromSource("fxaa.fx", format("ps_main", i), GL_FRAGMENT_SHADER, &m_fxaa.ps); //CompileShaderFromSource("fxaa.fx", format("ps_main", i), GL_FRAGMENT_SHADER, &m_fxaa.ps);
// **************************************************************** // ****************************************************************
@ -597,47 +601,62 @@ void GSDeviceOGL::DebugOutput()
//DebugBB(); //DebugBB();
} }
void GSDeviceOGL::DrawPrimitive() #ifdef DISABLE_GL42
static void set_uniform_buffer_binding(GLuint prog, GLchar* name, GLuint binding) {
GLuint index;
index = glGetUniformBlockIndex(prog, name);
if (index != GL_INVALID_INDEX) {
glUniformBlockBinding(prog, index, binding);
}
}
#endif
void GSDeviceOGL::BeforeDraw()
{ {
#ifdef OGL_DEBUG #ifdef OGL_DEBUG
DebugInput(); DebugInput();
#endif #endif
m_state.vb->DrawPrimitive(); #ifdef DISABLE_GL42
set_uniform_buffer_binding(m_state.vs, "cb20", 20);
set_uniform_buffer_binding(m_state.ps, "cb21", 21);
set_uniform_buffer_binding(m_state.ps, "cb10", 10);
set_uniform_buffer_binding(m_state.ps, "cb11", 11);
set_uniform_buffer_binding(m_state.ps, "cb12", 12);
set_uniform_buffer_binding(m_state.ps, "cb13", 13);
#endif
}
void GSDeviceOGL::AfterDraw()
{
#ifdef OGL_DEBUG #ifdef OGL_DEBUG
DebugOutput(); DebugOutput();
g_draw_count++; g_draw_count++;
#endif #endif
} }
void GSDeviceOGL::DrawPrimitive()
{
BeforeDraw();
m_state.vb->DrawPrimitive();
AfterDraw();
}
void GSDeviceOGL::DrawIndexedPrimitive() void GSDeviceOGL::DrawIndexedPrimitive()
{ {
#ifdef OGL_DEBUG BeforeDraw();
DebugInput();
#endif
m_state.vb->DrawIndexedPrimitive(); m_state.vb->DrawIndexedPrimitive();
AfterDraw();
#ifdef OGL_DEBUG
DebugOutput();
g_draw_count++;
#endif
} }
void GSDeviceOGL::DrawIndexedPrimitive(int offset, int count) void GSDeviceOGL::DrawIndexedPrimitive(int offset, int count)
{ {
ASSERT(offset + count <= m_index.count); ASSERT(offset + count <= m_index.count);
#ifdef OGL_DEBUG
DebugInput();
#endif
BeforeDraw();
m_state.vb->DrawIndexedPrimitive(offset, count); m_state.vb->DrawIndexedPrimitive(offset, count);
AfterDraw();
#ifdef OGL_DEBUG
DebugOutput();
g_draw_count++;
#endif
} }
void GSDeviceOGL::ClearRenderTarget(GSTexture* t, const GSVector4& c) void GSDeviceOGL::ClearRenderTarget(GSTexture* t, const GSVector4& c)
@ -733,7 +752,7 @@ GSTexture* GSDeviceOGL::CopyOffscreen(GSTexture* src, const GSVector4& sr, int w
{ {
ASSERT(0); ASSERT(0);
return false; return NULL;
} }
// FIXME: It is possible to bypass completely offscreen-buffer on opengl but it needs some re-thinking of the code. // FIXME: It is possible to bypass completely offscreen-buffer on opengl but it needs some re-thinking of the code.
@ -1283,7 +1302,11 @@ void GSDeviceOGL::CompileShaderFromSource(const std::string& glsl_file, const st
// Build a header string // Build a header string
// ***************************************************** // *****************************************************
// First select the version (must be the first line so we need to generate it // First select the version (must be the first line so we need to generate it
#ifdef DISABLE_GL42
std::string version = "#version 330\n#extension GL_ARB_separate_shader_objects : require\n#define DISABLE_GL42\n";
#else
std::string version = "#version 330\n#extension GL_ARB_shading_language_420pack: require\n#extension GL_ARB_separate_shader_objects : require\n"; std::string version = "#version 330\n#extension GL_ARB_shading_language_420pack: require\n#extension GL_ARB_separate_shader_objects : require\n";
#endif
//std::string version = "#version 420\n"; //std::string version = "#version 420\n";
// Allow to puts several shader in 1 files // Allow to puts several shader in 1 files

View File

@ -599,6 +599,8 @@ class GSDeviceOGL : public GSDevice
void DrawPrimitive(); void DrawPrimitive();
void DrawIndexedPrimitive(); void DrawIndexedPrimitive();
void DrawIndexedPrimitive(int offset, int count); void DrawIndexedPrimitive(int offset, int count);
void BeforeDraw();
void AfterDraw();
void ClearRenderTarget(GSTexture* t, const GSVector4& c); void ClearRenderTarget(GSTexture* t, const GSVector4& c);
void ClearRenderTarget(GSTexture* t, uint32 c); void ClearRenderTarget(GSTexture* t, uint32 c);

View File

@ -23,10 +23,13 @@
#include "GSDeviceOGL.h" #include "GSDeviceOGL.h"
#include "GSTables.h" #include "GSTables.h"
static const uint32 g_vs_cb_index = 20;
static const uint32 g_ps_cb_index = 21;
void GSDeviceOGL::CreateTextureFX() void GSDeviceOGL::CreateTextureFX()
{ {
m_vs_cb = new GSUniformBufferOGL(4, sizeof(VSConstantBuffer)); m_vs_cb = new GSUniformBufferOGL(g_vs_cb_index, sizeof(VSConstantBuffer));
m_ps_cb = new GSUniformBufferOGL(5, sizeof(PSConstantBuffer)); m_ps_cb = new GSUniformBufferOGL(g_ps_cb_index, sizeof(PSConstantBuffer));
glGenSamplers(1, &m_rt_ss); glGenSamplers(1, &m_rt_ss);
// FIXME, seem to have no difference between sampler !!! // FIXME, seem to have no difference between sampler !!!

View File

@ -35,3 +35,5 @@
//#define DISABLE_COLCLAMP //#define DISABLE_COLCLAMP
//#define DISABLE_DATE //#define DISABLE_DATE
//#define DISABLE_GL42

View File

@ -11,7 +11,11 @@ layout(location = 0) in vertex_basic PSin;
layout(location = 0) out vec4 SV_Target0; layout(location = 0) out vec4 SV_Target0;
layout(std140, binding = 2) uniform cb0 #ifdef DISABLE_GL42
layout(std140) uniform cb11
#else
layout(std140, binding = 11) uniform cb11
#endif
{ {
vec2 ZrH; vec2 ZrH;
float hH; float hH;

View File

@ -11,7 +11,11 @@ layout(location = 0) in vertex_basic PSin;
layout(location = 0) out vec4 SV_Target0; layout(location = 0) out vec4 SV_Target0;
layout(std140, binding = 1) uniform cb0 #ifdef DISABLE_GL42
layout(std140) uniform cb10
#else
layout(std140, binding = 10) uniform cb10
#endif
{ {
vec4 BGColor; vec4 BGColor;
}; };

View File

@ -18,7 +18,11 @@ layout(location = 0) in vertex_basic PSin;
layout(location = 0) out vec4 SV_Target0; layout(location = 0) out vec4 SV_Target0;
layout(std140, binding = 6) uniform cb0 #ifdef DISABLE_GL42
layout(std140) uniform cb12
#else
layout(std140, binding = 12) uniform cb12
#endif
{ {
vec4 BGColor; vec4 BGColor;
}; };

View File

@ -69,7 +69,11 @@ out gl_PerVertex {
float gl_ClipDistance[]; float gl_ClipDistance[];
}; };
layout(std140, binding = 4) uniform cb0 #ifdef DISABLE_GL42
layout(std140) uniform cb20
#else
layout(std140, binding = 20) uniform cb20
#endif
{ {
vec4 VertexScale; vec4 VertexScale;
vec4 VertexOffset; vec4 VertexOffset;
@ -278,7 +282,11 @@ layout(binding = 0) uniform sampler2D TextureSampler;
layout(binding = 1) uniform sampler2D PaletteSampler; layout(binding = 1) uniform sampler2D PaletteSampler;
layout(binding = 2) uniform sampler2D RTCopySampler; layout(binding = 2) uniform sampler2D RTCopySampler;
layout(std140, binding = 5) uniform cb1 #ifdef DISABLE_GL42
layout(std140) uniform cb21
#else
layout(std140, binding = 21) uniform cb21
#endif
{ {
vec3 FogColor; vec3 FogColor;
float AREF; float AREF;