- 多出来的 + 1?这里为什么多分配一个 PxVec3 呢?
nbPrimitives+1
bool AABBTree::buildInit(AABBTreeBuildParams& params, BuildStats& stats) | |
{ | |
// Checkings | |
const PxU32 nbPrimitives = params.mNbPrimitives; | |
if(!nbPrimitives) | |
return false; | |
// Release previous tree | |
release(); | |
// Init stats | |
stats.setCount(1); | |
// Initialize indices. This list will be modified during build. | |
mNbIndices = nbPrimitives; | |
mIndices = reinterpret_cast<PxU32*>(PX_ALLOC(sizeof(PxU32)*nbPrimitives, "AABB tree indices")); | |
// Identity permutation | |
for(PxU32 i=0;i<nbPrimitives;i++) | |
mIndices[i] = i; | |
// Allocate a pool of nodes | |
mNodeAllocator.init(nbPrimitives, params.mLimit); | |
// Compute box centers only once and cache them | |
params.mCache = reinterpret_cast<PxVec3*>(PX_ALLOC(sizeof(PxVec3)*(nbPrimitives+1), "cache")); | |
const float half = 0.5f; | |
const FloatV halfV = FLoad(half); | |
for(PxU32 i=0;i<nbPrimitives;i++) | |
{ | |
const Vec4V curMinV = V4LoadU(¶ms.mAABBArray[i].minimum.x); | |
const Vec4V curMaxV = V4LoadU(¶ms.mAABBArray[i].maximum.x); | |
const Vec4V centerV = V4Scale(V4Add(curMaxV, curMinV), halfV); | |
V4StoreU(centerV, ¶ms.mCache[i].x); | |
} | |
return true; | |
} |
为啥要用 Vec4 的接口来处理 Vec3 ?部分操作是 128 字节对齐例如 V4StoreU -> _mm_storeu_ps,另外这里参数还是反的比较有意思。
SqExtendedBucketPruner.cpp 的 refitMarkedNodes 有问题: