VK: Fixed update surface size when texture is transcoded.

This commit is contained in:
Branimir Karadžić
2021-11-11 17:39:41 -08:00
parent 67d1cce8f8
commit da8a5ff449
2 changed files with 24 additions and 17 deletions

View File

@@ -5122,7 +5122,7 @@ namespace bgfx { namespace d3d12
bimg::imageDecodeToBgra8(g_allocator, temp, srcData, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat));
srcData = temp;
box.right = bx::max(1u, m_width >> _mip);
box.right = bx::max(1u, m_width >> _mip);
box.bottom = bx::max(1u, m_height >> _mip);
}

View File

@@ -6091,27 +6091,13 @@ VK_DESTROY
if (bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat) ) )
{
const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat) );
rectpitch = (_rect.m_width / blockInfo.blockWidth) * blockInfo.blockSize;
rectpitch = (_rect.m_width / blockInfo.blockWidth ) * blockInfo.blockSize;
slicepitch = (_rect.m_height / blockInfo.blockHeight) * rectpitch;
}
const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch;
const uint32_t size = UINT16_MAX == _pitch ? slicepitch * _depth: _rect.m_height * _pitch * _depth;
const bool convert = m_textureFormat != m_requestedFormat;
uint8_t* data = _mem->data;
uint8_t* temp = NULL;
if (convert)
{
temp = (uint8_t*)BX_ALLOC(g_allocator, slicepitch);
bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat) );
data = temp;
}
VkBuffer stagingBuffer = VK_NULL_HANDLE;
VkDeviceMemory stagingDeviceMem = VK_NULL_HANDLE;
VK_CHECK(s_renderVK->createStagingBuffer(size, &stagingBuffer, &stagingDeviceMem, data) );
VkBufferImageCopy region;
region.bufferOffset = 0;
region.bufferRowLength = (_pitch == UINT16_MAX ? 0 : _pitch * 8 / bpp);
@@ -6120,9 +6106,30 @@ VK_DESTROY
region.imageSubresource.mipLevel = _mip;
region.imageSubresource.baseArrayLayer = 0;
region.imageSubresource.layerCount = 1;
region.imageOffset = { _rect.m_x, _rect.m_y, 0 };
region.imageOffset = { _rect.m_x, _rect.m_y, 0 };
region.imageExtent = { _rect.m_width, _rect.m_height, _depth };
uint8_t* data = _mem->data;
uint8_t* temp = NULL;
if (convert)
{
temp = (uint8_t*)BX_ALLOC(g_allocator, slicepitch);
bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat));
data = temp;
region.imageExtent =
{
bx::max(1u, m_width >> _mip),
bx::max(1u, m_height >> _mip),
_depth,
};
}
VkBuffer stagingBuffer = VK_NULL_HANDLE;
VkDeviceMemory stagingDeviceMem = VK_NULL_HANDLE;
VK_CHECK(s_renderVK->createStagingBuffer(size, &stagingBuffer, &stagingDeviceMem, data) );
if (VK_IMAGE_VIEW_TYPE_3D == m_type)
{
region.imageOffset.z = _z;