From c6ee689159af0b88d36327f6a90f3b0f3ed96150 Mon Sep 17 00:00:00 2001 From: gibbed Date: Sat, 12 May 2018 02:30:49 -0500 Subject: [PATCH] [Vulkan] Rework GetMipByteSize to properly handle linear textures. Probably breaks everything. --- src/xenia/gpu/texture_info.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/xenia/gpu/texture_info.cc b/src/xenia/gpu/texture_info.cc index 10af34067..999fff639 100644 --- a/src/xenia/gpu/texture_info.cc +++ b/src/xenia/gpu/texture_info.cc @@ -471,11 +471,21 @@ uint32_t TextureInfo::GetMipByteSize(const TextureInfo& src, uint32_t mip) { xe::round_up(logical_height, src.format_info()->block_height) / src.format_info()->block_height; - uint32_t size = block_width * block_height * bytes_per_block; + if (src.is_tiled) { + // If the texture is tiled, its dimensions must be a multiple of tile + // dimensions (32x32 blocks). + block_width = xe::round_up(block_width, 32); + block_height = xe::round_up(block_height, 32); + } - // Minimum of one tile, which is 32x32 blocks. - uint32_t tile_size = 32 * 32 * bytes_per_block; - return std::max(size, tile_size) * (src.depth + 1); + uint32_t byte_pitch = block_width * bytes_per_block; + + if (!src.is_tiled) { + // Each row must be a multiple of 256 in linear textures. + byte_pitch = xe::round_up(byte_pitch, 256); + } + + return byte_pitch * block_height; } uint32_t TextureInfo::GetMipLinearSize(const TextureInfo& src, uint32_t mip) {