From b4e6f81cb5ae108ff77cdee0332b561175278049 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Wed, 14 Jul 2021 22:01:11 +0200 Subject: [PATCH] [d3d9] Respect aligned pitch when using initial data --- src/d3d9/d3d9_common_texture.h | 6 ++--- src/d3d9/d3d9_initializer.cpp | 40 ++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/d3d9/d3d9_common_texture.h b/src/d3d9/d3d9_common_texture.h index f40ecf9fe..8bd2a0773 100644 --- a/src/d3d9/d3d9_common_texture.h +++ b/src/d3d9/d3d9_common_texture.h @@ -413,6 +413,9 @@ namespace dxvk { return m_dirtyBoxes[layer]; } + static VkImageType GetImageTypeFromResourceType( + D3DRESOURCETYPE Dimension); + private: D3D9DeviceEx* m_device; @@ -490,9 +493,6 @@ namespace dxvk { VkImageLayout OptimizeLayout( VkImageUsageFlags Usage) const; - static VkImageType GetImageTypeFromResourceType( - D3DRESOURCETYPE Dimension); - static VkImageViewType GetImageViewTypeFromResourceType( D3DRESOURCETYPE Dimension, UINT Layer); diff --git a/src/d3d9/d3d9_initializer.cpp b/src/d3d9/d3d9_initializer.cpp index 806fe0804..d3076954a 100644 --- a/src/d3d9/d3d9_initializer.cpp +++ b/src/d3d9/d3d9_initializer.cpp @@ -131,18 +131,36 @@ namespace dxvk { // If the buffer is mapped, we can write data directly // to the mapped memory region instead of doing it on // the GPU. Same goes for zero-initialization. - for (uint32_t i = 0; i < pTexture->CountSubresources(); i++) { - DxvkBufferSliceHandle mapSlice = pTexture->GetBuffer(i)->getSliceHandle(); + const D3D9_COMMON_TEXTURE_DESC* desc = pTexture->Desc(); + for (uint32_t a = 0; a < desc->ArraySize; a++) { + for (uint32_t m = 0; m < desc->MipLevels; m++) { + uint32_t subresource = pTexture->CalcSubresource(a, m); + DxvkBufferSliceHandle mapSlice = pTexture->GetBuffer(subresource)->getSliceHandle(); - if (pInitialData != nullptr) { - std::memcpy( - mapSlice.mapPtr, - pInitialData, - mapSlice.length); - } else { - std::memset( - mapSlice.mapPtr, 0, - mapSlice.length); + if (pInitialData != nullptr) { + VkExtent3D mipExtent = pTexture->GetExtentMip(m); + const DxvkFormatInfo* formatInfo = imageFormatInfo(pTexture->GetFormatMapping().FormatColor); + VkExtent3D blockCount = util::computeBlockCount(mipExtent, formatInfo->blockSize); + uint32_t pitch = blockCount.width * formatInfo->elementSize; + uint32_t alignedPitch = align(pitch, 4); + + util::packImageData( + mapSlice.mapPtr, + pInitialData, + pitch, + pitch * blockCount.height, + alignedPitch, + alignedPitch * blockCount.height, + D3D9CommonTexture::GetImageTypeFromResourceType(pTexture->GetType()), + mipExtent, + pTexture->Desc()->ArraySize, + formatInfo, + VK_IMAGE_ASPECT_COLOR_BIT); + } else { + std::memset( + mapSlice.mapPtr, 0, + mapSlice.length); + } } } }