Merge branch 'workload' of https://github.com/highfidelity/hifi into workload

This commit is contained in:
samcake 2018-02-28 09:25:24 -08:00
commit 66f1b7f1fc
5 changed files with 81 additions and 14 deletions

View file

@ -4170,6 +4170,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<workload::Space::View> views;
views.push_back(view);
getEntities()->getWorkloadSpace()->setViews(views);
_gameWorkload._engine->run();
}
{

View file

@ -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);
}
}
}

View file

@ -29,7 +29,7 @@ namespace workload {
class ClassificationTracker {
public:
using Config = ClassificationTrackerConfig;
using Outputs = Classifications;
using Outputs = SortedChanges;
using JobModel = workload::Job::ModelO<ClassificationTracker, Outputs, Config>;
ClassificationTracker() {}

View file

@ -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;
@ -47,12 +52,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 {
@ -86,8 +91,44 @@ private:
std::vector<int32_t> _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<Space>;
using Classifications = std::vector<Space::Change>;
using Changes = std::vector<Space::Change>;
using SortedChanges = std::vector<std::vector<int32_t>>;
} // namespace workload

View file

@ -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<workload::Space::ProxyUpdate> 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<workload::Space::ProxyUpdate> 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<workload::Space::ProxyUpdate> 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<int32_t> 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<uint64_t> timeToAddAll;
std::vector<uint64_t> timeToRemoveAll;
std::vector<uint64_t> timeToMoveView;
std::vector<uint64_t> timeToMoveProxies;
std::vector<uint64_t> timeToRemoveAll;
for (uint32_t i = 0; i < numTests; ++i) {
workload::Space space;