2019-03-22 02:26:50 +01:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-11-09 07:26:30 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
2019-04-24 21:35:54 +02:00
|
|
|
|
|
|
|
#include "common/alignment.h"
|
2019-05-11 04:12:35 +02:00
|
|
|
#include "common/bit_util.h"
|
2019-03-22 02:26:50 +01:00
|
|
|
#include "core/core.h"
|
2019-05-07 16:56:45 +02:00
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
2019-03-22 02:26:50 +01:00
|
|
|
#include "video_core/surface.h"
|
2019-11-09 07:26:30 +01:00
|
|
|
#include "video_core/texture_cache/format_lookup_table.h"
|
2019-04-24 21:35:54 +02:00
|
|
|
#include "video_core/texture_cache/surface_params.h"
|
2019-03-22 02:26:50 +01:00
|
|
|
|
|
|
|
namespace VideoCommon {
|
|
|
|
|
2019-06-15 17:08:11 +02:00
|
|
|
using VideoCore::Surface::PixelFormat;
|
2019-03-22 02:26:50 +01:00
|
|
|
using VideoCore::Surface::PixelFormatFromDepthFormat;
|
|
|
|
using VideoCore::Surface::PixelFormatFromRenderTargetFormat;
|
2019-04-24 07:45:03 +02:00
|
|
|
using VideoCore::Surface::SurfaceTarget;
|
2019-03-22 02:26:50 +01:00
|
|
|
using VideoCore::Surface::SurfaceTargetFromTextureType;
|
2019-06-15 17:08:11 +02:00
|
|
|
using VideoCore::Surface::SurfaceType;
|
2019-03-22 02:26:50 +01:00
|
|
|
|
2019-07-12 07:01:27 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
SurfaceTarget TextureTypeToSurfaceTarget(Tegra::Shader::TextureType type, bool is_array) {
|
2019-05-07 16:56:45 +02:00
|
|
|
switch (type) {
|
2019-07-12 07:01:27 +02:00
|
|
|
case Tegra::Shader::TextureType::Texture1D:
|
|
|
|
return is_array ? SurfaceTarget::Texture1DArray : SurfaceTarget::Texture1D;
|
|
|
|
case Tegra::Shader::TextureType::Texture2D:
|
|
|
|
return is_array ? SurfaceTarget::Texture2DArray : SurfaceTarget::Texture2D;
|
|
|
|
case Tegra::Shader::TextureType::Texture3D:
|
2019-05-07 16:56:45 +02:00
|
|
|
ASSERT(!is_array);
|
|
|
|
return SurfaceTarget::Texture3D;
|
2019-07-12 07:01:27 +02:00
|
|
|
case Tegra::Shader::TextureType::TextureCube:
|
|
|
|
return is_array ? SurfaceTarget::TextureCubeArray : SurfaceTarget::TextureCubemap;
|
|
|
|
default:
|
2019-05-07 16:56:45 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
return SurfaceTarget::Texture2D;
|
|
|
|
}
|
2019-07-12 07:01:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceTarget ImageTypeToSurfaceTarget(Tegra::Shader::ImageType type) {
|
|
|
|
switch (type) {
|
|
|
|
case Tegra::Shader::ImageType::Texture1D:
|
|
|
|
return SurfaceTarget::Texture1D;
|
|
|
|
case Tegra::Shader::ImageType::TextureBuffer:
|
|
|
|
return SurfaceTarget::TextureBuffer;
|
|
|
|
case Tegra::Shader::ImageType::Texture1DArray:
|
|
|
|
return SurfaceTarget::Texture1DArray;
|
|
|
|
case Tegra::Shader::ImageType::Texture2D:
|
|
|
|
return SurfaceTarget::Texture2D;
|
|
|
|
case Tegra::Shader::ImageType::Texture2DArray:
|
|
|
|
return SurfaceTarget::Texture2DArray;
|
|
|
|
case Tegra::Shader::ImageType::Texture3D:
|
|
|
|
return SurfaceTarget::Texture3D;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return SurfaceTarget::Texture2D;
|
2019-05-07 16:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-22 02:26:50 +01:00
|
|
|
constexpr u32 GetMipmapSize(bool uncompressed, u32 mip_size, u32 tile) {
|
|
|
|
return uncompressed ? mip_size : std::max(1U, (mip_size + tile - 1) / tile);
|
|
|
|
}
|
2019-07-12 07:01:27 +02:00
|
|
|
|
2019-04-24 07:45:03 +02:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
2019-11-09 07:26:30 +01:00
|
|
|
SurfaceParams SurfaceParams::CreateForTexture(const FormatLookupTable& lookup_table,
|
|
|
|
const Tegra::Texture::TICEntry& tic,
|
2019-07-12 07:01:27 +02:00
|
|
|
const VideoCommon::Shader::Sampler& entry) {
|
2019-03-22 02:26:50 +01:00
|
|
|
SurfaceParams params;
|
2019-07-12 02:59:59 +02:00
|
|
|
params.is_tiled = tic.IsTiled();
|
|
|
|
params.srgb_conversion = tic.IsSrgbConversionEnabled();
|
|
|
|
params.block_width = params.is_tiled ? tic.BlockWidth() : 0,
|
|
|
|
params.block_height = params.is_tiled ? tic.BlockHeight() : 0,
|
|
|
|
params.block_depth = params.is_tiled ? tic.BlockDepth() : 0,
|
|
|
|
params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1;
|
2019-11-09 07:26:30 +01:00
|
|
|
params.pixel_format = lookup_table.GetPixelFormat(
|
|
|
|
tic.format, params.srgb_conversion, tic.r_type, tic.g_type, tic.b_type, tic.a_type);
|
2019-06-15 17:08:11 +02:00
|
|
|
params.type = GetFormatType(params.pixel_format);
|
|
|
|
if (entry.IsShadow() && params.type == SurfaceType::ColorTexture) {
|
|
|
|
switch (params.pixel_format) {
|
2019-06-18 01:19:47 +02:00
|
|
|
case PixelFormat::R16U:
|
2020-02-16 08:12:38 +01:00
|
|
|
case PixelFormat::R16F:
|
2019-06-15 17:08:11 +02:00
|
|
|
params.pixel_format = PixelFormat::Z16;
|
|
|
|
break;
|
2020-02-16 08:12:38 +01:00
|
|
|
case PixelFormat::R32F:
|
2019-06-15 17:08:11 +02:00
|
|
|
params.pixel_format = PixelFormat::Z32F;
|
|
|
|
break;
|
2020-02-16 08:12:38 +01:00
|
|
|
default:
|
2019-06-15 17:08:11 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented shadow convert format: {}",
|
|
|
|
static_cast<u32>(params.pixel_format));
|
|
|
|
}
|
|
|
|
params.type = GetFormatType(params.pixel_format);
|
|
|
|
}
|
2019-03-22 02:26:50 +01:00
|
|
|
params.type = GetFormatType(params.pixel_format);
|
2019-05-07 16:56:45 +02:00
|
|
|
// TODO: on 1DBuffer we should use the tic info.
|
2019-07-12 07:01:27 +02:00
|
|
|
if (tic.IsBuffer()) {
|
|
|
|
params.target = SurfaceTarget::TextureBuffer;
|
|
|
|
params.width = tic.Width();
|
|
|
|
params.pitch = params.width * params.GetBytesPerPixel();
|
|
|
|
params.height = 1;
|
|
|
|
params.depth = 1;
|
|
|
|
params.num_levels = 1;
|
|
|
|
params.emulated_levels = 1;
|
|
|
|
params.is_layered = false;
|
|
|
|
} else {
|
|
|
|
params.target = TextureTypeToSurfaceTarget(entry.GetType(), entry.IsArray());
|
2019-07-12 02:59:59 +02:00
|
|
|
params.width = tic.Width();
|
|
|
|
params.height = tic.Height();
|
|
|
|
params.depth = tic.Depth();
|
|
|
|
params.pitch = params.is_tiled ? 0 : tic.Pitch();
|
2019-06-15 17:08:11 +02:00
|
|
|
if (params.target == SurfaceTarget::TextureCubemap ||
|
|
|
|
params.target == SurfaceTarget::TextureCubeArray) {
|
|
|
|
params.depth *= 6;
|
|
|
|
}
|
2019-07-12 02:59:59 +02:00
|
|
|
params.num_levels = tic.max_mip_level + 1;
|
2019-06-15 17:08:11 +02:00
|
|
|
params.emulated_levels = std::min(params.num_levels, params.MaxPossibleMipmap());
|
|
|
|
params.is_layered = params.IsLayered();
|
2019-07-12 07:01:27 +02:00
|
|
|
}
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2019-11-09 07:26:30 +01:00
|
|
|
SurfaceParams SurfaceParams::CreateForImage(const FormatLookupTable& lookup_table,
|
|
|
|
const Tegra::Texture::TICEntry& tic,
|
2019-07-12 07:01:27 +02:00
|
|
|
const VideoCommon::Shader::Image& entry) {
|
|
|
|
SurfaceParams params;
|
|
|
|
params.is_tiled = tic.IsTiled();
|
|
|
|
params.srgb_conversion = tic.IsSrgbConversionEnabled();
|
|
|
|
params.block_width = params.is_tiled ? tic.BlockWidth() : 0,
|
|
|
|
params.block_height = params.is_tiled ? tic.BlockHeight() : 0,
|
|
|
|
params.block_depth = params.is_tiled ? tic.BlockDepth() : 0,
|
|
|
|
params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1;
|
2019-11-09 07:26:30 +01:00
|
|
|
params.pixel_format = lookup_table.GetPixelFormat(
|
|
|
|
tic.format, params.srgb_conversion, tic.r_type, tic.g_type, tic.b_type, tic.a_type);
|
2019-07-12 07:01:27 +02:00
|
|
|
params.type = GetFormatType(params.pixel_format);
|
|
|
|
params.type = GetFormatType(params.pixel_format);
|
|
|
|
params.target = ImageTypeToSurfaceTarget(entry.GetType());
|
|
|
|
// TODO: on 1DBuffer we should use the tic info.
|
|
|
|
if (tic.IsBuffer()) {
|
2019-06-12 15:32:26 +02:00
|
|
|
params.target = SurfaceTarget::TextureBuffer;
|
2019-07-12 02:59:59 +02:00
|
|
|
params.width = tic.Width();
|
2019-06-15 17:08:11 +02:00
|
|
|
params.pitch = params.width * params.GetBytesPerPixel();
|
|
|
|
params.height = 1;
|
|
|
|
params.depth = 1;
|
|
|
|
params.num_levels = 1;
|
|
|
|
params.emulated_levels = 1;
|
|
|
|
params.is_layered = false;
|
2019-07-12 07:01:27 +02:00
|
|
|
} else {
|
|
|
|
params.width = tic.Width();
|
|
|
|
params.height = tic.Height();
|
|
|
|
params.depth = tic.Depth();
|
|
|
|
params.pitch = params.is_tiled ? 0 : tic.Pitch();
|
|
|
|
if (params.target == SurfaceTarget::TextureCubemap ||
|
|
|
|
params.target == SurfaceTarget::TextureCubeArray) {
|
|
|
|
params.depth *= 6;
|
|
|
|
}
|
|
|
|
params.num_levels = tic.max_mip_level + 1;
|
|
|
|
params.emulated_levels = std::min(params.num_levels, params.MaxPossibleMipmap());
|
|
|
|
params.is_layered = params.IsLayered();
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2020-02-16 08:12:38 +01:00
|
|
|
SurfaceParams SurfaceParams::CreateForDepthBuffer(Core::System& system) {
|
|
|
|
const auto& regs = system.GPU().Maxwell3D().regs;
|
|
|
|
regs.zeta_width, regs.zeta_height, regs.zeta.format, regs.zeta.memory_layout.type;
|
2019-03-22 02:26:50 +01:00
|
|
|
SurfaceParams params;
|
2020-02-16 08:12:38 +01:00
|
|
|
params.is_tiled = regs.zeta.memory_layout.type ==
|
|
|
|
Tegra::Engines::Maxwell3D::Regs::InvMemoryLayout::BlockLinear;
|
2019-04-17 01:01:07 +02:00
|
|
|
params.srgb_conversion = false;
|
2020-02-16 08:12:38 +01:00
|
|
|
params.block_width = std::min(regs.zeta.memory_layout.block_width.Value(), 5U);
|
|
|
|
params.block_height = std::min(regs.zeta.memory_layout.block_height.Value(), 5U);
|
|
|
|
params.block_depth = std::min(regs.zeta.memory_layout.block_depth.Value(), 5U);
|
2019-03-22 02:26:50 +01:00
|
|
|
params.tile_width_spacing = 1;
|
2020-02-16 08:12:38 +01:00
|
|
|
params.pixel_format = PixelFormatFromDepthFormat(regs.zeta.format);
|
2019-03-22 02:26:50 +01:00
|
|
|
params.type = GetFormatType(params.pixel_format);
|
2020-02-16 08:12:38 +01:00
|
|
|
params.width = regs.zeta_width;
|
|
|
|
params.height = regs.zeta_height;
|
2019-05-12 23:31:03 +02:00
|
|
|
params.pitch = 0;
|
2019-03-22 02:26:50 +01:00
|
|
|
params.num_levels = 1;
|
2019-05-24 21:34:31 +02:00
|
|
|
params.emulated_levels = 1;
|
2020-02-16 08:12:38 +01:00
|
|
|
|
|
|
|
const bool is_layered = regs.zeta_layers > 1 && params.block_depth == 0;
|
|
|
|
params.is_layered = is_layered;
|
|
|
|
params.target = is_layered ? SurfaceTarget::Texture2DArray : SurfaceTarget::Texture2D;
|
|
|
|
params.depth = is_layered ? regs.zeta_layers.Value() : 1U;
|
2019-03-22 02:26:50 +01:00
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceParams SurfaceParams::CreateForFramebuffer(Core::System& system, std::size_t index) {
|
|
|
|
const auto& config{system.GPU().Maxwell3D().regs.rt[index]};
|
|
|
|
SurfaceParams params;
|
|
|
|
params.is_tiled =
|
|
|
|
config.memory_layout.type == Tegra::Engines::Maxwell3D::Regs::InvMemoryLayout::BlockLinear;
|
2019-04-17 01:01:07 +02:00
|
|
|
params.srgb_conversion = config.format == Tegra::RenderTargetFormat::BGRA8_SRGB ||
|
|
|
|
config.format == Tegra::RenderTargetFormat::RGBA8_SRGB;
|
2019-05-10 09:17:48 +02:00
|
|
|
params.block_width = config.memory_layout.block_width;
|
|
|
|
params.block_height = config.memory_layout.block_height;
|
|
|
|
params.block_depth = config.memory_layout.block_depth;
|
2019-03-22 02:26:50 +01:00
|
|
|
params.tile_width_spacing = 1;
|
|
|
|
params.pixel_format = PixelFormatFromRenderTargetFormat(config.format);
|
|
|
|
params.type = GetFormatType(params.pixel_format);
|
|
|
|
if (params.is_tiled) {
|
2019-05-12 23:31:03 +02:00
|
|
|
params.pitch = 0;
|
2019-03-22 02:26:50 +01:00
|
|
|
params.width = config.width;
|
|
|
|
} else {
|
|
|
|
const u32 bpp = GetFormatBpp(params.pixel_format) / CHAR_BIT;
|
|
|
|
params.pitch = config.width;
|
|
|
|
params.width = params.pitch / bpp;
|
|
|
|
}
|
|
|
|
params.height = config.height;
|
|
|
|
params.num_levels = 1;
|
2019-05-24 21:34:31 +02:00
|
|
|
params.emulated_levels = 1;
|
2020-02-16 08:12:38 +01:00
|
|
|
|
|
|
|
const bool is_layered = config.layers > 1 && params.block_depth == 0;
|
|
|
|
params.is_layered = is_layered;
|
|
|
|
params.depth = is_layered ? config.layers.Value() : 1;
|
|
|
|
params.target = is_layered ? SurfaceTarget::Texture2DArray : SurfaceTarget::Texture2D;
|
2019-03-22 02:26:50 +01:00
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceParams SurfaceParams::CreateForFermiCopySurface(
|
|
|
|
const Tegra::Engines::Fermi2D::Regs::Surface& config) {
|
|
|
|
SurfaceParams params{};
|
|
|
|
params.is_tiled = !config.linear;
|
2019-04-17 01:01:07 +02:00
|
|
|
params.srgb_conversion = config.format == Tegra::RenderTargetFormat::BGRA8_SRGB ||
|
|
|
|
config.format == Tegra::RenderTargetFormat::RGBA8_SRGB;
|
2019-05-10 09:17:48 +02:00
|
|
|
params.block_width = params.is_tiled ? std::min(config.BlockWidth(), 5U) : 0,
|
|
|
|
params.block_height = params.is_tiled ? std::min(config.BlockHeight(), 5U) : 0,
|
|
|
|
params.block_depth = params.is_tiled ? std::min(config.BlockDepth(), 5U) : 0,
|
2019-03-22 02:26:50 +01:00
|
|
|
params.tile_width_spacing = 1;
|
|
|
|
params.pixel_format = PixelFormatFromRenderTargetFormat(config.format);
|
|
|
|
params.type = GetFormatType(params.pixel_format);
|
|
|
|
params.width = config.width;
|
|
|
|
params.height = config.height;
|
2019-05-07 16:56:45 +02:00
|
|
|
params.pitch = config.pitch;
|
2019-03-22 02:26:50 +01:00
|
|
|
// TODO(Rodrigo): Try to guess the surface target from depth and layer parameters
|
|
|
|
params.target = SurfaceTarget::Texture2D;
|
|
|
|
params.depth = 1;
|
|
|
|
params.num_levels = 1;
|
2019-05-24 21:34:31 +02:00
|
|
|
params.emulated_levels = 1;
|
2019-05-07 16:56:45 +02:00
|
|
|
params.is_layered = params.IsLayered();
|
2019-03-22 02:26:50 +01:00
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2019-10-16 16:47:44 +02:00
|
|
|
VideoCore::Surface::SurfaceTarget SurfaceParams::ExpectedTarget(
|
|
|
|
const VideoCommon::Shader::Sampler& entry) {
|
|
|
|
return TextureTypeToSurfaceTarget(entry.GetType(), entry.IsArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoCore::Surface::SurfaceTarget SurfaceParams::ExpectedTarget(
|
|
|
|
const VideoCommon::Shader::Image& entry) {
|
|
|
|
return ImageTypeToSurfaceTarget(entry.GetType());
|
|
|
|
}
|
|
|
|
|
2019-03-22 02:26:50 +01:00
|
|
|
bool SurfaceParams::IsLayered() const {
|
|
|
|
switch (target) {
|
|
|
|
case SurfaceTarget::Texture1DArray:
|
|
|
|
case SurfaceTarget::Texture2DArray:
|
|
|
|
case SurfaceTarget::TextureCubemap:
|
2019-04-21 01:01:26 +02:00
|
|
|
case SurfaceTarget::TextureCubeArray:
|
2019-03-22 02:26:50 +01:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-13 02:33:52 +02:00
|
|
|
// Auto block resizing algorithm from:
|
|
|
|
// https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
|
2019-03-22 02:26:50 +01:00
|
|
|
u32 SurfaceParams::GetMipBlockHeight(u32 level) const {
|
|
|
|
if (level == 0) {
|
2019-04-14 06:44:16 +02:00
|
|
|
return this->block_height;
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
2019-04-17 01:01:07 +02:00
|
|
|
|
2019-05-13 02:33:52 +02:00
|
|
|
const u32 height_new{GetMipHeight(level)};
|
2019-04-11 22:14:55 +02:00
|
|
|
const u32 default_block_height{GetDefaultBlockHeight()};
|
2019-05-13 02:33:52 +02:00
|
|
|
const u32 blocks_in_y{(height_new + default_block_height - 1) / default_block_height};
|
|
|
|
const u32 block_height_new = Common::Log2Ceil32(blocks_in_y);
|
|
|
|
return std::clamp(block_height_new, 3U, 7U) - 3U;
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 SurfaceParams::GetMipBlockDepth(u32 level) const {
|
2019-04-17 01:01:07 +02:00
|
|
|
if (level == 0) {
|
|
|
|
return this->block_depth;
|
|
|
|
}
|
2019-05-07 16:56:45 +02:00
|
|
|
if (is_layered) {
|
2019-05-10 09:17:48 +02:00
|
|
|
return 0;
|
2019-04-17 01:01:07 +02:00
|
|
|
}
|
2019-03-22 02:26:50 +01:00
|
|
|
|
2019-05-13 02:33:52 +02:00
|
|
|
const u32 depth_new{GetMipDepth(level)};
|
|
|
|
const u32 block_depth_new = Common::Log2Ceil32(depth_new);
|
|
|
|
if (block_depth_new > 4) {
|
2019-05-11 04:12:35 +02:00
|
|
|
return 5 - (GetMipBlockHeight(level) >= 2);
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
2019-05-13 02:33:52 +02:00
|
|
|
return block_depth_new;
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t SurfaceParams::GetGuestMipmapLevelOffset(u32 level) const {
|
|
|
|
std::size_t offset = 0;
|
|
|
|
for (u32 i = 0; i < level; i++) {
|
2019-04-17 01:01:07 +02:00
|
|
|
offset += GetInnerMipmapMemorySize(i, false, false);
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t SurfaceParams::GetHostMipmapLevelOffset(u32 level) const {
|
|
|
|
std::size_t offset = 0;
|
|
|
|
for (u32 i = 0; i < level; i++) {
|
2019-04-17 01:01:07 +02:00
|
|
|
offset += GetInnerMipmapMemorySize(i, true, false) * GetNumLayers();
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2019-05-13 02:33:52 +02:00
|
|
|
std::size_t SurfaceParams::GetConvertedMipmapOffset(u32 level) const {
|
|
|
|
std::size_t offset = 0;
|
|
|
|
for (u32 i = 0; i < level; i++) {
|
|
|
|
offset += GetConvertedMipmapSize(i);
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t SurfaceParams::GetConvertedMipmapSize(u32 level) const {
|
2019-06-26 00:03:25 +02:00
|
|
|
constexpr std::size_t rgba8_bpp = 4ULL;
|
2019-05-13 02:33:52 +02:00
|
|
|
const std::size_t width_t = GetMipWidth(level);
|
|
|
|
const std::size_t height_t = GetMipHeight(level);
|
|
|
|
const std::size_t depth_t = is_layered ? depth : GetMipDepth(level);
|
2019-06-26 00:03:25 +02:00
|
|
|
return width_t * height_t * depth_t * rgba8_bpp;
|
2019-05-13 02:33:52 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 01:01:07 +02:00
|
|
|
std::size_t SurfaceParams::GetLayerSize(bool as_host_size, bool uncompressed) const {
|
|
|
|
std::size_t size = 0;
|
|
|
|
for (u32 level = 0; level < num_levels; ++level) {
|
|
|
|
size += GetInnerMipmapMemorySize(level, as_host_size, uncompressed);
|
|
|
|
}
|
2019-05-07 16:56:45 +02:00
|
|
|
if (is_tiled && is_layered) {
|
2019-05-10 09:17:48 +02:00
|
|
|
return Common::AlignBits(size,
|
|
|
|
Tegra::Texture::GetGOBSizeShift() + block_height + block_depth);
|
2019-04-17 01:01:07 +02:00
|
|
|
}
|
|
|
|
return size;
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 01:01:07 +02:00
|
|
|
std::size_t SurfaceParams::GetInnerMipmapMemorySize(u32 level, bool as_host_size,
|
2019-03-22 02:26:50 +01:00
|
|
|
bool uncompressed) const {
|
2019-04-11 22:14:55 +02:00
|
|
|
const u32 width{GetMipmapSize(uncompressed, GetMipWidth(level), GetDefaultBlockWidth())};
|
|
|
|
const u32 height{GetMipmapSize(uncompressed, GetMipHeight(level), GetDefaultBlockHeight())};
|
2019-05-07 16:56:45 +02:00
|
|
|
const u32 depth{is_layered ? 1U : GetMipDepth(level)};
|
2019-07-11 21:15:21 +02:00
|
|
|
if (is_tiled) {
|
2019-07-14 14:41:06 +02:00
|
|
|
return Tegra::Texture::CalculateSize(!as_host_size, GetBytesPerPixel(), width, height,
|
|
|
|
depth, GetMipBlockHeight(level),
|
|
|
|
GetMipBlockDepth(level));
|
2019-07-14 23:42:39 +02:00
|
|
|
} else if (as_host_size || IsBuffer()) {
|
|
|
|
return GetBytesPerPixel() * width * height * depth;
|
2019-07-11 21:15:21 +02:00
|
|
|
} else {
|
2019-07-14 23:42:39 +02:00
|
|
|
// Linear Texture Case
|
|
|
|
return pitch * height * depth;
|
2019-07-11 21:15:21 +02:00
|
|
|
}
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
|
|
|
|
2019-05-07 16:56:45 +02:00
|
|
|
bool SurfaceParams::operator==(const SurfaceParams& rhs) const {
|
2019-03-22 02:26:50 +01:00
|
|
|
return std::tie(is_tiled, block_width, block_height, block_depth, tile_width_spacing, width,
|
2019-11-09 02:38:26 +01:00
|
|
|
height, depth, pitch, num_levels, pixel_format, type, target) ==
|
2019-03-22 02:26:50 +01:00
|
|
|
std::tie(rhs.is_tiled, rhs.block_width, rhs.block_height, rhs.block_depth,
|
|
|
|
rhs.tile_width_spacing, rhs.width, rhs.height, rhs.depth, rhs.pitch,
|
2019-11-09 02:38:26 +01:00
|
|
|
rhs.num_levels, rhs.pixel_format, rhs.type, rhs.target);
|
2019-03-22 02:26:50 +01:00
|
|
|
}
|
|
|
|
|
2019-05-07 16:56:45 +02:00
|
|
|
std::string SurfaceParams::TargetName() const {
|
|
|
|
switch (target) {
|
|
|
|
case SurfaceTarget::Texture1D:
|
|
|
|
return "1D";
|
2019-07-05 01:38:19 +02:00
|
|
|
case SurfaceTarget::TextureBuffer:
|
|
|
|
return "TexBuffer";
|
2019-05-07 16:56:45 +02:00
|
|
|
case SurfaceTarget::Texture2D:
|
|
|
|
return "2D";
|
|
|
|
case SurfaceTarget::Texture3D:
|
|
|
|
return "3D";
|
|
|
|
case SurfaceTarget::Texture1DArray:
|
|
|
|
return "1DArray";
|
|
|
|
case SurfaceTarget::Texture2DArray:
|
|
|
|
return "2DArray";
|
|
|
|
case SurfaceTarget::TextureCubemap:
|
|
|
|
return "Cube";
|
|
|
|
case SurfaceTarget::TextureCubeArray:
|
|
|
|
return "CubeArray";
|
|
|
|
default:
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented surface_target={}", static_cast<u32>(target));
|
|
|
|
UNREACHABLE();
|
|
|
|
return fmt::format("TUK({})", static_cast<u32>(target));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-08 18:13:18 +01:00
|
|
|
u32 SurfaceParams::GetBlockSize() const {
|
|
|
|
const u32 x = 64U << block_width;
|
|
|
|
const u32 y = 8U << block_height;
|
|
|
|
const u32 z = 1U << block_depth;
|
|
|
|
return x * y * z;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<u32, u32> SurfaceParams::GetBlockXY() const {
|
|
|
|
const u32 x_pixels = 64U / GetBytesPerPixel();
|
|
|
|
const u32 x = x_pixels << block_width;
|
|
|
|
const u32 y = 8U << block_height;
|
|
|
|
return {x, y};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<u32, u32, u32> SurfaceParams::GetBlockOffsetXYZ(u32 offset) const {
|
|
|
|
const auto div_ceil = [](const u32 x, const u32 y) { return ((x + y - 1) / y); };
|
|
|
|
const u32 block_size = GetBlockSize();
|
|
|
|
const u32 block_index = offset / block_size;
|
|
|
|
const u32 gob_offset = offset % block_size;
|
|
|
|
const u32 gob_index = gob_offset / static_cast<u32>(Tegra::Texture::GetGOBSize());
|
|
|
|
const u32 x_gob_pixels = 64U / GetBytesPerPixel();
|
|
|
|
const u32 x_block_pixels = x_gob_pixels << block_width;
|
|
|
|
const u32 y_block_pixels = 8U << block_height;
|
|
|
|
const u32 z_block_pixels = 1U << block_depth;
|
|
|
|
const u32 x_blocks = div_ceil(width, x_block_pixels);
|
|
|
|
const u32 y_blocks = div_ceil(height, y_block_pixels);
|
|
|
|
const u32 z_blocks = div_ceil(depth, z_block_pixels);
|
|
|
|
const u32 base_x = block_index % x_blocks;
|
|
|
|
const u32 base_y = (block_index / x_blocks) % y_blocks;
|
|
|
|
const u32 base_z = (block_index / (x_blocks * y_blocks)) % z_blocks;
|
|
|
|
u32 x = base_x * x_block_pixels;
|
|
|
|
u32 y = base_y * y_block_pixels;
|
|
|
|
u32 z = base_z * z_block_pixels;
|
|
|
|
z += gob_index >> block_height;
|
|
|
|
y += (gob_index * 8U) % y_block_pixels;
|
|
|
|
return {x, y, z};
|
|
|
|
}
|
|
|
|
|
2019-03-22 02:26:50 +01:00
|
|
|
} // namespace VideoCommon
|