Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize double alpha blending for 1/0 textures #6072

Merged
merged 1 commit into from
May 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion GPU/GLES/FragmentShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,14 @@ static bool AlphaToColorDoubling() {
// 2x alpha in the source function and full alpha = source color doubling.
// If we see this, we don't really need to care about the dest alpha function - sure we can't handle
// the doubling dest ones, but there's nothing we can do about that.
return (gstate.getBlendFuncA() == GE_SRCBLEND_DOUBLESRCALPHA) && (gstate_c.vertexFullAlpha && (gstate_c.textureFullAlpha || !gstate.isTextureAlphaUsed()));
if (gstate.getBlendFuncA() != GE_SRCBLEND_DOUBLESRCALPHA) {
return false;
}
if (gstate.getBlendFuncB() == GE_DSTBLEND_INVSRCALPHA) {
// If it's 1.0 or 0.0, then we can still color double (since 0.0 will blend out anyway.)
return (gstate_c.vertexFullAlpha && (gstate_c.textureSimpleAlpha || !gstate.isTextureAlphaUsed()));
}
return (gstate_c.vertexFullAlpha && (gstate_c.textureFullAlpha || !gstate.isTextureAlphaUsed()));
}

static bool CanDoubleSrcBlendMode() {
Expand Down
3 changes: 3 additions & 0 deletions GPU/GLES/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry) {
gstate_c.curTextureHeight = entry->framebuffer->height;
gstate_c.flipTexture = true;
gstate_c.textureFullAlpha = entry->framebuffer->format == GE_FORMAT_565;
gstate_c.textureSimpleAlpha = false;
} else {
if (entry->framebuffer->fbo)
entry->framebuffer->fbo = 0;
Expand Down Expand Up @@ -1071,6 +1072,7 @@ void TextureCache::SetTexture(bool force) {
glBindTexture(GL_TEXTURE_2D, entry->texture);
lastBoundTexture = entry->texture;
gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL;
gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN;
}
UpdateSamplingParams(*entry, false);
VERBOSE_LOG(G3D, "Texture at %08x Found in Cache, applying", texaddr);
Expand Down Expand Up @@ -1303,6 +1305,7 @@ void TextureCache::SetTexture(bool force) {
glPixelStorei(GL_PACK_ALIGNMENT, 1);

gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL;
gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN;
}

GLenum TextureCache::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const {
Expand Down
8 changes: 7 additions & 1 deletion GPU/GPUState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ struct GPUStateCache_v0
};

void GPUStateCache::DoState(PointerWrap &p) {
auto s = p.Section("GPUStateCache", 0, 2);
auto s = p.Section("GPUStateCache", 0, 3);
if (!s) {
// Old state, this was not versioned.
GPUStateCache_v0 old;
Expand Down Expand Up @@ -302,6 +302,12 @@ void GPUStateCache::DoState(PointerWrap &p) {
p.Do(flipTexture);
}

if (s >= 3) {
p.Do(textureSimpleAlpha);
} else {
textureSimpleAlpha = false;
}

if (s < 2) {
float l12[12];
float l4[4];
Expand Down
1 change: 1 addition & 0 deletions GPU/GPUState.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ struct GPUStateCache

u8 textureChanged;
bool textureFullAlpha;
bool textureSimpleAlpha;
bool vertexFullAlpha;
bool framebufChanged;

Expand Down