diff options
| author | Stenzek <stenzek@gmail.com> | 2018-01-21 15:03:06 +1000 |
|---|---|---|
| committer | Stenzek <stenzek@gmail.com> | 2018-03-01 17:31:24 +1000 |
| commit | 6374a4c4a80e88eea2e5914fb84e393c91ec65af (patch) | |
| tree | fcff01f0220c40ef2c594695272b181635bdf894 /Source/Core/VideoBackends/Vulkan/VKTexture.cpp | |
| parent | 4316f5f56b9f3fdba89a52224a058b0fcd8b8c55 (diff) | |
AbstractTexture: Support multisampled abstract texture
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/VKTexture.cpp')
| -rw-r--r-- | Source/Core/VideoBackends/Vulkan/VKTexture.cpp | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp index 4a4f70c2cb..974a8578a1 100644 --- a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp @@ -42,9 +42,10 @@ std::unique_ptr<VKTexture> VKTexture::Create(const TextureConfig& tex_config) // Allocate texture object VkFormat vk_format = Util::GetVkFormatForHostTextureFormat(tex_config.format); - auto texture = Texture2D::Create(tex_config.width, tex_config.height, tex_config.levels, - tex_config.layers, vk_format, VK_SAMPLE_COUNT_1_BIT, - VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_IMAGE_TILING_OPTIMAL, usage); + auto texture = + Texture2D::Create(tex_config.width, tex_config.height, tex_config.levels, tex_config.layers, + vk_format, static_cast<VkSampleCountFlagBits>(tex_config.samples), + VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_IMAGE_TILING_OPTIMAL, usage); if (!texture) { @@ -56,8 +57,9 @@ std::unique_ptr<VKTexture> VKTexture::Create(const TextureConfig& tex_config) if (tex_config.rendertarget) { VkImageView framebuffer_attachments[] = {texture->GetView()}; - VkRenderPass render_pass = g_object_cache->GetRenderPass( - texture->GetFormat(), VK_FORMAT_UNDEFINED, 1, VK_ATTACHMENT_LOAD_OP_DONT_CARE); + VkRenderPass render_pass = + g_object_cache->GetRenderPass(texture->GetFormat(), VK_FORMAT_UNDEFINED, tex_config.samples, + VK_ATTACHMENT_LOAD_OP_DONT_CARE); VkFramebufferCreateInfo framebuffer_info = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, @@ -195,6 +197,43 @@ void VKTexture::ScaleRectangleFromTexture(const AbstractTexture* source, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); } +void VKTexture::ResolveFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& rect, + u32 layer, u32 level) +{ + const VKTexture* srcentry = static_cast<const VKTexture*>(src); + _dbg_assert_(VIDEO, m_config.samples == 1 && m_config.width == srcentry->m_config.width && + m_config.height == srcentry->m_config.height && + srcentry->m_config.samples > 1); + _dbg_assert_(VIDEO, + rect.left + rect.GetWidth() <= static_cast<int>(srcentry->m_config.width) && + rect.top + rect.GetHeight() <= static_cast<int>(srcentry->m_config.height)); + + // Resolving is considered to be a transfer operation. + StateTracker::GetInstance()->EndRenderPass(); + VkImageLayout old_src_layout = srcentry->m_texture->GetLayout(); + srcentry->m_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + m_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + + VkImageResolve resolve = { + {VK_IMAGE_ASPECT_COLOR_BIT, level, layer, 1}, // srcSubresource + {rect.left, rect.top, 0}, // srcOffset + {VK_IMAGE_ASPECT_COLOR_BIT, level, layer, 1}, // dstSubresource + {rect.left, rect.top, 0}, // dstOffset + {static_cast<u32>(rect.GetWidth()), static_cast<u32>(rect.GetHeight()), 1} // extent + }; + vkCmdResolveImage(g_command_buffer_mgr->GetCurrentCommandBuffer(), + srcentry->m_texture->GetImage(), srcentry->m_texture->GetLayout(), + m_texture->GetImage(), m_texture->GetLayout(), 1, &resolve); + + // Restore old source texture layout. Destination is assumed to be bound as a shader resource. + srcentry->m_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), + old_src_layout); + m_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); +} + void VKTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer, size_t buffer_size) { |
