From 396b7c2978498712f6e6eea7f353408f3c33c147 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 19 Jan 2019 23:54:35 +1000 Subject: [PATCH] OGL: Invalidate tracked state when calling ResetAPIState() Due to the current design, any of the GL state can be mutated after calling this function, so we can't assume that the tracked state will match if we call SetPipeline() after ResetAPIState(). --- Source/Core/VideoBackends/OGL/Render.cpp | 12 +++++----- Source/Core/VideoBackends/OGL/Render.h | 6 ++--- Source/Core/VideoCommon/RenderState.cpp | 28 ++++++++++++++++++++++++ Source/Core/VideoCommon/RenderState.h | 4 ++++ 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 186b6a7da5..76483b3d5b 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -357,7 +357,10 @@ Renderer::Renderer(std::unique_ptr main_gl_context) : ::Renderer(static_cast(std::max(main_gl_context->GetBackBufferWidth(), 1u)), static_cast(std::max(main_gl_context->GetBackBufferHeight(), 1u)), AbstractTextureFormat::RGBA8), - m_main_gl_context(std::move(main_gl_context)) + m_main_gl_context(std::move(main_gl_context)), + m_current_rasterization_state(RenderState::GetInvalidRasterizationState()), + m_current_depth_state(RenderState::GetInvalidDepthState()), + m_current_blend_state(RenderState::GetInvalidBlendingState()) { bool bSuccess = true; @@ -1585,6 +1588,9 @@ void Renderer::ResetAPIState() } glDepthMask(GL_FALSE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + m_current_rasterization_state = RenderState::GetInvalidRasterizationState(); + m_current_depth_state = RenderState::GetInvalidDepthState(); + m_current_blend_state = RenderState::GetInvalidBlendingState(); } void Renderer::RestoreAPIState() @@ -1603,10 +1609,6 @@ void Renderer::RestoreAPIState() } BPFunctions::SetScissor(); BPFunctions::SetViewport(); - - ApplyRasterizationState(m_current_rasterization_state, true); - ApplyDepthState(m_current_depth_state, true); - ApplyBlendingState(m_current_blend_state, true); } void Renderer::ApplyRasterizationState(const RasterizationState state, bool force) diff --git a/Source/Core/VideoBackends/OGL/Render.h b/Source/Core/VideoBackends/OGL/Render.h index f520c6faa4..78f410bb52 100644 --- a/Source/Core/VideoBackends/OGL/Render.h +++ b/Source/Core/VideoBackends/OGL/Render.h @@ -168,8 +168,8 @@ private: std::unique_ptr m_main_gl_context; std::array m_bound_textures{}; const OGLPipeline* m_graphics_pipeline = nullptr; - RasterizationState m_current_rasterization_state = {}; - DepthState m_current_depth_state = {}; - BlendingState m_current_blend_state = {}; + RasterizationState m_current_rasterization_state; + DepthState m_current_depth_state; + BlendingState m_current_blend_state; }; } // namespace OGL diff --git a/Source/Core/VideoCommon/RenderState.cpp b/Source/Core/VideoCommon/RenderState.cpp index 5cad8c2584..b61b031b04 100644 --- a/Source/Core/VideoCommon/RenderState.cpp +++ b/Source/Core/VideoCommon/RenderState.cpp @@ -199,6 +199,13 @@ SamplerState& SamplerState::operator=(const SamplerState& rhs) namespace RenderState { +RasterizationState GetInvalidRasterizationState() +{ + RasterizationState state; + state.hex = UINT32_C(0xFFFFFFFF); + return state; +} + RasterizationState GetNoCullRasterizationState() { RasterizationState state = {}; @@ -206,6 +213,13 @@ RasterizationState GetNoCullRasterizationState() return state; } +DepthState GetInvalidDepthState() +{ + DepthState state; + state.hex = UINT32_C(0xFFFFFFFF); + return state; +} + DepthState GetNoDepthTestingDepthStencilState() { DepthState state = {}; @@ -215,6 +229,13 @@ DepthState GetNoDepthTestingDepthStencilState() return state; } +BlendingState GetInvalidBlendingState() +{ + BlendingState state; + state.hex = UINT32_C(0xFFFFFFFF); + return state; +} + BlendingState GetNoBlendingBlendState() { BlendingState state = {}; @@ -230,6 +251,13 @@ BlendingState GetNoBlendingBlendState() return state; } +SamplerState GetInvalidSamplerState() +{ + SamplerState state; + state.hex = UINT64_C(0xFFFFFFFFFFFFFFFF); + return state; +} + SamplerState GetPointSamplerState() { SamplerState state = {}; diff --git a/Source/Core/VideoCommon/RenderState.h b/Source/Core/VideoCommon/RenderState.h index d72c2d3984..5cd0ba7470 100644 --- a/Source/Core/VideoCommon/RenderState.h +++ b/Source/Core/VideoCommon/RenderState.h @@ -113,9 +113,13 @@ union SamplerState namespace RenderState { +RasterizationState GetInvalidRasterizationState(); RasterizationState GetNoCullRasterizationState(); +DepthState GetInvalidDepthState(); DepthState GetNoDepthTestingDepthStencilState(); +BlendingState GetInvalidBlendingState(); BlendingState GetNoBlendingBlendState(); +SamplerState GetInvalidSamplerState(); SamplerState GetPointSamplerState(); SamplerState GetLinearSamplerState(); }