Skip to content

Commit 6122f40

Browse files
committed
Make the existing ReinterpretFramebuffers/ShaderColorBitmask path work for Split/Second
It took writing and debugging #15500 for me to understand what the issue with the old path was.. Much simpler alternative to #15500, or we could merge both but disable Split/Second for this one. Needs some benchmarks I guess...
1 parent 2178567 commit 6122f40

9 files changed

+36
-16
lines changed

GPU/Common/DrawEngineCommon.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ bool DrawEngineCommon::ApplyFramebufferRead(bool *fboTexNeedsBind) {
501501
lastFrameBlit = gpuStats.numFlips;
502502
}
503503
++blitsThisFrame;
504-
if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME * 2) {
504+
if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME * 4) {
505505
WARN_LOG_ONCE(blendingBlit2, G3D, "Skipping additional blits needed for obscure blending: %d per frame, blend %d/%d/%d", blitsThisFrame, gstate.getBlendFuncA(), gstate.getBlendFuncB(), gstate.getBlendEq());
506506
return false;
507507
}

GPU/Common/GPUStateUtils.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ void ConvertMaskState(GenericMaskState &maskState, bool allowFramebufferRead) {
10331033
}
10341034

10351035
// Called even if AlphaBlendEnable == false - it also deals with stencil-related blend state.
1036-
void ConvertBlendState(GenericBlendState &blendState, bool allowFramebufferRead) {
1036+
void ConvertBlendState(GenericBlendState &blendState, bool allowFramebufferRead, bool forceReplaceBlend) {
10371037
// Blending is a bit complex to emulate. This is due to several reasons:
10381038
//
10391039
// * Doubled blend modes (src, dst, inversed) aren't supported in OpenGL.
@@ -1050,6 +1050,9 @@ void ConvertBlendState(GenericBlendState &blendState, bool allowFramebufferRead)
10501050
blendState.replaceAlphaWithStencil = REPLACE_ALPHA_NO;
10511051

10521052
ReplaceBlendType replaceBlend = ReplaceBlendWithShader(allowFramebufferRead, gstate.FrameBufFormat());
1053+
if (forceReplaceBlend) {
1054+
replaceBlend = REPLACE_BLEND_COPY_FBO;
1055+
}
10531056
ReplaceAlphaType replaceAlphaWithStencil = ReplaceAlphaWithStencil(replaceBlend);
10541057
bool usePreSrc = false;
10551058

GPU/Common/GPUStateUtils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ struct GenericBlendState {
166166
}
167167
};
168168

169-
void ConvertBlendState(GenericBlendState &blendState, bool allowShaderBlend);
169+
void ConvertBlendState(GenericBlendState &blendState, bool allowShaderBlend, bool forceReplaceBlend);
170170
void ApplyStencilReplaceAndLogicOpIgnoreBlend(ReplaceAlphaType replaceAlphaWithStencil, GenericBlendState &blendState);
171171

172172
struct GenericMaskState {

GPU/Common/ShaderId.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ void ComputeFragmentShaderID(FShaderID *id_out, const Draw::Bugs &bugs) {
253253
// Note how we here recompute some of the work already done in state mapping.
254254
// Not ideal! At least we share the code.
255255
ReplaceBlendType replaceBlend = ReplaceBlendWithShader(gstate_c.allowFramebufferRead, gstate.FrameBufFormat());
256+
if (colorWriteMask) {
257+
replaceBlend = REPLACE_BLEND_COPY_FBO;
258+
}
256259
ReplaceAlphaType stencilToAlpha = ReplaceAlphaWithStencil(replaceBlend);
257260

258261
// All texfuncs except replace are the same for RGB as for RGBA with full alpha.

GPU/D3D11/StateMappingD3D11.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,14 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
155155
keys_.blend.colorWriteMask = (colorMask ? (1 | 2 | 4) : 0) | (alphaMask ? 8 : 0);
156156
} else {
157157
keys_.blend.value = 0;
158-
// Set blend - unless we need to do it in the shader.
159-
GenericBlendState blendState;
160-
ConvertBlendState(blendState, gstate_c.allowFramebufferRead);
161158

162159
GenericMaskState maskState;
163160
ConvertMaskState(maskState, gstate_c.allowFramebufferRead);
164161

162+
// Set blend - unless we need to do it in the shader.
163+
GenericBlendState blendState;
164+
ConvertBlendState(blendState, gstate_c.allowFramebufferRead, maskState.applyFramebufferRead);
165+
165166
if (blendState.applyFramebufferRead || maskState.applyFramebufferRead) {
166167
if (ApplyFramebufferRead(&fboTexNeedsBind_)) {
167168
// The shader takes over the responsibility for blending, so recompute.

GPU/Directx9/StateMappingDX9.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ void DrawEngineDX9::ApplyDrawState(int prim) {
125125
bool alphaMask = gstate.isClearModeAlphaMask();
126126
dxstate.colorMask.set(colorMask, colorMask, colorMask, alphaMask);
127127
} else {
128-
// Set blend - unless we need to do it in the shader.
129-
GenericBlendState blendState;
130-
ConvertBlendState(blendState, gstate_c.allowFramebufferRead);
131-
132128
GenericMaskState maskState;
133129
ConvertMaskState(maskState, gstate_c.allowFramebufferRead);
134130

131+
// Set blend - unless we need to do it in the shader.
132+
GenericBlendState blendState;
133+
ConvertBlendState(blendState, gstate_c.allowFramebufferRead, maskState.applyFramebufferRead);
134+
135135
if (blendState.applyFramebufferRead || maskState.applyFramebufferRead) {
136136
if (ApplyFramebufferRead(&fboTexNeedsBind_)) {
137137
// The shader takes over the responsibility for blending, so recompute.

GPU/GLES/StateMappingGLES.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ void DrawEngineGLES::ApplyDrawState(int prim) {
155155
} else {
156156
// Do the large chunks of state conversion. We might be able to hide these two behind a dirty-flag each,
157157
// to avoid recomputing heavy stuff unnecessarily every draw call.
158-
GenericBlendState blendState;
159-
ConvertBlendState(blendState, gstate_c.allowFramebufferRead);
160158

161159
GenericMaskState maskState;
162160
ConvertMaskState(maskState, gstate_c.allowFramebufferRead);
163161

162+
GenericBlendState blendState;
163+
ConvertBlendState(blendState, gstate_c.allowFramebufferRead, maskState.applyFramebufferRead);
164+
164165
if (blendState.applyFramebufferRead || maskState.applyFramebufferRead) {
165166
if (ApplyFramebufferRead(&fboTexNeedsBind_)) {
166167
// The shader takes over the responsibility for blending, so recompute.

GPU/Vulkan/StateMappingVulkan.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
161161
key.logicOp = VK_LOGIC_OP_CLEAR;
162162
}
163163

164-
// Set blend - unless we need to do it in the shader.
165-
GenericBlendState blendState;
166-
ConvertBlendState(blendState, gstate_c.allowFramebufferRead);
167-
168164
GenericMaskState maskState;
169165
ConvertMaskState(maskState, gstate_c.allowFramebufferRead);
170166

167+
// Set blend - unless we need to do it in the shader.
168+
GenericBlendState blendState;
169+
ConvertBlendState(blendState, gstate_c.allowFramebufferRead, maskState.applyFramebufferRead);
170+
171171
if (blendState.applyFramebufferRead || maskState.applyFramebufferRead) {
172172
if (ApplyFramebufferRead(&fboTexNeedsBind_)) {
173173
// The shader takes over the responsibility for blending, so recompute.

assets/compat.ini

+12
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,12 @@ ULES01441 = true
10251025
ULJM05600 = true
10261026
ULJM05775 = true
10271027

1028+
# Split Second
1029+
ULES01402 = true
1030+
ULUS10513 = true
1031+
ULJM05812 = true
1032+
NPJH50371 = true
1033+
10281034
[ShaderColorBitmask]
10291035
# Outrun 2006: Coast to Coast - issue #11358
10301036
ULES00262 = true
@@ -1037,6 +1043,12 @@ ULJM05533 = true
10371043
NPJH50006 = true
10381044
ULES01301 = true
10391045

1046+
# Split Second
1047+
ULES01402 = true
1048+
ULUS10513 = true
1049+
ULJM05812 = true
1050+
NPJH50371 = true
1051+
10401052
[DisableFirstFrameReadback]
10411053
# Wipeout Pure: Temporary workaround for lens flare flicker. See #13344
10421054
UCUS98612 = true

0 commit comments

Comments
 (0)