56 if (m_kernelName == kernelName)
58 m_kernelName = kernelName;
80 if(strstr(kernelName.
getPtr(),
"otracer"))
99 fail(
"CudaBVHTracer: No BVH!");
101 fail(
"CudaBVHTracer: Incorrect BVH layout!");
131 nodePtr + nodeOfsA.x,
132 nodePtr + nodeOfsB.x,
133 nodePtr + nodeOfsC.x,
134 nodePtr + nodeOfsD.x,
143 module->
setTexRef(
"t_nodesA", nodePtr + nodeOfsA.x, nodeOfsA.y, CU_AD_FORMAT_FLOAT, 4);
144 module->
setTexRef(
"t_nodesB", nodePtr + nodeOfsB.x, nodeOfsB.y, CU_AD_FORMAT_FLOAT, 4);
145 module->
setTexRef(
"t_nodesC", nodePtr + nodeOfsC.x, nodeOfsC.y, CU_AD_FORMAT_FLOAT, 4);
146 module->
setTexRef(
"t_nodesD", nodePtr + nodeOfsD.x, nodeOfsD.y, CU_AD_FORMAT_FLOAT, 4);
147 module->
setTexRef(
"t_trisA", triPtr + triOfsA.x, triOfsA.y, CU_AD_FORMAT_FLOAT, 4);
148 module->
setTexRef(
"t_trisB", triPtr + triOfsB.x, triOfsB.y, CU_AD_FORMAT_FLOAT, 4);
149 module->
setTexRef(
"t_trisC", triPtr + triOfsC.x, triOfsC.y, CU_AD_FORMAT_FLOAT, 4);
150 module->
setTexRef(
"t_triIndices", indexBuf, CU_AD_FORMAT_SIGNED_INT32, 1);
154 int desiredWarps = (numRays + 31) / 32;
162 int blockWarps = (blockSize.x * blockSize.y + 31) / 32;
163 int numBlocks = (desiredWarps + blockWarps - 1) / blockWarps;
167 return kernel.
launchTimed(numBlocks * blockSize.x * blockSize.y, blockSize);
193 in.
nodesA = nodePtr + nodeOfsA.x;
194 in.
nodesB = nodePtr + nodeOfsB.x;
195 in.
nodesC = nodePtr + nodeOfsC.x;
196 in.
nodesD = nodePtr + nodeOfsD.x;
197 in.
trisA = triPtr + triOfsA.x;
198 in.
trisB = triPtr + triOfsB.x;
199 in.
trisC = triPtr + triOfsC.x;
222 module->
setTexRef(
"t_nodesA", nodePtr + nodeOfsA.x, nodeOfsA.y, CU_AD_FORMAT_FLOAT, 4);
223 module->
setTexRef(
"t_nodesB", nodePtr + nodeOfsB.x, nodeOfsB.y, CU_AD_FORMAT_FLOAT, 4);
224 module->
setTexRef(
"t_nodesC", nodePtr + nodeOfsC.x, nodeOfsC.y, CU_AD_FORMAT_FLOAT, 4);
225 module->
setTexRef(
"t_nodesD", nodePtr + nodeOfsD.x, nodeOfsD.y, CU_AD_FORMAT_FLOAT, 4);
226 module->
setTexRef(
"t_trisA", triPtr + triOfsA.x, triOfsA.y, CU_AD_FORMAT_FLOAT, 4);
227 module->
setTexRef(
"t_trisB", triPtr + triOfsB.x, triOfsB.y, CU_AD_FORMAT_FLOAT, 4);
228 module->
setTexRef(
"t_trisC", triPtr + triOfsC.x, triOfsC.y, CU_AD_FORMAT_FLOAT, 4);
229 module->
setTexRef(
"t_triIndices", indexBuf, CU_AD_FORMAT_SIGNED_INT32, 1);
233 int desiredWarps = (numRays + 31) / 32;
241 int blockWarps = (blockSize.x * blockSize.y + 31) / 32;
242 int numBlocks = (desiredWarps + blockWarps - 1) / blockWarps;
246 return kernel.
launchTimed(numBlocks * blockSize.x * blockSize.y, blockSize);
252 CudaModule* CudaBVHTracer::compileKernel(
void)
S32 getSize() const
Gets size of the buffer (number of rays).
const char * getPtr(void) const
Buffer & getTriVtxIndexBuffer(void)
Returns buffer of triangle's vertex indieces.
Vec2i getNodeSubArray(int idx) const
Returns node subarray.
CudaModule * compile(bool enablePrints=true, bool autoFail=true)
Buffer & getMaterialIds(void)
Returns material id buffer.
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule * module
const Image * getImage(void) const
BVHLayout getDesiredBVHLayout(void) const
F32 traceBatch(RayBuffer &rays)
Traces given batch of rays.
const Texture & getAtlasTexture(void)
Buffer & getVtxPosBuffer(void)
Returns vertex position buffer.
CUdeviceptr getCudaPtr(S64 ofs=0)
CudaBVHTracer(void)
Constructor.
TextureAtlas * getTextureAtlas(void)
Returns texture atlas holding scene's textures.
CudaKernel getKernel(const String &name)
Definitions for the BVH CUDA Tracer.
~CudaBVHTracer(void)
Destructor.
void setKernel(const String &kernelName)
Sets kernel that should perform the actual traversal of the k-d tree on the gpu.
const U8 * getPtr(S64 ofs=0)
Buffer & getRayBuffer()
Gets ray buffer.
bool getNeedClosestHit() const
Returns whether the closest hit is needed.
void setTexRef(const String &name, Buffer &buf, CUarray_format format, int numComponents)
int getNumVertices(void) const
Buffer & getTextureAtlasInfo(void)
Returns texture atlas information buffer.
CUdeviceptr getMutableCudaPtr(S64 ofs=0)
Buffer & getResultBuffer()
Gets ray result buffer.
BVHLayout getLayout(void) const
Buffer & getTriWoopBuffer(void)
Ray buffer class. Stores rays.
U8 * getMutablePtr(S64 ofs=0)
int getNumTriangles(void) const
String sprintf(const char *fmt,...)
Buffer & getMaterialInfo(void)
Returns material info buffer.
Buffer & getGlobal(const String &name)
Buffer & getTriIndexBuffer(void)
CudaKernel & setParams(const void *ptr, int size)
int getNumEmissive(void) const
Buffer & getVtxNormalBuffer(void)
Returns vertex normal buffer.
CudaKernel & launch(void)
Buffer & getEmissiveTris(void)
Returns buffer of emissive triangles.
Vec2i getTriWoopSubArray(int idx) const
Returns woop triangle subarray.
Buffer & getNodeBuffer(void)
F32 launchTimed(bool yield=true)
static void staticInit(void)
void fail(const char *fmt,...)
Buffer & getVtxTexCoordBuffer(void)
Returns vertex texture coordinate buffer.
void addOptions(const String &options)
void setSourceFile(const String &path)