From fb87f90d86166e34f25e4c6c23a2c5547f1b087b Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 11 Feb 2021 06:31:30 +0100 Subject: [PATCH] Fix some r_scene_multithreaded related bugs --- src/rendering/swrenderer/r_renderthread.cpp | 5 +++-- .../swrenderer/textures/r_swtexture.cpp | 19 ++++++++++++++----- src/rendering/swrenderer/things/r_sprite.cpp | 3 +-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/rendering/swrenderer/r_renderthread.cpp b/src/rendering/swrenderer/r_renderthread.cpp index 5908737839..4226a719ae 100644 --- a/src/rendering/swrenderer/r_renderthread.cpp +++ b/src/rendering/swrenderer/r_renderthread.cpp @@ -91,7 +91,8 @@ namespace swrenderer } static std::mutex loadmutex; - void RenderThread::PrepareTexture(FSoftwareTexture *texture, FRenderStyle style) { + void RenderThread::PrepareTexture(FSoftwareTexture *texture, FRenderStyle style) + { if (texture == nullptr) return; @@ -116,7 +117,7 @@ namespace swrenderer bool alpha = !!(style.Flags & STYLEF_RedIsAlpha); texture->GetPixels(alpha); texture->GetColumn(alpha, 0, &spans); - } + } } static std::mutex polyobjmutex; diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index c41837d36f..e45bd79786 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -39,7 +39,7 @@ #include "m_alloc.h" #include "imagehelpers.h" #include "texturemanager.h" - +#include inline EUpscaleFlags scaleFlagFromUseType(ETextureType useType) { @@ -562,15 +562,23 @@ void FSoftwareTexture::FreeAllSpans() } } +// Note: this function needs to be thread safe FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex) { FSoftwareTexture* SoftwareTexture = static_cast(tex->GetSoftwareTexture()); if (!SoftwareTexture) { - if (tex->isSoftwareCanvas()) SoftwareTexture = new FSWCanvasTexture(tex); - else if (tex->isWarped()) SoftwareTexture = new FWarpTexture(tex, tex->isWarped()); - else SoftwareTexture = new FSoftwareTexture(tex); - tex->SetSoftwareTexture(SoftwareTexture); + static std::mutex loadmutex; + std::unique_lock lock(loadmutex); + + SoftwareTexture = static_cast(tex->GetSoftwareTexture()); + if (!SoftwareTexture) + { + if (tex->isSoftwareCanvas()) SoftwareTexture = new FSWCanvasTexture(tex); + else if (tex->isWarped()) SoftwareTexture = new FWarpTexture(tex, tex->isWarped()); + else SoftwareTexture = new FSoftwareTexture(tex); + tex->SetSoftwareTexture(SoftwareTexture); + } } return SoftwareTexture; } @@ -582,6 +590,7 @@ CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL) R_InitSkyMap(); } +// Note: this function needs to be thread safe FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool checkcompat, bool allownull) { bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor(); diff --git a/src/rendering/swrenderer/things/r_sprite.cpp b/src/rendering/swrenderer/things/r_sprite.cpp index 2a7722a58b..2873b91495 100644 --- a/src/rendering/swrenderer/things/r_sprite.cpp +++ b/src/rendering/swrenderer/things/r_sprite.cpp @@ -262,8 +262,7 @@ namespace swrenderer { RenderTranslucentPass *translucentPass = thread->TranslucentPass.get(); short portalfloorclip[MAXWIDTH]; - int x2 = wallc.sx2; - for (int x = wallc.sx1; x < x2; x++) + for (int x = x1; x < x2; x++) { if (translucentPass->ClipSpriteColumnWithPortals(x, this)) portalfloorclip[x] = mceilingclip[x];