From d74ad74732723537bc92271cd4bd6067076c7758 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 2 Jun 2018 21:20:44 -0700 Subject: Fixed issue with partial views of a 3D texture in Vulkan --- Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index 58f7f394..886f2e3c 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -86,7 +86,10 @@ TextureVkImpl :: TextureVkImpl(IReferenceCounters *pRefCounters, else if (m_Desc.Type == RESOURCE_DIM_TEX_2D || m_Desc.Type == RESOURCE_DIM_TEX_2D_ARRAY || m_Desc.Type == RESOURCE_DIM_TEX_CUBE || m_Desc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) ImageCI.imageType = VK_IMAGE_TYPE_2D; else if (m_Desc.Type == RESOURCE_DIM_TEX_3D) + { ImageCI.imageType = VK_IMAGE_TYPE_3D; + ImageCI.flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT; + } else { LOG_ERROR_AND_THROW("Unknown texture type"); @@ -690,6 +693,19 @@ VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc ImageViewCI.subresourceRange.baseArrayLayer = ViewDesc.FirstArraySlice; ImageViewCI.subresourceRange.layerCount = ViewDesc.NumArraySlices; + if(ImageViewCI.viewType == VK_IMAGE_VIEW_TYPE_3D) + { + if(ImageViewCI.subresourceRange.baseArrayLayer == 0 && ImageViewCI.subresourceRange.layerCount == m_Desc.Depth ) + { + // If viewType is VK_IMAGE_VIEW_TYPE_3D, then baseArrayLayer must be 0, and layerCount must be 1 (11.5) + ImageViewCI.subresourceRange.layerCount = 1; + } + else + { + // Create a 2D texture array view + ImageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; + } + } const auto &FmtAttribs = GetTextureFormatAttribs(ViewDesc.Format); if(ViewDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL) -- cgit v1.2.3