Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into archive_split
Browse files Browse the repository at this point in the history
  • Loading branch information
madame-rachelle committed Sep 10, 2017
2 parents 76f8050 + 830b68a commit 69b8575
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 46 deletions.
7 changes: 3 additions & 4 deletions src/polyrenderer/poly_renderthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ void PeekThreadedErrorPane();

EXTERN_CVAR(Bool, r_scene_multithreaded);

PolyRenderThread::PolyRenderThread(bool mainThread)
PolyRenderThread::PolyRenderThread(int threadIndex) : MainThread(threadIndex == 0), ThreadIndex(threadIndex)
{
MainThread = mainThread;
FrameMemory.reset(new RenderMemory());
DrawQueue = std::make_shared<DrawerCommandQueue>(FrameMemory.get());
}
Expand Down Expand Up @@ -118,7 +117,7 @@ void PolyRenderThread::PreparePolyObject(subsector_t *sub)

PolyRenderThreads::PolyRenderThreads()
{
std::unique_ptr<PolyRenderThread> thread(new PolyRenderThread(true));
std::unique_ptr<PolyRenderThread> thread(new PolyRenderThread(0));
Threads.push_back(std::move(thread));
}

Expand Down Expand Up @@ -220,7 +219,7 @@ void PolyRenderThreads::StartThreads(size_t numThreads)
{
while (Threads.size() < (size_t)numThreads)
{
std::unique_ptr<PolyRenderThread> thread(new PolyRenderThread(false));
std::unique_ptr<PolyRenderThread> thread(new PolyRenderThread((int)Threads.size()));
auto renderthread = thread.get();
int start_run_id = run_id;
thread->thread = std::thread([=]()
Expand Down
9 changes: 3 additions & 6 deletions src/polyrenderer/poly_renderthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,19 @@ class RenderMemory;
class PolyRenderThread
{
public:
PolyRenderThread(bool mainThread = true);
PolyRenderThread(int threadIndex);
~PolyRenderThread();

void FlushDrawQueue();

int Start = 0;
int End = 0;
bool MainThread = false;
int ThreadIndex = 0;

std::unique_ptr<RenderMemory> FrameMemory;
DrawerCommandQueuePtr DrawQueue;

std::vector<PolyTranslucentObject *> TranslucentObjects;

std::vector<std::unique_ptr<PolyDrawSectorPortal>> SectorPortals;
std::vector<std::unique_ptr<PolyDrawLinePortal>> LinePortals;

// Make sure texture can accessed safely
void PrepareTexture(FTexture *texture);

Expand All @@ -74,6 +70,7 @@ class PolyRenderThreads
void RenderThreadSlices(int totalcount, std::function<void(PolyRenderThread *)> workerCallback, std::function<void(PolyRenderThread *)> collectCallback);

PolyRenderThread *MainThread() { return Threads.front().get(); }
int NumThreads() const { return (int)Threads.size(); }

private:
void RenderThreadSlice(PolyRenderThread *thread);
Expand Down
58 changes: 26 additions & 32 deletions src/polyrenderer/scene/poly_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,25 @@ void RenderPolyScene::Render(int portalDepth)
{
PolyRenderThread *thread = PolyRenderer::Instance()->Threads.MainThread();

ClearBuffers(thread);
SectorPortals.clear();
LinePortals.clear();
Cull.CullScene(WorldToClip, PortalPlane);
RenderSectors();
RenderPortals(portalDepth);
}

void RenderPolyScene::ClearBuffers(PolyRenderThread *thread)
{
thread->TranslucentObjects.clear();
thread->SectorPortals.clear();
thread->LinePortals.clear();
}

void RenderPolyScene::RenderSectors()
{
PolyRenderThread *mainthread = PolyRenderer::Instance()->Threads.MainThread();

int totalcount = (int)Cull.PvsSectors.size();
auto subsectors = Cull.PvsSectors.data();

TranslucentObjects.resize(PolyRenderer::Instance()->Threads.NumThreads());

PolyRenderer::Instance()->Threads.RenderThreadSlices(totalcount, [&](PolyRenderThread *thread)
{
if (!thread->MainThread)
{
ClearBuffers(thread);
}
TranslucentObjects[thread->ThreadIndex].clear();

int start = thread->Start;
int end = thread->End;
Expand All @@ -93,7 +86,8 @@ void RenderPolyScene::RenderSectors()
}
}, [&](PolyRenderThread *thread)
{
mainthread->TranslucentObjects.insert(mainthread->TranslucentObjects.end(), thread->TranslucentObjects.begin(), thread->TranslucentObjects.end());
const auto &objects = TranslucentObjects[thread->ThreadIndex];
TranslucentObjects[0].insert(TranslucentObjects[0].end(), objects.begin(), objects.end());
});
}

Expand Down Expand Up @@ -127,13 +121,13 @@ void RenderPolyScene::RenderSubsector(PolyRenderThread *thread, subsector_t *sub
RenderPolyNode(thread, &sub->BSP->Nodes.Last(), subsectorDepth, frontsector);
}

Render3DFloorPlane::RenderPlanes(thread, WorldToClip, PortalPlane, sub, StencilValue, subsectorDepth, thread->TranslucentObjects);
RenderPolyPlane::RenderPlanes(thread, WorldToClip, PortalPlane, sub, StencilValue, Cull.MaxCeilingHeight, Cull.MinFloorHeight, thread->SectorPortals);
Render3DFloorPlane::RenderPlanes(thread, WorldToClip, PortalPlane, sub, StencilValue, subsectorDepth, TranslucentObjects[thread->ThreadIndex]);
RenderPolyPlane::RenderPlanes(thread, WorldToClip, PortalPlane, sub, StencilValue, Cull.MaxCeilingHeight, Cull.MinFloorHeight, SectorPortals);
}
else
{
Render3DFloorPlane::RenderPlanes(thread, WorldToClip, PortalPlane, sub, StencilValue, subsectorDepth, thread->TranslucentObjects);
RenderPolyPlane::RenderPlanes(thread, WorldToClip, PortalPlane, sub, StencilValue, Cull.MaxCeilingHeight, Cull.MinFloorHeight, thread->SectorPortals);
Render3DFloorPlane::RenderPlanes(thread, WorldToClip, PortalPlane, sub, StencilValue, subsectorDepth, TranslucentObjects[thread->ThreadIndex]);
RenderPolyPlane::RenderPlanes(thread, WorldToClip, PortalPlane, sub, StencilValue, Cull.MaxCeilingHeight, Cull.MinFloorHeight, SectorPortals);

for (uint32_t i = 0; i < sub->numlines; i++)
{
Expand All @@ -151,7 +145,7 @@ void RenderPolyScene::RenderSubsector(PolyRenderThread *thread, subsector_t *sub
for (int i = ParticlesInSubsec[subsectorIndex]; i != NO_PARTICLE; i = Particles[i].snext)
{
particle_t *particle = Particles + i;
thread->TranslucentObjects.push_back(thread->FrameMemory->NewObject<PolyTranslucentParticle>(particle, sub, subsectorDepth, StencilValue));
TranslucentObjects[thread->ThreadIndex].push_back(thread->FrameMemory->NewObject<PolyTranslucentParticle>(particle, sub, subsectorDepth, StencilValue));
}
}
}
Expand Down Expand Up @@ -204,7 +198,7 @@ void RenderPolyScene::RenderPolySubsector(PolyRenderThread *thread, subsector_t
sub->flags |= SSECF_DRAWN;
}

RenderPolyWall::RenderLine(thread, WorldToClip, PortalPlane, line, frontsector, subsectorDepth, StencilValue, thread->TranslucentObjects, thread->LinePortals, LastPortalLine);
RenderPolyWall::RenderLine(thread, WorldToClip, PortalPlane, line, frontsector, subsectorDepth, StencilValue, TranslucentObjects[thread->ThreadIndex], LinePortals, LastPortalLine);
}
}
}
Expand All @@ -221,7 +215,7 @@ void RenderPolyScene::RenderSprite(PolyRenderThread *thread, AActor *thing, doub
subsector_t *sub = &level.subsectors[0];
auto it = Cull.SubsectorDepths.find(sub);
if (it != Cull.SubsectorDepths.end())
thread->TranslucentObjects.push_back(thread->FrameMemory->NewObject<PolyTranslucentThing>(thing, sub, it->second, sortDistance, 0.0f, 1.0f, StencilValue));
TranslucentObjects[thread->ThreadIndex].push_back(thread->FrameMemory->NewObject<PolyTranslucentThing>(thing, sub, it->second, sortDistance, 0.0f, 1.0f, StencilValue));
}
else
{
Expand Down Expand Up @@ -262,7 +256,7 @@ void RenderPolyScene::RenderSprite(PolyRenderThread *thread, AActor *thing, doub

auto it = Cull.SubsectorDepths.find(sub);
if (it != Cull.SubsectorDepths.end())
thread->TranslucentObjects.push_back(thread->FrameMemory->NewObject<PolyTranslucentThing>(thing, sub, it->second, sortDistance, (float)t1, (float)t2, StencilValue));
TranslucentObjects[thread->ThreadIndex].push_back(thread->FrameMemory->NewObject<PolyTranslucentThing>(thing, sub, it->second, sortDistance, (float)t1, (float)t2, StencilValue));
}

void RenderPolyScene::RenderLine(PolyRenderThread *thread, subsector_t *sub, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth)
Expand All @@ -280,12 +274,12 @@ void RenderPolyScene::RenderLine(PolyRenderThread *thread, subsector_t *sub, seg
for (unsigned int i = 0; i < line->backsector->e->XFloor.ffloors.Size(); i++)
{
F3DFloor *fakeFloor = line->backsector->e->XFloor.ffloors[i];
RenderPolyWall::Render3DFloorLine(thread, WorldToClip, PortalPlane, line, frontsector, subsectorDepth, StencilValue, fakeFloor, thread->TranslucentObjects);
RenderPolyWall::Render3DFloorLine(thread, WorldToClip, PortalPlane, line, frontsector, subsectorDepth, StencilValue, fakeFloor, TranslucentObjects[thread->ThreadIndex]);
}
}

// Render wall, and update culling info if its an occlusion blocker
RenderPolyWall::RenderLine(thread, WorldToClip, PortalPlane, line, frontsector, subsectorDepth, StencilValue, thread->TranslucentObjects, thread->LinePortals, LastPortalLine);
RenderPolyWall::RenderLine(thread, WorldToClip, PortalPlane, line, frontsector, subsectorDepth, StencilValue, TranslucentObjects[thread->ThreadIndex], LinePortals, LastPortalLine);
}

