gsdx-ogl-wnd:

* factorize sample object creation
* remember frame buffer attachment state
* Use a basic context on EGL. Allow to use Mesa 9.1 on AMD GPU.
* precompile vertex and geometry shader to avoid benchmark polution on replay
* Try harder to detect FGLRX driver on window
* various clean

Remain to fix the coordinate system for upscaling



git-svn-id: http://pcsx2.googlecode.com/svn/branches/gsdx-ogl-wnd@5651 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2013-06-09 16:41:58 +00:00
parent 65b5a376ed
commit 58699923e0
8 changed files with 111 additions and 246 deletions

View File

@ -113,7 +113,8 @@ namespace GLLoader {
fprintf(stderr, "Supported Opengl version: %s on GPU: %s. Vendor: %s\n", s, glGetString(GL_RENDERER), glGetString(GL_VENDOR)); fprintf(stderr, "Supported Opengl version: %s on GPU: %s. Vendor: %s\n", s, glGetString(GL_RENDERER), glGetString(GL_VENDOR));
// Could be useful to detect the GPU vendor: // Could be useful to detect the GPU vendor:
if (strcmp((const char*)glGetString(GL_VENDOR), "ATI Technologies Inc.") == 0) //if (strcmp((const char*)glGetString(GL_VENDOR), "ATI Technologies Inc.") == 0)
if (strstr((const char*)glGetString(GL_VENDOR), "ATI"))
fglrx_buggy_driver = true; fglrx_buggy_driver = true;
GLuint dot = 0; GLuint dot = 0;

View File

@ -489,9 +489,6 @@ EXPORT_C GSreadFIFO2(uint8* mem, uint32 size)
#ifdef ENABLE_OGL_MT_HACK #ifdef ENABLE_OGL_MT_HACK
// FIXME called from EE core thread not MTGS which cause // FIXME called from EE core thread not MTGS which cause
// invalidate data for opengl // invalidate data for opengl
#ifdef ENABLE_OGL_DEBUG
if (theApp.GetConfig("renderer", 0) / 3 == 4) fprintf(stderr, "Disable FIFO2(%d) on opengl\n", size);
#endif
s_gs->m_wnd->AttachContext(); s_gs->m_wnd->AttachContext();
#endif #endif

View File

@ -116,7 +116,7 @@ GSDeviceOGL::~GSDeviceOGL()
// Delete HW FX // Delete HW FX
delete m_vs_cb; delete m_vs_cb;
delete m_ps_cb; delete m_ps_cb;
gl_DeleteSamplers(1, &m_rt_ss); gl_DeleteSamplers(1, &m_palette_ss);
delete m_vb; delete m_vb;
if (GLLoader::found_GL_ARB_separate_shader_objects) { if (GLLoader::found_GL_ARB_separate_shader_objects) {
@ -235,36 +235,9 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
hr = m_dev->CreateBlendState(&bsd, &m_convert.bs); hr = m_dev->CreateBlendState(&bsd, &m_convert.bs);
#endif #endif
gl_GenSamplers(1, &m_convert.ln);
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// FIXME which value for GL_TEXTURE_MIN_LOD
gl_SamplerParameterf(m_convert.ln, GL_TEXTURE_MAX_LOD, FLT_MAX);
// FIXME: seems there is 2 possibility in opengl
// DX: sd.ComparisonFunc = D3D11_COMPARISON_NEVER;
// gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_COMPARE_MODE, GL_NONE);
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
gl_SamplerParameteri(m_convert.ln, GL_TEXTURE_COMPARE_FUNC, GL_NEVER);
// FIXME: need ogl extension sd.MaxAnisotropy = 16;
CreateSampler(m_convert.ln, true, false, false);
gl_GenSamplers(1, &m_convert.pt); CreateSampler(m_convert.pt, false, false, false);
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// FIXME which value for GL_TEXTURE_MIN_LOD
gl_SamplerParameterf(m_convert.pt, GL_TEXTURE_MAX_LOD, FLT_MAX);
// FIXME: seems there is 2 possibility in opengl
// DX: sd.ComparisonFunc = D3D11_COMPARISON_NEVER;
// gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_COMPARE_MODE, GL_NONE);
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
gl_SamplerParameteri(m_convert.pt, GL_TEXTURE_COMPARE_FUNC, GL_NEVER);
// FIXME: need ogl extension sd.MaxAnisotropy = 16;
m_convert.dss = new GSDepthStencilOGL(); m_convert.dss = new GSDepthStencilOGL();
m_convert.bs = new GSBlendStateOGL(); m_convert.bs = new GSBlendStateOGL();
@ -431,44 +404,6 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
// hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, NULL, 0, D3D11_SDK_VERSION, &scd, &m_swapchain, &m_dev, &level, &m_ctx); // hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, NULL, 0, D3D11_SDK_VERSION, &scd, &m_swapchain, &m_dev, &level, &m_ctx);
#endif #endif
// ****************************************************************
// The check of capability is done when context is created on openGL
// For the moment don't bother with extension, I just ask the most recent openGL version
// ****************************************************************
#if 0
if(FAILED(hr)) return false;
if(!SetFeatureLevel(level, true))
{
return false;
}
D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
hr = m_dev->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS));
// msaa
for(uint32 i = 2; i <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++)
{
uint32 quality[2] = {0, 0};
if(SUCCEEDED(m_dev->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, i, &quality[0])) && quality[0] > 0
&& SUCCEEDED(m_dev->CheckMultisampleQualityLevels(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, i, &quality[1])) && quality[1] > 0)
{
m_msaa_desc.Count = i;
m_msaa_desc.Quality = std::min<uint32>(quality[0] - 1, quality[1] - 1);
if(i >= m_msaa) break;
}
}
if(m_msaa_desc.Count == 1)
{
m_msaa = 0;
}
#endif
return true; return true;
} }
@ -508,79 +443,6 @@ void GSDeviceOGL::Flip()
#endif #endif
} }
void GSDeviceOGL::DebugBB()
{
bool dump_me = false;
uint32 start = theApp.GetConfig("debug_ogl_dump", 0);
uint32 length = theApp.GetConfig("debug_ogl_dump_length", 5);
if ( (start != 0 && g_frame_count >= start && g_frame_count < (start + length)) ) dump_me = true;
if (!dump_me) return;
GLuint fbo_old = m_state.fbo;
OMSetFBO(m_fbo);
GSVector2i size = m_backbuffer->GetSize();
GSTexture* rt = CreateRenderTarget(size.x, size.y, false);
static_cast<GSTextureOGL*>(rt)->Attach(GL_COLOR_ATTACHMENT0);
gl_BlitFramebuffer(0, 0, size.x, size.y,
0, 0, size.x, size.y,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
rt->Save(format("/tmp/out_f%d__d%d__bb.bmp", g_frame_count, g_draw_count));
delete rt;
OMSetFBO(fbo_old);
}
void GSDeviceOGL::DebugInput()
{
bool dump_me = false;
uint32 start = theApp.GetConfig("debug_ogl_dump", 0);
uint32 length = theApp.GetConfig("debug_ogl_dump_length", 5);
if ( (start != 0 && g_frame_count >= start && g_frame_count < (start + length)) ) dump_me = true;
if (!dump_me) return;
for (auto i = 0 ; i < 3 ; i++) {
if (m_state.ps_srv[i] != NULL) {
m_state.ps_srv[i]->Save(format("/tmp/in_f%d__d%d__%d.bmp", g_frame_count, g_draw_count, i));
}
}
//if (m_state.rtv != NULL) m_state.rtv->Save(format("/tmp/target_f%d__d%d__tex.bmp", g_frame_count, g_draw_count));
//if (m_state.dsv != NULL) m_state.dsv->Save(format("/tmp/ds_in_%d.bmp", g_draw_count));
fprintf(stderr, "Draw %d (Frame %d)\n", g_draw_count, g_frame_count);
fprintf(stderr, "vs: %d ; gs: %d ; ps: %d\n", m_state.vs, m_state.gs, m_state.ps);
m_state.vb->debug();
m_state.bs->debug();
m_state.dss->debug();
}
void GSDeviceOGL::DebugOutput()
{
CheckDebugLog();
bool dump_me = false;
uint32 start = theApp.GetConfig("debug_ogl_dump", 0);
uint32 length = theApp.GetConfig("debug_ogl_dump_length", 5);
if ( (start != 0 && g_frame_count >= start && g_frame_count < (start + length)) ) dump_me = true;
if (!dump_me) return;
if (m_state.rtv == m_backbuffer) {
m_state.rtv->Save(format("/tmp/out_f%d__d%d__back.bmp", g_frame_count, g_draw_count));
} else {
if (m_state.rtv != NULL) m_state.rtv->Save(format("/tmp/out_f%d__d%d__tex.bmp", g_frame_count, g_draw_count));
}
if (m_state.dsv != NULL) m_state.dsv->Save(format("/tmp/ds_out_%d.bmp", g_draw_count));
fprintf(stderr, "\n");
//DebugBB();
}
static void set_uniform_buffer_binding(GLuint prog, GLchar* name, GLuint binding) { static void set_uniform_buffer_binding(GLuint prog, GLchar* name, GLuint binding) {
GLuint index; GLuint index;
index = gl_GetUniformBlockIndex(prog, name); index = gl_GetUniformBlockIndex(prog, name);
@ -634,9 +496,6 @@ GLuint GSDeviceOGL::link_prog()
void GSDeviceOGL::BeforeDraw() void GSDeviceOGL::BeforeDraw()
{ {
#ifdef ENABLE_OGL_DEBUG
DebugInput();
#endif
hash_map<uint64, GLuint >::iterator single_prog; hash_map<uint64, GLuint >::iterator single_prog;
@ -684,9 +543,6 @@ void GSDeviceOGL::BeforeDraw()
void GSDeviceOGL::AfterDraw() void GSDeviceOGL::AfterDraw()
{ {
#ifdef ENABLE_OGL_DEBUG
DebugOutput();
#endif
#if defined(ENABLE_OGL_DEBUG) || defined(PRINT_FRAME_NUMBER) #if defined(ENABLE_OGL_DEBUG) || defined(PRINT_FRAME_NUMBER)
g_draw_count++; g_draw_count++;
#endif #endif
@ -766,6 +622,40 @@ void GSDeviceOGL::ClearStencil(GSTexture* t, uint8 c)
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
} }
void GSDeviceOGL::CreateSampler(GLuint& sampler, bool bilinear, bool tau, bool tav)
{
gl_GenSamplers(1, &sampler);
if (bilinear) {
gl_SamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl_SamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
gl_SamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl_SamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
// FIXME ensure U -> S, V -> T and W->R
if (tau)
gl_SamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_REPEAT);
else
gl_SamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
if (tav)
gl_SamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_REPEAT);
else
gl_SamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gl_SamplerParameteri(sampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// FIXME which value for GL_TEXTURE_MIN_LOD
gl_SamplerParameterf(sampler, GL_TEXTURE_MAX_LOD, FLT_MAX);
// FIXME: seems there is 2 possibility in opengl
// DX: sd.ComparisonFunc = D3D11_COMPARISON_NEVER;
// gl_SamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_NONE);
gl_SamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
gl_SamplerParameteri(sampler, GL_TEXTURE_COMPARE_FUNC, GL_NEVER);
// FIXME: need ogl extension sd.MaxAnisotropy = 16;
}
GSTexture* GSDeviceOGL::CreateRenderTarget(int w, int h, bool msaa, int format) GSTexture* GSDeviceOGL::CreateRenderTarget(int w, int h, bool msaa, int format)
{ {
return GSDevice::CreateRenderTarget(w, h, msaa, format ? format : GL_RGBA8); return GSDevice::CreateRenderTarget(w, h, msaa, format ? format : GL_RGBA8);
@ -1316,6 +1206,12 @@ void GSDeviceOGL::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVecto
void GSDeviceOGL::CompileShaderFromSource(const std::string& glsl_file, const std::string& entry, GLenum type, GLuint* program, const char* glsl_h_code, const std::string& macro_sel) void GSDeviceOGL::CompileShaderFromSource(const std::string& glsl_file, const std::string& entry, GLenum type, GLuint* program, const char* glsl_h_code, const std::string& macro_sel)
{ {
// Not supported
if (type == GL_GEOMETRY_SHADER && !GLLoader::found_geometry_shader) {
*program = 0;
return;
}
// ***************************************************** // *****************************************************
// Build a header string // Build a header string
// ***************************************************** // *****************************************************
@ -1459,13 +1355,13 @@ void GSDeviceOGL::CompileShaderFromSource(const std::string& glsl_file, const st
void GSDeviceOGL::CheckDebugLog() void GSDeviceOGL::CheckDebugLog()
{ {
unsigned int count = 64; // max. num. of messages that will be read from the log unsigned int count = 16; // max. num. of messages that will be read from the log
int bufsize = 2048; int bufsize = 2048;
unsigned int* sources = new unsigned int[count]; unsigned int sources[16] = {};
unsigned int* types = new unsigned int[count]; unsigned int types[16] = {};
unsigned int* ids = new unsigned int[count]; unsigned int ids[16] = {};
unsigned int* severities = new unsigned int[count]; unsigned int severities[16] = {};
int* lengths = new int[count]; int lengths[16] = {};
char* messageLog = new char[bufsize]; char* messageLog = new char[bufsize];
unsigned int retVal = gl_GetDebugMessageLogARB(count, bufsize, sources, types, ids, severities, lengths, messageLog); unsigned int retVal = gl_GetDebugMessageLogARB(count, bufsize, sources, types, ids, severities, lengths, messageLog);
@ -1480,13 +1376,6 @@ void GSDeviceOGL::CheckDebugLog()
pos += lengths[i]; pos += lengths[i];
} }
} }
delete [] sources;
delete [] types;
delete [] ids;
delete [] severities;
delete [] lengths;
delete [] messageLog;
} }
void GSDeviceOGL::DebugOutputToFile(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message) void GSDeviceOGL::DebugOutputToFile(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message)

View File

@ -280,8 +280,7 @@ class GSDeviceOGL : public GSDevice
uint32 tme:1; uint32 tme:1;
uint32 fst:1; uint32 fst:1;
uint32 logz:1; uint32 logz:1;
uint32 rtcopy:1; //uint32 rtcopy:1;
uint32 wildhack:2;
}; };
uint32 key; uint32 key;
@ -580,9 +579,6 @@ class GSDeviceOGL : public GSDevice
void CheckDebugLog(); void CheckDebugLog();
static void DebugOutputToFile(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message); static void DebugOutputToFile(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message);
void DebugOutput();
void DebugInput();
void DebugBB();
bool HasStencil() { return true; } bool HasStencil() { return true; }
bool HasDepth32() { return true; } bool HasDepth32() { return true; }
@ -603,6 +599,7 @@ class GSDeviceOGL : public GSDevice
void ClearDepth(GSTexture* t, float c); void ClearDepth(GSTexture* t, float c);
void ClearStencil(GSTexture* t, uint8 c); void ClearStencil(GSTexture* t, uint8 c);
void CreateSampler(GLuint& sampler, bool bilinear, bool tau, bool tav);
GSTexture* CreateRenderTarget(int w, int h, bool msaa, int format = 0); GSTexture* CreateRenderTarget(int w, int h, bool msaa, int format = 0);
GSTexture* CreateDepthStencil(int w, int h, bool msaa, int format = 0); GSTexture* CreateDepthStencil(int w, int h, bool msaa, int format = 0);
GSTexture* CreateTexture(int w, int h, int format = 0); GSTexture* CreateTexture(int w, int h, int format = 0);

View File

@ -319,10 +319,8 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour
vs_sel.tme = PRIM->TME; vs_sel.tme = PRIM->TME;
vs_sel.fst = PRIM->FST; vs_sel.fst = PRIM->FST;
//vs_sel.logz = dev->HasDepth32() ? 0 : m_logz ? 1 : 0;
vs_sel.logz = m_logz ? 1 : 0; vs_sel.logz = m_logz ? 1 : 0;
//OGL vs_sel.rtcopy = !!rtcopy; //OGL vs_sel.rtcopy = !!rtcopy;
vs_sel.rtcopy = false;
// The real GS appears to do no masking based on the Z buffer format and writing larger Z values // The real GS appears to do no masking based on the Z buffer format and writing larger Z values
// than the buffer supports seems to be an error condition on the real GS, causing it to crash. // than the buffer supports seems to be an error condition on the real GS, causing it to crash.
@ -529,8 +527,7 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour
dev->SetupOM(om_dssel, om_bsel, afix); dev->SetupOM(om_dssel, om_bsel, afix);
dev->SetupVS(vs_sel, &vs_cb); dev->SetupVS(vs_sel, &vs_cb);
if (GLLoader::found_geometry_shader) dev->SetupGS(gs_sel);
dev->SetupGS(gs_sel);
dev->SetupPS(ps_sel, &ps_cb, ps_ssel); dev->SetupPS(ps_sel, &ps_cb, ps_ssel);
// draw // draw

View File

@ -33,47 +33,42 @@ void GSDeviceOGL::CreateTextureFX()
m_vs_cb = new GSUniformBufferOGL(g_vs_cb_index, sizeof(VSConstantBuffer)); m_vs_cb = new GSUniformBufferOGL(g_vs_cb_index, sizeof(VSConstantBuffer));
m_ps_cb = new GSUniformBufferOGL(g_ps_cb_index, sizeof(PSConstantBuffer)); m_ps_cb = new GSUniformBufferOGL(g_ps_cb_index, sizeof(PSConstantBuffer));
gl_GenSamplers(1, &m_rt_ss); CreateSampler(m_palette_ss, false, false, false);
// FIXME, seem to have no difference between sampler !!!
m_palette_ss = m_rt_ss;
gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// FIXME which value for GL_TEXTURE_MIN_LOD
gl_SamplerParameterf(m_rt_ss, GL_TEXTURE_MAX_LOD, FLT_MAX);
// FIXME: seems there is 2 possibility in opengl
// DX: sd.ComparisonFunc = D3D11_COMPARISON_NEVER;
// gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_COMPARE_MODE, GL_NONE);
gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_COMPARE_FUNC, GL_NEVER);
// FIXME: need ogl extension sd.MaxAnisotropy = 16;
GSInputLayoutOGL vert_format[] = GSInputLayoutOGL vert_format[] =
{ {
// FIXME
{0 , 2 , GL_FLOAT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(0) } , {0 , 2 , GL_FLOAT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(0) } ,
{1 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(GSVertex) , (const GLvoid*)(8) } , {1 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(GSVertex) , (const GLvoid*)(8) } ,
{2 , 1 , GL_FLOAT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(12) } , {2 , 1 , GL_FLOAT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(12) } ,
{3 , 2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(16) } , {3 , 2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(16) } ,
{4 , 1 , GL_UNSIGNED_INT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(20) } , {4 , 1 , GL_UNSIGNED_INT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(20) } ,
// note: there is a 32 bits pad
{5 , 2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(24) } , {5 , 2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(24) } ,
{6 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(GSVertex) , (const GLvoid*)(28) } , {6 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(GSVertex) , (const GLvoid*)(28) } ,
}; };
m_vb = new GSVertexBufferStateOGL(sizeof(GSVertex), vert_format, countof(vert_format)); m_vb = new GSVertexBufferStateOGL(sizeof(GSVertex), vert_format, countof(vert_format));
// Compile some dummy shaders to allow modification inside Apitrace for debug // Compile some dummy shaders to allow modification inside Apitrace for debug
#ifdef _LINUX
GLuint dummy; GLuint dummy;
std::string macro = "\n"; std::string macro = "\n";
CompileShaderFromSource("tfx.glsl", "vs_main", GL_VERTEX_SHADER, &dummy, tfx_glsl, macro); CompileShaderFromSource("tfx.glsl", "vs_main", GL_VERTEX_SHADER, &dummy, tfx_glsl, macro);
if (GLLoader::found_geometry_shader) CompileShaderFromSource("tfx.glsl", "gs_main", GL_GEOMETRY_SHADER, &dummy, tfx_glsl, macro);
CompileShaderFromSource("tfx.glsl", "gs_main", GL_GEOMETRY_SHADER, &dummy, tfx_glsl, macro);
CompileShaderFromSource("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, &dummy, tfx_glsl, macro); CompileShaderFromSource("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, &dummy, tfx_glsl, macro);
#endif
// Pre compile all Geometry & Vertex Shader
// It might cost a seconds at startup but it would reduce benchmark pollution
GSDeviceOGL::GSSelector gs_sel;
for (uint32 key = 0; key < (1 << 3); key++) {
gs_sel.key = key;
SetupGS(gs_sel);
}
GSDeviceOGL::VSSelector vs_sel;
for (uint32 key = 0; key < (1 << 5); key++) {
vs_sel.key = key;
SetupVS(vs_sel, NULL);
}
// Use sane reset value
GSSetShader(0);
VSSetShader(0);
} }
void GSDeviceOGL::SetupVS(VSSelector sel, const VSConstantBuffer* cb) void GSDeviceOGL::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
@ -88,8 +83,7 @@ void GSDeviceOGL::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
std::string macro = format("#define VS_BPPZ %d\n", sel.bppz) std::string macro = format("#define VS_BPPZ %d\n", sel.bppz)
+ format("#define VS_LOGZ %d\n", sel.logz) + format("#define VS_LOGZ %d\n", sel.logz)
+ format("#define VS_TME %d\n", sel.tme) + format("#define VS_TME %d\n", sel.tme)
+ format("#define VS_FST %d\n", sel.fst) + format("#define VS_FST %d\n", sel.fst);
+ format("#define VS_RTCOPY %d\n", sel.rtcopy);
GLuint vs; GLuint vs;
CompileShaderFromSource("tfx.glsl", "vs_main", GL_VERTEX_SHADER, &vs, tfx_glsl, macro); CompileShaderFromSource("tfx.glsl", "vs_main", GL_VERTEX_SHADER, &vs, tfx_glsl, macro);
@ -101,7 +95,7 @@ void GSDeviceOGL::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
// ************************************************************* // *************************************************************
// Dynamic // Dynamic
// ************************************************************* // *************************************************************
if(m_vs_cb_cache.Update(cb)) { if(cb != NULL && m_vs_cb_cache.Update(cb)) {
SetUniformBuffer(m_vs_cb); SetUniformBuffer(m_vs_cb);
m_vs_cb->upload(cb); m_vs_cb->upload(cb);
} }
@ -168,7 +162,6 @@ void GSDeviceOGL::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerS
CompileShaderFromSource("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, &ps, tfx_glsl, macro); CompileShaderFromSource("tfx.glsl", "ps_main", GL_FRAGMENT_SHADER, &ps, tfx_glsl, macro);
m_ps[sel] = ps; m_ps[sel] = ps;
i = m_ps.find(sel);
} else { } else {
ps = i->second; ps = i->second;
} }
@ -201,36 +194,7 @@ void GSDeviceOGL::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerS
// ************************************************************* // *************************************************************
// Static // Static
// ************************************************************* // *************************************************************
gl_GenSamplers(1, &ss0); CreateSampler(ss0, ssel.ltf, ssel.tau, ssel.tav);
if (ssel.ltf) {
gl_SamplerParameteri(ss0, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl_SamplerParameteri(ss0, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
gl_SamplerParameteri(ss0, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl_SamplerParameteri(ss0, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
// FIXME ensure U -> S, V -> T and W->R
if (ssel.tau)
gl_SamplerParameteri(ss0, GL_TEXTURE_WRAP_S, GL_REPEAT);
else
gl_SamplerParameteri(ss0, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
if (ssel.tav)
gl_SamplerParameteri(ss0, GL_TEXTURE_WRAP_T, GL_REPEAT);
else
gl_SamplerParameteri(ss0, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gl_SamplerParameteri(ss0, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// FIXME which value for GL_TEXTURE_MIN_LOD
gl_SamplerParameterf(m_rt_ss, GL_TEXTURE_MAX_LOD, FLT_MAX);
// FIXME: seems there is 2 possibility in opengl
// DX: sd.ComparisonFunc = D3D11_COMPARISON_NEVER;
// gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_COMPARE_MODE, GL_NONE);
gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
gl_SamplerParameteri(m_rt_ss, GL_TEXTURE_COMPARE_FUNC, GL_NEVER);
// FIXME: need ogl extension sd.MaxAnisotropy = 16;
m_ps_ss[ssel] = ss0; m_ps_ss[ssel] = ss0;
} }
@ -241,8 +205,7 @@ void GSDeviceOGL::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerS
} }
} }
PSSetSamplerState(ss0, ss1, sel.date ? m_rt_ss : 0); PSSetSamplerState(ss0, ss1, 0);
PSSetShader(ps); PSSetShader(ps);
} }

