From 3b6fa9be8712f4c49e797d657403bce49ec2768d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 16 May 2017 13:30:10 +0200 Subject: [PATCH] Start work on separating frame from backbuffer renderpass --- GPU/Common/FramebufferCommon.cpp | 13 +++++----- GPU/Vulkan/FramebufferVulkan.cpp | 8 +++--- ext/native/thin3d/thin3d.h | 9 +++---- ext/native/thin3d/thin3d_vulkan.cpp | 39 ++++++++++++++++------------- ext/native/ui/ui_screen.cpp | 5 ++-- 5 files changed, 40 insertions(+), 34 deletions(-) diff --git a/GPU/Common/FramebufferCommon.cpp b/GPU/Common/FramebufferCommon.cpp index 66d677bd33..b7d89316be 100644 --- a/GPU/Common/FramebufferCommon.cpp +++ b/GPU/Common/FramebufferCommon.cpp @@ -205,7 +205,7 @@ void FramebufferManagerCommon::SetNumExtraFBOs(int num) { Draw::Framebuffer *fbo = draw_->CreateFramebuffer({ (int)renderWidth_, (int)renderHeight_, 1, 1, false, Draw::FBO_8888 }); extraFBOs_.push_back(fbo); - // The new FBO is still bound after creation, but let's bind it anyway. + // The new FBO is still bound after creation, but let's bind and clear it anyway. draw_->BindFramebufferAsRenderTarget(fbo); ClearBuffer(); } @@ -828,20 +828,16 @@ void FramebufferManagerCommon::CopyDisplayToOutput() { DownloadFramebufferOnSwitch(currentRenderVfb_); SetViewport2D(0, 0, pixelWidth_, pixelHeight_); - draw_->BindBackbufferAsRenderTarget(); currentRenderVfb_ = 0; if (displayFramebufPtr_ == 0) { DEBUG_LOG(FRAMEBUF, "Display disabled, displaying only black"); // No framebuffer to display! Clear to black. + draw_->BindBackbufferAsRenderTarget(); ClearBuffer(); return; } - if (useBufferedRendering_) { - draw_->Clear(Draw::FB_COLOR_BIT | Draw::FB_STENCIL_BIT | Draw::FB_DEPTH_BIT, 0, 0, 0); - } - u32 offsetX = 0; u32 offsetY = 0; @@ -888,6 +884,11 @@ void FramebufferManagerCommon::CopyDisplayToOutput() { } } + draw_->BindBackbufferAsRenderTarget(); + if (useBufferedRendering_) { + draw_->Clear(Draw::FB_COLOR_BIT | Draw::FB_STENCIL_BIT | Draw::FB_DEPTH_BIT, 0, 0, 0); + } + if (!vfb) { if (Memory::IsValidAddress(displayFramebufPtr_)) { // The game is displaying something directly from RAM. In GTA, it's decoded video. diff --git a/GPU/Vulkan/FramebufferVulkan.cpp b/GPU/Vulkan/FramebufferVulkan.cpp index b8899551a0..eed60df430 100644 --- a/GPU/Vulkan/FramebufferVulkan.cpp +++ b/GPU/Vulkan/FramebufferVulkan.cpp @@ -444,10 +444,10 @@ void FramebufferManagerVulkan::DrawTexture(VulkanTexture *texture, float x, floa } Vulkan2D::Vertex vtx[4] = { - {x,y,0,texCoords[0],texCoords[1]}, - {x + w,y,0,texCoords[2],texCoords[3]}, - {x,y + h,0,texCoords[6],texCoords[7] }, - {x + w,y + h,0,texCoords[4],texCoords[5] }, + {x,y, 0,texCoords[0],texCoords[1]}, + {x + w,y, 0,texCoords[2],texCoords[3]}, + {x,y + h, 0,texCoords[6],texCoords[7] }, + {x + w,y + h, 0,texCoords[4],texCoords[5] }, }; float invDestW = 1.0f / (destW * 0.5f); diff --git a/ext/native/thin3d/thin3d.h b/ext/native/thin3d/thin3d.h index 3722dc4bcd..75175c431e 100644 --- a/ext/native/thin3d/thin3d.h +++ b/ext/native/thin3d/thin3d.h @@ -636,11 +636,10 @@ public: virtual void DrawIndexed(int vertexCount, int offset) = 0; virtual void DrawUP(const void *vdata, int vertexCount) = 0; - // Render pass management. Default implementations here. - virtual void Begin(bool clear, uint32_t colorval, float depthVal, int stencilVal) { - Clear(0xF, colorval, depthVal, stencilVal); - } - virtual void End() {} + // Frame management (for the purposes of sync and resource management, necessary with modern APIs). Default implementations here. + virtual void BeginFrame() {} + virtual void EndFrame() {} + virtual void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) = 0; // Necessary to correctly flip scissor rectangles etc for OpenGL. diff --git a/ext/native/thin3d/thin3d_vulkan.cpp b/ext/native/thin3d/thin3d_vulkan.cpp index 08d1bac9a3..ca0e90e3cd 100644 --- a/ext/native/thin3d/thin3d_vulkan.cpp +++ b/ext/native/thin3d/thin3d_vulkan.cpp @@ -387,8 +387,8 @@ public: void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override; - void Begin(bool clear, uint32_t colorval, float depthVal, int stencilVal) override; - void End() override; + void BeginFrame() override; + void EndFrame() override; std::string GetInfoString(InfoField info) const override { // TODO: Make these actually query the right information @@ -731,21 +731,9 @@ VKContext::~VKContext() { vulkan_->Delete().QueueDeletePipelineCache(pipelineCache_); } -void VKContext::Begin(bool clear, uint32_t colorval, float depthVal, int stencilVal) { +void VKContext::BeginFrame() { cmd_ = vulkan_->BeginFrame(); - VkClearValue clearVal[2] = {}; - Uint8x4ToFloat4(colorval, clearVal[0].color.float32); - - // // Debug flicker - used to see if we swap at all. no longer necessary - // if (frameNum_ & 1) - // clearVal[0].color.float32[2] = 1.0f; - - clearVal[1].depthStencil.depth = depthVal; - clearVal[1].depthStencil.stencil = stencilVal; - - vulkan_->BeginSurfaceRenderPass(clearVal); - FrameData *frame = &frame_[frameNum_ & 1]; push_ = frame->pushBuffer; @@ -761,12 +749,29 @@ void VKContext::Begin(bool clear, uint32_t colorval, float depthVal, int stencil scissor_.extent.height = pixel_yres; scissorDirty_ = true; viewportDirty_ = true; + + int colorval = 0xFF000000; + float depthVal = 0.0; + int stencilVal = 0; + + VkClearValue clearVal[2] = {}; + Uint8x4ToFloat4(colorval, clearVal[0].color.float32); + + // // Debug flicker - used to see if we swap at all. no longer necessary + // if (frameNum_ & 1) + // clearVal[0].color.float32[2] = 1.0f; + + clearVal[1].depthStencil.depth = depthVal; + clearVal[1].depthStencil.stencil = stencilVal; + + vulkan_->BeginSurfaceRenderPass(clearVal); } -void VKContext::End() { +void VKContext::EndFrame() { + vulkan_->EndSurfaceRenderPass(); + // Stop collecting data in the frame's data pushbuffer. push_->End(); - vulkan_->EndSurfaceRenderPass(); vulkan_->EndFrame(); frameNum_++; diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index 3b93a1472e..becd3953ca 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -65,7 +65,8 @@ void UIScreen::preRender() { if (!draw) { return; } - draw->Begin(true, 0xFF000000, 0.0f, 0); + draw->BeginFrame(); + draw->Clear(0xF, 0xFF000000, 0.0f, 0); Draw::Viewport viewport; viewport.TopLeftX = 0; @@ -83,7 +84,7 @@ void UIScreen::postRender() { if (!draw) { return; } - draw->End(); + draw->EndFrame(); } void UIScreen::render() {