From bab21e8cb3df9c06e3c0a37a8fc68fed676f5d6e Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Thu, 11 Apr 2019 17:14:55 -0300 Subject: gl_texture_cache: Initial implementation --- src/video_core/texture_cache.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'src/video_core/texture_cache.cpp') diff --git a/src/video_core/texture_cache.cpp b/src/video_core/texture_cache.cpp index e96eba7cc..c42365a82 100644 --- a/src/video_core/texture_cache.cpp +++ b/src/video_core/texture_cache.cpp @@ -163,7 +163,7 @@ u32 SurfaceParams::GetMipBlockHeight(u32 level) const { return block_height; } const u32 height{GetMipHeight(level)}; - const u32 default_block_height{GetDefaultBlockHeight(pixel_format)}; + const u32 default_block_height{GetDefaultBlockHeight()}; const u32 blocks_in_y{(height + default_block_height - 1) / default_block_height}; u32 block_height = 16; while (block_height > 1 && blocks_in_y <= block_height * 4) { @@ -205,6 +205,10 @@ std::size_t SurfaceParams::GetHostMipmapLevelOffset(u32 level) const { return offset; } +std::size_t SurfaceParams::GetHostMipmapSize(u32 level) const { + return GetInnerMipmapMemorySize(level, true, true, false) * GetNumLayers(); +} + std::size_t SurfaceParams::GetGuestLayerSize() const { return GetInnerMemorySize(false, true, false); } @@ -213,6 +217,22 @@ std::size_t SurfaceParams::GetHostLayerSize(u32 level) const { return GetInnerMipmapMemorySize(level, true, IsLayered(), false); } +u32 SurfaceParams::GetDefaultBlockWidth() const { + return VideoCore::Surface::GetDefaultBlockWidth(pixel_format); +} + +u32 SurfaceParams::GetDefaultBlockHeight() const { + return VideoCore::Surface::GetDefaultBlockHeight(pixel_format); +} + +u32 SurfaceParams::GetBitsPerPixel() const { + return VideoCore::Surface::GetFormatBpp(pixel_format); +} + +u32 SurfaceParams::GetBytesPerPixel() const { + return VideoCore::Surface::GetBytesPerPixel(pixel_format); +} + bool SurfaceParams::IsFamiliar(const SurfaceParams& view_params) const { if (std::tie(is_tiled, tile_width_spacing, pixel_format, component_type, type) != std::tie(view_params.is_tiled, view_params.tile_width_spacing, view_params.pixel_format, @@ -257,7 +277,7 @@ void SurfaceParams::CalculateCachedValues() { // ASTC is uncompressed in software, in emulated as RGBA8 if (IsPixelFormatASTC(pixel_format)) { - host_size_in_bytes = width * height * depth * 4; + host_size_in_bytes = static_cast(width * height * depth) * 4ULL; } else { host_size_in_bytes = GetInnerMemorySize(true, false, false); } @@ -282,13 +302,11 @@ void SurfaceParams::CalculateCachedValues() { std::size_t SurfaceParams::GetInnerMipmapMemorySize(u32 level, bool as_host_size, bool layer_only, bool uncompressed) const { const bool tiled{as_host_size ? false : is_tiled}; - const u32 tile_x{GetDefaultBlockWidth(pixel_format)}; - const u32 tile_y{GetDefaultBlockHeight(pixel_format)}; - const u32 width{GetMipmapSize(uncompressed, GetMipWidth(level), tile_x)}; - const u32 height{GetMipmapSize(uncompressed, GetMipHeight(level), tile_y)}; + const u32 width{GetMipmapSize(uncompressed, GetMipWidth(level), GetDefaultBlockWidth())}; + const u32 height{GetMipmapSize(uncompressed, GetMipHeight(level), GetDefaultBlockHeight())}; const u32 depth{layer_only ? 1U : GetMipDepth(level)}; - return Tegra::Texture::CalculateSize(tiled, GetBytesPerPixel(pixel_format), width, height, - depth, GetMipBlockHeight(level), GetMipBlockDepth(level)); + return Tegra::Texture::CalculateSize(tiled, GetBytesPerPixel(), width, height, depth, + GetMipBlockHeight(level), GetMipBlockDepth(level)); } std::size_t SurfaceParams::GetInnerMemorySize(bool as_host_size, bool layer_only, @@ -297,7 +315,7 @@ std::size_t SurfaceParams::GetInnerMemorySize(bool as_host_size, bool layer_only for (u32 level = 0; level < num_levels; ++level) { size += GetInnerMipmapMemorySize(level, as_host_size, layer_only, uncompressed); } - if (!as_host_size && is_tiled) { + if (is_tiled && !as_host_size) { size = Common::AlignUp(size, Tegra::Texture::GetGOBSize() * block_height * block_depth); } return size; @@ -309,6 +327,7 @@ std::map> SurfaceParams::CreateViewOffsetMap() const { case SurfaceTarget::Texture1D: case SurfaceTarget::Texture2D: case SurfaceTarget::Texture3D: { + // TODO(Rodrigo): Add layer iterations for 3D textures constexpr u32 layer = 0; for (u32 level = 0; level < num_levels; ++level) { const std::size_t offset{GetGuestMipmapLevelOffset(level)}; -- cgit v1.2.3