diff options
| author | Stenzek <stenzek@gmail.com> | 2017-10-30 21:51:42 +1000 |
|---|---|---|
| committer | Stenzek <stenzek@gmail.com> | 2017-11-22 18:47:04 +1000 |
| commit | 56afebeb44f1ace990d9383e9b840fdc27610029 (patch) | |
| tree | 3717a9e24cde9cfcc870ebfb7e083b4db053c0e5 /Source/Core/VideoBackends/Vulkan/VKTexture.cpp | |
| parent | f43d85921dc85ae586d69b21d28a7578835a55bd (diff) | |
AbstractTexture: Seperate CopyRectangleFromTexture to two methods
ScaleRectangleFromTexture, which does a draw, and
CopyRectangleFromTexture, which where possible, does a bit-for-bit copy.
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/VKTexture.cpp')
| -rw-r--r-- | Source/Core/VideoBackends/Vulkan/VKTexture.cpp | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp index cfea34ff8e..f2db740551 100644 --- a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp @@ -163,10 +163,13 @@ void VKTexture::Unmap() m_staging_texture->Unmap(); } -void VKTexture::CopyTextureRectangle(const MathUtil::Rectangle<int>& dst_rect, - Texture2D* src_texture, - const MathUtil::Rectangle<int>& src_rect) +void VKTexture::CopyRectangleFromTexture(const AbstractTexture* src, + const MathUtil::Rectangle<int>& src_rect, u32 src_layer, + u32 src_level, const MathUtil::Rectangle<int>& dst_rect, + u32 dst_layer, u32 dst_level) { + Texture2D* src_texture = static_cast<const VKTexture*>(src)->GetRawTexIdentifier(); + _assert_msg_(VIDEO, static_cast<u32>(src_rect.GetWidth()) <= src_texture->GetWidth() && static_cast<u32>(src_rect.GetHeight()) <= src_texture->GetHeight(), "Source rect is too large for CopyRectangleFromTexture"); @@ -176,15 +179,11 @@ void VKTexture::CopyTextureRectangle(const MathUtil::Rectangle<int>& dst_rect, "Dest rect is too large for CopyRectangleFromTexture"); VkImageCopy image_copy = { - {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, - src_texture->GetLayers()}, // VkImageSubresourceLayers srcSubresource - {src_rect.left, src_rect.top, 0}, // VkOffset3D srcOffset - {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, // VkImageSubresourceLayers dstSubresource - m_config.layers}, - {dst_rect.left, dst_rect.top, 0}, // VkOffset3D dstOffset - {static_cast<uint32_t>(src_rect.GetWidth()), static_cast<uint32_t>(src_rect.GetHeight()), - 1} // VkExtent3D extent - }; + {VK_IMAGE_ASPECT_COLOR_BIT, src_level, src_layer, src_texture->GetLayers()}, + {src_rect.left, src_rect.top, 0}, + {VK_IMAGE_ASPECT_COLOR_BIT, dst_level, dst_layer, m_config.layers}, + {dst_rect.left, dst_rect.top, 0}, + {static_cast<uint32_t>(src_rect.GetWidth()), static_cast<uint32_t>(src_rect.GetHeight()), 1}}; // Must be called outside of a render pass. StateTracker::GetInstance()->EndRenderPass(); @@ -197,12 +196,20 @@ void VKTexture::CopyTextureRectangle(const MathUtil::Rectangle<int>& dst_rect, vkCmdCopyImage(g_command_buffer_mgr->GetCurrentCommandBuffer(), src_texture->GetImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_texture->GetImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &image_copy); + + // Ensure both textures remain in the SHADER_READ_ONLY layout so they can be bound. + src_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + m_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); } -void VKTexture::ScaleTextureRectangle(const MathUtil::Rectangle<int>& dst_rect, - Texture2D* src_texture, - const MathUtil::Rectangle<int>& src_rect) +void VKTexture::ScaleRectangleFromTexture(const AbstractTexture* source, + const MathUtil::Rectangle<int>& src_rect, + const MathUtil::Rectangle<int>& dst_rect) { + Texture2D* src_texture = static_cast<const VKTexture*>(source)->GetRawTexIdentifier(); + // Can't do this within a game render pass. StateTracker::GetInstance()->EndRenderPass(); StateTracker::GetInstance()->SetPendingRebind(); @@ -235,27 +242,10 @@ void VKTexture::ScaleTextureRectangle(const MathUtil::Rectangle<int>& dst_rect, static_cast<int>(src_texture->GetWidth()), static_cast<int>(src_texture->GetHeight())); draw.EndRenderPass(); -} - -void VKTexture::CopyRectangleFromTexture(const AbstractTexture* source, - const MathUtil::Rectangle<int>& srcrect, - const MathUtil::Rectangle<int>& dstrect) -{ - auto* raw_source_texture = static_cast<const VKTexture*>(source)->GetRawTexIdentifier(); - CopyRectangleFromTexture(raw_source_texture, srcrect, dstrect); -} - -void VKTexture::CopyRectangleFromTexture(Texture2D* source, const MathUtil::Rectangle<int>& srcrect, - const MathUtil::Rectangle<int>& dstrect) -{ - if (srcrect.GetWidth() == dstrect.GetWidth() && srcrect.GetHeight() == dstrect.GetHeight()) - CopyTextureRectangle(dstrect, source, srcrect); - else - ScaleTextureRectangle(dstrect, source, srcrect); // Ensure both textures remain in the SHADER_READ_ONLY layout so they can be bound. - source->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + src_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); m_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); } |
