diff --git a/core/rend/TexCache.cpp b/core/rend/TexCache.cpp index 977d854e4..7e145090d 100644 --- a/core/rend/TexCache.cpp +++ b/core/rend/TexCache.cpp @@ -174,7 +174,7 @@ void vramlock_list_add(vram_block* block) std::mutex vramlist_lock; -vram_block* libCore_vramlock_Lock(u32 start_offset64,u32 end_offset64,void* userdata) +void libCore_vramlock_Lock(u32 start_offset64, u32 end_offset64, BaseTextureCacheData *texture) { vram_block* block=(vram_block* )malloc(sizeof(vram_block)); @@ -195,17 +195,21 @@ vram_block* libCore_vramlock_Lock(u32 start_offset64,u32 end_offset64,void* user block->end=end_offset64; block->start=start_offset64; block->len=end_offset64-start_offset64+1; - block->userdata=userdata; + block->userdata = texture; block->type=64; { std::lock_guard lock(vramlist_lock); - // This also protects vram if needed - vramlock_list_add(block); + if (texture->lock_block == nullptr) + { + // This also protects vram if needed + vramlock_list_add(block); + texture->lock_block = block; + } + else + free(block); } - - return block; } bool VramLockedWriteOffset(size_t offset) @@ -217,7 +221,7 @@ bool VramLockedWriteOffset(size_t offset) std::vector& list = VramLocks[addr_hash]; { - std::lock_guard lock(vramlist_lock); + std::lock_guard lockguard(vramlist_lock); for (auto& lock : list) { @@ -716,8 +720,7 @@ void BaseTextureCacheData::Update() h = original_h; //lock the texture to detect changes in it - if (lock_block == nullptr) - lock_block = libCore_vramlock_Lock(sa_tex,sa+size-1,this); + libCore_vramlock_Lock(sa_tex, sa + size - 1, this); 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 e4e70c75d..5c9934400 100644 --- a/core/rend/TexCache.h +++ b/core/rend/TexCache.h @@ -643,9 +643,11 @@ struct vram_block void* userdata; }; +class BaseTextureCacheData; + bool VramLockedWriteOffset(size_t offset); void libCore_vramlock_Unlock_block(vram_block *block); -vram_block *libCore_vramlock_Lock(u32 start_offset, u32 end_offset, void *userdata); +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); diff --git a/core/rend/gles/gltex.cpp b/core/rend/gles/gltex.cpp index 13162f20c..4f25ff11c 100644 --- a/core/rend/gles/gltex.cpp +++ b/core/rend/gles/gltex.cpp @@ -287,8 +287,7 @@ void ReadRTTBuffer() { texture_data->Create(); texture_data->texID = gl.rtt.tex; texture_data->dirty = 0; - if (texture_data->lock_block == NULL) - texture_data->lock_block = libCore_vramlock_Lock(texture_data->sa_tex, texture_data->sa + texture_data->size - 1, texture_data); + libCore_vramlock_Lock(texture_data->sa_tex, texture_data->sa + texture_data->size - 1, texture_data); } gl.rtt.tex = 0; diff --git a/core/rend/vulkan/drawer.cpp b/core/rend/vulkan/drawer.cpp index 7ecf84a37..fdeca8617 100644 --- a/core/rend/vulkan/drawer.cpp +++ b/core/rend/vulkan/drawer.cpp @@ -574,8 +574,7 @@ void TextureDrawer::EndRenderPass() //memset(&vram[fb_rtt.TexAddr << 3], '\0', size); texture->dirty = 0; - if (texture->lock_block == NULL) - texture->lock_block = libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture); + libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture); } Drawer::EndRenderPass(); } diff --git a/core/rend/vulkan/oit/oit_drawer.cpp b/core/rend/vulkan/oit/oit_drawer.cpp index 9528a0ec3..441280fb7 100644 --- a/core/rend/vulkan/oit/oit_drawer.cpp +++ b/core/rend/vulkan/oit/oit_drawer.cpp @@ -675,8 +675,7 @@ void OITTextureDrawer::EndFrame() //memset(&vram[fb_rtt.TexAddr << 3], '\0', size); texture->dirty = 0; - if (texture->lock_block == NULL) - texture->lock_block = libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture); + libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture); } OITDrawer::EndFrame(); }