void RenderPolyScene::RenderPortals(int portalDepth)
Expand All @@ -295,10 +289,10 @@ void RenderPolyScene::RenderPortals(int portalDepth)
bool foggy = false;
if (portalDepth < r_portal_recursions)
{
for (auto &portal : thread->SectorPortals)
for (auto &portal : SectorPortals)
portal->Render(portalDepth + 1);

for (auto &portal : thread->LinePortals)
for (auto &portal : LinePortals)
portal->Render(portalDepth + 1);
}
else // Fill with black
Expand All @@ -310,7 +304,7 @@ void RenderPolyScene::RenderPortals(int portalDepth)
args.SetClipPlane(0, PortalPlane);
args.SetStyle(TriBlendMode::FillOpaque);

for (auto &portal : thread->SectorPortals)
for (auto &portal : SectorPortals)
{
args.SetStencilTestValue(portal->StencilValue);
args.SetWriteStencil(true, portal->StencilValue + 1);
Expand All @@ -321,7 +315,7 @@ void RenderPolyScene::RenderPortals(int portalDepth)
}
}

for (auto &portal : thread->LinePortals)
for (auto &portal : LinePortals)
{
args.SetStencilTestValue(portal->StencilValue);
args.SetWriteStencil(true, portal->StencilValue + 1);
Expand All @@ -340,7 +334,7 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)

