NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Renderer.cpp
Go to the documentation of this file.
1 #include "cuda/Renderer.hpp"
3 #include "gui/Window.hpp"
4 #include "io/File.hpp"
6 
7 using namespace FW;
8 
9 //------------------------------------------------------------------------
10 
12 : m_raygen (1 << 20),
13 
14  m_window (NULL),
15  m_enableRandom (false),
16 
17  m_mesh (NULL),
18  m_scene (NULL),
19 
20  m_image (NULL),
21  m_cameraFar (0.0f),
22 
23  m_newBatch (true),
24  m_batchRays (NULL),
25  m_batchStart (0),
26 
27  m_accelStruct (NULL),
28 
29  m_asType (as),
30  m_vis (NULL),
31  m_showVis (false)
32 {
33  m_env = env;
34 
35  if (m_asType == tKDTree)
36  {
38  }
39  else
40  {
42  }
44 
45  m_compiler.setSourceFile("src/rt/cuda/RendererKernels.cu");
46  m_compiler.addOptions("-use_fast_math");
47  m_compiler.include("src/rt");
48  m_compiler.include("src/framework");
49  m_bvhCachePath = "bvhcache";
50 
51  m_platform = Platform("GPU");
53 }
54 
55 //------------------------------------------------------------------------
56 
58 {
59  setMesh(NULL);
60 
61  delete m_image;
62  delete m_cudaTracer;
63  delete m_accelStruct;
64 }
65 
66 //------------------------------------------------------------------------
67 
69 {
70  // Same mesh => done.
71 
72  if (mesh == m_mesh)
73  return;
74 
75  // Deinit scene and BVH.
76 
77  delete m_scene;
78  m_scene = NULL;
79 
80  invalidateBVH();
81 
82  // Create scene.
83 
84  m_mesh = mesh;
85  if (mesh)
86  {
87  m_scene = new Scene(*mesh);
89  }
90 }
91 
92 //------------------------------------------------------------------------
93 
95 {
96  m_params = params;
97 
99 }
100 
101 //------------------------------------------------------------------------
102 
104 {
105  string bvhBuilder;
106  m_env->GetStringValue("BVHBuilder", bvhBuilder);
107 
108  // BVH is already valid => done.
109 
111  if (!m_mesh || (m_accelStruct && m_accelStruct->getLayout() == layout))
112  return m_accelStruct;
113 
114  // Deinit.
115 
116  delete m_accelStruct;
118 
119  // Setup build parameters.
120 
121  BVH::Stats stats;
122  m_buildParams.stats = &stats;
123 
124  // If we use HLBVH, use HLBVH
125 
126  if (bvhBuilder == "HLBVH")
127  {
129  params.hlbvh = true;
130  params.hlbvhBits = 4;
131  params.leafSize = 8;
132  params.epsilon = 0.001f;
133  HLBVHBuilder* bvh = new HLBVHBuilder(m_scene, m_platform, params);
134  return bvh;
135  }
136 
137  // Determine cache file name.
138 
139  String cacheFileName = sprintf("%s/%08x.dat", m_bvhCachePath.getPtr(), hashBits(
140  m_scene->hash(),
143  layout,
144  m_asType));
145 
146  // Cache file exists => import.
147 
148  if (!hasError())
149  {
150  File file(cacheFileName, File::Read);
151  if (!hasError())
152  {
153  m_accelStruct = new CudaBVH(file);
154  return m_accelStruct;
155  }
156  clearError();
157  }
158 
159  // Display status.
160 
161  printf("\nBuilding BVH...\nThis will take a while.\n");
162  if (m_window)
163  m_window->showModalMessage("Building BVH...");
164 
165  // Build BVH.
166 
167  BVH bvh(m_scene, m_platform, m_buildParams, m_env);
168  stats.print();
169  m_accelStruct = new CudaBVH(bvh, layout);
170  failIfError();
171 
172  // Write to cache.
173 
174  if (!hasError())
175  {
176  CreateDirectory(m_bvhCachePath.getPtr(), NULL);
177  File file(cacheFileName, File::Create);
178  m_accelStruct->serialize(file);
179  clearError();
180  }
181 
182  // Display status.
183 
184  printf("Done.\n\n");
185  return m_accelStruct;
186 }
187 
188 //------------------------------------------------------------------------
189 
191 {
193  if (!m_mesh || (m_accelStruct && m_accelStruct->getLayout() == layout))
194  return m_accelStruct;
195 
196  String cacheFileName = sprintf("%s/%08x.dat", m_bvhCachePath.getPtr(), hashBits(
197  m_scene->hash(),
200  layout,
201  m_asType));
202 
203  if(!hasError())
204  {
205  File file(cacheFileName, File::Read);
206  if (!hasError())
207  {
208  m_accelStruct = new CudaKDTree(file);
209  return m_accelStruct;
210  }
211  clearError();
212  }
213 
214  delete m_accelStruct;
216 
217  printf("\nBuilding k-d tree...\nThis will take a while.\n");
218  if (m_window)
219  m_window->showModalMessage("Building k-d tree...");
220 
223  params.stats = new KDTree::Stats();
224  params.builder = KDTree::SAH;
225 
226  KDTree kdtree(m_scene, m_platform, params);
227  m_accelStruct = new CudaKDTree(kdtree);
228 
229  failIfError();
230 
231  // Write to cache.
232 
233  //if (!hasError())
234  //{
235  // CreateDirectory(m_bvhCachePath.getPtr(), NULL);
236  // File file(cacheFileName, File::Create);
237  // m_accelStruct->serialize(file);
238  // clearError();
239  //}
240 
241  params.stats->print();
242 
243  return m_accelStruct;
244 }
245 
246 //------------------------------------------------------------------------
247 
249 {
250  F32 launchTime = 0.0f;
251  beginFrame(gl, camera);
252  while (nextBatch())
253  {
254  launchTime += traceBatch();
255  updateResult();
256  }
257  displayResult(gl);
258  CameraControls& c = const_cast<CameraControls&>(camera);
259  if(m_showVis && m_vis != NULL) // If visualization is enabled
260  m_vis->draw(gl, c);
261 
262  return launchTime;
263 }
264 
265 //------------------------------------------------------------------------
266 
268 {
269  FW_ASSERT(gl && m_mesh);
270 
271  // Setup BVH.
272  if(m_asType == tBVH)
274  else
276 
277  // Setup result image.
278 
279  const Vec2i& size = gl->getViewSize();
280  if (!m_image || m_image->getSize() != size)
281  {
282  delete m_image;
283  m_image = new Image(size, ImageFormat::ABGR_8888);
285  m_image->clear();
286  }
287 
288  // Generate primary rays.
289 
291  camera.getPosition(),
292  invert(gl->xformFitToView(-1.0f, 2.0f) * camera.getWorldToClip()),
293  size.x, size.y,
294  camera.getFar());
295 
296  // Secondary rays enabled => trace primary rays.
297 
299  {
301  }
302 
303  // Initialize state.
304 
305  m_cameraFar = camera.getFar();
306  m_newBatch = true;
307  m_batchRays = NULL;
308  m_batchStart = 0;
309 }
310 
311 //------------------------------------------------------------------------
312 
314 {
316 
317  // Clean up the previous batch.
318 
319  if (m_batchRays)
321  m_batchRays = NULL;
322 
323  // Generate new batch.
324 
325  U32 randomSeed = (m_enableRandom) ? m_random.getU32() : 0;
326  switch (m_params.rayType)
327  {
328  case RayType_Primary:
329  case RayType_Textured:
330  case RayType_PathTracing:
331  if (!m_newBatch)
332  return false;
333  m_newBatch = false;
335  break;
336 
337  case RayType_AO:
339  return false;
341  break;
342 
343  case RayType_Diffuse:
345  return false;
348  break;
349 
350  default:
351  FW_ASSERT(false);
352  return false;
353  }
354 
355  // Sort rays.
356 
359  return true;
360 }
361 
362 //------------------------------------------------------------------------
363 
365 {
367 
369 }
370 
371 //------------------------------------------------------------------------
372 
374 {
376 
377  // Compile kernel.
378 
380 
381  // Setup input struct.
382 
383  ReconstructInput& in = *(ReconstructInput*)module->getGlobal("c_ReconstructInput").getMutablePtr();
388  in.isAO = (m_params.rayType == RayType_AO);
399 
406 
407  module->setTexRef("t_textures", *m_scene->getTextureAtlas()->getAtlasTexture().getImage(), true, true, true, false);
408 
409  // Launch.
410 
411  module->getKernel("reconstructKernel").launch(in.numPrimary);
412 }
413 
414 //------------------------------------------------------------------------
415 
417 {
418  FW_ASSERT(gl);
419  Mat4f oldXform = gl->setVGXform(Mat4f());
420  glPushAttrib(GL_ENABLE_BIT);
421  glDisable(GL_DEPTH_TEST);
422  gl->drawImage(*m_image, Vec2f(0.0f), 0.5f, false);
423  gl->setVGXform(oldXform);
424  glPopAttrib();
425 }
426 
427 //------------------------------------------------------------------------
428 
430 {
431  // Casting primary rays => no degenerates.
432 
434  return m_primaryRays.getSize();
435 
436  // Compile kernel.
437 
439 
440  // Set input and output.
441 
442  CountHitsInput& in = *(CountHitsInput*)module->getGlobal("c_CountHitsInput").getMutablePtr();
445  in.raysPerThread = 32;
446  module->getGlobal("g_CountHitsOutput").clear();
447 
448  // Count primary ray hits.
449 
450  module->getKernel("countHitsKernel").launch(
451  (in.numRays - 1) / in.raysPerThread + 1,
453 
454  int numHits = *(S32*)module->getGlobal("g_CountHitsOutput").getPtr();
455 
456  // numSecondary = secondaryPerPrimary * primaryHits
457 
458  return numHits * m_params.numSamples;
459 }
460 
461 //------------------------------------------------------------------------
462 
463 F32 Renderer::calcNodeSAHCostKdtree(const Platform& platform, Buffer* nodes, Buffer* tris, S32 n, AABB bbox, S32 depth, S32& maxDepth, S32& sumDepth, S32& numNodes, S32& numLeaves, F32& nodeArea, F32 &weightedLeafArea, F32& test)
464 {
465  numNodes++;
466  if(depth > maxDepth)
467  maxDepth = depth;
468  sumDepth += depth;
469 
470  F32 pa = bbox.area();
471 
472  if((n & KDTREE_MASK) == KDTREE_EMPTYLEAF) // Empty leaf
473  {
474  return calcLeafSAHCostNum(platform, 0, numLeaves)*pa;
475  }
476 
477  if(n >= 0) // Inner node
478  {
479  Vec4i cell = ((Vec4i*)nodes)[n];
480  unsigned int type = cell.w & KDTREE_MASK;
481  float split = *(float*)&cell.z;
482 
483  AABB bboxLeft = bbox;
484  AABB bboxRight = bbox;
485 
486  switch((type >> KDTREE_DIMPOS))
487  {
488  case 0:
489  bboxLeft.max().x = split;
490  bboxRight.min().x = split;
491  break;
492 
493  case 1:
494  bboxLeft.max().y = split;
495  bboxRight.min().y = split;
496  break;
497 
498  case 2:
499  bboxLeft.max().z = split;
500  bboxRight.min().z = split;
501  break;
502  }
503 
504  S32 nl = cell.x;
505  S32 nr = cell.y;
506 
507  nodeArea += pa;
508 
509  weightedLeafArea += calcNodeSAHCostKdtree(platform, nodes, tris, nl, bboxLeft, depth+1, maxDepth, sumDepth, numNodes, numLeaves, nodeArea, weightedLeafArea, test);
510  weightedLeafArea += calcNodeSAHCostKdtree(platform, nodes, tris, nr, bboxRight, depth+1, maxDepth, sumDepth, numNodes, numLeaves, nodeArea, weightedLeafArea, test);
511 
512  if(depth == 0)
513  {
514  F32 pa = bbox.area();
515  return platform.getNodeCost(1) * nodeArea/pa + weightedLeafArea/pa;
516  }
517 
518  return 0.f;
519  }
520  else // Leaf
521  {
522  return calcLeafSAHCostCompact(platform, tris, ~n, numLeaves)*pa;
523  }
524 }
525 
526 //------------------------------------------------------------------------
527 
528 F32 Renderer::calcLeafSAHCostCompact(const Platform& platform, Buffer* triIdx, S32 n, S32& numLeaves)
529 {
530  numLeaves++;
531 
532  int* idx = (int*)triIdx + n;
533 
534  S32 cnt = 0;
535  while(idx[cnt] != 0x80000000)
536  cnt++;
537 
538  return platform.getTriangleCost(cnt);
539 }
540 
541 //------------------------------------------------------------------------
542 
543 F32 Renderer::calcLeafSAHCostNum(const Platform& platform, S32 n, S32& numLeaves)
544 {
545  numLeaves++;
546  return platform.getTriangleCost(0);
547 }
548 
549 //------------------------------------------------------------------------
550 
552 {
553  if(m_window == NULL)
554  return;
555 
556  if(m_vis != NULL)
557  endBVHVis();
558 
559  // Trace the primary rays so that we have correct rays to visualize
560  // TODO: Enable secondary rays visualization too?
561  RayStats stats;
562  //m_as->setTraceParams(&m_platform, m_scene);
563  //setTracerBVH(m_bvh);
564  //traceBatch(m_primaryRays, &stats);
565  //m_newBatch = true;
566  //m_batchRays = NULL;
567  //m_batchStart = 0;
568  //m_sampleIndex = 0;
569  //m_secondaryIndex = 0;
570 
571  //m_buildParams.visibility = &getVisibleTriangles(m_scene->getNumTriangles(), true); // Get visibility buffer
572  //if(m_params.rayType != RayType_Primary)
573  //{
574  // traceBatch();
575  //}
576  //while (nextBatch())
577  //{
578  // traceBatch();
579  //}
580 
582  m_vis->setVisible(true);
584 
585  m_showVis = true;
586 }
587 
588 //------------------------------------------------------------------------
589 
591 {
592  if(m_window != NULL)
594  delete m_vis;
595  m_vis = NULL;
596 
597  m_showVis = false;
598 }
bool enablePrints
Flag whether to enable prints about build progress.
Definition: BVH.hpp:112
Buffer & getTriMaterialColorBuffer(void)
Returns material color buffer.
Definition: Scene.hpp:89
void setScene(Scene *scene)
AccelStructType m_asType
Definition: Renderer.hpp:151
bool nextBatch(void)
Definition: Renderer.cpp:313
S32 getSize() const
Gets size of the buffer (number of rays).
Definition: RayBuffer.hpp:52
#define NULL
Definition: Defs.hpp:39
String m_bvhCachePath
Definition: Renderer.hpp:126
Params m_params
Definition: Renderer.hpp:132
const char * getPtr(void) const
Definition: String.hpp:51
Cuda BVH class.
Definition: CudaBVH.hpp:93
Buffer & getTriVtxIndexBuffer(void)
Returns buffer of triangle's vertex indieces.
Definition: Scene.hpp:75
Stats * stats
Statistics collected during build phase. Set to NULL if no stats should be collected.
Definition: KDTree.hpp:97
virtual void draw(GLContext *gl, CameraControls &camera)=0
The method used to draw the current state of visualization to the OpenGL context. ...
void setLeafPreferences(S32 minSize, S32 maxSize)
Sets leaf size preferences (desired number of triangles in one leaf node).
Definition: Platform.hpp:147
Image * m_image
Definition: Renderer.hpp:139
Class for the BVH visualization.
Mat4f setVGXform(const Mat4f &m)
Definition: GLContext.hpp:171
RayBuffer * m_batchRays
Definition: Renderer.hpp:145
S32 m_batchStart
Definition: Renderer.hpp:146
virtual void setBVH(CudaAS *as)=0
bool GetStringValue(const char *name, char *value, const bool isFatal=false) const
void include(const String &path)
void clear(int value=0)
Definition: Buffer.hpp:100
FW_CUDA_FUNC const Vec3f & max(void) const
Definition: Util.hpp:49
CudaModule * compile(bool enablePrints=true, bool autoFail=true)
Buffer & getMaterialIds(void)
Returns material id buffer.
Definition: Scene.hpp:131
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule * module
Definition: DLLImports.inl:60
void clear(U32 abgr=0)
Definition: Image.hpp:160
const Image * getImage(void) const
Definition: Texture.hpp:64
F32 calcLeafSAHCostNum(const Platform &platform, S32 n, S32 &numLeaves)
Definition: Renderer.cpp:543
Stats * stats
Statistics. If NULL, no statistics are gathered.
Definition: BVH.hpp:111
Renderer(AccelStructType as, Environment *env)
Definition: Renderer.cpp:11
Buffer & getIDToSlotBuffer()
Gets buffer mapping ids to slots.
Definition: RayBuffer.hpp:179
Cuda friendly KDTree representation.
Definition: CudaKDTree.hpp:20
CudaAS * getCudaBVH(void)
Definition: Renderer.cpp:103
void endBVHVis(void)
Definition: Renderer.cpp:590
virtual BVHLayout getDesiredBVHLayout(void) const =0
void print() const
Prints the statistics to the console.
Definition: BVH.hpp:96
bool ao(RayBuffer &orays, RayBuffer &irays, Scene &scene, int numSamples, float maxDist, bool &newBatch, U32 randomSeed=0)
Generates ao rays on the GPU. Batches rays if necessary.
Definition: RayGen.cpp:196
const Texture & getAtlasTexture(void)
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
void addListener(Listener *listener)
Definition: Window.cpp:282
String clearError(void)
Definition: Defs.cpp:269
CUdeviceptr getCudaPtr(S64 ofs=0)
Definition: Buffer.hpp:108
TextureAtlas * getTextureAtlas(void)
Returns texture atlas holding scene's textures.
Definition: Scene.hpp:151
F32 traceBatch(void)
Definition: Renderer.cpp:364
Scene * m_scene
Definition: Renderer.hpp:137
#define KDTREE_DIMPOS
Strucure holding build parameters.
Definition: KDTree.hpp:85
K-d tree acceleration structure class.
Definition: KDTree.hpp:41
CudaKernel getKernel(const String &name)
Definition: CudaModule.cpp:80
virtual F32 traceBatch(RayBuffer &rays)=0
Structure holding ray statistics. Also provides print to the console. These statistics are used in a ...
Definition: BVH.hpp:45
Structure holding statistics about k-d tree.
Definition: KDTree.hpp:57
CudaCompiler m_compiler
Definition: Renderer.hpp:125
float getTriangleCost(S32 n) const
Calcuates cost of a given number of triangles rounded to the batch size.
Definition: Platform.hpp:95
Mat4f getWorldToClip(void) const
const U8 * getPtr(S64 ofs=0)
Definition: Buffer.hpp:106
CudaVirtualTracer * m_cudaTracer
Definition: Renderer.hpp:149
void startBVHVis(void)
Definition: Renderer.cpp:551
#define KDTREE_EMPTYLEAF
Sturcture for holding statistics about the BVH.
Definition: BVH.hpp:81
Mat4f xformFitToView(const Vec2f &pos, const Vec2f &size) const
Definition: GLContext.hpp:151
void setTexRef(const String &name, Buffer &buf, CUarray_format format, int numComponents)
Definition: CudaModule.cpp:193
RayBuffer m_primaryRays
Definition: Renderer.hpp:141
F32 renderFrame(GLContext *gl, const CameraControls &camera)
Definition: Renderer.cpp:248
Buffer & getSlotToIDBuffer()
Gets buffer slots to ids.
Definition: RayBuffer.hpp:185
void updateResult(void)
Definition: Renderer.cpp:373
Buffer & getTriShadedColorBuffer(void)
Returns shaded color buffer.
Definition: Scene.hpp:96
void drawImage(const Image &image, const Vec4f &pos, const Vec2f &align, bool topToBottom=true)
Definition: GLContext.cpp:808
float F32
Definition: Defs.hpp:89
virtual void serialize(OutputStream &out)=0
Writes buffers to outpu stream.
Buffer & getTextureAtlasInfo(void)
Returns texture atlas information buffer.
Definition: Scene.hpp:124
CUdeviceptr getMutableCudaPtr(S64 ofs=0)
Definition: Buffer.hpp:112
void removeListener(Listener *listener)
Definition: Window.cpp:293
void setHints(U32 hints)
Definition: Buffer.hpp:73
FW_CUDA_FUNC S invert(const MatrixBase< T, L, S > &v)
Definition: Math.hpp:784
CUdeviceptr triMaterialColor
MeshBase * m_mesh
Definition: Renderer.hpp:136
Buffer & getResultBuffer()
Gets ray result buffer.
Definition: RayBuffer.hpp:173
FW_CUDA_FUNC float area(void) const
Definition: Util.hpp:45
F32 getFar(void) const
void showModalMessage(const String &msg)
Definition: Window.cpp:487
float getNodeCost(S32 n) const
Calculates cost of a given number of nodes rounded to the batch size.
Definition: Platform.hpp:102
U8 * getMutablePtr(S64 ofs=0)
Definition: Buffer.hpp:110
void primary(RayBuffer &orays, const Vec3f &origin, const Mat4f &nscreenToWorld, S32 w, S32 h, float maxDist)
Generates primary rays on the GPU.
Definition: RayGen.cpp:44
CudaAS * getCudaKDTree(void)
Definition: Renderer.cpp:190
BVH acceleration structure class.
Definition: BVH.hpp:74
void setMesh(MeshBase *mesh)
Definition: Renderer.cpp:68
#define FW_ASSERT(X)
Definition: Defs.hpp:67
signed int S32
Definition: Defs.hpp:88
String sprintf(const char *fmt,...)
Definition: Defs.cpp:241
F32 calcNodeSAHCostKdtree(const Platform &platform, Buffer *nodes, Buffer *tri, S32 n, AABB bbox, S32 depth, S32 &maxDepth, S32 &sumDepth, S32 &numNodes, S32 &numLeaves, F32 &nodeArea, F32 &weightedLeafArea, F32 &test)
Definition: Renderer.cpp:463
void print() const
Prints statistics to stdout.
Definition: KDTree.hpp:72
Buffer & getMaterialInfo(void)
Returns material info buffer.
Definition: Scene.hpp:145
void setVisible(bool visible)
Sets whether the visualization should be rendered or not.
void setParams(const Params &params)
Definition: Renderer.cpp:94
unsigned int U32
Definition: Defs.hpp:85
Buffer & getBuffer(void) const
Definition: Image.hpp:148
BuilderType builder
Defines which builder type will be used to build the k-d tree.
Definition: KDTree.hpp:99
bool hasError(void)
Definition: Defs.cpp:289
U32 hashBits(U32 a, U32 b=FW_HASH_MAGIC, U32 c=0)
Definition: Hash.hpp:183
Class holding 3d scene.
Definition: Scene.hpp:44
int getTotalNumRays(void)
Definition: Renderer.cpp:429
Buffer & getGlobal(const String &name)
Definition: CudaModule.cpp:117
const Vec2i & getSize(void) const
Definition: Image.hpp:143
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
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 n
Definition: DLLImports.inl:325
Visualization * m_vis
Definition: Renderer.hpp:152
virtual BVHLayout getLayout(void) const =0
Returns layout of buffers.
void printf(const char *fmt,...)
Definition: Defs.cpp:225
RayBuffer m_secondaryRays
Definition: Renderer.hpp:142
Buffer & getVtxNormalBuffer(void)
Returns vertex normal buffer.
Definition: Scene.hpp:110
U32 computeHash() const
Definition: Platform.hpp:162
CudaKernel & launch(void)
Definition: CudaKernel.cpp:179
virtual void setKernel(const String &kernelName)=0
Class holding various SAH and batch processing parameters.
Definition: Platform.hpp:46
void failIfError(void)
Definition: Defs.cpp:361
~Renderer(void)
Definition: Renderer.cpp:57
U32 getU32(void)
Definition: Random.hpp:51
bool enablePrints
Flag whether to print information during build phase.
Definition: KDTree.hpp:98
RayGen m_raygen
Definition: Renderer.hpp:129
U32 computeHash(void) const
Computes hash of the build parameters.
Definition: BVH.hpp:142
const Vec2i & getViewSize(void) const
Definition: GLContext.hpp:148
U32 hash(void)
Definition: Scene.cpp:174
BVH::BuildParams m_buildParams
Definition: Renderer.hpp:128
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 depth
Definition: DLLImports.inl:349
void invalidateBVH(void)
Definition: Renderer.hpp:90
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
Definition: DLLImports.inl:323
void setNeedClosestHit(bool c)
Sets whether the closet hit is needed.
Definition: RayBuffer.hpp:144
#define KDTREE_MASK
Buffer & getVtxTexCoordBuffer(void)
Returns vertex texture coordinate buffer.
Definition: Scene.hpp:117
Platform m_platform
Definition: Renderer.hpp:127
void addOptions(const String &options)
bool m_newBatch
Definition: Renderer.hpp:144
const Vec3f & getPosition(void) const
Window * m_window
Definition: Renderer.hpp:133
void setSourceFile(const String &path)
void displayResult(GLContext *gl)
Definition: Renderer.cpp:416
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
bool m_enableRandom
Definition: Renderer.hpp:134
CUDA tracer for the BVH acceleration structure. Performs BVH traversal on the GPU.
FW_CUDA_FUNC T min(void) const
Definition: Math.hpp:146
bool m_showVis
Definition: Renderer.hpp:153
F32 calcLeafSAHCostCompact(const Platform &platform, Buffer *triIdx, S32 n, S32 &numLeaves)
Definition: Renderer.cpp:528
void mortonSort()
Performs morton sort.
Definition: RayBuffer.cpp:103
Interface for acceleration structure.
Definition: CudaAS.hpp:19
CudaAS * m_accelStruct
Definition: Renderer.hpp:148
Cuda tracer for the k-d tree acceleration structure. Performs kd-tree traversal on the GPU...
void beginFrame(GLContext *gl, const CameraControls &camera)
Definition: Renderer.cpp:267
Random m_random
Definition: Renderer.hpp:130