From 5e399e3e17973ad1d5efb0de2a9c378ede73f377 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 29 Aug 2018 08:42:31 -0700 Subject: Fixed update data for compressed textures --- .../GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index b389141f..7fc80d8a 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1135,21 +1135,23 @@ namespace Diligent VERIFY(TexDesc.SampleCount == 1, "Only single-sample textures can be updated with vkCmdCopyBufferToImage()"); const auto& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format); VERIFY_EXPR(DstBox.MaxX > DstBox.MinX && DstBox.MaxY > DstBox.MinY && DstBox.MaxZ > DstBox.MinZ); - auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; - auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; - auto UpdateRegionDepth = DstBox.MaxZ - DstBox.MinZ; - auto PixelSize = Uint32{FmtAttribs.ComponentSize} * Uint32{FmtAttribs.NumComponents}; - auto BufferDataStride = UpdateRegionWidth * PixelSize; - auto BufferDataDepthStride = UpdateRegionHeight * BufferDataStride; - VERIFY(SrcStride >= UpdateRegionWidth * PixelSize, "Source data stride (", SrcStride, ") is below the image row width (", UpdateRegionWidth * PixelSize, ")"); + const auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; + const auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; + const auto UpdateRegionDepth = DstBox.MaxZ - DstBox.MinZ; + const Uint32 RowSize = FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED ? + UpdateRegionWidth / Uint32{FmtAttribs.BlockWidth} * Uint32{FmtAttribs.ComponentSize} : + UpdateRegionWidth * Uint32{FmtAttribs.ComponentSize} * Uint32{FmtAttribs.NumComponents}; + VERIFY(SrcStride >= RowSize, "Source data stride (", SrcStride, ") is below the image row size (", RowSize, ")"); VERIFY(SrcDepthStride == 0 || SrcDepthStride >= SrcStride * UpdateRegionHeight, "Source data depth stride (", SrcDepthStride, ") is below the image plane size (", SrcStride * UpdateRegionHeight, ")"); + const auto BufferDataStride = RowSize; + const auto BufferDataDepthStride = UpdateRegionHeight * BufferDataStride; auto MemorySize = UpdateRegionDepth * BufferDataDepthStride; size_t Alignment = 4; auto UploadSpace = AllocateDynamicSpace(MemorySize + static_cast(Alignment)); auto AlignedOffset = (UploadSpace.Offset + (Alignment-1)) & ~(Alignment-1); for(Uint32 slice = 0; slice < UpdateRegionDepth; ++slice) { - for(Uint32 row = 0; row < UpdateRegionHeight; ++row) + for(Uint32 row = 0; row < UpdateRegionHeight / FmtAttribs.BlockHeight; ++row) { const auto* pSrcPtr = reinterpret_cast(pSrcData) @@ -1161,7 +1163,7 @@ namespace Diligent + row * BufferDataStride + slice * BufferDataDepthStride; - memcpy(pDstPtr, pSrcPtr, UpdateRegionWidth * PixelSize); + memcpy(pDstPtr, pSrcPtr, RowSize); } } -- cgit v1.2.3