if (portalDepth < r_portal_recursions)
{
for (auto it = thread->SectorPortals.rbegin(); it != thread->SectorPortals.rend(); ++it)
for (auto it = SectorPortals.rbegin(); it != SectorPortals.rend(); ++it)
{
auto &portal = *it;
portal->RenderTranslucent(portalDepth + 1);
Expand All @@ -358,7 +352,7 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
}
}

for (auto it = thread->LinePortals.rbegin(); it != thread->LinePortals.rend(); ++it)
for (auto it = LinePortals.rbegin(); it != LinePortals.rend(); ++it)
{
auto &portal = *it;
portal->RenderTranslucent(portalDepth + 1);
Expand Down Expand Up @@ -390,14 +384,14 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
}
}

std::stable_sort(thread->TranslucentObjects.begin(), thread->TranslucentObjects.end(), [](auto a, auto b) { return *a < *b; });
std::stable_sort(TranslucentObjects[0].begin(), TranslucentObjects[0].end(), [](auto a, auto b) { return *a < *b; });

for (auto it = thread->TranslucentObjects.rbegin(); it != thread->TranslucentObjects.rend(); ++it)
for (auto it = TranslucentObjects[0].rbegin(); it != TranslucentObjects[0].rend(); ++it)
{
PolyTranslucentObject *obj = *it;
obj->Render(thread, WorldToClip, PortalPlane);
obj->~PolyTranslucentObject();
}

