summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-06-02 17:37:07 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-06-02 17:37:07 +0000
commitde7b7fc8cfaa753503d5b313993aa0b1474b4c1a (patch)
treef045848ef1c8949b6829d5cd81c678ca40425187 /Graphics/GraphicsEngineVulkan
parentImplemented texture initialization with initial data in Vulkan (diff)
downloadDiligentCore-de7b7fc8cfaa753503d5b313993aa0b1474b4c1a.tar.gz
DiligentCore-de7b7fc8cfaa753503d5b313993aa0b1474b4c1a.zip
Implemented CopyTextureRegion in Vulkan
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h3
-rw-r--r--Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h17
-rw-r--r--Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp33
-rw-r--r--Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp84
4 files changed, 86 insertions, 51 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h
index 99b08f73..20f7c00e 100644
--- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h
@@ -116,9 +116,8 @@ public:
void UpdateBufferRegion(class BufferVkImpl *pBuffVk, const void *pData, Uint64 DstOffset, Uint64 NumBytes);
void CopyBufferRegion(class BufferVkImpl *pSrcBuffVk, class BufferVkImpl *pDstBuffVk, Uint64 SrcOffset, Uint64 DstOffset, Uint64 NumBytes);
+ void CopyTextureRegion(class TextureVkImpl *pSrcTexture, class TextureVkImpl *pDstTexture, const VkImageCopy &CopyRegion);
#if 0
- void CopyTextureRegion(class TextureVkImpl *pSrcTexture, Uint32 SrcSubResIndex, const Vk_BOX *pVkSrcBox,
- class TextureVkImpl *pDstTexture, Uint32 DstSubResIndex, Uint32 DstX, Uint32 DstY, Uint32 DstZ);
void CopyTextureRegion(IBuffer *pSrcBuffer, Uint32 SrcStride, Uint32 SrcDepthStride, class TextureVkImpl *pTextureVk, Uint32 DstSubResIndex, const Box &DstBox);
#endif
void GenerateMips(class TextureViewVkImpl *pTexView);
diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h
index e5a886f7..b4d3269c 100644
--- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h
+++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h
@@ -344,6 +344,23 @@ namespace VulkanUtilities
}
vkCmdCopyBuffer(m_VkCmdBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
}
+
+ void CopyImage(VkImage srcImage,
+ VkImageLayout srcImageLayout,
+ VkImage dstImage,
+ VkImageLayout dstImageLayout,
+ uint32_t regionCount,
+ const VkImageCopy* pRegions)
+ {
+ VERIFY_EXPR(m_VkCmdBuffer != VK_NULL_HANDLE);
+ if(m_State.RenderPass != VK_NULL_HANDLE)
+ {
+ // Copy operations must be performed outside of render pass.
+ EndRenderPass();
+ }
+
+ vkCmdCopyImage(m_VkCmdBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
+ }
void FlushBarriers();
diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
index 35b5104f..33d58923 100644
--- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
@@ -953,28 +953,24 @@ namespace Diligent
++m_State.NumCommands;
}
-#if 0
- void DeviceContextVkImpl::CopyTextureRegion(TextureVkImpl *pSrcTexture, Uint32 SrcSubResIndex, const Vk_BOX *pVkSrcBox,
- TextureVkImpl *pDstTexture, Uint32 DstSubResIndex, Uint32 DstX, Uint32 DstY, Uint32 DstZ)
+ void DeviceContextVkImpl::CopyTextureRegion(TextureVkImpl *pSrcTexture, TextureVkImpl *pDstTexture, const VkImageCopy &CopyRegion)
{
- auto pCmdCtx = RequestCmdContext();
- pCmdCtx->TransitionResource(pSrcTexture, Vk_RESOURCE_STATE_COPY_SOURCE);
- pCmdCtx->TransitionResource(pDstTexture, Vk_RESOURCE_STATE_COPY_DEST, true);
-
- Vk_TEXTURE_COPY_LOCATION DstLocation = {}, SrcLocation = {};
-
- DstLocation.Type = Vk_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
- DstLocation.pResource = pDstTexture->GetVkResource();
- DstLocation.SubresourceIndex = DstSubResIndex;
-
- SrcLocation.Type = Vk_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
- SrcLocation.pResource = pSrcTexture->GetVkResource();
- SrcLocation.SubresourceIndex = SrcSubResIndex;
-
- pCmdCtx->GetCommandList()->CopyTextureRegion( &DstLocation, DstX, DstY, DstZ, &SrcLocation, pVkSrcBox);
+ EnsureVkCmdBuffer();
+ if(pSrcTexture->GetLayout() != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL)
+ {
+ TransitionImageLayout(*pSrcTexture, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
+ }
+ if(pDstTexture->GetLayout() != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL)
+ {
+ TransitionImageLayout(*pDstTexture, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
+ }
+ // srcImageLayout must be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL
+ // dstImageLayout must be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL (18.3)
+ m_CommandBuffer.CopyImage(pSrcTexture->GetVkImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, pDstTexture->GetVkImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &CopyRegion);
++m_State.NumCommands;
}
+#if 0
void DeviceContextVkImpl::CopyTextureRegion(IBuffer *pSrcBuffer, Uint32 SrcStride, Uint32 SrcDepthStride, class TextureVkImpl *pTextureVk, Uint32 DstSubResIndex, const Box &DstBox)
{
auto *pBufferVk = ValidatedCast<BufferVkImpl>(pSrcBuffer);
@@ -1036,6 +1032,7 @@ namespace Diligent
}
}
#endif
+
void DeviceContextVkImpl::GenerateMips(TextureViewVkImpl *pTexView)
{
#if 0
diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
index 3696ee54..58f7f394 100644
--- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
@@ -245,12 +245,7 @@ TextureVkImpl :: TextureVkImpl(IReferenceCounters *pRefCounters,
if (FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH)
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
else if (FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL)
- {
- // If image has a depth / stencil format with both depth and stencil components, then the
- // aspectMask member of subresourceRange must include both VK_IMAGE_ASPECT_DEPTH_BIT and
- // VK_IMAGE_ASPECT_STENCIL_BIT (6.7.3)
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
- }
else
aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
@@ -266,7 +261,7 @@ TextureVkImpl :: TextureVkImpl(IReferenceCounters *pRefCounters,
auto MipWidth = std::max(m_Desc.Width >> mip, 1u);
auto MipHeight = std::max(m_Desc.Height >> mip, 1u);
- auto MipDepth = std::max(m_Desc.Depth >> mip, 1u);
+ auto MipDepth = (m_Desc.Type == RESOURCE_DIM_TEX_3D) ? std::max(m_Desc.Depth >> mip, 1u) : 1u;
CopyRegion.bufferOffset = uploadBufferSize; // offset in bytes from the start of the buffer object
// bufferRowLength and bufferImageHeight specify the data in buffer memory as a subregion
@@ -551,7 +546,7 @@ void TextureVkImpl::UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint3
return;
}
- VERIFY( m_Desc.Usage == USAGE_DEFAULT, "Only default usage resiurces can be updated with UpdateData()" );
+ VERIFY( m_Desc.Usage == USAGE_DEFAULT, "Only default usage resources can be updated with UpdateData()" );
#if 0
auto *pCtxVk = ValidatedCast<DeviceContextVkImpl>(pContext);
@@ -563,40 +558,67 @@ void TextureVkImpl::UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint3
}
void TextureVkImpl :: CopyData(IDeviceContext *pContext,
- ITexture *pSrcTexture,
- Uint32 SrcMipLevel,
- Uint32 SrcSlice,
- const Box *pSrcBox,
- Uint32 DstMipLevel,
- Uint32 DstSlice,
- Uint32 DstX,
- Uint32 DstY,
- Uint32 DstZ)
+ ITexture *pSrcTexture,
+ Uint32 SrcMipLevel,
+ Uint32 SrcSlice,
+ const Box *pSrcBox,
+ Uint32 DstMipLevel,
+ Uint32 DstSlice,
+ Uint32 DstX,
+ Uint32 DstY,
+ Uint32 DstZ)
{
TTextureBase::CopyData( pContext, pSrcTexture, SrcMipLevel, SrcSlice, pSrcBox,
DstMipLevel, DstSlice, DstX, DstY, DstZ );
-#if 0
- auto *pCtxVk = ValidatedCast<DeviceContextVkImpl>(pContext);
auto *pSrcTexVk = ValidatedCast<TextureVkImpl>( pSrcTexture );
-
- Vk_BOX VkSrcBox, *pVkSrcBox = nullptr;
+ VkImageCopy CopyRegion = {};
if( pSrcBox )
{
- VkSrcBox.left = pSrcBox->MinX;
- VkSrcBox.right = pSrcBox->MaxX;
- VkSrcBox.top = pSrcBox->MinY;
- VkSrcBox.bottom = pSrcBox->MaxY;
- VkSrcBox.front = pSrcBox->MinZ;
- VkSrcBox.back = pSrcBox->MaxZ;
- pVkSrcBox = &VkSrcBox;
+ CopyRegion.srcOffset.x = pSrcBox->MinX;
+ CopyRegion.srcOffset.y = pSrcBox->MinY;
+ CopyRegion.srcOffset.z = pSrcBox->MinZ;
+ CopyRegion.extent.width = pSrcBox->MaxX - pSrcBox->MinX;
+ CopyRegion.extent.height = std::max(pSrcBox->MaxY - pSrcBox->MinY, 1u);
+ CopyRegion.extent.depth = std::max(pSrcBox->MaxZ - pSrcBox->MinZ, 1u);
+ }
+ else
+ {
+ CopyRegion.srcOffset = VkOffset3D{0,0,0};
+ CopyRegion.extent.width = std::max(m_Desc.Width >> SrcMipLevel, 1u);
+ CopyRegion.extent.height = std::max(m_Desc.Height >> SrcMipLevel, 1u);
+ if(m_Desc.Type == RESOURCE_DIM_TEX_3D)
+ CopyRegion.extent.depth = std::max(m_Desc.Depth >> SrcMipLevel, 1u);
+ else
+ CopyRegion.extent.depth = 1;
}
- auto DstSubResIndex = VkCalcSubresource(DstMipLevel, DstSlice, 0, m_Desc.MipLevels, m_Desc.ArraySize);
- auto SrcSubResIndex = VkCalcSubresource(SrcMipLevel, SrcSlice, 0, pSrcTexVk->m_Desc.MipLevels, pSrcTexVk->m_Desc.ArraySize);
- pCtxVk->CopyTextureRegion(pSrcTexVk, SrcSubResIndex, pVkSrcBox, this, DstSubResIndex, DstX, DstY, DstZ);
-#endif
+ const auto& FmtAttribs = GetDevice()->GetTextureFormatInfo(m_Desc.Format);
+ VkImageAspectFlags aspectMask = 0;
+ if (FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH)
+ aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
+ else if (FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL)
+ aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
+ else
+ aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+
+ CopyRegion.srcSubresource.baseArrayLayer = SrcSlice;
+ CopyRegion.srcSubresource.layerCount = 1;
+ CopyRegion.srcSubresource.mipLevel = SrcMipLevel;
+ CopyRegion.srcSubresource.aspectMask = aspectMask;
+
+ CopyRegion.dstSubresource.baseArrayLayer = DstSlice;
+ CopyRegion.dstSubresource.layerCount = 1;
+ CopyRegion.dstSubresource.mipLevel = DstMipLevel;
+ CopyRegion.dstSubresource.aspectMask = aspectMask;
+
+ CopyRegion.dstOffset.x = DstX;
+ CopyRegion.dstOffset.y = DstY;
+ CopyRegion.dstOffset.z = DstZ;
+
+ auto *pCtxVk = ValidatedCast<DeviceContextVkImpl>(pContext);
+ pCtxVk->CopyTextureRegion(pSrcTexVk, this, CopyRegion);
}
void TextureVkImpl :: Map(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData)