diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index de9d617a66..2cd6b87bb7 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -357,19 +357,6 @@ void VKGSRender::begin() //TODO: Set up other render-state parameters into the program pipeline - VkRenderPassBeginInfo rp_begin; - rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - rp_begin.pNext = NULL; - rp_begin.renderPass = m_render_pass; - rp_begin.framebuffer = m_framebuffer; - rp_begin.renderArea.offset.x = 0; - rp_begin.renderArea.offset.y = 0; - rp_begin.renderArea.extent.width = m_frame->client_size().width; - rp_begin.renderArea.extent.height = m_frame->client_size().height; - rp_begin.clearValueCount = 0; - rp_begin.pClearValues = nullptr; - - vkCmdBeginRenderPass(m_command_buffer, &rp_begin, VK_SUBPASS_CONTENTS_INLINE); m_draw_calls++; } @@ -394,7 +381,21 @@ namespace } void VKGSRender::end() -{ +{ + VkRenderPassBeginInfo rp_begin; + rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + rp_begin.pNext = NULL; + rp_begin.renderPass = m_render_pass; + rp_begin.framebuffer = m_framebuffer; + rp_begin.renderArea.offset.x = 0; + rp_begin.renderArea.offset.y = 0; + rp_begin.renderArea.extent.width = m_frame->client_size().width; + rp_begin.renderArea.extent.height = m_frame->client_size().height; + rp_begin.clearValueCount = 0; + rp_begin.pClearValues = nullptr; + + vkCmdBeginRenderPass(m_command_buffer, &rp_begin, VK_SUBPASS_CONTENTS_INLINE); + vk::texture *texture0 = nullptr; for (int i = 0; i < rsx::limits::textures_count; ++i) { @@ -571,12 +572,22 @@ void VKGSRender::clear_surface(u32 mask) if (std::get<1>(m_rtts.m_bound_render_targets[i]) == nullptr) continue; VkImage color_image = (*std::get<1>(m_rtts.m_bound_render_targets[i])); - vkCmdClearColorImage(m_command_buffer, color_image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, &color_clear_values.color, 1, &range); + VkImageLayout old_layout = std::get<1>(m_rtts.m_bound_render_targets[i])->get_layout(); + std::get<1>(m_rtts.m_bound_render_targets[i])->change_layout(m_command_buffer, VK_IMAGE_LAYOUT_GENERAL); + + vkCmdClearColorImage(m_command_buffer, color_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_values.color, 1, &range); + std::get<1>(m_rtts.m_bound_render_targets[i])->change_layout(m_command_buffer, old_layout); } } if (mask & 0x3) - vkCmdClearDepthStencilImage(m_command_buffer, (*std::get<1>(m_rtts.m_bound_depth_stencil)), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &depth_stencil_clear_values.depthStencil, 1, &depth_range); + { + VkImageLayout old_layout = std::get<1>(m_rtts.m_bound_depth_stencil)->get_layout(); + std::get<1>(m_rtts.m_bound_depth_stencil)->change_layout(m_command_buffer, VK_IMAGE_LAYOUT_GENERAL); + + vkCmdClearDepthStencilImage(m_command_buffer, (*std::get<1>(m_rtts.m_bound_depth_stencil)), VK_IMAGE_LAYOUT_GENERAL, &depth_stencil_clear_values.depthStencil, 1, &depth_range); + std::get<1>(m_rtts.m_bound_depth_stencil)->change_layout(m_command_buffer, old_layout); + } if (!was_recording) { diff --git a/rpcs3/Emu/RSX/VK/VKRenderTargets.h b/rpcs3/Emu/RSX/VK/VKRenderTargets.h index 75fb00c6dc..ef877b0052 100644 --- a/rpcs3/Emu/RSX/VK/VKRenderTargets.h +++ b/rpcs3/Emu/RSX/VK/VKRenderTargets.h @@ -20,6 +20,18 @@ namespace rsx vk::texture rtt; rtt.create(device, requested_format, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, width, height, 1, true); + rtt.change_layout(*cmd, VK_IMAGE_LAYOUT_GENERAL); + + //Clear new surface + VkClearColorValue clear_color; + VkImageSubresourceRange range = vk::default_image_subresource_range(); + + clear_color.float32[0] = 0.f; + clear_color.float32[1] = 0.f; + clear_color.float32[2] = 0.f; + clear_color.float32[3] = 0.f; + + vkCmdClearColorImage(*cmd, rtt, rtt.get_layout(), &clear_color, 1, &range); rtt.change_layout(*cmd, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); return rtt; @@ -31,6 +43,24 @@ namespace rsx vk::texture rtt; rtt.create(device, requested_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, width, height, 1, true); + rtt.change_layout(*cmd, VK_IMAGE_LAYOUT_GENERAL); + + //Clear new surface.. + VkClearDepthStencilValue clear_depth; + VkImageSubresourceRange range; + range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + range.baseArrayLayer = 0; + range.baseMipLevel = 0; + range.layerCount = 1; + range.levelCount = 1; + + if (format == surface_depth_format::z24s8) + range.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; + + clear_depth.depth = 1.f; + clear_depth.stencil = 0; + + vkCmdClearDepthStencilImage(*cmd, rtt, rtt.get_layout(), &clear_depth, 1, &range); rtt.change_layout(*cmd, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); return rtt;