diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-08-29 15:42:31 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-08-29 15:42:31 +0000 |
| commit | 5e399e3e17973ad1d5efb0de2a9c378ede73f377 (patch) | |
| tree | ef79f8a86fba3eab4192489cf04675967bae17c4 /Graphics/GraphicsEngineVulkan | |
| parent | Added few debug checks (diff) | |
| download | DiligentCore-5e399e3e17973ad1d5efb0de2a9c378ede73f377.tar.gz DiligentCore-5e399e3e17973ad1d5efb0de2a9c378ede73f377.zip | |
Fixed update data for compressed textures
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
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<Uint32>(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<const Uint8*>(pSrcData) @@ -1161,7 +1163,7 @@ namespace Diligent + row * BufferDataStride + slice * BufferDataDepthStride; - memcpy(pDstPtr, pSrcPtr, UpdateRegionWidth * PixelSize); + memcpy(pDstPtr, pSrcPtr, RowSize); } } |
