Skip to content

Commit

Permalink
gsdx-ogl: only compile useful VS
Browse files Browse the repository at this point in the history
logz is a constant
wildhack is only compatbile with TME/FST

Compilation goes down from 64 to 20 vertex shaders.
  • Loading branch information
gregory38 committed Apr 20, 2015
1 parent 16e6d0d commit 6124eb8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions plugins/GSdx/GSDeviceOGL.cpp
Expand Up @@ -653,10 +653,10 @@ void GSDeviceOGL::Barrier(GLbitfield b)
}

/* Note: must be here because tfx_glsl is static */
GLuint GSDeviceOGL::CompileVS(VSSelector sel)
GLuint GSDeviceOGL::CompileVS(VSSelector sel, int logz)
{
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", logz)
+ format("#define VS_TME %d\n", sel.tme)
+ format("#define VS_FST %d\n", sel.fst)
+ format("#define VS_WILDHACK %d\n", sel.wildhack)
Expand Down
7 changes: 3 additions & 4 deletions plugins/GSdx/GSDeviceOGL.h
Expand Up @@ -275,7 +275,6 @@ class GSDeviceOGL : public GSDevice
{
uint32 wildhack:1;
uint32 bppz:2;
uint32 logz:1;
// Next param will be handle by subroutine
uint32 tme:1;
uint32 fst:1;
Expand All @@ -284,12 +283,12 @@ class GSDeviceOGL : public GSDevice
uint32 key;
};

operator uint32() {return key & 0x7f;}
operator uint32() {return key & 0x3f;}

VSSelector() : key(0) {}
VSSelector(uint32 k) : key(k) {}

static uint32 size() { return 1 << 6; }
static uint32 size() { return 1 << 5; }
};

__aligned(struct, 32) PSConstantBuffer
Expand Down Expand Up @@ -612,7 +611,7 @@ class GSDeviceOGL : public GSDevice
void OMSetWriteBuffer(GLenum buffer = GL_COLOR_ATTACHMENT0);

void CreateTextureFX();
GLuint CompileVS(VSSelector sel);
GLuint CompileVS(VSSelector sel, int logz);
GLuint CompileGS();
GLuint CompilePS(PSSelector sel);
GLuint CreateSampler(bool bilinear, bool tau, bool tav);
Expand Down
2 changes: 0 additions & 2 deletions plugins/GSdx/GSRendererOGL.cpp
Expand Up @@ -27,7 +27,6 @@
GSRendererOGL::GSRendererOGL()
: GSRendererHW(new GSTextureCacheOGL(this))
{
m_logz = !!theApp.GetConfig("logz", 1);
m_fba = !!theApp.GetConfig("fba", 1);
UserHacks_AlphaHack = !!theApp.GetConfig("UserHacks_AlphaHack", 0) && !!theApp.GetConfig("UserHacks", 0);
UserHacks_AlphaStencil = !!theApp.GetConfig("UserHacks_AlphaStencil", 0) && !!theApp.GetConfig("UserHacks", 0);
Expand Down Expand Up @@ -262,7 +261,6 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour

vs_sel.tme = PRIM->TME;
vs_sel.fst = PRIM->FST;
vs_sel.logz = m_logz ? 1 : 0;
vs_sel.wildhack = (UserHacks_WildHack && !isPackedUV_HackFlag) ? 1 : 0;

// The real GS appears to do no masking based on the Z buffer format and writing larger Z values
Expand Down
1 change: 0 additions & 1 deletion plugins/GSdx/GSRendererOGL.h
Expand Up @@ -35,7 +35,6 @@ class GSRendererOGL : public GSRendererHW
{
private:
GSVector2 m_pixelcenter;
bool m_logz;
bool m_fba;
bool UserHacks_AlphaHack;
bool UserHacks_AlphaStencil;
Expand Down
2 changes: 1 addition & 1 deletion plugins/GSdx/GSShaderOGL.cpp
Expand Up @@ -263,7 +263,7 @@ void GSShaderOGL::UseProgram()
hash_map<uint64, GLuint >::iterator it;
// Note: shader are integer lookup pointer. They start from 1 and incr
// every time you create a new shader OR a new program.
// Note2: vs & gs are precompiled at startup. FGLRX and radeon got value < 128.
// Note2: vs & gs are precompiled at startup. FGLRX and radeon got value < 128. GS has only 2 programs
// We migth be able to pack the value in a 32bits int
// I would need to check the behavior on Nvidia (pause/resume).
uint64 sel = (uint64)GLState::vs << 40 | (uint64)GLState::gs << 20 | GLState::ps;
Expand Down
11 changes: 9 additions & 2 deletions plugins/GSdx/GSTextureFXOGL.cpp
Expand Up @@ -39,8 +39,15 @@ void GSDeviceOGL::CreateTextureFX()
// It might cost a seconds at startup but it would reduce benchmark pollution
m_gs = CompileGS();

for (uint32 key = 0; key < VSSelector::size(); key++)
m_vs[key] = CompileVS(VSSelector(key));
int logz = theApp.GetConfig("logz", 1);
for (uint32 key = 0; key < VSSelector::size(); key++) {
// wildhack is only useful if both TME and FST are enabled.
VSSelector sel(key);
if (sel.wildhack && (!sel.tme || !sel.fst))
m_vs[key] = 0;
else
m_vs[key] = CompileVS(sel, logz);
}

for (uint32 key = 0; key < OMDepthStencilSelector::size(); key++)
m_om_dss[key] = CreateDepthStencil(OMDepthStencilSelector(key));
Expand Down

0 comments on commit 6124eb8

Please sign in to comment.