mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Vulkan: Make backbuffer transitions part of backbuffer render pass. Optimize depth buffer memory operations.
This commit is contained in:
parent
9e734b3791
commit
74861d2d73
4 changed files with 5 additions and 27 deletions
|
@ -153,20 +153,6 @@ VulkanContext::~VulkanContext() {
|
||||||
VulkanFree();
|
VulkanFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransitionToPresent(VkCommandBuffer cmd, VkImage image) {
|
|
||||||
TransitionImageLayout2(cmd, image, VK_IMAGE_ASPECT_COLOR_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
|
||||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
|
||||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TransitionFromPresent(VkCommandBuffer cmd, VkImage image) {
|
|
||||||
TransitionImageLayout2(cmd, image, VK_IMAGE_ASPECT_COLOR_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
|
||||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
|
|
||||||
VK_ACCESS_MEMORY_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VulkanContext::BeginFrame() {
|
void VulkanContext::BeginFrame() {
|
||||||
FrameData *frame = &frame_[curFrame_];
|
FrameData *frame = &frame_[curFrame_];
|
||||||
// Process pending deletes.
|
// Process pending deletes.
|
||||||
|
|
|
@ -393,9 +393,6 @@ void TransitionImageLayout2(VkCommandBuffer cmd, VkImage image, VkImageAspectFla
|
||||||
VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask,
|
VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask,
|
||||||
VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask);
|
VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask);
|
||||||
|
|
||||||
void TransitionFromPresent(VkCommandBuffer cmd, VkImage image);
|
|
||||||
void TransitionToPresent(VkCommandBuffer cmd, VkImage image);
|
|
||||||
|
|
||||||
// GLSL compiler
|
// GLSL compiler
|
||||||
void init_glslang();
|
void init_glslang();
|
||||||
void finalize_glslang();
|
void finalize_glslang();
|
||||||
|
|
|
@ -54,16 +54,16 @@ void VulkanQueueRunner::InitBackbufferRenderPass() {
|
||||||
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
attachments[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; // We don't want to preserve the backbuffer between frames so we really don't care.
|
||||||
attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
attachments[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; // We only render once to the backbuffer per frame so we can do this here.
|
||||||
attachments[0].flags = 0;
|
attachments[0].flags = 0;
|
||||||
|
|
||||||
attachments[1].format = vulkan_->GetDeviceInfo().preferredDepthStencilFormat; // must use this same format later for the back depth buffer.
|
attachments[1].format = vulkan_->GetDeviceInfo().preferredDepthStencilFormat; // must use this same format later for the back depth buffer.
|
||||||
attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
|
attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; // Don't care about storing backbuffer Z - we clear it anyway.
|
||||||
attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
|
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachments[1].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
attachments[1].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
attachments[1].flags = 0;
|
attachments[1].flags = 0;
|
||||||
|
|
|
@ -302,6 +302,7 @@ VkCommandBuffer VulkanRenderManager::GetInitCmd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanRenderManager::BindFramebufferAsRenderTarget(VKRFramebuffer *fb, VKRRenderPassAction color, VKRRenderPassAction depth, uint32_t clearColor, float clearDepth, uint8_t clearStencil) {
|
void VulkanRenderManager::BindFramebufferAsRenderTarget(VKRFramebuffer *fb, VKRRenderPassAction color, VKRRenderPassAction depth, uint32_t clearColor, float clearDepth, uint8_t clearStencil) {
|
||||||
|
assert(insideFrame_);
|
||||||
// Eliminate dupes.
|
// Eliminate dupes.
|
||||||
if (steps_.size() && steps_.back()->render.framebuffer == fb && steps_.back()->stepType == VKRStepType::RENDER) {
|
if (steps_.size() && steps_.back()->render.framebuffer == fb && steps_.back()->stepType == VKRStepType::RENDER) {
|
||||||
if (color != VKRRenderPassAction::CLEAR && depth != VKRRenderPassAction::CLEAR) {
|
if (color != VKRRenderPassAction::CLEAR && depth != VKRRenderPassAction::CLEAR) {
|
||||||
|
@ -570,9 +571,6 @@ void VulkanRenderManager::BeginSubmitFrame(int frame) {
|
||||||
|
|
||||||
assert(res == VK_SUCCESS);
|
assert(res == VK_SUCCESS);
|
||||||
|
|
||||||
// TODO: Is it best to do this here, or combine with some other transition, or just do it right before the backbuffer bind-for-render?
|
|
||||||
TransitionFromPresent(frameData.mainCmd, swapchainImages_[frameData.curSwapchainImage].image);
|
|
||||||
|
|
||||||
queueRunner_.SetBackbuffer(framebuffers_[frameData.curSwapchainImage]);
|
queueRunner_.SetBackbuffer(framebuffers_[frameData.curSwapchainImage]);
|
||||||
|
|
||||||
frameData.hasBegun = true;
|
frameData.hasBegun = true;
|
||||||
|
@ -629,8 +627,6 @@ void VulkanRenderManager::EndSubmitFrame(int frame) {
|
||||||
frameData.hasBegun = false;
|
frameData.hasBegun = false;
|
||||||
insideFrame_ = false;
|
insideFrame_ = false;
|
||||||
|
|
||||||
TransitionToPresent(frameData.mainCmd, swapchainImages_[frameData.curSwapchainImage].image);
|
|
||||||
|
|
||||||
Submit(frame, true);
|
Submit(frame, true);
|
||||||
|
|
||||||
VkSwapchainKHR swapchain = vulkan_->GetSwapchain();
|
VkSwapchainKHR swapchain = vulkan_->GetSwapchain();
|
||||||
|
@ -640,7 +636,6 @@ void VulkanRenderManager::EndSubmitFrame(int frame) {
|
||||||
present.pImageIndices = &frameData.curSwapchainImage;
|
present.pImageIndices = &frameData.curSwapchainImage;
|
||||||
present.pWaitSemaphores = &renderingCompleteSemaphore_;
|
present.pWaitSemaphores = &renderingCompleteSemaphore_;
|
||||||
present.waitSemaphoreCount = 1;
|
present.waitSemaphoreCount = 1;
|
||||||
present.pResults = nullptr;
|
|
||||||
|
|
||||||
VkResult res = vkQueuePresentKHR(vulkan_->GetGraphicsQueue(), &present);
|
VkResult res = vkQueuePresentKHR(vulkan_->GetGraphicsQueue(), &present);
|
||||||
// TODO: Deal with the VK_SUBOPTIMAL_WSI and VK_ERROR_OUT_OF_DATE_WSI
|
// TODO: Deal with the VK_SUBOPTIMAL_WSI and VK_ERROR_OUT_OF_DATE_WSI
|
||||||
|
|
Loading…
Add table
Reference in a new issue