View File

@ -22,8 +22,11 @@
#include "stdafx.h" #include "stdafx.h"
#include <limits.h> #include <limits.h>
#include "GSTextureOGL.h" #include "GSTextureOGL.h"
static int g_state_texture_unit = -1; static GLuint g_state_texture_unit = -1;
static int g_state_texture_id[7] = {0, 0, 0, 0, 0, 0, 0}; static GLuint g_state_texture_id[7] = {0, 0, 0, 0, 0, 0, 0};
static GLuint g_color0 = 0;
static GLuint g_color1 = 0;
static GLuint g_depth = 0;
// FIXME: check if it possible to always use those setup by default // FIXME: check if it possible to always use those setup by default
// glPixelStorei(GL_PACK_ALIGNMENT, 1); // glPixelStorei(GL_PACK_ALIGNMENT, 1);
@ -90,6 +93,7 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, bool msaa, int format, GLuint
// Extra buffer to handle various pixel transfer // Extra buffer to handle various pixel transfer
gl_GenBuffers(1, &m_pbo_id); gl_GenBuffers(1, &m_pbo_id);
#if 0
uint32 msaa_level; uint32 msaa_level;
if (m_msaa) { if (m_msaa) {
// FIXME which level of MSAA // FIXME which level of MSAA
@ -97,6 +101,7 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, bool msaa, int format, GLuint
} else { } else {
msaa_level = 0; msaa_level = 0;
} }
#endif
// Allocate the buffer // Allocate the buffer
switch (m_type) { switch (m_type) {
@ -117,17 +122,12 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, bool msaa, int format, GLuint
case GSTexture::DepthStencil: case GSTexture::DepthStencil:
case GSTexture::RenderTarget: case GSTexture::RenderTarget:
case GSTexture::Texture: case GSTexture::Texture:
// FIXME: check the opensource driver
// Howto allocate the texture unit !!!
// In worst case the HW renderer seems to use 3 texture unit
// For the moment SW renderer only use 1 so don't bother
EnableUnit(3); EnableUnit(3);
if (m_msaa) { if (m_msaa) {
ASSERT(m_texture_target == GL_TEXTURE_2D_MULTISAMPLE); ASSERT(m_texture_target == GL_TEXTURE_2D_MULTISAMPLE);
// Require a recent GLEW and GL4.3 // Require a recent GL4.3 extension
//gl_TexStorage2DMultisample(m_texture_target, msaa_level, m_format, m_size.x, m_size.y, false); //gl_TexStorage2DMultisample(m_texture_target, msaa_level, m_format, m_size.x, m_size.y, false);
} else { } else {
//glTexParameteri(m_texture_target, GL_TEXTURE_MAX_LEVEL, 0);
gl_TexStorage2D(m_texture_target, 1, m_format, m_size.x, m_size.y); gl_TexStorage2D(m_texture_target, 1, m_format, m_size.x, m_size.y);
} }
break; break;
@ -148,7 +148,30 @@ GSTextureOGL::~GSTextureOGL()
void GSTextureOGL::Attach(GLenum attachment) void GSTextureOGL::Attach(GLenum attachment)
{ {
gl_FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, m_texture_target, m_texture_id, 0); switch(attachment) {
case GL_COLOR_ATTACHMENT0:
if (g_color0 != m_texture_id) {
g_color0 = m_texture_id;
gl_FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, m_texture_target, m_texture_id, 0);
}
break;
case GL_COLOR_ATTACHMENT1:
if (g_color1 != m_texture_id) {
g_color1 = m_texture_id;
gl_FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, m_texture_target, m_texture_id, 0);
}
break;
case GL_DEPTH_STENCIL_ATTACHMENT:
if (g_depth != m_texture_id) {
gl_FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, m_texture_target, m_texture_id, 0);
g_depth = m_texture_id;
}
break;
default:
gl_FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, m_texture_target, m_texture_id, 0);
break;
}
// FIXME DEBUG // FIXME DEBUG
//fprintf(stderr, "FB status %x\n", gl_CheckFramebufferStatus(GL_FRAMEBUFFER)); //fprintf(stderr, "FB status %x\n", gl_CheckFramebufferStatus(GL_FRAMEBUFFER));
} }
@ -204,11 +227,6 @@ bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch)
fprintf(stderr, "Skip Texture %dx%d with a pitch of %d pixel. Type %x\n", m_size.x, m_size.y, pitch >>2, m_format); fprintf(stderr, "Skip Texture %dx%d with a pitch of %d pixel. Type %x\n", m_size.x, m_size.y, pitch >>2, m_format);
fprintf(stderr, "Box (%d,%d)x(%d,%d)\n", r.x, r.y, r.width(), r.height()); fprintf(stderr, "Box (%d,%d)x(%d,%d)\n", r.x, r.y, r.width(), r.height());
#endif #endif
//char *random = (char*)malloc(m_size.x*m_size.y*32);
//glTexSubImage2D(m_texture_target, 0, r.x, r.y, r.width(), r.height(), GL_RGBA, GL_UNSIGNED_BYTE, random);
//return true;
//glTexSubImage2D(m_texture_target, 0, r.x, r.y, r.width(), r.height(), GL_RGBA, GL_UNSIGNED_BYTE, data);
//glFinish();
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); // Restore default behavior glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); // Restore default behavior
return false; return false;

View File

@ -52,12 +52,15 @@ bool GSWndEGL::CreateContext(int major, int minor)
EGLint numConfigs; EGLint numConfigs;
EGLint contextAttribs[] = EGLint contextAttribs[] =
{ {
// Not yet supported by Radeon/Gallium
#if 0
EGL_CONTEXT_MAJOR_VERSION_KHR, major, EGL_CONTEXT_MAJOR_VERSION_KHR, major,
EGL_CONTEXT_MINOR_VERSION_KHR, minor, EGL_CONTEXT_MINOR_VERSION_KHR, minor,
// Keep compatibility for old cruft // Keep compatibility for old cruft
//EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR, //EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR,
// FIXME : Request a debug context to ease opengl development // FIXME : Request a debug context to ease opengl development
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
#endif
EGL_NONE EGL_NONE
}; };
EGLint attrList[] = { EGLint attrList[] = {