From 08d173ceee56ba2bb093a66546e5fcd9c82032b5 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Fri, 17 Feb 2017 12:21:27 +0100 Subject: [PATCH] Unify ApplyShaderBlending --- GPU/Common/DrawEngineCommon.cpp | 28 ++++++++++++++++++++++++++++ GPU/Common/DrawEngineCommon.h | 1 + GPU/D3D11/DrawEngineD3D11.h | 1 - GPU/D3D11/StateMappingD3D11.cpp | 24 ------------------------ GPU/Directx9/DrawEngineDX9.h | 1 - GPU/Directx9/StateMappingDX9.cpp | 28 ---------------------------- GPU/GLES/DrawEngineGLES.h | 1 - GPU/GLES/StateMappingGLES.cpp | 28 ---------------------------- GPU/Vulkan/DrawEngineVulkan.h | 3 +++ GPU/Vulkan/StateMappingVulkan.cpp | 7 ++----- 10 files changed, 34 insertions(+), 88 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 0a87e98b0a..370662b931 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -466,3 +466,31 @@ u32 DrawEngineCommon::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, // Okay, there we are! Return the new type (but keep the index bits) return GE_VTYPE_TC_FLOAT | GE_VTYPE_COL_8888 | GE_VTYPE_NRM_FLOAT | GE_VTYPE_POS_FLOAT | (vertType & (GE_VTYPE_IDX_MASK | GE_VTYPE_THROUGH)); } + +bool DrawEngineCommon::ApplyShaderBlending() { + if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) { + return true; + } + + static const int MAX_REASONABLE_BLITS_PER_FRAME = 24; + + static int lastFrameBlit = -1; + static int blitsThisFrame = 0; + if (lastFrameBlit != gpuStats.numFlips) { + if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME) { + WARN_LOG_REPORT_ONCE(blendingBlit, G3D, "Lots of blits needed for obscure blending: %d per frame, blend %d/%d/%d", blitsThisFrame, gstate.getBlendFuncA(), gstate.getBlendFuncB(), gstate.getBlendEq()); + } + blitsThisFrame = 0; + lastFrameBlit = gpuStats.numFlips; + } + ++blitsThisFrame; + if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME * 2) { + 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()); + return false; + } + + fboTexNeedBind_ = true; + + gstate_c.Dirty(DIRTY_SHADERBLEND); + return true; +} diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 285f32e074..f9c0440eca 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -63,6 +63,7 @@ protected: u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType); void ApplyClearToMemory(int x1, int y1, int x2, int y2, u32 clearColor); + bool ApplyShaderBlending(); VertexDecoder *GetVertexDecoder(u32 vtype); diff --git a/GPU/D3D11/DrawEngineD3D11.h b/GPU/D3D11/DrawEngineD3D11.h index 1827f49d69..4a94a307df 100644 --- a/GPU/D3D11/DrawEngineD3D11.h +++ b/GPU/D3D11/DrawEngineD3D11.h @@ -162,7 +162,6 @@ private: void ApplyDrawState(int prim); void ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef); - bool ApplyShaderBlending(); void ResetShaderBlending(); ID3D11InputLayout *SetupDecFmtForDraw(D3D11VertexShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt); diff --git a/GPU/D3D11/StateMappingD3D11.cpp b/GPU/D3D11/StateMappingD3D11.cpp index 5bc5f31fb9..0d40715cd2 100644 --- a/GPU/D3D11/StateMappingD3D11.cpp +++ b/GPU/D3D11/StateMappingD3D11.cpp @@ -121,30 +121,6 @@ static const D3D11_LOGIC_OP logicOps[] = { }; */ -bool DrawEngineD3D11::ApplyShaderBlending() { - static const int MAX_REASONABLE_BLITS_PER_FRAME = 24; - - static int lastFrameBlit = -1; - static int blitsThisFrame = 0; - if (lastFrameBlit != gpuStats.numFlips) { - if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME) { - WARN_LOG_REPORT_ONCE(blendingBlit, G3D, "Lots of blits needed for obscure blending: %d per frame, blend %d/%d/%d", blitsThisFrame, gstate.getBlendFuncA(), gstate.getBlendFuncB(), gstate.getBlendEq()); - } - blitsThisFrame = 0; - lastFrameBlit = gpuStats.numFlips; - } - ++blitsThisFrame; - if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME * 2) { - 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()); - return false; - } - - fboTexNeedBind_ = true; - - gstate_c.Dirty(DIRTY_SHADERBLEND); - return true; -} - void DrawEngineD3D11::ResetShaderBlending() { if (fboTexBound_) { ID3D11ShaderResourceView *srv = nullptr; diff --git a/GPU/Directx9/DrawEngineDX9.h b/GPU/Directx9/DrawEngineDX9.h index 1aa9fe099f..e4d8622e8f 100644 --- a/GPU/Directx9/DrawEngineDX9.h +++ b/GPU/Directx9/DrawEngineDX9.h @@ -162,7 +162,6 @@ private: void ApplyDrawState(int prim); void ApplyDrawStateLate(); - bool ApplyShaderBlending(); void ResetShaderBlending(); IDirect3DVertexDeclaration9 *SetupDecFmtForDraw(VSShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt); diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index b7c3bc0169..0f97c19b0b 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -90,34 +90,6 @@ static const D3DSTENCILOP stencilOps[] = { D3DSTENCILOP_KEEP, // reserved }; -bool DrawEngineDX9::ApplyShaderBlending() { - if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) { - return true; - } - - static const int MAX_REASONABLE_BLITS_PER_FRAME = 24; - - static int lastFrameBlit = -1; - static int blitsThisFrame = 0; - if (lastFrameBlit != gpuStats.numFlips) { - if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME) { - WARN_LOG_REPORT_ONCE(blendingBlit, G3D, "Lots of blits needed for obscure blending: %d per frame, blend %d/%d/%d", blitsThisFrame, gstate.getBlendFuncA(), gstate.getBlendFuncB(), gstate.getBlendEq()); - } - blitsThisFrame = 0; - lastFrameBlit = gpuStats.numFlips; - } - ++blitsThisFrame; - if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME * 2) { - 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()); - return false; - } - - fboTexNeedBind_ = true; - - gstate_c.Dirty(DIRTY_SHADERBLEND); - return true; -} - inline void DrawEngineDX9::ResetShaderBlending() { if (fboTexBound_) { pD3Ddevice->SetTexture(1, nullptr); diff --git a/GPU/GLES/DrawEngineGLES.h b/GPU/GLES/DrawEngineGLES.h index ef0236f366..a2cee574bd 100644 --- a/GPU/GLES/DrawEngineGLES.h +++ b/GPU/GLES/DrawEngineGLES.h @@ -170,7 +170,6 @@ private: void DoFlush(); void ApplyDrawState(int prim); void ApplyDrawStateLate(); - bool ApplyShaderBlending(); void ResetShaderBlending(); GLuint AllocateBuffer(size_t sz); diff --git a/GPU/GLES/StateMappingGLES.cpp b/GPU/GLES/StateMappingGLES.cpp index 6eb6b7efcb..440469e4f4 100644 --- a/GPU/GLES/StateMappingGLES.cpp +++ b/GPU/GLES/StateMappingGLES.cpp @@ -120,34 +120,6 @@ static const GLushort logicOps[] = { }; #endif -bool DrawEngineGLES::ApplyShaderBlending() { - if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) { - return true; - } - - static const int MAX_REASONABLE_BLITS_PER_FRAME = 24; - - static int lastFrameBlit = -1; - static int blitsThisFrame = 0; - if (lastFrameBlit != gpuStats.numFlips) { - if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME) { - WARN_LOG_REPORT_ONCE(blendingBlit, G3D, "Lots of blits needed for obscure blending: %d per frame, blend %d/%d/%d", blitsThisFrame, gstate.getBlendFuncA(), gstate.getBlendFuncB(), gstate.getBlendEq()); - } - blitsThisFrame = 0; - lastFrameBlit = gpuStats.numFlips; - } - ++blitsThisFrame; - if (blitsThisFrame > MAX_REASONABLE_BLITS_PER_FRAME * 2) { - 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()); - return false; - } - - fboTexNeedBind_ = true; - - gstate_c.Dirty(DIRTY_SHADERBLEND); - return true; -} - inline void DrawEngineGLES::ResetShaderBlending() { if (fboTexBound_) { glActiveTexture(GL_TEXTURE1); diff --git a/GPU/Vulkan/DrawEngineVulkan.h b/GPU/Vulkan/DrawEngineVulkan.h index e9f35b7283..f94d61f93f 100644 --- a/GPU/Vulkan/DrawEngineVulkan.h +++ b/GPU/Vulkan/DrawEngineVulkan.h @@ -40,6 +40,7 @@ #include "GPU/Common/VertexDecoderCommon.h" #include "GPU/Common/DrawEngineCommon.h" #include "GPU/Common/GPUStateUtils.h" +#include "GPU/Vulkan/StateMappingVulkan.h" struct DecVtxFormat; struct UVScale; @@ -132,6 +133,8 @@ public: private: struct FrameData; + void ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManager, ShaderManagerVulkan *shaderManager, int prim, VulkanPipelineRasterStateKey &key, VulkanDynamicState &dynState); + void InitDeviceObjects(); void DestroyDeviceObjects(); diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index 15f28ae6b3..77eb596529 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -30,6 +30,7 @@ #include "GPU/Vulkan/TextureCacheVulkan.h" #include "GPU/Vulkan/FramebufferVulkan.h" #include "GPU/Vulkan/ShaderManagerVulkan.h" +#include "GPU/Vulkan/DrawEngineVulkan.h" //#include "GPU/Vulkan/PixelShaderGeneratorVulkan.h" // These tables all fit into u8s. @@ -120,10 +121,6 @@ static const VkLogicOp logicOps[] = { VK_LOGIC_OP_SET, }; -bool ApplyShaderBlending() { - return false; -} - void ResetShaderBlending() { // } @@ -131,7 +128,7 @@ void ResetShaderBlending() { // TODO: Do this more progressively. No need to compute the entire state if the entire state hasn't changed. // In Vulkan, we simply collect all the state together into a "pipeline key" - we don't actually set any state here // (the caller is responsible for setting the little dynamic state that is supported, dynState). -void ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManager, ShaderManagerVulkan *shaderManager, int prim, VulkanPipelineRasterStateKey &key, VulkanDynamicState &dynState) { +void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManager, ShaderManagerVulkan *shaderManager, int prim, VulkanPipelineRasterStateKey &key, VulkanDynamicState &dynState) { memset(&key, 0, sizeof(key)); memset(&dynState, 0, sizeof(dynState)); // Unfortunately, this isn't implemented yet.