Move TCacheEntry out of TextureCacheBase

Allows for fowards declaration
This commit is contained in:
Scott Mansell
2022-07-24 10:46:05 +12:00
parent 2843cd10a8
commit c1fd4a2013
2 changed files with 134 additions and 135 deletions

View File

@ -33,6 +33,8 @@ struct VideoConfig;
constexpr std::string_view EFB_DUMP_PREFIX = "efb1";
constexpr std::string_view XFB_DUMP_PREFIX = "xfb1";
static constexpr int FRAMECOUNT_INVALID = 0;
struct TextureAndTLUTFormat
{
TextureAndTLUTFormat(TextureFormat texfmt_ = TextureFormat::I4,
@ -103,121 +105,118 @@ struct fmt::formatter<EFBCopyParams>
}
};
struct TCacheEntry
{
// 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;
bool tmem_only = false; // indicates that this texture only exists in the tmem cache
bool has_arbitrary_mips = false; // indicates that the mips in this texture are arbitrary
// content, aren't just downscaled
bool should_force_safe_hashing = false; // for XFB
bool is_xfb_copy = false;
bool is_xfb_container = false;
u64 id = 0;
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
std::multimap<u64, TCacheEntry*>::iterator textures_by_hash_iter;
// 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;
bool pending_efb_copy_invalidated = false;
std::string texture_info_name = "";
explicit TCacheEntry(std::unique_ptr<AbstractTexture> tex,
std::unique_ptr<AbstractFramebuffer> fb);
~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;
}
void SetDimensions(unsigned int _native_width, unsigned int _native_height,
unsigned int _native_levels)
{
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);
}
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;
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);
};
class TextureCacheBase
{
private:
static const int FRAMECOUNT_INVALID = 0;
public:
struct TCacheEntry
{
// 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;
bool tmem_only = false; // indicates that this texture only exists in the tmem cache
bool has_arbitrary_mips = false; // indicates that the mips in this texture are arbitrary
// content, aren't just downscaled
bool should_force_safe_hashing = false; // for XFB
bool is_xfb_copy = false;
bool is_xfb_container = false;
u64 id = 0;
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
std::multimap<u64, TCacheEntry*>::iterator textures_by_hash_iter;
// 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;
bool pending_efb_copy_invalidated = false;
std::string texture_info_name = "";
explicit TCacheEntry(std::unique_ptr<AbstractTexture> tex,
std::unique_ptr<AbstractFramebuffer> fb);
~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;
}
void SetDimensions(unsigned int _native_width, unsigned int _native_height,
unsigned int _native_levels)
{
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);
}
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;
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);
};
// Minimal version of TCacheEntry just for TexPool
struct TexPoolEntry
{