diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-10-01 00:01:15 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-10-01 00:01:15 +0000 |
| commit | 3941b472dedd0836b5e4970460fbf0e38a42e4e4 (patch) | |
| tree | fc4d0002e0c17cab1f09f4f1955e80c2b5fa4ce0 /Graphics/GraphicsEngineVulkan | |
| parent | Updated Metal interfaces plus a number of misc fixes (diff) | |
| download | DiligentCore-3941b472dedd0836b5e4970460fbf0e38a42e4e4.tar.gz DiligentCore-3941b472dedd0836b5e4970460fbf0e38a42e4e4.zip | |
A number of updates to support Metal backend
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
3 files changed, 16 insertions, 44 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.hpp index 39eb7ec1..b04babec 100644 --- a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.hpp @@ -42,8 +42,6 @@ namespace Diligent class FixedBlockMemoryAllocator; -Uint32 GetStagingDataOffset(const TextureDesc& TexDesc, Uint32 ArraySlice, Uint32 MipLevel, Uint32 Alignment = 4); - /// Texture object implementation in Vulkan backend. class TextureVkImpl final : public TextureBase<ITextureVk, RenderDeviceVkImpl, TextureViewVkImpl, FixedBlockMemoryAllocator> { @@ -101,6 +99,12 @@ public: void InvalidateStagingRange(VkDeviceSize Offset, VkDeviceSize Size); + // bufferOffset must be a multiple of 4 (18.4) + // If the calling command's VkImage parameter is a compressed image, bufferOffset + // must be a multiple of the compressed texel block size in bytes (18.4). This + // is automatically guaranteed as MipWidth and MipHeight are rounded to block size. + static constexpr Uint32 StagingDataAlignment = 4; + protected: void CreateViewInternal(const struct TextureViewDesc& ViewDesc, ITextureView** ppView, bool bIsDefaultView) override; //void PrepareVkInitData(const TextureData &InitData, Uint32 NumSubresources, std::vector<Vk_SUBRESOURCE_DATA> &VkInitData); diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index cd5d0901..f14e7f9c 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1634,7 +1634,7 @@ void DeviceContextVkImpl::CopyTexture(const CopyTextureAttribs& CopyAttribs) DEV_CHECK_ERR((SrcTexDesc.CPUAccessFlags & CPU_ACCESS_WRITE), "Attempting to copy from staging texture that was not created with CPU_ACCESS_WRITE flag"); DEV_CHECK_ERR(pSrcTexVk->GetState() == RESOURCE_STATE_COPY_SOURCE, "Source staging texture must permanently be in RESOURCE_STATE_COPY_SOURCE state"); - auto SrcBufferOffset = GetStagingDataOffset(SrcTexDesc, CopyAttribs.SrcSlice, CopyAttribs.SrcMipLevel); + auto SrcBufferOffset = GetStagingTextureSubresOffset(SrcTexDesc, CopyAttribs.SrcSlice, CopyAttribs.SrcMipLevel, TextureVkImpl::StagingDataAlignment); auto SrcMipLevelAttribs = GetMipLevelProperties(SrcTexDesc, CopyAttribs.SrcMipLevel); // address of (x,y,z) = region->bufferOffset + (((z * imageHeight) + y) * rowLength + x) * texelBlockSize; (18.4.1) SrcBufferOffset += @@ -1667,8 +1667,10 @@ void DeviceContextVkImpl::CopyTexture(const CopyTextureAttribs& CopyAttribs) DEV_CHECK_ERR((DstTexDesc.CPUAccessFlags & CPU_ACCESS_READ), "Attempting to copy to staging texture that was not created with CPU_ACCESS_READ flag"); DEV_CHECK_ERR(pDstTexVk->GetState() == RESOURCE_STATE_COPY_DEST, "Destination staging texture must permanently be in RESOURCE_STATE_COPY_DEST state"); - auto DstBufferOffset = GetStagingDataOffset(DstTexDesc, CopyAttribs.DstSlice, CopyAttribs.DstMipLevel); - auto DstMipLevelAttribs = GetMipLevelProperties(DstTexDesc, CopyAttribs.DstMipLevel); + auto DstBufferOffset = + GetStagingTextureSubresOffset(DstTexDesc, CopyAttribs.DstSlice, CopyAttribs.DstMipLevel, + TextureVkImpl::StagingDataAlignment); + const auto DstMipLevelAttribs = GetMipLevelProperties(DstTexDesc, CopyAttribs.DstMipLevel); // address of (x,y,z) = region->bufferOffset + (((z * imageHeight) + y) * rowLength + x) * texelBlockSize; (18.4.1) DstBufferOffset += // For compressed-block formats, RowSize is the size of one compressed row. @@ -2007,8 +2009,10 @@ void DeviceContextVkImpl::MapTextureSubresource(ITexture* pTextu } else if (TexDesc.Usage == USAGE_STAGING) { - auto SubresourceOffset = GetStagingDataOffset(TexDesc, ArraySlice, MipLevel); - auto MipLevelAttribs = GetMipLevelProperties(TexDesc, MipLevel); + auto SubresourceOffset = + GetStagingTextureSubresOffset(TexDesc, ArraySlice, MipLevel, + TextureVkImpl::StagingDataAlignment); + const auto MipLevelAttribs = GetMipLevelProperties(TexDesc, MipLevel); // address of (x,y,z) = region->bufferOffset + (((z * imageHeight) + y) * rowLength + x) * texelBlockSize; (18.4.1) auto MapStartOffset = SubresourceOffset + // For compressed-block formats, RowSize is the size of one compressed row. diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index ca04f900..8a37df0c 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -408,7 +408,7 @@ TextureVkImpl::TextureVkImpl(IReferenceCounters* pRefCounters, VkStagingBuffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; VkStagingBuffCI.pNext = nullptr; VkStagingBuffCI.flags = 0; - VkStagingBuffCI.size = GetStagingDataOffset(m_Desc, m_Desc.ArraySize, 0); + VkStagingBuffCI.size = GetStagingTextureSubresOffset(m_Desc, m_Desc.ArraySize, 0, StagingDataAlignment); // clang-format off DEV_CHECK_ERR((m_Desc.CPUAccessFlags & (CPU_ACCESS_READ | CPU_ACCESS_WRITE)) == CPU_ACCESS_READ || @@ -470,42 +470,6 @@ TextureVkImpl::TextureVkImpl(IReferenceCounters* pRefCounters, VERIFY_EXPR(IsInKnownState()); } -Uint32 GetStagingDataOffset(const TextureDesc& TexDesc, Uint32 ArraySlice, Uint32 MipLevel, Uint32 Alignment) -{ - VERIFY_EXPR(ArraySlice < TexDesc.ArraySize && MipLevel < TexDesc.MipLevels || ArraySlice == TexDesc.ArraySize && MipLevel == 0); - - Uint32 Offset = 0; - if (ArraySlice > 0) - { - Uint32 ArraySliceSize = 0; - for (Uint32 mip = 0; mip < TexDesc.MipLevels; ++mip) - { - auto MipInfo = GetMipLevelProperties(TexDesc, mip); - // bufferOffset must be a multiple of 4 (18.4) - // If the calling command's VkImage parameter is a compressed image, bufferOffset - // must be a multiple of the compressed texel block size in bytes (18.4). This - // is automatically guaranteed as MipWidth and MipHeight are rounded to block size - ArraySliceSize += Align(MipInfo.MipSize, Alignment); - } - - Offset = ArraySliceSize; - if (TexDesc.Type == RESOURCE_DIM_TEX_1D_ARRAY || - TexDesc.Type == RESOURCE_DIM_TEX_2D_ARRAY || - TexDesc.Type == RESOURCE_DIM_TEX_CUBE || - TexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) - Offset *= ArraySlice; - } - - for (Uint32 mip = 0; mip < MipLevel; ++mip) - { - auto MipInfo = GetMipLevelProperties(TexDesc, mip); - // bufferOffset must be a multiple of 4 (18.4) - Offset += Align(MipInfo.MipSize, Alignment); - } - - return Offset; -} - TextureVkImpl::TextureVkImpl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& TexViewObjAllocator, RenderDeviceVkImpl* pDeviceVk, |
