summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2022-11-11 22:35:41 +0200
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2022-11-12 00:19:20 +0200
commit7c677776801385166fe836857ca597a130dbda33 (patch)
tree2e4f426487eb1b995df7c412377c718a1ff7e96d /indra
parent344c5196b408f0382f8424f3b2e940d76050358c (diff)
SL-18518 Move 'json to override' work to background thread
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/llgltfmateriallist.cpp129
1 files changed, 80 insertions, 49 deletions
diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp
index 173e9ebb1d..206be33051 100644
--- a/indra/newview/llgltfmateriallist.cpp
+++ b/indra/newview/llgltfmateriallist.cpp
@@ -163,67 +163,102 @@ public:
LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL;
}
}
+
+ LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop");
+ LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General");
- LLUUID object_id = message["object_id"].asUUID();
-
- LLViewerObject * obj = gObjectList.findObject(object_id); // NOTE: null object here does NOT mean nothing to do, parse message and queue results for later
- bool clear_all = true;
+ struct ReturnData
+ {
+ public:
+ std::vector<LLPointer<LLGLTFMaterial> > mMaterialVector;
+ std::vector<bool> mResults;
+ };
- if (message.has("sides") && message.has("gltf_json"))
+ // fromJson() is performance heavy offload to a thread.
+ main_queue->postTo(
+ general_queue,
+ [message]() // Work done on general queue
{
- LLSD& sides = message["sides"];
- LLSD& gltf_json = message["gltf_json"];
+ ReturnData result;
- if (sides.isArray() && gltf_json.isArray() &&
- sides.size() != 0 &&
- sides.size() == gltf_json.size())
+ if (message.has("sides") && message.has("gltf_json"))
{
- clear_all = false;
+ LLSD& sides = message.get("sides");
+ LLSD& gltf_json = message.get("gltf_json");
- // message should be interpreted thusly:
- /// sides is a list of face indices
- // gltf_json is a list of corresponding json
- // any side not represented in "sides" has no override
+ if (sides.isArray() && gltf_json.isArray() &&
+ sides.size() != 0 &&
+ sides.size() == gltf_json.size())
+ {
+ // message should be interpreted thusly:
+ /// sides is a list of face indices
+ // gltf_json is a list of corresponding json
+ // any side not represented in "sides" has no override
+ result.mResults.resize(sides.size());
+ result.mMaterialVector.resize(sides.size());
+
+ // parse json
+ for (int i = 0; i < sides.size(); ++i)
+ {
+ LLPointer<LLGLTFMaterial> override_data = new LLGLTFMaterial();
- // parse json
- std::unordered_set<S32> side_set;
+ std::string gltf_json_str = gltf_json[i].asString();
- for (int i = 0; i < sides.size(); ++i)
- {
- LLPointer<LLGLTFMaterial> override_data = new LLGLTFMaterial();
-
- std::string gltf_json = message["gltf_json"][i].asString();
+ std::string warn_msg, error_msg;
- std::string warn_msg, error_msg;
-
- bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg);
+ bool success = override_data->fromJSON(gltf_json_str, warn_msg, error_msg);
- if (!success)
- {
- LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL;
+ result.mResults[i] = success;
- // unblock material editor
- if (obj && obj->isAnySelected())
+ if (success)
{
- LLMaterialEditor::updateLive(object_id, sides[i].asInteger());
+ result.mMaterialVector[i] = override_data;
+ }
+ else
+ {
+ LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL;
}
}
- else
+ }
+ }
+ return result;
+ },
+ [message](ReturnData result) // Callback to main thread
+ mutable {
+
+ LLUUID object_id = message["object_id"].asUUID();
+ LLSD& sides = message["sides"];
+ LLViewerObject * obj = gObjectList.findObject(object_id);
+ std::unordered_set<S32> side_set;
+
+ if (result.mResults.size() > 0 )
+ {
+ for (int i = 0; i < result.mResults.size(); ++i)
+ {
+ if (result.mResults[i])
{
S32 side = sides[i].asInteger();
// flag this side to not be nulled out later
side_set.insert(sides[i]);
- if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data))
+ if (!obj || !obj->setTEGLTFMaterialOverride(side, result.mMaterialVector[i]))
{
// object not ready to receive override data, queue for later
- gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data);
+ gGLTFMaterialList.queueOverrideUpdate(object_id, side, result.mMaterialVector[i]);
}
else if (obj && obj->isAnySelected())
{
LLMaterialEditor::updateLive(object_id, side);
}
}
+ else
+ {
+ // unblock material editor
+ if (obj && obj->isAnySelected())
+ {
+ LLMaterialEditor::updateLive(object_id, sides[i].asInteger());
+ }
+ }
}
if (obj && side_set.size() != obj->getNumTEs())
@@ -242,24 +277,20 @@ public:
}
}
}
- else
- {
- LL_WARNS() << "Malformed GLTF override message data: " << message << LL_ENDL;
- }
- }
-
- if (clear_all && obj)
- { // override list was empty or an error occurred, null out all overrides for this object
- bool object_has_selection = obj->isAnySelected();
- for (int i = 0; i < obj->getNumTEs(); ++i)
- {
- obj->setTEGLTFMaterialOverride(i, nullptr);
- if (object_has_selection)
+ else if (obj)
+ { // override list was empty or an error occurred, null out all overrides for this object
+ bool object_has_selection = obj->isAnySelected();
+ for (int i = 0; i < obj->getNumTEs(); ++i)
{
- LLMaterialEditor::updateLive(obj->getID(), i);
+ obj->setTEGLTFMaterialOverride(i, nullptr);
+ if (object_has_selection)
+ {
+ LLMaterialEditor::updateLive(obj->getID(), i);
+ }
}
}
- }
+ });
+
return true;
}
};