From f8a067b709c0d0f85dd7cd1a1693228e59b8f5d8 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 29 Aug 2024 16:04:56 +0100 Subject: [PATCH] Return settings by value with temporaries * This is slightly less efficient but this isn't high-performance code, and it makes settings like shader debug SearchDirPaths safe to access on multiple threads. --- renderdoc/core/settings.cpp | 20 ++++++++------------ renderdoc/core/settings.h | 11 +++++------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/renderdoc/core/settings.cpp b/renderdoc/core/settings.cpp index e7a11d920..cb61b2aa8 100644 --- a/renderdoc/core/settings.cpp +++ b/renderdoc/core/settings.cpp @@ -367,29 +367,24 @@ static bool MergeConfigValues(const rdcstr &prefix, SDObject *dstConfig, const S return ret; } -const bool &ConfigVarRegistration::value() +bool ConfigVarRegistration::value() const { - // avoid warnings on stupid compilers - (void)tmp; return obj->data.basic.b; } -const uint64_t &ConfigVarRegistration::value() +uint64_t ConfigVarRegistration::value() const { - (void)tmp; return obj->data.basic.u; } -const uint32_t &ConfigVarRegistration::value() +uint32_t ConfigVarRegistration::value() const { - tmp = obj->data.basic.u & 0xFFFFFFFFU; - return tmp; + return obj->data.basic.u & 0xFFFFFFFFU; } -const rdcstr &ConfigVarRegistration::value() +rdcstr ConfigVarRegistration::value() const { - tmp = obj->data.str; - return tmp; + return obj->data.str; } template @@ -399,8 +394,9 @@ rdcstr DefValString(const T &el) } // this one needs a special implementation unfortunately to convert -const rdcarray &ConfigVarRegistration>::value() +rdcarray ConfigVarRegistration>::value() const { + rdcarray tmp; tmp.resize(obj->NumChildren()); for(size_t i = 0; i < tmp.size(); i++) tmp[i] = obj->GetChild(i)->data.str; diff --git a/renderdoc/core/settings.h b/renderdoc/core/settings.h index 34faff435..3b2e2ec5c 100644 --- a/renderdoc/core/settings.h +++ b/renderdoc/core/settings.h @@ -40,11 +40,10 @@ struct ConfigVarRegistration; { \ ConfigVarRegistration(rdcliteral name, const T &defaultValue, bool debugOnly, \ rdcliteral description); \ - const T &value(); \ + T value() const; \ \ private: \ SDObject *obj; \ - T tmp; \ }; CONFIG_SUPPORT_TYPE(rdcstr); @@ -58,11 +57,11 @@ CONFIG_SUPPORT_TYPE(rdcarray); #define RDOC_CONFIG(type, name, defaultValue, description) \ static ConfigVarRegistration CONCAT(config, __LINE__)( \ STRING_LITERAL(STRINGIZE(name)), defaultValue, false, STRING_LITERAL(description)); \ - const type &name() \ + type name() \ { \ return CONCAT(config, __LINE__).value(); \ } -#define RDOC_EXTERN_CONFIG(type, name) extern const type &name(); +#define RDOC_EXTERN_CONFIG(type, name) extern type name(); // debug configs get set to constants in official stable builds, they will remain configurable // in nightly builds and of course in development builds @@ -71,7 +70,7 @@ CONFIG_SUPPORT_TYPE(rdcarray); #define RDOC_DEBUG_CONFIG(type, name, defaultValue, description) \ static ConfigVarRegistration CONCAT(config, __LINE__)( \ STRING_LITERAL(STRINGIZE(name)), defaultValue, true, STRING_LITERAL(description)); \ - const type &name() \ + type name() \ { \ static const type ret = defaultValue; \ return ret; \ @@ -81,7 +80,7 @@ CONFIG_SUPPORT_TYPE(rdcarray); #define RDOC_DEBUG_CONFIG(type, name, defaultValue, description) \ static ConfigVarRegistration CONCAT(config, __LINE__)( \ STRING_LITERAL(STRINGIZE(name)), defaultValue, true, STRING_LITERAL(description)); \ - const type &name() \ + type name() \ { \ return CONCAT(config, __LINE__).value(); \ }