From c9661af1a7b9cc643e1adbee0779b0a366bd6189 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Fri, 2 Nov 2018 10:05:58 -0700 Subject: Fixed Vulkan validation error message about incorrect buffer offset alignment for compressed formats --- Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 538467d1..5f93f689 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1219,6 +1219,13 @@ namespace Diligent const auto& DeviceLimits = m_pDevice.RawPtr()->GetPhysicalDevice().GetProperties().limits; // Source buffer offset must be multiple of 4 (18.4) auto BufferOffsetAlignment = std::max(DeviceLimits.optimalBufferCopyOffsetAlignment, VkDeviceSize{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) + const auto& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format); + if (FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED) + { + BufferOffsetAlignment = std::max(BufferOffsetAlignment, VkDeviceSize{FmtAttribs.ComponentSize}); + } auto Allocation = m_UploadHeap.Allocate(CopyInfo.MemorySize, BufferOffsetAlignment); // The allocation will stay in the upload heap until the end of the frame at which point all upload // pages will be discarded @@ -1342,6 +1349,13 @@ namespace Diligent const auto& DeviceLimits = m_pDevice.RawPtr()->GetPhysicalDevice().GetProperties().limits; // Source buffer offset must be multiple of 4 (18.4) auto Alignment = std::max(DeviceLimits.optimalBufferCopyOffsetAlignment, VkDeviceSize{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) + const auto& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format); + if (FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED) + { + Alignment = std::max(Alignment, VkDeviceSize{FmtAttribs.ComponentSize}); + } auto Allocation = AllocateDynamicSpace(CopyInfo.MemorySize, static_cast(Alignment)); MappedData.pData = reinterpret_cast(Allocation.pDynamicMemMgr->GetCPUAddress()) + Allocation.AlignedOffset; -- cgit v1.2.3