thread->TranslucentObjects.clear();
TranslucentObjects[0].clear();
}
5 changes: 4 additions & 1 deletion src/polyrenderer/scene/poly_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class RenderPolyScene
line_t *LastPortalLine = nullptr;

private:
void ClearBuffers(PolyRenderThread *thread);
void RenderPortals(int portalDepth);
void RenderSectors();
void RenderSubsector(PolyRenderThread *thread, subsector_t *sub, uint32_t subsectorDepth);
Expand All @@ -85,4 +84,8 @@ class RenderPolyScene
uint32_t StencilValue = 0;
PolyCull Cull;
bool PortalSegmentsAdded = false;

std::vector<std::vector<PolyTranslucentObject *>> TranslucentObjects;
std::vector<std::unique_ptr<PolyDrawSectorPortal>> SectorPortals;
std::vector<std::unique_ptr<PolyDrawLinePortal>> LinePortals;
};
3 changes: 3 additions & 0 deletions src/polyrenderer/scene/poly_wall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ void RenderPolyWall::Render3DFloorLine(PolyRenderThread *thread, const TriMatrix
double topTexZ = fakeFloor->model->GetPlaneTexZ(sector_t::ceiling);
double bottomTexZ = fakeFloor->model->GetPlaneTexZ(sector_t::floor);

if (frontceilz1 <= frontfloorz1 || frontceilz2 <= frontfloorz2)
return;

RenderPolyWall wall;
wall.LineSeg = line;
wall.LineSegLine = line->linedef;
Expand Down
5 changes: 2 additions & 3 deletions wadsrc/static/zscript/statscreen/statscreen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class StatusScreen abstract play version("2.5")
CurState = ShowNextLoc;
acceleratestage = 0;
cnt = SHOWNEXTLOCDELAY * Thinker.TICRATE;
bg.LoadBackground(true);
noautostartmap = bg.LoadBackground(true);
}

//====================================================================
Expand Down Expand Up @@ -693,7 +693,6 @@ class StatusScreen abstract play version("2.5")

virtual void Start (wbstartstruct wbstartstruct)
{
noautostartmap = false;
wbs = wbstartstruct;
acceleratestage = 0;
cnt = bcnt = 0;
Expand All @@ -717,7 +716,7 @@ class StatusScreen abstract play version("2.5")
lnametexts[1] = wbstartstruct.nextname;

bg = InterBackground.Create(wbs);
bg.LoadBackground(false);
noautostartmap = bg.LoadBackground(false);
initStats();
}

Expand Down

0 comments on commit 69b8575

Please sign in to comment.