add texture copy block size workaround

This commit is contained in:
Samuliak 2025-01-12 18:05:24 +01:00
parent aec7a182ce
commit 21bc5f247b
No known key found for this signature in database

View file

@ -762,6 +762,18 @@ void MetalRenderer::texture_setLatteTexture(LatteTextureView* textureView, uint3
void MetalRenderer::texture_copyImageSubData(LatteTexture* src, sint32 srcMip, sint32 effectiveSrcX, sint32 effectiveSrcY, sint32 srcSlice, LatteTexture* dst, sint32 dstMip, sint32 effectiveDstX, sint32 effectiveDstY, sint32 dstSlice, sint32 effectiveCopyWidth, sint32 effectiveCopyHeight, sint32 srcDepth_)
{
// Source size seems to apply to the destination texture as well, therefore we need to adjust it when block size doesn't match
Uvec2 srcBlockTexelSize = GetMtlPixelFormatInfo(src->format, src->isDepth).blockTexelSize;
Uvec2 dstBlockTexelSize = GetMtlPixelFormatInfo(dst->format, dst->isDepth).blockTexelSize;
if (srcBlockTexelSize.x != dstBlockTexelSize.x || srcBlockTexelSize.y != dstBlockTexelSize.y)
{
uint32 multX = (srcBlockTexelSize.x > dstBlockTexelSize.x ? srcBlockTexelSize.x / dstBlockTexelSize.x : dstBlockTexelSize.x / srcBlockTexelSize.x);
effectiveCopyWidth *= multX;
uint32 multY = (srcBlockTexelSize.y > dstBlockTexelSize.y ? srcBlockTexelSize.y / dstBlockTexelSize.y : dstBlockTexelSize.y / srcBlockTexelSize.y);
effectiveCopyHeight *= multY;
}
auto blitCommandEncoder = GetBlitCommandEncoder();
auto mtlSrc = static_cast<LatteTextureMtl*>(src)->GetTexture();