Skip to content

Commit

Permalink
zzogl glsl4:
Browse files Browse the repository at this point in the history
* properly delete program and vertex array. Avoid a crash on plugin reload
* reset shader state. Avoid to reuse invalid data on plugin reload
gsdx:
* add an hack to unattach/attach the gl context from different thread. Help to solve some crashes. The best will be to move gpu operation out of gsreadfifo but it would need more works
* implement logz for test purpose (don't seem to help)
gsdx replay:
* use default xdg location


git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5289 96395faa-99c1-11dd-bbfe-3dabce05a288
  • Loading branch information
gregory.hainaut committed Jun 12, 2012
1 parent b722dfd commit 3b22f0f
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 39 deletions.
5 changes: 5 additions & 0 deletions plugins/GSdx/CMakeLists.txt
Expand Up @@ -10,6 +10,7 @@ endif(NOT TOP_CMAKE_WAS_SOURCED)
set(Output GSdx-0.1.16)

set(CommonFlags
-DOGL_MT_HACK
-D_LINUX
-fno-operator-names
-mpreferred-stack-boundary=2
Expand Down Expand Up @@ -49,6 +50,10 @@ if(CMAKE_BUILD_TYPE STREQUAL Release)
add_definitions(${CommonFlags} ${SDLFlags} ${OptimizationFlags} -W)
endif(CMAKE_BUILD_TYPE STREQUAL Release)

if(XDG_STD)
add_definitions(-DXDG_STD)
endif(XDG_STD)

set(GSdxSources
GPU.cpp
GPUDrawScanline.cpp
Expand Down
23 changes: 12 additions & 11 deletions plugins/GSdx/GS.cpp
Expand Up @@ -55,7 +55,11 @@ extern bool RunLinuxDialog();
#define PS2E_X86 0x01 // 32 bit
#define PS2E_X86_64 0x02 // 64 bit

#ifdef OGL_MT_HACK
GSRenderer* s_gs = NULL;
#else
static GSRenderer* s_gs = NULL;
#endif
static void (*s_irq)() = NULL;
static uint8* s_basemem = NULL;
static int s_renderer = -1;
Expand Down Expand Up @@ -457,18 +461,18 @@ EXPORT_C GSreadFIFO(uint8* mem)
{
try
{
#ifdef _LINUX
#ifdef OGL_MT_HACK
// FIXME: double check which thread call this function
// See fifo2 issue below
if (theApp.GetConfig("renderer", 0) / 3 == 4) {
fprintf(stderr, "Disable FIFO1 on opengl\n");
}
#ifdef OGL_DEBUG
if (theApp.GetConfig("renderer", 0) / 3 == 4) fprintf(stderr, "Disable FIFO1 on opengl\n");
#endif
s_gs->m_wnd.AttachContext();
#endif

s_gs->ReadFIFO(mem, 1);

#ifdef _LINUX
#ifdef OGL_MT_HACK
s_gs->m_wnd.DetachContext();
#endif
}
Expand All @@ -481,21 +485,18 @@ EXPORT_C GSreadFIFO2(uint8* mem, uint32 size)
{
try
{
#ifdef _LINUX
#ifdef OGL_MT_HACK
// FIXME called from EE core thread not MTGS which cause
// invalidate data for opengl
if (theApp.GetConfig("renderer", 0) / 3 == 4) {
#ifdef OGL_DEBUG
fprintf(stderr, "Disable FIFO2(%d) on opengl\n", size);
if (theApp.GetConfig("renderer", 0) / 3 == 4) fprintf(stderr, "Disable FIFO2(%d) on opengl\n", size);
#endif
//return;
}
s_gs->m_wnd.AttachContext();
#endif

s_gs->ReadFIFO(mem, size);

#ifdef _LINUX
#ifdef OGL_MT_HACK
s_gs->m_wnd.DetachContext();
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/GSdx/GSRendererOGL.cpp
Expand Up @@ -205,7 +205,8 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour

vs_sel.tme = PRIM->TME;
vs_sel.fst = PRIM->FST;
vs_sel.logz = dev->HasDepth32() ? 0 : m_logz ? 1 : 0;
//vs_sel.logz = dev->HasDepth32() ? 0 : m_logz ? 1 : 0;
vs_sel.logz = m_logz ? 1 : 0;
//OGL vs_sel.rtcopy = !!rtcopy;
vs_sel.rtcopy = false;

Expand Down
13 changes: 13 additions & 0 deletions plugins/GSdx/GSState.cpp
Expand Up @@ -23,6 +23,13 @@
#include "GSState.h"
#include "GSdx.h"

#ifdef OGL_MT_HACK

#include "GSRendererOGL.h"
extern GSRenderer* s_gs;

#endif

//#define Offset_ST // Fixes Persona3 mini map alignment which is off even in software rendering

GSState::GSState()
Expand Down Expand Up @@ -1252,6 +1259,9 @@ void GSState::GIFRegHandlerTRXDIR(const GIFReg* RESTRICT r)
break;
case 1: // local -> host
m_tr.Init(m_env.TRXPOS.SSAX, m_env.TRXPOS.SSAY);
#ifdef OGL_MT_HACK
s_gs->m_wnd.DetachContext();
#endif
break;
case 2: // local -> local
Move();
Expand Down Expand Up @@ -1756,6 +1766,9 @@ static hash_map<uint64, uint64> s_tags;
template<int index> void GSState::Transfer(const uint8* mem, uint32 size)
{
GSPerfMonAutoTimer pmat(&m_perfmon);
#ifdef OGL_MT_HACK
s_gs->m_wnd.AttachContext();
#endif

const uint8* start = mem;

Expand Down
1 change: 1 addition & 0 deletions plugins/GSdx/GSTextureFXOGL.cpp
Expand Up @@ -86,6 +86,7 @@ void GSDeviceOGL::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
if(i == m_vs.end())
{
std::string macro = format("#define VS_BPPZ %d\n", sel.bppz)
+ format("#define VS_LOGZ %d\n", sel.logz)
+ format("#define VS_TME %d\n", sel.tme)
+ format("#define VS_FST %d\n", sel.fst)
+ format("#define VS_RTCOPY %d\n", sel.rtcopy);
Expand Down
15 changes: 12 additions & 3 deletions plugins/GSdx/GSWnd.cpp
Expand Up @@ -213,7 +213,7 @@ void GSWnd::HideFrame()
#else

GSWnd::GSWnd()
: m_window(NULL), m_Xwindow(0), m_XDisplay(NULL)
: m_window(NULL), m_Xwindow(0), m_XDisplay(NULL), m_ctx_attached(false)
{
}

Expand Down Expand Up @@ -278,16 +278,25 @@ bool GSWnd::CreateContext(int major, int minor)
if (!m_context) return false;

XSync( m_XDisplay, false);
return true;
}

void GSWnd::AttachContext()
{
glXMakeCurrent(m_XDisplay, m_Xwindow, m_context);
if (!IsContextAttached()) {
fprintf(stderr, "Attach the context\n");
glXMakeCurrent(m_XDisplay, m_Xwindow, m_context);
m_ctx_attached = true;
}
}

void GSWnd::DetachContext()
{
glXMakeCurrent(m_XDisplay, None, NULL);
if (IsContextAttached()) {
fprintf(stderr, "Detach the context\n");
glXMakeCurrent(m_XDisplay, None, NULL);
m_ctx_attached = false;
}
}

void GSWnd::CheckContext()
Expand Down
2 changes: 2 additions & 0 deletions plugins/GSdx/GSWnd.h
Expand Up @@ -103,6 +103,7 @@ class GSWnd
Window m_Xwindow;
Display* m_XDisplay;

bool m_ctx_attached;
bool m_managed;
int m_renderer;
GLXContext m_context;
Expand All @@ -115,6 +116,7 @@ class GSWnd
bool Attach(void* handle, bool managed = true);
void Detach();
bool IsManaged() const {return m_managed;}
bool IsContextAttached() const { return m_ctx_attached; }

Display* GetDisplay();
void* GetHandle() {return (void*)m_Xwindow;}
Expand Down
26 changes: 23 additions & 3 deletions plugins/GSdx/linux_replay.cpp
Expand Up @@ -34,8 +34,28 @@ void help()

int main ( int argc, char *argv[] )
{
if ( argc != 3 ) help();
if ( argc == 3) {
GSsetSettingsDir(argv[1]);
GSReplay(argv[2], 12);
} else if ( argc == 2) {
#ifdef XDG_STD
std::string home("HOME");
char * val = getenv( home.c_str() );
if (val == NULL) {
fprintf(stderr, "Failed to get the home dir\n");
help();
}

std::string ini_dir(val);
ini_dir += "/.config/pcsx2/inis";

GSsetSettingsDir(ini_dir.c_str());
GSReplay(argv[1], 12);
#else
fprintf(stderr, "default ini dir only supported on XDG\n");
help();
#endif
} else
help();

GSsetSettingsDir(argv[1]);
GSReplay(argv[2], 12);
}
10 changes: 6 additions & 4 deletions plugins/GSdx/res/tfx.glsl
Expand Up @@ -87,22 +87,24 @@ void vs_main()
// input granularity is 1/16 pixel, anything smaller than that won't step drawing up/left by one pixel
// example: 133.0625 (133 + 1/16) should start from line 134, ceil(133.0625 - 0.05) still above 133

// Greg TEST
//float logz = log2(1+float(z))/32 * 0.999f;
//vec4 p = vec4(i_p, logz, 0) - vec4(0.05f, 0.05f, 0, 0);

vec4 p = vec4(i_p, z, 0) - vec4(0.05f, 0.05f, 0, 0);
vec4 final_p = p * VertexScale - VertexOffset;
// FIXME
// FLIP vertically
final_p.y *= -1.0f;

if(VS_LOGZ == 1)
{
final_p.z = log2(1.0f + float(z)) / 32.0f;
}

VSout.p = final_p;
gl_Position = final_p; // NOTE I don't know if it is possible to merge POSITION_OUT and gl_Position
#if VS_RTCOPY
VSout.tp = final_p * vec4(0.5, -0.5, 0, 0) + 0.5;
#endif


if(VS_TME != 0)
{
if(VS_FST != 0)
Expand Down
11 changes: 11 additions & 0 deletions plugins/zzogl-pg/opengl/ZZGl.h
Expand Up @@ -185,7 +185,18 @@ namespace FB

static __forceinline void Create()
{
assert(buf == 0);
glGenFramebuffersEXT(1, &buf);
if (buf == 0)
ZZLog::Error_Log("Failed to create the renderbuffer.");
}

static __forceinline void Delete()
{
if (buf != 0) {
glDeleteFramebuffers(1, &buf);
buf = 0;
}
}

static __forceinline void Bind()
Expand Down
14 changes: 7 additions & 7 deletions plugins/zzogl-pg/opengl/ZZoglCreate.cpp
Expand Up @@ -496,11 +496,6 @@ bool ZZCreate(int _width, int _height)

FB::Create();

if (FB::buf == 0)
{
ZZLog::Error_Log("Failed to create the renderbuffer.");
}

GL_REPORT_ERRORD();

FB::Bind();
Expand Down Expand Up @@ -803,7 +798,7 @@ bool ZZCreate(int _width, int _height)
}
else
{
ZZLog::Debug_Log("In final init!");
ZZLog::Debug_Log("Error In final init!");
return false;
}
}
Expand Down Expand Up @@ -834,7 +829,10 @@ void ZZDestroy()
}

#ifdef GLSL4_API
delete vertex_array;
if (vertex_array != NULL) {
delete vertex_array;
vertex_array = NULL;
}
#endif

g_nCurVBOIndex = 0;
Expand Down Expand Up @@ -878,6 +876,8 @@ void ZZDestroy()

safe_delete(font_p);

FB::Delete();

GLWin.ReleaseContext();

mapGLExtensions.clear();
Expand Down
23 changes: 23 additions & 0 deletions plugins/zzogl-pg/opengl/ZZoglShaders.h
Expand Up @@ -110,7 +110,9 @@ const ZZshParamInfo qZero = {ShName:"", type:ZZ_UNDEFINED, fvalue:{0}, sampler:
const ZZshShaderLink sZero = {link: NULL, isFragment: false};

inline bool ZZshActiveParameter(ZZshParameter param) {return (param > -1); }
#ifndef GLSL4_API
#define SAFE_RELEASE_PROG(x) { /*don't know what to do*/ }
#endif

// ---------------------------

Expand Down Expand Up @@ -616,7 +618,28 @@ struct VERTEXSHADER
bool IsDualContext(ZZshParameter param) { return false;}

void set_context(uint new_context) { context = new_context * NOCONTEXT;}

void release_prog() {
if(program) {
glDeleteProgram(program);
program = 0;
}
}
};
#endif

#ifdef GLSL4_API
#define SAFE_RELEASE_PROG(x) { \
if ((x.link) != NULL) { \
if (x.isFragment) { \
FRAGMENTSHADER* shader = (FRAGMENTSHADER*)x.link; \
shader->release_prog(); \
} else { \
VERTEXSHADER* shader = (VERTEXSHADER*)x.link; \
shader->release_prog(); \
} \
} \
}
#endif

extern VERTEXSHADER pvsBitBlt;
Expand Down
12 changes: 9 additions & 3 deletions plugins/zzogl-pg/opengl/ZZoglShadersGLSL4.cpp
Expand Up @@ -113,8 +113,6 @@ extern bool s_bWriteDepth;
const char* ShaderCallerName = "";
const char* ShaderHandleName = "";

ZZshProgram CompiledPrograms[MAX_ACTIVE_SHADERS][MAX_ACTIVE_SHADERS] = {{0}};

// new for GLSL4
GSUniformBufferOGL *constant_buffer;
GSUniformBufferOGL *common_buffer;
Expand All @@ -124,7 +122,7 @@ static bool dirty_common_buffer = true;
static bool dirty_vertex_buffer = true;
static bool dirty_fragment_buffer = true;

GSVertexBufferStateOGL *vertex_array;
GSVertexBufferStateOGL *vertex_array = NULL;

COMMONSHADER g_cs;
static GLuint s_pipeline = 0;
Expand Down Expand Up @@ -227,6 +225,14 @@ void ZZshExitCleaning() {
delete vertex_buffer;
delete fragment_buffer;

dirty_fragment_buffer = true;
dirty_vertex_buffer = true;
dirty_common_buffer = true;
g_current_ps = 0;
g_current_vs = 0;
for (uint i = 0; i < 11; i++)
g_current_texture_bind[i] = 0;

glDeleteProgramPipelines(1, &s_pipeline);
}

Expand Down

0 comments on commit 3b22f0f

Please sign in to comment.