From 0deefb82a93eb170ab0bc1a57d0242baa19af30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Aug 2023 15:53:05 +0200 Subject: [PATCH] thin3d: Merge BeginFrame and SetDebugFlags (set them every frame anyway) --- Common/GPU/D3D11/thin3d_d3d11.cpp | 4 +- Common/GPU/OpenGL/thin3d_gl.cpp | 11 ++--- Common/GPU/Vulkan/thin3d_vulkan.cpp | 12 ++---- Common/GPU/thin3d.h | 3 +- UI/NativeApp.cpp | 64 +++++++++++++++-------------- headless/Headless.cpp | 2 +- libretro/libretro.cpp | 2 +- 7 files changed, 44 insertions(+), 54 deletions(-) diff --git a/Common/GPU/D3D11/thin3d_d3d11.cpp b/Common/GPU/D3D11/thin3d_d3d11.cpp index e80fe6ef20..ec5fcb44fa 100644 --- a/Common/GPU/D3D11/thin3d_d3d11.cpp +++ b/Common/GPU/D3D11/thin3d_d3d11.cpp @@ -137,7 +137,7 @@ public: void DrawUP(const void *vdata, int vertexCount) override; void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override; - void BeginFrame() override; + void BeginFrame(DebugFlags debugFlags) override; void EndFrame() override; void Present() override; @@ -1529,7 +1529,7 @@ void D3D11DrawContext::Clear(int mask, uint32_t colorval, float depthVal, int st } } -void D3D11DrawContext::BeginFrame() { +void D3D11DrawContext::BeginFrame(DebugFlags debugFlags) { context_->OMSetRenderTargets(1, &curRenderTargetView_, curDepthStencilView_); if (curBlend_ != nullptr) { diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index a1da0cc9b4..8da8345109 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -329,9 +329,6 @@ public: DrawContext::SetTargetSize(w, h); renderManager_.Resize(w, h); } - void SetDebugFlags(DebugFlags flags) override { - debugFlags_ = flags; - } const DeviceCaps &GetDeviceCaps() const override { return caps_; @@ -367,7 +364,7 @@ public: Buffer *CreateBuffer(size_t size, uint32_t usageFlags) override; Framebuffer *CreateFramebuffer(const FramebufferDesc &desc) override; - void BeginFrame() override; + void BeginFrame(DebugFlags debugFlags) override; void EndFrame() override; void Present() override; @@ -528,8 +525,6 @@ private: GLPushBuffer *push; }; FrameData frameData_[GLRenderManager::MAX_INFLIGHT_FRAMES]{}; - - DebugFlags debugFlags_ = DebugFlags::NONE; }; static constexpr int MakeIntelSimpleVer(int v1, int v2, int v3) { @@ -794,8 +789,8 @@ OpenGLContext::~OpenGLContext() { } } -void OpenGLContext::BeginFrame() { - renderManager_.BeginFrame(debugFlags_ & DebugFlags::PROFILE_TIMESTAMPS); +void OpenGLContext::BeginFrame(DebugFlags debugFlags) { + renderManager_.BeginFrame(debugFlags & DebugFlags::PROFILE_TIMESTAMPS); FrameData &frameData = frameData_[renderManager_.GetCurFrame()]; renderManager_.BeginPushBuffer(frameData.push); } diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index b4d7db8012..e4a37eb82e 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -388,7 +388,6 @@ public: ~VKContext(); void DebugAnnotate(const char *annotation) override; - void SetDebugFlags(DebugFlags flags) override; const DeviceCaps &GetDeviceCaps() const override { return caps_; @@ -479,7 +478,7 @@ public: void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override; - void BeginFrame() override; + void BeginFrame(DebugFlags debugFlags) override; void EndFrame() override; void Present() override; @@ -558,7 +557,6 @@ private: AutoRef curFramebuffer_; VkDevice device_; - DebugFlags debugFlags_ = DebugFlags::NONE; enum { MAX_FRAME_COMMAND_BUFFERS = 256, @@ -1105,9 +1103,9 @@ VKContext::~VKContext() { vulkan_->Delete().QueueDeletePipelineCache(pipelineCache_); } -void VKContext::BeginFrame() { +void VKContext::BeginFrame(DebugFlags debugFlags) { // TODO: Bad dependency on g_Config here! - renderManager_.BeginFrame(debugFlags_ & DebugFlags::PROFILE_TIMESTAMPS, debugFlags_ & DebugFlags::PROFILE_SCOPES); + renderManager_.BeginFrame(debugFlags & DebugFlags::PROFILE_TIMESTAMPS, debugFlags & DebugFlags::PROFILE_SCOPES); FrameData &frame = frame_[vulkan_->GetCurFrame()]; @@ -1875,8 +1873,4 @@ void VKContext::DebugAnnotate(const char *annotation) { renderManager_.DebugAnnotate(annotation); } -void VKContext::SetDebugFlags(DebugFlags flags) { - debugFlags_ = flags; -} - } // namespace Draw diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index 6f752708dd..e58b6072ce 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -708,7 +708,6 @@ public: virtual void SetErrorCallback(ErrorCallbackFn callback, void *userdata) {} virtual void DebugAnnotate(const char *annotation) {} - virtual void SetDebugFlags(DebugFlags flags) {} // Partial pipeline state, used to create pipelines. (in practice, in d3d11 they'll use the native state objects directly). // TODO: Possibly ditch these and just put the descs directly in PipelineDesc since only D3D11 benefits. @@ -814,7 +813,7 @@ public: virtual void DrawUP(const void *vdata, int vertexCount) = 0; // Frame management (for the purposes of sync and resource management, necessary with modern APIs). Default implementations here. - virtual void BeginFrame() {} + virtual void BeginFrame(DebugFlags debugFlags) {} virtual void EndFrame() = 0; virtual void Present() = 0; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 0e3e9a8a74..9fe58fa44a 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1049,6 +1049,37 @@ void RenderOverlays(UIContext *dc, void *userdata) { } } +static Matrix4x4 ComputeOrthoMatrix(float xres, float yres) { + Matrix4x4 ortho; + switch (GetGPUBackend()) { + case GPUBackend::VULKAN: + ortho.setOrthoD3D(0.0f, xres, 0, yres, -1.0f, 1.0f); + break; + case GPUBackend::DIRECT3D9: + ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f); + Matrix4x4 translation; + // Account for the small window adjustment. + translation.setTranslation(Vec3( + -0.5f * g_display.dpi_scale_x / g_display.dpi_scale_real_x, + -0.5f * g_display.dpi_scale_y / g_display.dpi_scale_real_y, 0.0f)); + ortho = translation * ortho; + break; + case GPUBackend::DIRECT3D11: + ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f); + break; + case GPUBackend::OPENGL: + default: + ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f); + break; + } + + // Compensate for rotated display if needed. + if (g_display.rotation != DisplayRotation::ROTATE_0) { + ortho = ortho * g_display.rot_matrix; + } + return ortho; +} + void NativeFrame(GraphicsContext *graphicsContext) { PROFILE_END_FRAME(); @@ -1090,38 +1121,9 @@ void NativeFrame(GraphicsContext *graphicsContext) { g_BackgroundAudio.Update(); } - float xres = g_display.dp_xres; - float yres = g_display.dp_yres; - // Apply the UIContext bounds as a 2D transformation matrix. // TODO: This should be moved into the draw context... - Matrix4x4 ortho; - switch (GetGPUBackend()) { - case GPUBackend::VULKAN: - ortho.setOrthoD3D(0.0f, xres, 0, yres, -1.0f, 1.0f); - break; - case GPUBackend::DIRECT3D9: - ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f); - Matrix4x4 translation; - // Account for the small window adjustment. - translation.setTranslation(Vec3( - -0.5f * g_display.dpi_scale_x / g_display.dpi_scale_real_x, - -0.5f * g_display.dpi_scale_y / g_display.dpi_scale_real_y, 0.0f)); - ortho = translation * ortho; - break; - case GPUBackend::DIRECT3D11: - ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f); - break; - case GPUBackend::OPENGL: - default: - ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f); - break; - } - - // Compensate for rotated display if needed. - if (g_display.rotation != DisplayRotation::ROTATE_0) { - ortho = ortho * g_display.rot_matrix; - } + Matrix4x4 ortho = ComputeOrthoMatrix(g_display.dp_xres, g_display.dp_yres); Draw::DebugFlags debugFlags = Draw::DebugFlags::NONE; if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::GPU_PROFILE) @@ -1129,7 +1131,7 @@ void NativeFrame(GraphicsContext *graphicsContext) { if (g_Config.bGpuLogProfiler) debugFlags |= Draw::DebugFlags::PROFILE_SCOPES; - g_draw->BeginFrame(); + g_draw->BeginFrame(debugFlags); ui_draw2d.PushDrawMatrix(ortho); ui_draw2d_front.PushDrawMatrix(ortho); diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 2c2b19cbb7..e8e3d83d9f 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -238,7 +238,7 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, const PSP_BeginHostFrame(); Draw::DrawContext *draw = coreParameter.graphicsContext ? coreParameter.graphicsContext->GetDrawContext() : nullptr; if (draw) - draw->BeginFrame(); + draw->BeginFrame(Draw::DebugFlags::NONE); bool passed = true; double deadline = time_now_d() + opt.timeout; diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 4b762dee63..9274e4cc15 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -1163,7 +1163,7 @@ namespace Libretro { ctx->SetRenderTarget(); if (ctx->GetDrawContext()) - ctx->GetDrawContext()->BeginFrame(); + ctx->GetDrawContext()->BeginFrame(Draw::DebugFlags::NONE); gpu->BeginHostFrame();