NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Renderer.hpp
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 #pragma once
29 #include "3d/CameraControls.hpp"
30 #include "base/Random.hpp"
31 #include "cuda/CudaBVHTracer.hpp"
32 #include "ray/RayGen.hpp"
33 
36 #include "Environment.h"
37 
38 
39 namespace FW
40 {
41 //------------------------------------------------------------------------
42 
43 class Renderer
44 {
45 public:
47  {
48  tBVH = 0,
50  };
51 
52  enum RayType
53  {
59 
61  };
62 
63  struct Params
64  {
70 
71  Params(void)
72  {
73  kernelName = "";
75  aoRadius = 1.0f;
76  numSamples = 32;
77  sortSecondary = false;
78  }
79  };
80 
81 private:
82  Environment* m_env;
83 
84 public:
86  ~Renderer (void);
87 
88  void setMesh (MeshBase* mesh);
90  void invalidateBVH (void) { delete m_accelStruct; m_accelStruct = NULL; }
91 
92  void setParams (const Params& params);
94  void setEnableRandom (bool enable) { m_enableRandom = enable; }
95 
97  Scene* getScene (void) const { return m_scene; }
98  CudaAS* getCudaBVH (void);
99 
100  F32 renderFrame (GLContext* gl, const CameraControls& camera); // returns total launch time
101 
102  void beginFrame (GLContext* gl, const CameraControls& camera);
103  bool nextBatch (void);
104  F32 traceBatch (void); // returns launch time
105  void updateResult (void); // for current batch
106  void displayResult (GLContext* gl);
107 
108  int getTotalNumRays (void); // for selected ray type, excluding degenerates
109 
110  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);
111  F32 calcLeafSAHCostCompact(const Platform& platform, Buffer* triIdx, S32 n, S32& numLeaves);
112  F32 calcLeafSAHCostNum (const Platform& platform, S32 n, S32& numLeaves);
113 
114  CudaAS* getCudaKDTree (void);
115 
116  void startBVHVis (void);
117  void endBVHVis (void);
119 
120 protected:
121  Renderer (const Renderer&); // forbidden
122  Renderer& operator= (const Renderer&); // forbidden
123 
124 protected:
131 
135 
138 
143 
147 
150 
153  bool m_showVis;
154 };
155 
156 //------------------------------------------------------------------------
157 }
Class for the visualization.
AccelStructType m_asType
Definition: Renderer.hpp:151
bool nextBatch(void)
Definition: Renderer.cpp:313
Stucture holding the BVH build parameters.
Definition: BVH.hpp:109
Scene * getScene(void) const
Definition: Renderer.hpp:97
#define NULL
Definition: Defs.hpp:39
String m_bvhCachePath
Definition: Renderer.hpp:126
Params m_params
Definition: Renderer.hpp:132
Image * m_image
Definition: Renderer.hpp:139
RayBuffer * m_batchRays
Definition: Renderer.hpp:145
S32 m_batchStart
Definition: Renderer.hpp:146
void setMessageWindow(Window *window)
F32 calcLeafSAHCostNum(const Platform &platform, S32 n, S32 &numLeaves)
Definition: Renderer.cpp:543
Renderer(AccelStructType as, Environment *env)
Definition: Renderer.cpp:11
CudaAS * getCudaBVH(void)
Definition: Renderer.cpp:103
void endBVHVis(void)
Definition: Renderer.cpp:590
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
F32 traceBatch(void)
Definition: Renderer.cpp:364
Scene * m_scene
Definition: Renderer.hpp:137
Definitions for the BVH CUDA Tracer.
Definitions for the ray generator class.
CudaCompiler m_compiler
Definition: Renderer.hpp:125
CudaVirtualTracer * m_cudaTracer
Definition: Renderer.hpp:149
void startBVHVis(void)
Definition: Renderer.cpp:551
void setEnableRandom(bool enable)
Definition: Renderer.hpp:94
RayBuffer m_primaryRays
Definition: Renderer.hpp:141
F32 renderFrame(GLContext *gl, const CameraControls &camera)
Definition: Renderer.cpp:248
void updateResult(void)
Definition: Renderer.cpp:373
float F32
Definition: Defs.hpp:89
Renderer & operator=(const Renderer &)
void setBuildParams(const BVH::BuildParams &params)
Definition: Renderer.hpp:89
MeshBase * m_mesh
Definition: Renderer.hpp:136
Ray buffer class. Stores rays.
Definition: RayBuffer.hpp:38
CudaAS * getCudaKDTree(void)
Definition: Renderer.cpp:190
void setMesh(MeshBase *mesh)
Definition: Renderer.cpp:68
signed int S32
Definition: Defs.hpp:88
Definitions for the BVH visualization framework.
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 toggleBVHVis(void)
Definition: Renderer.hpp:118
Definitions for the Cuda KDTree Tracer.
void setParams(const Params &params)
Definition: Renderer.cpp:94
Class holding 3d scene.
Definition: Scene.hpp:44
int getTotalNumRays(void)
Definition: Renderer.cpp:429
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
void setMessageWindow(Window *window)
Definition: Renderer.hpp:93
RayBuffer m_secondaryRays
Definition: Renderer.hpp:142
Class holding various SAH and batch processing parameters.
Definition: Platform.hpp:46
~Renderer(void)
Definition: Renderer.cpp:57
RayGen m_raygen
Definition: Renderer.hpp:129
CudaVirtualTracer & getCudaTracer(void)
Definition: Renderer.hpp:96
Ray generator class. Generates rays for both the GPU and the CPU.
Definition: RayGen.hpp:47
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
Platform m_platform
Definition: Renderer.hpp:127
bool m_newBatch
Definition: Renderer.hpp:144
virtual void setMessageWindow(Window *window)=0
Window * m_window
Definition: Renderer.hpp:133
void displayResult(GLContext *gl)
Definition: Renderer.cpp:416
bool m_enableRandom
Definition: Renderer.hpp:134
bool m_showVis
Definition: Renderer.hpp:153
F32 calcLeafSAHCostCompact(const Platform &platform, Buffer *triIdx, S32 n, S32 &numLeaves)
Definition: Renderer.cpp:528
Interface for acceleration structure.
Definition: CudaAS.hpp:19
CudaAS * m_accelStruct
Definition: Renderer.hpp:148
void beginFrame(GLContext *gl, const CameraControls &camera)
Definition: Renderer.cpp:267
Random m_random
Definition: Renderer.hpp:130