47inline float renderImage(
bool useCuda,
const RenderFn renderOp,
int width,
int height,
float* image,
const GridT* grid)
49#if defined(__CUDACC__)
56 cudaEvent_t startEv, stopEv;
57 NANOVDB_CUDA_CHECK_ERROR(cudaEventCreate(&startEv), __FILE__, __LINE__);
58 NANOVDB_CUDA_CHECK_ERROR(cudaEventCreate(&stopEv), __FILE__, __LINE__);
60 NANOVDB_CUDA_CHECK_ERROR(cudaEventRecord(startEv, 0), __FILE__, __LINE__);
63 true, width * height, 256, __FILE__, __LINE__, [renderOp, image, grid]
__hostdev__(
int start,
int end) {
64 renderOp(start, end, image, grid);
67 NANOVDB_CUDA_CHECK_ERROR(cudaEventRecord(stopEv, 0), __FILE__, __LINE__);
68 NANOVDB_CUDA_CHECK_ERROR(cudaEventSynchronize(stopEv), __FILE__, __LINE__);
71 NANOVDB_CUDA_CHECK_ERROR(cudaEventElapsedTime(&ms, startEv, stopEv), __FILE__, __LINE__);
73 NANOVDB_CUDA_CHECK_ERROR(cudaEventDestroy(startEv), __FILE__, __LINE__);
74 NANOVDB_CUDA_CHECK_ERROR(cudaEventDestroy(stopEv), __FILE__, __LINE__);
79 using ClockT = std::chrono::high_resolution_clock;
80 auto t0 = ClockT::now();
83 useCuda, width * height, 256, __FILE__, __LINE__, [renderOp, image, grid]
__hostdev__(
int start,
int end) {
84 renderOp(start, end, image, grid);
88 auto t1 = ClockT::now();
89 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count() / 1000.f;
143 const float fov = 45.f;
144 const float u = (float(x) + 0.5f) / w;
145 const float v = (float(y) + 0.5f) / h;
146 const float aspect = w / float(h);
147 const float Px = (2.f * u - 1.f) * tanf(fov / 2 * 3.14159265358979323846f / 180.f) * aspect;
148 const float Py = (2.f * v - 1.f) * tanf(fov / 2 * 3.14159265358979323846f / 180.f);
150 Vec3T dir(Px, Py, -1.f);
void computeForEach(bool useCuda, int numItems, int blockSize, const char *file, int line, const FunctorT &op, Args... args)
Definition ComputePrimitives.h:128
void computeSync(bool useCuda, const char *file, int line)
Definition ComputePrimitives.h:107
float renderImage(bool useCuda, const RenderFn renderOp, int width, int height, float *image, const GridT *grid)
Definition common.h:47
void saveImage(const std::string &filename, int width, int height, const float *image)
Definition common.h:63
__hostdev__ void operator()(float *outImage, int i, int w, int h, float value, float alpha) const
Definition common.h:159
__hostdev__ void operator()(int i, int w, int h, Vec3T &outOrigin, Vec3T &outDir) const
Definition common.h:133