NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SAHBVHBuilder.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2009-2010 NVIDIA Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #pragma once
23 #include "bvh/BVH.hpp"
24 #include "cuda/CudaBVH.hpp"
25 #include "base/Timer.hpp"
26 
27 //#define BVH_EPSILON 0.00001f
28 #define BVH_EPSILON 0.001f // PowerPlant
29 //#define BVH_EPSILON 0.01f
30 
31 namespace FW
32 {
33 //------------------------------------------------------------------------
34 
39 {
40 protected:
41 
45  enum
46  {
47  MaxDepth = 64,
48  };
49 
53  struct Reference
54  {
57 
61  Reference(void) : triIdx(-1) {}
62  };
63 
67  struct NodeSpec
68  {
71 
75  NodeSpec(void) : numRef(0) {}
76  };
77 
81  struct ObjectSplit
82  {
83  F32 sah;
88 
93  };
94 
95 public:
101  SAHBVHBuilder (BVH& bvh, const BVH::BuildParams& params);
102 
106  virtual ~SAHBVHBuilder (void);
107 
112  virtual BVHNode* run (void);
113 
114 protected:
115  //static int sortCompare (void* data, int idxA, int idxB);
116 
121  static bool sortCompare (void* data, int idxA, int idxB);
122 
126  static void sortSwap (void* data, int idxA, int idxB);
127 
136  BVHNode* buildNode (const NodeSpec& spec, int level, F32 progressStart, F32 progressEnd);
137 
148  BVHNode* buildNode (const NodeSpec& spec, int start, int end, int level, F32 progressStart, F32 progressEnd);
149 
155  BVHNode* createLeaf (const NodeSpec& spec);
156 
164  BVHNode* createLeaf (const NodeSpec& spec, int start, int end);
165 
172  ObjectSplit findObjectSplit (const NodeSpec& spec, F32 nodeSAH);
173 
181  ObjectSplit findObjectSplit (int start, int end, F32 nodeSAH);
182 
190  void performObjectSplit (NodeSpec& left, NodeSpec& right, const NodeSpec& spec, const ObjectSplit& split);
191 
200  void performObjectSplit (NodeSpec& left, NodeSpec& right, const NodeSpec& spec, int start, int end, const ObjectSplit& split);
201 
202 private:
203  SAHBVHBuilder (const SAHBVHBuilder&); // forbidden
204  SAHBVHBuilder& operator= (const SAHBVHBuilder&); // forbidden
205 
206 protected:
210 
214 
217 };
218 
219 //------------------------------------------------------------------------
220 }
Stucture holding the BVH build parameters.
Definition: BVH.hpp:109
Array< Reference > m_refStack
Reference stack.
#define FW_F32_MAX
Definition: Defs.hpp:118
S32 m_numDuplicates
Number of duplicated references.
BVH & m_bvh
BVH being built.
AABB leftBounds
AABB of a left child node.
F32 sah
SAH cost of the split.
AABB bounds
Bounding box of the node.
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(const 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.
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
AABB rightBounds
AABB of a right child node.
S32 numRef
Number of the node's references saved in a node stack.
ObjectSplit findObjectSplit(const NodeSpec &spec, F32 nodeSAH)
Finds the best object split of the node.
SAHBVHBuilder(BVH &bvh, const BVH::BuildParams &params)
Constructor.
Array< AABB > m_rightBounds
Bounding boxes of all the possible right children.
BVHNode * createLeaf(const NodeSpec &spec)
Builds a leaf node.
Declarations for the BVH acceleration structure.
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...
virtual ~SAHBVHBuilder(void)
Destructor.
float F32
Definition: Defs.hpp:89
Timer m_progressTimer
Progress timer.
Structure holding info about a split of the BVH node.
S32 m_sortDim
Sort dimension. Used by the sort method.
BVH acceleration structure class.
Definition: BVH.hpp:74
Declarations for the Cuda version of the BVH.
const Platform & m_platform
Platform settings.
signed int S32
Definition: Defs.hpp:88
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.
Reference(void)
Constructor.
S32 triIdx
Index of the triangle.
void performObjectSplit(NodeSpec &left, NodeSpec &right, const NodeSpec &spec, const ObjectSplit &split)
Performs the split operation.
const BVH::BuildParams & m_params
Build parameters.
S32 numLeft
Number of triangles in left child node.
Class holding various SAH and batch processing parameters.
Definition: Platform.hpp:46
ObjectSplit(void)
Constructor.
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
Structure holding triangle's index together with its bounding box.
AABB bounds
Bounding box of the triangle.
BVH virtual node. Parent class of both a leaf node and an inner node.
Definition: BVHNode.hpp:136
S32 sortDim
Dimension in which triangles are sorted.
Structure holding specifications of a BVH's node.
NodeSpec(void)
Constructor.
Class that builds a BVH using SAH.
virtual BVHNode * run(void)
Performs the actual build.