Merge dpJudas's renderslices branch (#1356)

* Remove threading from the drawers

* Fix some r_scene_multithreaded related bugs

* Fix some r_scene_multithreaded crashes

* Fix fullbright shade bug

* Fix truecolor drawer crash

* Add debug code for showing the render slices

* Fix texture loading race condition and improve performance by only locking the load mutex if data hasn't already been updated for this frame

Co-authored-by: Magnus Norddahl <dpjudas@users.noreply.github.com>
This commit is contained in:
Xaser Acheron 2021-03-25 19:58:08 -05:00 committed by GitHub
commit a5cba1aba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 1336 additions and 1987 deletions

View file

@ -53,6 +53,9 @@
#include "swrenderer/drawers/r_draw_pal.h"
#include "swrenderer/viewport/r_viewport.h"
#include "r_memory.h"
#include "common/rendering/polyrenderer/drawers/poly_thread.h"
std::pair<PalEntry, PalEntry>& R_GetSkyCapColor(FGameTexture* tex);
namespace swrenderer
{
@ -63,7 +66,6 @@ namespace swrenderer
FrameMemory.reset(new RenderMemory());
Viewport.reset(new RenderViewport());
Light.reset(new LightVisibility());
DrawQueue.reset(new DrawerCommandQueue(FrameMemory.get()));
OpaquePass.reset(new RenderOpaquePass(this));
TranslucentPass.reset(new RenderTranslucentPass(this));
SpriteList.reset(new VisibleSpriteList());
@ -73,8 +75,9 @@ namespace swrenderer
PlaneList.reset(new VisiblePlaneList(this));
DrawSegments.reset(new DrawSegmentList(this));
ClipSegments.reset(new RenderClipSegment());
tc_drawers.reset(new SWTruecolorDrawers(DrawQueue));
pal_drawers.reset(new SWPalDrawers(DrawQueue));
Poly.reset(new PolyTriangleThreadData(0, 1, 0, 1, 0, screen->GetHeight()));
tc_drawers.reset(new SWTruecolorDrawers(this));
pal_drawers.reset(new SWPalDrawers(this));
}
RenderThread::~RenderThread()
@ -89,33 +92,13 @@ namespace swrenderer
return pal_drawers.get();
}
static std::mutex loadmutex;
void RenderThread::PrepareTexture(FSoftwareTexture *texture, FRenderStyle style) {
if (texture == nullptr)
return;
// Textures may not have loaded/refreshed yet. The shared code doing
// this is not thread safe. By calling GetPixels in a mutex lock we
// make sure that only one thread is loading a texture at any given
// time.
//
// It is critical that this function is called before any direct
// calls to GetPixels for this to work.
std::mutex loadmutex;
std::pair<PalEntry, PalEntry> RenderThread::GetSkyCapColor(FSoftwareTexture* tex)
{
std::unique_lock<std::mutex> lock(loadmutex);
const FSoftwareTextureSpan *spans;
if (Viewport->RenderTarget->IsBgra())
{
texture->GetPixelsBgra();
texture->GetColumnBgra(0, &spans);
}
else
{
bool alpha = !!(style.Flags & STYLEF_RedIsAlpha);
texture->GetPixels(alpha);
texture->GetColumn(alpha, 0, &spans);
}
std::pair<PalEntry, PalEntry> colors = R_GetSkyCapColor(tex->GetTexture());
return colors;
}
static std::mutex polyobjmutex;