From 1e71e819f4a66146124ec9cc71d3fc0b1254f643 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 22 Feb 2018 12:04:25 -0800 Subject: [PATCH 1/3] update space view according to main ViewFrustum --- interface/src/Application.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0c654e9196..00c4b06378 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4169,6 +4169,14 @@ void Application::idle() { } { + // TEMP HACK: one view with static radiuses + float r0 = 10.0f; + float r1 = 20.0f; + float r2 = 30.0f; + workload::Space::View view(_viewFrustum.getPosition(), r0, r1, r2); + std::vector views; + views.push_back(view); + getEntities()->getWorkloadSpace()->setViews(views); _gameWorkload._engine->run(); } { From c1b8f12b7f81d7d6b08901faf539007668228270 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 22 Feb 2018 13:06:39 -0800 Subject: [PATCH 2/3] compute Space changes --- .../src/workload/ClassificationTracker.cpp | 14 ++++- .../src/workload/ClassificationTracker.h | 2 +- libraries/workload/src/workload/Space.h | 53 ++++++++++++++++--- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/libraries/workload/src/workload/ClassificationTracker.cpp b/libraries/workload/src/workload/ClassificationTracker.cpp index 009549737f..15066b1050 100644 --- a/libraries/workload/src/workload/ClassificationTracker.cpp +++ b/libraries/workload/src/workload/ClassificationTracker.cpp @@ -18,7 +18,17 @@ using namespace workload; void ClassificationTracker::configure(const Config& config) { } -void ClassificationTracker::run(const workload::WorkloadContextPointer& renderContext, Outputs& outputs) { - +void ClassificationTracker::run(const WorkloadContextPointer& context, Outputs& outputs) { + auto space = context->_space; + if (space) { + Changes changes; + space->categorizeAndGetChanges(changes); + outputs.resize(workload::Space::NUM_TRANSITIONS); + for (uint32_t i = 0; i < changes.size(); ++i) { + int32_t j = Space::computeTransitionIndex(changes[i].prevRegion, changes[i].region); + assert(j >= 0 && j < workload::Space::NUM_TRANSITIONS); + outputs[j].push_back(changes[i].proxyId); + } + } } diff --git a/libraries/workload/src/workload/ClassificationTracker.h b/libraries/workload/src/workload/ClassificationTracker.h index ca7a919769..e3364950da 100644 --- a/libraries/workload/src/workload/ClassificationTracker.h +++ b/libraries/workload/src/workload/ClassificationTracker.h @@ -29,7 +29,7 @@ namespace workload { class ClassificationTracker { public: using Config = ClassificationTrackerConfig; - using Outputs = Classifications; + using Outputs = SortedChanges; using JobModel = workload::Job::ModelO; ClassificationTracker() {} diff --git a/libraries/workload/src/workload/Space.h b/libraries/workload/src/workload/Space.h index ee06383288..eef1fc17cd 100644 --- a/libraries/workload/src/workload/Space.h +++ b/libraries/workload/src/workload/Space.h @@ -24,6 +24,11 @@ namespace workload { class Space { public: + static const int32_t NUM_CLASSIFICATIONS = 4; + static const int32_t NUM_TRANSITIONS = NUM_CLASSIFICATIONS * (NUM_CLASSIFICATIONS - 1); + + static int32_t computeTransitionIndex(int32_t prevIndex, int32_t newIndex); + static const uint8_t REGION_NEAR = 0; static const uint8_t REGION_MIDDLE = 1; static const uint8_t REGION_FAR = 2; @@ -45,12 +50,12 @@ public: 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; + radiuses[REGION_NEAR] = nearRadius; + radiuses[REGION_MIDDLE] = midRadius; + radiuses[REGION_FAR] = farRadius; } - glm::vec3 center { 0.0f, 0.0f, 0.0f }; - float radiuses[3] { 0.0f, 0.0f, 0.0f }; + glm::vec3 center; + float radiuses[NUM_CLASSIFICATIONS - 1]; }; class Change { @@ -84,8 +89,44 @@ private: std::vector _freeIndices; }; +inline int32_t Space::computeTransitionIndex(int32_t prevIndex, int32_t newIndex) { + // given prevIndex and newIndex compute an index into the transition list, + // where the lists between unchanged indices don't exist (signaled by index = -1). + // + // Given an NxN array + // let p = i + N * j + // + // then k = -1 when i == j + // = p - (1 + p/(N+1)) when i != j + // + // i 0 1 2 3 + // j +-------+-------+-------+-------+ + // |p = 0 | 1 | 2 | 3 | + // 0 | | | | | + // |k = -1 | 0 | 1 | 2 | + // +-------+-------+-------+-------+ + // | 4 | 5 | 6 | 7 | + // 1 | | | | | + // | 3 | -1 | 4 | 5 | + // +-------+-------+-------+-------+ + // | 8 | 9 | 10 | 11 | + // 2 | | | | | + // | 6 | 7 | -1 | 8 | + // +-------+-------+-------+-------+ + // | 12 | 13 | 14 | 15 | + // 3 | | | | | + // | 9 | 10 | 11 | -1 | + // +-------+-------+-------+-------+ + int32_t p = prevIndex + Space::NUM_CLASSIFICATIONS * newIndex; + if (0 == (p % (Space::NUM_CLASSIFICATIONS + 1))) { + return -1; + } + return p - (1 + p / (Space::NUM_CLASSIFICATIONS + 1)); +} + using SpacePointer = std::shared_ptr; -using Classifications = std::vector; +using Changes = std::vector; +using SortedChanges = std::vector>; } // namespace workload From a4442828bef673cc92842e1610b04cf6a72ed6ef Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 22 Feb 2018 14:39:13 -0800 Subject: [PATCH 3/3] fix workoad unit tests --- tests/workload/src/SpaceTests.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/workload/src/SpaceTests.cpp b/tests/workload/src/SpaceTests.cpp index 1c6b0491a7..23e12074ea 100644 --- a/tests/workload/src/SpaceTests.cpp +++ b/tests/workload/src/SpaceTests.cpp @@ -55,7 +55,9 @@ void SpaceTests::testOverlaps() { 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); + std::vector updates; + updates.push_back(workload::Space::ProxyUpdate(proxyId, newSphere)); + space.updateProxies(updates); Changes changes; space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 1); @@ -68,7 +70,9 @@ void SpaceTests::testOverlaps() { 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); + std::vector updates; + updates.push_back(workload::Space::ProxyUpdate(proxyId, newSphere)); + space.updateProxies(updates); Changes changes; space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 1); @@ -81,7 +85,9 @@ void SpaceTests::testOverlaps() { 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); + std::vector updates; + updates.push_back(workload::Space::ProxyUpdate(proxyId, newSphere)); + space.updateProxies(updates); Changes changes; space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 1); @@ -92,7 +98,9 @@ void SpaceTests::testOverlaps() { { // delete proxy // NOTE: atm deleting a proxy doesn't result in a "Change" - space.deleteProxy(proxyId); + std::vector deadProxies; + deadProxies.push_back(proxyId); + space.deleteProxies(deadProxies); Changes changes; space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 0); @@ -145,9 +153,9 @@ 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; + std::vector timeToRemoveAll; for (uint32_t i = 0; i < numTests; ++i) { workload::Space space;