This commit is contained in:
SamGondelman 2018-08-31 11:25:17 -07:00
parent 5f08ed5027
commit d01b438cb3
7 changed files with 50 additions and 15 deletions

View file

@ -264,9 +264,11 @@ void AvatarManager::updateOtherAvatars(float deltaTime) {
const SortableAvatar& newSortData = *it; const SortableAvatar& newSortData = *it;
const auto newAvatar = std::static_pointer_cast<Avatar>(newSortData.getAvatar()); const auto newAvatar = std::static_pointer_cast<Avatar>(newSortData.getAvatar());
bool inView = newSortData.getPriority() > OUT_OF_VIEW_THRESHOLD; bool inView = newSortData.getPriority() > OUT_OF_VIEW_THRESHOLD;
if (inView && newAvatar->hasNewJointData()) { // Once we reach an avatar that's not in view, all avatars after it will also be out of view
numAVatarsNotUpdated++; if (!inView) {
break;
} }
numAVatarsNotUpdated += (int)(newAvatar->hasNewJointData());
++it; ++it;
} }
break; break;

View file

@ -56,18 +56,16 @@ namespace buffer_helpers {
tangent = glm::clamp(tangent, -1.0f, 1.0f); tangent = glm::clamp(tangent, -1.0f, 1.0f);
normal *= 511.0f; normal *= 511.0f;
tangent *= 511.0f; tangent *= 511.0f;
normal = fastRoundf(normal);
tangent = fastRoundf(tangent);
glm::detail::i10i10i10i2 normalStruct; glm::detail::i10i10i10i2 normalStruct;
glm::detail::i10i10i10i2 tangentStruct; glm::detail::i10i10i10i2 tangentStruct;
normalStruct.data.x = int(normal.x); normalStruct.data.x = fastLrintf(normal.x);
normalStruct.data.y = int(normal.y); normalStruct.data.y = fastLrintf(normal.y);
normalStruct.data.z = int(normal.z); normalStruct.data.z = fastLrintf(normal.z);
normalStruct.data.w = 0; normalStruct.data.w = 0;
tangentStruct.data.x = int(tangent.x); tangentStruct.data.x = fastLrintf(tangent.x);
tangentStruct.data.y = int(tangent.y); tangentStruct.data.y = fastLrintf(tangent.y);
tangentStruct.data.z = int(tangent.z); tangentStruct.data.z = fastLrintf(tangent.z);
tangentStruct.data.w = 0; tangentStruct.data.w = 0;
packedNormal = normalStruct.pack; packedNormal = normalStruct.pack;
packedTangent = tangentStruct.pack; packedTangent = tangentStruct.pack;

View file

@ -79,6 +79,16 @@ void AABox::setBox(const glm::vec3& corner, const glm::vec3& scale) {
glm::vec3 AABox::getFarthestVertex(const glm::vec3& normal) const { glm::vec3 AABox::getFarthestVertex(const glm::vec3& normal) const {
glm::vec3 result = _corner; glm::vec3 result = _corner;
// This is a branchless version of:
//if (normal.x > 0.0f) {
// result.x += _scale.x;
//}
//if (normal.y > 0.0f) {
// result.y += _scale.y;
//}
//if (normal.z > 0.0f) {
// result.z += _scale.z;
//}
float blend = (float)(normal.x > 0.0f); float blend = (float)(normal.x > 0.0f);
result.x += blend * _scale.x + (1.0f - blend) * 0.0f; result.x += blend * _scale.x + (1.0f - blend) * 0.0f;
blend = (float)(normal.y > 0.0f); blend = (float)(normal.y > 0.0f);
@ -90,6 +100,16 @@ glm::vec3 AABox::getFarthestVertex(const glm::vec3& normal) const {
glm::vec3 AABox::getNearestVertex(const glm::vec3& normal) const { glm::vec3 AABox::getNearestVertex(const glm::vec3& normal) const {
glm::vec3 result = _corner; glm::vec3 result = _corner;
// This is a branchless version of:
//if (normal.x < 0.0f) {
// result.x += _scale.x;
//}
//if (normal.y < 0.0f) {
// result.y += _scale.y;
//}
//if (normal.z < 0.0f) {
// result.z += _scale.z;
//}
float blend = (float)(normal.x < 0.0f); float blend = (float)(normal.x < 0.0f);
result.x += blend * _scale.x + (1.0f - blend) * 0.0f; result.x += blend * _scale.x + (1.0f - blend) * 0.0f;
blend = (float)(normal.y < 0.0f); blend = (float)(normal.y < 0.0f);

View file

@ -86,6 +86,15 @@ public:
AABox clamp(float min, float max) const; AABox clamp(float min, float max) const;
inline AABox& operator+=(const glm::vec3& point) { inline AABox& operator+=(const glm::vec3& point) {
// Branchless version of:
//if (isInvalid()) {
// _corner = glm::min(_corner, point);
//} else {
// glm::vec3 maximum(_corner + _scale);
// _corner = glm::min(_corner, point);
// maximum = glm::max(maximum, point);
// _scale = maximum - _corner;
//}
float blend = (float)isInvalid(); float blend = (float)isInvalid();
glm::vec3 maximumScale(glm::max(_scale, point - _corner)); glm::vec3 maximumScale(glm::max(_scale, point - _corner));
_corner = glm::min(_corner, point); _corner = glm::min(_corner, point);

View file

@ -316,11 +316,16 @@ inline void glm_mat4u_mul(const glm::mat4& m1, const glm::mat4& m2, glm::mat4& r
#endif #endif
} }
inline glm::vec3 fastRoundf(const glm::vec3& vec) { // convert float to int, using round-to-nearest-even (undefined on overflow)
inline int fastLrintf(float x) {
#if GLM_ARCH & GLM_ARCH_SSE2_BIT #if GLM_ARCH & GLM_ARCH_SSE2_BIT
return glm::vec3(_mm_cvt_ss2si(_mm_set_ss(vec.x)), _mm_cvt_ss2si(_mm_set_ss(vec.y)), _mm_cvt_ss2si(_mm_set_ss(vec.z))); return _mm_cvt_ss2si(_mm_set_ss(x));
#else #else
return glm::round(vec); // return lrintf(x);
static_assert(std::numeric_limits<double>::is_iec559, "Requires IEEE-754 double precision format");
union { double d; int64_t i; } bits = { (double)x };
bits.d += (3ULL << 51);
return (int)bits.i;
#endif #endif
} }

View file

@ -168,12 +168,13 @@ void AACubeTests::rayVsParabolaPerformance() {
glm::vec3 origin(0.0f); glm::vec3 origin(0.0f);
glm::vec3 direction = glm::normalize(glm::vec3(1.0f)); glm::vec3 direction = glm::normalize(glm::vec3(1.0f));
glm::vec3 invDirection = 1.0f / direction;
float distance; float distance;
BoxFace face; BoxFace face;
glm::vec3 normal; glm::vec3 normal;
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
for (auto& cube : cubes) { for (auto& cube : cubes) {
if (cube.findRayIntersection(origin, direction, 1.0f / direction, distance, face, normal)) { if (cube.findRayIntersection(origin, direction, invDirection, distance, face, normal)) {
numRayHits++; numRayHits++;
} }
} }

View file

@ -234,7 +234,7 @@ void GLMHelpersTests::roundPerf() {
auto glmTime = std::chrono::high_resolution_clock::now() - start; auto glmTime = std::chrono::high_resolution_clock::now() - start;
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
for (auto& vec : vecs2) { for (auto& vec : vecs2) {
vec = fastRoundf(vec); vec = glm::vec3(fastLrintf(vec.x), fastLrintf(vec.y), fastLrintf(vec.z));
} }
auto manualTime = std::chrono::high_resolution_clock::now() - start; auto manualTime = std::chrono::high_resolution_clock::now() - start;