qbsp: replace `-nothreads` with `-threads 1` for consistency with light/vis

This commit is contained in:
Eric Wasylishen 2022-01-30 17:44:48 -07:00
parent e0981b356b
commit 8531286777
5 changed files with 38 additions and 10 deletions

View File

@ -25,4 +25,4 @@ add_library(common STATIC
${CMAKE_SOURCE_DIR}/include/common/fs.hh
${CMAKE_SOURCE_DIR}/include/common/imglib.hh)
target_link_libraries(common ${CMAKE_THREAD_LIBS_INIT} fmt::fmt nlohmann_json::nlohmann_json)
target_link_libraries(common ${CMAKE_THREAD_LIBS_INIT} TBB::tbb fmt::fmt nlohmann_json::nlohmann_json)

View File

@ -169,3 +169,20 @@ void RunThreadsOn(int start, int workcnt, void *(func)(void *), void *arg)
}
#endif /* HAVE_THREADS */
/*
* =======================================================================
* TBB
* =======================================================================
*/
std::unique_ptr<tbb::global_control> ConfigureTBB(int maxthreads)
{
auto tbbOptions = std::unique_ptr<tbb::global_control>();
if (maxthreads > 0) {
tbbOptions = std::make_unique<tbb::global_control>(tbb::global_control::max_allowed_parallelism, maxthreads);
}
return tbbOptions;
}

View File

@ -2,6 +2,10 @@
#pragma once
#include <memory>
#include "tbb/global_control.h"
extern int numthreads;
void LowerProcessPriority(void);
@ -15,3 +19,10 @@ void ThreadUnlock(void);
/* Call if needing to print to stdout - should be called with lock held */
void InterruptThreadProgress__(void);
/**
* Configures TBB to have the given max threads (specify 0 for unlimited).
*
* Call this from main() and keep the returned object until main() finishes.
*/
std::unique_ptr<tbb::global_control> ConfigureTBB(int maxthreads);

View File

@ -117,7 +117,7 @@ public:
bool fLeakTest = false;
bool fContentHack = false;
vec_t worldExtent = 0.f;
bool fNoThreads = false;
int threads = 0; // 0 = let TBB auto select ideal number of threads
bool includeSkip = false;
bool fNoTJunc = false;
};

View File

@ -26,6 +26,7 @@
#include <common/log.hh>
#include <common/aabb.hh>
#include <common/fs.hh>
#include <common/threads.hh>
#include <qbsp/qbsp.hh>
#include <qbsp/wad.hh>
#include <fmt/chrono.h>
@ -1059,7 +1060,7 @@ PrintOptions
" -expand Write hull 1 expanded brushes to expanded.map for debugging\n"
" -leaktest Make compilation fail if the map leaks\n"
" -contenthack Hack to fix leaks through solids. Causes missing faces in some cases so disabled by default.\n"
" -nothreads Disable multithreading\n"
" -threads n Set the number of threads (1 to disable multithreading)\n"
" sourcefile .MAP file to process\n"
" destfile .BSP file to output\n");
@ -1295,8 +1296,11 @@ static void ParseOptions(char *szOptions)
options.fLeakTest = true;
} else if (!Q_strcasecmp(szTok, "contenthack")) {
options.fContentHack = true;
} else if (!Q_strcasecmp(szTok, "nothreads")) {
options.fNoThreads = true;
} else if (!Q_strcasecmp(szTok, "threads")) {
szTok2 = GetTok(szTok + strlen(szTok) + 1, szEnd);
if (!szTok2)
FError("Invalid argument to option {}", szTok);
options.threads = atoi(szTok2);
} else if (!Q_strcasecmp(szTok, "?") || !Q_strcasecmp(szTok, "help")) {
PrintOptions();
} else {
@ -1421,11 +1425,7 @@ int qbsp_main(int argc, const char **argv)
InitQBSP(argc, argv);
// disable TBB if requested
auto tbbOptions = std::unique_ptr<tbb::global_control>();
if (options.fNoThreads) {
tbbOptions = std::make_unique<tbb::global_control>(tbb::global_control::max_allowed_parallelism, 1);
}
auto tbbOptions = ConfigureTBB(options.threads);
// do it!
auto start = I_FloatTime();