diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-06-18 01:30:07 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-06-18 01:30:07 +0000 |
| commit | ff6691cfd674a9f185beede1563bd60f8627e7f7 (patch) | |
| tree | 0058c7cd1531567e21946947b2355d49b9175525 /Graphics/GraphicsEngineVulkan | |
| parent | Added update of the dynamic texel buffer in Vk (diff) | |
| download | DiligentCore-ff6691cfd674a9f185beede1563bd60f8627e7f7.tar.gz DiligentCore-ff6691cfd674a9f185beede1563bd60f8627e7f7.zip | |
Fixed creation of views of a depth-stencil textures in Vulkan
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp | 19 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp | 25 |
2 files changed, 34 insertions, 10 deletions
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp index f282426e..4b6671d2 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp @@ -143,9 +143,22 @@ void ShaderResourceCacheVk::TransitionResources(DeviceContextVkImpl *pCtxVkImpl) // The image subresources for a sampled image or a combined image sampler must be in the // VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, // or VK_IMAGE_LAYOUT_GENERAL layout in order to access its data in a shader (13.1.3, 13.1.4). - VkImageLayout RequiredLayout = - Res.Type == SPIRVShaderResourceAttribs::ResourceType::StorageImage ? - VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + VkImageLayout RequiredLayout; + if(Res.Type == SPIRVShaderResourceAttribs::ResourceType::StorageImage) + RequiredLayout = VK_IMAGE_LAYOUT_GENERAL; + else + { + if(pTextureVk->GetDesc().BindFlags & BIND_DEPTH_STENCIL) + { + // VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL must only be used as a read - only depth / stencil attachment + // in a VkFramebuffer and/or as a read - only image in a shader (which can be read as a sampled image, combined + // image / sampler and /or input attachment). This layout is valid only for image subresources of images created + // with the VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT usage bit enabled. + RequiredLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; + } + else + RequiredLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + } if(pTextureVk->GetLayout() != RequiredLayout) { if (VerifyOnly) diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index 2df6b8ff..efd292ab 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -96,9 +96,15 @@ TextureVkImpl :: TextureVkImpl(IReferenceCounters *pRefCounters, if (FmtAttribs.IsTypeless) { - // Use SRV format to create the texture - auto SRVFormat = GetDefaultTextureViewFormat(m_Desc, TEXTURE_VIEW_SHADER_RESOURCE); - ImageCI.format = TexFormatToVkFormat(SRVFormat); + TEXTURE_VIEW_TYPE DefaultTexView; + if(m_Desc.BindFlags & BIND_DEPTH_STENCIL) + DefaultTexView = TEXTURE_VIEW_DEPTH_STENCIL; + else if (m_Desc.BindFlags & BIND_RENDER_TARGET) + DefaultTexView = TEXTURE_VIEW_RENDER_TARGET; + else + DefaultTexView = TEXTURE_VIEW_SHADER_RESOURCE; + auto DefaultViewFormat = GetDefaultTextureViewFormat(m_Desc, DefaultTexView); + ImageCI.format = TexFormatToVkFormat(DefaultViewFormat); } else { @@ -625,14 +631,17 @@ VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc default: UNEXPECTED("Unexpcted view dimension"); } - ImageViewCI.format = TexFormatToVkFormat(ViewDesc.Format); + TEXTURE_FORMAT CorrectedViewFormat = ViewDesc.Format; + if(m_Desc.BindFlags & BIND_DEPTH_STENCIL) + CorrectedViewFormat = GetDefaultTextureViewFormat(CorrectedViewFormat, TEXTURE_VIEW_DEPTH_STENCIL, m_Desc.BindFlags); + ImageViewCI.format = TexFormatToVkFormat(CorrectedViewFormat); ImageViewCI.components = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A }; ImageViewCI.subresourceRange.baseMipLevel = ViewDesc.MostDetailedMip; ImageViewCI.subresourceRange.levelCount = ViewDesc.NumMipLevels; ImageViewCI.subresourceRange.baseArrayLayer = ViewDesc.FirstArraySlice; ImageViewCI.subresourceRange.layerCount = ViewDesc.NumArraySlices; - if(ImageViewCI.viewType == VK_IMAGE_VIEW_TYPE_3D) + if(ImageViewCI.viewType == VK_IMAGE_VIEW_TYPE_3D) { if(ImageViewCI.subresourceRange.baseArrayLayer == 0 && ImageViewCI.subresourceRange.layerCount == m_Desc.Depth ) { @@ -645,7 +654,7 @@ VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc ImageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; } } - const auto &FmtAttribs = GetTextureFormatAttribs(ViewDesc.Format); + const auto &FmtAttribs = GetTextureFormatAttribs(CorrectedViewFormat); if(ViewDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL) { @@ -663,7 +672,9 @@ VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc // aspectMask must be only VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT // if format is a color, depth-only or stencil-only format, respectively. (11.5) if(FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH ) + { ImageViewCI.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + } else if (FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL) { if(ViewDesc.Format == TEX_FORMAT_D32_FLOAT_S8X24_UINT || @@ -687,7 +698,7 @@ VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc else ImageViewCI.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; } - + auto *pRenderDeviceVk = GetDevice<RenderDeviceVkImpl>(); const auto& LogicalDevice = pRenderDeviceVk->GetLogicalDevice(); |
