Fix some r_scene_multithreaded crashes

This commit is contained in:
Magnus Norddahl 2021-02-11 08:53:37 +01:00 committed by Rachael Alexanderson
parent fb87f90d86
commit bdb35e5e86
4 changed files with 17 additions and 6 deletions

View file

@ -59,8 +59,6 @@ CVAR(Bool, r_linearsky, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
EXTERN_CVAR(Int, r_skymode)
EXTERN_CVAR(Bool, cl_oldfreelooklimit)
std::pair<PalEntry, PalEntry>& R_GetSkyCapColor(FGameTexture* tex);
namespace swrenderer
{
static FSoftwareTexture *GetSWTex(FTextureID texid, bool allownull = true)
@ -255,6 +253,8 @@ namespace swrenderer
angle1 = UMulScale16(ang, frontcyl) + frontpos;
angle2 = UMulScale16(ang, backcyl) + backpos;
auto skycapcolors = Thread->GetSkyCapColor(frontskytex);
drawerargs.SetFrontTexture(Thread, frontskytex, angle1);
drawerargs.SetBackTexture(Thread, backskytex, angle2);
drawerargs.SetTextureVStep(uv_step);
@ -262,9 +262,8 @@ namespace swrenderer
drawerargs.SetDest(viewport, start_x, y1);
drawerargs.SetCount(y2 - y1);
drawerargs.SetFadeSky(r_skymode == 2 && !(Level->flags & LEVEL_FORCETILEDSKY));
auto& col = R_GetSkyCapColor(frontskytex->GetTexture());
drawerargs.SetSolidTop(col.first);
drawerargs.SetSolidBottom(col.second);
drawerargs.SetSolidTop(skycapcolors.first);
drawerargs.SetSolidBottom(skycapcolors.second);
if (!backskytex)
drawerargs.DrawSingleSkyColumn(Thread);

View file

@ -55,6 +55,8 @@
#include "r_memory.h"
#include "common/rendering/polyrenderer/drawers/poly_thread.h"
std::pair<PalEntry, PalEntry>& R_GetSkyCapColor(FGameTexture* tex);
namespace swrenderer
{
RenderThread::RenderThread(RenderScene *scene, bool mainThread)
@ -120,6 +122,13 @@ namespace swrenderer
}
}
std::pair<PalEntry, PalEntry> RenderThread::GetSkyCapColor(FSoftwareTexture* tex)
{
std::unique_lock<std::mutex> lock(loadmutex);
std::pair<PalEntry, PalEntry> colors = R_GetSkyCapColor(tex->GetTexture());
return colors;
}
static std::mutex polyobjmutex;
void RenderThread::PreparePolyObject(subsector_t *sub)
{

View file

@ -93,6 +93,9 @@ namespace swrenderer
// Setup poly object in a threadsafe manner
void PreparePolyObject(subsector_t *sub);
// Retrieve skycap color in a threadsafe way
std::pair<PalEntry, PalEntry> GetSkyCapColor(FSoftwareTexture* tex);
private:
std::unique_ptr<SWTruecolorDrawers> tc_drawers;
std::unique_ptr<SWPalDrawers> pal_drawers;

View file

@ -66,7 +66,7 @@ void PeekThreadedErrorPane();
EXTERN_CVAR(Int, r_clearbuffer)
EXTERN_CVAR(Int, r_debug_draw)
CVAR(Int, r_scene_multithreaded, 0, 0);
CVAR(Int, r_scene_multithreaded, 1, 0);
CVAR(Bool, r_models, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
bool r_modelscene = false;