2018-06-22 01:36:01 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
2018-03-19 22:45:22 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2018-06-22 01:36:01 +02:00
|
|
|
#include <map>
|
2018-03-19 22:45:22 +01:00
|
|
|
#include <memory>
|
2018-10-29 02:14:25 +01:00
|
|
|
#include <string>
|
2018-06-26 21:05:13 +02:00
|
|
|
#include <vector>
|
2018-08-06 05:30:18 +02:00
|
|
|
|
2018-09-21 05:41:25 +02:00
|
|
|
#include "common/alignment.h"
|
2018-03-19 22:45:22 +01:00
|
|
|
#include "common/common_types.h"
|
2018-08-22 04:04:54 +02:00
|
|
|
#include "common/hash.h"
|
2018-03-19 22:45:22 +01:00
|
|
|
#include "common/math_util.h"
|
2018-10-06 05:39:03 +02:00
|
|
|
#include "video_core/engines/fermi_2d.h"
|
2018-06-24 15:50:08 +02:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2018-08-23 21:44:41 +02:00
|
|
|
#include "video_core/rasterizer_cache.h"
|
2018-03-19 22:45:22 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2018-09-14 17:42:28 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
2018-10-29 02:14:25 +01:00
|
|
|
#include "video_core/surface.h"
|
2018-10-13 08:08:04 +02:00
|
|
|
#include "video_core/textures/decoders.h"
|
2018-03-27 04:46:11 +02:00
|
|
|
#include "video_core/textures/texture.h"
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2018-06-22 01:36:01 +02:00
|
|
|
class CachedSurface;
|
2018-03-19 22:45:22 +01:00
|
|
|
using Surface = std::shared_ptr<CachedSurface>;
|
|
|
|
using SurfaceSurfaceRect_Tuple = std::tuple<Surface, Surface, MathUtil::Rectangle<u32>>;
|
|
|
|
|
2018-10-29 02:14:25 +01:00
|
|
|
using SurfaceTarget = VideoCore::Surface::SurfaceTarget;
|
|
|
|
using SurfaceType = VideoCore::Surface::SurfaceType;
|
|
|
|
using PixelFormat = VideoCore::Surface::PixelFormat;
|
|
|
|
using ComponentType = VideoCore::Surface::ComponentType;
|
2018-09-01 08:42:43 +02:00
|
|
|
|
2018-10-29 02:14:25 +01:00
|
|
|
struct SurfaceParams {
|
2018-09-23 23:55:41 +02:00
|
|
|
static std::string SurfaceTargetName(SurfaceTarget target) {
|
|
|
|
switch (target) {
|
|
|
|
case SurfaceTarget::Texture1D:
|
|
|
|
return "Texture1D";
|
|
|
|
case SurfaceTarget::Texture2D:
|
|
|
|
return "Texture2D";
|
|
|
|
case SurfaceTarget::Texture3D:
|
|
|
|
return "Texture3D";
|
|
|
|
case SurfaceTarget::Texture1DArray:
|
|
|
|
return "Texture1DArray";
|
|
|
|
case SurfaceTarget::Texture2DArray:
|
|
|
|
return "Texture2DArray";
|
|
|
|
case SurfaceTarget::TextureCubemap:
|
|
|
|
return "TextureCubemap";
|
2018-10-19 02:04:43 +02:00
|
|
|
case SurfaceTarget::TextureCubeArray:
|
|
|
|
return "TextureCubeArray";
|
2018-09-23 23:55:41 +02:00
|
|
|
default:
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented surface_target={}", static_cast<u32>(target));
|
|
|
|
UNREACHABLE();
|
|
|
|
return fmt::format("TextureUnknown({})", static_cast<u32>(target));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-24 05:45:47 +02:00
|
|
|
u32 GetFormatBpp() const {
|
2018-10-29 02:14:25 +01:00
|
|
|
return VideoCore::Surface::GetFormatBpp(pixel_format);
|
2018-10-13 05:44:18 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 22:14:14 +02:00
|
|
|
/// Returns the rectangle corresponding to this surface
|
2018-10-25 00:30:27 +02:00
|
|
|
MathUtil::Rectangle<u32> GetRect(u32 mip_level = 0) const;
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-10-13 08:08:04 +02:00
|
|
|
/// Returns the total size of this surface in bytes, adjusted for compression
|
|
|
|
std::size_t SizeInBytesRaw(bool ignore_tiled = false) const {
|
2018-06-24 15:50:08 +02:00
|
|
|
const u32 compression_factor{GetCompressionFactor(pixel_format)};
|
2018-10-13 08:08:04 +02:00
|
|
|
const u32 bytes_per_pixel{GetBytesPerPixel(pixel_format)};
|
|
|
|
const size_t uncompressed_size{
|
|
|
|
Tegra::Texture::CalculateSize((ignore_tiled ? false : is_tiled), bytes_per_pixel, width,
|
|
|
|
height, depth, block_height, block_depth)};
|
|
|
|
|
|
|
|
// Divide by compression_factor^2, as height and width are factored by this
|
|
|
|
return uncompressed_size / (compression_factor * compression_factor);
|
2018-09-14 17:33:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-13 08:08:04 +02:00
|
|
|
/// Returns the size of this surface as an OpenGL texture in bytes
|
|
|
|
std::size_t SizeInBytesGL() const {
|
|
|
|
return SizeInBytesRaw(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the size of this surface as a cube face in bytes
|
|
|
|
std::size_t SizeInBytesCubeFace() const {
|
|
|
|
return size_in_bytes / 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the size of this surface as an OpenGL cube face in bytes
|
|
|
|
std::size_t SizeInBytesCubeFaceGL() const {
|
|
|
|
return size_in_bytes_gl / 6;
|
2018-03-19 22:45:22 +01:00
|
|
|
}
|
|
|
|
|
2018-10-18 21:04:33 +02:00
|
|
|
/// Returns the exact size of memory occupied by the texture in VRAM, including mipmaps.
|
|
|
|
std::size_t MemorySize() const {
|
2018-10-25 00:30:27 +02:00
|
|
|
std::size_t size = InnerMemorySize(false, is_layered);
|
2018-10-18 21:04:33 +02:00
|
|
|
if (is_layered)
|
|
|
|
return size * depth;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the exact size of the memory occupied by a layer in a texture in VRAM, including
|
|
|
|
/// mipmaps.
|
|
|
|
std::size_t LayerMemorySize() const {
|
2018-10-25 00:30:27 +02:00
|
|
|
return InnerMemorySize(false, true);
|
2018-10-18 21:04:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the size of a layer of this surface in OpenGL.
|
2018-10-25 00:30:27 +02:00
|
|
|
std::size_t LayerSizeGL(u32 mip_level) const {
|
|
|
|
return InnerMipmapMemorySize(mip_level, true, is_layered, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t GetMipmapSizeGL(u32 mip_level, bool ignore_compressed = true) const {
|
|
|
|
std::size_t size = InnerMipmapMemorySize(mip_level, true, is_layered, ignore_compressed);
|
|
|
|
if (is_layered)
|
|
|
|
return size * depth;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t GetMipmapLevelOffset(u32 mip_level) const {
|
|
|
|
std::size_t offset = 0;
|
|
|
|
for (u32 i = 0; i < mip_level; i++)
|
|
|
|
offset += InnerMipmapMemorySize(i, false, is_layered);
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t GetMipmapLevelOffsetGL(u32 mip_level) const {
|
|
|
|
std::size_t offset = 0;
|
|
|
|
for (u32 i = 0; i < mip_level; i++)
|
|
|
|
offset += InnerMipmapMemorySize(i, true, is_layered);
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 MipWidth(u32 mip_level) const {
|
|
|
|
return std::max(1U, width >> mip_level);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 MipHeight(u32 mip_level) const {
|
|
|
|
return std::max(1U, height >> mip_level);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 MipDepth(u32 mip_level) const {
|
2018-10-30 03:46:09 +01:00
|
|
|
return is_layered ? depth : std::max(1U, depth >> mip_level);
|
2018-10-25 00:30:27 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 18:24:10 +02:00
|
|
|
// Auto block resizing algorithm from:
|
|
|
|
// https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
|
2018-10-27 01:18:03 +02:00
|
|
|
u32 MipBlockHeight(u32 mip_level) const {
|
2018-10-25 18:24:10 +02:00
|
|
|
if (mip_level == 0)
|
|
|
|
return block_height;
|
2018-10-27 01:18:03 +02:00
|
|
|
u32 alt_height = MipHeight(mip_level);
|
|
|
|
u32 h = GetDefaultBlockHeight(pixel_format);
|
|
|
|
u32 blocks_in_y = (alt_height + h - 1) / h;
|
|
|
|
u32 bh = 16;
|
|
|
|
while (bh > 1 && blocks_in_y <= bh * 4) {
|
2018-10-25 18:24:10 +02:00
|
|
|
bh >>= 1;
|
2018-10-25 00:30:27 +02:00
|
|
|
}
|
|
|
|
return bh;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 MipBlockDepth(u32 mip_level) const {
|
2018-10-25 18:24:10 +02:00
|
|
|
if (mip_level == 0)
|
|
|
|
return block_depth;
|
2018-10-27 01:18:03 +02:00
|
|
|
if (is_layered)
|
|
|
|
return 1;
|
2018-10-25 00:30:27 +02:00
|
|
|
u32 depth = MipDepth(mip_level);
|
2018-10-25 18:24:10 +02:00
|
|
|
u32 bd = 32;
|
2018-10-27 01:18:03 +02:00
|
|
|
while (bd > 1 && depth * 2 <= bd) {
|
|
|
|
bd >>= 1;
|
|
|
|
}
|
|
|
|
if (bd == 32) {
|
|
|
|
u32 bh = MipBlockHeight(mip_level);
|
|
|
|
if (bh >= 4)
|
|
|
|
return 16;
|
2018-10-25 00:30:27 +02:00
|
|
|
}
|
|
|
|
return bd;
|
2018-10-18 21:04:33 +02:00
|
|
|
}
|
|
|
|
|
2018-07-04 05:32:59 +02:00
|
|
|
/// Creates SurfaceParams from a texture configuration
|
2018-09-14 17:42:28 +02:00
|
|
|
static SurfaceParams CreateForTexture(const Tegra::Texture::FullTextureInfo& config,
|
|
|
|
const GLShader::SamplerEntry& entry);
|
2018-06-26 20:59:45 +02:00
|
|
|
|
2018-07-04 05:32:59 +02:00
|
|
|
/// Creates SurfaceParams from a framebuffer configuration
|
2018-09-15 15:21:06 +02:00
|
|
|
static SurfaceParams CreateForFramebuffer(std::size_t index);
|
2018-06-26 20:59:45 +02:00
|
|
|
|
2018-07-04 05:32:59 +02:00
|
|
|
/// Creates SurfaceParams for a depth buffer configuration
|
2018-10-10 04:28:19 +02:00
|
|
|
static SurfaceParams CreateForDepthBuffer(
|
|
|
|
u32 zeta_width, u32 zeta_height, Tegra::GPUVAddr zeta_address, Tegra::DepthFormat format,
|
|
|
|
u32 block_width, u32 block_height, u32 block_depth,
|
|
|
|
Tegra::Engines::Maxwell3D::Regs::InvMemoryLayout type);
|
2018-07-04 05:32:59 +02:00
|
|
|
|
2018-10-06 05:39:03 +02:00
|
|
|
/// Creates SurfaceParams for a Fermi2D surface copy
|
|
|
|
static SurfaceParams CreateForFermiCopySurface(
|
|
|
|
const Tegra::Engines::Fermi2D::Regs::Surface& config);
|
|
|
|
|
2018-08-06 05:30:18 +02:00
|
|
|
/// Checks if surfaces are compatible for caching
|
|
|
|
bool IsCompatibleSurface(const SurfaceParams& other) const {
|
2018-11-16 18:01:54 +01:00
|
|
|
if (std::tie(pixel_format, type, width, height, target, depth, is_tiled) ==
|
|
|
|
std::tie(other.pixel_format, other.type, other.width, other.height, other.target,
|
|
|
|
other.depth, other.is_tiled)) {
|
|
|
|
if (!is_tiled)
|
|
|
|
return true;
|
|
|
|
return std::tie(block_height, block_depth, tile_width_spacing) ==
|
|
|
|
std::tie(other.block_height, other.block_depth, other.tile_width_spacing);
|
|
|
|
}
|
|
|
|
return false;
|
2018-08-06 05:30:18 +02:00
|
|
|
}
|
|
|
|
|
2018-10-13 04:24:40 +02:00
|
|
|
/// Initializes parameters for caching, should be called after everything has been initialized
|
|
|
|
void InitCacheParameters(Tegra::GPUVAddr gpu_addr);
|
|
|
|
|
2018-06-26 20:59:45 +02:00
|
|
|
bool is_tiled;
|
2018-10-08 20:34:55 +02:00
|
|
|
u32 block_width;
|
2018-06-26 20:59:45 +02:00
|
|
|
u32 block_height;
|
2018-10-08 20:34:55 +02:00
|
|
|
u32 block_depth;
|
2018-11-16 18:01:54 +01:00
|
|
|
u32 tile_width_spacing;
|
2018-06-26 20:59:45 +02:00
|
|
|
PixelFormat pixel_format;
|
|
|
|
ComponentType component_type;
|
|
|
|
SurfaceType type;
|
|
|
|
u32 width;
|
|
|
|
u32 height;
|
2018-09-05 04:00:24 +02:00
|
|
|
u32 depth;
|
2018-06-26 21:05:13 +02:00
|
|
|
u32 unaligned_height;
|
2018-09-01 08:42:43 +02:00
|
|
|
SurfaceTarget target;
|
2018-09-21 05:41:25 +02:00
|
|
|
u32 max_mip_level;
|
2018-10-18 21:04:33 +02:00
|
|
|
bool is_layered;
|
2018-10-24 22:09:40 +02:00
|
|
|
bool srgb_conversion;
|
2018-10-13 04:24:40 +02:00
|
|
|
// Parameters used for caching
|
|
|
|
VAddr addr;
|
2018-10-16 03:24:34 +02:00
|
|
|
Tegra::GPUVAddr gpu_addr;
|
2018-10-13 08:08:04 +02:00
|
|
|
std::size_t size_in_bytes;
|
|
|
|
std::size_t size_in_bytes_gl;
|
2018-10-13 04:24:40 +02:00
|
|
|
|
2018-09-21 05:41:25 +02:00
|
|
|
// Render target specific parameters, not used in caching
|
|
|
|
struct {
|
|
|
|
u32 index;
|
|
|
|
u32 array_mode;
|
2018-10-16 03:04:20 +02:00
|
|
|
u32 volume;
|
2018-09-21 05:41:25 +02:00
|
|
|
u32 layer_stride;
|
|
|
|
u32 base_layer;
|
|
|
|
} rt;
|
2018-10-18 21:04:33 +02:00
|
|
|
|
|
|
|
private:
|
2018-10-25 00:30:27 +02:00
|
|
|
std::size_t InnerMipmapMemorySize(u32 mip_level, bool force_gl = false, bool layer_only = false,
|
|
|
|
bool uncompressed = false) const;
|
|
|
|
std::size_t InnerMemorySize(bool force_gl = false, bool layer_only = false,
|
|
|
|
bool uncompressed = false) const;
|
2018-06-26 20:59:45 +02:00
|
|
|
};
|
|
|
|
|
2018-08-22 04:04:54 +02:00
|
|
|
}; // namespace OpenGL
|
|
|
|
|
|
|
|
/// Hashable variation of SurfaceParams, used for a key in the surface cache
|
|
|
|
struct SurfaceReserveKey : Common::HashableStruct<OpenGL::SurfaceParams> {
|
|
|
|
static SurfaceReserveKey Create(const OpenGL::SurfaceParams& params) {
|
|
|
|
SurfaceReserveKey res;
|
|
|
|
res.state = params;
|
2018-10-16 03:24:34 +02:00
|
|
|
res.state.gpu_addr = {}; // Ignore GPU vaddr in caching
|
|
|
|
res.state.rt = {}; // Ignore rt config in caching
|
2018-08-22 04:04:54 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
namespace std {
|
|
|
|
template <>
|
|
|
|
struct hash<SurfaceReserveKey> {
|
2018-09-15 15:21:06 +02:00
|
|
|
std::size_t operator()(const SurfaceReserveKey& k) const {
|
2018-08-22 04:04:54 +02:00
|
|
|
return k.Hash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace OpenGL {
|
|
|
|
|
2018-11-08 12:08:00 +01:00
|
|
|
class RasterizerOpenGL;
|
|
|
|
|
2018-10-16 22:51:53 +02:00
|
|
|
class CachedSurface final : public RasterizerCacheObject {
|
2018-06-22 01:36:01 +02:00
|
|
|
public:
|
|
|
|
CachedSurface(const SurfaceParams& params);
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-10-16 22:51:53 +02:00
|
|
|
VAddr GetAddr() const override {
|
2018-08-23 21:44:41 +02:00
|
|
|
return params.addr;
|
|
|
|
}
|
|
|
|
|
2018-10-16 22:51:53 +02:00
|
|
|
std::size_t GetSizeInBytes() const override {
|
2018-10-16 03:24:34 +02:00
|
|
|
return cached_size_in_bytes;
|
2018-08-23 21:44:41 +02:00
|
|
|
}
|
|
|
|
|
2018-10-16 22:51:53 +02:00
|
|
|
void Flush() override {
|
2018-10-10 01:15:05 +02:00
|
|
|
FlushGLBuffer();
|
|
|
|
}
|
|
|
|
|
2018-06-22 01:36:01 +02:00
|
|
|
const OGLTexture& Texture() const {
|
|
|
|
return texture;
|
2018-03-19 22:45:22 +01:00
|
|
|
}
|
|
|
|
|
2018-12-29 21:51:32 +01:00
|
|
|
const OGLTexture& TextureLayer() {
|
|
|
|
if (params.is_layered) {
|
|
|
|
return Texture();
|
|
|
|
}
|
|
|
|
EnsureTextureView();
|
|
|
|
return texture_view;
|
|
|
|
}
|
|
|
|
|
2018-09-01 08:42:43 +02:00
|
|
|
GLenum Target() const {
|
|
|
|
return gl_target;
|
|
|
|
}
|
|
|
|
|
2018-12-29 21:51:32 +01:00
|
|
|
GLenum TargetLayer() const {
|
|
|
|
using VideoCore::Surface::SurfaceTarget;
|
|
|
|
switch (params.target) {
|
|
|
|
case SurfaceTarget::Texture1D:
|
|
|
|
return GL_TEXTURE_1D_ARRAY;
|
|
|
|
case SurfaceTarget::Texture2D:
|
|
|
|
return GL_TEXTURE_2D_ARRAY;
|
|
|
|
case SurfaceTarget::TextureCubemap:
|
|
|
|
return GL_TEXTURE_CUBE_MAP_ARRAY;
|
|
|
|
}
|
|
|
|
return Target();
|
|
|
|
}
|
|
|
|
|
2018-06-22 01:36:01 +02:00
|
|
|
const SurfaceParams& GetSurfaceParams() const {
|
|
|
|
return params;
|
|
|
|
}
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-03-23 04:06:54 +01:00
|
|
|
// Read/Write data in Switch memory to/from gl_buffer
|
2018-06-22 01:36:01 +02:00
|
|
|
void LoadGLBuffer();
|
|
|
|
void FlushGLBuffer();
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-09-01 08:42:43 +02:00
|
|
|
// Upload data in gl_buffer to this surface's texture
|
2018-06-22 01:36:01 +02:00
|
|
|
void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle);
|
|
|
|
|
|
|
|
private:
|
2018-10-25 00:30:27 +02:00
|
|
|
void UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, GLuint draw_fb_handle);
|
|
|
|
|
2018-12-29 21:51:32 +01:00
|
|
|
void EnsureTextureView();
|
|
|
|
|
2018-06-22 01:36:01 +02:00
|
|
|
OGLTexture texture;
|
2018-12-29 21:51:32 +01:00
|
|
|
OGLTexture texture_view;
|
2018-10-25 00:30:27 +02:00
|
|
|
std::vector<std::vector<u8>> gl_buffer;
|
2018-12-29 21:51:32 +01:00
|
|
|
SurfaceParams params{};
|
|
|
|
GLenum gl_target{};
|
|
|
|
GLenum gl_internal_format{};
|
|
|
|
bool gl_is_compressed{};
|
|
|
|
std::size_t cached_size_in_bytes{};
|
2018-03-19 22:45:22 +01:00
|
|
|
};
|
|
|
|
|
2018-08-23 21:44:41 +02:00
|
|
|
class RasterizerCacheOpenGL final : public RasterizerCache<Surface> {
|
2018-03-19 22:45:22 +01:00
|
|
|
public:
|
2018-11-08 12:08:00 +01:00
|
|
|
explicit RasterizerCacheOpenGL(RasterizerOpenGL& rasterizer);
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-06-26 22:14:14 +02:00
|
|
|
/// Get a surface based on the texture configuration
|
2018-09-14 17:42:28 +02:00
|
|
|
Surface GetTextureSurface(const Tegra::Texture::FullTextureInfo& config,
|
|
|
|
const GLShader::SamplerEntry& entry);
|
2018-06-26 22:14:14 +02:00
|
|
|
|
2018-09-10 01:01:21 +02:00
|
|
|
/// Get the depth surface based on the framebuffer configuration
|
|
|
|
Surface GetDepthBufferSurface(bool preserve_contents);
|
|
|
|
|
|
|
|
/// Get the color surface based on the framebuffer configuration and the specified render target
|
2018-09-15 15:21:06 +02:00
|
|
|
Surface GetColorBufferSurface(std::size_t index, bool preserve_contents);
|
2018-06-26 22:14:14 +02:00
|
|
|
|
2018-08-28 03:35:15 +02:00
|
|
|
/// Tries to find a framebuffer using on the provided CPU address
|
|
|
|
Surface TryFindFramebufferSurface(VAddr addr) const;
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-10-06 05:39:03 +02:00
|
|
|
/// Copies the contents of one surface to another
|
|
|
|
void FermiCopySurface(const Tegra::Engines::Fermi2D::Regs::Surface& src_config,
|
|
|
|
const Tegra::Engines::Fermi2D::Regs::Surface& dst_config);
|
|
|
|
|
2018-03-19 22:45:22 +01:00
|
|
|
private:
|
2018-06-26 22:14:14 +02:00
|
|
|
void LoadSurface(const Surface& surface);
|
2018-08-20 22:18:51 +02:00
|
|
|
Surface GetSurface(const SurfaceParams& params, bool preserve_contents = true);
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-08-31 02:08:43 +02:00
|
|
|
/// Gets an uncached surface, creating it if need be
|
|
|
|
Surface GetUncachedSurface(const SurfaceParams& params);
|
|
|
|
|
2018-07-21 22:04:01 +02:00
|
|
|
/// Recreates a surface with new parameters
|
2018-09-14 17:33:55 +02:00
|
|
|
Surface RecreateSurface(const Surface& old_surface, const SurfaceParams& new_params);
|
2018-07-21 22:04:01 +02:00
|
|
|
|
2018-08-22 04:04:54 +02:00
|
|
|
/// Reserves a unique surface that can be reused later
|
|
|
|
void ReserveSurface(const Surface& surface);
|
|
|
|
|
|
|
|
/// Tries to get a reserved surface for the specified parameters
|
|
|
|
Surface TryGetReservedSurface(const SurfaceParams& params);
|
|
|
|
|
2018-10-16 23:20:49 +02:00
|
|
|
/// Performs a slow but accurate surface copy, flushing to RAM and reinterpreting the data
|
|
|
|
void AccurateCopySurface(const Surface& src_surface, const Surface& dst_surface);
|
2018-11-19 17:04:07 +01:00
|
|
|
void FastLayeredCopySurface(const Surface& src_surface, const Surface& dst_surface);
|
2018-10-16 23:20:49 +02:00
|
|
|
|
2018-08-22 04:04:54 +02:00
|
|
|
/// The surface reserve is a "backup" cache, this is where we put unique surfaces that have
|
|
|
|
/// previously been used. This is to prevent surfaces from being constantly created and
|
|
|
|
/// destroyed when used with different surface parameters.
|
|
|
|
std::unordered_map<SurfaceReserveKey, Surface> surface_reserve;
|
|
|
|
|
2018-03-19 22:45:22 +01:00
|
|
|
OGLFramebuffer read_framebuffer;
|
|
|
|
OGLFramebuffer draw_framebuffer;
|
2018-09-08 07:04:47 +02:00
|
|
|
|
|
|
|
/// Use a Pixel Buffer Object to download the previous texture and then upload it to the new one
|
|
|
|
/// using the new format.
|
|
|
|
OGLBuffer copy_pbo;
|
2019-01-07 05:11:03 +01:00
|
|
|
|
|
|
|
std::array<Surface, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> last_color_buffers;
|
2018-03-19 22:45:22 +01:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|