Skip to content

Commit

Permalink
Fixed the texture extents when doing a reinterpret copy between block…
Browse files Browse the repository at this point in the history
…-compressed and uint textures on Vulkan.
  • Loading branch information
apanteleev committed Jan 6, 2024
1 parent 3f62a4f commit 0884149
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/vulkan/vulkan-texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ namespace nvrhi::vulkan

const auto& dstSubresourceView = dst->getSubresourceView(dstSubresource, TextureDimension::Unknown, Format::UNKNOWN);

// When copying between block-compressed and uint textures, the extents and offsets are scaled by the block size.
// To simplify the logic here, assume that one of (src, dst) is compressed, therefore its extents are smaller, and use that.
// See https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdCopyImage.html
const VkExtent3D extent = vk::Extent3D(
std::min(resolvedSrcSlice.width, resolvedDstSlice.width),
std::min(resolvedSrcSlice.height, resolvedDstSlice.height),
std::min(resolvedSrcSlice.depth, resolvedDstSlice.depth));

auto imageCopy = vk::ImageCopy()
.setSrcSubresource(vk::ImageSubresourceLayers()
.setAspectMask(srcSubresourceView.subresourceRange.aspectMask)
Expand All @@ -417,9 +425,8 @@ namespace nvrhi::vulkan
.setBaseArrayLayer(dstSubresource.baseArraySlice)
.setLayerCount(dstSubresource.numArraySlices))
.setDstOffset(vk::Offset3D(resolvedDstSlice.x, resolvedDstSlice.y, resolvedDstSlice.z))
.setExtent(vk::Extent3D(resolvedDstSlice.width, resolvedDstSlice.height, resolvedDstSlice.depth));


.setExtent(extent);

if (m_EnableAutomaticBarriers)
{
requireTextureState(src, TextureSubresourceSet(resolvedSrcSlice.mipLevel, 1, resolvedSrcSlice.arraySlice, 1), ResourceStates::CopySource);
Expand Down

0 comments on commit 0884149

Please sign in to comment.