summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-08-07 02:56:24 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-08-07 02:56:24 +0000
commit87a8af6362b241f99fa578b952b364acb42c755c (patch)
tree8f59ad5ae054d9fa64551dd6d29cb6d8b8c67938 /Graphics/GraphicsEngineVulkan
parentMoved Troubleshooting.md to main repo (diff)
downloadDiligentCore-87a8af6362b241f99fa578b952b364acb42c755c.tar.gz
DiligentCore-87a8af6362b241f99fa578b952b364acb42c755c.zip
Fixed issue with logical vs storage texture size for block-compressed formats
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp24
-rw-r--r--Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp16
2 files changed, 21 insertions, 19 deletions
diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
index 1162725c..3a3c301a 100644
--- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
@@ -1336,8 +1336,8 @@ namespace Diligent
if (pSrcBox == nullptr)
{
auto MipLevelAttribs = GetMipLevelProperties(SrcTexDesc, CopyAttribs.SrcMipLevel);
- FullMipBox.MaxX = MipLevelAttribs.Width;
- FullMipBox.MaxY = MipLevelAttribs.Height;
+ FullMipBox.MaxX = MipLevelAttribs.LogicalWidth;
+ FullMipBox.MaxY = MipLevelAttribs.LogicalHeight;
FullMipBox.MaxZ = MipLevelAttribs.Depth;
pSrcBox = &FullMipBox;
}
@@ -1390,7 +1390,7 @@ namespace Diligent
SrcBufferOffset +=
// For compressed-block formats, RowSize is the size of one compressed row.
// For non-compressed formats, BlockHeight is 1.
- (pSrcBox->MinZ * SrcMipLevelAttribs.Height + pSrcBox->MinY) / SrcFmtAttribs.BlockHeight * SrcMipLevelAttribs.RowSize +
+ (pSrcBox->MinZ * SrcMipLevelAttribs.StorageHeight + pSrcBox->MinY) / SrcFmtAttribs.BlockHeight * SrcMipLevelAttribs.RowSize +
// For non-compressed formats, BlockWidth is 1.
(pSrcBox->MinX / SrcFmtAttribs.BlockWidth) * SrcFmtAttribs.GetElementSize();
@@ -1405,7 +1405,7 @@ namespace Diligent
CopyBufferToTexture(
pSrcTexVk->GetVkStagingBuffer(),
SrcBufferOffset,
- SrcMipLevelAttribs.Width,
+ SrcMipLevelAttribs.StorageWidth,
*pDstTexVk,
DstBox,
CopyAttribs.DstMipLevel,
@@ -1424,7 +1424,7 @@ namespace Diligent
DstBufferOffset +=
// For compressed-block formats, RowSize is the size of one compressed row.
// For non-compressed formats, BlockHeight is 1.
- (CopyAttribs.DstZ * DstMipLevelAttribs.Height + CopyAttribs.DstY) / DstFmtAttribs.BlockHeight * DstMipLevelAttribs.RowSize *
+ (CopyAttribs.DstZ * DstMipLevelAttribs.StorageHeight + CopyAttribs.DstY) / DstFmtAttribs.BlockHeight * DstMipLevelAttribs.RowSize *
// For non-compressed formats, BlockWidth is 1.
(CopyAttribs.DstX / DstFmtAttribs.BlockWidth) * DstFmtAttribs.GetElementSize();
@@ -1436,7 +1436,7 @@ namespace Diligent
CopyAttribs.SrcTextureTransitionMode,
pDstTexVk->GetVkStagingBuffer(),
DstBufferOffset,
- DstMipLevelAttribs.Width
+ DstMipLevelAttribs.StorageWidth
);
}
else
@@ -1717,8 +1717,8 @@ namespace Diligent
if (pMapRegion == nullptr)
{
auto MipLevelAttribs = GetMipLevelProperties(TexDesc, MipLevel);
- FullExtentBox.MaxX = MipLevelAttribs.Width;
- FullExtentBox.MaxY = MipLevelAttribs.Height;
+ FullExtentBox.MaxX = MipLevelAttribs.LogicalWidth;
+ FullExtentBox.MaxY = MipLevelAttribs.LogicalHeight;
FullExtentBox.MaxZ = MipLevelAttribs.Depth;
pMapRegion = &FullExtentBox;
}
@@ -1770,7 +1770,7 @@ namespace Diligent
auto MapStartOffset = SubresourceOffset +
// For compressed-block formats, RowSize is the size of one compressed row.
// For non-compressed formats, BlockHeight is 1.
- (pMapRegion->MinZ * MipLevelAttribs.Height + pMapRegion->MinY) / FmtAttribs.BlockHeight * MipLevelAttribs.RowSize +
+ (pMapRegion->MinZ * MipLevelAttribs.StorageHeight + pMapRegion->MinY) / FmtAttribs.BlockHeight * MipLevelAttribs.RowSize +
// For non-compressed formats, BlockWidth is 1.
pMapRegion->MinX / FmtAttribs.BlockWidth * FmtAttribs.GetElementSize();
@@ -1784,9 +1784,11 @@ namespace Diligent
// Reaback memory is not created with HOST_COHERENT flag, so we have to explicitly invalidate the mapped range
// to make device writes visible to CPU reads
VERIFY_EXPR(pMapRegion->MaxZ >= 1 && pMapRegion->MaxY >= 1);
+ auto BlockAlignedMaxX = Align(pMapRegion->MaxX, Uint32{FmtAttribs.BlockWidth});
+ auto BlockAlignedMaxY = Align(pMapRegion->MaxY, Uint32{FmtAttribs.BlockHeight});
auto MapEndOffset = SubresourceOffset +
- ((pMapRegion->MaxZ-1) * MipLevelAttribs.Height + (pMapRegion->MaxY-FmtAttribs.BlockHeight)) / FmtAttribs.BlockHeight * MipLevelAttribs.RowSize +
- (pMapRegion->MaxX / FmtAttribs.BlockWidth) * FmtAttribs.GetElementSize();
+ ((pMapRegion->MaxZ-1) * MipLevelAttribs.StorageHeight + (BlockAlignedMaxY - FmtAttribs.BlockHeight)) / FmtAttribs.BlockHeight * MipLevelAttribs.RowSize +
+ (BlockAlignedMaxX / FmtAttribs.BlockWidth) * FmtAttribs.GetElementSize();
TextureVk.InvalidateStagingRange(MapStartOffset, MapEndOffset - MapStartOffset);
}
else if (MapType == MAP_WRITE)
diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
index dfed36b9..4aa96367 100644
--- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
@@ -243,7 +243,7 @@ TextureVkImpl :: TextureVkImpl(IReferenceCounters* pRefCounters,
CopyRegion.bufferImageHeight = 0;
// For block-compression formats, all parameters are still specified in texels rather than compressed texel blocks (18.4.1)
CopyRegion.imageOffset = VkOffset3D{0, 0, 0};
- CopyRegion.imageExtent = VkExtent3D{MipInfo.Width, MipInfo.Height, MipInfo.Depth};
+ CopyRegion.imageExtent = VkExtent3D{MipInfo.LogicalWidth, MipInfo.LogicalHeight, MipInfo.Depth};
CopyRegion.imageSubresource.aspectMask = aspectMask;
CopyRegion.imageSubresource.mipLevel = mip;
@@ -252,7 +252,7 @@ TextureVkImpl :: TextureVkImpl(IReferenceCounters* pRefCounters,
VERIFY(SubResData.Stride == 0 || SubResData.Stride >= MipInfo.RowSize, "Stride is too small");
// For compressed-block formats, MipInfo.RowSize is the size of one row of blocks
- VERIFY(SubResData.DepthStride == 0 || SubResData.DepthStride >= (MipInfo.Height / FmtAttribs.BlockHeight) * MipInfo.RowSize, "Depth stride is too small");
+ VERIFY(SubResData.DepthStride == 0 || SubResData.DepthStride >= (MipInfo.StorageHeight / FmtAttribs.BlockHeight) * MipInfo.RowSize, "Depth stride is too small");
// bufferOffset must be a multiple of 4 (18.4)
// If the calling command's VkImage parameter is a compressed image, bufferOffset
@@ -303,19 +303,19 @@ TextureVkImpl :: TextureVkImpl(IReferenceCounters* pRefCounters,
auto MipInfo = GetMipLevelProperties(m_Desc, mip);
- VERIFY_EXPR(MipInfo.Width == CopyRegion.imageExtent.width);
- VERIFY_EXPR(MipInfo.Height == CopyRegion.imageExtent.height);
- VERIFY_EXPR(MipInfo.Depth == CopyRegion.imageExtent.depth);
+ VERIFY_EXPR(MipInfo.LogicalWidth == CopyRegion.imageExtent.width);
+ VERIFY_EXPR(MipInfo.LogicalHeight == CopyRegion.imageExtent.height);
+ VERIFY_EXPR(MipInfo.Depth == CopyRegion.imageExtent.depth);
VERIFY(SubResData.Stride == 0 || SubResData.Stride >= MipInfo.RowSize, "Stride is too small");
// For compressed-block formats, MipInfo.RowSize is the size of one row of blocks
- VERIFY(SubResData.DepthStride == 0 || SubResData.DepthStride >= (MipInfo.Height / FmtAttribs.BlockHeight) * MipInfo.RowSize, "Depth stride is too small");
+ VERIFY(SubResData.DepthStride == 0 || SubResData.DepthStride >= (MipInfo.StorageHeight / FmtAttribs.BlockHeight) * MipInfo.RowSize, "Depth stride is too small");
for(Uint32 z=0; z < MipInfo.Depth; ++z)
{
- for(Uint32 y=0; y < MipInfo.Height; y += FmtAttribs.BlockHeight)
+ for(Uint32 y=0; y < MipInfo.StorageHeight; y += FmtAttribs.BlockHeight)
{
- memcpy(StagingData + CopyRegion.bufferOffset + ((y + z * MipInfo.Height) / FmtAttribs.BlockHeight) * MipInfo.RowSize,
+ memcpy(StagingData + CopyRegion.bufferOffset + ((y + z * MipInfo.StorageHeight) / FmtAttribs.BlockHeight) * MipInfo.RowSize,
// SubResData.Stride must be the stride of one row of compressed blocks
reinterpret_cast<const uint8_t*>(SubResData.pData) + (y/FmtAttribs.BlockHeight) * SubResData.Stride + z * SubResData.DepthStride,
MipInfo.RowSize);