exact SAH-optimized kd-tree builder works for the first time (without primitive clipping)
parent
577a732cd0
commit
679cd18613
|
@ -109,6 +109,13 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* Uh oh, allocation could not be found. Check if it has size==0 */
|
||||||
|
for (std::vector<Chunk>::iterator it = m_chunks.begin();
|
||||||
|
it != m_chunks.end(); ++it) {
|
||||||
|
const Chunk &chunk = *it;
|
||||||
|
if ((uint8_t *) ptr == chunk.start + chunk.size)
|
||||||
|
return;
|
||||||
|
}
|
||||||
SLog(EError, "OrderedChunkAllocator: Internal error while"
|
SLog(EError, "OrderedChunkAllocator: Internal error while"
|
||||||
" releasing memory");
|
" releasing memory");
|
||||||
}
|
}
|
||||||
|
@ -127,6 +134,15 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* Uh oh, allocation could not be found. Check if it has size==0 */
|
||||||
|
if (newSize == 0) {
|
||||||
|
for (std::vector<Chunk>::iterator it = m_chunks.begin();
|
||||||
|
it != m_chunks.end(); ++it) {
|
||||||
|
const Chunk &chunk = *it;
|
||||||
|
if ((uint8_t *) ptr == chunk.start + chunk.size)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
SLog(EError, "OrderedChunkAllocator: Internal error in shrinkAllocation");
|
SLog(EError, "OrderedChunkAllocator: Internal error in shrinkAllocation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +151,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* \brief Return the total amount of chunk memory in bytes
|
* \brief Return the total amount of chunk memory in bytes
|
||||||
*/
|
*/
|
||||||
inline size_t getSize() const {
|
size_t getSize() const {
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
for (std::vector<Chunk>::const_iterator it = m_chunks.begin();
|
for (std::vector<Chunk>::const_iterator it = m_chunks.begin();
|
||||||
it != m_chunks.end(); ++it)
|
it != m_chunks.end(); ++it)
|
||||||
|
@ -146,13 +162,25 @@ public:
|
||||||
/**
|
/**
|
||||||
* \brief Return the total amount of used memory in bytes
|
* \brief Return the total amount of used memory in bytes
|
||||||
*/
|
*/
|
||||||
inline size_t getUsed() const {
|
size_t getUsed() const {
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
for (std::vector<Chunk>::const_iterator it = m_chunks.begin();
|
for (std::vector<Chunk>::const_iterator it = m_chunks.begin();
|
||||||
it != m_chunks.end(); ++it)
|
it != m_chunks.end(); ++it)
|
||||||
result += (*it).getUsed();
|
result += (*it).getUsed();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Return a string representation of the chunks
|
||||||
|
*/
|
||||||
|
std::string toString() const {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "OrderedChunkAllocator[" << endl;
|
||||||
|
for (size_t i=0; i<m_chunks.size(); ++i)
|
||||||
|
oss << " Chunk " << i << ": " << m_chunks[i].toString() << endl;
|
||||||
|
oss << "]";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Chunk {
|
struct Chunk {
|
||||||
|
@ -166,6 +194,12 @@ private:
|
||||||
inline size_t getRemainder() const {
|
inline size_t getRemainder() const {
|
||||||
return size - getUsed();
|
return size - getUsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string toString() const {
|
||||||
|
return formatString("0x%llx-0x%llx (size=" SIZE_T_FMT
|
||||||
|
", used=" SIZE_T_FMT ")", start, start+size,
|
||||||
|
size, getUsed());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<Chunk> m_chunks;
|
std::vector<Chunk> m_chunks;
|
||||||
|
@ -246,7 +280,7 @@ public:
|
||||||
m_stopPrims = 2;
|
m_stopPrims = 2;
|
||||||
m_maxBadRefines = 3;
|
m_maxBadRefines = 3;
|
||||||
m_exactDepth = 1;
|
m_exactDepth = 1;
|
||||||
m_maxDepth = 7;
|
m_maxDepth = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -831,11 +865,12 @@ protected:
|
||||||
++badRefines;
|
++badRefines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
cout << "Depth " << depth << endl;
|
cout << "Depth " << depth << endl;
|
||||||
cout << "AABB: " << nodeAABB.toString() << endl;
|
cout << "AABB: " << nodeAABB.toString() << endl;
|
||||||
cout << "SAH cost: " << leafCost << " -> " << bestSplit.toString() << endl;
|
cout << "SAH cost: " << leafCost << " -> " << bestSplit.toString() << endl;
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ==================================================================== */
|
/* ==================================================================== */
|
||||||
/* Partitioning */
|
/* Partitioning */
|
||||||
|
@ -1087,10 +1122,12 @@ protected:
|
||||||
|
|
||||||
Assert(bestSplit.sahCost != std::numeric_limits<Float>::infinity());
|
Assert(bestSplit.sahCost != std::numeric_limits<Float>::infinity());
|
||||||
|
|
||||||
|
#if 0
|
||||||
cout << "Depth " << depth << endl;
|
cout << "Depth " << depth << endl;
|
||||||
cout << "AABB: " << nodeAABB.toString() << endl;
|
cout << "AABB: " << nodeAABB.toString() << endl;
|
||||||
cout << "SAH cost: " << leafCost << " -> " << bestSplit.toString() << endl;
|
cout << "SAH cost: " << leafCost << " -> " << bestSplit.toString() << endl;
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* "Bad refines" heuristic from PBRT */
|
/* "Bad refines" heuristic from PBRT */
|
||||||
if (bestSplit.sahCost >= leafCost) {
|
if (bestSplit.sahCost >= leafCost) {
|
||||||
|
@ -1099,7 +1136,6 @@ protected:
|
||||||
createLeaf(ctx, node, nodeAABB, primCount);
|
createLeaf(ctx, node, nodeAABB, primCount);
|
||||||
return leafCost;
|
return leafCost;
|
||||||
}
|
}
|
||||||
cout << "Increasing bad refines " << primCount << ", leafCost=" << leafCost << ", sahCost=" << bestSplit.sahCost << endl;
|
|
||||||
++badRefines;
|
++badRefines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1306,12 +1342,12 @@ protected:
|
||||||
|
|
||||||
/* Shrink the edge event storage now that we know exactly how
|
/* Shrink the edge event storage now that we know exactly how
|
||||||
many are on each side */
|
many are on each side */
|
||||||
// ctx.leftAlloc.shrinkAllocation(leftEventsStart,
|
ctx.leftAlloc.shrinkAllocation(leftEventsStart,
|
||||||
// leftEventsEnd - leftEventsStart);
|
leftEventsEnd - leftEventsStart);
|
||||||
|
|
||||||
|
ctx.rightAlloc.shrinkAllocation(rightEventsStart,
|
||||||
|
rightEventsEnd - rightEventsStart);
|
||||||
|
|
||||||
// ctx.rightAlloc.shrinkAllocation(rightEventsStart,
|
|
||||||
// rightEventsEnd - rightEventsStart);
|
|
||||||
|
|
||||||
/* ==================================================================== */
|
/* ==================================================================== */
|
||||||
/* Recursion */
|
/* Recursion */
|
||||||
/* ==================================================================== */
|
/* ==================================================================== */
|
||||||
|
|
Loading…
Reference in New Issue