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

View file

@ -55,6 +55,8 @@
#include "r_memory.h" #include "r_memory.h"
#include "common/rendering/polyrenderer/drawers/poly_thread.h" #include "common/rendering/polyrenderer/drawers/poly_thread.h"
std::pair<PalEntry, PalEntry>& R_GetSkyCapColor(FGameTexture* tex);
namespace swrenderer namespace swrenderer
{ {
RenderThread::RenderThread(RenderScene *scene, bool mainThread) 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; static std::mutex polyobjmutex;
void RenderThread::PreparePolyObject(subsector_t *sub) void RenderThread::PreparePolyObject(subsector_t *sub)
{ {

View file

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

View file

@ -66,7 +66,7 @@ void PeekThreadedErrorPane();
EXTERN_CVAR(Int, r_clearbuffer) EXTERN_CVAR(Int, r_clearbuffer)
EXTERN_CVAR(Int, r_debug_draw) 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); CVAR(Bool, r_models, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
bool r_modelscene = false; bool r_modelscene = false;