Merge pull request #15915 from unknownbrackets/gpu-minor

GPU: Add a way to defer dirty rechecks
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2022-08-28 18:10:02 +02:00
commit e87b1c9ba8
9 files changed
+77 -42

No files matched your search

+3
View File
@@ -189,6 +189,9 @@ protected:
bool fboTexNeedsBind_ = false;
bool fboTexBound_ = false;
// Sometimes, unusual situations mean we need to reset dirty flags after state calc finishes.
uint64_t dirtyRequiresRecheck_ = 0;
// Hardware tessellation
TessellationDataTransfer *tessDataTransfer;
};
+36 -21
View File
@@ -202,25 +202,40 @@ void ConvertStencilFuncState(GenericStencilFuncState &stencilFuncState);
// See issue #15898
inline bool SpongebobDepthInverseConditions(const GenericStencilFuncState &stencilState) {
// Check that the depth/stencil state matches the conditions exactly
return gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() &&
gstate.getDepthTestFunction() == GE_COMP_GEQUAL &&
stencilState.zFail == GE_STENCILOP_ZERO && stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP &&
stencilState.testFunc == GE_COMP_ALWAYS && stencilState.writeMask == 0xFF &&
// And also verify no color is written. The game does this through simple alpha blending with a constant zero alpha.
// We also check for color mask, since it's more natural, in case another game does it.
((gstate.isAlphaBlendEnabled() &&
!gstate.isTextureMapEnabled() &&
gstate.getBlendFuncA() == GE_SRCBLEND_SRCALPHA &&
gstate.getBlendFuncB() == GE_DSTBLEND_INVSRCALPHA &&
(
( // Spongebob
gstate.getMaterialAmbientA() == 0x0 && // our accessor is kinda misnamed here, but material diffuse A is both used as default color and as ambient alpha
gstate.getMaterialUpdate() == 0
) ||
( // MX vs ATV : Reflex
gstate.getMaterialUpdate() == 1 // Really should also check vertex data, since that's where the zero is :(
)
)
) || gstate.getColorMask() == 0xFFFFFF00); // note that PSP masks are "inverted"
// Check that the depth/stencil state matches the conditions exactly.
// Always with a depth test that's not writing to the depth buffer (only stencil.)
if (!gstate.isDepthTestEnabled() || gstate.isDepthWriteEnabled())
return false;
// Always GREATER_EQUAL, which we flip to LESS.
if (gstate.getDepthTestFunction() != GE_COMP_GEQUAL)
return false;
// The whole purpose here is a depth fail that we need to write to alpha.
if (stencilState.zFail != GE_STENCILOP_ZERO || stencilState.sFail != GE_STENCILOP_KEEP || stencilState.zPass != GE_STENCILOP_KEEP)
return false;
if (stencilState.testFunc != GE_COMP_ALWAYS || stencilState.writeMask != 0xFF)
return false;
// Lastly, verify no color is written. Natural way is a mask, in case another game uses it.
// Note that the PSP masks are reversed compared to typical APIs.
if (gstate.getColorMask() == 0xFFFFFF00)
return true;
// These games specifically use simple alpha blending with a constant zero alpha.
if (!gstate.isAlphaBlendEnabled() || gstate.getBlendFuncA() != GE_SRCBLEND_SRCALPHA || gstate.getBlendFuncB() != GE_DSTBLEND_INVSRCALPHA)
return false;
// Also make sure there's no texture, in case its alpha gets involved.
if (gstate.isTextureMapEnabled())
return false;
// Spongebob uses material alpha.
if (gstate.getMaterialAmbientA() == 0x00 && gstate.getMaterialUpdate() == 0)
return true;
// MX vs ATV : Reflex uses vertex colors, should really check them...
if (gstate.getMaterialUpdate() == 1)
return true;
// Okay, color is most likely being used if we didn't hit the above.
return false;
}
+1 -1
View File
@@ -191,7 +191,7 @@ Draw2DPipeline *TextureShaderCache::GetDepalettizeShader(uint32_t clutMode, GETe
using namespace Draw;
// Generate an ID for depal shaders.
u64 id = (depthUpperBits << 32) | (clutMode & 0xFFFFFF) | (textureFormat << 24) | (bufferFormat << 28);
u64 id = ((u64)depthUpperBits << 32) | (clutMode & 0xFFFFFF) | (textureFormat << 24) | (bufferFormat << 28);
auto shader = depalCache_.find(id);
if (shader != depalCache_.end()) {
+8 -6
View File
@@ -174,12 +174,15 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
framebufferManager_->RebindFramebuffer("RebindFramebuffer - ApplyDrawState");
// Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects.
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE;
gstate_c.Dirty(DIRTY_BLEND_STATE);
}
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
} else if (blendState.resetFramebufferRead) {
ResetFramebufferRead();
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
}
@@ -193,6 +196,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
keys_.blend.destColor = d3d11BlendFactorLookup[(size_t)blendState.dstColor];
keys_.blend.destAlpha = d3d11BlendFactorLookup[(size_t)blendState.dstAlpha];
if (blendState.dirtyShaderBlendFixValues) {
dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND;
gstate_c.Dirty(DIRTY_SHADERBLEND);
}
dynState_.useBlendColor = blendState.useBlendColor;
@@ -315,8 +319,8 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
keys_.depthStencil.stencilFailOp = D3D11_STENCIL_OP_ZERO;
keys_.depthStencil.stencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
// TODO: Need to set in a way that carries over to the next draw..
gstate_c.Dirty(DIRTY_BLEND_STATE);
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE;
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE);
}
} else {
keys_.depthStencil.stencilTestEnable = false;
@@ -464,8 +468,6 @@ void DrawEngineD3D11::ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRe
context_->OMSetDepthStencilState(depthStencilState_, applyStencilRef ? stencilRef : dynState_.stencilRef);
}
gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_BLEND_STATE);
// Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects.
if (fboTexBound_)
gstate_c.Dirty(DIRTY_BLEND_STATE);
gstate_c.Dirty(dirtyRequiresRecheck_);
dirtyRequiresRecheck_ = 0;
}
+7 -2
View File
@@ -153,9 +153,11 @@ void DrawEngineDX9::ApplyDrawState(int prim) {
device_->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
fboTexBound_ = true;
fboTexNeedsBind_ = false;
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE;
gstate_c.Dirty(DIRTY_BLEND_STATE);
}
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
} else if (blendState.resetFramebufferRead) {
ResetFramebufferRead();
@@ -169,6 +171,7 @@ void DrawEngineDX9::ApplyDrawState(int prim) {
dxBlendFactorLookup[(size_t)blendState.srcColor], dxBlendFactorLookup[(size_t)blendState.dstColor],
dxBlendFactorLookup[(size_t)blendState.srcAlpha], dxBlendFactorLookup[(size_t)blendState.dstAlpha]);
if (blendState.dirtyShaderBlendFixValues) {
dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND;
gstate_c.Dirty(DIRTY_SHADERBLEND);
}
if (blendState.useBlendColor) {
@@ -262,8 +265,8 @@ void DrawEngineDX9::ApplyDrawState(int prim) {
// Invert
dxstate.stencilOp.set(D3DSTENCILOP_ZERO, D3DSTENCILOP_KEEP, D3DSTENCILOP_ZERO);
// TODO: Need to set in a way that carries over to the next draw..
gstate_c.Dirty(DIRTY_BLEND_STATE);
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE;
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE);
}
} else {
dxstate.stencilTest.disable();
@@ -289,6 +292,8 @@ void DrawEngineDX9::ApplyDrawState(int prim) {
}
gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_BLEND_STATE);
gstate_c.Dirty(dirtyRequiresRecheck_);
dirtyRequiresRecheck_ = 0;
}
void DrawEngineDX9::ApplyDrawStateLate() {
+9 -2
View File
@@ -141,6 +141,7 @@ void DrawEngineGLES::ApplyDrawState(int prim) {
// Start profiling here to skip SetTexture which is already accounted for
PROFILE_THIS_SCOPE("applydrawstate");
uint64_t dirtyRequiresRecheck_ = 0;
bool useBufferedRendering = framebufferManager_->UseBufferedRendering();
if (gstate_c.IsDirty(DIRTY_BLEND_STATE)) {
@@ -177,17 +178,21 @@ void DrawEngineGLES::ApplyDrawState(int prim) {
framebufferManager_->RebindFramebuffer("RebindFramebuffer - ApplyDrawState");
// Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects.
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE;
gstate_c.Dirty(DIRTY_BLEND_STATE);
}
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
} else if (blendState.resetFramebufferRead) {
ResetFramebufferRead();
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
}
if (blendState.enabled) {
if (blendState.dirtyShaderBlendFixValues) {
// Not quite sure how necessary this is.
dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND;
gstate_c.Dirty(DIRTY_SHADERBLEND);
}
if (blendState.useBlendColor) {
@@ -269,8 +274,8 @@ void DrawEngineGLES::ApplyDrawState(int prim) {
renderManager->SetStencilFunc(true, GL_ALWAYS, 0xFF, 0xFF);
renderManager->SetStencilOp(0xFF, GL_ZERO, GL_KEEP, GL_ZERO);
// TODO: Need to set in a way that carries over to the next draw..
gstate_c.Dirty(DIRTY_BLEND_STATE);
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE;
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE);
}
} else {
renderManager->SetStencilDisabled();
@@ -293,6 +298,8 @@ void DrawEngineGLES::ApplyDrawState(int prim) {
}
gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_BLEND_STATE);
gstate_c.Dirty(dirtyRequiresRecheck_);
dirtyRequiresRecheck_ = 0;
}
void DrawEngineGLES::ApplyDrawStateLate(bool setStencilValue, int stencilValue) {
+4 -8
View File
@@ -796,11 +796,9 @@ void DrawEngineVulkan::DoFlush() {
}
ApplyDrawStateLate(renderManager, false, 0, pipeline->UsesBlendConstant());
gstate_c.Clean(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
gstate_c.Dirty(dirtyRequiresRecheck_);
dirtyRequiresRecheck_ = 0;
lastPipeline_ = pipeline;
// Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects.
if (fboTexBound_)
gstate_c.Dirty(DIRTY_BLEND_STATE);
}
lastPrim_ = prim;
@@ -928,11 +926,9 @@ void DrawEngineVulkan::DoFlush() {
}
ApplyDrawStateLate(renderManager, result.setStencil, result.stencilValue, pipeline->UsesBlendConstant());
gstate_c.Clean(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
gstate_c.Dirty(dirtyRequiresRecheck_);
dirtyRequiresRecheck_ = 0;
lastPipeline_ = pipeline;
// Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects.
if (fboTexBound_)
gstate_c.Dirty(DIRTY_BLEND_STATE);
}
lastPrim_ = prim;
+8 -2
View File
@@ -173,9 +173,11 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
ApplyFramebufferRead(&fboTexNeedsBind_);
// The shader takes over the responsibility for blending, so recompute.
ApplyStencilReplaceAndLogicOpIgnoreBlend(blendState.replaceAlphaWithStencil, blendState);
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
} else if (blendState.resetFramebufferRead) {
ResetFramebufferRead();
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
}
@@ -188,6 +190,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
key.destColor = vkBlendFactorLookup[(size_t)blendState.dstColor];
key.destAlpha = vkBlendFactorLookup[(size_t)blendState.dstAlpha];
if (blendState.dirtyShaderBlendFixValues) {
dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND;
gstate_c.Dirty(DIRTY_SHADERBLEND);
}
dynState.useBlendColor = blendState.useBlendColor;
@@ -322,8 +325,8 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
key.stencilFailOp = VK_STENCIL_OP_ZERO;
key.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
// TODO: Need to set in a way that carries over to the next draw..
gstate_c.Dirty(DIRTY_BLEND_STATE);
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE;
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE);
}
} else {
key.stencilTestEnable = false;
@@ -375,6 +378,9 @@ void DrawEngineVulkan::BindShaderBlendTex() {
boundSecondary_ = (VkImageView)draw_->GetNativeObject(Draw::NativeObject::BOUND_TEXTURE1_IMAGEVIEW);
fboTexBound_ = true;
fboTexNeedsBind_ = false;
// Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects.
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE;
}
}
}
+1
View File
@@ -1,3 +1,4 @@
#include <algorithm>
#include <sstream>
#include "UI/OnScreenDisplay.h"