mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Unify "SetOffsetTexture"
This commit is contained in:
parent
346b9d0c51
commit
454f2cf4bf
8 changed files with 59 additions and 160 deletions
|
@ -419,6 +419,40 @@ void TextureCacheCommon::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFram
|
|||
nextNeedsRebuild_ = false;
|
||||
}
|
||||
|
||||
bool TextureCacheCommon::SetOffsetTexture(u32 offset) {
|
||||
if (g_Config.iRenderingMode != FB_BUFFERED_MODE) {
|
||||
return false;
|
||||
}
|
||||
u32 texaddr = gstate.getTextureAddress(0);
|
||||
if (!Memory::IsValidAddress(texaddr) || !Memory::IsValidAddress(texaddr + offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const u16 dim = gstate.getTextureDimension(0);
|
||||
u64 cachekey = TexCacheEntry::CacheKey(texaddr, gstate.getTextureFormat(), dim, 0);
|
||||
TexCache::iterator iter = cache.find(cachekey);
|
||||
if (iter == cache.end()) {
|
||||
return false;
|
||||
}
|
||||
TexCacheEntry *entry = &iter->second;
|
||||
|
||||
bool success = false;
|
||||
for (size_t i = 0, n = fbCache_.size(); i < n; ++i) {
|
||||
auto framebuffer = fbCache_[i];
|
||||
if (AttachFramebuffer(entry, framebuffer->fb_address, framebuffer, offset)) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (success && entry->framebuffer) {
|
||||
// This will not apply the texture immediately.
|
||||
SetTextureFramebuffer(entry, entry->framebuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextureCacheCommon::NotifyConfigChanged() {
|
||||
int scaleFactor;
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
void LoadClut(u32 clutAddr, u32 loadBytes);
|
||||
bool GetCurrentClutBuffer(GPUDebugBuffer &buffer);
|
||||
|
||||
virtual bool SetOffsetTexture(u32 offset) = 0;
|
||||
bool SetOffsetTexture(u32 offset);
|
||||
void Invalidate(u32 addr, int size, GPUInvalidationType type);
|
||||
void InvalidateAll(GPUInvalidationType type);
|
||||
void ClearNextFrame();
|
||||
|
|
|
@ -590,39 +590,6 @@ void TextureCacheDX9::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFrame
|
|||
lastBoundTexture = INVALID_TEX;
|
||||
}
|
||||
|
||||
bool TextureCacheDX9::SetOffsetTexture(u32 offset) {
|
||||
if (g_Config.iRenderingMode != FB_BUFFERED_MODE) {
|
||||
return false;
|
||||
}
|
||||
u32 texaddr = gstate.getTextureAddress(0);
|
||||
if (!Memory::IsValidAddress(texaddr) || !Memory::IsValidAddress(texaddr + offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const u16 dim = gstate.getTextureDimension(0);
|
||||
u64 cachekey = TexCacheEntry::CacheKey(texaddr, gstate.getTextureFormat(), dim, 0);
|
||||
TexCache::iterator iter = cache.find(cachekey);
|
||||
if (iter == cache.end()) {
|
||||
return false;
|
||||
}
|
||||
TexCacheEntry *entry = &iter->second;
|
||||
|
||||
bool success = false;
|
||||
for (size_t i = 0, n = fbCache_.size(); i < n; ++i) {
|
||||
auto framebuffer = fbCache_[i];
|
||||
if (AttachFramebuffer(entry, framebuffer->fb_address, framebuffer, offset)) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (success && entry->framebuffer) {
|
||||
SetTextureFramebuffer(entry, entry->framebuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextureCacheDX9::SetTexture(bool force) {
|
||||
#ifdef DEBUG_TEXTURES
|
||||
if (SetDebugTexture()) {
|
||||
|
@ -1108,29 +1075,19 @@ TextureCacheDX9::TexCacheEntry::Status TextureCacheDX9::CheckAlpha(const u32 *pi
|
|||
|
||||
ReplacedTextureFormat FromD3D9Format(u32 fmt) {
|
||||
switch (fmt) {
|
||||
case D3DFMT_R5G6B5:
|
||||
return ReplacedTextureFormat::F_5650;
|
||||
case D3DFMT_A1R5G5B5:
|
||||
return ReplacedTextureFormat::F_5551;
|
||||
case D3DFMT_A4R4G4B4:
|
||||
return ReplacedTextureFormat::F_4444;
|
||||
case D3DFMT_A8R8G8B8:
|
||||
default:
|
||||
return ReplacedTextureFormat::F_8888;
|
||||
case D3DFMT_R5G6B5: return ReplacedTextureFormat::F_5650;
|
||||
case D3DFMT_A1R5G5B5: return ReplacedTextureFormat::F_5551;
|
||||
case D3DFMT_A4R4G4B4: return ReplacedTextureFormat::F_4444;
|
||||
case D3DFMT_A8R8G8B8: default: return ReplacedTextureFormat::F_8888;
|
||||
}
|
||||
}
|
||||
|
||||
D3DFORMAT ToD3D9Format(ReplacedTextureFormat fmt) {
|
||||
switch (fmt) {
|
||||
case ReplacedTextureFormat::F_5650:
|
||||
return D3DFMT_R5G6B5;
|
||||
case ReplacedTextureFormat::F_5551:
|
||||
return D3DFMT_A1R5G5B5;
|
||||
case ReplacedTextureFormat::F_4444:
|
||||
return D3DFMT_A4R4G4B4;
|
||||
case ReplacedTextureFormat::F_8888:
|
||||
default:
|
||||
return D3DFMT_A8R8G8B8;
|
||||
case ReplacedTextureFormat::F_5650: return D3DFMT_R5G6B5;
|
||||
case ReplacedTextureFormat::F_5551: return D3DFMT_A1R5G5B5;
|
||||
case ReplacedTextureFormat::F_4444: return D3DFMT_A4R4G4B4;
|
||||
case ReplacedTextureFormat::F_8888: default: return D3DFMT_A8R8G8B8;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ public:
|
|||
~TextureCacheDX9();
|
||||
|
||||
void SetTexture(bool force = false);
|
||||
virtual bool SetOffsetTexture(u32 offset) override;
|
||||
|
||||
void Clear(bool delete_them);
|
||||
void StartFrame();
|
||||
|
|
|
@ -653,66 +653,22 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram
|
|||
lastBoundTexture = INVALID_TEX;
|
||||
}
|
||||
|
||||
bool TextureCacheGLES::SetOffsetTexture(u32 offset) {
|
||||
if (g_Config.iRenderingMode != FB_BUFFERED_MODE) {
|
||||
return false;
|
||||
}
|
||||
u32 texaddr = gstate.getTextureAddress(0);
|
||||
if (!Memory::IsValidAddress(texaddr) || !Memory::IsValidAddress(texaddr + offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const u16 dim = gstate.getTextureDimension(0);
|
||||
u64 cachekey = TexCacheEntry::CacheKey(texaddr, gstate.getTextureFormat(), dim, 0);
|
||||
TexCache::iterator iter = cache.find(cachekey);
|
||||
if (iter == cache.end()) {
|
||||
return false;
|
||||
}
|
||||
TexCacheEntry *entry = &iter->second;
|
||||
|
||||
bool success = false;
|
||||
for (size_t i = 0, n = fbCache_.size(); i < n; ++i) {
|
||||
auto framebuffer = fbCache_[i];
|
||||
if (AttachFramebuffer(entry, framebuffer->fb_address, framebuffer, offset)) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (success && entry->framebuffer) {
|
||||
// This will not apply the texture immediately.
|
||||
SetTextureFramebuffer(entry, entry->framebuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ReplacedTextureFormat FromGLESFormat(GLenum fmt, bool useBGRA = false) {
|
||||
// TODO: 16-bit formats are incorrect, since swizzled.
|
||||
switch (fmt) {
|
||||
case GL_UNSIGNED_SHORT_5_6_5:
|
||||
return ReplacedTextureFormat::F_0565_ABGR;
|
||||
case GL_UNSIGNED_SHORT_5_5_5_1:
|
||||
return ReplacedTextureFormat::F_1555_ABGR;
|
||||
case GL_UNSIGNED_SHORT_4_4_4_4:
|
||||
return ReplacedTextureFormat::F_4444_ABGR;
|
||||
case GL_UNSIGNED_BYTE:
|
||||
default:
|
||||
return useBGRA ? ReplacedTextureFormat::F_8888_BGRA : ReplacedTextureFormat::F_8888;
|
||||
case GL_UNSIGNED_SHORT_5_6_5: return ReplacedTextureFormat::F_0565_ABGR;
|
||||
case GL_UNSIGNED_SHORT_5_5_5_1: return ReplacedTextureFormat::F_1555_ABGR;
|
||||
case GL_UNSIGNED_SHORT_4_4_4_4: return ReplacedTextureFormat::F_4444_ABGR;
|
||||
case GL_UNSIGNED_BYTE: default: return useBGRA ? ReplacedTextureFormat::F_8888_BGRA : ReplacedTextureFormat::F_8888;
|
||||
}
|
||||
}
|
||||
|
||||
GLenum ToGLESFormat(ReplacedTextureFormat fmt) {
|
||||
switch (fmt) {
|
||||
case ReplacedTextureFormat::F_5650:
|
||||
return GL_UNSIGNED_SHORT_5_6_5;
|
||||
case ReplacedTextureFormat::F_5551:
|
||||
return GL_UNSIGNED_SHORT_5_5_5_1;
|
||||
case ReplacedTextureFormat::F_4444:
|
||||
return GL_UNSIGNED_SHORT_4_4_4_4;
|
||||
case ReplacedTextureFormat::F_8888:
|
||||
default:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case ReplacedTextureFormat::F_5650: return GL_UNSIGNED_SHORT_5_6_5;
|
||||
case ReplacedTextureFormat::F_5551: return GL_UNSIGNED_SHORT_5_5_5_1;
|
||||
case ReplacedTextureFormat::F_4444: return GL_UNSIGNED_SHORT_4_4_4_4;
|
||||
case ReplacedTextureFormat::F_8888: default: return GL_UNSIGNED_BYTE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ public:
|
|||
~TextureCacheGLES();
|
||||
|
||||
void SetTexture(bool force = false);
|
||||
virtual bool SetOffsetTexture(u32 offset) override;
|
||||
|
||||
void Clear(bool delete_them);
|
||||
void StartFrame();
|
||||
|
|
|
@ -594,65 +594,21 @@ void TextureCacheVulkan::ApplyTextureFramebuffer(VkCommandBuffer cmd, TexCacheEn
|
|||
}
|
||||
}
|
||||
|
||||
bool TextureCacheVulkan::SetOffsetTexture(u32 offset) {
|
||||
if (g_Config.iRenderingMode != FB_BUFFERED_MODE) {
|
||||
return false;
|
||||
}
|
||||
u32 texaddr = gstate.getTextureAddress(0);
|
||||
if (!Memory::IsValidAddress(texaddr) || !Memory::IsValidAddress(texaddr + offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const u16 dim = gstate.getTextureDimension(0);
|
||||
u64 cachekey = TexCacheEntry::CacheKey(texaddr, gstate.getTextureFormat(), dim, 0);
|
||||
TexCache::iterator iter = cache.find(cachekey);
|
||||
if (iter == cache.end()) {
|
||||
return false;
|
||||
}
|
||||
TexCacheEntry *entry = &iter->second;
|
||||
|
||||
bool success = false;
|
||||
for (size_t i = 0, n = fbCache_.size(); i < n; ++i) {
|
||||
auto framebuffer = fbCache_[i];
|
||||
if (AttachFramebuffer(entry, framebuffer->fb_address, framebuffer, offset)) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (success && entry->framebuffer) {
|
||||
// This will not apply the texture immediately.
|
||||
SetTextureFramebuffer(entry, entry->framebuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ReplacedTextureFormat FromVulkanFormat(VkFormat fmt) {
|
||||
switch (fmt) {
|
||||
case VULKAN_565_FORMAT:
|
||||
return ReplacedTextureFormat::F_5650;
|
||||
case VULKAN_1555_FORMAT:
|
||||
return ReplacedTextureFormat::F_5551;
|
||||
case VULKAN_4444_FORMAT:
|
||||
return ReplacedTextureFormat::F_4444;
|
||||
case VULKAN_8888_FORMAT:
|
||||
default:
|
||||
return ReplacedTextureFormat::F_8888;
|
||||
case VULKAN_565_FORMAT: return ReplacedTextureFormat::F_5650;
|
||||
case VULKAN_1555_FORMAT: return ReplacedTextureFormat::F_5551;
|
||||
case VULKAN_4444_FORMAT: return ReplacedTextureFormat::F_4444;
|
||||
case VULKAN_8888_FORMAT: default: return ReplacedTextureFormat::F_8888;
|
||||
}
|
||||
}
|
||||
|
||||
VkFormat ToVulkanFormat(ReplacedTextureFormat fmt) {
|
||||
switch (fmt) {
|
||||
case ReplacedTextureFormat::F_5650:
|
||||
return VULKAN_565_FORMAT;
|
||||
case ReplacedTextureFormat::F_5551:
|
||||
return VULKAN_1555_FORMAT;
|
||||
case ReplacedTextureFormat::F_4444:
|
||||
return VULKAN_4444_FORMAT;
|
||||
case ReplacedTextureFormat::F_8888:
|
||||
default:
|
||||
return VULKAN_8888_FORMAT;
|
||||
case ReplacedTextureFormat::F_5650: return VULKAN_565_FORMAT;
|
||||
case ReplacedTextureFormat::F_5551: return VULKAN_1555_FORMAT;
|
||||
case ReplacedTextureFormat::F_4444: return VULKAN_4444_FORMAT;
|
||||
case ReplacedTextureFormat::F_8888: default: return VULKAN_8888_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,8 +90,6 @@ public:
|
|||
~TextureCacheVulkan();
|
||||
|
||||
void SetTexture();
|
||||
virtual bool SetOffsetTexture(u32 offset) override;
|
||||
|
||||
void Clear(bool delete_them);
|
||||
void StartFrame();
|
||||
void EndFrame();
|
||||
|
|
Loading…
Add table
Reference in a new issue