From be38a4bc71c6676b07a0a44028a20897d84bef3b Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 7 Feb 2018 16:12:33 -0800 Subject: [PATCH 01/15] creating workload lib --- interface/CMakeLists.txt | 1 + libraries/workload/CMakeLists.txt | 5 + libraries/workload/src/workload/Space.cpp | 96 ++++++++ libraries/workload/src/workload/Space.h | 81 +++++++ tests/workload/CMakeLists.txt | 8 + tests/workload/src/SpaceTests.cpp | 272 ++++++++++++++++++++++ tests/workload/src/SpaceTests.h | 29 +++ 7 files changed, 492 insertions(+) create mode 100644 libraries/workload/CMakeLists.txt create mode 100644 libraries/workload/src/workload/Space.cpp create mode 100644 libraries/workload/src/workload/Space.h create mode 100644 tests/workload/CMakeLists.txt create mode 100644 tests/workload/src/SpaceTests.cpp create mode 100644 tests/workload/src/SpaceTests.h diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 728f1467e0..c5800959f0 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -211,6 +211,7 @@ link_hifi_libraries( render-utils entities-renderer avatars-renderer ui qml auto-updater midi controllers plugins image trackers ui-plugins display-plugins input-plugins + workload ${PLATFORM_GL_BACKEND} ) diff --git a/libraries/workload/CMakeLists.txt b/libraries/workload/CMakeLists.txt new file mode 100644 index 0000000000..3fcf00e0e9 --- /dev/null +++ b/libraries/workload/CMakeLists.txt @@ -0,0 +1,5 @@ +set(TARGET_NAME workload) +setup_hifi_library() + +link_hifi_libraries(shared) + diff --git a/libraries/workload/src/workload/Space.cpp b/libraries/workload/src/workload/Space.cpp new file mode 100644 index 0000000000..075f9fe477 --- /dev/null +++ b/libraries/workload/src/workload/Space.cpp @@ -0,0 +1,96 @@ +// +// Space.h +// libraries/shared/src/ +// +// Created by Andrew Meadows 2018.01.30 +// Copyright 2018 High Fidelity, Inc. +// +// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards +// Simple plane class. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "Space.h" + +#include + +#include + +using namespace workload; + +int32_t Space::createProxy(const Space::Sphere& newSphere) { + if (_freeIndices.empty()) { + _proxies.emplace_back(Space::Proxy(newSphere)); + return (int32_t)_proxies.size() - 1; + } else { + int32_t index = _freeIndices.back(); + _freeIndices.pop_back(); + _proxies[index].sphere = newSphere; + _proxies[index].region = Space::REGION_UNKNOWN; + _proxies[index].prevRegion = Space::REGION_UNKNOWN; + return index; + } +} + +void Space::deleteProxy(int32_t proxyId) { + if (proxyId >= (int32_t)_proxies.size() || _proxies.empty()) { + return; + } + if (proxyId == (int32_t)_proxies.size() - 1) { + // remove proxy on back + _proxies.pop_back(); + if (!_freeIndices.empty()) { + // remove any freeIndices on back + std::sort(_freeIndices.begin(), _freeIndices.end()); + while(!_freeIndices.empty() && _freeIndices.back() == (int32_t)_proxies.size() - 1) { + _freeIndices.pop_back(); + _proxies.pop_back(); + } + } + } else { + _proxies[proxyId].region = Space::REGION_INVALID; + _freeIndices.push_back(proxyId); + } +} + +void Space::updateProxy(int32_t proxyId, const Space::Sphere& newSphere) { + if (proxyId >= (int32_t)_proxies.size()) { + return; + } + _proxies[proxyId].sphere = newSphere; + // TODO: when view is not changing it would be faster to recategorize each Proxy that changes. + // Otherwise, we would want to just update all changed objects, adjust the view, and then comute changes. +} + +void Space::setViews(const std::vector& views) { + _views = views; +} + +void Space::recategorizeProxiesAndGetChanges(std::vector& changes) { + uint32_t numProxies = _proxies.size(); + uint32_t numViews = _views.size(); + for (uint32_t i = 0; i < numProxies; ++i) { + Proxy& proxy = _proxies[i]; + if (proxy.region < Space::REGION_INVALID) { + uint8_t region = Space::REGION_UNKNOWN; + for (uint32_t j = 0; j < numViews; ++j) { + float distance2 = glm::distance2(_views[j].center, glm::vec3(_proxies[i].sphere)); + for (uint8_t c = 0; c < region; ++c) { + float touchDistance = _views[j].radiuses[c] + _proxies[i].sphere.w; + if (distance2 < touchDistance * touchDistance) { + region = c; + break; + } + } + } + proxy.prevRegion = proxy.region; + proxy.region = region; + if (proxy.region != proxy.prevRegion) { + changes.emplace_back(Space::Change((int32_t)i, proxy.region, proxy.prevRegion)); + } + } + } +} + diff --git a/libraries/workload/src/workload/Space.h b/libraries/workload/src/workload/Space.h new file mode 100644 index 0000000000..717c15e159 --- /dev/null +++ b/libraries/workload/src/workload/Space.h @@ -0,0 +1,81 @@ +// +// Space.h +// libraries/workload/src/workload +// +// Created by Andrew Meadows 2018.01.30 +// Copyright 2018 High Fidelity, Inc. +// +// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards +// Simple plane class. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_workload_Space_h +#define hifi_workload_Space_h + +#include +#include + +namespace workload { + +class Space { +public: + static const uint8_t REGION_NEAR = 0; + static const uint8_t REGION_MIDDLE = 1; + static const uint8_t REGION_FAR = 2; + static const uint8_t REGION_UNKNOWN = 3; + static const uint8_t REGION_INVALID = 4; + + using Sphere = glm::vec4; // = center, w = radius + + class Proxy { + public: + Proxy(const Sphere& s) : sphere(s) {} + Sphere sphere; + uint8_t region { REGION_UNKNOWN }; + uint8_t prevRegion { REGION_UNKNOWN }; + }; + + class View { + public: + View(const glm::vec3& pos, float nearRadius, float midRadius, float farRadius) : center(pos) { + radiuses[0] = nearRadius; + radiuses[1] = midRadius; + radiuses[2] = farRadius; + } + glm::vec3 center { 0.0f, 0.0f, 0.0f }; // these init values are not important + float radiuses[3] { 1.0f, 2.0f, 3.0f }; // these init values are not important + }; + + class Change { + public: + Change(int32_t i, uint32_t c, uint32_t p) : proxyId(i), region(c), prevRegion(p) {} + int32_t proxyId { -1 }; + uint8_t region { 0 }; + uint8_t prevRegion { 0 }; + }; + + Space() {} + + int32_t createProxy(const Sphere& sphere); + void deleteProxy(int32_t proxyId); + void updateProxy(int32_t proxyId, const Sphere& sphere); + void setViews(const std::vector& views); + + uint32_t getNumObjects() const { return (uint32_t)(_proxies.size() - _freeIndices.size()); } + + void recategorizeProxiesAndGetChanges(std::vector& changes); + +private: + // NOTE: double-buffering proxy.category and .prevRegion in their own arrays is NOT faster + // (performance is within the noise) than leaving them as data members of Proxy. + std::vector _proxies; + std::vector _views; + std::vector _freeIndices; +}; + +} // namespace workload + +#endif // hifi_workload_Space_h diff --git a/tests/workload/CMakeLists.txt b/tests/workload/CMakeLists.txt new file mode 100644 index 0000000000..53ee7acba1 --- /dev/null +++ b/tests/workload/CMakeLists.txt @@ -0,0 +1,8 @@ + +# Declare dependencies +macro (setup_testcase_dependencies) + link_hifi_libraries(shared workload) + package_libraries_for_deployment() +endmacro () + +setup_hifi_testcase() diff --git a/tests/workload/src/SpaceTests.cpp b/tests/workload/src/SpaceTests.cpp new file mode 100644 index 0000000000..17b6911899 --- /dev/null +++ b/tests/workload/src/SpaceTests.cpp @@ -0,0 +1,272 @@ +// +// SpaceTests.cpp +// tests/physics/src +// +// Created by Andrew Meadows on 2017.01.26 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "SpaceTests.h" + +#include + +#include +#include +#include + + +const float INV_SQRT_3 = 1.0f / sqrtf(3.0f); + +QTEST_MAIN(SpaceTests) + +void SpaceTests::testOverlaps() { + workload::Space space; + using Changes = std::vector; + using Views = std::vector; + + glm::vec3 viewCenter(0.0f, 0.0f, 0.0f); + float near = 1.0f; + float mid = 2.0f; + float far = 3.0f; + + Views views; + views.push_back(workload::Space::View(viewCenter, near, mid, far)); + space.setViews(views); + + int32_t proxyId = 0; + const float DELTA = 0.001f; + float proxyRadius = 0.5f; + glm::vec3 proxyPosition = viewCenter + glm::vec3(0.0f, 0.0f, far + proxyRadius + DELTA); + workload::Space::Sphere proxySphere(proxyPosition, proxyRadius); + + { // create very_far proxy + proxyId = space.createProxy(proxySphere); + QVERIFY(space.getNumObjects() == 1); + + Changes changes; + space.recategorizeProxiesAndGetChanges(changes); + QVERIFY(changes.size() == 0); + } + + { // move proxy far + float newRadius = 1.0f; + glm::vec3 newPosition = viewCenter + glm::vec3(0.0f, 0.0f, far + newRadius - DELTA); + workload::Space::Sphere newSphere(newPosition, newRadius); + space.updateProxy(proxyId, newSphere); + Changes changes; + space.recategorizeProxiesAndGetChanges(changes); + QVERIFY(changes.size() == 1); + QVERIFY(changes[0].proxyId == proxyId); + QVERIFY(changes[0].region == workload::Space::REGION_FAR); + QVERIFY(changes[0].prevRegion == workload::Space::REGION_UNKNOWN); + } + + { // move proxy mid + float newRadius = 1.0f; + glm::vec3 newPosition = viewCenter + glm::vec3(0.0f, 0.0f, mid + newRadius - DELTA); + workload::Space::Sphere newSphere(newPosition, newRadius); + space.updateProxy(proxyId, newSphere); + Changes changes; + space.recategorizeProxiesAndGetChanges(changes); + QVERIFY(changes.size() == 1); + QVERIFY(changes[0].proxyId == proxyId); + QVERIFY(changes[0].region == workload::Space::REGION_MIDDLE); + QVERIFY(changes[0].prevRegion == workload::Space::REGION_FAR); + } + + { // move proxy near + float newRadius = 1.0f; + glm::vec3 newPosition = viewCenter + glm::vec3(0.0f, 0.0f, near + newRadius - DELTA); + workload::Space::Sphere newSphere(newPosition, newRadius); + space.updateProxy(proxyId, newSphere); + Changes changes; + space.recategorizeProxiesAndGetChanges(changes); + QVERIFY(changes.size() == 1); + QVERIFY(changes[0].proxyId == proxyId); + QVERIFY(changes[0].region == workload::Space::REGION_NEAR); + QVERIFY(changes[0].prevRegion == workload::Space::REGION_MIDDLE); + } + + { // delete proxy + // NOTE: atm deleting a proxy doesn't result in a "Change" + space.deleteProxy(proxyId); + Changes changes; + space.recategorizeProxiesAndGetChanges(changes); + QVERIFY(changes.size() == 0); + QVERIFY(space.getNumObjects() == 0); + } +} + +#ifdef MANUAL_TEST + +const float WORLD_WIDTH = 1000.0f; +const float MIN_RADIUS = 1.0f; +const float MAX_RADIUS = 100.0f; + +float randomFloat() { + return 2.0f * ((float)rand() / (float)RAND_MAX) - 1.0f; +} + +glm::vec3 randomVec3() { + glm::vec3 v(randomFloat(), randomFloat(), randomFloat()); + return v; +} + +void generateSpheres(uint32_t numProxies, std::vector& spheres) { + spheres.reserve(numProxies); + for (uint32_t i = 0; i < numProxies; ++i) { + workload::Space::Sphere sphere( + WORLD_WIDTH * randomFloat(), + WORLD_WIDTH * randomFloat(), + WORLD_WIDTH * randomFloat(), + (MIN_RADIUS + (MAX_RADIUS - MIN_RADIUS)) * randomFloat()); + spheres.push_back(sphere); + } +} + +void generatePositions(uint32_t numProxies, std::vector& positions) { + positions.reserve(numProxies); + for (uint32_t i = 0; i < numProxies; ++i) { + positions.push_back(WORLD_WIDTH * randomVec3()); + } +} + +void generateRadiuses(uint32_t numRadiuses, std::vector& radiuses) { + radiuses.reserve(numRadiuses); + for (uint32_t i = 0; i < numRadiuses; ++i) { + radiuses.push_back(MIN_RADIUS + (MAX_RADIUS - MIN_RADIUS) * randomFloat()); + } +} + +void SpaceTests::benchmark() { + uint32_t numProxies[] = { 100, 1000, 10000, 100000 }; + uint32_t numTests = 4; + std::vector timeToAddAll; + std::vector timeToRemoveAll; + std::vector timeToMoveView; + std::vector timeToMoveProxies; + for (uint32_t i = 0; i < numTests; ++i) { + + workload::Space space; + + { // build the views + std::vector viewPositions; + viewPositions.push_back(glm::vec3(0.0f, 0.0f, 0.0f)); + viewPositions.push_back(glm::vec3(0.0f, 0.0f, 0.1f * WORLD_WIDTH)); + float radius0 = 0.25f * WORLD_WIDTH; + float radius1 = 0.50f * WORLD_WIDTH; + float radius2 = 0.75f * WORLD_WIDTH; + std::vector views; + views.push_back(workload::Space::View(viewPositions[0], radius0, radius1, radius2)); + views.push_back(workload::Space::View(viewPositions[1], radius0, radius1, radius2)); + space.setViews(views); + } + + // build the proxies + uint32_t n = numProxies[i]; + std::vector proxySpheres; + generateSpheres(n, proxySpheres); + std::vector proxyKeys; + proxyKeys.reserve(n); + + // measure time to put proxies in the space + uint64_t startTime = usecTimestampNow(); + for (uint32_t j = 0; j < n; ++j) { + int32_t key = space.createProxy(proxySpheres[j]); + proxyKeys.push_back(key); + } + uint64_t usec = usecTimestampNow() - startTime; + timeToAddAll.push_back(usec); + + { + // build the views + std::vector viewPositions; + viewPositions.push_back(glm::vec3(1.0f, 2.0f, 3.0f)); + viewPositions.push_back(glm::vec3(1.0f, 2.0f, 3.0f + 0.1f * WORLD_WIDTH)); + float radius0 = 0.25f * WORLD_WIDTH; + float radius1 = 0.50f * WORLD_WIDTH; + float radius2 = 0.75f * WORLD_WIDTH; + std::vector views; + views.push_back(workload::Space::View(viewPositions[0], radius0, radius1, radius2)); + views.push_back(workload::Space::View(viewPositions[1], radius0, radius1, radius2)); + space.setViews(views); + } + + // measure time to recategorize everything + std::vector changes; + startTime = usecTimestampNow(); + space.recategorizeProxiesAndGetChanges(changes); + usec = usecTimestampNow() - startTime; + timeToMoveView.push_back(usec); + + // move every 10th proxy around + const float proxySpeed = 1.0f; + std::vector newSpheres; + uint32_t numMovingProxies = n / 10; + uint32_t jstep = n / numMovingProxies; + uint32_t maxJ = numMovingProxies * jstep - 1; + glm::vec3 direction; + for (uint32_t j = 0; j < maxJ - jstep; j += jstep) { + glm::vec3 position = (glm::vec3)proxySpheres[j]; + glm::vec3 destination = (glm::vec3)proxySpheres[j + jstep]; + direction = glm::normalize(destination - position); + glm::vec3 newPosition = position + proxySpeed * direction; + newSpheres.push_back(workload::Space::Sphere(newPosition, proxySpheres[j].w)); + } + glm::vec3 position = (glm::vec3)proxySpheres[maxJ = jstep]; + glm::vec3 destination = (glm::vec3)proxySpheres[0]; + direction = glm::normalize(destination - position); + direction = position + proxySpeed * direction; + newSpheres.push_back(workload::Space::Sphere(direction, proxySpheres[0].w)); + uint32_t k = 0; + startTime = usecTimestampNow(); + for (uint32_t j = 0; j < maxJ; j += jstep) { + space.updateProxy(proxyKeys[j], newSpheres[k++]); + } + changes.clear(); + space.recategorizeProxiesAndGetChanges(changes); + usec = usecTimestampNow() - startTime; + timeToMoveProxies.push_back(usec); + + // measure time to remove proxies from space + startTime = usecTimestampNow(); + for (uint32_t j = 0; j < n; ++j) { + space.deleteProxy(proxyKeys[j]); + } + usec = usecTimestampNow() - startTime; + timeToRemoveAll.push_back(usec); + } + + std::cout << "[numProxies, timeToAddAll] = [" << std::endl; + for (uint32_t i = 0; i < timeToAddAll.size(); ++i) { + uint32_t n = numProxies[i]; + std::cout << " " << n << ", " << timeToAddAll[i] << std::endl; + } + std::cout << "];" << std::endl; + + std::cout << "[numProxies, timeToMoveView] = [" << std::endl; + for (uint32_t i = 0; i < timeToMoveView.size(); ++i) { + uint32_t n = numProxies[i]; + std::cout << " " << n << ", " << timeToMoveView[i] << std::endl; + } + std::cout << "];" << std::endl; + + std::cout << "[numProxies, timeToMoveProxies] = [" << std::endl; + for (uint32_t i = 0; i < timeToMoveProxies.size(); ++i) { + uint32_t n = numProxies[i]; + std::cout << " " << n << "/10, " << timeToMoveProxies[i] << std::endl; + } + std::cout << "];" << std::endl; + + std::cout << "[numProxies, timeToRemoveAll] = [" << std::endl; + for (uint32_t i = 0; i < timeToRemoveAll.size(); ++i) { + uint32_t n = numProxies[i]; + std::cout << " " << n << ", " << timeToRemoveAll[i] << std::endl; + } + std::cout << "];" << std::endl; +} + +#endif // MANUAL_TEST diff --git a/tests/workload/src/SpaceTests.h b/tests/workload/src/SpaceTests.h new file mode 100644 index 0000000000..153b89dfc5 --- /dev/null +++ b/tests/workload/src/SpaceTests.h @@ -0,0 +1,29 @@ +// +// SpaceTests.h +// tests/physics/src +// +// Created by Andrew Meadows on 2017.01.26 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_workload_SpaceTests_h +#define hifi_workload_SpaceTests_h + +#include + +//#define MANUAL_TEST + +class SpaceTests : public QObject { + Q_OBJECT + +private slots: + void testOverlaps(); +#ifdef MANUAL_TEST + void benchmark(); +#endif // MANUAL_TEST +}; + +#endif // hifi_workload_SpaceTests_h From a8ad846f2b27a1e54c11307cff9d87102222f1e0 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 7 Feb 2018 16:25:06 -0800 Subject: [PATCH 02/15] cleanup --- libraries/workload/src/workload/Space.cpp | 4 +--- libraries/workload/src/workload/Space.h | 8 +++----- tests/workload/src/SpaceTests.cpp | 16 ++++++++-------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/libraries/workload/src/workload/Space.cpp b/libraries/workload/src/workload/Space.cpp index 075f9fe477..6562f60ac7 100644 --- a/libraries/workload/src/workload/Space.cpp +++ b/libraries/workload/src/workload/Space.cpp @@ -60,15 +60,13 @@ void Space::updateProxy(int32_t proxyId, const Space::Sphere& newSphere) { return; } _proxies[proxyId].sphere = newSphere; - // TODO: when view is not changing it would be faster to recategorize each Proxy that changes. - // Otherwise, we would want to just update all changed objects, adjust the view, and then comute changes. } void Space::setViews(const std::vector& views) { _views = views; } -void Space::recategorizeProxiesAndGetChanges(std::vector& changes) { +void Space::categorizeAndGetChanges(std::vector& changes) { uint32_t numProxies = _proxies.size(); uint32_t numViews = _views.size(); for (uint32_t i = 0; i < numProxies; ++i) { diff --git a/libraries/workload/src/workload/Space.h b/libraries/workload/src/workload/Space.h index 717c15e159..be47cddc4e 100644 --- a/libraries/workload/src/workload/Space.h +++ b/libraries/workload/src/workload/Space.h @@ -45,8 +45,8 @@ public: radiuses[1] = midRadius; radiuses[2] = farRadius; } - glm::vec3 center { 0.0f, 0.0f, 0.0f }; // these init values are not important - float radiuses[3] { 1.0f, 2.0f, 3.0f }; // these init values are not important + glm::vec3 center { 0.0f, 0.0f, 0.0f }; + float radiuses[3] { 0.0f, 0.0f, 0.0f }; }; class Change { @@ -66,11 +66,9 @@ public: uint32_t getNumObjects() const { return (uint32_t)(_proxies.size() - _freeIndices.size()); } - void recategorizeProxiesAndGetChanges(std::vector& changes); + void categorizeAndGetChanges(std::vector& changes); private: - // NOTE: double-buffering proxy.category and .prevRegion in their own arrays is NOT faster - // (performance is within the noise) than leaving them as data members of Proxy. std::vector _proxies; std::vector _views; std::vector _freeIndices; diff --git a/tests/workload/src/SpaceTests.cpp b/tests/workload/src/SpaceTests.cpp index 17b6911899..1c6b0491a7 100644 --- a/tests/workload/src/SpaceTests.cpp +++ b/tests/workload/src/SpaceTests.cpp @@ -47,7 +47,7 @@ void SpaceTests::testOverlaps() { QVERIFY(space.getNumObjects() == 1); Changes changes; - space.recategorizeProxiesAndGetChanges(changes); + space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 0); } @@ -57,7 +57,7 @@ void SpaceTests::testOverlaps() { workload::Space::Sphere newSphere(newPosition, newRadius); space.updateProxy(proxyId, newSphere); Changes changes; - space.recategorizeProxiesAndGetChanges(changes); + space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 1); QVERIFY(changes[0].proxyId == proxyId); QVERIFY(changes[0].region == workload::Space::REGION_FAR); @@ -70,7 +70,7 @@ void SpaceTests::testOverlaps() { workload::Space::Sphere newSphere(newPosition, newRadius); space.updateProxy(proxyId, newSphere); Changes changes; - space.recategorizeProxiesAndGetChanges(changes); + space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 1); QVERIFY(changes[0].proxyId == proxyId); QVERIFY(changes[0].region == workload::Space::REGION_MIDDLE); @@ -83,7 +83,7 @@ void SpaceTests::testOverlaps() { workload::Space::Sphere newSphere(newPosition, newRadius); space.updateProxy(proxyId, newSphere); Changes changes; - space.recategorizeProxiesAndGetChanges(changes); + space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 1); QVERIFY(changes[0].proxyId == proxyId); QVERIFY(changes[0].region == workload::Space::REGION_NEAR); @@ -94,7 +94,7 @@ void SpaceTests::testOverlaps() { // NOTE: atm deleting a proxy doesn't result in a "Change" space.deleteProxy(proxyId); Changes changes; - space.recategorizeProxiesAndGetChanges(changes); + space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 0); QVERIFY(space.getNumObjects() == 0); } @@ -195,10 +195,10 @@ void SpaceTests::benchmark() { space.setViews(views); } - // measure time to recategorize everything + // measure time to categorizeAndGetChanges everything std::vector changes; startTime = usecTimestampNow(); - space.recategorizeProxiesAndGetChanges(changes); + space.categorizeAndGetChanges(changes); usec = usecTimestampNow() - startTime; timeToMoveView.push_back(usec); @@ -227,7 +227,7 @@ void SpaceTests::benchmark() { space.updateProxy(proxyKeys[j], newSpheres[k++]); } changes.clear(); - space.recategorizeProxiesAndGetChanges(changes); + space.categorizeAndGetChanges(changes); usec = usecTimestampNow() - startTime; timeToMoveProxies.push_back(usec); From 955af21aba0abbac34f08f5d48fb87f610ef79a4 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 8 Feb 2018 08:30:29 -0800 Subject: [PATCH 03/15] use explicit cast to avoid windows warning --- libraries/workload/src/workload/Space.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/workload/src/workload/Space.cpp b/libraries/workload/src/workload/Space.cpp index 6562f60ac7..1e2bfb228a 100644 --- a/libraries/workload/src/workload/Space.cpp +++ b/libraries/workload/src/workload/Space.cpp @@ -67,8 +67,8 @@ void Space::setViews(const std::vector& views) { } void Space::categorizeAndGetChanges(std::vector& changes) { - uint32_t numProxies = _proxies.size(); - uint32_t numViews = _views.size(); + uint32_t numProxies = (uint32_t)_proxies.size(); + uint32_t numViews = (uint32_t)_views.size(); for (uint32_t i = 0; i < numProxies; ++i) { Proxy& proxy = _proxies[i]; if (proxy.region < Space::REGION_INVALID) { From 8231a56b2299b33ce18e77e19e5f8e18f6a2df40 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 8 Feb 2018 14:19:19 -0800 Subject: [PATCH 04/15] pull task out of render and into its own lib --- interface/CMakeLists.txt | 2 +- libraries/avatars-renderer/CMakeLists.txt | 1 + libraries/entities-renderer/CMakeLists.txt | 1 + libraries/render-utils/CMakeLists.txt | 4 +- libraries/render-utils/src/ZoneRenderer.h | 2 +- libraries/render/CMakeLists.txt | 1 + libraries/render/src/render/Engine.h | 5 +- libraries/render/src/render/SortTask.h | 2 +- .../{render => task}/src/task/Config.cpp | 0 libraries/{render => task}/src/task/Config.h | 2 +- libraries/{render => task}/src/task/Task.h | 58 +++++++++---------- libraries/{render => task}/src/task/Varying.h | 0 tests/gpu-test/CMakeLists.txt | 2 +- tests/render-perf/CMakeLists.txt | 2 +- tests/render-texture-load/CMakeLists.txt | 2 +- 15 files changed, 44 insertions(+), 40 deletions(-) rename libraries/{render => task}/src/task/Config.cpp (100%) rename libraries/{render => task}/src/task/Config.h (99%) rename libraries/{render => task}/src/task/Task.h (88%) rename libraries/{render => task}/src/task/Varying.h (100%) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index c5800959f0..85007f5f15 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -204,7 +204,7 @@ endif() # link required hifi libraries link_hifi_libraries( - shared octree ktx gpu gl procedural graphics render + shared task octree ktx gpu gl procedural graphics render pointers recording fbx networking model-networking entities avatars trackers audio audio-client animation script-engine physics diff --git a/libraries/avatars-renderer/CMakeLists.txt b/libraries/avatars-renderer/CMakeLists.txt index 1f740700c5..40e1607b2a 100644 --- a/libraries/avatars-renderer/CMakeLists.txt +++ b/libraries/avatars-renderer/CMakeLists.txt @@ -13,5 +13,6 @@ include_hifi_library_headers(entities-renderer) include_hifi_library_headers(audio) include_hifi_library_headers(entities) include_hifi_library_headers(octree) +include_hifi_library_headers(task) target_bullet() diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index 4eaa16a107..0f33a73e40 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -13,6 +13,7 @@ include_hifi_library_headers(fbx) include_hifi_library_headers(entities) include_hifi_library_headers(avatars) include_hifi_library_headers(controllers) +include_hifi_library_headers(task) target_bullet() target_polyvox() diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 57e3572012..3e01fd2643 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -3,10 +3,10 @@ AUTOSCRIBE_SHADER_LIB(gpu graphics render) # pull in the resources.qrc file qt5_add_resources(QT_RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/fonts/fonts.qrc") setup_hifi_library(Gui Network Qml Quick Script) -link_hifi_libraries(shared ktx gpu graphics model-networking render animation fbx image procedural) +link_hifi_libraries(shared task ktx gpu graphics model-networking render animation fbx image procedural) +include_hifi_library_headers(audio) include_hifi_library_headers(networking) include_hifi_library_headers(octree) -include_hifi_library_headers(audio) if (NOT ANDROID) target_nsight() diff --git a/libraries/render-utils/src/ZoneRenderer.h b/libraries/render-utils/src/ZoneRenderer.h index 5737499270..419db4ebe2 100644 --- a/libraries/render-utils/src/ZoneRenderer.h +++ b/libraries/render-utils/src/ZoneRenderer.h @@ -88,4 +88,4 @@ protected: }; -#endif \ No newline at end of file +#endif diff --git a/libraries/render/CMakeLists.txt b/libraries/render/CMakeLists.txt index 1d88c3e5f5..08f0e07b8f 100644 --- a/libraries/render/CMakeLists.txt +++ b/libraries/render/CMakeLists.txt @@ -4,5 +4,6 @@ setup_hifi_library() # render needs octree only for getAccuracyAngle(float, int) link_hifi_libraries(shared ktx gpu graphics octree) +include_hifi_library_headers(task) target_nsight() diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index 1650d09c5d..94102b4834 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -14,9 +14,10 @@ #include -#include "Scene.h" -#include "../task/Task.h" #include +#include + +#include "Scene.h" namespace render { diff --git a/libraries/render/src/render/SortTask.h b/libraries/render/src/render/SortTask.h index de670b1676..8e4c58803e 100644 --- a/libraries/render/src/render/SortTask.h +++ b/libraries/render/src/render/SortTask.h @@ -55,4 +55,4 @@ namespace render { }; } -#endif // hifi_render_SortTask_h; \ No newline at end of file +#endif // hifi_render_SortTask_h; diff --git a/libraries/render/src/task/Config.cpp b/libraries/task/src/task/Config.cpp similarity index 100% rename from libraries/render/src/task/Config.cpp rename to libraries/task/src/task/Config.cpp diff --git a/libraries/render/src/task/Config.h b/libraries/task/src/task/Config.h similarity index 99% rename from libraries/render/src/task/Config.h rename to libraries/task/src/task/Config.h index 7632d4e85d..8f23efe031 100644 --- a/libraries/render/src/task/Config.h +++ b/libraries/task/src/task/Config.h @@ -20,7 +20,7 @@ #include "SettingHandle.h" -#include "Logging.h" +//#include "Logging.h" namespace task { diff --git a/libraries/render/src/task/Task.h b/libraries/task/src/task/Task.h similarity index 88% rename from libraries/render/src/task/Task.h rename to libraries/task/src/task/Task.h index 63bda7bafa..3ac6614a09 100644 --- a/libraries/render/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -1,6 +1,6 @@ // // Task.h -// render/src/task +// task/src/task // // Created by Zach Pomerantz on 1/6/2016. // Copyright 2016 High Fidelity, Inc. @@ -17,7 +17,7 @@ #include "SettingHandle.h" -#include "Logging.h" +//#include "Logging.h" #include #include @@ -25,8 +25,8 @@ namespace task { class JobConcept; -template class JobT; -template class TaskT; +template class JobT; +template class TaskT; class JobNoIO {}; class JobContext { @@ -68,23 +68,23 @@ template void jobConfigure(T&, const TaskConfig&) { // nop, as the default TaskConfig was used, so the data does not need a configure method } -template void jobRun(T& data, const RC& renderContext, const JobNoIO& input, JobNoIO& output) { - data.run(renderContext); +template void jobRun(T& data, const JC& jobContext, const JobNoIO& input, JobNoIO& output) { + data.run(jobContext); } -template void jobRun(T& data, const RC& renderContext, const I& input, JobNoIO& output) { - data.run(renderContext, input); +template void jobRun(T& data, const JC& jobContext, const I& input, JobNoIO& output) { + data.run(jobContext, input); } -template void jobRun(T& data, const RC& renderContext, const JobNoIO& input, O& output) { - data.run(renderContext, output); +template void jobRun(T& data, const JC& jobContext, const JobNoIO& input, O& output) { + data.run(jobContext, output); } -template void jobRun(T& data, const RC& renderContext, const I& input, O& output) { - data.run(renderContext, input, output); +template void jobRun(T& data, const JC& jobContext, const I& input, O& output) { + data.run(jobContext, input, output); } -template +template class Job { public: - using Context = RC; + using Context = JC; using ContextPointer = std::shared_ptr; using Config = JobConfig; using None = JobNoIO; @@ -94,7 +94,7 @@ public: Concept(QConfigPointer config) : JobConcept(config) {} virtual ~Concept() = default; - virtual void run(const ContextPointer& renderContext) = 0; + virtual void run(const ContextPointer& jobContext) = 0; }; using ConceptPointer = std::shared_ptr; @@ -130,12 +130,12 @@ public: jobConfigure(_data, *std::static_pointer_cast(Concept::_config)); } - void run(const ContextPointer& renderContext) override { - renderContext->jobConfig = std::static_pointer_cast(Concept::_config); - if (renderContext->jobConfig->alwaysEnabled || renderContext->jobConfig->isEnabled()) { - jobRun(_data, renderContext, _input.get(), _output.edit()); + void run(const ContextPointer& jobContext) override { + jobContext->jobConfig = std::static_pointer_cast(Concept::_config); + if (jobContext->jobConfig->alwaysEnabled || jobContext->jobConfig->isEnabled()) { + jobRun(_data, jobContext, _input.get(), _output.edit()); } - renderContext->jobConfig.reset(); + jobContext->jobConfig.reset(); } }; template using ModelI = Model; @@ -161,12 +161,12 @@ public: return concept->_data; } - virtual void run(const ContextPointer& renderContext) { + virtual void run(const ContextPointer& jobContext) { PerformanceTimer perfTimer(_name.c_str()); - PROFILE_RANGE(render, _name.c_str()); + //PROFILE_RANGE(render, _name.c_str()); auto start = usecTimestampNow(); - _concept->run(renderContext); + _concept->run(jobContext); _concept->setCPURunTime((double)(usecTimestampNow() - start) / 1000.0); } @@ -186,13 +186,13 @@ protected: // The build method is where child Jobs can be added internally to the task // where the input of the task can be setup to feed the child jobs // and where the output of the task is defined -template -class Task : public Job { +template +class Task : public Job { public: - using Context = RC; + using Context = JC; using ContextPointer = std::shared_ptr; using Config = TaskConfig; - using JobType = Job; + using JobType = Job; using None = typename JobType::None; using Concept = typename JobType::Concept; using ConceptPointer = typename JobType::ConceptPointer; @@ -300,11 +300,11 @@ public: } } - void run(const ContextPointer& renderContext) override { + void run(const ContextPointer& jobContext) override { auto config = std::static_pointer_cast(Concept::_config); if (config->alwaysEnabled || config->enabled) { for (auto job : TaskConcept::_jobs) { - job.run(renderContext); + job.run(jobContext); } } } diff --git a/libraries/render/src/task/Varying.h b/libraries/task/src/task/Varying.h similarity index 100% rename from libraries/render/src/task/Varying.h rename to libraries/task/src/task/Varying.h diff --git a/tests/gpu-test/CMakeLists.txt b/tests/gpu-test/CMakeLists.txt index 7bc1349091..336dcf753c 100644 --- a/tests/gpu-test/CMakeLists.txt +++ b/tests/gpu-test/CMakeLists.txt @@ -5,7 +5,7 @@ setup_hifi_project(Quick Gui Script) setup_memory_debugger() set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") link_hifi_libraries( - shared networking gl + shared task networking gl ktx gpu procedural octree image graphics model-networking fbx animation script-engine render render-utils diff --git a/tests/render-perf/CMakeLists.txt b/tests/render-perf/CMakeLists.txt index 57ae7dace7..7ad38c5795 100644 --- a/tests/render-perf/CMakeLists.txt +++ b/tests/render-perf/CMakeLists.txt @@ -13,7 +13,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") # link in the shared libraries link_hifi_libraries( - shared networking animation + shared task networking animation ktx image octree gl gpu gpu-gl render render-utils graphics fbx model-networking diff --git a/tests/render-texture-load/CMakeLists.txt b/tests/render-texture-load/CMakeLists.txt index 2ed905a3ef..b3e49d830b 100644 --- a/tests/render-texture-load/CMakeLists.txt +++ b/tests/render-texture-load/CMakeLists.txt @@ -13,7 +13,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") # link in the shared libraries link_hifi_libraries( - shared networking octree + shared task networking octree gl gpu render ktx image animation graphics fbx model-networking render-utils From 724e2f7e660987def919ca9fa45b9c672175d76e Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 9 Feb 2018 10:00:32 -0800 Subject: [PATCH 05/15] add CMakeLists.txt for new 'task' library --- libraries/task/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 libraries/task/CMakeLists.txt diff --git a/libraries/task/CMakeLists.txt b/libraries/task/CMakeLists.txt new file mode 100644 index 0000000000..4c97f34acd --- /dev/null +++ b/libraries/task/CMakeLists.txt @@ -0,0 +1,3 @@ +set(TARGET_NAME task) +setup_hifi_library() +link_hifi_libraries(shared) From 342ba5f8aa795b01429ced0442b4d3f6e5feba05 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 9 Feb 2018 11:50:41 -0800 Subject: [PATCH 06/15] add 'task' lib dependency to HMD plugins --- plugins/oculus/CMakeLists.txt | 2 +- plugins/openvr/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/oculus/CMakeLists.txt b/plugins/oculus/CMakeLists.txt index 2a011a349a..638cadf574 100644 --- a/plugins/oculus/CMakeLists.txt +++ b/plugins/oculus/CMakeLists.txt @@ -19,7 +19,7 @@ if (WIN32 AND (NOT USE_GLES)) set(TARGET_NAME oculus) setup_hifi_plugin(Multimedia) link_hifi_libraries( - shared gl gpu gpu-gl controllers ui qml + shared task gl gpu gpu-gl controllers ui qml plugins ui-plugins display-plugins input-plugins audio-client networking render-utils ${PLATFORM_GL_BACKEND} diff --git a/plugins/openvr/CMakeLists.txt b/plugins/openvr/CMakeLists.txt index a6e90aa5a6..ff94152d57 100644 --- a/plugins/openvr/CMakeLists.txt +++ b/plugins/openvr/CMakeLists.txt @@ -11,7 +11,7 @@ if (WIN32 AND (NOT USE_GLES)) add_definitions(-DGLEW_STATIC) set(TARGET_NAME openvr) setup_hifi_plugin(Gui Qml Multimedia) - link_hifi_libraries(shared gl qml networking controllers ui + link_hifi_libraries(shared task gl qml networking controllers ui plugins display-plugins ui-plugins input-plugins script-engine audio-client render-utils graphics gpu render model-networking fbx ktx image procedural ${PLATFORM_GL_BACKEND}) From cfb64ad6938c4dec228216c3fd5d6bdc1584e932 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 9 Feb 2018 11:58:36 -0800 Subject: [PATCH 07/15] add LoggingCategory data member to JobContext --- libraries/render/src/render/Engine.h | 3 ++- libraries/task/src/task/Task.h | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index 94102b4834..0271c71529 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -25,6 +25,7 @@ namespace render { class RenderContext : public task::JobContext { public: + RenderContext() : task::JobContext(trace_render()) {} virtual ~RenderContext() {} RenderArgs* args; @@ -101,7 +102,7 @@ namespace render { protected: RenderContextPointer _renderContext; - + void run(const RenderContextPointer& context) override { assert(_renderContext); Task::run(_renderContext); } }; using EnginePointer = std::shared_ptr; diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index 3ac6614a09..2ab90411c1 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -31,9 +31,13 @@ class JobNoIO {}; class JobContext { public: + JobContext(const QLoggingCategory& category) : profileCategory(category) { + assert(category); + } virtual ~JobContext() {} std::shared_ptr jobConfig { nullptr }; + const QLoggingCategory& profileCategory; }; using JobContextPointer = std::shared_ptr; @@ -163,7 +167,9 @@ public: virtual void run(const ContextPointer& jobContext) { PerformanceTimer perfTimer(_name.c_str()); - //PROFILE_RANGE(render, _name.c_str()); + //PROFILE_RANGE(foo, _name); + //Duration profileRangeThis(trace_foo(), name); + Duration profileRange(jobContext->profileCategory, _name.c_str()); auto start = usecTimestampNow(); _concept->run(jobContext); From d59c3898dcebde9a2492daa93761bcd3e2a658ac Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 9 Feb 2018 11:59:50 -0800 Subject: [PATCH 08/15] add 'workload' logging profile --- libraries/shared/src/Profile.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/shared/src/Profile.h b/libraries/shared/src/Profile.h index fc6a2a52cb..f2a747afa3 100644 --- a/libraries/shared/src/Profile.h +++ b/libraries/shared/src/Profile.h @@ -32,6 +32,7 @@ Q_DECLARE_LOGGING_CATEGORY(trace_simulation_animation) Q_DECLARE_LOGGING_CATEGORY(trace_simulation_animation_detail) Q_DECLARE_LOGGING_CATEGORY(trace_simulation_physics) Q_DECLARE_LOGGING_CATEGORY(trace_simulation_physics_detail) +Q_DECLARE_LOGGING_CATEGORY(trace_workload) class Duration { public: From 2b1b75450d83378d58858fa697bc5479bd45db04 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 9 Feb 2018 15:47:38 -0800 Subject: [PATCH 09/15] fix assert --- libraries/task/src/task/Task.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index 2ab90411c1..3c9895d1a6 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -32,7 +32,7 @@ class JobNoIO {}; class JobContext { public: JobContext(const QLoggingCategory& category) : profileCategory(category) { - assert(category); + assert(&category); } virtual ~JobContext() {} @@ -167,8 +167,7 @@ public: virtual void run(const ContextPointer& jobContext) { PerformanceTimer perfTimer(_name.c_str()); - //PROFILE_RANGE(foo, _name); - //Duration profileRangeThis(trace_foo(), name); + // NOTE: rather than use the PROFILE_RANGE macro, we create a Duration manually Duration profileRange(jobContext->profileCategory, _name.c_str()); auto start = usecTimestampNow(); @@ -189,7 +188,7 @@ protected: // It can be created on any type T by aliasing the type JobModel in the class T // using JobModel = Task::Model // The class T is expected to have a "build" method acting as a constructor. -// The build method is where child Jobs can be added internally to the task +// The build method is where child Jobs can be added internally to the task // where the input of the task can be setup to feed the child jobs // and where the output of the task is defined template From a1c540fc85b6725d135258dc5ebba1797450319c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 12 Feb 2018 08:05:51 -0800 Subject: [PATCH 10/15] instantiate trace_workload logging category --- libraries/shared/src/Profile.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/shared/src/Profile.cpp b/libraries/shared/src/Profile.cpp index eb7440f4b3..97def2015a 100644 --- a/libraries/shared/src/Profile.cpp +++ b/libraries/shared/src/Profile.cpp @@ -27,6 +27,7 @@ Q_LOGGING_CATEGORY(trace_simulation_animation, "trace.simulation.animation") Q_LOGGING_CATEGORY(trace_simulation_animation_detail, "trace.simulation.animation.detail") Q_LOGGING_CATEGORY(trace_simulation_physics, "trace.simulation.physics") Q_LOGGING_CATEGORY(trace_simulation_physics_detail, "trace.simulation.physics.detail") +Q_LOGGING_CATEGORY(trace_workload, "trace.workload") #if defined(NSIGHT_FOUND) #include "nvToolsExt.h" From b6f81a8131dd3f84a7e7f30a80e246891bccb65b Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 12 Feb 2018 08:09:08 -0800 Subject: [PATCH 11/15] android app depends on task lib --- android/app/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/CMakeLists.txt b/android/app/CMakeLists.txt index 0ef1427306..d24a84c6a5 100644 --- a/android/app/CMakeLists.txt +++ b/android/app/CMakeLists.txt @@ -1,6 +1,6 @@ set(TARGET_NAME native-lib) setup_hifi_library() -link_hifi_libraries(shared networking gl gpu qml image fbx render-utils physics entities octree ${PLATFORM_GL_BACKEND}) +link_hifi_libraries(shared task networking gl gpu qml image fbx render-utils physics entities octree ${PLATFORM_GL_BACKEND}) target_opengl() target_bullet() From f1495d27f65d669629e3f3ea1b81c2762c58a7f3 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 12 Feb 2018 08:56:04 -0800 Subject: [PATCH 12/15] try task link dependency rather than include --- libraries/render/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/render/CMakeLists.txt b/libraries/render/CMakeLists.txt index 08f0e07b8f..2a888a5b18 100644 --- a/libraries/render/CMakeLists.txt +++ b/libraries/render/CMakeLists.txt @@ -3,7 +3,6 @@ AUTOSCRIBE_SHADER_LIB(gpu graphics) setup_hifi_library() # render needs octree only for getAccuracyAngle(float, int) -link_hifi_libraries(shared ktx gpu graphics octree) -include_hifi_library_headers(task) +link_hifi_libraries(shared task ktx gpu graphics octree) target_nsight() From 95b34cf112fbaf42fc5c7968c74b0cf69c3f1425 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 12 Feb 2018 10:32:19 -0800 Subject: [PATCH 13/15] remove cruft and extra whitespace --- libraries/task/src/task/Config.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libraries/task/src/task/Config.h b/libraries/task/src/task/Config.h index 8f23efe031..36dfb35f25 100644 --- a/libraries/task/src/task/Config.h +++ b/libraries/task/src/task/Config.h @@ -20,8 +20,6 @@ #include "SettingHandle.h" -//#include "Logging.h" - namespace task { class JobConcept; @@ -140,12 +138,12 @@ public: TaskConfig(bool enabled) : JobConfig(enabled) {} - + // Get a sub job config through task.getConfig(path) // where path can be: // - search for the first job named job_name traversing the the sub graph of task and jobs (from this task as root) // - .[.] - // Allowing to first look for the parent_name job (from this task as root) and then search from there for the + // Allowing to first look for the parent_name job (from this task as root) and then search from there for the // optional sub_parent_names and finally from there looking for the job_name (assuming every job in the path were found) // // getter for qml integration, prefer the templated getter @@ -174,7 +172,7 @@ public: void connectChildConfig(QConfigPointer childConfig, const std::string& name); void transferChildrenConfigs(QConfigPointer source); - + JobConcept* _task; public slots: @@ -182,7 +180,7 @@ public slots: }; using QConfigPointer = std::shared_ptr; - + } #endif // hifi_task_Config_h From 01fb8f336956527fbe68a29f8c71a44d1e557c1b Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 12 Feb 2018 10:41:54 -0800 Subject: [PATCH 14/15] remove cruft --- libraries/task/src/task/Task.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index 3c9895d1a6..b75f6d7321 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -17,8 +17,6 @@ #include "SettingHandle.h" -//#include "Logging.h" - #include #include From 38bc3120042a61e0a15a5e02a82f489af71b25df Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 13 Feb 2018 11:25:34 -0800 Subject: [PATCH 15/15] faster and const EntityTree::findByID() --- libraries/entities/src/EntityTree.cpp | 21 ++++++++++++++------- libraries/entities/src/EntityTree.h | 6 +++--- libraries/shared/src/SpatialParentFinder.h | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index bf29f3bec9..60bcc85575 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -913,18 +913,25 @@ void EntityTree::findEntities(RecurseOctreeOperation& elementFilter, recurseTreeWithOperation(elementFilter, nullptr); } -EntityItemPointer EntityTree::findEntityByID(const QUuid& id) { +EntityItemPointer EntityTree::findEntityByID(const QUuid& id) const { EntityItemID entityID(id); return findEntityByEntityItemID(entityID); } -EntityItemPointer EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) /*const*/ { - EntityItemPointer foundEntity = NULL; - EntityTreeElementPointer containingElement = getContainingElement(entityID); - if (containingElement) { - foundEntity = containingElement->getEntityWithEntityItemID(entityID); +EntityItemPointer EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) const { + EntityItemPointer foundEntity = nullptr; + { + QReadLocker locker(&_entityMapLock); + foundEntity = _entityMap.value(entityID); + } + if (foundEntity && !foundEntity->getElement()) { + // special case to maintain legacy behavior: + // if the entity is in the map but not in the tree + // then pretend the entity doesn't exist + return EntityItemPointer(nullptr); + } else { + return foundEntity; } - return foundEntity; } void EntityTree::fixupTerseEditLogging(EntityItemProperties& properties, QList& changedProperties) { diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 8cb89d6493..90fe342f57 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -132,9 +132,9 @@ public: /// \param position point of query in world-frame (meters) /// \param targetRadius radius of query (meters) EntityItemPointer findClosestEntity(const glm::vec3& position, float targetRadius); - EntityItemPointer findEntityByID(const QUuid& id); - EntityItemPointer findEntityByEntityItemID(const EntityItemID& entityID); - virtual SpatiallyNestablePointer findByID(const QUuid& id) override { return findEntityByID(id); } + EntityItemPointer findEntityByID(const QUuid& id) const; + EntityItemPointer findEntityByEntityItemID(const EntityItemID& entityID) const; + virtual SpatiallyNestablePointer findByID(const QUuid& id) const override { return findEntityByID(id); } EntityItemID assignEntityID(const EntityItemID& entityItemID); /// Assigns a known ID for a creator token ID diff --git a/libraries/shared/src/SpatialParentFinder.h b/libraries/shared/src/SpatialParentFinder.h index aae7d9f040..c19babbc7f 100644 --- a/libraries/shared/src/SpatialParentFinder.h +++ b/libraries/shared/src/SpatialParentFinder.h @@ -21,7 +21,7 @@ using SpatiallyNestableWeakPointer = std::weak_ptr; using SpatiallyNestablePointer = std::shared_ptr; class SpatialParentTree { public: - virtual SpatiallyNestablePointer findByID(const QUuid& id) { return nullptr; } + virtual SpatiallyNestablePointer findByID(const QUuid& id) const { return nullptr; } }; class SpatialParentFinder : public Dependency {