From 4364569cf4efa5e0aa8ce921fbc4362397355f8d Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 19 Feb 2017 18:53:30 +0100 Subject: [PATCH] Move TexCacheEntry outside the TextureCacheCommon class. Nested structs are annoying. --- GPU/Common/TextureCacheCommon.cpp | 4 +- GPU/Common/TextureCacheCommon.h | 179 +++++++++++++++--------------- GPU/D3D11/TextureCacheD3D11.cpp | 2 +- GPU/Directx9/TextureCacheDX9.cpp | 2 +- GPU/GLES/TextureCacheGLES.cpp | 2 +- GPU/Vulkan/TextureCacheVulkan.cpp | 2 +- 6 files changed, 96 insertions(+), 95 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 9c0bc78a32..0cb2b21a38 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -239,7 +239,7 @@ void TextureCacheCommon::AttachFramebufferValid(TexCacheEntry *entry, VirtualFra } entry->framebuffer = framebuffer; entry->invalidHint = 0; - entry->status &= ~TextureCacheCommon::TexCacheEntry::STATUS_DEPALETTIZE; + entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; entry->maxLevel = 0; fbTexInfo_[cachekey] = fbInfo; framebuffer->last_frame_attached = gpuStats.numFlips; @@ -258,7 +258,7 @@ void TextureCacheCommon::AttachFramebufferInvalid(TexCacheEntry *entry, VirtualF } entry->framebuffer = framebuffer; entry->invalidHint = -1; - entry->status &= ~TextureCacheCommon::TexCacheEntry::STATUS_DEPALETTIZE; + entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; entry->maxLevel = 0; fbTexInfo_[cachekey] = fbInfo; host->GPUNotifyTextureAttachment(entry->addr); diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index e9987e9b18..09bf70eef4 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -76,6 +76,93 @@ struct SamplerCacheKey { } }; + +// Wow this is starting to grow big. Soon need to start looking at resizing it. +// Must stay a POD. +struct TexCacheEntry { + // After marking STATUS_UNRELIABLE, if it stays the same this many frames we'll trust it again. + const static int FRAMES_REGAIN_TRUST = 1000; + + enum Status { + STATUS_HASHING = 0x00, + STATUS_RELIABLE = 0x01, // Don't bother rehashing. + STATUS_UNRELIABLE = 0x02, // Always recheck hash. + STATUS_MASK = 0x03, + + STATUS_ALPHA_UNKNOWN = 0x04, + STATUS_ALPHA_FULL = 0x00, // Has no alpha channel, or always full alpha. + STATUS_ALPHA_SIMPLE = 0x08, // Like above, but also has 0 alpha (e.g. 5551.) + STATUS_ALPHA_MASK = 0x0c, + + STATUS_CHANGE_FREQUENT = 0x10, // Changes often (less than 6 frames in between.) + STATUS_CLUT_RECHECK = 0x20, // Another texture with same addr had a hashfail. + STATUS_DEPALETTIZE = 0x40, // Needs to go through a depalettize pass. + STATUS_TO_SCALE = 0x80, // Pending texture scaling in a later frame. + STATUS_IS_SCALED = 0x100, // Has been scaled (can't be replaceImages'd.) + STATUS_FREE_CHANGE = 0x200, // Allow one change before marking "frequent". + }; + + // Status, but int so we can zero initialize. + int status; + u32 addr; + u32 hash; + VirtualFramebuffer *framebuffer; // if null, not sourced from an FBO. + u32 sizeInRAM; + int lastFrame; + int numFrames; + int numInvalidated; + u32 framesUntilNextFullHash; + u8 format; + u8 maxLevel; + u16 dim; + u16 bufw; + union { + u32 textureName; + void *texturePtr; + CachedTextureVulkan *vkTex; + }; +#ifdef _WIN32 + void *textureView; // Used by D3D11 only for the shader resource view. +#endif + int invalidHint; + u32 fullhash; + u32 cluthash; + float lodBias; + u16 maxSeenV; + + // Cache the current filter settings so we can avoid setting it again. + // (OpenGL madness where filter settings are attached to each texture. Unused in Vulkan). + u8 magFilt; + u8 minFilt; + bool sClamp; + bool tClamp; + + Status GetHashStatus() { + return Status(status & STATUS_MASK); + } + void SetHashStatus(Status newStatus) { + status = (status & ~STATUS_MASK) | newStatus; + } + Status GetAlphaStatus() { + return Status(status & STATUS_ALPHA_MASK); + } + void SetAlphaStatus(Status newStatus) { + status = (status & ~STATUS_ALPHA_MASK) | newStatus; + } + void SetAlphaStatus(Status newStatus, int level) { + // For non-level zero, only set more restrictive. + if (newStatus == STATUS_ALPHA_UNKNOWN || level == 0) { + SetAlphaStatus(newStatus); + } else if (newStatus == STATUS_ALPHA_SIMPLE && GetAlphaStatus() == STATUS_ALPHA_FULL) { + SetAlphaStatus(STATUS_ALPHA_SIMPLE); + } + } + + bool Matches(u16 dim2, u8 format2, u8 maxLevel2) const; + u64 CacheKey() const; + static u64 CacheKey(u32 addr, u8 format, u16 dim, u32 cluthash); +}; + class FramebufferManagerCommon; class TextureCacheCommon { @@ -107,92 +194,6 @@ public: return PSP_CoreParameter().compat.flags().FakeMipmapChange && gstate.getTexLevelMode() == GE_TEXLEVEL_MODE_CONST; } - // Wow this is starting to grow big. Soon need to start looking at resizing it. - // Must stay a POD. - struct TexCacheEntry { - // After marking STATUS_UNRELIABLE, if it stays the same this many frames we'll trust it again. - const static int FRAMES_REGAIN_TRUST = 1000; - - enum Status { - STATUS_HASHING = 0x00, - STATUS_RELIABLE = 0x01, // Don't bother rehashing. - STATUS_UNRELIABLE = 0x02, // Always recheck hash. - STATUS_MASK = 0x03, - - STATUS_ALPHA_UNKNOWN = 0x04, - STATUS_ALPHA_FULL = 0x00, // Has no alpha channel, or always full alpha. - STATUS_ALPHA_SIMPLE = 0x08, // Like above, but also has 0 alpha (e.g. 5551.) - STATUS_ALPHA_MASK = 0x0c, - - STATUS_CHANGE_FREQUENT = 0x10, // Changes often (less than 6 frames in between.) - STATUS_CLUT_RECHECK = 0x20, // Another texture with same addr had a hashfail. - STATUS_DEPALETTIZE = 0x40, // Needs to go through a depalettize pass. - STATUS_TO_SCALE = 0x80, // Pending texture scaling in a later frame. - STATUS_IS_SCALED = 0x100, // Has been scaled (can't be replaceImages'd.) - STATUS_FREE_CHANGE = 0x200, // Allow one change before marking "frequent". - }; - - // Status, but int so we can zero initialize. - int status; - u32 addr; - u32 hash; - VirtualFramebuffer *framebuffer; // if null, not sourced from an FBO. - u32 sizeInRAM; - int lastFrame; - int numFrames; - int numInvalidated; - u32 framesUntilNextFullHash; - u8 format; - u8 maxLevel; - u16 dim; - u16 bufw; - union { - u32 textureName; - void *texturePtr; - CachedTextureVulkan *vkTex; - }; -#ifdef _WIN32 - void *textureView; // Used by D3D11 only for the shader resource view. -#endif - int invalidHint; - u32 fullhash; - u32 cluthash; - float lodBias; - u16 maxSeenV; - - // Cache the current filter settings so we can avoid setting it again. - // (OpenGL madness where filter settings are attached to each texture. Unused in Vulkan). - u8 magFilt; - u8 minFilt; - bool sClamp; - bool tClamp; - - Status GetHashStatus() { - return Status(status & STATUS_MASK); - } - void SetHashStatus(Status newStatus) { - status = (status & ~STATUS_MASK) | newStatus; - } - Status GetAlphaStatus() { - return Status(status & STATUS_ALPHA_MASK); - } - void SetAlphaStatus(Status newStatus) { - status = (status & ~STATUS_ALPHA_MASK) | newStatus; - } - void SetAlphaStatus(Status newStatus, int level) { - // For non-level zero, only set more restrictive. - if (newStatus == STATUS_ALPHA_UNKNOWN || level == 0) { - SetAlphaStatus(newStatus); - } else if (newStatus == STATUS_ALPHA_SIMPLE && GetAlphaStatus() == STATUS_ALPHA_FULL) { - SetAlphaStatus(STATUS_ALPHA_SIMPLE); - } - } - - bool Matches(u16 dim2, u8 format2, u8 maxLevel2) const; - u64 CacheKey() const; - static u64 CacheKey(u32 addr, u8 format, u16 dim, u32 cluthash); - }; - protected: virtual void Unbind() = 0; @@ -298,15 +299,15 @@ protected: bool nextNeedsRebuild_; }; -inline bool TextureCacheCommon::TexCacheEntry::Matches(u16 dim2, u8 format2, u8 maxLevel2) const { +inline bool TexCacheEntry::Matches(u16 dim2, u8 format2, u8 maxLevel2) const { return dim == dim2 && format == format2 && maxLevel == maxLevel2; } -inline u64 TextureCacheCommon::TexCacheEntry::CacheKey() const { +inline u64 TexCacheEntry::CacheKey() const { return CacheKey(addr, format, dim, cluthash); } -inline u64 TextureCacheCommon::TexCacheEntry::CacheKey(u32 addr, u8 format, u16 dim, u32 cluthash) { +inline u64 TexCacheEntry::CacheKey(u32 addr, u8 format, u16 dim, u32 cluthash) { u64 cachekey = ((u64)(addr & 0x3FFFFFFF) << 32) | dim; bool hasClut = (format & 4) != 0; if (hasClut) { diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 8c1531d582..8641c07aaf 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -1041,7 +1041,7 @@ DXGI_FORMAT TextureCacheD3D11::GetDestFormat(GETextureFormat format, GEPaletteFo } } -TextureCacheD3D11::TexCacheEntry::Status TextureCacheD3D11::CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h) { +TexCacheEntry::Status TextureCacheD3D11::CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h) { CheckAlphaResult res; switch (dstFmt) { case DXGI_FORMAT_B4G4R4A4_UNORM: diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index db6b5924de..5e1efd93eb 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -1058,7 +1058,7 @@ D3DFORMAT TextureCacheDX9::GetDestFormat(GETextureFormat format, GEPaletteFormat } } -TextureCacheDX9::TexCacheEntry::Status TextureCacheDX9::CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h) { +TexCacheEntry::Status TextureCacheDX9::CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h) { CheckAlphaResult res; switch (dstFmt) { case D3DFMT_A4R4G4B4: diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 58a4a1ea43..56bb45cf50 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -1173,7 +1173,7 @@ void *TextureCacheGLES::DecodeTextureLevelOld(GETextureFormat format, GEPaletteF return finalBuf; } -TextureCacheGLES::TexCacheEntry::Status TextureCacheGLES::CheckAlpha(const u32 *pixelData, GLenum dstFmt, int stride, int w, int h) { +TexCacheEntry::Status TextureCacheGLES::CheckAlpha(const u32 *pixelData, GLenum dstFmt, int stride, int w, int h) { CheckAlphaResult res; switch (dstFmt) { case GL_UNSIGNED_SHORT_4_4_4_4: diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 4eb9d162c0..30e6554b43 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -1149,7 +1149,7 @@ VkFormat TextureCacheVulkan::GetDestFormat(GETextureFormat format, GEPaletteForm } } -TextureCacheVulkan::TexCacheEntry::Status TextureCacheVulkan::CheckAlpha(const u32 *pixelData, VkFormat dstFmt, int stride, int w, int h) { +TexCacheEntry::Status TextureCacheVulkan::CheckAlpha(const u32 *pixelData, VkFormat dstFmt, int stride, int w, int h) { CheckAlphaResult res; switch (dstFmt) { case VULKAN_4444_FORMAT: