From 047eb16f4c8fdfb1826136db9ee2eed83cb95416 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 10 Sep 2024 23:07:07 +0300 Subject: viewer#2529 Optimize updateGLVariablesForSettings Intent is to eventually use only stored variables for everything. LLSD operations are far too expensive. --- indra/llinventory/llsettingsbase.h | 109 +++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 48 deletions(-) (limited to 'indra/llinventory/llsettingsbase.h') diff --git a/indra/llinventory/llsettingsbase.h b/indra/llinventory/llsettingsbase.h index 9d8d746b7e..c2867f32d9 100644 --- a/indra/llinventory/llsettingsbase.h +++ b/indra/llinventory/llsettingsbase.h @@ -110,71 +110,55 @@ public: virtual bool isVeryDirty() const { return mReplaced; } inline void setDirtyFlag(bool dirty) { mDirty = dirty; clearAssetId(); } - size_t getHash() const; // Hash will not include Name, ID or a previously stored Hash + size_t getHash(); // Hash will not include Name, ID or a previously stored Hash inline LLUUID getId() const { - return getValue(SETTING_ID).asUUID(); + return mSettingId; } inline std::string getName() const { - return getValue(SETTING_NAME).asString(); + return mSettingName; } inline void setName(std::string val) { - setValue(SETTING_NAME, val); + mSettingName = val; + setLLSDDirty(); } inline LLUUID getAssetId() const { - if (mSettings.has(SETTING_ASSETID)) - return mSettings[SETTING_ASSETID].asUUID(); - return LLUUID(); + return mAssetId; } inline U32 getFlags() const { - if (mSettings.has(SETTING_FLAGS)) - return static_cast(mSettings[SETTING_FLAGS].asInteger()); - return 0; + return mSettingFlags; } inline void setFlags(U32 value) { - setLLSD(SETTING_FLAGS, LLSD::Integer(value)); + mSettingFlags = value; + setLLSDDirty(); } inline bool getFlag(U32 flag) const { - if (mSettings.has(SETTING_FLAGS)) - return ((U32)mSettings[SETTING_FLAGS].asInteger() & flag) == flag; - return false; + return (mSettingFlags & flag) == flag; } inline void setFlag(U32 flag) { - U32 flags((mSettings.has(SETTING_FLAGS)) ? (U32)mSettings[SETTING_FLAGS].asInteger() : 0); - - flags |= flag; - - if (flags) - mSettings[SETTING_FLAGS] = LLSD::Integer(flags); - else - mSettings.erase(SETTING_FLAGS); + mSettingFlags |= flag; + setLLSDDirty(); } inline void clearFlag(U32 flag) { - U32 flags((mSettings.has(SETTING_FLAGS)) ? (U32)mSettings[SETTING_FLAGS].asInteger() : 0); - - flags &= ~flag; - - if (flags) - mSettings[SETTING_FLAGS] = LLSD::Integer(flags); - else - mSettings.erase(SETTING_FLAGS); + mSettingFlags &= ~flag; + setLLSDDirty(); } virtual void replaceSettings(LLSD settings) @@ -183,14 +167,31 @@ public: setDirtyFlag(true); mReplaced = true; mSettings = settings; + loadValuesFromLLSD(); + } + + void setSettings(LLSD settings) + { + setDirtyFlag(true); + mSettings = settings; + loadValuesFromLLSD(); } - virtual LLSD getSettings() const; + // if you are using getSettings to edit them, call setSettings(settings), + // replaceSettings(settings) or loadValuesFromLLSD() afterwards + virtual LLSD& getSettings(); + virtual void setLLSDDirty() + { + mLLSDDirty = true; + mDirty = true; + clearAssetId(); + } //--------------------------------------------------------------------- // inline void setLLSD(const std::string &name, const LLSD &value) { + saveValuesIfNeeded(); mSettings[name] = value; mDirty = true; if (name != SETTING_ASSETID) @@ -202,8 +203,9 @@ public: setLLSD(name, value); } - inline LLSD getValue(const std::string &name, const LLSD &deflt = LLSD()) const + inline LLSD getValue(const std::string &name, const LLSD &deflt = LLSD()) { + saveValuesIfNeeded(); if (!mSettings.has(name)) return deflt; return mSettings[name]; @@ -259,11 +261,11 @@ public: (const_cast(this))->updateSettings(); } - virtual void blend(const ptr_t &end, BlendFactor blendf) = 0; + virtual void blend(ptr_t &end, BlendFactor blendf) = 0; virtual bool validate(); - virtual ptr_t buildDerivedClone() const = 0; + virtual ptr_t buildDerivedClone() = 0; class Validator { @@ -310,17 +312,20 @@ public: inline void setAssetId(LLUUID value) { // note that this skips setLLSD - mSettings[SETTING_ASSETID] = value; + mAssetId = value; + mLLSDDirty = true; } inline void clearAssetId() { - if (mSettings.has(SETTING_ASSETID)) - mSettings.erase(SETTING_ASSETID); + mAssetId.setNull(); + mLLSDDirty = true; } // Calculate any custom settings that may need to be cached. virtual void updateSettings() { mDirty = false; mReplaced = false; } + LLSD cloneSettings(); + protected: LLSettingsBase(); @@ -331,7 +336,7 @@ protected: typedef std::set stringset_t; // combining settings objects. Customize for specific setting types - virtual void lerpSettings(const LLSettingsBase &other, BlendFactor mix); + virtual void lerpSettings(LLSettingsBase &other, BlendFactor mix); // combining settings maps where it can based on mix rate // @settings initial value (mix==0) @@ -339,8 +344,8 @@ protected: // @defaults list of default values for legacy fields and (re)setting shaders // @mix from 0 to 1, ratio or rate of transition from initial 'settings' to 'other' // return interpolated and combined LLSD map - LLSD interpolateSDMap(const LLSD &settings, const LLSD &other, const parammapping_t& defaults, BlendFactor mix) const; - LLSD interpolateSDValue(const std::string& name, const LLSD &value, const LLSD &other, const parammapping_t& defaults, BlendFactor mix, const stringset_t& slerps) const; + static LLSD interpolateSDMap(const LLSD &settings, const LLSD &other, const parammapping_t& defaults, BlendFactor mix, const stringset_t& skip, const stringset_t& slerps); + static LLSD interpolateSDValue(const std::string& name, const LLSD &value, const LLSD &other, const parammapping_t& defaults, BlendFactor mix, const stringset_t& skip, const stringset_t& slerps); /// when lerping between settings, some may require special handling. /// Get a list of these key to be skipped by the default settings lerp. @@ -353,32 +358,40 @@ protected: virtual validation_list_t getValidationList() const = 0; - // Apply any settings that need special handling. - virtual void applySpecial(void *, bool force = false) { }; + // Apply settings. + virtual void applyToUniforms(void *) { }; + virtual void applySpecial(void*, bool force = false) { }; virtual parammapping_t getParameterMap() const { return parammapping_t(); } - LLSD mSettings; - - LLSD cloneSettings() const; - inline void setBlendFactor(BlendFactor blendfactor) { mBlendedFactor = blendfactor; } - void replaceWith(LLSettingsBase::ptr_t other) + virtual void replaceWith(LLSettingsBase::ptr_t other) { replaceSettings(other->cloneSettings()); setBlendFactor(other->getBlendFactor()); } + virtual void loadValuesFromLLSD(); + virtual void saveValuesToLLSD(); + void saveValuesIfNeeded(); + + LLUUID mAssetId; + LLUUID mSettingId; + std::string mSettingName; + U32 mSettingFlags; + private: + bool mLLSDDirty; bool mDirty; bool mReplaced; // super dirty! - LLSD combineSDMaps(const LLSD &first, const LLSD &other) const; + static LLSD combineSDMaps(const LLSD &first, const LLSD &other); + LLSD mSettings; BlendFactor mBlendedFactor; }; -- cgit v1.2.3 From 0a110ff0833216b167e032987b0d676f29ad0ee5 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 11 Sep 2024 18:21:03 +0300 Subject: viewer#2529 Track interpolateSDMap's performance viewer#2529 Fix initialization --- indra/llinventory/llsettingsbase.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llinventory/llsettingsbase.h') diff --git a/indra/llinventory/llsettingsbase.h b/indra/llinventory/llsettingsbase.h index c2867f32d9..dc2a745fa0 100644 --- a/indra/llinventory/llsettingsbase.h +++ b/indra/llinventory/llsettingsbase.h @@ -125,6 +125,7 @@ public: inline void setName(std::string val) { mSettingName = val; + setDirtyFlag(true); setLLSDDirty(); } @@ -141,6 +142,7 @@ public: inline void setFlags(U32 value) { mSettingFlags = value; + setDirtyFlag(true); setLLSDDirty(); } @@ -183,8 +185,6 @@ public: virtual void setLLSDDirty() { mLLSDDirty = true; - mDirty = true; - clearAssetId(); } //--------------------------------------------------------------------- -- cgit v1.2.3 From dfff269d83df60de49fe8e5d7fffe9d1913e8036 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 11 Sep 2024 20:05:26 +0300 Subject: viewer#2529 Optimize LLSettingsSky::blend --- indra/llinventory/llsettingsbase.h | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llinventory/llsettingsbase.h') diff --git a/indra/llinventory/llsettingsbase.h b/indra/llinventory/llsettingsbase.h index dc2a745fa0..7b59437d6e 100644 --- a/indra/llinventory/llsettingsbase.h +++ b/indra/llinventory/llsettingsbase.h @@ -109,6 +109,7 @@ public: virtual bool isDirty() const { return mDirty; } virtual bool isVeryDirty() const { return mReplaced; } inline void setDirtyFlag(bool dirty) { mDirty = dirty; clearAssetId(); } + inline void setReplaced() { mReplaced = true; } size_t getHash(); // Hash will not include Name, ID or a previously stored Hash -- cgit v1.2.3 From e71215dcfdb960f64a7f10d2fba71790f8e7bcd1 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 12 Sep 2024 14:32:43 +0300 Subject: viewer#2529 Optimize LLSettingsWater::blend --- indra/llinventory/llsettingsbase.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'indra/llinventory/llsettingsbase.h') diff --git a/indra/llinventory/llsettingsbase.h b/indra/llinventory/llsettingsbase.h index 7b59437d6e..816ff3e111 100644 --- a/indra/llinventory/llsettingsbase.h +++ b/indra/llinventory/llsettingsbase.h @@ -173,6 +173,18 @@ public: loadValuesFromLLSD(); } + virtual void replaceSettings(const ptr_t& other) + { + mBlendedFactor = 0.0; + setDirtyFlag(true); + mReplaced = true; + mSettingFlags = other->getFlags(); + mSettingName = other->getName(); + mSettingId = other->getId(); + mAssetId = other->getAssetId(); + setLLSDDirty(); + } + void setSettings(LLSD settings) { setDirtyFlag(true); @@ -327,6 +339,10 @@ public: virtual void updateSettings() { mDirty = false; mReplaced = false; } LLSD cloneSettings(); + static void lerpVector2(LLVector2& a, const LLVector2& b, F32 mix); + static void lerpVector3(LLVector3& a, const LLVector3& b, F32 mix); + static void lerpColor(LLColor3& a, const LLColor3& b, F32 mix); + protected: LLSettingsBase(); @@ -370,9 +386,9 @@ protected: mBlendedFactor = blendfactor; } - virtual void replaceWith(LLSettingsBase::ptr_t other) + virtual void replaceWith(const LLSettingsBase::ptr_t other) { - replaceSettings(other->cloneSettings()); + replaceSettings(other); setBlendFactor(other->getBlendFactor()); } -- cgit v1.2.3