From e8e44991db668a12d81362647aef2ec0279e6dbd Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 28 Feb 2020 22:42:56 +1000 Subject: [PATCH] GPU: Fix display in OpenGL renderer --- src/core/gpu_hw_d3d11.cpp | 23 ++++++-------- src/core/gpu_hw_opengl.cpp | 34 ++++++++++----------- src/core/gpu_hw_opengl_es.cpp | 30 +++++++++--------- src/core/gpu_sw.cpp | 12 ++++---- src/core/host_display.h | 19 +++++++++--- src/duckstation-qt/d3d11displaywindow.cpp | 8 ++--- src/duckstation-qt/opengldisplaywindow.cpp | 8 ++--- src/duckstation-sdl/d3d11_host_display.cpp | 8 ++--- src/duckstation-sdl/opengl_host_display.cpp | 8 ++--- 9 files changed, 76 insertions(+), 74 deletions(-) diff --git a/src/core/gpu_hw_d3d11.cpp b/src/core/gpu_hw_d3d11.cpp index 3ba88bfbf..80a7b8e36 100644 --- a/src/core/gpu_hw_d3d11.cpp +++ b/src/core/gpu_hw_d3d11.cpp @@ -521,11 +521,10 @@ void GPU_HW_D3D11::UpdateDisplay() if (m_system->GetSettings().debugging.show_vram) { - m_host_display->SetDisplayTexture( - m_vram_texture.GetD3DSRV(), m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), - Common::Rectangle(0, 0, m_vram_texture.GetWidth(), m_vram_texture.GetHeight())); - m_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, - Common::Rectangle(0, 0, VRAM_WIDTH, VRAM_HEIGHT), 1.0f); + m_host_display->SetDisplayTexture(m_vram_texture.GetD3DSRV(), m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), + 0, 0, m_vram_texture.GetWidth(), m_vram_texture.GetHeight()); + m_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, Common::Rectangle(0, 0, VRAM_WIDTH, VRAM_HEIGHT), + 1.0f); } else { @@ -546,10 +545,9 @@ void GPU_HW_D3D11::UpdateDisplay() } else if (!m_GPUSTAT.display_area_color_depth_24 && !interlaced) { - m_host_display->SetDisplayTexture( - m_vram_texture.GetD3DSRV(), m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), - Common::Rectangle::FromExtents(scaled_vram_offset_x, scaled_vram_offset_y, scaled_display_width, - scaled_display_height)); + m_host_display->SetDisplayTexture(m_vram_texture.GetD3DSRV(), m_vram_texture.GetWidth(), + m_vram_texture.GetHeight(), scaled_vram_offset_x, scaled_vram_offset_y, + scaled_display_width, scaled_display_height); } else { @@ -575,8 +573,7 @@ void GPU_HW_D3D11::UpdateDisplay() DrawUtilityShader(display_pixel_shader, uniforms, sizeof(uniforms)); m_host_display->SetDisplayTexture(m_display_texture.GetD3DSRV(), m_display_texture.GetWidth(), - m_display_texture.GetHeight(), - Common::Rectangle(0, 0, display_width, display_height)); + m_display_texture.GetHeight(), 0, 0, display_width, display_height); } else { @@ -588,8 +585,8 @@ void GPU_HW_D3D11::UpdateDisplay() DrawUtilityShader(display_pixel_shader, uniforms, sizeof(uniforms)); m_host_display->SetDisplayTexture(m_display_texture.GetD3DSRV(), m_display_texture.GetWidth(), - m_display_texture.GetHeight(), - Common::Rectangle(0, 0, scaled_display_width, scaled_display_height)); + m_display_texture.GetHeight(), 0, 0, scaled_display_width, + scaled_display_height); } RestoreGraphicsAPIState(); diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index 72cf9a5df..694bda534 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -476,12 +476,12 @@ void GPU_HW_OpenGL::UpdateDisplay() if (m_system->GetSettings().debugging.show_vram) { - m_host_display->SetDisplayTexture( - reinterpret_cast(static_cast(m_vram_texture.GetGLId())), m_vram_texture.GetWidth(), - -static_cast(m_vram_texture.GetHeight()), - Common::Rectangle(0, m_vram_texture.GetHeight(), m_vram_texture.GetWidth(), 0)); - m_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, - Common::Rectangle(0, 0, VRAM_WIDTH, VRAM_HEIGHT), 1.0f); + m_host_display->SetDisplayTexture(reinterpret_cast(static_cast(m_vram_texture.GetGLId())), + m_vram_texture.GetWidth(), static_cast(m_vram_texture.GetHeight()), 0, + m_vram_texture.GetHeight(), m_vram_texture.GetWidth(), + -static_cast(m_vram_texture.GetHeight())); + m_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, Common::Rectangle(0, 0, VRAM_WIDTH, VRAM_HEIGHT), + 1.0f); } else { @@ -501,11 +501,10 @@ void GPU_HW_OpenGL::UpdateDisplay() } else if (!m_GPUSTAT.display_area_color_depth_24 && !interlaced) { - m_host_display->SetDisplayTexture( - reinterpret_cast(static_cast(m_vram_texture.GetGLId())), m_vram_texture.GetWidth(), - m_vram_texture.GetHeight(), - Common::Rectangle(scaled_vram_offset_x, m_vram_texture.GetHeight() - scaled_vram_offset_y, - scaled_display_width, -static_cast(scaled_display_height))); + m_host_display->SetDisplayTexture(reinterpret_cast(static_cast(m_vram_texture.GetGLId())), + m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), scaled_vram_offset_x, + m_vram_texture.GetHeight() - scaled_vram_offset_y, scaled_display_width, + -static_cast(scaled_display_height)); } else { @@ -544,10 +543,9 @@ void GPU_HW_OpenGL::UpdateDisplay() glDrawArrays(GL_TRIANGLES, 0, 3); - m_host_display->SetDisplayTexture( - reinterpret_cast(static_cast(m_display_texture.GetGLId())), m_display_texture.GetWidth(), - m_display_texture.GetHeight(), - Common::Rectangle(0, display_height, display_width, -static_cast(display_height))); + m_host_display->SetDisplayTexture(reinterpret_cast(static_cast(m_display_texture.GetGLId())), + m_display_texture.GetWidth(), m_display_texture.GetHeight(), 0, + display_height, display_width, -static_cast(display_height)); } else { @@ -563,9 +561,9 @@ void GPU_HW_OpenGL::UpdateDisplay() glDrawArrays(GL_TRIANGLES, 0, 3); m_host_display->SetDisplayTexture(reinterpret_cast(static_cast(m_display_texture.GetGLId())), - m_display_texture.GetWidth(), m_display_texture.GetHeight(), - Common::Rectangle(0, scaled_display_height, scaled_display_width, - -static_cast(scaled_display_height))); + m_display_texture.GetWidth(), m_display_texture.GetHeight(), 0, + scaled_display_height, scaled_display_width, + -static_cast(scaled_display_height)); } // restore state diff --git a/src/core/gpu_hw_opengl_es.cpp b/src/core/gpu_hw_opengl_es.cpp index 72146bc93..80853a4cf 100644 --- a/src/core/gpu_hw_opengl_es.cpp +++ b/src/core/gpu_hw_opengl_es.cpp @@ -343,10 +343,10 @@ void GPU_HW_OpenGL_ES::UpdateDisplay() if (m_system->GetSettings().debugging.show_vram) { - m_host_display->SetDisplayTexture( - reinterpret_cast(static_cast(m_vram_texture.GetGLId())), m_vram_texture.GetWidth(), - -static_cast(m_vram_texture.GetHeight()), - Common::Rectangle(0, m_vram_texture.GetHeight(), m_vram_texture.GetWidth(), 0)); + m_host_display->SetDisplayTexture(reinterpret_cast(static_cast(m_vram_texture.GetGLId())), + m_vram_texture.GetWidth(), static_cast(m_vram_texture.GetHeight()), 0, + m_vram_texture.GetHeight(), m_vram_texture.GetWidth(), + -static_cast(m_vram_texture.GetHeight())); m_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, Common::Rectangle(0, 0, VRAM_WIDTH, VRAM_HEIGHT), 1.0f); } @@ -368,11 +368,10 @@ void GPU_HW_OpenGL_ES::UpdateDisplay() } else if (!m_GPUSTAT.display_area_color_depth_24 && !interlaced) { - m_host_display->SetDisplayTexture( - reinterpret_cast(static_cast(m_vram_texture.GetGLId())), m_vram_texture.GetWidth(), - m_vram_texture.GetHeight(), - Common::Rectangle(scaled_vram_offset_x, m_vram_texture.GetHeight() - scaled_vram_offset_y, - scaled_display_width, -static_cast(scaled_display_height))); + m_host_display->SetDisplayTexture(reinterpret_cast(static_cast(m_vram_texture.GetGLId())), + m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), scaled_vram_offset_x, + m_vram_texture.GetHeight() - scaled_vram_offset_y, scaled_display_width, + -static_cast(scaled_display_height)); } else { @@ -411,10 +410,9 @@ void GPU_HW_OpenGL_ES::UpdateDisplay() glDrawArrays(GL_TRIANGLES, 0, 3); - m_host_display->SetDisplayTexture( - reinterpret_cast(static_cast(m_display_texture.GetGLId())), m_display_texture.GetWidth(), - m_display_texture.GetHeight(), - Common::Rectangle(0, display_height, display_width, -static_cast(display_height))); + m_host_display->SetDisplayTexture(reinterpret_cast(static_cast(m_display_texture.GetGLId())), + m_display_texture.GetWidth(), m_display_texture.GetHeight(), 0, + display_height, display_width, -static_cast(display_height)); } else { @@ -430,9 +428,9 @@ void GPU_HW_OpenGL_ES::UpdateDisplay() glDrawArrays(GL_TRIANGLES, 0, 3); m_host_display->SetDisplayTexture(reinterpret_cast(static_cast(m_display_texture.GetGLId())), - m_display_texture.GetWidth(), m_display_texture.GetHeight(), - Common::Rectangle(0, scaled_display_height, scaled_display_width, - -static_cast(scaled_display_height))); + m_display_texture.GetWidth(), m_display_texture.GetHeight(), 0, + scaled_display_height, scaled_display_width, + -static_cast(scaled_display_height)); } // restore state diff --git a/src/core/gpu_sw.cpp b/src/core/gpu_sw.cpp index 90c08419c..959bceabb 100644 --- a/src/core/gpu_sw.cpp +++ b/src/core/gpu_sw.cpp @@ -140,8 +140,8 @@ void GPU_SW::UpdateDisplay() m_host_display->UpdateTexture(m_display_texture.get(), 0, 0, display_width, display_height, m_display_texture_buffer.data(), display_width * sizeof(u32)); - m_host_display->SetDisplayTexture(m_display_texture->GetHandle(), VRAM_WIDTH, VRAM_HEIGHT, - Common::Rectangle(0, 0, display_width, display_height)); + m_host_display->SetDisplayTexture(m_display_texture->GetHandle(), VRAM_WIDTH, VRAM_HEIGHT, 0, 0, display_width, + display_height); m_host_display->SetDisplayParameters(m_crtc_state.visible_display_width, m_crtc_state.visible_display_height, m_crtc_state.GetActiveDisplayRectangle(), m_crtc_state.display_aspect_ratio); } @@ -150,10 +150,10 @@ void GPU_SW::UpdateDisplay() CopyOut15Bit(m_vram.data(), VRAM_WIDTH, m_display_texture_buffer.data(), VRAM_WIDTH, VRAM_HEIGHT, VRAM_HEIGHT); m_host_display->UpdateTexture(m_display_texture.get(), 0, 0, VRAM_WIDTH, VRAM_HEIGHT, m_display_texture_buffer.data(), VRAM_WIDTH * sizeof(u32)); - m_host_display->SetDisplayTexture(m_display_texture->GetHandle(), VRAM_WIDTH, VRAM_HEIGHT, - Common::Rectangle(0, 0, VRAM_WIDTH, VRAM_HEIGHT)); - m_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, - Common::Rectangle(0, 0, VRAM_WIDTH, VRAM_HEIGHT), 1.0f); + m_host_display->SetDisplayTexture(m_display_texture->GetHandle(), VRAM_WIDTH, VRAM_HEIGHT, 0, 0, VRAM_WIDTH, + VRAM_HEIGHT); + m_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, Common::Rectangle(0, 0, VRAM_WIDTH, VRAM_HEIGHT), + 1.0f); } } diff --git a/src/core/host_display.h b/src/core/host_display.h index 9a3b27b97..086909d01 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -57,17 +57,23 @@ public: m_display_texture_handle = nullptr; m_display_texture_width = 0; m_display_texture_height = 0; - m_display_texture_rect = {}; + m_display_texture_view_x = 0; + m_display_texture_view_y = 0; + m_display_texture_view_width = 0; + m_display_texture_view_height = 0; m_display_changed = true; } - void SetDisplayTexture(void* texture_handle, s32 texture_width, s32 texture_height, - const Common::Rectangle& texture_rect) + void SetDisplayTexture(void* texture_handle, s32 texture_width, s32 texture_height, s32 view_x, s32 view_y, + s32 view_width, s32 view_height) { m_display_texture_handle = texture_handle; m_display_texture_width = texture_width; m_display_texture_height = texture_height; - m_display_texture_rect = texture_rect; + m_display_texture_view_x = view_x; + m_display_texture_view_y = view_y; + m_display_texture_view_width = view_width; + m_display_texture_view_height = view_height; m_display_changed = true; } @@ -99,7 +105,10 @@ protected: void* m_display_texture_handle = nullptr; s32 m_display_texture_width = 0; s32 m_display_texture_height = 0; - Common::Rectangle m_display_texture_rect{}; + s32 m_display_texture_view_x = 0; + s32 m_display_texture_view_y = 0; + s32 m_display_texture_view_width = 0; + s32 m_display_texture_view_height = 0; s32 m_display_top_margin = 0; diff --git a/src/duckstation-qt/d3d11displaywindow.cpp b/src/duckstation-qt/d3d11displaywindow.cpp index d9261ba12..28dafaaed 100644 --- a/src/duckstation-qt/d3d11displaywindow.cpp +++ b/src/duckstation-qt/d3d11displaywindow.cpp @@ -418,10 +418,10 @@ void D3D11DisplayWindow::renderDisplay() 0, 1, m_display_linear_filtering ? m_linear_sampler.GetAddressOf() : m_point_sampler.GetAddressOf()); const float uniforms[4] = { - static_cast(m_display_texture_rect.left) / static_cast(m_display_texture_width), - static_cast(m_display_texture_rect.top) / static_cast(m_display_texture_height), - (static_cast(m_display_texture_rect.GetWidth()) - 0.5f) / static_cast(m_display_texture_width), - (static_cast(m_display_texture_rect.GetHeight()) - 0.5f) / static_cast(m_display_texture_height)}; + static_cast(m_display_texture_view_x) / static_cast(m_display_texture_width), + static_cast(m_display_texture_view_y) / static_cast(m_display_texture_height), + (static_cast(m_display_texture_view_width) - 0.5f) / static_cast(m_display_texture_width), + (static_cast(m_display_texture_view_height) - 0.5f) / static_cast(m_display_texture_height)}; const auto map = m_display_uniform_buffer.Map(m_context.Get(), sizeof(uniforms), sizeof(uniforms)); std::memcpy(map.pointer, uniforms, sizeof(uniforms)); m_display_uniform_buffer.Unmap(m_context.Get(), sizeof(uniforms)); diff --git a/src/duckstation-qt/opengldisplaywindow.cpp b/src/duckstation-qt/opengldisplaywindow.cpp index c8c4fe5b3..be62ff1ea 100644 --- a/src/duckstation-qt/opengldisplaywindow.cpp +++ b/src/duckstation-qt/opengldisplaywindow.cpp @@ -475,10 +475,10 @@ void OpenGLDisplayWindow::renderDisplay() glDepthMask(GL_FALSE); m_display_program.Bind(); m_display_program.Uniform4f( - 0, static_cast(m_display_texture_rect.left) / static_cast(m_display_texture_width), - static_cast(m_display_texture_rect.top) / static_cast(m_display_texture_height), - (static_cast(m_display_texture_rect.GetWidth()) - 0.5f) / static_cast(m_display_texture_width), - (static_cast(m_display_texture_rect.GetHeight()) - 0.5f) / static_cast(m_display_texture_height)); + 0, static_cast(m_display_texture_view_x) / static_cast(m_display_texture_width), + static_cast(m_display_texture_view_y) / static_cast(m_display_texture_height), + (static_cast(m_display_texture_view_width) - 0.5f) / static_cast(m_display_texture_width), + (static_cast(m_display_texture_view_height) - 0.5f) / static_cast(m_display_texture_height)); glBindTexture(GL_TEXTURE_2D, static_cast(reinterpret_cast(m_display_texture_handle))); glBindSampler(0, m_display_linear_filtering ? m_display_linear_sampler : m_display_nearest_sampler); glBindVertexArray(m_display_vao); diff --git a/src/duckstation-sdl/d3d11_host_display.cpp b/src/duckstation-sdl/d3d11_host_display.cpp index a6548a579..1ac4792f7 100644 --- a/src/duckstation-sdl/d3d11_host_display.cpp +++ b/src/duckstation-sdl/d3d11_host_display.cpp @@ -395,10 +395,10 @@ void D3D11HostDisplay::RenderDisplay() 0, 1, m_display_linear_filtering ? m_linear_sampler.GetAddressOf() : m_point_sampler.GetAddressOf()); const float uniforms[4] = { - static_cast(m_display_texture_rect.left) / static_cast(m_display_texture_width), - static_cast(m_display_texture_rect.top) / static_cast(m_display_texture_height), - (static_cast(m_display_texture_rect.GetWidth()) - 0.5f) / static_cast(m_display_texture_width), - (static_cast(m_display_texture_rect.GetHeight()) - 0.5f) / static_cast(m_display_texture_height)}; + static_cast(m_display_texture_view_x) / static_cast(m_display_texture_width), + static_cast(m_display_texture_view_y) / static_cast(m_display_texture_height), + (static_cast(m_display_texture_view_width) - 0.5f) / static_cast(m_display_texture_width), + (static_cast(m_display_texture_view_height) - 0.5f) / static_cast(m_display_texture_height)}; const auto map = m_display_uniform_buffer.Map(m_context.Get(), sizeof(uniforms), sizeof(uniforms)); std::memcpy(map.pointer, uniforms, sizeof(uniforms)); m_display_uniform_buffer.Unmap(m_context.Get(), sizeof(uniforms)); diff --git a/src/duckstation-sdl/opengl_host_display.cpp b/src/duckstation-sdl/opengl_host_display.cpp index 60490471f..516f21ed8 100644 --- a/src/duckstation-sdl/opengl_host_display.cpp +++ b/src/duckstation-sdl/opengl_host_display.cpp @@ -386,10 +386,10 @@ void OpenGLHostDisplay::RenderDisplay() glDepthMask(GL_FALSE); m_display_program.Bind(); m_display_program.Uniform4f( - 0, static_cast(m_display_texture_rect.left) / static_cast(m_display_texture_width), - static_cast(m_display_texture_rect.top) / static_cast(m_display_texture_height), - (static_cast(m_display_texture_rect.GetWidth()) - 0.5f) / static_cast(m_display_texture_width), - (static_cast(m_display_texture_rect.GetHeight()) - 0.5f) / static_cast(m_display_texture_height)); + 0, static_cast(m_display_texture_view_x) / static_cast(m_display_texture_width), + static_cast(m_display_texture_view_y) / static_cast(m_display_texture_height), + (static_cast(m_display_texture_view_width) - 0.5f) / static_cast(m_display_texture_width), + (static_cast(m_display_texture_view_height) - 0.5f) / static_cast(m_display_texture_height)); glBindTexture(GL_TEXTURE_2D, static_cast(reinterpret_cast(m_display_texture_handle))); glBindSampler(0, m_display_linear_filtering ? m_display_linear_sampler : m_display_nearest_sampler); glBindVertexArray(m_display_vao);