2015-05-19 06:21:33 +02:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-04-30 17:34:51 +02:00
|
|
|
#include <array>
|
2018-04-29 11:51:02 +02:00
|
|
|
#include <list>
|
2015-09-11 13:20:02 +02:00
|
|
|
#include <memory>
|
2016-04-17 00:57:57 +02:00
|
|
|
#include <set>
|
2016-04-30 17:34:51 +02:00
|
|
|
#include <tuple>
|
2017-01-29 19:53:52 +01:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma GCC diagnostic push
|
2017-10-22 09:56:50 +02:00
|
|
|
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
|
2017-01-29 19:53:52 +01:00
|
|
|
#endif
|
2016-04-17 00:57:57 +02:00
|
|
|
#include <boost/icl/interval_map.hpp>
|
2017-11-17 18:27:51 +01:00
|
|
|
#include <boost/icl/interval_set.hpp>
|
2017-01-29 19:53:52 +01:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
2018-04-29 11:51:02 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <boost/functional/hash.hpp>
|
2016-04-30 17:34:51 +02:00
|
|
|
#include <glad/glad.h>
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_funcs.h"
|
|
|
|
#include "common/common_types.h"
|
2017-11-17 18:27:51 +01:00
|
|
|
#include "common/math_util.h"
|
2016-04-17 00:57:57 +02:00
|
|
|
#include "core/hw/gpu.h"
|
2017-01-29 00:12:09 +01:00
|
|
|
#include "video_core/regs_framebuffer.h"
|
|
|
|
#include "video_core/regs_texturing.h"
|
2015-09-11 13:20:02 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2018-04-29 11:51:02 +02:00
|
|
|
#include "video_core/texture/texture_decode.h"
|
2016-04-30 17:34:51 +02:00
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
struct CachedSurface;
|
2017-11-17 18:27:51 +01:00
|
|
|
using Surface = std::shared_ptr<CachedSurface>;
|
|
|
|
using SurfaceSet = std::set<Surface>;
|
|
|
|
|
|
|
|
using SurfaceRegions = boost::icl::interval_set<PAddr>;
|
|
|
|
using SurfaceMap = boost::icl::interval_map<PAddr, Surface>;
|
|
|
|
using SurfaceCache = boost::icl::interval_map<PAddr, SurfaceSet>;
|
|
|
|
|
|
|
|
using SurfaceInterval = SurfaceCache::interval_type;
|
|
|
|
static_assert(std::is_same<SurfaceRegions::interval_type, SurfaceCache::interval_type>() &&
|
|
|
|
std::is_same<SurfaceMap::interval_type, SurfaceCache::interval_type>(),
|
|
|
|
"incorrect interval types");
|
|
|
|
|
|
|
|
using SurfaceRect_Tuple = std::tuple<Surface, MathUtil::Rectangle<u32>>;
|
|
|
|
using SurfaceSurfaceRect_Tuple = std::tuple<Surface, Surface, MathUtil::Rectangle<u32>>;
|
|
|
|
|
|
|
|
using PageMap = boost::icl::interval_map<u32, int>;
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-11-17 18:27:51 +01:00
|
|
|
enum class ScaleMatch {
|
|
|
|
Exact, // only accept same res scale
|
|
|
|
Upscale, // only allow higher scale than params
|
|
|
|
Ignore // accept every scaled res
|
|
|
|
};
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-11-17 18:27:51 +01:00
|
|
|
struct SurfaceParams {
|
2016-04-17 00:57:57 +02:00
|
|
|
enum class PixelFormat {
|
|
|
|
// First 5 formats are shared between textures and color buffers
|
2016-09-18 02:38:01 +02:00
|
|
|
RGBA8 = 0,
|
|
|
|
RGB8 = 1,
|
|
|
|
RGB5A1 = 2,
|
|
|
|
RGB565 = 3,
|
|
|
|
RGBA4 = 4,
|
2016-04-17 00:57:57 +02:00
|
|
|
|
|
|
|
// Texture-only formats
|
2016-09-18 02:38:01 +02:00
|
|
|
IA8 = 5,
|
|
|
|
RG8 = 6,
|
|
|
|
I8 = 7,
|
|
|
|
A8 = 8,
|
|
|
|
IA4 = 9,
|
|
|
|
I4 = 10,
|
|
|
|
A4 = 11,
|
|
|
|
ETC1 = 12,
|
|
|
|
ETC1A4 = 13,
|
2016-04-17 00:57:57 +02:00
|
|
|
|
|
|
|
// Depth buffer-only formats
|
2016-09-18 02:38:01 +02:00
|
|
|
D16 = 14,
|
2016-04-17 00:57:57 +02:00
|
|
|
// gap
|
2016-09-18 02:38:01 +02:00
|
|
|
D24 = 16,
|
|
|
|
D24S8 = 17,
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
Invalid = 255,
|
2016-04-17 00:57:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class SurfaceType {
|
2016-09-18 02:38:01 +02:00
|
|
|
Color = 0,
|
|
|
|
Texture = 1,
|
|
|
|
Depth = 2,
|
2016-04-17 00:57:57 +02:00
|
|
|
DepthStencil = 3,
|
2017-11-17 18:27:51 +01:00
|
|
|
Fill = 4,
|
|
|
|
Invalid = 5
|
2016-04-17 00:57:57 +02:00
|
|
|
};
|
|
|
|
|
2017-11-17 18:27:51 +01:00
|
|
|
static constexpr unsigned int GetFormatBpp(PixelFormat format) {
|
2017-11-17 05:20:50 +01:00
|
|
|
constexpr std::array<unsigned int, 18> bpp_table = {
|
2016-04-17 00:57:57 +02:00
|
|
|
32, // RGBA8
|
|
|
|
24, // RGB8
|
|
|
|
16, // RGB5A1
|
|
|
|
16, // RGB565
|
|
|
|
16, // RGBA4
|
|
|
|
16, // IA8
|
|
|
|
16, // RG8
|
|
|
|
8, // I8
|
|
|
|
8, // A8
|
|
|
|
8, // IA4
|
|
|
|
4, // I4
|
|
|
|
4, // A4
|
|
|
|
4, // ETC1
|
|
|
|
8, // ETC1A4
|
|
|
|
16, // D16
|
|
|
|
0,
|
|
|
|
24, // D24
|
|
|
|
32, // D24S8
|
|
|
|
};
|
|
|
|
|
2017-12-13 18:22:29 +01:00
|
|
|
assert(static_cast<size_t>(format) < bpp_table.size());
|
2017-11-17 18:27:51 +01:00
|
|
|
return bpp_table[static_cast<size_t>(format)];
|
|
|
|
}
|
|
|
|
unsigned int GetFormatBpp() const {
|
|
|
|
return GetFormatBpp(pixel_format);
|
2016-04-17 00:57:57 +02:00
|
|
|
}
|
|
|
|
|
2017-01-28 05:51:59 +01:00
|
|
|
static PixelFormat PixelFormatFromTextureFormat(Pica::TexturingRegs::TextureFormat format) {
|
2016-04-17 00:57:57 +02:00
|
|
|
return ((unsigned int)format < 14) ? (PixelFormat)format : PixelFormat::Invalid;
|
|
|
|
}
|
|
|
|
|
2017-01-28 06:47:34 +01:00
|
|
|
static PixelFormat PixelFormatFromColorFormat(Pica::FramebufferRegs::ColorFormat format) {
|
2016-04-17 00:57:57 +02:00
|
|
|
return ((unsigned int)format < 5) ? (PixelFormat)format : PixelFormat::Invalid;
|
|
|
|
}
|
|
|
|
|
2017-01-28 06:47:34 +01:00
|
|
|
static PixelFormat PixelFormatFromDepthFormat(Pica::FramebufferRegs::DepthFormat format) {
|
2016-09-18 02:38:01 +02:00
|
|
|
return ((unsigned int)format < 4) ? (PixelFormat)((unsigned int)format + 14)
|
|
|
|
: PixelFormat::Invalid;
|
2016-04-17 00:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static PixelFormat PixelFormatFromGPUPixelFormat(GPU::Regs::PixelFormat format) {
|
|
|
|
switch (format) {
|
|
|
|
// RGB565 and RGB5A1 are switched in PixelFormat compared to ColorFormat
|
|
|
|
case GPU::Regs::PixelFormat::RGB565:
|
|
|
|
return PixelFormat::RGB565;
|
|
|
|
case GPU::Regs::PixelFormat::RGB5A1:
|
|
|
|
return PixelFormat::RGB5A1;
|
|
|
|
default:
|
|
|
|
return ((unsigned int)format < 5) ? (PixelFormat)format : PixelFormat::Invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool CheckFormatsBlittable(PixelFormat pixel_format_a, PixelFormat pixel_format_b) {
|
|
|
|
SurfaceType a_type = GetFormatType(pixel_format_a);
|
|
|
|
SurfaceType b_type = GetFormatType(pixel_format_b);
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
if ((a_type == SurfaceType::Color || a_type == SurfaceType::Texture) &&
|
|
|
|
(b_type == SurfaceType::Color || b_type == SurfaceType::Texture)) {
|
2016-04-17 00:57:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_type == SurfaceType::Depth && b_type == SurfaceType::Depth) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_type == SurfaceType::DepthStencil && b_type == SurfaceType::DepthStencil) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-17 05:20:50 +01:00
|
|
|
static constexpr SurfaceType GetFormatType(PixelFormat pixel_format) {
|
2016-04-17 00:57:57 +02:00
|
|
|
if ((unsigned int)pixel_format < 5) {
|
|
|
|
return SurfaceType::Color;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((unsigned int)pixel_format < 14) {
|
|
|
|
return SurfaceType::Texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixel_format == PixelFormat::D16 || pixel_format == PixelFormat::D24) {
|
|
|
|
return SurfaceType::Depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixel_format == PixelFormat::D24S8) {
|
|
|
|
return SurfaceType::DepthStencil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SurfaceType::Invalid;
|
|
|
|
}
|
|
|
|
|
2017-11-17 18:27:51 +01:00
|
|
|
/// Update the params "size", "end" and "type" from the already set "addr", "width", "height"
|
|
|
|
/// and "pixel_format"
|
|
|
|
void UpdateParams() {
|
|
|
|
if (stride == 0) {
|
|
|
|
stride = width;
|
|
|
|
}
|
|
|
|
type = GetFormatType(pixel_format);
|
|
|
|
size = !is_tiled ? BytesInPixels(stride * (height - 1) + width)
|
|
|
|
: BytesInPixels(stride * 8 * (height / 8 - 1) + width * 8);
|
|
|
|
end = addr + size;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterval GetInterval() const {
|
|
|
|
return SurfaceInterval::right_open(addr, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the outer rectangle containing "interval"
|
|
|
|
SurfaceParams FromInterval(SurfaceInterval interval) const;
|
|
|
|
|
|
|
|
SurfaceInterval GetSubRectInterval(MathUtil::Rectangle<u32> unscaled_rect) const;
|
|
|
|
|
|
|
|
// Returns the region of the biggest valid rectange within interval
|
|
|
|
SurfaceInterval GetCopyableInterval(const Surface& src_surface) const;
|
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
u32 GetScaledWidth() const {
|
2017-11-17 18:27:51 +01:00
|
|
|
return width * res_scale;
|
2016-04-17 00:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 GetScaledHeight() const {
|
2017-11-17 18:27:51 +01:00
|
|
|
return height * res_scale;
|
2016-04-17 00:57:57 +02:00
|
|
|
}
|
|
|
|
|
2017-11-17 18:27:51 +01:00
|
|
|
MathUtil::Rectangle<u32> GetRect() const {
|
|
|
|
return {0, height, width, 0};
|
|
|
|
}
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-11-17 18:27:51 +01:00
|
|
|
MathUtil::Rectangle<u32> GetScaledRect() const {
|
|
|
|
return {0, GetScaledHeight(), GetScaledWidth(), 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 PixelsInBytes(u32 size) const {
|
2017-12-24 00:09:25 +01:00
|
|
|
return size * CHAR_BIT / GetFormatBpp(pixel_format);
|
2017-11-17 18:27:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 BytesInPixels(u32 pixels) const {
|
2017-12-24 00:09:25 +01:00
|
|
|
return pixels * GetFormatBpp(pixel_format) / CHAR_BIT;
|
2017-11-17 18:27:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ExactMatch(const SurfaceParams& other_surface) const;
|
|
|
|
bool CanSubRect(const SurfaceParams& sub_surface) const;
|
|
|
|
bool CanExpand(const SurfaceParams& expanded_surface) const;
|
|
|
|
bool CanTexCopy(const SurfaceParams& texcopy_params) const;
|
|
|
|
|
|
|
|
MathUtil::Rectangle<u32> GetSubRect(const SurfaceParams& sub_surface) const;
|
|
|
|
MathUtil::Rectangle<u32> GetScaledSubRect(const SurfaceParams& sub_surface) const;
|
|
|
|
|
|
|
|
PAddr addr = 0;
|
|
|
|
PAddr end = 0;
|
|
|
|
u32 size = 0;
|
|
|
|
|
|
|
|
u32 width = 0;
|
|
|
|
u32 height = 0;
|
|
|
|
u32 stride = 0;
|
|
|
|
u16 res_scale = 1;
|
|
|
|
|
|
|
|
bool is_tiled = false;
|
|
|
|
PixelFormat pixel_format = PixelFormat::Invalid;
|
|
|
|
SurfaceType type = SurfaceType::Invalid;
|
|
|
|
};
|
|
|
|
|
2018-04-29 11:51:02 +02:00
|
|
|
/**
|
|
|
|
* A watcher that notifies whether a cached surface has been changed. This is useful for caching
|
|
|
|
* surface collection objects, including texture cube and mipmap.
|
|
|
|
*/
|
|
|
|
struct SurfaceWatcher {
|
|
|
|
public:
|
|
|
|
explicit SurfaceWatcher(std::weak_ptr<CachedSurface>&& surface) : surface(std::move(surface)) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the surface has been changed.
|
|
|
|
* @return false if the surface content has been changed since last Validate() call or has been
|
|
|
|
* destroyed; otherwise true
|
|
|
|
*/
|
|
|
|
bool IsValid() const {
|
|
|
|
return !surface.expired() && valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Marks that the content of the referencing surface has been updated to the watcher user.
|
|
|
|
void Validate() {
|
|
|
|
ASSERT(!surface.expired());
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the referencing surface. Returns null if the surface has been destroyed
|
|
|
|
Surface Get() const {
|
|
|
|
return surface.lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend struct CachedSurface;
|
|
|
|
std::weak_ptr<CachedSurface> surface;
|
|
|
|
bool valid = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CachedSurface : SurfaceParams, std::enable_shared_from_this<CachedSurface> {
|
2017-11-17 18:27:51 +01:00
|
|
|
bool CanFill(const SurfaceParams& dest_surface, SurfaceInterval fill_interval) const;
|
|
|
|
bool CanCopy(const SurfaceParams& dest_surface, SurfaceInterval copy_interval) const;
|
|
|
|
|
|
|
|
bool IsRegionValid(SurfaceInterval interval) const {
|
|
|
|
return (invalid_regions.find(interval) == invalid_regions.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsSurfaceFullyInvalid() const {
|
|
|
|
return (invalid_regions & GetInterval()) == SurfaceRegions(GetInterval());
|
|
|
|
}
|
|
|
|
|
2017-12-30 07:42:32 +01:00
|
|
|
bool registered = false;
|
2017-11-17 18:27:51 +01:00
|
|
|
SurfaceRegions invalid_regions;
|
|
|
|
|
|
|
|
u32 fill_size = 0; /// Number of bytes to read from fill_data
|
|
|
|
std::array<u8, 4> fill_data;
|
2016-04-17 00:57:57 +02:00
|
|
|
|
|
|
|
OGLTexture texture;
|
2017-11-17 18:27:51 +01:00
|
|
|
|
|
|
|
static constexpr unsigned int GetGLBytesPerPixel(PixelFormat format) {
|
|
|
|
// OpenGL needs 4 bpp alignment for D24 since using GL_UNSIGNED_INT as type
|
|
|
|
return format == PixelFormat::Invalid
|
|
|
|
? 0
|
|
|
|
: (format == PixelFormat::D24 || GetFormatType(format) == SurfaceType::Texture)
|
|
|
|
? 4
|
|
|
|
: SurfaceParams::GetFormatBpp(format) / 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<u8[]> gl_buffer;
|
|
|
|
size_t gl_buffer_size = 0;
|
|
|
|
|
|
|
|
// Read/Write data in 3DS memory to/from gl_buffer
|
|
|
|
void LoadGLBuffer(PAddr load_start, PAddr load_end);
|
|
|
|
void FlushGLBuffer(PAddr flush_start, PAddr flush_end);
|
|
|
|
|
|
|
|
// Upload/Download data in gl_buffer in/to this surface's texture
|
2017-12-29 17:00:09 +01:00
|
|
|
void UploadGLTexture(const MathUtil::Rectangle<u32>& rect, GLuint read_fb_handle,
|
|
|
|
GLuint draw_fb_handle);
|
|
|
|
void DownloadGLTexture(const MathUtil::Rectangle<u32>& rect, GLuint read_fb_handle,
|
|
|
|
GLuint draw_fb_handle);
|
2018-04-29 11:51:02 +02:00
|
|
|
|
|
|
|
std::shared_ptr<SurfaceWatcher> CreateWatcher() {
|
|
|
|
auto watcher = std::make_shared<SurfaceWatcher>(weak_from_this());
|
|
|
|
watchers.push_front(watcher);
|
|
|
|
return watcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InvalidateAllWatcher() {
|
|
|
|
for (const auto& watcher : watchers) {
|
|
|
|
if (auto locked = watcher.lock()) {
|
|
|
|
locked->valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::list<std::weak_ptr<SurfaceWatcher>> watchers;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextureCubeConfig {
|
|
|
|
PAddr px;
|
|
|
|
PAddr nx;
|
|
|
|
PAddr py;
|
|
|
|
PAddr ny;
|
|
|
|
PAddr pz;
|
|
|
|
PAddr nz;
|
|
|
|
u32 width;
|
|
|
|
Pica::TexturingRegs::TextureFormat format;
|
|
|
|
|
|
|
|
bool operator==(const TextureCubeConfig& rhs) const {
|
|
|
|
return std::tie(px, nx, py, ny, pz, nz, width, format) ==
|
|
|
|
std::tie(rhs.px, rhs.nx, rhs.py, rhs.ny, rhs.pz, rhs.nz, rhs.width, rhs.format);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const TextureCubeConfig& rhs) const {
|
|
|
|
return !(*this == rhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template <>
|
|
|
|
struct hash<TextureCubeConfig> {
|
|
|
|
size_t operator()(const TextureCubeConfig& config) const {
|
|
|
|
std::size_t hash = 0;
|
|
|
|
boost::hash_combine(hash, config.px);
|
|
|
|
boost::hash_combine(hash, config.nx);
|
|
|
|
boost::hash_combine(hash, config.py);
|
|
|
|
boost::hash_combine(hash, config.ny);
|
|
|
|
boost::hash_combine(hash, config.pz);
|
|
|
|
boost::hash_combine(hash, config.nz);
|
|
|
|
boost::hash_combine(hash, config.width);
|
|
|
|
boost::hash_combine(hash, static_cast<u32>(config.format));
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
struct CachedTextureCube {
|
|
|
|
OGLTexture texture;
|
|
|
|
u16 res_scale = 1;
|
|
|
|
std::shared_ptr<SurfaceWatcher> px;
|
|
|
|
std::shared_ptr<SurfaceWatcher> nx;
|
|
|
|
std::shared_ptr<SurfaceWatcher> py;
|
|
|
|
std::shared_ptr<SurfaceWatcher> ny;
|
|
|
|
std::shared_ptr<SurfaceWatcher> pz;
|
|
|
|
std::shared_ptr<SurfaceWatcher> nz;
|
2016-04-17 00:57:57 +02:00
|
|
|
};
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
class RasterizerCacheOpenGL : NonCopyable {
|
|
|
|
public:
|
2016-04-17 00:57:57 +02:00
|
|
|
RasterizerCacheOpenGL();
|
2015-05-19 06:21:33 +02:00
|
|
|
~RasterizerCacheOpenGL();
|
|
|
|
|
2017-11-25 21:21:32 +01:00
|
|
|
/// Blit one surface's texture to another
|
|
|
|
bool BlitSurfaces(const Surface& src_surface, const MathUtil::Rectangle<u32>& src_rect,
|
|
|
|
const Surface& dst_surface, const MathUtil::Rectangle<u32>& dst_rect);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2018-01-16 03:06:35 +01:00
|
|
|
void ConvertD24S8toABGR(GLuint src_tex, const MathUtil::Rectangle<u32>& src_rect,
|
|
|
|
GLuint dst_tex, const MathUtil::Rectangle<u32>& dst_rect);
|
|
|
|
|
2017-11-25 21:21:32 +01:00
|
|
|
/// Copy one surface's region to another
|
|
|
|
void CopySurface(const Surface& src_surface, const Surface& dst_surface,
|
|
|
|
SurfaceInterval copy_interval);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-11-25 21:21:32 +01:00
|
|
|
/// Load a texture from 3DS memory to OpenGL and cache it (if not already cached)
|
|
|
|
Surface GetSurface(const SurfaceParams& params, ScaleMatch match_res_scale,
|
|
|
|
bool load_if_create);
|
2015-08-30 15:05:56 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
/// Attempt to find a subrect (resolution scaled) of a surface, otherwise loads a texture from
|
|
|
|
/// 3DS memory to OpenGL and caches it (if not already cached)
|
2017-11-25 21:21:32 +01:00
|
|
|
SurfaceRect_Tuple GetSurfaceSubRect(const SurfaceParams& params, ScaleMatch match_res_scale,
|
|
|
|
bool load_if_create);
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2017-11-25 21:21:32 +01:00
|
|
|
/// Get a surface based on the texture configuration
|
2018-04-29 11:51:02 +02:00
|
|
|
Surface GetTextureSurface(const Pica::TexturingRegs::FullTextureConfig& config);
|
|
|
|
Surface GetTextureSurface(const Pica::Texture::TextureInfo& info);
|
2018-03-09 15:46:34 +01:00
|
|
|
|
2018-04-29 11:51:02 +02:00
|
|
|
/// Get a texture cube based on the texture configuration
|
|
|
|
const CachedTextureCube& GetTextureCube(const TextureCubeConfig& config);
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2017-11-25 21:21:32 +01:00
|
|
|
/// Get the color and depth surfaces based on the framebuffer configuration
|
|
|
|
SurfaceSurfaceRect_Tuple GetFramebufferSurfaces(bool using_color_fb, bool using_depth_fb,
|
|
|
|
const MathUtil::Rectangle<s32>& viewport_rect);
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2017-11-25 21:21:32 +01:00
|
|
|
/// Get a surface that matches the fill config
|
|
|
|
Surface GetFillSurface(const GPU::Regs::MemoryFillConfig& config);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-11-25 21:21:32 +01:00
|
|
|
/// Get a surface that matches a "texture copy" display transfer config
|
|
|
|
SurfaceRect_Tuple GetTexCopySurface(const SurfaceParams& params);
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2017-11-25 21:21:32 +01:00
|
|
|
/// Write any cached resources overlapping the region back to memory (if dirty)
|
|
|
|
void FlushRegion(PAddr addr, u32 size, Surface flush_surface = nullptr);
|
|
|
|
|
|
|
|
/// Mark region as being invalidated by region_owner (nullptr if 3DS memory)
|
|
|
|
void InvalidateRegion(PAddr addr, u32 size, const Surface& region_owner);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
|
|
|
/// Flush all cached resources tracked by this cache manager
|
|
|
|
void FlushAll();
|
|
|
|
|
|
|
|
private:
|
2017-11-25 21:21:32 +01:00
|
|
|
void DuplicateSurface(const Surface& src_surface, const Surface& dest_surface);
|
|
|
|
|
|
|
|
/// Update surface's texture for given region when necessary
|
|
|
|
void ValidateSurface(const Surface& surface, PAddr addr, u32 size);
|
|
|
|
|
|
|
|
/// Create a new surface
|
|
|
|
Surface CreateSurface(const SurfaceParams& params);
|
|
|
|
|
|
|
|
/// Register surface into the cache
|
|
|
|
void RegisterSurface(const Surface& surface);
|
|
|
|
|
|
|
|
/// Remove surface from the cache
|
|
|
|
void UnregisterSurface(const Surface& surface);
|
|
|
|
|
|
|
|
/// Increase/decrease the number of surface in pages touching the specified region
|
|
|
|
void UpdatePagesCachedCount(PAddr addr, u32 size, int delta);
|
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
SurfaceCache surface_cache;
|
2017-11-25 21:21:32 +01:00
|
|
|
PageMap cached_pages;
|
2017-12-29 17:00:09 +01:00
|
|
|
SurfaceMap dirty_regions;
|
2017-11-25 21:21:32 +01:00
|
|
|
SurfaceSet remove_surfaces;
|
2017-12-29 17:00:09 +01:00
|
|
|
|
2017-12-24 00:09:25 +01:00
|
|
|
OGLFramebuffer read_framebuffer;
|
|
|
|
OGLFramebuffer draw_framebuffer;
|
2018-01-16 03:06:35 +01:00
|
|
|
|
|
|
|
OGLVertexArray attributeless_vao;
|
|
|
|
OGLBuffer d24s8_abgr_buffer;
|
|
|
|
GLsizeiptr d24s8_abgr_buffer_size;
|
2018-04-09 23:26:09 +02:00
|
|
|
OGLProgram d24s8_abgr_shader;
|
2018-01-16 03:06:35 +01:00
|
|
|
GLint d24s8_abgr_tbo_size_u_id;
|
|
|
|
GLint d24s8_abgr_viewport_u_id;
|
2018-04-29 11:51:02 +02:00
|
|
|
|
|
|
|
std::unordered_map<TextureCubeConfig, CachedTextureCube> texture_cube_cache;
|
2015-05-19 06:21:33 +02:00
|
|
|
};
|