2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-10-19 22:24:27 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2010-10-19 22:24:27 +00:00
|
|
|
|
2017-03-25 18:45:55 +00:00
|
|
|
#include <array>
|
2017-06-29 21:09:32 +00:00
|
|
|
#include <bitset>
|
2021-12-09 22:00:08 +00:00
|
|
|
#include <fmt/format.h>
|
2010-10-19 22:24:27 +00:00
|
|
|
#include <map>
|
2015-12-21 02:49:49 +00:00
|
|
|
#include <memory>
|
2017-09-29 05:32:04 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
2022-05-26 05:59:24 +00:00
|
|
|
#include <string_view>
|
2016-01-24 03:43:01 +00:00
|
|
|
#include <tuple>
|
2015-01-17 09:57:19 +00:00
|
|
|
#include <unordered_map>
|
2016-06-16 09:51:39 +00:00
|
|
|
#include <unordered_set>
|
2018-11-02 14:17:00 +00:00
|
|
|
#include <vector>
|
2010-10-19 22:24:27 +00:00
|
|
|
|
2019-09-06 09:22:47 +00:00
|
|
|
#include "Common/BitSet.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2023-01-30 11:46:10 +00:00
|
|
|
#include "Common/Flag.h"
|
2019-07-17 00:18:48 +00:00
|
|
|
#include "Common/MathUtil.h"
|
2023-01-30 11:46:10 +00:00
|
|
|
|
2017-04-23 04:44:34 +00:00
|
|
|
#include "VideoCommon/AbstractTexture.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/BPMemory.h"
|
2017-04-23 04:44:34 +00:00
|
|
|
#include "VideoCommon/TextureConfig.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/TextureDecoder.h"
|
2021-05-01 05:59:24 +00:00
|
|
|
#include "VideoCommon/TextureInfo.h"
|
2023-01-30 11:46:10 +00:00
|
|
|
#include "VideoCommon/VideoEvents.h"
|
2010-10-19 22:24:27 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
class AbstractFramebuffer;
|
2018-11-02 14:17:00 +00:00
|
|
|
class AbstractStagingTexture;
|
2019-06-29 09:27:53 +00:00
|
|
|
class PointerWrap;
|
2019-07-17 00:18:48 +00:00
|
|
|
struct VideoConfig;
|
2012-05-28 09:31:37 +00:00
|
|
|
|
2022-05-26 05:59:24 +00:00
|
|
|
constexpr std::string_view EFB_DUMP_PREFIX = "efb1";
|
|
|
|
constexpr std::string_view XFB_DUMP_PREFIX = "xfb1";
|
|
|
|
|
2022-07-23 22:46:05 +00:00
|
|
|
static constexpr int FRAMECOUNT_INVALID = 0;
|
|
|
|
|
2017-07-30 19:45:55 +00:00
|
|
|
struct TextureAndTLUTFormat
|
|
|
|
{
|
|
|
|
TextureAndTLUTFormat(TextureFormat texfmt_ = TextureFormat::I4,
|
|
|
|
TLUTFormat tlutfmt_ = TLUTFormat::IA8)
|
|
|
|
: texfmt(texfmt_), tlutfmt(tlutfmt_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const TextureAndTLUTFormat& other) const
|
|
|
|
{
|
|
|
|
if (IsColorIndexed(texfmt))
|
|
|
|
return texfmt == other.texfmt && tlutfmt == other.tlutfmt;
|
|
|
|
|
|
|
|
return texfmt == other.texfmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const TextureAndTLUTFormat& other) const { return !operator==(other); }
|
|
|
|
TextureFormat texfmt;
|
|
|
|
TLUTFormat tlutfmt;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EFBCopyParams
|
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
EFBCopyParams(PixelFormat efb_format_, EFBCopyFormat copy_format_, bool depth_, bool yuv_,
|
2022-02-07 21:37:28 +00:00
|
|
|
bool all_copy_filter_coefs_needed_, bool copy_filter_can_overflow_,
|
|
|
|
bool apply_gamma_)
|
2018-05-03 04:09:32 +00:00
|
|
|
: efb_format(efb_format_), copy_format(copy_format_), depth(depth_), yuv(yuv_),
|
2022-02-07 21:37:28 +00:00
|
|
|
all_copy_filter_coefs_needed(all_copy_filter_coefs_needed_),
|
|
|
|
copy_filter_can_overflow(copy_filter_can_overflow_), apply_gamma(apply_gamma_)
|
2017-07-30 19:45:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const EFBCopyParams& rhs) const
|
|
|
|
{
|
2022-02-07 21:37:28 +00:00
|
|
|
return std::tie(efb_format, copy_format, depth, yuv, all_copy_filter_coefs_needed,
|
|
|
|
copy_filter_can_overflow,
|
|
|
|
apply_gamma) < std::tie(rhs.efb_format, rhs.copy_format, rhs.depth, rhs.yuv,
|
|
|
|
rhs.all_copy_filter_coefs_needed,
|
|
|
|
rhs.copy_filter_can_overflow, rhs.apply_gamma);
|
2017-07-30 19:45:55 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 02:11:31 +00:00
|
|
|
PixelFormat efb_format;
|
2017-07-30 19:45:55 +00:00
|
|
|
EFBCopyFormat copy_format;
|
|
|
|
bool depth;
|
|
|
|
bool yuv;
|
2022-02-07 21:37:28 +00:00
|
|
|
bool all_copy_filter_coefs_needed;
|
|
|
|
bool copy_filter_can_overflow;
|
|
|
|
bool apply_gamma;
|
2017-07-30 19:45:55 +00:00
|
|
|
};
|
|
|
|
|
2021-12-09 22:00:08 +00:00
|
|
|
template <>
|
|
|
|
struct fmt::formatter<EFBCopyParams>
|
|
|
|
{
|
2022-07-25 05:20:33 +00:00
|
|
|
std::shared_ptr<int> state;
|
2021-12-09 22:00:08 +00:00
|
|
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
|
|
|
template <typename FormatContext>
|
2022-01-13 01:16:29 +00:00
|
|
|
auto format(const EFBCopyParams& uid, FormatContext& ctx) const
|
2021-12-09 22:00:08 +00:00
|
|
|
{
|
|
|
|
std::string copy_format;
|
|
|
|
if (uid.copy_format == EFBCopyFormat::XFB)
|
|
|
|
copy_format = "XFB";
|
|
|
|
else
|
|
|
|
copy_format = fmt::to_string(uid.copy_format);
|
2022-01-13 06:52:21 +00:00
|
|
|
return fmt::format_to(ctx.out(),
|
2022-02-07 21:37:28 +00:00
|
|
|
"format: {}, copy format: {}, depth: {}, yuv: {}, apply_gamma: {}, "
|
|
|
|
"all_copy_filter_coefs_needed: {}, copy_filter_can_overflow: {}",
|
|
|
|
uid.efb_format, copy_format, uid.depth, uid.yuv, uid.apply_gamma,
|
|
|
|
uid.all_copy_filter_coefs_needed, uid.copy_filter_can_overflow);
|
2021-12-09 22:00:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-23 22:46:05 +00:00
|
|
|
struct TCacheEntry
|
2010-10-19 22:24:27 +00:00
|
|
|
{
|
2022-07-23 22:46:05 +00:00
|
|
|
// common members
|
|
|
|
std::unique_ptr<AbstractTexture> texture;
|
|
|
|
std::unique_ptr<AbstractFramebuffer> framebuffer;
|
|
|
|
u32 addr = 0;
|
|
|
|
u32 size_in_bytes = 0;
|
|
|
|
u64 base_hash = 0;
|
|
|
|
u64 hash = 0; // for paletted textures, hash = base_hash ^ palette_hash
|
|
|
|
TextureAndTLUTFormat format;
|
|
|
|
u32 memory_stride = 0;
|
|
|
|
bool is_efb_copy = false;
|
|
|
|
bool is_custom_tex = false;
|
|
|
|
bool may_have_overlapping_textures = true;
|
2022-07-25 05:20:33 +00:00
|
|
|
bool has_arbitrary_mips = false; // indicates that the mips in this texture are arbitrary
|
|
|
|
// content, aren't just downscaled
|
2022-07-23 22:46:05 +00:00
|
|
|
bool should_force_safe_hashing = false; // for XFB
|
|
|
|
bool is_xfb_copy = false;
|
|
|
|
bool is_xfb_container = false;
|
|
|
|
u64 id = 0;
|
2022-07-27 07:35:51 +00:00
|
|
|
u32 content_semaphore = 0; // Counts up
|
2022-07-23 22:46:05 +00:00
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
// Indicates that this TCacheEntry has been invalided from textures_by_address
|
|
|
|
bool invalidated = false;
|
|
|
|
|
2022-07-23 22:46:05 +00:00
|
|
|
bool reference_changed = false; // used by xfb to determine when a reference xfb changed
|
|
|
|
|
|
|
|
// Texture dimensions from the GameCube's point of view
|
|
|
|
u32 native_width = 0;
|
|
|
|
u32 native_height = 0;
|
|
|
|
u32 native_levels = 0;
|
|
|
|
|
|
|
|
// used to delete textures which haven't been used for TEXTURE_KILL_THRESHOLD frames
|
|
|
|
int frameCount = FRAMECOUNT_INVALID;
|
|
|
|
|
|
|
|
// Keep an iterator to the entry in textures_by_hash, so it does not need to be searched when
|
|
|
|
// removing the cache entry
|
2022-07-27 07:35:51 +00:00
|
|
|
std::multimap<u64, std::shared_ptr<TCacheEntry>>::iterator textures_by_hash_iter;
|
2022-07-23 22:46:05 +00:00
|
|
|
|
|
|
|
// This is used to keep track of both:
|
|
|
|
// * efb copies used by this partially updated texture
|
|
|
|
// * partially updated textures which refer to this efb copy
|
|
|
|
std::unordered_set<TCacheEntry*> references;
|
|
|
|
|
|
|
|
// Pending EFB copy
|
|
|
|
std::unique_ptr<AbstractStagingTexture> pending_efb_copy;
|
|
|
|
u32 pending_efb_copy_width = 0;
|
|
|
|
u32 pending_efb_copy_height = 0;
|
|
|
|
|
|
|
|
std::string texture_info_name = "";
|
|
|
|
|
|
|
|
explicit TCacheEntry(std::unique_ptr<AbstractTexture> tex,
|
2022-07-25 05:20:33 +00:00
|
|
|
std::unique_ptr<AbstractFramebuffer> fb);
|
2022-07-23 22:46:05 +00:00
|
|
|
|
|
|
|
~TCacheEntry();
|
|
|
|
|
|
|
|
void SetGeneralParameters(u32 _addr, u32 _size, TextureAndTLUTFormat _format,
|
|
|
|
bool force_safe_hashing)
|
|
|
|
{
|
|
|
|
addr = _addr;
|
|
|
|
size_in_bytes = _size;
|
|
|
|
format = _format;
|
|
|
|
should_force_safe_hashing = force_safe_hashing;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-07-23 22:46:05 +00:00
|
|
|
void SetDimensions(unsigned int _native_width, unsigned int _native_height,
|
2022-07-25 05:20:33 +00:00
|
|
|
unsigned int _native_levels)
|
2010-10-19 22:24:27 +00:00
|
|
|
{
|
2022-07-23 22:46:05 +00:00
|
|
|
native_width = _native_width;
|
|
|
|
native_height = _native_height;
|
|
|
|
native_levels = _native_levels;
|
|
|
|
memory_stride = _native_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetHashes(u64 _base_hash, u64 _hash)
|
|
|
|
{
|
|
|
|
base_hash = _base_hash;
|
|
|
|
hash = _hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This texture entry is used by the other entry as a sub-texture
|
|
|
|
void CreateReference(TCacheEntry* other_entry)
|
|
|
|
{
|
|
|
|
// References are two-way, so they can easily be destroyed later
|
|
|
|
this->references.emplace(other_entry);
|
|
|
|
other_entry->references.emplace(this);
|
|
|
|
}
|
|
|
|
|
2022-07-27 07:35:51 +00:00
|
|
|
// Acquiring a content lock will lock the current contents and prevent texture cache from
|
|
|
|
// reusing the same entry for a newer version of the texture.
|
|
|
|
void AcquireContentLock() { content_semaphore++; }
|
|
|
|
void ReleaseContentLock() { content_semaphore--; }
|
|
|
|
|
|
|
|
// Can this be mutated?
|
|
|
|
bool IsLocked() const { return content_semaphore > 0; }
|
|
|
|
|
2022-07-23 22:46:05 +00:00
|
|
|
void SetXfbCopy(u32 stride);
|
|
|
|
void SetEfbCopy(u32 stride);
|
|
|
|
void SetNotCopy();
|
|
|
|
|
|
|
|
bool OverlapsMemoryRange(u32 range_address, u32 range_size) const;
|
|
|
|
|
|
|
|
bool IsEfbCopy() const { return is_efb_copy; }
|
|
|
|
bool IsCopy() const { return is_xfb_copy || is_efb_copy; }
|
|
|
|
u32 NumBlocksX() const;
|
|
|
|
u32 NumBlocksY() const;
|
|
|
|
u32 BytesPerRow() const;
|
|
|
|
|
|
|
|
u64 CalculateHash() const;
|
2019-06-29 09:27:53 +00:00
|
|
|
|
2022-07-23 22:46:05 +00:00
|
|
|
int HashSampleSize() const;
|
|
|
|
u32 GetWidth() const { return texture->GetConfig().width; }
|
|
|
|
u32 GetHeight() const { return texture->GetConfig().height; }
|
|
|
|
u32 GetNumLevels() const { return texture->GetConfig().levels; }
|
|
|
|
u32 GetNumLayers() const { return texture->GetConfig().layers; }
|
|
|
|
AbstractTextureFormat GetFormat() const { return texture->GetConfig().format; }
|
|
|
|
void DoState(PointerWrap& p);
|
|
|
|
};
|
|
|
|
|
2022-07-27 07:35:51 +00:00
|
|
|
using RcTcacheEntry = std::shared_ptr<TCacheEntry>;
|
2022-07-25 05:20:33 +00:00
|
|
|
|
2022-07-23 22:46:05 +00:00
|
|
|
class TextureCacheBase
|
|
|
|
{
|
|
|
|
public:
|
2019-06-29 09:27:53 +00:00
|
|
|
// Minimal version of TCacheEntry just for TexPool
|
|
|
|
struct TexPoolEntry
|
|
|
|
{
|
|
|
|
std::unique_ptr<AbstractTexture> texture;
|
|
|
|
std::unique_ptr<AbstractFramebuffer> framebuffer;
|
|
|
|
int frameCount = FRAMECOUNT_INVALID;
|
|
|
|
|
|
|
|
TexPoolEntry(std::unique_ptr<AbstractTexture> tex, std::unique_ptr<AbstractFramebuffer> fb);
|
2012-08-10 11:13:51 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
TextureCacheBase();
|
|
|
|
virtual ~TextureCacheBase();
|
|
|
|
|
|
|
|
bool Initialize();
|
2022-07-25 05:20:33 +00:00
|
|
|
void Shutdown();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-08-05 02:31:25 +00:00
|
|
|
void OnConfigChanged(const VideoConfig& config);
|
2019-08-17 19:40:58 +00:00
|
|
|
void ForceReload();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-05-16 19:57:14 +00:00
|
|
|
// Removes textures which aren't used for more than TEXTURE_KILL_THRESHOLD frames,
|
|
|
|
// frameCount is the current frame number.
|
2016-09-06 22:57:58 +00:00
|
|
|
void Cleanup(int _frameCount);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-09-06 22:57:58 +00:00
|
|
|
void Invalidate();
|
2022-07-25 05:20:33 +00:00
|
|
|
void ReleaseToPool(TCacheEntry* entry);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-03-05 20:52:43 +00:00
|
|
|
TCacheEntry* Load(const TextureInfo& texture_info);
|
2022-07-25 05:20:33 +00:00
|
|
|
RcTcacheEntry GetTexture(const int textureCacheSafetyColorSampleSize,
|
|
|
|
const TextureInfo& texture_info);
|
|
|
|
RcTcacheEntry GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
|
|
|
|
MathUtil::Rectangle<int>* display_rect);
|
2017-09-29 05:32:04 +00:00
|
|
|
|
2019-09-06 09:22:47 +00:00
|
|
|
virtual void BindTextures(BitSet32 used_textures);
|
2017-12-23 11:44:01 +00:00
|
|
|
void CopyRenderTargetToTexture(u32 dstAddr, EFBCopyFormat dstFormat, u32 width, u32 height,
|
2019-04-15 14:47:46 +00:00
|
|
|
u32 dstStride, bool is_depth_copy,
|
|
|
|
const MathUtil::Rectangle<int>& srcRect, bool isIntensity,
|
|
|
|
bool scaleByHalf, float y_scale, float gamma, bool clamp_top,
|
|
|
|
bool clamp_bottom,
|
2018-04-29 08:52:30 +00:00
|
|
|
const CopyFilterCoefficients::Values& filter_coefficients);
|
2010-10-19 22:24:27 +00:00
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
void ScaleTextureCacheEntryTo(RcTcacheEntry& entry, u32 new_width, u32 new_height);
|
2017-07-03 02:24:20 +00:00
|
|
|
|
2018-11-02 14:17:00 +00:00
|
|
|
// Flushes all pending EFB copies to emulated RAM.
|
|
|
|
void FlushEFBCopies();
|
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
// Flush any Bound textures that can't be reused
|
|
|
|
void FlushStaleBinds();
|
|
|
|
|
2019-06-29 09:27:53 +00:00
|
|
|
// Texture Serialization
|
|
|
|
void SerializeTexture(AbstractTexture* tex, const TextureConfig& config, PointerWrap& p);
|
|
|
|
std::optional<TexPoolEntry> DeserializeTexture(PointerWrap& p);
|
|
|
|
|
|
|
|
// Save States
|
|
|
|
void DoState(PointerWrap& p);
|
|
|
|
|
2022-02-07 21:37:28 +00:00
|
|
|
static bool AllCopyFilterCoefsNeeded(const std::array<u32, 3>& coefficients);
|
|
|
|
static bool CopyFilterCanOverflow(const std::array<u32, 3>& coefficients);
|
2018-11-02 14:17:00 +00:00
|
|
|
|
2023-01-30 11:46:10 +00:00
|
|
|
// Will forcibly reload all textures when the frame next ends
|
|
|
|
void ForceReloadTextures() { m_force_reload_textures.Set(); }
|
|
|
|
|
2010-10-19 22:24:27 +00:00
|
|
|
protected:
|
2019-02-15 01:59:50 +00:00
|
|
|
// Decodes the specified data to the GPU texture specified by entry.
|
|
|
|
// Returns false if the configuration is not supported.
|
|
|
|
// width, height are the size of the image in pixels.
|
|
|
|
// aligned_width, aligned_height are the size of the image in pixels, aligned to the block size.
|
|
|
|
// row_stride is the number of bytes for a row of blocks, not pixels.
|
2022-07-25 05:20:33 +00:00
|
|
|
bool DecodeTextureOnGPU(RcTcacheEntry& entry, u32 dst_level, const u8* data, u32 data_size,
|
2019-02-15 01:59:50 +00:00
|
|
|
TextureFormat format, u32 width, u32 height, u32 aligned_width,
|
|
|
|
u32 aligned_height, u32 row_stride, const u8* palette,
|
|
|
|
TLUTFormat palette_format);
|
|
|
|
|
|
|
|
virtual void CopyEFB(AbstractStagingTexture* dst, const EFBCopyParams& params, u32 native_width,
|
|
|
|
u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
|
2019-04-15 14:47:46 +00:00
|
|
|
const MathUtil::Rectangle<int>& src_rect, bool scale_by_half,
|
|
|
|
bool linear_filter, float y_scale, float gamma, bool clamp_top,
|
2022-02-07 21:37:28 +00:00
|
|
|
bool clamp_bottom, const std::array<u32, 3>& filter_coefficients);
|
2022-07-25 05:20:33 +00:00
|
|
|
virtual void CopyEFBToCacheEntry(RcTcacheEntry& entry, bool is_depth_copy,
|
2019-04-15 14:47:46 +00:00
|
|
|
const MathUtil::Rectangle<int>& src_rect, bool scale_by_half,
|
2019-03-31 04:42:38 +00:00
|
|
|
bool linear_filter, EFBCopyFormat dst_format, bool is_intensity,
|
|
|
|
float gamma, bool clamp_top, bool clamp_bottom,
|
2022-02-07 21:37:28 +00:00
|
|
|
const std::array<u32, 3>& filter_coefficients);
|
2018-05-03 04:09:32 +00:00
|
|
|
|
2016-09-06 22:57:58 +00:00
|
|
|
alignas(16) u8* temp = nullptr;
|
|
|
|
size_t temp_size = 0;
|
2010-10-19 22:24:27 +00:00
|
|
|
|
|
|
|
private:
|
2022-07-25 05:20:33 +00:00
|
|
|
using TexAddrCache = std::multimap<u32, RcTcacheEntry>;
|
|
|
|
using TexHashCache = std::multimap<u64, RcTcacheEntry>;
|
|
|
|
|
2017-10-09 00:15:34 +00:00
|
|
|
using TexPool = std::unordered_multimap<TextureConfig, TexPoolEntry>;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
bool CreateUtilityTextures();
|
|
|
|
|
2016-09-06 22:57:58 +00:00
|
|
|
void SetBackupConfig(const VideoConfig& config);
|
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
RcTcacheEntry GetXFBFromCache(u32 address, u32 width, u32 height, u32 stride);
|
2019-03-31 04:11:53 +00:00
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
RcTcacheEntry ApplyPaletteToEntry(RcTcacheEntry& entry, const u8* palette, TLUTFormat tlutfmt);
|
2016-09-06 22:57:58 +00:00
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
RcTcacheEntry ReinterpretEntry(const RcTcacheEntry& existing_entry, TextureFormat new_format);
|
2019-07-14 05:24:12 +00:00
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
RcTcacheEntry DoPartialTextureUpdates(RcTcacheEntry& entry_to_update, const u8* palette,
|
|
|
|
TLUTFormat tlutfmt);
|
|
|
|
void StitchXFBCopy(RcTcacheEntry& entry_to_update);
|
2016-09-06 22:57:58 +00:00
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
void DumpTexture(RcTcacheEntry& entry, std::string basename, unsigned int level,
|
|
|
|
bool is_arbitrary);
|
2016-09-06 22:57:58 +00:00
|
|
|
void CheckTempSize(size_t required_size);
|
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
RcTcacheEntry AllocateCacheEntry(const TextureConfig& config);
|
2019-02-15 01:59:50 +00:00
|
|
|
std::optional<TexPoolEntry> AllocateTexture(const TextureConfig& config);
|
2017-04-23 04:44:34 +00:00
|
|
|
TexPool::iterator FindMatchingTextureFromPool(const TextureConfig& config);
|
|
|
|
TexAddrCache::iterator GetTexCacheIter(TCacheEntry* entry);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-12-26 17:41:34 +00:00
|
|
|
// Return all possible overlapping textures. As addr+size of the textures is not
|
|
|
|
// indexed, this may return false positives.
|
|
|
|
std::pair<TexAddrCache::iterator, TexAddrCache::iterator>
|
|
|
|
FindOverlappingTextures(u32 addr, u32 size_in_bytes);
|
|
|
|
|
2016-06-17 15:28:57 +00:00
|
|
|
// Removes and unlinks texture from texture cache and returns it to the pool
|
2018-11-02 14:17:00 +00:00
|
|
|
TexAddrCache::iterator InvalidateTexture(TexAddrCache::iterator t_iter,
|
|
|
|
bool discard_pending_efb_copy = false);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-06-25 05:42:17 +00:00
|
|
|
void UninitializeEFBMemory(u8* dst, u32 stride, u32 bytes_per_row, u32 num_blocks_y);
|
2017-11-04 17:04:26 +00:00
|
|
|
void UninitializeXFBMemory(u8* dst, u32 stride, u32 bytes_per_row, u32 num_blocks_y);
|
|
|
|
|
2018-04-29 08:52:30 +00:00
|
|
|
// Precomputing the coefficients for the previous, current, and next lines for the copy filter.
|
2022-02-07 21:37:28 +00:00
|
|
|
static std::array<u32, 3>
|
2019-02-15 01:59:50 +00:00
|
|
|
GetRAMCopyFilterCoefficients(const CopyFilterCoefficients::Values& coefficients);
|
2022-02-07 21:37:28 +00:00
|
|
|
static std::array<u32, 3>
|
2019-02-15 01:59:50 +00:00
|
|
|
GetVRAMCopyFilterCoefficients(const CopyFilterCoefficients::Values& coefficients);
|
2018-04-29 08:52:30 +00:00
|
|
|
|
2018-11-02 14:17:00 +00:00
|
|
|
// Flushes a pending EFB copy to RAM from the host to the guest RAM.
|
|
|
|
void WriteEFBCopyToRAM(u8* dst_ptr, u32 width, u32 height, u32 stride,
|
|
|
|
std::unique_ptr<AbstractStagingTexture> staging_texture);
|
|
|
|
void FlushEFBCopy(TCacheEntry* entry);
|
|
|
|
|
|
|
|
// Returns a staging texture of the maximum EFB copy size.
|
|
|
|
std::unique_ptr<AbstractStagingTexture> GetEFBCopyStagingTexture();
|
|
|
|
|
|
|
|
// Returns an EFB copy staging texture to the pool, so it can be re-used.
|
|
|
|
void ReleaseEFBCopyStagingTexture(std::unique_ptr<AbstractStagingTexture> tex);
|
|
|
|
|
2019-06-29 09:27:53 +00:00
|
|
|
bool CheckReadbackTexture(u32 width, u32 height, AbstractTextureFormat format);
|
|
|
|
void DoSaveState(PointerWrap& p);
|
|
|
|
void DoLoadState(PointerWrap& p);
|
|
|
|
|
2022-07-25 05:20:33 +00:00
|
|
|
// textures_by_address is the authoritive version of what's actually "in" the texture cache
|
|
|
|
// but it's possible for invalidated TCache entries to live on elsewhere
|
2016-12-25 17:48:19 +00:00
|
|
|
TexAddrCache textures_by_address;
|
2022-07-25 05:20:33 +00:00
|
|
|
|
|
|
|
// textures_by_hash is an alternative view of the texture cache
|
|
|
|
// All textures in here will also be in textures_by_address
|
2016-12-25 17:48:19 +00:00
|
|
|
TexHashCache textures_by_hash;
|
2022-07-25 05:20:33 +00:00
|
|
|
|
|
|
|
// bound_textures are actually active in the current draw
|
|
|
|
// It's valid for textures to be in here after they've been invalidated
|
|
|
|
std::array<RcTcacheEntry, 8> bound_textures{};
|
|
|
|
|
2016-09-06 22:57:58 +00:00
|
|
|
TexPool texture_pool;
|
2017-08-20 19:24:37 +00:00
|
|
|
u64 last_entry_id = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2012-05-28 09:31:37 +00:00
|
|
|
// Backup configuration values
|
2016-09-06 22:57:58 +00:00
|
|
|
struct BackupConfig
|
2012-05-28 09:31:37 +00:00
|
|
|
{
|
2016-09-06 22:57:58 +00:00
|
|
|
int color_samples;
|
|
|
|
bool texfmt_overlay;
|
|
|
|
bool texfmt_overlay_center;
|
|
|
|
bool hires_textures;
|
|
|
|
bool cache_hires_textures;
|
|
|
|
bool copy_cache_enable;
|
|
|
|
bool stereo_3d;
|
|
|
|
bool efb_mono_depth;
|
2016-11-27 08:14:59 +00:00
|
|
|
bool gpu_texture_decoding;
|
2018-05-03 04:24:44 +00:00
|
|
|
bool disable_vram_copies;
|
2018-07-03 10:19:07 +00:00
|
|
|
bool arbitrary_mipmap_detection;
|
2022-03-05 20:52:43 +00:00
|
|
|
bool graphics_mods;
|
2022-03-15 06:46:58 +00:00
|
|
|
u32 graphics_mod_change_count;
|
2016-09-06 22:57:58 +00:00
|
|
|
};
|
|
|
|
BackupConfig backup_config = {};
|
2018-11-02 14:17:00 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
// Encoding texture used for EFB copies to RAM.
|
|
|
|
std::unique_ptr<AbstractTexture> m_efb_encoding_texture;
|
|
|
|
std::unique_ptr<AbstractFramebuffer> m_efb_encoding_framebuffer;
|
|
|
|
|
|
|
|
// Decoding texture used for GPU texture decoding.
|
|
|
|
std::unique_ptr<AbstractTexture> m_decoding_texture;
|
|
|
|
|
2018-11-02 14:17:00 +00:00
|
|
|
// Pool of readback textures used for deferred EFB copies.
|
|
|
|
std::vector<std::unique_ptr<AbstractStagingTexture>> m_efb_copy_staging_texture_pool;
|
|
|
|
|
|
|
|
// List of pending EFB copies. It is important that the order is preserved for these,
|
|
|
|
// so that overlapping textures are written to guest RAM in the order they are issued.
|
2022-07-25 05:20:33 +00:00
|
|
|
// It's valid for textures to live be in here after they've been invalidated
|
|
|
|
std::vector<RcTcacheEntry> m_pending_efb_copies;
|
2019-06-29 09:27:53 +00:00
|
|
|
|
|
|
|
// Staging texture used for readbacks.
|
|
|
|
// We store this in the class so that the same staging texture can be used for multiple
|
|
|
|
// readbacks, saving the overhead of allocating a new buffer every time.
|
|
|
|
std::unique_ptr<AbstractStagingTexture> m_readback_texture;
|
2023-01-30 11:46:10 +00:00
|
|
|
|
|
|
|
void OnFrameEnd();
|
|
|
|
|
|
|
|
Common::Flag m_force_reload_textures;
|
|
|
|
EventHook m_frame_event = AfterFrameEvent::Register([this] { OnFrameEnd(); }, "TextureCache");
|
2010-10-19 22:24:27 +00:00
|
|
|
};
|
|
|
|
|
2015-12-21 02:49:49 +00:00
|
|
|
extern std::unique_ptr<TextureCacheBase> g_texture_cache;
|