Skip to content

Commit 75eb743

Browse files
committed
GPU Display: Fix several minor issues
1 parent 8be4de9 commit 75eb743

12 files changed

Lines changed: 109 additions & 87 deletions

‎GPU/GPUTracking/Definitions/GPUSettingsListDisplay.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ AddOption(camYUp, bool, false, "", 0, "Orient the camera such that the y-axis is
9393
AddOption(cameraMode, int32_t, 0, "", 0, "Camera mode", min(0), max(3))
9494
AddOption(fullScreen, bool, false, "", 0, "Full Screen")
9595
AddOption(maximized, bool, true, "", 0, "Maximized window")
96-
AddOption(drawQualityMSAA, int32_t, 0, "", 0, "MultiSample Anti Aliasing", min(0), max(8))
96+
AddOption(drawQualityMSAA, int32_t, 0, "", 0, "MultiSample Anti Aliasing", min(0), max(16))
9797
AddOption(drawQualityDownsampleFSAA, int32_t, 0, "", 0, "Downsampling Anti Aliasing", min(0), max(4))
9898
AddOption(drawQualityVSync, bool, true, "", 0, "Enable Vertical Sync")
9999
AddOption(fpsLimit, int32_t, 1, "", 0, "FPS limit: 0 = none (maximum rate), 1 = display refresh rate (no limit without VSync), 2 = fpsRate")

‎GPU/GPUTracking/display/frontend/GPUDisplayConsole.cxx‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ struct consoleArgumentError : public std::runtime_error { // Wrong arguments for
3232
{
3333
static constexpr std::pair<char, const char*> names[] = {{'s', "string"}, {'i', "int"}, {'d', "double"}, {'a', "any"}, {'+', "[optional]"}};
3434
for (char t : types) {
35-
for (const auto& [c, name] : names) {
36-
usage += c == t ? std::string(usage.size() > 1 ? " " : "") + name : "";
35+
if (const auto* n = std::find_if(std::begin(names), std::end(names), [t](const auto& entry) { return entry.first == t; }); n != std::end(names)) {
36+
usage += (usage.size() > 1 ? " " : "") + std::string(n->second);
3737
}
3838
}
3939
usage += "]";
@@ -154,11 +154,13 @@ void GPUDisplayConsole::consoleLimitHistory(uint32_t historySize)
154154
const size_t removed = mConsoleHistory.size() - size;
155155
std::move(mConsoleHistory.begin() + 1 + removed, mConsoleHistory.end(), mConsoleHistory.begin() + 1); // Keep the title (entry 0)
156156
mConsoleHistory.resize(size);
157-
mConsoleTextCurrent = mConsoleTextCurrent > removed ? mConsoleTextCurrent - removed : 0;
157+
mConsoleTextCurrent = mConsoleTextCurrent > removed ? mConsoleTextCurrent - removed : 0; // Same entry, the end if it was removed
158+
mConsoleTextPos = std::min<uint32_t>(mConsoleTextPos, shownText().size());
159+
mScroll = mScroll + 1 >= size ? 0 : mScroll; // Counted from the end: same lines, the end if the lowest shown one was removed
158160
}
159161

160162
// Tokens separated by spaces: text in single / double quotes and characters after a backslash are plain text (the token is a string),
161-
// otherwise a token is int64_t for [+-]digits, double for [+-]digits with one '.', a string otherwise. Throws std::runtime_error for an unterminated quote / trailing backslash.
163+
// otherwise a token is int64_t for [+-]digits, double for other decimal numbers (also with exponent), a string otherwise. Throws std::runtime_error for an unterminated quote / trailing backslash.
162164

163165
std::tuple<const GPUDisplayConsole::GPUDisplayConsoleCommand&, std::vector<GPUDisplayConsole::consoleArg>> GPUDisplayConsole::parseConsoleCommand(std::string_view cmd) const
164166
{
@@ -217,11 +219,14 @@ std::tuple<const GPUDisplayConsole::GPUDisplayConsoleCommand&, std::vector<GPUDi
217219
auto autoType = [](const std::string& text, bool plain) -> consoleArg { // int64_t for [+-]digits, double for other decimal numbers (also with exponent, as saveSettings writes them), string otherwise or if plain text
218220
const char *begin = text.c_str() + (text[0] == '+' || text[0] == '-'), *end = text.c_str() + text.size();
219221
const bool number = !plain && begin < end && ((*begin >= '0' && *begin <= '9') || *begin == '.') && std::all_of(begin, end, [](char c) { return (c >= '0' && c <= '9') || c == '.' || c == 'e' || c == 'E' || c == '+' || c == '-'; });
222+
if (!number) {
223+
return text;
224+
}
220225
int64_t intValue = 0;
221226
double doubleValue = 0.;
222-
if (const auto rInt = std::from_chars(begin, end, intValue); number && rInt.ec == std::errc() && rInt.ptr == end) {
227+
if (const auto rInt = std::from_chars(begin, end, intValue); rInt.ec == std::errc() && rInt.ptr == end) {
223228
return text[0] == '-' ? -intValue : intValue;
224-
} else if (const auto rDouble = std::from_chars(begin, end, doubleValue); number && rDouble.ec == std::errc() && rDouble.ptr == end) {
229+
} else if (const auto rDouble = std::from_chars(begin, end, doubleValue); rDouble.ec == std::errc() && rDouble.ptr == end) {
225230
return text[0] == '-' ? -doubleValue : doubleValue; // Also integers out of the int64_t range
226231
}
227232
return text;
@@ -332,16 +337,15 @@ void GPUDisplayConsole::runScriptFile(const std::string& filename)
332337
runScript(content.str());
333338
}
334339

335-
void GPUDisplayConsole::printCommands(const std::function<void(const std::string&)>& print)
340+
void GPUDisplayConsole::printCommands(const std::function<void(const std::string&)>& print) const
336341
{
337-
std::vector<std::string> names;
338-
for (const auto& [name, command] : mConsoleCommands) {
339-
names.emplace_back(name);
342+
std::vector<const std::pair<const std::string, GPUDisplayConsoleCommand>*> commands;
343+
for (const auto& entry : mConsoleCommands) {
344+
commands.emplace_back(&entry);
340345
}
341-
std::sort(names.begin(), names.end());
346+
std::sort(commands.begin(), commands.end(), [](const auto* a, const auto* b) { return a->first < b->first; });
342347
print("Console commands (argument types: s string, i integer, d number, a any, + further arguments):");
343-
for (const auto& name : names) {
344-
const auto& command = mConsoleCommands[name];
345-
print(" " + name + (command.args.empty() ? "" : " ") + command.args + ": " + command.description);
348+
for (const auto* c : commands) {
349+
print(" " + c->first + (c->second.args.empty() ? "" : " ") + c->second.args + ": " + c->second.description);
346350
}
347351
}

‎GPU/GPUTracking/display/frontend/GPUDisplayConsole.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class GPUDisplayConsole : public GPUDisplayFrontendKeyVars // Text console of th
5151
void waitSeconds(double t) { mWaitUntil = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(t)); }
5252
void waitFor(std::function<bool()> condition) { mWaitCondition = std::move(condition); } // The following script lines run once the condition is true
5353
void startBenchmark(uint32_t n); // Measures the next n frames, the following script lines run afterwards
54-
void printCommands(const std::function<void(const std::string&)>& print); // List of the commands with argument types and description, one line per call
54+
void printCommands(const std::function<void(const std::string&)>& print) const; // List of the commands with argument types and description, one line per call
5555
std::tuple<const GPUDisplayConsoleCommand&, std::vector<consoleArg>> parseConsoleCommand(std::string_view cmd) const; // Command and its arguments with the types it requests, throws std::runtime_error for syntax errors, unknown commands, wrong arguments
5656
void consolePrint(const char* format, ...); // printf-like output to the console, indented by 2 spaces in mConsoleHistory
5757
void consoleInfo(const char* format, const char* text); // Output of SetInfo, updates the last line instead for the same message within 2 s

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontend.cxx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ void GPUDisplayFrontend::FrontendThreadWrapper()
7777
GPUError("Error in display frontend: %s", e.what());
7878
retVal = -1;
7979
}
80+
std::unique_lock lock(mExitStateMutex);
81+
mDisplayRunning = false; // Also after an error / exception in the main loop, StopDisplay waits for it
82+
mDisplayStoppedCV.notify_all();
8083
if (retVal) {
81-
std::unique_lock lock(mExitStateMutex);
8284
if (mDisplay->mInitResult == 0) { // Failed before InitDisplay was called, report failure to StartDisplay(), which otherwise waits forever
8385
lock.unlock();
8486
InitDisplay(true);

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendConfig.cxx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ void GPUDisplay::checkAndApplyConfigChanges()
232232
if (oldCfgR.drawQualityMSAA != mCfgR.drawQualityMSAA || oldCfgR.drawQualityDownsampleFSAA != mCfgR.drawQualityDownsampleFSAA || oldCfgL.depthBuffer != mCfgL.depthBuffer || oldCfgR.screenshotScaleFactor != mCfgR.screenshotScaleFactor) {
233233
mUpdateRenderPipeline = true;
234234
}
235+
if (oldCfgL.depthBuffer != mCfgL.depthBuffer) { // Also for set / scripts, not only key and GUI
236+
mBackend->setDepthBuffer();
237+
}
235238

236239
if (oldCfgR.drawQualityVSync != mCfgR.drawQualityVSync) {
237240
mFrontend->SetVSync(mCfgR.drawQualityVSync);

0 commit comments

Comments
 (0)