summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-07-03 05:09:39 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-07-03 05:09:39 +0000
commit5981d4a4e67c01f291b9a05614aa1de2cb064713 (patch)
treefcc57f5d7e5816ae7359b311d1bb22363ba6cabe /Graphics/GraphicsEngineVulkan
parentImproved bound RTV,DSV - PSO mismatch reporting in D3D11 backend (diff)
downloadDiligentCore-5981d4a4e67c01f291b9a05614aa1de2cb064713.tar.gz
DiligentCore-5981d4a4e67c01f291b9a05614aa1de2cb064713.zip
Fixed issues with RTV/DSV clears and 3D texture views in Vulkan
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp52
-rw-r--r--Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp48
2 files changed, 56 insertions, 44 deletions
diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
index 7ed86eb5..e8f83022 100644
--- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
@@ -552,7 +552,8 @@ namespace Diligent
EnsureVkCmdBuffer();
const auto& ViewDesc = pVkDSV->GetDesc();
-
+ VERIFY(ViewDesc.TextureDim != RESOURCE_DIM_TEX_3D, "Depth-stencil view of a 3D texture should've been created as 2D texture array view");
+
if(pVkDSV == m_pBoundDepthStencil)
{
// Render pass may not be currently committed
@@ -568,9 +569,12 @@ namespace Diligent
ClearAttachment.clearValue.depthStencil.depth = fDepth;
ClearAttachment.clearValue.depthStencil.stencil = Stencil;
VkClearRect ClearRect;
- ClearRect.rect = { { 0,0 },{ m_FramebufferWidth, m_FramebufferHeight } };
- ClearRect.baseArrayLayer = ViewDesc.FirstArraySlice;
- ClearRect.layerCount = ViewDesc.NumArraySlices;
+ // m_FramebufferWidth, m_FramebufferHeight are scaled to the proper mip level
+ ClearRect.rect = { {0, 0}, {m_FramebufferWidth, m_FramebufferHeight} };
+ // The layers [baseArrayLayer, baseArrayLayer + layerCount) count from the base layer of
+ // the attachment image view (17.2), so baseArrayLayer is 0, not ViewDesc.FirstArraySlice
+ ClearRect.baseArrayLayer = 0;
+ ClearRect.layerCount = ViewDesc.NumArraySlices;
// No memory barriers are needed between vkCmdClearAttachments and preceding or
// subsequent draw or attachment clear commands in the same subpass (17.2)
m_CommandBuffer.ClearAttachment(ClearAttachment, ClearRect);
@@ -593,10 +597,11 @@ namespace Diligent
Subresource.aspectMask = 0;
if (ClearFlags & CLEAR_DEPTH_FLAG) Subresource.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
if (ClearFlags & CLEAR_STENCIL_FLAG) Subresource.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
+ // We are clearing the image, not image view with vkCmdClearDepthStencilImage
Subresource.baseArrayLayer = ViewDesc.FirstArraySlice;
- Subresource.layerCount = ViewDesc.NumArraySlices;
- Subresource.baseMipLevel = ViewDesc.MostDetailedMip;
- Subresource.levelCount = ViewDesc.NumMipLevels;
+ Subresource.layerCount = ViewDesc.NumArraySlices;
+ Subresource.baseMipLevel = ViewDesc.MostDetailedMip;
+ Subresource.levelCount = ViewDesc.NumMipLevels;
m_CommandBuffer.ClearDepthStencilImage(pTextureVk->GetVkImage(), ClearValue, Subresource);
}
@@ -658,7 +663,8 @@ namespace Diligent
EnsureVkCmdBuffer();
const auto& ViewDesc = pVkRTV->GetDesc();
-
+ VERIFY(ViewDesc.TextureDim != RESOURCE_DIM_TEX_3D, "Render target view of a 3D texture should've been created as 2D texture array view");
+
// Check if the texture is one of the currently bound render targets
static constexpr const Uint32 InvalidAttachmentIndex = static_cast<Uint32>(-1);
Uint32 attachmentIndex = InvalidAttachmentIndex;
@@ -686,9 +692,12 @@ namespace Diligent
ClearAttachment.colorAttachment = attachmentIndex;
ClearAttachment.clearValue.color = ClearValueToVkClearValue(RGBA, ViewDesc.Format);
VkClearRect ClearRect;
- ClearRect.rect = {{0,0}, {m_FramebufferWidth, m_FramebufferHeight}};
- ClearRect.baseArrayLayer = ViewDesc.FirstArraySlice;
- ClearRect.layerCount = ViewDesc.NumArraySlices;
+ // m_FramebufferWidth, m_FramebufferHeight are scaled to the proper mip level
+ ClearRect.rect = { {0, 0}, {m_FramebufferWidth, m_FramebufferHeight} };
+ // The layers [baseArrayLayer, baseArrayLayer + layerCount) count from the base layer of
+ // the attachment image view (17.2), so baseArrayLayer is 0, not ViewDesc.FirstArraySlice
+ ClearRect.baseArrayLayer = 0;
+ ClearRect.layerCount = ViewDesc.NumArraySlices;
// No memory barriers are needed between vkCmdClearAttachments and preceding or
// subsequent draw or attachment clear commands in the same subpass (17.2)
m_CommandBuffer.ClearAttachment(ClearAttachment, ClearRect);
@@ -706,21 +715,12 @@ namespace Diligent
TransitionImageLayout(pTexture, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
auto ClearValue = ClearValueToVkClearValue(RGBA, ViewDesc.Format);
VkImageSubresourceRange Subresource;
- Subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- if(ViewDesc.TextureDim == RESOURCE_DIM_TEX_3D)
- {
- if(ViewDesc.NumDepthSlices != pTextureVk->GetDesc().Depth || ViewDesc.FirstDepthSlice != 0)
- LOG_ERROR_MESSAGE("Partial clears of 3D textures are not supported in Vulkan. Texture '", pTextureVk->GetDesc().Name,"' will be cleared entirely.");
- Subresource.baseArrayLayer = 0;
- Subresource.layerCount = 1;
- }
- else
- {
- Subresource.baseArrayLayer = ViewDesc.FirstArraySlice;
- Subresource.layerCount = ViewDesc.NumArraySlices;
- }
- Subresource.baseMipLevel = ViewDesc.MostDetailedMip;
- Subresource.levelCount = ViewDesc.NumMipLevels;
+ Subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ // We are clearing the image, not image view with vkCmdClearColorImage
+ Subresource.baseArrayLayer = ViewDesc.FirstArraySlice;
+ Subresource.layerCount = ViewDesc.NumArraySlices;
+ Subresource.baseMipLevel = ViewDesc.MostDetailedMip;
+ Subresource.levelCount = ViewDesc.NumMipLevels;
VERIFY(ViewDesc.NumMipLevels, "RTV must contain single mip level");
m_CommandBuffer.ClearColorImage(pTextureVk->GetVkImage(), ClearValue, Subresource);
diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
index 4d8135cd..d7a29937 100644
--- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
@@ -560,7 +560,7 @@ void TextureVkImpl::Unmap( IDeviceContext *pContext, Uint32 Subresource, MAP_TYP
UNEXPECTED("TextureVkImpl::Unmap() is not implemented");
}
-VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc &ViewDesc)
+VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc& ViewDesc)
{
VERIFY(ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE ||
ViewDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET ||
@@ -596,7 +596,21 @@ VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc
break;
case RESOURCE_DIM_TEX_3D:
- ImageViewCI.viewType = VK_IMAGE_VIEW_TYPE_3D;
+ if (ViewDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET || ViewDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL)
+ {
+ ViewDesc.TextureDim = RESOURCE_DIM_TEX_2D_ARRAY;
+ ImageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
+ }
+ else
+ {
+ ImageViewCI.viewType = VK_IMAGE_VIEW_TYPE_3D;
+ if (ViewDesc.FirstDepthSlice != 0 && ViewDesc.NumDepthSlices == m_Desc.Depth)
+ {
+ LOG_ERROR_MESSAGE("In Vulkan SRVs and UAVs of a 3D texture must reference all depth slices.");
+ ViewDesc.FirstDepthSlice = 0;
+ ViewDesc.NumDepthSlices = m_Desc.Depth;
+ }
+ }
break;
case RESOURCE_DIM_TEX_CUBE:
@@ -615,24 +629,22 @@ VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc
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)
+ ImageViewCI.subresourceRange.baseMipLevel = ViewDesc.MostDetailedMip;
+ ImageViewCI.subresourceRange.levelCount = ViewDesc.NumMipLevels;
+ if (ViewDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY ||
+ ViewDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY ||
+ ViewDesc.TextureDim == RESOURCE_DIM_TEX_CUBE ||
+ ViewDesc.TextureDim == RESOURCE_DIM_TEX_CUBE_ARRAY )
{
- 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;
- }
+ ImageViewCI.subresourceRange.baseArrayLayer = ViewDesc.FirstArraySlice;
+ ImageViewCI.subresourceRange.layerCount = ViewDesc.NumArraySlices;
}
+ else
+ {
+ ImageViewCI.subresourceRange.baseArrayLayer = 0;
+ ImageViewCI.subresourceRange.layerCount = 1;
+ }
+
const auto &FmtAttribs = GetTextureFormatAttribs(CorrectedViewFormat);
if(ViewDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL)