Fix some r_scene_multithreaded related bugs

This commit is contained in:
Magnus Norddahl 2021-02-11 06:31:30 +01:00 committed by Rachael Alexanderson
parent 4cd994c027
commit fb87f90d86
3 changed files with 18 additions and 9 deletions

View file

@ -91,7 +91,8 @@ namespace swrenderer
} }
static std::mutex loadmutex; static std::mutex loadmutex;
void RenderThread::PrepareTexture(FSoftwareTexture *texture, FRenderStyle style) { void RenderThread::PrepareTexture(FSoftwareTexture *texture, FRenderStyle style)
{
if (texture == nullptr) if (texture == nullptr)
return; return;
@ -116,7 +117,7 @@ namespace swrenderer
bool alpha = !!(style.Flags & STYLEF_RedIsAlpha); bool alpha = !!(style.Flags & STYLEF_RedIsAlpha);
texture->GetPixels(alpha); texture->GetPixels(alpha);
texture->GetColumn(alpha, 0, &spans); texture->GetColumn(alpha, 0, &spans);
} }
} }
static std::mutex polyobjmutex; static std::mutex polyobjmutex;

View file

@ -39,7 +39,7 @@
#include "m_alloc.h" #include "m_alloc.h"
#include "imagehelpers.h" #include "imagehelpers.h"
#include "texturemanager.h" #include "texturemanager.h"
#include <mutex>
inline EUpscaleFlags scaleFlagFromUseType(ETextureType useType) 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* GetSoftwareTexture(FGameTexture* tex)
{ {
FSoftwareTexture* SoftwareTexture = static_cast<FSoftwareTexture*>(tex->GetSoftwareTexture()); FSoftwareTexture* SoftwareTexture = static_cast<FSoftwareTexture*>(tex->GetSoftwareTexture());
if (!SoftwareTexture) if (!SoftwareTexture)
{ {
if (tex->isSoftwareCanvas()) SoftwareTexture = new FSWCanvasTexture(tex); static std::mutex loadmutex;
else if (tex->isWarped()) SoftwareTexture = new FWarpTexture(tex, tex->isWarped()); std::unique_lock<std::mutex> lock(loadmutex);
else SoftwareTexture = new FSoftwareTexture(tex);
tex->SetSoftwareTexture(SoftwareTexture); SoftwareTexture = static_cast<FSoftwareTexture*>(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; return SoftwareTexture;
} }
@ -582,6 +590,7 @@ CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL)
R_InitSkyMap(); R_InitSkyMap();
} }
// Note: this function needs to be thread safe
FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool checkcompat, bool allownull) FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool checkcompat, bool allownull)
{ {
bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor(); bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor();

View file

@ -262,8 +262,7 @@ namespace swrenderer
{ {
RenderTranslucentPass *translucentPass = thread->TranslucentPass.get(); RenderTranslucentPass *translucentPass = thread->TranslucentPass.get();
short portalfloorclip[MAXWIDTH]; short portalfloorclip[MAXWIDTH];
int x2 = wallc.sx2; for (int x = x1; x < x2; x++)
for (int x = wallc.sx1; x < x2; x++)
{ {
if (translucentPass->ClipSpriteColumnWithPortals(x, this)) if (translucentPass->ClipSpriteColumnWithPortals(x, this))
portalfloorclip[x] = mceilingclip[x]; portalfloorclip[x] = mceilingclip[x];