NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SplitBVHBuilder.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2011, NVIDIA Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "bvh/SplitBVHBuilder.hpp"
29 #include "base/Sort.hpp"
30 
31 using namespace FW;
32 
33 //------------------------------------------------------------------------
34 
36 : m_bvh (bvh),
37  m_platform (bvh.getPlatform()),
38  m_params (params),
39  m_minOverlap (0.0f),
40  m_sortDim (-1)
41 {
42 }
43 
44 //------------------------------------------------------------------------
45 
47 {
48 }
49 
50 //------------------------------------------------------------------------
51 
53 {
54  // Initialize reference stack and determine root bounds.
55 
56  const Vec3i* tris = (const Vec3i*)m_bvh.getScene()->getTriVtxIndexBuffer().getPtr();
57  const Vec3f* verts = (const Vec3f*)m_bvh.getScene()->getVtxPosBuffer().getPtr();
58 
59  NodeSpec rootSpec;
60  rootSpec.numRef = m_bvh.getScene()->getNumTriangles();
61  m_refStack.resize(rootSpec.numRef);
62 
63  for (int i = 0; i < rootSpec.numRef; i++)
64  {
65  m_refStack[i].triIdx = i;
66  for (int j = 0; j < 3; j++)
67  m_refStack[i].bounds.grow(verts[tris[i][j]]);
68  rootSpec.bounds.grow(m_refStack[i].bounds);
69  }
70 
71  // Initialize rest of the members.
72 
74  m_rightBounds.reset(max(rootSpec.numRef, (int)NumSpatialBins) - 1);
75  m_numDuplicates = 0;
77 
78  // Build recursively.
79 
80  BVHNode* root = buildNode(rootSpec, 0, 0.0f, 1.0f);
82 
83  // Done.
84 
86  printf("SplitBVHBuilder: progress %.0f%%, duplicates %.0f%%\n",
87  100.0f, (F32)m_numDuplicates / (F32)m_bvh.getScene()->getNumTriangles() * 100.0f);
88  return root;
89 }
90 
91 //------------------------------------------------------------------------
92 
93 bool SplitBVHBuilder::sortCompare(void* data, int idxA, int idxB)
94 {
95  const SplitBVHBuilder* ptr = (const SplitBVHBuilder*)data;
96  int dim = ptr->m_sortDim;
97  const Reference& ra = ptr->m_refStack[idxA];
98  const Reference& rb = ptr->m_refStack[idxB];
99  F32 ca = ra.bounds.min()[dim] + ra.bounds.max()[dim];
100  F32 cb = rb.bounds.min()[dim] + rb.bounds.max()[dim];
101  return (ca < cb || (ca == cb && ra.triIdx < rb.triIdx));
102 }
103 
104 //------------------------------------------------------------------------
105 
106 void SplitBVHBuilder::sortSwap(void* data, int idxA, int idxB)
107 {
109  swap(ptr->m_refStack[idxA], ptr->m_refStack[idxB]);
110 }
111 
112 //------------------------------------------------------------------------
113 
114 BVHNode* SplitBVHBuilder::buildNode(NodeSpec spec, int level, F32 progressStart, F32 progressEnd)
115 {
116  // Display progress.
117 
119  {
120  printf("SplitBVHBuilder: progress %.0f%%, duplicates %.0f%%\r",
121  progressStart * 100.0f, (F32)m_numDuplicates / (F32)m_bvh.getScene()->getNumTriangles() * 100.0f);
123  }
124 
125  // Remove degenerates.
126  {
127  int firstRef = m_refStack.getSize() - spec.numRef;
128  for (int i = m_refStack.getSize() - 1; i >= firstRef; i--)
129  {
130  Vec3f size = m_refStack[i].bounds.max() - m_refStack[i].bounds.min();
131  if (min(size) < 0.0f || sum(size) == max(size))
133  }
134  spec.numRef = m_refStack.getSize() - firstRef;
135  }
136 
137  // Small enough or too deep => create leaf.
138 
139  if (spec.numRef <= m_platform.getMinLeafSize() || level >= MaxDepth)
140  return createLeaf(spec);
141 
142  // Find split candidates.
143 
144  F32 area = spec.bounds.area();
145  F32 leafSAH = area * m_platform.getTriangleCost(spec.numRef);
146  F32 nodeSAH = area * m_platform.getNodeCost(2);
147  ObjectSplit object = findObjectSplit(spec, nodeSAH);
148 
149  SpatialSplit spatial;
150  if (level < MaxSpatialDepth)
151  {
152  AABB overlap = object.leftBounds;
153  overlap.intersect(object.rightBounds);
154  if (overlap.area() >= m_minOverlap)
155  spatial = findSpatialSplit(spec, nodeSAH);
156  }
157 
158  // Leaf SAH is the lowest => create leaf.
159 
160  F32 minSAH = min(leafSAH, object.sah, spatial.sah);
161  if (minSAH == leafSAH && spec.numRef <= m_platform.getMaxLeafSize())
162  return createLeaf(spec);
163 
164  // Perform split.
165 
166  NodeSpec left, right;
167  if (minSAH == spatial.sah)
168  performSpatialSplit(left, right, spec, spatial);
169  if (!left.numRef || !right.numRef)
170  performObjectSplit(left, right, spec, object);
171 
172  // Create inner node.
173 
174  m_numDuplicates += left.numRef + right.numRef - spec.numRef;
175  F32 progressMid = lerp(progressStart, progressEnd, (F32)right.numRef / (F32)(left.numRef + right.numRef));
176  BVHNode* rightNode = buildNode(right, level + 1, progressStart, progressMid);
177  BVHNode* leftNode = buildNode(left, level + 1, progressMid, progressEnd);
178  return new InnerNode(spec.bounds, leftNode, rightNode);
179 }
180 
181 //------------------------------------------------------------------------
182 
184 {
185  Array<S32>& tris = m_bvh.getTriIndices();
186  for (int i = 0; i < spec.numRef; i++)
188  return new LeafNode(spec.bounds, tris.getSize() - spec.numRef, tris.getSize());
189 }
190 
191 //------------------------------------------------------------------------
192 
194 {
195  ObjectSplit split;
196  const Reference* refPtr = m_refStack.getPtr(m_refStack.getSize() - spec.numRef);
197  F32 bestTieBreak = FW_F32_MAX;
198 
199  // Sort along each dimension.
200 
201  for (m_sortDim = 0; m_sortDim < 3; m_sortDim++)
202  {
204 
205  // Sweep right to left and determine bounds.
206 
207  AABB rightBounds;
208  for (int i = spec.numRef - 1; i > 0; i--)
209  {
210  rightBounds.grow(refPtr[i].bounds);
211  m_rightBounds[i - 1] = rightBounds;
212  }
213 
214  // Sweep left to right and select lowest SAH.
215 
216  AABB leftBounds;
217  for (int i = 1; i < spec.numRef; i++)
218  {
219  leftBounds.grow(refPtr[i - 1].bounds);
220  F32 sah = nodeSAH + leftBounds.area() * m_platform.getTriangleCost(i) + m_rightBounds[i - 1].area() * m_platform.getTriangleCost(spec.numRef - i);
221  F32 tieBreak = sqr((F32)i) + sqr((F32)(spec.numRef - i));
222  if (sah < split.sah || (sah == split.sah && tieBreak < bestTieBreak))
223  {
224  split.sah = sah;
225  split.sortDim = m_sortDim;
226  split.numLeft = i;
227  split.leftBounds = leftBounds;
228  split.rightBounds = m_rightBounds[i - 1];
229  bestTieBreak = tieBreak;
230  }
231  }
232  }
233  return split;
234 }
235 
236 //------------------------------------------------------------------------
237 
238 void SplitBVHBuilder::performObjectSplit(NodeSpec& left, NodeSpec& right, const NodeSpec& spec, const ObjectSplit& split)
239 {
240  m_sortDim = split.sortDim;
242 
243  left.numRef = split.numLeft;
244  left.bounds = split.leftBounds;
245  right.numRef = spec.numRef - split.numLeft;
246  right.bounds = split.rightBounds;
247 }
248 
249 //------------------------------------------------------------------------
250 
252 {
253  // Initialize bins.
254 
255  Vec3f origin = spec.bounds.min();
256  Vec3f binSize = (spec.bounds.max() - origin) * (1.0f / (F32)NumSpatialBins);
257  Vec3f invBinSize = 1.0f / binSize;
258 
259  for (int dim = 0; dim < 3; dim++)
260  {
261  for (int i = 0; i < NumSpatialBins; i++)
262  {
263  SpatialBin& bin = m_bins[dim][i];
264  bin.bounds = AABB();
265  bin.enter = 0;
266  bin.exit = 0;
267  }
268  }
269 
270  // Chop references into bins.
271 
272  for (int refIdx = m_refStack.getSize() - spec.numRef; refIdx < m_refStack.getSize(); refIdx++)
273  {
274  const Reference& ref = m_refStack[refIdx];
275  Vec3i firstBin = clamp(Vec3i((ref.bounds.min() - origin) * invBinSize), 0, NumSpatialBins - 1);
276  Vec3i lastBin = clamp(Vec3i((ref.bounds.max() - origin) * invBinSize), firstBin, NumSpatialBins - 1);
277 
278  for (int dim = 0; dim < 3; dim++)
279  {
280  Reference currRef = ref;
281  for (int i = firstBin[dim]; i < lastBin[dim]; i++)
282  {
283  Reference leftRef, rightRef;
284  splitReference(leftRef, rightRef, currRef, dim, origin[dim] + binSize[dim] * (F32)(i + 1));
285  m_bins[dim][i].bounds.grow(leftRef.bounds);
286  currRef = rightRef;
287  }
288  m_bins[dim][lastBin[dim]].bounds.grow(currRef.bounds);
289  m_bins[dim][firstBin[dim]].enter++;
290  m_bins[dim][lastBin[dim]].exit++;
291  }
292  }
293 
294  // Select best split plane.
295 
296  SpatialSplit split;
297  for (int dim = 0; dim < 3; dim++)
298  {
299  // Sweep right to left and determine bounds.
300 
301  AABB rightBounds;
302  for (int i = NumSpatialBins - 1; i > 0; i--)
303  {
304  rightBounds.grow(m_bins[dim][i].bounds);
305  m_rightBounds[i - 1] = rightBounds;
306  }
307 
308  // Sweep left to right and select lowest SAH.
309 
310  AABB leftBounds;
311  int leftNum = 0;
312  int rightNum = spec.numRef;
313 
314  for (int i = 1; i < NumSpatialBins; i++)
315  {
316  leftBounds.grow(m_bins[dim][i - 1].bounds);
317  leftNum += m_bins[dim][i - 1].enter;
318  rightNum -= m_bins[dim][i - 1].exit;
319 
320  F32 sah = nodeSAH + leftBounds.area() * m_platform.getTriangleCost(leftNum) + m_rightBounds[i - 1].area() * m_platform.getTriangleCost(rightNum);
321  if (sah < split.sah)
322  {
323  split.sah = sah;
324  split.dim = dim;
325  split.pos = origin[dim] + binSize[dim] * (F32)i;
326  }
327  }
328  }
329  return split;
330 }
331 
332 //------------------------------------------------------------------------
333 
334 void SplitBVHBuilder::performSpatialSplit(NodeSpec& left, NodeSpec& right, const NodeSpec& spec, const SpatialSplit& split)
335 {
336  // Categorize references and compute bounds.
337  //
338  // Left-hand side: [leftStart, leftEnd[
339  // Uncategorized/split: [leftEnd, rightStart[
340  // Right-hand side: [rightStart, refs.getSize()[
341 
343  int leftStart = refs.getSize() - spec.numRef;
344  int leftEnd = leftStart;
345  int rightStart = refs.getSize();
346  left.bounds = right.bounds = AABB();
347 
348  for (int i = leftEnd; i < rightStart; i++)
349  {
350  // Entirely on the left-hand side?
351 
352  if (refs[i].bounds.max()[split.dim] <= split.pos)
353  {
354  left.bounds.grow(refs[i].bounds);
355  swap(refs[i], refs[leftEnd++]);
356  }
357 
358  // Entirely on the right-hand side?
359 
360  else if (refs[i].bounds.min()[split.dim] >= split.pos)
361  {
362  right.bounds.grow(refs[i].bounds);
363  swap(refs[i--], refs[--rightStart]);
364  }
365  }
366 
367  // Duplicate or unsplit references intersecting both sides.
368 
369  while (leftEnd < rightStart)
370  {
371  // Split reference.
372 
373  Reference lref, rref;
374  splitReference(lref, rref, refs[leftEnd], split.dim, split.pos);
375 
376  // Compute SAH for duplicate/unsplit candidates.
377 
378  AABB lub = left.bounds; // Unsplit to left: new left-hand bounds.
379  AABB rub = right.bounds; // Unsplit to right: new right-hand bounds.
380  AABB ldb = left.bounds; // Duplicate: new left-hand bounds.
381  AABB rdb = right.bounds; // Duplicate: new right-hand bounds.
382  lub.grow(refs[leftEnd].bounds);
383  rub.grow(refs[leftEnd].bounds);
384  ldb.grow(lref.bounds);
385  rdb.grow(rref.bounds);
386 
387  F32 lac = m_platform.getTriangleCost(leftEnd - leftStart);
388  F32 rac = m_platform.getTriangleCost(refs.getSize() - rightStart);
389  F32 lbc = m_platform.getTriangleCost(leftEnd - leftStart + 1);
390  F32 rbc = m_platform.getTriangleCost(refs.getSize() - rightStart + 1);
391 
392  F32 unsplitLeftSAH = lub.area() * lbc + right.bounds.area() * rac;
393  F32 unsplitRightSAH = left.bounds.area() * lac + rub.area() * rbc;
394  F32 duplicateSAH = ldb.area() * lbc + rdb.area() * rbc;
395  F32 minSAH = min(unsplitLeftSAH, unsplitRightSAH, duplicateSAH);
396 
397  // Unsplit to left?
398 
399  if (minSAH == unsplitLeftSAH)
400  {
401  left.bounds = lub;
402  leftEnd++;
403  }
404 
405  // Unsplit to right?
406 
407  else if (minSAH == unsplitRightSAH)
408  {
409  right.bounds = rub;
410  swap(refs[leftEnd], refs[--rightStart]);
411  }
412 
413  // Duplicate?
414 
415  else
416  {
417  left.bounds = ldb;
418  right.bounds = rdb;
419  refs[leftEnd++] = lref;
420  refs.add(rref);
421  }
422  }
423 
424  left.numRef = leftEnd - leftStart;
425  right.numRef = refs.getSize() - rightStart;
426 }
427 
428 //------------------------------------------------------------------------
429 
431 {
432  // Initialize references.
433 
434  left.triIdx = right.triIdx = ref.triIdx;
435  left.bounds = right.bounds = AABB();
436 
437  // Loop over vertices/edges.
438 
439  const Vec3i* tris = (const Vec3i*)m_bvh.getScene()->getTriVtxIndexBuffer().getPtr();
440  const Vec3f* verts = (const Vec3f*)m_bvh.getScene()->getVtxPosBuffer().getPtr();
441  const Vec3i& inds = tris[ref.triIdx];
442  const Vec3f* v1 = &verts[inds.z];
443 
444  for (int i = 0; i < 3; i++)
445  {
446  const Vec3f* v0 = v1;
447  v1 = &verts[inds[i]];
448  F32 v0p = v0->get(dim);
449  F32 v1p = v1->get(dim);
450 
451  // Insert vertex to the boxes it belongs to.
452 
453  if (v0p <= pos)
454  left.bounds.grow(*v0);
455  if (v0p >= pos)
456  right.bounds.grow(*v0);
457 
458  // Edge intersects the plane => insert intersection to both boxes.
459 
460  if ((v0p < pos && v1p > pos) || (v0p > pos && v1p < pos))
461  {
462  Vec3f t = lerp(*v0, *v1, clamp((pos - v0p) / (v1p - v0p), 0.0f, 1.0f));
463  left.bounds.grow(t);
464  right.bounds.grow(t);
465  }
466  }
467 
468  // Intersect with original bounds.
469 
470  left.bounds.max()[dim] = pos;
471  right.bounds.min()[dim] = pos;
472  left.bounds.intersect(ref.bounds);
473  right.bounds.intersect(ref.bounds);
474 }
475 
476 //------------------------------------------------------------------------
bool enablePrints
Flag whether to enable prints about build progress.
Definition: BVH.hpp:112
Stucture holding the BVH build parameters.
Definition: BVH.hpp:109
BVHNode * run(void)
Performs the actual build.
#define FW_F32_MAX
Definition: Defs.hpp:118
Maximum depth of the BVH tree.
F32 pos
Position of the split.
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1
Definition: DLLImports.inl:353
S32 sortDim
Dimension in which triangles are sorted.
Buffer & getTriVtxIndexBuffer(void)
Returns buffer of triangle's vertex indieces.
Definition: Scene.hpp:75
void sort(void *data, int start, int end, SortCompareFunc compareFunc, SortSwapFunc swapFunc, bool multicore=false)
Definition: Sort.cpp:203
F32 sah
SAH cost of the split.
FW_CUDA_FUNC const Vec3f & max(void) const
Definition: Util.hpp:49
T removeSwap(S idx)
Definition: Array.hpp:474
Array< Reference > m_refStack
Reference stack.
BVH leaf node.
Definition: BVHNode.hpp:275
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid * data
Definition: DLLImports.inl:319
BVHNode * buildNode(NodeSpec spec, int level, F32 progressStart, F32 progressEnd)
Builds a BVH node. The built node may be an inner node as well as a leaf node.
S32 enter
Number of triangles entering the bin.
AABB bounds
Bounding box of the node.
void ** ptr
Definition: DLLImports.cpp:74
AABB bounds
Bounding box of the bin.
Buffer & getVtxPosBuffer(void)
Returns vertex position buffer.
Definition: Scene.hpp:103
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint GLfloat GLfloat GLfloat z GLuint GLint GLenum GLboolean GLsizei const GLvoid pointer GLuint GLuint const GLchar name GLenum GLsizei GLenum GLsizei GLsizei height GLenum GLuint renderbuffer GLenum GLenum GLint * params
Definition: DLLImports.inl:373
Array< AABB > m_rightBounds
Bounding boxes of all the possible right children.
FW_CUDA_FUNC T sqr(const T &a)
Definition: Math.hpp:113
BVHNode * createLeaf(const NodeSpec &spec)
Builds a leaf node.
BVH inner node.
Definition: BVHNode.hpp:228
void start(void)
Definition: Timer.hpp:42
ObjectSplit findObjectSplit(const NodeSpec &spec, F32 nodeSAH)
Finds best object split of the node.
BVH & m_bvh
BVH being built.
float getTriangleCost(S32 n) const
Calcuates cost of a given number of triangles rounded to the batch size.
Definition: Platform.hpp:95
const U8 * getPtr(S64 ofs=0)
Definition: Buffer.hpp:106
F32 splitAlpha
Spatial split area threshold.
Definition: BVH.hpp:113
const BVH::BuildParams & m_params
Build parameters.
F32 sah
SAH cost of the split.
AABB leftBounds
AABB of the left child node.
~SplitBVHBuilder(void)
Destructor.
S32 m_numDuplicates
Number of duplicated references.
void performSpatialSplit(NodeSpec &left, NodeSpec &right, const NodeSpec &spec, const SpatialSplit &split)
Performs the spatial split operation.
Declarations for SplitBVHBuilder.
FW_CUDA_FUNC const T & get(int idx) const
Definition: Math.hpp:128
static void sortSwap(void *data, int idxA, int idxB)
Sort swap function. Swaps two references placed in the reference stack. For details see framework/bas...
const Platform & m_platform
Platform settings.
FW_CUDA_FUNC T sum(const VectorBase< T, L, S > &v)
Definition: Math.hpp:463
Array< S32 > & getTriIndices(void)
Returns an array of triangle indices to which leaf nodes are pointig. These indices point to scene's ...
Definition: BVH.hpp:180
float F32
Definition: Defs.hpp:89
S32 exit
Number of triangles leaving the bin.
AABB rightBounds
AABB of the right child node.
S32 numRef
Number of the node's references saved in a node stack.
Scene * getScene(void) const
static bool sortCompare(void *data, int idxA, int idxB)
Sort comparator. Sorts references according to their position in descending order. For details see framework/base.Sort.hpp.
FW_CUDA_FUNC float area(void) const
Definition: Util.hpp:45
float getNodeCost(S32 n) const
Calculates cost of a given number of nodes rounded to the batch size.
Definition: Platform.hpp:102
SpatialSplit findSpatialSplit(const NodeSpec &spec, F32 nodeSAH)
Finds the best spatial split of the node.
FW_CUDA_FUNC T min(const VectorBase< T, L, S > &v)
Definition: Math.hpp:461
FW_CUDA_FUNC T max(const VectorBase< T, L, S > &v)
Definition: Math.hpp:462
S32 m_sortDim
Sort dimension. Used by sort method.
int getNumTriangles(void) const
Definition: Scene.hpp:61
BVH acceleration structure class.
Definition: BVH.hpp:74
F32 m_minOverlap
Minimum overlap of the left and right AABB of the object split needed to make spatial split worth fin...
Maximum depth of the BVH where spatial split will still be used.
void splitReference(Reference &left, Reference &right, const Reference &ref, int dim, F32 pos)
Splits the triangle's bounding box.
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat v0
Definition: DLLImports.inl:353
T & add(void)
Definition: Array.hpp:384
FW_CUDA_FUNC const Vec3f & min(void) const
Definition: Util.hpp:48
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int dim
Definition: DLLImports.inl:74
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction f
Definition: DLLImports.inl:88
Number of spatial bins per node in each axis.
FW_CUDA_FUNC void grow(const Vec3f &pt)
Definition: Util.hpp:41
Structure holding specifications of the BVH's node.
S32 numLeft
Number of triangles in left child node.
Class performing SBVH build.
void printf(const char *fmt,...)
Definition: Defs.cpp:225
S32 triIdx
Index of the triangle.
S32 getMaxLeafSize() const
Definition: Platform.hpp:157
void compact(void)
Definition: Array.hpp:335
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level
Definition: DLLImports.inl:333
FW_CUDA_FUNC void swap(T &a, T &b)
Definition: Defs.hpp:183
SplitBVHBuilder(BVH &bvh, const BVH::BuildParams &params)
Constructor.
Structure holding info about object split of a BVH node.
BVH virtual node. Parent class of both a leaf node and an inner node.
Definition: BVHNode.hpp:136
T & removeLast(void)
Definition: Array.hpp:465
SpatialBin m_bins[3][NumSpatialBins]
Spatial bins.
Structure holding info about spatial split of a BVH node.
AABB bounds
Bounding box of the triangle.
const T * getPtr(S idx=0) const
Definition: Array.hpp:202
Structure holding info about a spatial bin.
S32 getMinLeafSize() const
Definition: Platform.hpp:152
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr size
Definition: DLLImports.inl:319
void performObjectSplit(NodeSpec &left, NodeSpec &right, const NodeSpec &spec, const ObjectSplit &split)
Performs the object split operation.
F32 getElapsed(void)
Definition: Timer.hpp:44
Structure holding triangle's index together with its bounding box.
S32 dim
Dimension of the split.
FW_CUDA_FUNC void intersect(const AABB &aabb)
Definition: Util.hpp:43
void resize(S size)
Definition: Array.hpp:366
S getSize(void) const
Definition: Array.hpp:188
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint GLfloat GLfloat GLfloat z GLuint GLint GLenum GLboolean GLsizei const GLvoid pointer GLuint GLuint const GLchar name GLenum GLsizei GLenum GLsizei GLsizei height GLenum GLuint renderbuffer GLenum GLenum GLint params GLuint GLsizei range GLuint GLsizei const GLubyte GLsizei GLenum const GLvoid coords GLuint GLsizei GLsizei GLsizei const GLubyte GLsizei GLenum const GLvoid coords GLuint GLenum GLsizei const GLvoid pathString GLuint GLenum const GLvoid GLbitfield GLuint GLsizei GLenum GLuint GLfloat emScale GLuint GLuint srcPath GLuint GLuint GLenum const GLfloat transformValues GLuint GLenum GLint value GLuint GLenum GLfloat value GLenum GLint ref
Definition: DLLImports.inl:400
FW_CUDA_FUNC A lerp(const A &a, const A &b, const B &t)
Definition: Math.hpp:115
Timer m_progressTimer
Progress timer.