From ddcd3861d39c20583573c2197e01373f3368568d Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 31 May 2022 17:41:57 +0200 Subject: [PATCH] ggpo: don't protect rtt texture vram if ggpo is enabled tentative fix for flashing water reflection texture in vf4 during netplay --- core/rend/TexCache.cpp | 39 ++++++++++++++++++----------- core/rend/TexCache.h | 4 ++- core/rend/dx11/dx11_renderer.cpp | 5 +++- core/rend/dx9/d3d_renderer.cpp | 5 +++- core/rend/gles/gltex.cpp | 5 +++- core/rend/vulkan/drawer.cpp | 5 +++- core/rend/vulkan/oit/oit_drawer.cpp | 5 +++- 7 files changed, 47 insertions(+), 21 deletions(-) diff --git a/core/rend/TexCache.cpp b/core/rend/TexCache.cpp index d8034abfb..670c38516 100644 --- a/core/rend/TexCache.cpp +++ b/core/rend/TexCache.cpp @@ -214,23 +214,23 @@ void vramlock_list_add(vram_block* block) std::mutex vramlist_lock; -void libCore_vramlock_Lock(u32 start_offset64, u32 end_offset64, BaseTextureCacheData *texture) +static void vramlock_Lock(u32 start, u32 end, BaseTextureCacheData *texture) { - if (end_offset64 > VRAM_SIZE - 1) + if (end >= VRAM_SIZE) { - WARN_LOG(PVR, "vramlock_Lock_64: end_offset64>(VRAM_SIZE-1) \n Tried to lock area out of vram , possibly bug on the pvr plugin"); - end_offset64 = VRAM_SIZE - 1; + WARN_LOG(PVR, "vramlock_Lock: end >= VRAM_SIZE. Tried to lock area out of vram"); + end = VRAM_SIZE - 1; } - if (start_offset64 > end_offset64) + if (start > end) { - WARN_LOG(PVR, "vramlock_Lock_64: start_offset64>end_offset64 \n Tried to lock negative block , possibly bug on the pvr plugin"); + WARN_LOG(PVR, "vramlock_Lock: start > end. Tried to lock negative block"); return; } vram_block *block = new vram_block(); - block->end = end_offset64; - block->start = start_offset64; + block->end = end; + block->start = start; block->texture = texture; { @@ -445,19 +445,28 @@ bool BaseTextureCacheData::NeedsUpdate() { return rc; } +void BaseTextureCacheData::protectVRam() +{ + vramlock_Lock(sa_tex, sa + size - 1, this); +} + +void BaseTextureCacheData::unprotectVRam() +{ + std::lock_guard lock(vramlist_lock); + if (lock_block) + libCore_vramlock_Unlock_block_wb(lock_block); + lock_block = nullptr; +} + bool BaseTextureCacheData::Delete() { if (custom_load_in_progress > 0) return false; - { - std::lock_guard lock(vramlist_lock); - if (lock_block) - libCore_vramlock_Unlock_block_wb(lock_block); - lock_block = nullptr; - } + unprotectVRam(); free(custom_image_data); + custom_image_data = nullptr; return true; } @@ -777,7 +786,7 @@ void BaseTextureCacheData::Update() height = original_h; //lock the texture to detect changes in it - libCore_vramlock_Lock(sa_tex, sa + size - 1, this); + protectVRam(); UploadToGPU(upscaled_w, upscaled_h, (u8*)temp_tex_buffer, IsMipmapped(), mipmapped); if (config::DumpTextures) diff --git a/core/rend/TexCache.h b/core/rend/TexCache.h index 4e595e1e2..26b7875e5 100644 --- a/core/rend/TexCache.h +++ b/core/rend/TexCache.h @@ -564,7 +564,6 @@ struct vram_block bool VramLockedWriteOffset(size_t offset); bool VramLockedWrite(u8* address); -void libCore_vramlock_Lock(u32 start_offset, u32 end_offset, BaseTextureCacheData *texture); void UpscalexBRZ(int factor, u32* source, u32* dest, int width, int height, bool has_alpha); @@ -648,6 +647,9 @@ public: bool NeedsUpdate(); virtual bool Delete(); virtual ~BaseTextureCacheData() = default; + void protectVRam(); + void unprotectVRam(); + static bool IsGpuHandledPaletted(TSP tsp, TCW tcw) { // Some palette textures are handled on the GPU diff --git a/core/rend/dx11/dx11_renderer.cpp b/core/rend/dx11/dx11_renderer.cpp index 6508005fb..28978b44e 100644 --- a/core/rend/dx11/dx11_renderer.cpp +++ b/core/rend/dx11/dx11_renderer.cpp @@ -1338,7 +1338,10 @@ void DX11Renderer::readRttRenderTarget(u32 texAddress) device->CreateShaderResourceView(texture->texture, &viewDesc, &texture->textureView.get()); texture->dirty = 0; - libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture); + if (!config::GGPOEnable) + texture->protectVRam(); + else + texture->unprotectVRam(); } } } diff --git a/core/rend/dx9/d3d_renderer.cpp b/core/rend/dx9/d3d_renderer.cpp index 481477fc7..9fb0f0c45 100644 --- a/core/rend/dx9/d3d_renderer.cpp +++ b/core/rend/dx9/d3d_renderer.cpp @@ -968,7 +968,10 @@ void D3DRenderer::readRttRenderTarget(u32 texAddress) texture->texture = rttTexture; texture->dirty = 0; - libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture); + if (!config::GGPOEnable) + texture->protectVRam(); + else + texture->unprotectVRam(); } } } diff --git a/core/rend/gles/gltex.cpp b/core/rend/gles/gltex.cpp index f895829f5..c22f32116 100644 --- a/core/rend/gles/gltex.cpp +++ b/core/rend/gles/gltex.cpp @@ -364,7 +364,10 @@ void ReadRTTBuffer() texture_data->texID = gl.rtt.tex; gl.rtt.tex = 0; texture_data->dirty = 0; - libCore_vramlock_Lock(texture_data->sa_tex, texture_data->sa + texture_data->size - 1, texture_data); + if (!config::GGPOEnable) + texture_data->protectVRam(); + else + texture_data->unprotectVRam(); } gl.rtt.texAddress = ~0; } diff --git a/core/rend/vulkan/drawer.cpp b/core/rend/vulkan/drawer.cpp index 7041d4c29..0b137d1cb 100644 --- a/core/rend/vulkan/drawer.cpp +++ b/core/rend/vulkan/drawer.cpp @@ -558,7 +558,10 @@ void TextureDrawer::EndRenderPass() //memset(&vram[fb_rtt.TexAddr << 3], '\0', size); texture->dirty = 0; - libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture); + if (!config::GGPOEnable) + texture->protectVRam(); + else + texture->unprotectVRam(); } Drawer::EndRenderPass(); } diff --git a/core/rend/vulkan/oit/oit_drawer.cpp b/core/rend/vulkan/oit/oit_drawer.cpp index 48bbe5937..3da8f35a9 100644 --- a/core/rend/vulkan/oit/oit_drawer.cpp +++ b/core/rend/vulkan/oit/oit_drawer.cpp @@ -678,7 +678,10 @@ void OITTextureDrawer::EndFrame() //memset(&vram[fb_rtt.TexAddr << 3], '\0', size); texture->dirty = 0; - libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture); + if (!config::GGPOEnable) + texture->protectVRam(); + else + texture->unprotectVRam(); } OITDrawer::EndFrame(); }