Skip to content

Commit

Permalink
Fix some r_scene_multithreaded related bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas authored and madame-rachelle committed Mar 26, 2021
1 parent 4cd994c commit fb87f90
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/rendering/swrenderer/r_renderthread.cpp
Expand Up @@ -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;

Expand All @@ -116,7 +117,7 @@ namespace swrenderer
bool alpha = !!(style.Flags & STYLEF_RedIsAlpha);
texture->GetPixels(alpha);
texture->GetColumn(alpha, 0, &spans);
}
}
}

static std::mutex polyobjmutex;
Expand Down
19 changes: 14 additions & 5 deletions src/rendering/swrenderer/textures/r_swtexture.cpp
Expand Up @@ -39,7 +39,7 @@
#include "m_alloc.h"
#include "imagehelpers.h"
#include "texturemanager.h"

#include <mutex>

inline EUpscaleFlags scaleFlagFromUseType(ETextureType useType)
{
Expand Down Expand Up @@ -562,15 +562,23 @@ void FSoftwareTexture::FreeAllSpans()
}
}

// Note: this function needs to be thread safe
FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex)
{
FSoftwareTexture* 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);
static std::mutex loadmutex;
std::unique_lock<std::mutex> lock(loadmutex);

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;
}
Expand All @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/rendering/swrenderer/things/r_sprite.cpp
Expand Up @@ -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];
Expand Down

0 comments on commit fb87f90

Please sign in to comment.