From da62e0e044da36524bfb17671f88b73c804ef6a4 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Tue, 8 May 2018 10:07:44 -0500 Subject: [PATCH] [GPU] Rename TextureInfo::size_xx -> TextureInfo::size --- src/xenia/gpu/texture_info.cc | 133 +++++++++++++------------- src/xenia/gpu/texture_info.h | 42 +++----- src/xenia/gpu/vulkan/texture_cache.cc | 57 ++++++----- 3 files changed, 108 insertions(+), 124 deletions(-) diff --git a/src/xenia/gpu/texture_info.cc b/src/xenia/gpu/texture_info.cc index 27d86d124..bb478728f 100644 --- a/src/xenia/gpu/texture_info.cc +++ b/src/xenia/gpu/texture_info.cc @@ -122,25 +122,24 @@ bool TextureInfo::PrepareResolve(uint32_t physical_address, } void TextureInfo::CalculateTextureSizes1D(uint32_t width) { - size_1d.logical_width = width; + size.logical_width = width; auto format = format_info(); // width in blocks. - uint32_t block_width = - xe::round_up(size_1d.logical_width, format->block_width) / - format->block_width; + uint32_t block_width = xe::round_up(size.logical_width, format->block_width) / + format->block_width; if (is_tiled) { // If the texture is tiled, its dimensions must be a multiple of tile // dimensions (32x32 blocks). - size_1d.block_width = xe::round_up(block_width, 32); + size.block_width = xe::round_up(block_width, 32); } else { - size_1d.block_width = block_width; + size.block_width = block_width; } uint32_t bytes_per_block = format->block_width * format->bits_per_pixel / 8; - uint32_t byte_pitch = size_1d.block_width * bytes_per_block; + uint32_t byte_pitch = size.block_width * bytes_per_block; uint32_t texel_width; if (!is_tiled) { @@ -148,42 +147,47 @@ void TextureInfo::CalculateTextureSizes1D(uint32_t width) { byte_pitch = xe::round_up(byte_pitch, 256); texel_width = (byte_pitch / bytes_per_block) * format->block_width; } else { - texel_width = size_2d.block_width * format->block_width; + texel_width = size.block_width * format->block_width; } - size_1d.input_width = texel_width; - size_1d.input_pitch = byte_pitch; + size.input_width = texel_width; + size.input_pitch = byte_pitch; - input_length = size_1d.input_pitch; + // Set some reasonable defaults for unused fields. + size.logical_height = 1; + size.block_height = format->block_height; + size.input_height = 1; + size.input_face_length = size.input_pitch; + + input_length = size.input_pitch; } void TextureInfo::CalculateTextureSizes2D(uint32_t width, uint32_t height) { - size_2d.logical_width = width; - size_2d.logical_height = height; + size.logical_width = width; + size.logical_height = height; auto format = format_info(); // w/h in blocks. - uint32_t block_width = - xe::round_up(size_2d.logical_width, format->block_width) / - format->block_width; + uint32_t block_width = xe::round_up(size.logical_width, format->block_width) / + format->block_width; uint32_t block_height = - xe::round_up(size_2d.logical_height, format->block_height) / + xe::round_up(size.logical_height, format->block_height) / format->block_height; if (is_tiled) { // If the texture is tiled, its dimensions must be a multiple of tile // dimensions (32x32 blocks). - size_2d.block_width = xe::round_up(block_width, 32); - size_2d.block_height = xe::round_up(block_height, 32); + size.block_width = xe::round_up(block_width, 32); + size.block_height = xe::round_up(block_height, 32); } else { - size_2d.block_width = block_width; - size_2d.block_height = block_height; + size.block_width = block_width; + size.block_height = block_height; } uint32_t bytes_per_block = format->block_width * format->block_height * format->bits_per_pixel / 8; - uint32_t byte_pitch = size_2d.block_width * bytes_per_block; + uint32_t byte_pitch = size.block_width * bytes_per_block; uint32_t texel_width; if (!is_tiled) { @@ -191,44 +195,44 @@ void TextureInfo::CalculateTextureSizes2D(uint32_t width, uint32_t height) { byte_pitch = xe::round_up(byte_pitch, 256); texel_width = (byte_pitch / bytes_per_block) * format->block_width; } else { - texel_width = size_2d.block_width * format->block_width; + texel_width = size.block_width * format->block_width; } - size_2d.input_width = texel_width; - size_2d.input_height = size_2d.block_height * format->block_height; - size_2d.input_pitch = byte_pitch; + size.input_width = texel_width; + size.input_height = size.block_height * format->block_height; + size.input_pitch = byte_pitch; - input_length = size_2d.input_pitch * size_2d.block_height; + size.input_face_length = size.input_pitch * size.block_height; + input_length = size.input_face_length; } void TextureInfo::CalculateTextureSizes3D(uint32_t width, uint32_t height, uint32_t depth) { - size_3d.logical_width = width; - size_3d.logical_height = height; + size.logical_width = width; + size.logical_height = height; auto format = format_info(); // w/h in blocks must be a multiple of block size. - uint32_t block_width = - xe::round_up(size_3d.logical_width, format->block_width) / - format->block_width; + uint32_t block_width = xe::round_up(size.logical_width, format->block_width) / + format->block_width; uint32_t block_height = - xe::round_up(size_3d.logical_height, format->block_height) / + xe::round_up(size.logical_height, format->block_height) / format->block_height; if (is_tiled) { // If the texture is tiled, its dimensions must be a multiple of tile // dimensions (32x32 blocks). - size_3d.block_width = xe::round_up(block_width, 32); - size_3d.block_height = xe::round_up(block_height, 32); + size.block_width = xe::round_up(block_width, 32); + size.block_height = xe::round_up(block_height, 32); } else { - size_3d.block_width = block_width; - size_3d.block_height = block_height; + size.block_width = block_width; + size.block_height = block_height; } uint32_t bytes_per_block = format->block_width * format->block_height * format->bits_per_pixel / 8; - uint32_t byte_pitch = size_3d.block_width * bytes_per_block; + uint32_t byte_pitch = size.block_width * bytes_per_block; uint32_t texel_width; if (!is_tiled) { @@ -236,46 +240,45 @@ void TextureInfo::CalculateTextureSizes3D(uint32_t width, uint32_t height, byte_pitch = xe::round_up(byte_pitch, 256); texel_width = (byte_pitch / bytes_per_block) * format->block_width; } else { - texel_width = size_3d.block_width * format->block_width; + texel_width = size.block_width * format->block_width; } - size_3d.input_width = texel_width; - size_3d.input_height = size_3d.block_height * format->block_height; - size_3d.input_pitch = byte_pitch; + size.input_width = texel_width; + size.input_height = size.block_height * format->block_height; + size.input_pitch = byte_pitch; - size_3d.input_face_length = size_3d.input_pitch * size_3d.block_height; - input_length = size_3d.input_face_length * depth; + size.input_face_length = size.input_pitch * size.block_height; + input_length = size.input_face_length * depth; } void TextureInfo::CalculateTextureSizesCube(uint32_t width, uint32_t height, uint32_t depth) { assert_true(depth == 6); - size_cube.logical_width = width; - size_cube.logical_height = height; + size.logical_width = width; + size.logical_height = height; auto format = format_info(); // w/h in blocks must be a multiple of block size. - uint32_t block_width = - xe::round_up(size_cube.logical_width, format->block_width) / - format->block_width; + uint32_t block_width = xe::round_up(size.logical_width, format->block_width) / + format->block_width; uint32_t block_height = - xe::round_up(size_cube.logical_height, format->block_height) / + xe::round_up(size.logical_height, format->block_height) / format->block_height; if (is_tiled) { // If the texture is tiled, its dimensions must be a multiple of tile // dimensions (32x32 blocks). - size_cube.block_width = xe::round_up(block_width, 32); - size_cube.block_height = xe::round_up(block_height, 32); + size.block_width = xe::round_up(block_width, 32); + size.block_height = xe::round_up(block_height, 32); } else { - size_cube.block_width = block_width; - size_cube.block_height = block_height; + size.block_width = block_width; + size.block_height = block_height; } uint32_t bytes_per_block = format->block_width * format->block_height * format->bits_per_pixel / 8; - uint32_t byte_pitch = size_cube.block_width * bytes_per_block; + uint32_t byte_pitch = size.block_width * bytes_per_block; uint32_t texel_width; if (!is_tiled) { @@ -283,15 +286,15 @@ void TextureInfo::CalculateTextureSizesCube(uint32_t width, uint32_t height, byte_pitch = xe::round_up(byte_pitch, 256); texel_width = (byte_pitch / bytes_per_block) * format->block_width; } else { - texel_width = size_cube.block_width * format->block_width; + texel_width = size.block_width * format->block_width; } - size_cube.input_width = texel_width; - size_cube.input_height = size_cube.block_height * format->block_height; - size_cube.input_pitch = byte_pitch; + size.input_width = texel_width; + size.input_height = size.block_height * format->block_height; + size.input_pitch = byte_pitch; - size_cube.input_face_length = size_cube.input_pitch * size_cube.block_height; - input_length = size_cube.input_face_length * 6; + size.input_face_length = size.input_pitch * size.block_height; + input_length = size.input_face_length * 6; } static void TextureSwap(Endian endianness, void* dest, const void* src, @@ -433,7 +436,7 @@ uint32_t TextureInfo::GetMipLocation(const TextureInfo& src, uint32_t mip, break; } - address_offset += GetMipSize(src, i); + address_offset += GetMipByteSize(src, i); } // Now, check if the mip is packed at an offset. @@ -443,7 +446,7 @@ uint32_t TextureInfo::GetMipLocation(const TextureInfo& src, uint32_t mip, return address_base + address_offset; } -uint32_t TextureInfo::GetMipSize(const TextureInfo& src, uint32_t mip) { +uint32_t TextureInfo::GetMipByteSize(const TextureInfo& src, uint32_t mip) { if (mip == 0) { return src.input_length; } @@ -547,8 +550,8 @@ bool TextureInfo::GetPackedTileOffset(uint32_t width, uint32_t height, bool TextureInfo::GetPackedTileOffset(const TextureInfo& texture_info, uint32_t* out_offset_x, uint32_t* out_offset_y) { - return GetPackedTileOffset(xe::next_pow2(texture_info.size_2d.logical_width), - xe::next_pow2(texture_info.size_2d.logical_height), + return GetPackedTileOffset(xe::next_pow2(texture_info.size.logical_width), + xe::next_pow2(texture_info.size.logical_height), texture_info.format_info(), out_offset_x, out_offset_y); } diff --git a/src/xenia/gpu/texture_info.h b/src/xenia/gpu/texture_info.h index 5c3cb3d35..dec537bac 100644 --- a/src/xenia/gpu/texture_info.h +++ b/src/xenia/gpu/texture_info.h @@ -259,6 +259,17 @@ struct TextureInfo { uint32_t mip_levels; uint32_t input_length; + struct Size { + uint32_t logical_width; + uint32_t logical_height; + uint32_t block_width; // # of horizontal blocks + uint32_t block_height; // # of vertical blocks + uint32_t input_width; // texel pitch + uint32_t input_height; // texel height + uint32_t input_pitch; // byte pitch + uint32_t input_face_length; // byte pitch of face + } size; + const FormatInfo* format_info() const { return FormatInfo::Get(static_cast(texture_format)); } @@ -267,34 +278,6 @@ struct TextureInfo { return format_info()->type == FormatType::kCompressed; } - union { - struct { - uint32_t logical_width; - uint32_t block_width; // # of horizontal blocks - uint32_t input_width; // texel pitch - uint32_t input_pitch; // byte pitch - } size_1d; - struct { - uint32_t logical_width; - uint32_t logical_height; - uint32_t block_width; // # of horizontal blocks - uint32_t block_height; // # of vertical blocks - uint32_t input_width; // texel pitch - uint32_t input_height; // texel height - uint32_t input_pitch; // byte pitch - } size_2d; - struct { - uint32_t logical_width; - uint32_t logical_height; - uint32_t block_width; // # of horizontal blocks - uint32_t block_height; // # of vertical blocks - uint32_t input_width; // texel pitch - uint32_t input_height; // texel height - uint32_t input_pitch; // byte pitch - uint32_t input_face_length; // byte pitch of face - } size_3d, size_cube; - }; - static bool Prepare(const xenos::xe_gpu_texture_fetch_t& fetch, TextureInfo* out_info); @@ -315,7 +298,8 @@ struct TextureInfo { // Get the memory location of a mip. offset_x and offset_y are in blocks. static uint32_t GetMipLocation(const TextureInfo& src, uint32_t mip, uint32_t* offset_x, uint32_t* offset_y); - static uint32_t GetMipSize(const TextureInfo& src, uint32_t mip); + static uint32_t GetMipByteSize(const TextureInfo& src, uint32_t mip); + static uint32_t GetMipSizes(const TextureInfo& src, uint32_t mip); // Get the byte size of a MIP when stored linearly. static uint32_t GetMipLinearSize(const TextureInfo& src, uint32_t mip); diff --git a/src/xenia/gpu/vulkan/texture_cache.cc b/src/xenia/gpu/vulkan/texture_cache.cc index 59f4b99ae..5a33d224f 100644 --- a/src/xenia/gpu/vulkan/texture_cache.cc +++ b/src/xenia/gpu/vulkan/texture_cache.cc @@ -809,14 +809,14 @@ TextureCache::Texture* TextureCache::LookupAddress(uint32_t guest_address, if (guest_address >= texture_info.guest_address && guest_address < texture_info.guest_address + texture_info.input_length && - texture_info.size_2d.input_width >= width && - texture_info.size_2d.input_height >= height && out_offset) { + texture_info.size.input_width >= width && + texture_info.size.input_height >= height && out_offset) { auto offset_bytes = guest_address - texture_info.guest_address; if (texture_info.dimension == Dimension::k2D) { out_offset->x = 0; - out_offset->y = offset_bytes / texture_info.size_2d.input_pitch; - if (offset_bytes % texture_info.size_2d.input_pitch != 0) { + out_offset->y = offset_bytes / texture_info.size.input_pitch; + if (offset_bytes % texture_info.size.input_pitch != 0) { // TODO: offset_x } } @@ -826,8 +826,8 @@ TextureCache::Texture* TextureCache::LookupAddress(uint32_t guest_address, if (texture_info.guest_address == guest_address && texture_info.dimension == Dimension::k2D && - texture_info.size_2d.input_width == width && - texture_info.size_2d.input_height == height) { + texture_info.size.input_width == width && + texture_info.size.input_height == height) { if (out_offset) { out_offset->x = 0; out_offset->y = 0; @@ -905,13 +905,12 @@ bool TextureCache::ConvertTexture2D(uint8_t* dest, void* host_address = memory_->TranslatePhysical(address); // Pitch of the source texture in blocks. - uint32_t block_width = mip == 0 - ? src.size_2d.block_width - : xe::next_pow2(src.size_2d.block_width) >> mip; - uint32_t logical_width = src.size_2d.logical_width >> mip; - uint32_t logical_height = src.size_2d.logical_height >> mip; - uint32_t input_width = src.size_2d.input_width >> mip; - uint32_t input_height = src.size_2d.input_height >> mip; + uint32_t block_width = mip == 0 ? src.size.block_width + : xe::next_pow2(src.size.block_width) >> mip; + uint32_t logical_width = src.size.logical_width >> mip; + uint32_t logical_height = src.size.logical_height >> mip; + uint32_t input_width = src.size.input_width >> mip; + uint32_t input_height = src.size.input_height >> mip; // All dimensions must be a multiple of block w/h logical_width = xe::round_up(logical_width, src.format_info()->block_width); @@ -931,7 +930,7 @@ bool TextureCache::ConvertTexture2D(uint8_t* dest, const uint8_t* src_mem = reinterpret_cast(host_address); src_mem += offset_y * src_pitch; src_mem += offset_x * bytes_per_block; - for (uint32_t y = 0; y < src.size_2d.logical_height; y++) { + for (uint32_t y = 0; y < src.size.logical_height; y++) { TextureSwap(src.endianness, dest + y * dst_pitch, src_mem + y * src_pitch, dst_pitch); } @@ -962,13 +961,12 @@ bool TextureCache::ConvertTextureCube(uint8_t* dest, void* host_address = memory_->TranslatePhysical(address); // Pitch of the source texture in blocks. - uint32_t block_width = mip == 0 - ? src.size_2d.block_width - : xe::next_pow2(src.size_2d.block_width) >> mip; - uint32_t logical_width = src.size_2d.logical_width >> mip; - uint32_t logical_height = src.size_2d.logical_height >> mip; - uint32_t input_width = src.size_2d.input_width >> mip; - uint32_t input_height = src.size_2d.input_height >> mip; + uint32_t block_width = mip == 0 ? src.size.block_width + : xe::next_pow2(src.size.block_width) >> mip; + uint32_t logical_width = src.size.logical_width >> mip; + uint32_t logical_height = src.size.logical_height >> mip; + uint32_t input_width = src.size.input_width >> mip; + uint32_t input_height = src.size.input_height >> mip; if (!src.is_tiled) { // Fast path copy entire image. @@ -980,16 +978,16 @@ bool TextureCache::ConvertTextureCube(uint8_t* dest, TextureInfo::ConvertTiled( dest, src_mem, src.endianness, src.format_info(), offset_x, offset_y, block_width, logical_width, logical_height, input_width); - src_mem += src.size_cube.input_face_length; - dest += src.size_cube.input_face_length; + src_mem += src.size.input_face_length; + dest += src.size.input_face_length; } } - copy_region->bufferRowLength = src.size_cube.input_width; - copy_region->bufferImageHeight = src.size_cube.input_height; + copy_region->bufferRowLength = src.size.input_width; + copy_region->bufferImageHeight = src.size.input_height; copy_region->imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, mip, 0, 6}; - copy_region->imageExtent = {src.size_cube.logical_width, - src.size_cube.logical_height, 1}; + copy_region->imageExtent = {src.size.logical_width, src.size.logical_height, + 1}; return false; } @@ -1158,15 +1156,14 @@ bool TextureCache::ComputeTextureStorage(size_t* output_length, assert_always(); } break; case Dimension::k2D: { - *output_length = src.size_2d.input_width * src.size_2d.input_height * 2; + *output_length = src.size.input_width * src.size.input_height * 2; return true; } case Dimension::k3D: { assert_always(); } break; case Dimension::kCube: { - *output_length = - src.size_cube.input_width * src.size_cube.input_height * 2 * 6; + *output_length = src.size.input_width * src.size.input_height * 2 * 6; return true; } }