Tachyon (current)  Current Main Branch
TachyonOptiX.h
Go to the documentation of this file.
1 /*
2  * TachyonOptiX.h - OptiX host-side RT engine APIs and data structures
3  *
4  * (C) Copyright 2013-2022 John E. Stone
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * $Id: TachyonOptiX.h,v 1.57 2022/04/19 02:54:24 johns Exp $
8  *
9  */
10 
26 //
27 // This is a second generation of the Tachyon implementation for OptiX.
28 // The new implementation favors the strengths of OptiX 7, and uses
29 // OptiX ray payload registers, direct CUDA interoperability and advanced
30 // CUDA features for both performance and maintainability.
31 //
32 // This software and its line of antecedants are described in:
33 // "Multiscale modeling and cinematic visualization of photosynthetic
34 // energy conversion processes from electronic to cell scales"
35 // M. Sener, S. Levy, J. E. Stone, AJ Christensen, B. Isralewitz,
36 // R. Patterson, K. Borkiewicz, J. Carpenter, C. N. Hunter,
37 // Z. Luthey-Schulten, D. Cox.
38 // J. Parallel Computing, 102, pp. 102698, 2021.
39 // https://doi.org/10.1016/j.parco.2020.102698
40 //
41 // "Omnidirectional Stereoscopic Projections for VR"
42 // J. E. Stone. In, William R. Sherman, editor,
43 // VR Developer Gems, Taylor and Francis / CRC Press, Chapter 24, 2019.
44 // https://www.taylorfrancis.com/chapters/edit/10.1201/b21598-24/omnidirectional-stereoscopic-projections-vr-john-stone
45 //
46 // "Interactive Ray Tracing Techniques for
47 // High-Fidelity Scientific Visualization"
48 // J. E. Stone. In, Eric Haines and Tomas Akenine-Möller, editors,
49 // Ray Tracing Gems, Apress, Chapter 27, pp. 493-515, 2019.
50 // https://link.springer.com/book/10.1007/978-1-4842-4427-2
51 //
52 // "A Planetarium Dome Master Camera"
53 // J. E. Stone. In, Eric Haines and Tomas Akenine-Möller, editors,
54 // Ray Tracing Gems, Apress, Chapter 4, pp. 49-60, 2019.
55 // https://link.springer.com/book/10.1007/978-1-4842-4427-2
56 //
57 // "Immersive Molecular Visualization with Omnidirectional
58 // Stereoscopic Ray Tracing and Remote Rendering"
59 // J. E. Stone, W. R. Sherman, and K. Schulten.
60 // High Performance Data Analysis and Visualization Workshop,
61 // 2016 IEEE International Parallel and Distributed Processing
62 // Symposium Workshops (IPDPSW), pp. 1048-1057, 2016.
63 // http://dx.doi.org/10.1109/IPDPSW.2016.121
64 //
65 // "Atomic Detail Visualization of Photosynthetic Membranes with
66 // GPU-Accelerated Ray Tracing"
67 // J. E. Stone, M. Sener, K. L. Vandivort, A. Barragan, A. Singharoy,
68 // I. Teo, J. V. Ribeiro, B. Isralewitz, B. Liu, B.-C. Goh, J. C. Phillips,
69 // C. MacGregor-Chatwin, M. P. Johnson, L. F. Kourkoutis, C. N. Hunter,
70 // K. Schulten
71 // J. Parallel Computing, 55:17-27, 2016.
72 // http://dx.doi.org/10.1016/j.parco.2015.10.015
73 //
74 // "GPU-Accelerated Molecular Visualization on
75 // Petascale Supercomputing Platforms"
76 // J. E. Stone, K. L. Vandivort, and K. Schulten.
77 // UltraVis'13: Proceedings of the 8th International Workshop on
78 // Ultrascale Visualization, pp. 6:1-6:8, 2013.
79 // http://dx.doi.org/10.1145/2535571.2535595
80 //
81 // "An Efficient Library for Parallel Ray Tracing and Animation"
82 // John E. Stone. Master's Thesis, University of Missouri-Rolla,
83 // Department of Computer Science, April 1998
84 // https://scholarsmine.mst.edu/masters_theses/1747
85 //
86 // "Rendering of Numerical Flow Simulations Using MPI"
87 // J. Stone and M. Underwood.
88 // Second MPI Developers Conference, pages 138-141, 1996.
89 // http://dx.doi.org/10.1109/MPIDC.1996.534105
90 //
91 
92 #ifndef TACHYONOPTIX_H
93 #define TACHYONOPTIX_H
94 
95 #if 0
96 #define TACHYON_CUMEMBUF_FORCE_SYNCHRONOUS 1
99 
103 #define TACHYON_CUMEMBUF_FORCE_FREE 1
104 
105 
108 #define TACHYON_USEPINNEDMEMORY 1
109 
110 #endif
111 
112 #if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)
113 // OptiX headers require NOMINMAX be defined for Windows builds
114 #define NOMINMAX 1
115 #endif
116 
117 #include <cuda.h>
118 #include <cuda_runtime.h>
119 #include <optix.h>
120 
121 #include <stdio.h>
122 #include <stdlib.h>
123 #include <string.h>
124 #include <math.h>
125 #include <vector>
126 
127 // When compiling using the classic Tachyon-internal timer API,
128 // we use the non-renamed rt_xxx API struct and function names.
129 #if defined(TACHYONINTERNAL)
130 #define wkf_timerhandle rt_timerhandle
131 #define wkf_timer_create rt_timer_create
132 #define wkf_timer_start rt_timer_start
133 #define wkf_timer_stop rt_timer_stop
134 #define wkf_timer_time rt_timer_time
135 #define wkf_timer_timenow rt_timer_timenow
136 #define wkf_timer_destroy rt_timer_destroy
137 #include "util.h"
138 #else
139 #include "WKFUtils.h"
140 #endif
141 #include "TachyonOptiXShaders.h"
142 
143 
144 #if defined(TACHYON_USEPINNEDMEMORY)
145 //
146 // Include NVIDIA Thrust lib for special pinned allocator support
147 //
148 #include <cuda_runtime.h>
149 
150 // THRUST_VERSION >= 100904
151 // Thrust 1.9.4 adds new thrust::universal_host_pinned_memory_resource
152 // for getting pinned memory, but this isn't a drop-in replacement for
153 // what we've been doing with the experimental pinned allocator.
154 // For now we continue using the existing interface.
155 #include <thrust/system/cuda/experimental/pinned_allocator.h>
156 
158 #define THRUSTPINALLOC thrust::system::cuda::experimental::pinned_allocator
159 #define PINALLOCS(memtype) ,thrust::system::cuda::experimental::pinned_allocator<memtype>
161 
162 #else
163 #define PINALLOCS(memtype)
165 #endif
166 
167 
168 // Tachyon profiling colors
169 #define RTPROF_GENERAL PROFILE_BLUE
170 #define RTPROF_ACCEL PROFILE_RED
171 #define RTPROF_SBT PROFILE_TEAL
172 #define RTPROF_RENDER PROFILE_ORANGE
173 #define RTPROF_RENDERRT PROFILE_YELLOW
174 #define RTPROF_TRANSFER PROFILE_RED
175 #define RTPROF_GEOM PROFILE_PURPLE
176 
177 struct ConeArray {
178  std::vector<float3 PINALLOCS(float3)> base;
179  std::vector<float3 PINALLOCS(float3)> apex;
180  std::vector<float PINALLOCS(float)> baserad;
181  std::vector<float PINALLOCS(float)> apexrad;
182  std::vector<float3 PINALLOCS(float3)> primcolors3f;
185 
186  void addCone(const float3 &cbase, const float3 &capex,
187  const float cbaserad, const float capexrad) {
188  base.push_back(cbase);
189  apex.push_back(capex);
190  baserad.push_back(cbaserad);
191  apexrad.push_back(capexrad);
192  }
193 };
194 
195 
197  std::vector<float3 PINALLOCS(float3)> start;
198  std::vector<float3 PINALLOCS(float3)> end;
199  std::vector<float PINALLOCS(float)> radius;
200  std::vector<float3 PINALLOCS(float3)> primcolors3f;
203 
204  void addCylinder(const float3 &cstart, const float3 &cend, const float crad) {
205  start.push_back(cstart);
206  end.push_back(cend);
207  radius.push_back(crad);
208  }
209 };
210 
211 
212 struct QuadMesh {
213  std::vector<float3 PINALLOCS(float3)> vertices;
214  std::vector<int4 PINALLOCS(int4)> indices;
215  std::vector<float3 PINALLOCS(float3)> normals;
216  std::vector<uint4 PINALLOCS(uint4)> packednormals;
217  std::vector<float3 PINALLOCS(float3)> vertcolors3f;
218  std::vector<uchar4 PINALLOCS(uchar4)> vertcolors4u;
219  std::vector<float3 PINALLOCS(float3)> primcolors3f;
222 };
223 
224 
225 struct RingArray {
226  std::vector<float3 PINALLOCS(float3)> center;
227  std::vector<float3 PINALLOCS(float3)> normal;
228  std::vector<float PINALLOCS(float)> inrad;
229  std::vector<float PINALLOCS(float)> outrad;
230  std::vector<float3 PINALLOCS(float3)> primcolors3f;
233 
234  void addRing(const float3 &ricenter, const float3 &rinorm,
235  const float riinrad, const float rioutrad) {
236  center.push_back(ricenter);
237  normal.push_back(rinorm);
238  inrad.push_back(riinrad);
239  outrad.push_back(rioutrad);
240  }
241 };
242 
243 
244 struct SphereArray {
245  std::vector<float3 PINALLOCS(float3)> center;
246  std::vector<float PINALLOCS(float)> radius;
247  std::vector<float3 PINALLOCS(float3)> primcolors3f;
250 
251  void addSphere(const float3 &spcenter, const float &spradius) {
252  center.push_back(spcenter);
253  radius.push_back(spradius);
254  }
255 };
256 
257 
258 struct CurveArray {
259  std::vector<float3 PINALLOCS(float3)> vertices;
260  std::vector<float PINALLOCS(float)> vertradii;
261  std::vector<int PINALLOCS(int)> segindices;
262  // std::vector<float3 PINALLOCS(float3)> normals; // XXX not implemented in Optix <= 7.4
263  std::vector<float3 PINALLOCS(float3)> primcolors3f;
266 
267  void addCurve(const float *verts, const int numverts,
268  const float *rads, const int numradii,
269  const int *sidxs, const int numindices) {
270  for (int i=0; i<numverts; i++) {
271  vertices.push_back(make_float3(verts[3*i ],
272  verts[3*i + 1],
273  verts[3*i + 2]));
274  }
275  for (int i=0; i<numradii; i++) {
276  vertradii.push_back(rads[i]);
277  }
278  for (int i=0; i<numindices; i++) {
279  segindices.push_back(sidxs[i]);
280  }
281  }
282 };
283 
284 
285 struct TriangleMesh {
286  std::vector<float3 PINALLOCS(float3) > vertices;
287  std::vector<int3 PINALLOCS(int3) > indices;
288  std::vector<float3 PINALLOCS(float3) > normals;
289  std::vector<uint4 PINALLOCS(uint4) > packednormals;
290  std::vector<float3 PINALLOCS(float3) > vertcolors3f;
291  std::vector<uchar4 PINALLOCS(uchar4) > vertcolors4u;
292  std::vector<float3 PINALLOCS(float3) > primcolors3f;
293  std::vector<float2 PINALLOCS(float2) > tex2d;
294  std::vector<float3 PINALLOCS(float3) > tex3d;
297 
298  void addCube(const float3 &center, const float3 &s /* size */) {
299  int firstVertexID = (int)vertices.size();
300  vertices.push_back(center + make_float3(s.x*0.f, s.y*0.f, s.z*0.f));
301  vertices.push_back(center + make_float3(s.x*1.f, s.y*0.f, s.z*0.f));
302  vertices.push_back(center + make_float3(s.x*0.f, s.y*1.f, s.z*0.f));
303  vertices.push_back(center + make_float3(s.x*1.f, s.y*1.f, s.z*0.f));
304  vertices.push_back(center + make_float3(s.x*0.f, s.y*0.f, s.z*1.f));
305  vertices.push_back(center + make_float3(s.x*1.f, s.y*0.f, s.z*1.f));
306  vertices.push_back(center + make_float3(s.x*0.f, s.y*1.f, s.z*1.f));
307  vertices.push_back(center + make_float3(s.x*1.f, s.y*1.f, s.z*1.f));
308  int ind[] = {0,1,3, 2,3,0,
309  5,7,6, 5,6,4,
310  0,4,5, 0,5,1,
311  2,3,7, 2,7,6,
312  1,5,7, 1,7,3,
313  4,0,2, 4,2,6
314  };
315  for (int i=0; i<12; i++)
316  indices.push_back(make_int3(ind[3*i+0] + firstVertexID,
317  ind[3*i+1] + firstVertexID,
318  ind[3*i+2] + firstVertexID));
319  }
320 };
321 
322 
328 struct CUMemBuf {
329  size_t sz { 0 };
330  size_t dmemsz { 0 };
331  void *d_ptr { nullptr };
332 
333  inline void * dptr() const {
334  // if we've kept GPU memory allocations persistent but the current
335  // stored size is zero, we return a NULL device pointer if a caller
336  // asks for it, to indicate that there's nothing here. This emulates
337  // the previous behavior of the non-persistent allocation scheme.
338  return (sz > 0) ? d_ptr : 0;
339  }
340 
341  inline CUdeviceptr cu_dptr() const {
342  // if we've kept GPU memory allocations persistent but the current
343  // stored size is zero, we return a NULL device pointer if a caller
344  // asks for it, to indicate that there's nothing here. This emulates
345  // the previous behavior of the non-persistent allocation scheme.
346  return CUdeviceptr((sz > 0) ? d_ptr : 0);
347  }
348 
350  size_t get_size(void) {
351  return sz;
352  }
353 
355  void set_size(size_t newsize) {
356  // don't reallocate unless it is strictly necessary since
357  // CUDA memory management operations are very costly
358  if (newsize > dmemsz) {
359  if (d_ptr)
360  this->free();
361 
362  sz = newsize;
363  dmemsz = newsize;
364  cudaMalloc((void**) &d_ptr, dmemsz);
365  } else {
366  // use the existing CUDA memory allocation, but change the stored size
367  sz = newsize;
368  }
369  }
370 
372  void set_size(size_t newsize, cudaStream_t stream) {
373 #if !defined(TACHYON_CUMEMBUF_FORCE_FREE)
374  // don't reallocate unless it is strictly necessary since
375  // CUDA memory management operations are very costly
376  if (newsize != dmemsz) {
377  if (d_ptr)
378  this->free(stream);
379 #if defined(TACHYON_CUMEMBUF_FORCE_SYNCHRONOUS)
380  cudaStreamSynchronize(stream);
381 #endif
382 
383  sz = newsize;
384  dmemsz = newsize;
385 #if CUDA_VERSION >= 11200
386  cudaMallocAsync((void**) &d_ptr, dmemsz, stream);
387 #else
388  cudaMalloc((void**) &d_ptr, dmemsz);
389 #endif
390 #if defined(TACHYON_CUMEMBUF_FORCE_SYNCHRONOUS)
391  cudaStreamSynchronize(stream);
392 #endif
393  } else {
394  // use the existing CUDA memory allocation, but change the stored size
395  sz = newsize;
396  }
397 #else
398  // don't reallocate unless it is strictly necessary since
399  // CUDA memory management operations are very costly
400  if (newsize != sz) {
401  if (d_ptr)
402  this->free(stream);
403 #if defined(TACHYON_CUMEMBUF_FORCE_SYNCHRONOUS)
404  cudaStreamSynchronize(stream);
405 #endif
406 
407  sz = newsize;
408  dmemsz = newsize;
409 #if CUDA_VERSION >= 11200
410  cudaMallocAsync((void**) &d_ptr, dmemsz, stream);
411 #else
412  cudaMalloc((void**) &d_ptr, dmemsz);
413 #endif
414 #if defined(TACHYON_CUMEMBUF_FORCE_SYNCHRONOUS)
415  cudaStreamSynchronize(stream);
416 #endif
417  }
418 #endif
419 
420  }
421 
422 
425 #if defined(TACHYON_CUMEMBUF_FORCE_FREE)
426  free();
427 #endif
428  sz = 0;
429  }
430 
431 
433  void free() {
434  cudaFree(d_ptr);
435  d_ptr = nullptr;
436  sz = 0;
437  dmemsz = 0;
438  }
439 
440 
442  void free(cudaStream_t stream) {
443 #if CUDA_VERSION >= 11200
444  cudaFreeAsync(d_ptr, stream);
445 #else
446  cudaFree(d_ptr);
447 #endif
448 #if defined(TACHYON_CUMEMBUF_FORCE_SYNCHRONOUS)
449  cudaStreamSynchronize(stream);
450 #endif
451  d_ptr = nullptr;
452  sz = 0;
453  dmemsz = 0;
454  }
455 
456 
457  //
458  // synchronous copies that also allocate/resize the buffer
459  //
460  // XXX Should seriously look at the viability of using 'GDRCopy' rather
461  // than the standard CUDA APIs for small payloads where latency
462  // dominates and/or when they are used for repetitive minor updates
463  // to GPU-side state. GDRCopy depends on some kernel driver components,
464  // but they are likely already installed on HPC systems w/ InfiniBand:
465  // https://github.com/NVIDIA/gdrcopy
466  //
467 
470  template<typename T>
471  void resize_upload(const std::vector<T> &vecT) {
472  set_size(vecT.size()*sizeof(T));
473  upload((const T*) vecT.data(), vecT.size());
474  }
475 
478  template<typename T>
479  void resize_upload(const T *t, size_t cnt) {
480  set_size(cnt*sizeof(T));
481  cudaMemcpy(d_ptr, (void *)t, cnt*sizeof(T), cudaMemcpyHostToDevice);
482  }
483 
484 
485  //
486  // async versions of resize_upload() w/ stream parameter
487  //
488 
492  template<typename T>
493  void resize_upload(const std::vector<T> &vecT, cudaStream_t stream) {
494  set_size(vecT.size()*sizeof(T), stream);
495  upload((const T*) vecT.data(), vecT.size(), stream);
496  }
497 
501  template<typename T>
502  void resize_upload(const T *t, size_t cnt, cudaStream_t stream) {
503  set_size(cnt*sizeof(T), stream);
504  cudaMemcpyAsync(d_ptr, (void *)t, cnt*sizeof(T),
505  cudaMemcpyHostToDevice, stream);
506 #if defined(TACHYON_CUMEMBUF_FORCE_SYNCHRONOUS)
507  cudaStreamSynchronize(stream);
508 #endif
509  }
510 
511 
512 #if defined(TACHYON_USEPINNEDMEMORY)
513  //
514  // Pinned memory allocator variants of both sync and async resize_upload().
515  // These must exist to support std::vector instantiations based on the
516  // Thrust pinned allocator.
517  //
518 
523  template<typename T>
524  void resize_upload(const std::vector<T, THRUSTPINALLOC<T>> &vecT) {
525  set_size(vecT.size()*sizeof(T));
526  upload((const T*) vecT.data(), vecT.size());
527  }
528 
533  template<typename T>
534  void resize_upload(const std::vector<T, THRUSTPINALLOC<T>> &vecT, cudaStream_t stream) {
535  set_size(vecT.size()*sizeof(T), stream);
536  upload((const T*) vecT.data(), vecT.size(), stream);
537  }
538 #endif
539 
540 
541  //
542  // synchronous DMA copies
543  //
544  // XXX Should seriously look at the viability of using 'GDRCopy' rather
545  // than the standard CUDA APIs for small payloads where latency
546  // dominates and/or when they are used for repetitive minor updates
547  // to GPU-side state. GDRCopy depends on some kernel driver components,
548  // but they are likely already installed on HPC systems w/ InfiniBand:
549  // https://github.com/NVIDIA/gdrcopy
550  //
551 
553  template<typename T>
554  void upload(const T *t, size_t cnt) {
555  cudaMemcpy(d_ptr, (void *)t, cnt*sizeof(T), cudaMemcpyHostToDevice);
556  }
557 
559  template<typename T>
560  void download(T *t, size_t cnt) {
561  cudaMemcpy((void *)t, d_ptr, cnt*sizeof(T), cudaMemcpyDeviceToHost);
562  }
563 
564 
565  //
566  // asynchronous DMA copies
567  //
568 
571  template<typename T>
572  void upload(const T *t, size_t cnt, cudaStream_t stream) {
573  cudaMemcpyAsync(d_ptr, (void *)t,
574  cnt*sizeof(T), cudaMemcpyHostToDevice, stream);
575 #if defined(TACHYON_CUMEMBUF_FORCE_SYNCHRONOUS)
576  cudaStreamSynchronize(stream);
577 #endif
578  }
579 
582  template<typename T>
583  void download_async(T *t, size_t cnt, cudaStream_t stream) {
584  cudaMemcpyAsync((void *)t, d_ptr,
585  cnt*sizeof(T), cudaMemcpyDeviceToHost, stream);
586 #if defined(TACHYON_CUMEMBUF_FORCE_SYNCHRONOUS)
587  cudaStreamSynchronize(stream);
588 #endif
589  }
590 };
591 
592 
594  //
595  // primitive array buffers
596  //
597  std::vector<ConeArray> conearrays;
598  std::vector<CurveArray> curvearrays;
599  std::vector<CylinderArray> cyarrays;
600  std::vector<RingArray> riarrays;
601  std::vector<SphereArray> sparrays;
602  std::vector<TriangleMesh> trimeshes;
603 
604  // GASes get rebuilt upon any group geometry changes
605  std::vector<HGRecordGroup> sbtHGRecGroups;
607 #if OPTIX_VERSION >= 70100
608  CUMemBuf curvesGASBuffer;
609 #endif
611 
612  std::vector<float *> transforms;
613 };
614 
615 
617 public:
622  };
623 
627  };
628 
629  enum FogMode {
634  // XXX should explicitly define radial/omnidirection fog types also
635  };
636 
637  enum CameraType {
645  };
646 
647  enum Verbosity {
651  };
652 
653  enum BGMode {
657  };
658 
659 private:
660  int context_created;
661  CUcontext cuda_ctx;
662  CUstream stream;
663  OptixDeviceContext optix_ctx;
664  OptixResult lasterr;
665  Verbosity verbose;
666 
667  char shaderpath[8192];
668 
669  wkf_timerhandle rt_timer;
670  double time_ctx_create;
671  double time_ctx_setup;
672  double time_ctx_validate;
673  double time_ctx_AS_build;
674  double time_ctx_destroy_scene;
675  double time_ray_tracing;
676  double time_image_io;
677 
678  //
679  // OptiX launch parameters
680  //
681  tachyonLaunchParams rtLaunch;
682  CUMemBuf launchParamsBuffer;
683 
684  //
685  // OptiX framebuffers and associated state
686  //
687  int width;
688  int height;
689  int colorspace;
690 
691  CUMemBuf framebuffer;
692  CUMemBuf accumulation_buffer;
693 
694 #if defined(TACHYON_OPTIXDENOISER)
695  OptixDenoiser denoiser_ctx;
696  OptixDenoiserOptions denoiser_options;
697  OptixDenoiserSizes denoiser_sizes;
698 
699  // extra buffers required for denoising
700  CUMemBuf denoiser_colorbuffer;
701  CUMemBuf denoiser_denoisedbuffer;
702  CUMemBuf denoiser_scratch;
703  CUMemBuf denoiser_state;
704 #endif
705 
706 #if defined(TACHYON_RAYSTATS)
707  CUMemBuf raystats1_buffer;
708  CUMemBuf raystats2_buffer;
709 #endif
710 
711 
712  //
713  // OptiX pipeline and shader compilations
714  //
715 
716  // the PTX module that contains all device programs
717  char * rt_ptx_code_string = {};
718  OptixPipelineCompileOptions pipeCompOpts = {};
719  OptixModule general_module;
720  OptixModule curve_module;
721 
722  std::vector<OptixProgramGroup> exceptionPGs;
723  std::vector<OptixProgramGroup> raygenPGs;
724  std::vector<OptixProgramGroup> missPGs;
725  std::vector<OptixProgramGroup> custprimPGs;
726  std::vector<OptixProgramGroup> curvePGs;
727  std::vector<OptixProgramGroup> trimeshPGs;
728 
729  // SBT-associated GPU data structures
730  // SBT must be entirely rebuilt upon any change to the rendering pipeline
731  CUMemBuf exceptionRecordsBuffer;
732  CUMemBuf raygenRecordsBuffer;
733  CUMemBuf missRecordsBuffer;
734 
735  std::vector<TachyonInstanceGroup> sceneinstancegroups;
736 
737  int sync_hitgroupRecordGroups;
738  std::vector<HGRecordGroup> hitgroupRecordGroups; // all GeomSBTHG recs
739 
740  CUMemBuf hitgroupRecordsBuffer;
741  OptixShaderBindingTable sbt = {};
742 
743  // OptiX RT pipeline produced from all of raygen/miss/hitgroup PGs
744  OptixPipeline pipe;
745 
746  // generic temporary buffer used by AS builders
747  // This temp buffer only grows and will not shrink unless the entire context
748  // is destroyed, or the minimize_memory_use() API is called.
749  CUMemBuf ASTempBuffer;
750  CUMemBuf compactedSizeBuffer;
751 
752  // GASes get rebuilt upon any scene geometry changes
753  CUMemBuf custprimsGASBuffer;
754  CUMemBuf curvesGASBuffer;
755  CUMemBuf trimeshesGASBuffer;
756 
757  // IAS to combine all triangle, curve, and custom primitive GASes together
758  // The scene-wide IAS buffer only grows and will not shrink unless
759  // the entire context is destroyed, or the minimize_memory_use() API
760  // is called.
761  CUMemBuf IASBuffer;
762 
763 
764  //
765  // primitive array buffers
766  //
767  std::vector<CUMemBuf> coneAabbBuffers;
768  std::vector<CUMemBuf> coneBaseBuffers;
769  std::vector<CUMemBuf> coneApexBuffers;
770  std::vector<CUMemBuf> coneBaseRadBuffers;
771  std::vector<CUMemBuf> coneApexRadBuffers;
772  std::vector<CUMemBuf> conePrimColorBuffers;
773  std::vector<ConeArray> conearrays;
774 
775  std::vector<CUMemBuf> curveVertBuffers;
776  std::vector<CUMemBuf> curveVertRadBuffers;
777  std::vector<CUMemBuf> curveSegIdxBuffers;
778  std::vector<CUMemBuf> curvePrimColorBuffers;
779  std::vector<CurveArray> curvearrays;
780 
781  std::vector<CUMemBuf> cyAabbBuffers;
782  std::vector<CUMemBuf> cyStartBuffers;
783  std::vector<CUMemBuf> cyEndBuffers;
784  std::vector<CUMemBuf> cyRadiusBuffers;
785  std::vector<CUMemBuf> cyPrimColorBuffers;
786  std::vector<CylinderArray> cyarrays;
787 
788  std::vector<CUMemBuf> quadMeshAabbBuffers;
789  std::vector<CUMemBuf> quadMeshVertBuffers;
790  std::vector<CUMemBuf> quadMeshIdxBuffers;
791  std::vector<CUMemBuf> quadMeshVertNormalBuffers;
792  std::vector<CUMemBuf> quadMeshVertPackedNormalBuffers;
793  std::vector<CUMemBuf> quadMeshVertColor3fBuffers;
794  std::vector<CUMemBuf> quadMeshVertColor4uBuffers;
795  std::vector<CUMemBuf> quadMeshPrimColorBuffers;
796  std::vector<QuadMesh> quadmeshes;
797 
798  std::vector<CUMemBuf> riAabbBuffers;
799  std::vector<CUMemBuf> riCenterBuffers;
800  std::vector<CUMemBuf> riNormalBuffers;
801  std::vector<CUMemBuf> riInRadiusBuffers;
802  std::vector<CUMemBuf> riOutRadiusBuffers;
803  std::vector<CUMemBuf> riPrimColorBuffers;
804  std::vector<RingArray> riarrays;
805 
806  std::vector<CUMemBuf> spAabbBuffers;
807  std::vector<CUMemBuf> spPosRadiusBuffers;
808  std::vector<CUMemBuf> spPrimColorBuffers;
809  std::vector<SphereArray> sparrays;
810 
811  std::vector<CUMemBuf> triMeshVertBuffers;
812  std::vector<CUMemBuf> triMeshIdxBuffers;
813  std::vector<CUMemBuf> triMeshVertNormalBuffers;
814  std::vector<CUMemBuf> triMeshVertPackedNormalBuffers;
815  std::vector<CUMemBuf> triMeshVertColor3fBuffers;
816  std::vector<CUMemBuf> triMeshVertColor4uBuffers;
817  std::vector<CUMemBuf> triMeshPrimColorBuffers;
818  std::vector<CUMemBuf> triMeshTex2dBuffers;
819  std::vector<CUMemBuf> triMeshTex3dBuffers;
820  std::vector<TriangleMesh> trimeshes;
821 
822 
823  //
824  // OptiX shader state variables and the like
825  //
826  unsigned int scene_max_depth;
827  int scene_max_trans;
828 
829  float scene_epsilon;
830 
831  int ext_aa_loops;
832  int aa_samples;
833 
834  int denoiser_enabled;
835  int shadows_enabled;
836 
837  int ao_samples;
838  float ao_ambient;
839  float ao_direct;
840  float ao_maxdist;
841 
842  int headlight_mode;
843 
844  // clipping plane/sphere parameters
845  int clipview_mode;
846  float clipview_start;
847  float clipview_end;
848 
849  float cam_pos[3];
850  float cam_U[3];
851  float cam_V[3];
852  float cam_W[3];
853  float cam_zoom;
854 
855  int cam_dof_enabled;
856  float cam_dof_focal_dist;
857  float cam_dof_fnumber;
858 
859  int cam_stereo_enabled;
860  float cam_stereo_eyesep;
861  float cam_stereo_convergence_dist;
862 
863  CameraType camera_type;
864 
865  // background color and/or gradient parameters
866  BGMode scene_background_mode;
867  float scene_bg_color[3];
868  float scene_bg_grad_top[3];
869  float scene_bg_grad_bot[3];
870  float scene_bg_grad_updir[3];
871  float scene_bg_grad_topval;
872  float scene_bg_grad_botval;
873  float scene_bg_grad_invrange;
874 
875  // clipping plane/sphere parameters
876  int clip_mode;
877  float clip_start;
878  float clip_end;
879 
880  // fog / depth cueing parameters
881  int fog_mode;
882  float fog_start;
883  float fog_end;
884  float fog_density;
885 
886  std::vector<rt_texture> texturecache;
887  std::vector<rt_material> materialcache;
888 
889  int regen_optix_materials;
890  CUMemBuf materialsBuffer;
891 
892  std::vector<rt_directional_light> directional_lights;
893  std::vector<rt_positional_light> positional_lights;
894  int regen_optix_lights;
895  CUMemBuf directionalLightsBuffer;
896  CUMemBuf positionalLightsBuffer;
897 
898 
899  //
900  // Scene and geometric primitive counters
901  //
902 
903  // state variables to hold scene geometry
904  int scene_created;
905 
906  // cylinder array primitive
907  long cylinder_array_cnt;
908 
909  // color-per-cylinder array primitive
910  long cylinder_array_color_cnt;
911 
912 
913  // color-per-ring array primitive
914  long ring_array_color_cnt;
915 
916 
917  // sphere array primitive
918  long sphere_array_cnt;
919 
920  // color-per-sphere array primitive
921  long sphere_array_color_cnt;
922 
923 
924  // triangle mesh primitives of various types
925  long tricolor_cnt;
926  long trimesh_c4u_n3b_v3f_cnt;
927  long trimesh_n3b_v3f_cnt;
928  long trimesh_n3f_v3f_cnt;
929  long trimesh_v3f_cnt;
930 
931 
932  //
933  // Internal methods
934  //
935 
937  void create_context(void);
938  void destroy_context(void);
939 
940  void check_verbose_env();
941  void render_compile_and_validate(void);
942 
944  char *internal_compiled_ptx_src(void);
945  int read_ptx_src(const char *ptxfilename, char **ptxstring);
946 
947  void context_create_denoiser(void);
948  void context_destroy_denoiser(void);
949  void denoiser_resize_update(void);
950  void denoiser_launch(void);
951 
952  void context_create_exception_pgms(void);
953  void context_destroy_exception_pgms(void);
954 
955  void context_create_raygen_pgms(void);
956  void context_destroy_raygen_pgms(void);
957 
958  void context_create_miss_pgms(void);
959  void context_destroy_miss_pgms(void);
960 
961  void context_create_curve_hitgroup_pgms(void);
962  void context_destroy_curve_hitgroup_pgms(void);
963 
964  void context_create_hwtri_hitgroup_pgms(void);
965  void context_destroy_hwtri_hitgroup_pgms(void);
966 
967  void context_create_intersection_pgms(void);
968  void context_destroy_intersection_pgms(void);
969 
970  void context_create_module(void);
971  void context_destroy_module(void);
972 
973  int regen_optix_pipeline;
974  void context_create_pipeline(void);
975  void context_destroy_pipeline(void);
976 
978  int regen_optix_sbt;
979  void SBT_create_programs(void);
980  void SBT_create_hitgroups(void);
981  void SBT_clear(void);
982  void SBT_destroy(void);
983 
985  void SBT_update_hitgroup_geomflags(void);
986 
987 
988  //
989  // AABB calc helpers
990  //
991  void AABB_cone_array(CUMemBuf &aabbBuffer,
992  const float3 *base, const float3 *apex,
993  const float *brad, const float *arad, int primcnt);
994 
995  void AABB_cylinder_array(CUMemBuf &aabbBuffer,
996  const float3 *base, const float3 *apex,
997  const float *rads, int primcnt);
998 
999  void AABB_quadmesh(CUMemBuf &aabbBuffer, const float3 *verts,
1000  const int4 *indices, int primcnt);
1001 
1002  void AABB_ring_array(CUMemBuf &aabbBuffer,
1003  const float3 *pos, const float *rads, int primcnt);
1004 
1005  void AABB_sphere_array(CUMemBuf &aabbBuffer,
1006  const float3 *pos, const float *rads, int primcnt);
1007 
1008  //
1009  // AABB AS build input helper method
1010  //
1011  void AS_buildinp_AABB(OptixBuildInput &asInp,
1012  CUdeviceptr *aabbptr, uint32_t *flagsptr, int primcnt);
1013 
1014  //
1015  // Core AS builder methods
1016  //
1017  int build_GAS(std::vector<OptixBuildInput>,
1018  CUMemBuf &ASTmpBuf,
1019  CUMemBuf &GASbuffer,
1020  uint64_t *d_ASCompactedSize,
1021  OptixTraversableHandle &tvh,
1022  cudaStream_t GASstream);
1023 
1024  int build_IAS(std::vector<OptixBuildInput>,
1025  CUMemBuf &ASTmpBuf,
1026  CUMemBuf &IASbuffer,
1027  OptixTraversableHandle &tvh,
1028  cudaStream_t IASstream);
1029 
1033  OptixTraversableHandle build_custprims_GAS(void);
1034  OptixTraversableHandle build_curves_GAS(void);
1035  OptixTraversableHandle build_trimeshes_GAS(void);
1036 
1037  //
1038  // Instance AS builder methods
1039  //
1040  void build_scene_IAS(void);
1041  void free_scene_IAS(void);
1042 
1043 public:
1044  TachyonOptiX();
1045  ~TachyonOptiX(void);
1046 
1049  static int device_list(int **, char ***);
1050  static int device_count(void);
1051  static unsigned int optix_version(void);
1052 
1054  void log_callback(unsigned int level, const char *tag, const char *msg);
1055 
1056  void print_raystats_info(void);
1057  void print_internal_struct_info(void);
1058 
1060  void set_verbose_mode(TachyonOptiX::Verbosity mode) { verbose = mode; }
1061 
1064  void minimize_memory_use(void);
1065 
1066 
1067  //
1068  // Camera parameters
1069  //
1070 
1073  if (camera_type != m) {
1074  camera_type = m;
1075  regen_optix_pipeline=1; // this requires changing the raygen program
1076  }
1077  }
1078 
1080  void set_camera_pos(const float *pos) {
1081  memcpy(cam_pos, pos, sizeof(cam_pos));
1082  }
1083 
1085  void set_camera_ONB(const float *U, const float *V, const float *W) {
1086  memcpy(cam_U, U, sizeof(cam_U));
1087  memcpy(cam_V, V, sizeof(cam_V));
1088  memcpy(cam_W, W, sizeof(cam_W));
1089  }
1090 
1094  void set_camera_lookat(const float *at, const float *V);
1095 
1097  void set_camera_zoom(float zoomfactor) { cam_zoom = zoomfactor; }
1098 
1100  void camera_dof_enable(int onoff) {
1101  if (cam_dof_enabled != (onoff != 0)) {
1102  cam_dof_enabled = (onoff != 0);
1103  regen_optix_pipeline=1; // this requires changing the raygen program
1104  }
1105  }
1106 
1108  void set_camera_dof_focal_dist(float d) { cam_dof_focal_dist = d; }
1109 
1111  void set_camera_dof_fnumber(float n) { cam_dof_fnumber = n; }
1112 
1114  void camera_stereo_enable(int onoff) {
1115  if (cam_stereo_enabled != (onoff != 0)) {
1116  cam_stereo_enabled = (onoff != 0);
1117  regen_optix_pipeline=1; // this requires changing the raygen program
1118  }
1119  }
1120 
1122  void set_camera_stereo_eyesep(float eyesep) { cam_stereo_eyesep = eyesep; }
1123 
1126  cam_stereo_convergence_dist = dist;
1127  }
1128 
1129 
1131  void set_cue_mode(FogMode mode, float start, float end, float density) {
1132  fog_mode = mode;
1133  fog_start = start;
1134  fog_end = end;
1135  fog_density = density;
1136  }
1137 
1138 
1139  //
1140  // View clipping
1141  //
1142 
1144  void set_clip_sphere(ViewClipMode mode, float start, float end) {
1145  clip_mode = mode;
1146  clip_start = start;
1147  clip_end = end;
1148  }
1149 
1151  void set_clipview_mode(int mode) {
1152  clipview_mode = mode;
1153  };
1154 
1155 
1156  //
1157  // Scene background color, gradient, etc.
1158  //
1159 
1162  if (scene_background_mode != m) {
1163  scene_background_mode = m;
1164  regen_optix_pipeline=1; // this requires changing the miss program
1165  }
1166  }
1167 
1169  void set_bg_color(float *rgb) { memcpy(scene_bg_color, rgb, sizeof(scene_bg_color)); }
1170 
1172  void set_bg_color_grad_top(float *rgb) { memcpy(scene_bg_grad_top, rgb, sizeof(scene_bg_grad_top)); }
1173 
1175  void set_bg_color_grad_bot(float *rgb) { memcpy(scene_bg_grad_bot, rgb, sizeof(scene_bg_grad_bot)); }
1176 
1178  void set_bg_gradient(float *vec) { memcpy(scene_bg_grad_updir, vec, sizeof(scene_bg_grad_updir)); }
1179 
1181  void set_bg_gradient_topval(float v) { scene_bg_grad_topval = v; }
1182 
1184  void set_bg_gradient_botval(float v) { scene_bg_grad_botval = v; }
1185 
1186 
1187  //
1188  // Images, Materials, and Textures
1189  //
1190 
1192  int image_index_from_user_index(int userindex);
1193 
1195  int add_tex2d_rgba4u(const unsigned char *img, int xres, int yres,
1196  int texflags, int userindex);
1197 
1199  int add_tex3d_rgba4u(const unsigned char *img, int xres, int yres, int zres,
1200  int texflags, int userindex);
1201 
1203  int material_index_from_user_index(int userindex);
1204 
1206  int add_material(float ambient, float diffuse,
1207  float specular, float shininess, float reflectivity,
1208  float opacity, float outline, float outlinewidth,
1209  int transmode, int userindex);
1210 
1211  int add_material_textured(float ambient, float diffuse,
1212  float specular, float shininess, float reflectivity,
1213  float opacity, float outline, float outlinewidth,
1214  int transmode, int textureindex, int userindex);
1215 
1216  void destroy_materials();
1217 
1218 
1219  //
1220  // Lighting modes, light definitions
1221  //
1222 
1224  void shadows_enable(int onoff) { shadows_enabled = (onoff != 0); }
1225 
1227  void denoiser_enable(int onoff) { denoiser_enabled = (onoff != 0); }
1228 
1230  void set_ao_samples(int cnt) { ao_samples = cnt; }
1231 
1233  void set_ao_ambient(float aoa) { ao_ambient = aoa; }
1234 
1236  void set_ao_direct(float aod) { ao_direct = aod; }
1237 
1239  void set_ao_maxdist(float dist) { ao_maxdist = dist; }
1240 
1241 
1242  void set_headlight_enable(int onoff) {
1243  headlight_mode = (onoff==1) ? RT_HEADLIGHT_ON : RT_HEADLIGHT_OFF;
1244  };
1245 
1246  void add_directional_light(const float *dir, const float *color);
1247  void add_positional_light(const float *pos, const float *color);
1248  void destroy_lights() {
1249  directional_lights.clear();
1250  positional_lights.clear();
1251  regen_optix_lights=1;
1252  }
1253 
1254 
1255  //
1256  // Framebuffer configuration
1257  //
1258 
1259  void framebuffer_config(int fbwidth, int fbheight, int interactive);
1260 
1261  void framebuffer_colorspace(int colspace);
1262  void framebuffer_resize(int fbwidth, int fbheight);
1263  void framebuffer_get_size(int &fbwidth, int &fbheight) {
1264  fbwidth=width;
1265  fbheight=height;
1266  }
1267  void framebuffer_clear(void);
1268  void framebuffer_download_rgb4u(unsigned char *imgrgb4u);
1269  void framebuffer_destroy(void);
1270 
1271 
1272  //
1273  // Scene management
1274  //
1275 
1276  void destroy_scene(void);
1277 
1278 
1279  //
1280  // Renderer controls
1281  //
1282 
1284  void set_aa_samples(int cnt) { aa_samples = (cnt < 0) ? 1 : cnt; }
1285 
1286  void update_rendering_state(int interactive);
1287 
1288  void render();
1289 
1290 
1291  //
1292  // Geometric primitive APIs
1293  //
1294 
1297  int finalize_geom_instance_group(int idx);
1298  int destroy_geom_instance_group(int idx);
1299 // int set_geom_instance_group_xforms(int idx, int n, float [][16]);
1300 
1301 
1302  //
1303  // XXX short-term host API hacks to facilitate early bring-up and testing
1304  //
1305  void add_conearray(ConeArray & model, int matidx);
1306  void add_curvearray(CurveArray & model, int matidx);
1307  void add_cylarray(CylinderArray & model, int matidx);
1308  void add_ringarray(RingArray & model, int matidx);
1309  void add_quadmesh(QuadMesh & model, int matidx);
1310  void add_spherearray(SphereArray & model, int matidx);
1311  void add_trimesh(TriangleMesh & model, int matidx);
1312 
1313 };
1314 
1315 
1316 
1317 #endif
1318 
size_t sz
device memory buffer usage size in bytes
Definition: TachyonOptiX.h:329
Several OptiX APIs make use of CUDA driver API pointer types (CUdevicepointer) so it becomes worthwhi...
Definition: TachyonOptiX.h:328
void minimize_memory_use(void)
reduce active memory footprint without destroying the scene by freeing internal temporary buffers use...
std::vector< float3 PINALLOCS(float3)> center
Definition: TachyonOptiX.h:226
void set_ao_maxdist(float dist)
set AO maximum occlusion distance
std::vector< float3 PINALLOCS(float3)> primcolors3f
Definition: TachyonOptiX.h:263
void set_clip_sphere(ViewClipMode mode, float start, float end)
set camera clipping plane/sphere mode and parameters
omnidirectional octahedral
Definition: TachyonOptiX.h:643
std::vector< uint4 PINALLOCS(uint4) > packednormals
Definition: TachyonOptiX.h:289
VR headlight at cam center.
Definition: TachyonOptiX.h:626
std::vector< float3 PINALLOCS(float3)> center
Definition: TachyonOptiX.h:245
void set_bg_gradient_topval(float v)
set background gradient "top" value (view direction dot product)
std::vector< float3 PINALLOCS(float3)> vertcolors3f
Definition: TachyonOptiX.h:217
int materialindex
Definition: TachyonOptiX.h:184
void free()
free allocated memory
Definition: TachyonOptiX.h:433
int add_tex3d_rgba4u(const unsigned char *img, int xres, int yres, int zres, int texflags, int userindex)
define image to be used in a texture map
int create_geom_instance_group()
Create geometry instance group.
std::vector< float PINALLOCS(float)> radius
Definition: TachyonOptiX.h:199
float3 uniform_color
Definition: TachyonOptiX.h:231
void set_ao_samples(int cnt)
ambient occlusion (samples > 1 == on)
planetarium dome master
Definition: TachyonOptiX.h:641
int add_tex2d_rgba4u(const unsigned char *img, int xres, int yres, int texflags, int userindex)
define image to be used in a texture map
void addRing(const float3 &ricenter, const float3 &rinorm, const float riinrad, const float rioutrad)
Definition: TachyonOptiX.h:234
std::vector< float * > transforms
Definition: TachyonOptiX.h:612
std::vector< CurveArray > curvearrays
Definition: TachyonOptiX.h:598
int add_material_textured(float ambient, float diffuse, float specular, float shininess, float reflectivity, float opacity, float outline, float outlinewidth, int transmode, int textureindex, int userindex)
std::vector< int PINALLOCS(int)> segindices
Definition: TachyonOptiX.h:261
void resize_upload(const T *t, size_t cnt, cudaStream_t stream)
Combination of a buffer resize with asynchronous upload to GPU device memory using the caller-provide...
Definition: TachyonOptiX.h:502
std::vector< float3 PINALLOCS(float3)> apex
Definition: TachyonOptiX.h:179
void print_internal_struct_info(void)
diagnostic info routines
size_t get_size(void)
query current buffer size in bytes
Definition: TachyonOptiX.h:350
__host__ __device__ float3 make_float3(const float s)
void framebuffer_get_size(int &fbwidth, int &fbheight)
void add_directional_light(const float *dir, const float *color)
void addCone(const float3 &cbase, const float3 &capex, const float cbaserad, const float capexrad)
Definition: TachyonOptiX.h:186
std::vector< float3 PINALLOCS(float3)> base
Definition: TachyonOptiX.h:178
std::vector< float3 PINALLOCS(float3)> primcolors3f
Definition: TachyonOptiX.h:200
omnidirectional lat/long
Definition: TachyonOptiX.h:642
void download_async(T *t, size_t cnt, cudaStream_t stream)
Asynchronous download from GPU device memory, using the caller-provided CUDA stream to enforce orderi...
Definition: TachyonOptiX.h:583
Tachyon ray tracing engine core routines and data structures compiled to PTX for runtime JIT to build...
std::vector< HGRecordGroup > sbtHGRecGroups
all GeomSBTHG recs
Definition: TachyonOptiX.h:605
std::vector< SphereArray > sparrays
Definition: TachyonOptiX.h:601
std::vector< float3 PINALLOCS(float3) > tex3d
Definition: TachyonOptiX.h:294
void set_camera_ONB(const float *U, const float *V, const float *W)
set the camera ONB vector orientation frame
float3 uniform_color
Definition: TachyonOptiX.h:183
int add_material(float ambient, float diffuse, float specular, float shininess, float reflectivity, float opacity, float outline, float outlinewidth, int transmode, int userindex)
add a material with an associated user-provided index
Tachyon OptiX global launch parameter structure containing the active camera, framebuffer, materials, and any global scene parameters required for shading.
std::vector< float PINALLOCS(float)> apexrad
Definition: TachyonOptiX.h:181
void add_curvearray(CurveArray &model, int matidx)
void addCurve(const float *verts, const int numverts, const float *rads, const int numradii, const int *sidxs, const int numindices)
Definition: TachyonOptiX.h:267
std::vector< float PINALLOCS(float)> radius
Definition: TachyonOptiX.h:246
void framebuffer_resize(int fbwidth, int fbheight)
std::vector< float3 PINALLOCS(float3) > normals
Definition: TachyonOptiX.h:288
std::vector< RingArray > riarrays
Definition: TachyonOptiX.h:600
std::vector< float3 PINALLOCS(float3)> primcolors3f
Definition: TachyonOptiX.h:182
void camera_dof_enable(int onoff)
depth of field on/off
int materialindex
Definition: TachyonOptiX.h:232
static int device_count(void)
static GPU device query
void set_camera_lookat(const float *at, const float *V)
set camera orientation to look "at" a point in space, with a given "up" direction (camera ONB "V" vec...
void destroy_scene(void)
cam/frustum clipping sphere
Definition: TachyonOptiX.h:621
void destroy_materials()
CUdeviceptr cu_dptr() const
Definition: TachyonOptiX.h:341
int destroy_geom_instance_group(int idx)
void print_raystats_info(void)
report performance statistics
void free(cudaStream_t stream)
free allocated memory asynchronously
Definition: TachyonOptiX.h:442
std::vector< float3 PINALLOCS(float3) > vertices
Definition: TachyonOptiX.h:286
void framebuffer_destroy(void)
static int device_list(int **, char ***)
static methods for querying OptiX-supported GPU hardware independent of whether we actually have an a...
std::vector< float3 PINALLOCS(float3)> start
Definition: TachyonOptiX.h:197
void addCube(const float3 &center, const float3 &s)
Definition: TachyonOptiX.h:298
Output timing/perf data only.
Definition: TachyonOptiX.h:649
CUMemBuf custprimsGASBuffer
final, compacted GAS
Definition: TachyonOptiX.h:606
void set_ao_direct(float aod)
set AO direct lighting rescale factor
conventional orthographic
Definition: TachyonOptiX.h:639
void framebuffer_clear(void)
void set_bg_gradient(float *vec)
set world "up" direction for background gradient
cam/frustum front clipping plane
Definition: TachyonOptiX.h:620
void add_spherearray(SphereArray &model, int matidx)
void update_rendering_state(int interactive)
void set_size(size_t newsize, cudaStream_t stream)
(re)allocate buffer of requested size, asynchronously
Definition: TachyonOptiX.h:372
void add_ringarray(RingArray &model, int matidx)
conventional perspective
Definition: TachyonOptiX.h:638
No console output.
Definition: TachyonOptiX.h:648
void resize_upload(const T *t, size_t cnt)
Combination of a buffer resize with synchronous upload to GPU device memory.
Definition: TachyonOptiX.h:479
std::vector< float PINALLOCS(float)> inrad
Definition: TachyonOptiX.h:228
void resize_upload(const std::vector< T > &vecT, cudaStream_t stream)
Combination of a buffer resize with asynchronous upload to GPU device memory using the caller-provide...
Definition: TachyonOptiX.h:493
no frustum clipping
Definition: TachyonOptiX.h:619
std::vector< float3 PINALLOCS(float3) > vertcolors3f
Definition: TachyonOptiX.h:290
void add_conearray(ConeArray &model, int matidx)
std::vector< float3 PINALLOCS(float3)> primcolors3f
Definition: TachyonOptiX.h:230
void set_camera_zoom(float zoomfactor)
set camera zoom factor
void log_callback(unsigned int level, const char *tag, const char *msg)
console output logging callback
std::vector< float3 PINALLOCS(float3)> primcolors3f
Definition: TachyonOptiX.h:219
void set_size(size_t newsize)
(re)allocate buffer of requested size
Definition: TachyonOptiX.h:355
Tachyon cross-platform timers, special math function wrappers, and RNGs.
std::vector< ConeArray > conearrays
Definition: TachyonOptiX.h:597
std::vector< float2 PINALLOCS(float2) > tex2d
Definition: TachyonOptiX.h:293
void set_camera_dof_fnumber(float n)
set depth of field f/stop number
Exp^2 fog w/ Z-depth.
Definition: TachyonOptiX.h:633
std::vector< float3 PINALLOCS(float3)> vertices
Definition: TachyonOptiX.h:213
void * dptr() const
Definition: TachyonOptiX.h:333
std::vector< float3 PINALLOCS(float3)> normal
Definition: TachyonOptiX.h:227
std::vector< int4 PINALLOCS(int4)> indices
Definition: TachyonOptiX.h:214
std::vector< uchar4 PINALLOCS(uchar4)> vertcolors4u
Definition: TachyonOptiX.h:218
size_t dmemsz
device memory buffer allocated size in bytes
Definition: TachyonOptiX.h:330
void set_bg_color_grad_bot(float *rgb)
set color for "bottom" of background gradient
void set_camera_type(CameraType m)
set the camera projection mode
Linear fog w/ Z-depth.
Definition: TachyonOptiX.h:631
void framebuffer_download_rgb4u(unsigned char *imgrgb4u)
std::vector< float3 PINALLOCS(float3) > primcolors3f
Definition: TachyonOptiX.h:292
std::vector< float3 PINALLOCS(float3)> normals
Definition: TachyonOptiX.h:215
void set_camera_stereo_convergence_dist(float dist)
set stereo convergence distance
float3 uniform_color
Definition: TachyonOptiX.h:264
void shadows_enable(int onoff)
enable/disable shadows
void set_bg_color(float *rgb)
set solid background color
void denoiser_enable(int onoff)
enable/disable denoiser
int finalize_geom_instance_group(int idx)
void camera_stereo_enable(int onoff)
depth of field on/off
void addCylinder(const float3 &cstart, const float3 &cend, const float crad)
Definition: TachyonOptiX.h:204
void set_ao_ambient(float aoa)
set AO ambient lighting factor
void set_aa_samples(int cnt)
antialiasing (samples > 1 == on)
void addSphere(const float3 &spcenter, const float &spradius)
Definition: TachyonOptiX.h:251
void download(T *t, size_t cnt)
Synchronous download from GPU device memory.
Definition: TachyonOptiX.h:560
void framebuffer_config(int fbwidth, int fbheight, int interactive)
int materialindex
Definition: TachyonOptiX.h:265
std::vector< float3 PINALLOCS(float3)> vertices
Definition: TachyonOptiX.h:259
CUMemBuf trimeshesGASBuffer
final, compacted GAS
Definition: TachyonOptiX.h:610
void set_cue_mode(FogMode mode, float start, float end, float density)
set depth cueing mode and parameters
void set_bg_gradient_botval(float v)
set background gradient "bottom" value (view direction dot product)
void set_verbose_mode(TachyonOptiX::Verbosity mode)
programmatically set verbosity
std::vector< uint4 PINALLOCS(uint4)> packednormals
Definition: TachyonOptiX.h:216
void set_bg_color_grad_top(float *rgb)
set color for "top" of background gradient
void upload(const T *t, size_t cnt)
Synchronous upload to GPU device memory.
Definition: TachyonOptiX.h:554
void add_positional_light(const float *pos, const float *color)
Exp fog w/ Z-depth.
Definition: TachyonOptiX.h:632
std::vector< float PINALLOCS(float)> outrad
Definition: TachyonOptiX.h:229
void set_camera_pos(const float *pos)
set the camera position
float3 uniform_color
Definition: TachyonOptiX.h:295
static unsigned int optix_version(void)
static OptiX version query
float3 uniform_color
Definition: TachyonOptiX.h:248
std::vector< int3 PINALLOCS(int3) > indices
Definition: TachyonOptiX.h:287
void destroy_lights()
void upload(const T *t, size_t cnt, cudaStream_t stream)
Asynchronous upload to GPU device memory, using the caller-provided CUDA stream to enforce ordering r...
Definition: TachyonOptiX.h:572
std::vector< float PINALLOCS(float)> vertradii
Definition: TachyonOptiX.h:260
void set_camera_stereo_eyesep(float eyesep)
set stereo eye separation
Output fully verbose debug info.
Definition: TachyonOptiX.h:650
void clear_persist_allocation(void)
clear "used" size to zero, but keep existing device allocation
Definition: TachyonOptiX.h:424
float3 uniform_color
Definition: TachyonOptiX.h:201
std::vector< float PINALLOCS(float)> baserad
Definition: TachyonOptiX.h:180
int materialindex
Definition: TachyonOptiX.h:221
void * d_ptr
pointer to device memory buffer
Definition: TachyonOptiX.h:331
void framebuffer_colorspace(int colspace)
float3 uniform_color
Definition: TachyonOptiX.h:220
void set_clipview_mode(int mode)
VR view clipping.
std::vector< TriangleMesh > trimeshes
Definition: TachyonOptiX.h:602
int material_index_from_user_index(int userindex)
locate material via user index
void add_cylarray(CylinderArray &model, int matidx)
void set_headlight_enable(int onoff)
std::vector< CylinderArray > cyarrays
Definition: TachyonOptiX.h:599
~TachyonOptiX(void)
void set_bg_mode(BGMode m)
set background rendering mode
void set_camera_dof_focal_dist(float d)
set depth of field focal plane distance
omnidirectional cubemap
Definition: TachyonOptiX.h:640
std::vector< float3 PINALLOCS(float3)> primcolors3f
Definition: TachyonOptiX.h:247
void add_trimesh(TriangleMesh &model, int matidx)
std::vector< float3 PINALLOCS(float3)> end
Definition: TachyonOptiX.h:198
void add_quadmesh(QuadMesh &model, int matidx)
std::vector< uchar4 PINALLOCS(uchar4) > vertcolors4u
Definition: TachyonOptiX.h:291
Definition: util.c:161
void resize_upload(const std::vector< T > &vecT)
Combination of a buffer resize with synchronous upload to GPU device memory.
Definition: TachyonOptiX.h:471
int image_index_from_user_index(int userindex)
locate texture via user index