From 396b7c2978498712f6e6eea7f353408f3c33c147 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 19 Jan 2019 23:54:35 +1000 Subject: 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 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') 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) -- cgit v1.2.3 From d1868d9475db2ec99314a2f7f192a63fc40bf962 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 10 Oct 2018 00:57:52 +1100 Subject: RenderBase: Implement imgui rendering --- Source/Core/VideoBackends/OGL/Render.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 76483b3d5b..e967ae6a75 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1455,6 +1455,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawDebugText(); OSD::DrawMessages(); + DrawImGui(); // Swap the back and front buffers, presenting the image. m_main_gl_context->Swap(); -- cgit v1.2.3 From 600d1fc0bc884644127057fa8cce5d31cbaef143 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 10 Oct 2018 01:26:31 +1100 Subject: Renderer: Use imgui for drawing debug text and OSD --- Source/Core/VideoBackends/OGL/Render.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index e967ae6a75..c857cce083 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1424,9 +1424,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region ResetAPIState(); - // Do our OSD callbacks - OSD::DoCallbacks(OSD::CallbackType::OnFrame); - // Check if we need to render to a new surface. CheckForSurfaceChange(); CheckForSurfaceResize(); @@ -1451,10 +1448,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region // Render OSD messages. glViewport(0, 0, m_backbuffer_width, m_backbuffer_height); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - DrawDebugText(); - OSD::DrawMessages(); DrawImGui(); // Swap the back and front buffers, presenting the image. -- cgit v1.2.3 From 63dd91628de0c9e8c7a25c403b7900675c515d36 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 10 Oct 2018 01:34:26 +1100 Subject: Remove old RasterFont classes --- Source/Core/VideoBackends/OGL/Render.cpp | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index c857cce083..dc724353d7 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -33,7 +33,6 @@ #include "VideoBackends/OGL/OGLTexture.h" #include "VideoBackends/OGL/PostProcessing.h" #include "VideoBackends/OGL/ProgramShaderCache.h" -#include "VideoBackends/OGL/RasterFont.h" #include "VideoBackends/OGL/SamplerCache.h" #include "VideoBackends/OGL/StreamBuffer.h" #include "VideoBackends/OGL/TextureCache.h" @@ -57,7 +56,6 @@ VideoConfig g_ogl_config; // Declarations and definitions // ---------------------------- -static std::unique_ptr s_raster_font; // 1 for no MSAA. Use s_MSAASamples > 1 to check for MSAA. static int s_MSAASamples = 1; @@ -827,8 +825,6 @@ bool Renderer::Initialize() m_current_framebuffer_height = m_target_height; m_post_processor = std::make_unique(); - s_raster_font = std::make_unique(); - return true; } @@ -839,7 +835,6 @@ void Renderer::Shutdown() UpdateActiveConfig(); - s_raster_font.reset(); m_post_processor.reset(); } @@ -862,21 +857,6 @@ Renderer::CreateFramebuffer(const AbstractTexture* color_attachment, static_cast(depth_attachment)); } -void Renderer::RenderText(const std::string& text, int left, int top, u32 color) -{ - int screen_width = m_backbuffer_width; - int screen_height = m_backbuffer_height; - if (screen_width >= 2000) - { - screen_width /= 2; - screen_height /= 2; - } - - s_raster_font->printMultilineText(text, left * 2.0f / static_cast(screen_width) - 1.0f, - 1.0f - top * 2.0f / static_cast(screen_height), 0, - screen_width, screen_height, color); -} - std::unique_ptr Renderer::CreateShaderFromSource(ShaderStage stage, const char* source, size_t length) { -- cgit v1.2.3 From c9c0b8505615cb16a770d66650e89c0f41d00dc8 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 19 Jan 2019 00:35:00 +1000 Subject: VideoBackends: Store a backbuffer 'scale' This is a scaling factor, used for hi-dpi configurations. --- Source/Core/VideoBackends/OGL/Render.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index dc724353d7..630cea738e 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -351,10 +351,10 @@ static void InitDriverInfo() } // Init functions -Renderer::Renderer(std::unique_ptr main_gl_context) +Renderer::Renderer(std::unique_ptr main_gl_context, float backbuffer_scale) : ::Renderer(static_cast(std::max(main_gl_context->GetBackBufferWidth(), 1u)), static_cast(std::max(main_gl_context->GetBackBufferHeight(), 1u)), - AbstractTextureFormat::RGBA8), + backbuffer_scale, AbstractTextureFormat::RGBA8), m_main_gl_context(std::move(main_gl_context)), m_current_rasterization_state(RenderState::GetInvalidRasterizationState()), m_current_depth_state(RenderState::GetInvalidDepthState()), -- cgit v1.2.3 From e4b205c76937d379cd9043939e2cef1651b1a21b Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 28 Nov 2018 14:30:47 +1000 Subject: Decouple XFB scanout from presentation --- Source/Core/VideoBackends/OGL/Render.cpp | 180 ++++++++++--------------------- 1 file changed, 56 insertions(+), 124 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 630cea738e..35ec1a6715 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -59,10 +59,6 @@ VideoConfig g_ogl_config; // 1 for no MSAA. Use s_MSAASamples > 1 to check for MSAA. static int s_MSAASamples = 1; -static u32 s_last_multisamples = 1; -static bool s_last_stereo_mode = false; - -static bool s_vsync; // EFB cache related static const u32 EFB_CACHE_RECT_SIZE = 64; // Cache 64x64 blocks. @@ -725,9 +721,6 @@ Renderer::Renderer(std::unique_ptr main_gl_context, float backbuffer_ g_Config.VerifyValidity(); UpdateActiveConfig(); - // Since we modify the config here, we need to update the last host bits, it may have changed. - m_last_host_config_bits = ShaderHostConfig::GetCurrent().bits; - OSD::AddMessage(StringFromFormat("Video Info: %s, %s, %s", g_ogl_config.gl_vendor, g_ogl_config.gl_renderer, g_ogl_config.gl_version), 5000); @@ -756,15 +749,9 @@ Renderer::Renderer(std::unique_ptr main_gl_context, float backbuffer_ g_ogl_config.bSupportsCopySubImage ? "" : "CopyImageSubData ", g_ActiveConfig.backend_info.bSupportsDepthClamp ? "" : "DepthClamp "); - s_last_multisamples = g_ActiveConfig.iMultisamples; - s_MSAASamples = s_last_multisamples; - - s_last_stereo_mode = g_ActiveConfig.stereo_mode != StereoMode::Off; - // Handle VSync on/off - s_vsync = g_ActiveConfig.IsVSync(); if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC)) - m_main_gl_context->SwapInterval(s_vsync); + m_main_gl_context->SwapInterval(g_ActiveConfig.IsVSync()); // Because of the fixed framebuffer size we need to disable the resolution // options while running @@ -1220,37 +1207,55 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE ClearEFBCache(); } -void Renderer::BlitScreen(TargetRectangle src, TargetRectangle dst, GLuint src_texture, - int src_width, int src_height) +void Renderer::RenderXFBToScreen(const AbstractTexture* texture, const EFBRectangle& rc) { + TargetRectangle source_rc = rc; + source_rc.top = rc.GetHeight(); + source_rc.bottom = 0; + + // Check if we need to render to a new surface. + TargetRectangle flipped_trc = GetTargetRectangle(); + std::swap(flipped_trc.top, flipped_trc.bottom); + + // Copy the framebuffer to screen. OpenGLPostProcessing* post_processor = static_cast(m_post_processor.get()); if (g_ActiveConfig.stereo_mode == StereoMode::SBS || g_ActiveConfig.stereo_mode == StereoMode::TAB) { - TargetRectangle leftRc, rightRc; + TargetRectangle left_rc, right_rc; // Top-and-Bottom mode needs to compensate for inverted vertical screen coordinates. if (g_ActiveConfig.stereo_mode == StereoMode::TAB) - std::tie(rightRc, leftRc) = ConvertStereoRectangle(dst); + std::tie(right_rc, left_rc) = ConvertStereoRectangle(flipped_trc); else - std::tie(leftRc, rightRc) = ConvertStereoRectangle(dst); + std::tie(left_rc, right_rc) = ConvertStereoRectangle(flipped_trc); - post_processor->BlitFromTexture(src, leftRc, src_texture, src_width, src_height, 0); - post_processor->BlitFromTexture(src, rightRc, src_texture, src_width, src_height, 1); + post_processor->BlitFromTexture(source_rc, left_rc, + static_cast(texture)->GetRawTexIdentifier(), + texture->GetWidth(), texture->GetHeight(), 0); + post_processor->BlitFromTexture(source_rc, right_rc, + static_cast(texture)->GetRawTexIdentifier(), + texture->GetWidth(), texture->GetHeight(), 1); } else if (g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer) { glDrawBuffer(GL_BACK_LEFT); - post_processor->BlitFromTexture(src, dst, src_texture, src_width, src_height, 0); + post_processor->BlitFromTexture(source_rc, flipped_trc, + static_cast(texture)->GetRawTexIdentifier(), + texture->GetWidth(), texture->GetHeight(), 0); glDrawBuffer(GL_BACK_RIGHT); - post_processor->BlitFromTexture(src, dst, src_texture, src_width, src_height, 1); + post_processor->BlitFromTexture(source_rc, flipped_trc, + static_cast(texture)->GetRawTexIdentifier(), + texture->GetWidth(), texture->GetHeight(), 1); glDrawBuffer(GL_BACK); } else { - post_processor->BlitFromTexture(src, dst, src_texture, src_width, src_height, 0); + post_processor->BlitFromTexture(source_rc, flipped_trc, + static_cast(texture)->GetRawTexIdentifier(), + texture->GetWidth(), texture->GetHeight(), 0); } } @@ -1385,8 +1390,20 @@ void Renderer::ApplyBlendingState(const BlendingState state, bool force) m_current_blend_state = state; } -// This function has the final picture. We adjust the aspect ratio here. -void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region, u64 ticks) +void Renderer::BindBackbuffer(const ClearColor& clear_color) +{ + CheckForSurfaceChange(); + CheckForSurfaceResize(); + + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + m_current_framebuffer = nullptr; + m_current_framebuffer_width = m_backbuffer_width; + m_current_framebuffer_height = m_backbuffer_height; +} + +void Renderer::PresentBackbuffer() { if (g_ogl_config.bSupportsDebug) { @@ -1396,72 +1413,22 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region glDisable(GL_DEBUG_OUTPUT); } - auto* xfb_texture = static_cast(texture); - - TargetRectangle sourceRc = xfb_region; - sourceRc.top = xfb_region.GetHeight(); - sourceRc.bottom = 0; - - ResetAPIState(); - - // Check if we need to render to a new surface. - CheckForSurfaceChange(); - CheckForSurfaceResize(); - UpdateDrawRectangle(); - TargetRectangle flipped_trc = GetTargetRectangle(); - std::swap(flipped_trc.top, flipped_trc.bottom); - - // Skip screen rendering when running in headless mode. - if (!IsHeadless()) - { - // Clear the framebuffer before drawing anything. - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - m_current_framebuffer = nullptr; - m_current_framebuffer_width = m_backbuffer_width; - m_current_framebuffer_height = m_backbuffer_height; - - // Copy the framebuffer to screen. - BlitScreen(sourceRc, flipped_trc, xfb_texture->GetRawTexIdentifier(), - xfb_texture->GetConfig().width, xfb_texture->GetConfig().height); - - // Render OSD messages. - glViewport(0, 0, m_backbuffer_width, m_backbuffer_height); - DrawImGui(); - - // Swap the back and front buffers, presenting the image. - m_main_gl_context->Swap(); - } - else - { - // Since we're not swapping in headless mode, ensure all commands are sent to the GPU. - // Otherwise the driver could batch several frames togehter. - glFlush(); - } - - // Was the size changed since the last frame? - bool target_size_changed = CalculateTargetSize(); - bool stencil_buffer_enabled = - static_cast(g_framebuffer_manager.get())->HasStencilBuffer(); - - bool fb_needs_update = target_size_changed || - s_last_multisamples != g_ActiveConfig.iMultisamples || - stencil_buffer_enabled != BoundingBox::NeedsStencilBuffer() || - s_last_stereo_mode != (g_ActiveConfig.stereo_mode != StereoMode::Off); + // Swap the back and front buffers, presenting the image. + m_main_gl_context->Swap(); +} - if (fb_needs_update) +void Renderer::OnConfigChanged(u32 bits) +{ + if (bits & (CONFIG_CHANGE_BIT_TARGET_SIZE | CONFIG_CHANGE_BIT_MULTISAMPLES | + CONFIG_CHANGE_BIT_STEREO_MODE | CONFIG_CHANGE_BIT_BBOX)) { - s_last_stereo_mode = g_ActiveConfig.stereo_mode != StereoMode::Off; - s_last_multisamples = g_ActiveConfig.iMultisamples; - s_MSAASamples = s_last_multisamples; - + s_MSAASamples = g_ActiveConfig.iMultisamples; if (s_MSAASamples > 1 && s_MSAASamples > g_ogl_config.max_samples) { s_MSAASamples = g_ogl_config.max_samples; OSD::AddMessage( StringFromFormat("%d Anti Aliasing samples selected, but only %d supported by your GPU.", - s_last_multisamples, g_ogl_config.max_samples), + s_MSAASamples, g_ogl_config.max_samples), 10000); } @@ -1469,40 +1436,13 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region g_framebuffer_manager = std::make_unique( m_target_width, m_target_height, s_MSAASamples, BoundingBox::NeedsStencilBuffer()); BoundingBox::SetTargetSizeChanged(m_target_width, m_target_height); - UpdateDrawRectangle(); - } - - if (s_vsync != g_ActiveConfig.IsVSync()) - { - s_vsync = g_ActiveConfig.IsVSync(); - if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC)) - m_main_gl_context->SwapInterval(s_vsync); } - // Clean out old stuff from caches. It's not worth it to clean out the shader caches. - g_texture_cache->Cleanup(frameCount); - - RestoreAPIState(); - - g_Config.iSaveTargetId = 0; + if (bits & CONFIG_CHANGE_BIT_VSYNC && !DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC)) + m_main_gl_context->SwapInterval(g_ActiveConfig.IsVSync()); - int old_anisotropy = g_ActiveConfig.iMaxAnisotropy; - UpdateActiveConfig(); - g_texture_cache->OnConfigChanged(g_ActiveConfig); - - if (old_anisotropy != g_ActiveConfig.iMaxAnisotropy) + if (bits & CONFIG_CHANGE_BIT_ANISOTROPY) g_sampler_cache->Clear(); - - // Invalidate shader cache when the host config changes. - CheckForHostConfigChanges(); - - // For testing zbuffer targets. - // Renderer::SetZBufferRender(); - // SaveTexture("tex.png", GL_TEXTURE_2D, s_FakeZTarget, - // GetTargetWidth(), GetTargetHeight()); - - // Invalidate EFB cache - ClearEFBCache(); } void Renderer::Flush() @@ -1535,15 +1475,6 @@ void Renderer::CheckForSurfaceResize() m_backbuffer_height = m_main_gl_context->GetBackBufferHeight(); } -void Renderer::DrawEFB(GLuint framebuffer, const TargetRectangle& target_rc, - const TargetRectangle& source_rc) -{ - // for msaa mode, we must resolve the efb content to non-msaa - GLuint tex = FramebufferManager::ResolveAndGetRenderTarget(source_rc); - glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); - BlitScreen(source_rc, target_rc, tex, m_target_width, m_target_height); -} - // ALWAYS call RestoreAPIState for each ResetAPIState call you're doing void Renderer::ResetAPIState() { @@ -1671,6 +1602,7 @@ void Renderer::UnbindTexture(const AbstractTexture* texture) glActiveTexture(static_cast(GL_TEXTURE0 + i)); glBindTexture(GL_TEXTURE_2D_ARRAY, 0); + m_bound_textures[i] = nullptr; } } -- cgit v1.2.3