NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Platform.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 
33 #pragma once
34 #include "base/String.hpp"
35 #include "base/Hash.hpp"
36 
37 namespace FW
38 {
39 
40 class LeafNode;
41 class BVHNode;
42 
46 class Platform
47 {
48 public:
49 
53  Platform() { m_name=String("Default"); m_SAHNodeCost = 1.f; m_SAHTriangleCost = 1.f; m_nodeBatchSize = 1; m_triBatchSize = 1; m_minLeafSize=1; m_maxLeafSize=0x7FFFFFF; }
54 
63  Platform(const String& name, float nodeCost=1.f, float triCost=1.f, S32 nodeBatchSize=1, S32 triBatchSize=1) { m_name=name; m_SAHNodeCost = nodeCost; m_SAHTriangleCost = triCost; m_nodeBatchSize = nodeBatchSize; m_triBatchSize = triBatchSize; m_minLeafSize=1; m_maxLeafSize=0x7FFFFFF; }
64 
68  const String& getName() const { return m_name; }
69 
70  // SAH weights
74  float getSAHTriangleCost() const { return m_SAHTriangleCost; }
75 
79  float getSAHNodeCost() const { return m_SAHNodeCost; }
80 
81  // SAH costs, raw and batched
88  float getCost(int numChildNodes, int numTris) const { return getNodeCost(numChildNodes) + getTriangleCost(numTris); }
89 
95  float getTriangleCost(S32 n) const { return roundToTriangleBatchSize(n) * m_SAHTriangleCost; }
96 
102  float getNodeCost(S32 n) const { return roundToNodeBatchSize(n) * m_SAHNodeCost; }
103 
104  // batch processing (how many ops at the price of one)
108  S32 getTriangleBatchSize() const { return m_triBatchSize; }
109 
113  S32 getNodeBatchSize() const { return m_nodeBatchSize; }
114 
119  void setTriangleBatchSize(S32 triBatchSize) { m_triBatchSize = triBatchSize; }
120 
125  void setNodeBatchSize(S32 nodeBatchSize) { m_nodeBatchSize = nodeBatchSize; }
126 
132  S32 roundToTriangleBatchSize(S32 n) const { return ((n+m_triBatchSize-1)/m_triBatchSize)*m_triBatchSize; }
133 
139  S32 roundToNodeBatchSize(S32 n) const { return ((n+m_nodeBatchSize-1)/m_nodeBatchSize)*m_nodeBatchSize; }
140 
141  // leaf preferences
147  void setLeafPreferences(S32 minSize, S32 maxSize) { m_minLeafSize=minSize; m_maxLeafSize=maxSize; }
148 
152  S32 getMinLeafSize() const { return m_minLeafSize; }
153 
157  S32 getMaxLeafSize() const { return m_maxLeafSize; }
158 
162  U32 computeHash() const { return hashBits(hash<String>(m_name), floatToBits(m_SAHNodeCost), floatToBits(m_SAHTriangleCost), hashBits(m_triBatchSize, m_nodeBatchSize, m_minLeafSize, m_maxLeafSize)); }
163 
164 private:
165  String m_name;
166  float m_SAHNodeCost;
167  float m_SAHTriangleCost;
168  S32 m_triBatchSize;
169  S32 m_nodeBatchSize;
170  S32 m_minLeafSize;
171  S32 m_maxLeafSize;
172 };
173 
174 } //
const String & getName() const
Definition: Platform.hpp:68
U32 floatToBits(F32 a)
Definition: Math.hpp:95
void setLeafPreferences(S32 minSize, S32 maxSize)
Sets leaf size preferences (desired number of triangles in one leaf node).
Definition: Platform.hpp:147
S32 getTriangleBatchSize() const
Definition: Platform.hpp:108
S32 getNodeBatchSize() const
Definition: Platform.hpp:113
const char * name
Definition: DLLImports.cpp:42
void setTriangleBatchSize(S32 triBatchSize)
Sets triangle batch size to a given value.
Definition: Platform.hpp:119
void setNodeBatchSize(S32 nodeBatchSize)
Sets node batch size to a given value.
Definition: Platform.hpp:125
Platform(const String &name, float nodeCost=1.f, float triCost=1.f, S32 nodeBatchSize=1, S32 triBatchSize=1)
Constructor.
Definition: Platform.hpp:63
float getSAHNodeCost() const
Definition: Platform.hpp:79
float getTriangleCost(S32 n) const
Calcuates cost of a given number of triangles rounded to the batch size.
Definition: Platform.hpp:95
S32 roundToTriangleBatchSize(S32 n) const
Rounds given value up to the nearest triangle batch size multiple.
Definition: Platform.hpp:132
Platform()
Constructor.
Definition: Platform.hpp:53
float getNodeCost(S32 n) const
Calculates cost of a given number of nodes rounded to the batch size.
Definition: Platform.hpp:102
signed int S32
Definition: Defs.hpp:88
unsigned int U32
Definition: Defs.hpp:85
U32 hashBits(U32 a, U32 b=FW_HASH_MAGIC, U32 c=0)
Definition: Hash.hpp:183
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
U32 computeHash() const
Definition: Platform.hpp:162
S32 getMaxLeafSize() const
Definition: Platform.hpp:157
Class holding various SAH and batch processing parameters.
Definition: Platform.hpp:46
U32 hash< String >(const String &value)
Definition: Hash.hpp:273
float getCost(int numChildNodes, int numTris) const
Calculates cost of a single node.
Definition: Platform.hpp:88
float getSAHTriangleCost() const
Definition: Platform.hpp:74
S32 getMinLeafSize() const
Definition: Platform.hpp:152
S32 roundToNodeBatchSize(S32 n) const
Rounds given value up to the nearest node batch size multiple.
Definition: Platform.hpp:139