Merge pull request #6202 from unknownbrackets/gpu-minor

Decimate in clut stuff, adjustments to IsReallyAClear()
This commit is contained in:
Henrik Rydgård 2014-06-01 09:53:52 +02:00
commit 410fc713a4
10 changed files with 55 additions and 41 deletions

View file

@ -24,6 +24,8 @@
#include "GPU/GPUState.h"
#include "GPU/GLES/TextureCache.h"
static const int DEPAL_TEXTURE_OLD_AGE = 120;
#ifdef _WIN32
#define SHADERLOG
#endif
@ -95,7 +97,7 @@ DepalShaderCache::DepalShaderCache() {
glShaderSource(vertexShader_, 1, useGL3_ ? &depalVShader300 : &depalVShader100, 0);
glCompileShader(vertexShader_);
if (CheckShaderCompileSuccess(vertexShader_, depalVShader100)) {
if (!CheckShaderCompileSuccess(vertexShader_, useGL3_ ? depalVShader300 : depalVShader100)) {
// ...
}
}
@ -322,6 +324,7 @@ GLuint DepalShaderCache::GetClutTexture(const u32 clutID, u32 *rawClut) {
auto oldtex = texCache_.find(realClutID);
if (oldtex != texCache_.end()) {
oldtex->second->lastFrame = gpuStats.numFlips;
return oldtex->second->texture;
}
@ -348,6 +351,7 @@ GLuint DepalShaderCache::GetClutTexture(const u32 clutID, u32 *rawClut) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
tex->lastFrame = gpuStats.numFlips;
texCache_[realClutID] = tex;
return tex->texture;
}
@ -367,7 +371,15 @@ void DepalShaderCache::Clear() {
}
void DepalShaderCache::Decimate() {
// TODO
for (auto tex = texCache_.begin(); tex != texCache_.end(); ) {
if (tex->second->lastFrame + DEPAL_TEXTURE_OLD_AGE < gpuStats.numFlips) {
glDeleteTextures(1, &tex->second->texture);
delete tex->second;
texCache_.erase(tex++);
} else {
++tex;
}
}
}
GLuint DepalShaderCache::GetDepalettizeShader(GEBufferFormat pixelFormat) {

View file

@ -30,6 +30,7 @@ public:
class DepalTexture {
public:
GLuint texture;
int lastFrame;
};
// Caches both shaders and palette textures.

View file

@ -202,7 +202,6 @@ StencilValueType ReplaceAlphaWithStencilType() {
return STENCIL_VALUE_KEEP;
}
// Decrementing always zeros, since there's only one bit.
case GE_STENCILOP_DECR:
case GE_STENCILOP_INCR:
case GE_STENCILOP_INVERT:

View file

@ -521,6 +521,8 @@ void FramebufferManager::DrawPlainColor(u32 color) {
((color & 0xFF000000) >> 24) / 255.0f,
};
shaderManager_->DirtyLastShader();
glsl_bind(program);
glUniform4fv(plainColorLoc_, 1, col);
glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -588,6 +590,8 @@ void FramebufferManager::DrawActiveTexture(GLuint texture, float x, float y, flo
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
shaderManager_->DirtyLastShader(); // dirty lastShader_
glsl_bind(program);
if (program == postShaderProgram_ && timeLoc_ != -1) {
int flipCount = __DisplayGetFlipCount();
@ -606,8 +610,6 @@ void FramebufferManager::DrawActiveTexture(GLuint texture, float x, float y, flo
glDisableVertexAttribArray(program->a_texcoord0);
glsl_unbind();
shaderManager_->DirtyLastShader(); // dirty lastShader_
}

View file

@ -411,6 +411,7 @@ GLES_GPU::GLES_GPU()
framebufferManager_.SetShaderManager(shaderManager_);
textureCache_.SetFramebufferManager(&framebufferManager_);
textureCache_.SetDepalShaderCache(&depalShaderCache_);
textureCache_.SetShaderManager(shaderManager_);
// Sanity check gstate
if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) {
@ -545,6 +546,7 @@ void GLES_GPU::BeginFrameInternal() {
textureCache_.StartFrame();
transformDraw_.DecimateTrackedVertexArrays();
depalShaderCache_.Decimate();
if (dumpNextFrame_) {
NOTICE_LOG(G3D, "DUMPING THIS FRAME");

View file

@ -684,11 +684,10 @@ Shader *ShaderManager::ApplyVertexShader(int prim, u32 vertType) {
LinkedShader *ShaderManager::ApplyFragmentShader(Shader *vs, int prim, u32 vertType) {
FragmentShaderID FSID;
ComputeFragmentShaderID(&FSID);
if (lastVShaderSame_ && FSID == lastFSID_ && !gstate_c.shaderChanged) {
if (lastVShaderSame_ && FSID == lastFSID_) {
lastShader_->UpdateUniforms(vertType);
return lastShader_;
}
gstate_c.shaderChanged = false;
lastFSID_ = FSID;

View file

@ -23,6 +23,7 @@
#include "GPU/Math3D.h"
#include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/TransformCommon.h"
#include "GPU/GLES/Framebuffer.h"
#include "GPU/GLES/ShaderManager.h"
#include "GPU/GLES/TransformPipeline.h"
@ -88,8 +89,7 @@ bool TransformDrawEngine::IsReallyAClear(int numVerts) const {
if (transformed[0].x != 0.0f || transformed[0].y != 0.0f)
return false;
u32 matchcolor;
memcpy(&matchcolor, transformed[0].color0, 4);
u32 matchcolor = transformed[0].color0_32;
float matchz = transformed[0].z;
int bufW = gstate_c.curRTWidth;
@ -97,9 +97,7 @@ bool TransformDrawEngine::IsReallyAClear(int numVerts) const {
float prevX = 0.0f;
for (int i = 1; i < numVerts; i++) {
u32 vcolor;
memcpy(&vcolor, transformed[i].color0, 4);
if (vcolor != matchcolor || transformed[i].z != matchz)
if (transformed[i].color0_32 != matchcolor || transformed[i].z != matchz)
return false;
if ((i & 1) == 0) {
@ -385,9 +383,8 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
//
// An alternative option is to simply ditch all the verts except the first and last to create a single
// rectangle out of many. Quite a small optimization though.
if (false && maxIndex > 1 && gstate.isModeClear() && prim == GE_PRIM_RECTANGLES && IsReallyAClear(maxIndex)) {
u32 clearColor;
memcpy(&clearColor, transformed[0].color0, 4);
if (maxIndex > 1 && gstate.isModeClear() && prim == GE_PRIM_RECTANGLES && IsReallyAClear(maxIndex)) {
u32 clearColor = transformed[0].color0_32;
float clearDepth = transformed[0].z;
const float col[4] = {
((clearColor & 0xFF)) / 255.0f,
@ -398,22 +395,17 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
bool colorMask = gstate.isClearModeColorMask();
bool alphaMask = gstate.isClearModeAlphaMask();
glstate.colorMask.set(colorMask, colorMask, colorMask, alphaMask);
if (alphaMask) {
glstate.stencilTest.set(true);
// Clear stencil
// TODO: extract the stencilValue properly, see below
int stencilValue = 0;
glstate.stencilFunc.set(GL_ALWAYS, stencilValue, 255);
} else {
// Don't touch stencil
glstate.stencilTest.set(false);
}
glstate.scissorTest.set(false);
bool depthMask = gstate.isClearModeDepthMask();
if (depthMask) {
framebufferManager_->SetDepthUpdated();
}
int target = 0;
if (colorMask || alphaMask) target |= GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
glstate.stencilTest.set(false);
glstate.scissorTest.set(false);
GLbitfield target = 0;
if (colorMask || alphaMask) target |= GL_COLOR_BUFFER_BIT;
if (alphaMask) target |= GL_STENCIL_BUFFER_BIT;
if (depthMask) target |= GL_DEPTH_BUFFER_BIT;
glClearColor(col[0], col[1], col[2], col[3]);
@ -422,7 +414,8 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
#else
glClearDepth(clearDepth);
#endif
glClearStencil(0); // TODO - take from alpha?
// Stencil takes alpha.
glClearStencil(clearColor >> 24);
glClear(target);
return;
}

View file

@ -28,6 +28,7 @@
#include "GPU/GLES/Framebuffer.h"
#include "GPU/GLES/FragmentShaderGenerator.h"
#include "GPU/GLES/DepalettizeShader.h"
#include "GPU/GLES/ShaderManager.h"
#include "GPU/Common/TextureDecoder.h"
#include "Core/Config.h"
#include "Core/Host.h"
@ -916,13 +917,17 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry) {
};
static const GLubyte indices[4] = { 0, 1, 3, 2 };
shaderManager_->DirtyLastShader();
glUseProgram(program);
gstate_c.shaderChanged = true;
GLint a_position = glGetAttribLocation(program, "a_position");
GLint a_texcoord0 = glGetAttribLocation(program, "a_texcoord0");
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(a_position);
glEnableVertexAttribArray(a_texcoord0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, clutTexture);
@ -944,14 +949,12 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry) {
#endif
glViewport(0, 0, entry->framebuffer->renderWidth, entry->framebuffer->renderHeight);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 12, pos);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 8, uv);
glVertexAttribPointer(a_position, 3, GL_FLOAT, GL_FALSE, 12, pos);
glVertexAttribPointer(a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, uv);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
glDisableVertexAttribArray(a_position);
glDisableVertexAttribArray(a_texcoord0);
/*
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
*/
fbo_bind_color_as_texture(entry->depalFBO, 0);
glstate.Restore();
framebufferManager_->RebindFramebuffer();

View file

@ -28,6 +28,7 @@
struct VirtualFramebuffer;
class FramebufferManager;
class DepalShaderCache;
class ShaderManager;
enum TextureFiltering {
AUTO = 1,
@ -74,6 +75,9 @@ public:
void SetDepalShaderCache(DepalShaderCache *dpCache) {
depalShaderCache_ = dpCache;
}
void SetShaderManager(ShaderManager *sm) {
shaderManager_ = sm;
}
size_t NumLoadedTextures() const {
return cache.size();
@ -203,6 +207,7 @@ private:
int decimationCounter_;
FramebufferManager *framebufferManager_;
DepalShaderCache *depalShaderCache_;
ShaderManager *shaderManager_;
};
GLenum getClutDestFormat(GEPaletteFormat format);

View file

@ -453,8 +453,6 @@ struct GPUStateCache
bool textureSimpleAlpha;
bool vertexFullAlpha;
bool framebufChanged;
// Doesn't need savestating.
bool shaderChanged;
int skipDrawReason;