qbsp: fix some threading issues with solidbsp.cc stats

This commit is contained in:
Eric Wasylishen 2021-08-22 23:55:10 -06:00
parent a53cf8dbbe
commit 29652b4a7a
5 changed files with 37 additions and 21 deletions

View File

@ -22,7 +22,9 @@
#ifndef QBSP_SOLIDBSP_HH
#define QBSP_SOLIDBSP_HH
extern int splitnodes;
#include <atomic>
extern std::atomic<int> splitnodes;
void DetailToSolid(node_t *node);
int Contents_Priority(int contents);

View File

@ -667,7 +667,7 @@ CutNodePortals_r(node_t *node, portal_state_t *state)
/* Display progress */
state->iNodesDone++;
Message(msgPercent, state->iNodesDone, splitnodes);
Message(msgPercent, state->iNodesDone, splitnodes.load());
CutNodePortals_r(front, state);
CutNodePortals_r(back, state);

View File

@ -23,14 +23,16 @@
#include <qbsp/qbsp.hh>
#include <atomic>
#include "tbb/task_group.h"
int splitnodes;
std::atomic<int> splitnodes;
static int leaffaces;
static int nodefaces;
static int c_solid, c_empty, c_water, c_detail, c_detail_illusionary, c_detail_fence;
static int c_illusionary_visblocker;
static std::atomic<int> leaffaces;
static std::atomic<int> nodefaces;
static std::atomic<int> c_solid, c_empty, c_water, c_detail, c_detail_illusionary, c_detail_fence;
static std::atomic<int> c_illusionary_visblocker;
static bool usemidsplit;
/**
@ -462,6 +464,8 @@ SelectPartition
Selects a surface from a linked list of surfaces to split the group on
returns NULL if the surface list can not be divided any more (a leaf)
Called in parallel.
==================
*/
static surface_t *
@ -782,7 +786,9 @@ int Contents_Priority(int contents)
LinkConvexFaces
Determines the contents of the leaf and creates the final list of
original faces that have some fragment inside this leaf
original faces that have some fragment inside this leaf.
Called in parallel.
==================
*/
static void
@ -879,7 +885,9 @@ First subdivides surface->faces.
Then, duplicates the list of subdivided faces and returns it.
For each surface->faces, ->original is set to the respective duplicate that
is returned here (why?)
is returned here (why?).
Called in parallel.
==================
*/
static face_t *
@ -913,6 +921,8 @@ LinkNodeFaces(surface_t *surface)
/*
==================
PartitionSurfaces
Called in parallel.
==================
*/
static void
@ -929,7 +939,7 @@ PartitionSurfaces(surface_t *surfaces, node_t *node)
}
splitnodes++;
Message(msgPercent, splitnodes, csgmergefaces);
Message(msgPercent, splitnodes.load(), csgmergefaces);
node->faces = LinkNodeFaces(split);
node->children[0] = (node_t *)AllocMem(NODE, 1, true);
@ -1041,16 +1051,16 @@ SolidBSP(const mapentity_t *entity, surface_t *surfhead, bool midsplit)
PartitionSurfaces(surfhead, headnode);
Message(msgStat, "%8d split nodes", splitnodes);
Message(msgStat, "%8d solid leafs", c_solid);
Message(msgStat, "%8d empty leafs", c_empty);
Message(msgStat, "%8d water leafs", c_water);
Message(msgStat, "%8d detail leafs", c_detail);
Message(msgStat, "%8d detail illusionary leafs", c_detail_illusionary);
Message(msgStat, "%8d detail fence leafs", c_detail_fence);
Message(msgStat, "%8d illusionary visblocker leafs", c_illusionary_visblocker);
Message(msgStat, "%8d leaffaces", leaffaces);
Message(msgStat, "%8d nodefaces", nodefaces);
Message(msgStat, "%8d split nodes", splitnodes.load());
Message(msgStat, "%8d solid leafs", c_solid.load());
Message(msgStat, "%8d empty leafs", c_empty.load());
Message(msgStat, "%8d water leafs", c_water.load());
Message(msgStat, "%8d detail leafs", c_detail.load());
Message(msgStat, "%8d detail illusionary leafs", c_detail_illusionary.load());
Message(msgStat, "%8d detail fence leafs", c_detail_fence.load());
Message(msgStat, "%8d illusionary visblocker leafs", c_illusionary_visblocker.load());
Message(msgStat, "%8d leaffaces", leaffaces.load());
Message(msgStat, "%8d nodefaces", nodefaces.load());
return headnode;
}

View File

@ -409,7 +409,7 @@ MakeFaceEdges_r(mapentity_t *entity, node_t *node, int progress)
FindFaceEdges(entity, f);
}
Message(msgPercent, ++progress, splitnodes);
Message(msgPercent, ++progress, splitnodes.load());
progress = MakeFaceEdges_r(entity, node->children[0], progress);
progress = MakeFaceEdges_r(entity, node->children[1], progress);

View File

@ -206,6 +206,8 @@ FreeAllMem(void)
/* Keep track of output state */
static bool fInPercent = false;
std::mutex messageLock;
/*
=================
Message
@ -216,6 +218,8 @@ Generic output of warnings, stats, etc
void
Message(int msgType, ...)
{
std::unique_lock<std::mutex> lck { messageLock };
va_list argptr;
char szBuffer[512];
char *szFmt;