1.3.72
 
Loading...
Searching...
No Matches
OptiX8LaunchParams.h
Go to the documentation of this file.
1
16#ifndef OPTIX8_LAUNCH_PARAMS_H
17#define OPTIX8_LAUNCH_PARAMS_H
18
19// This header is included by both host (.cpp) and device (.cu) code.
20// Only use types compatible with both CUDA and C++.
21#include <stdint.h>
22
23// CUDA vector types (float3, float2, int2, float4, ...) - available in both host and device contexts
24#include <vector_types.h>
25
26// OptiX traversable handle type (host and device)
27#include <optix.h>
28
29#ifndef M_PI
30#define M_PI 3.14159265358979323846f
31#endif
32
33typedef unsigned int uint;
34
35// ---------------------------------------------------------------------------
36// Per-ray payload. Passed by pointer-in-two-registers.
37// Allocated in a per-thread pool on the device.
38// ---------------------------------------------------------------------------
39struct PerRayData {
40 double strength;
42 bool face;
43 uint seed;
44 unsigned char source_ID;
45 bool hit_periodic_boundary;
46 float3 periodic_hit;
47};
48
49// ---------------------------------------------------------------------------
50// SBT hit-group record data (per primitive type).
51// ---------------------------------------------------------------------------
53 float3* vertices;
54 uint32_t* UUIDs;
55 uint32_t prim_type;
56};
57
58// ---------------------------------------------------------------------------
59// Main launch parameters structure.
60// Passed from host to device via optixLaunch(d_params, ...).
61// Accessible on device as: extern "C" __constant__ OptiX8LaunchParams params;
62// ---------------------------------------------------------------------------
64 // Traversal handle
65 OptixTraversableHandle traversable;
66
67 // ---- Per-ray-data pool (size = launch_dim_x * launch_dim_y) ----
68 PerRayData* prd_pool;
69
70 // ---- Geometry buffers (device pointers) ----
72 uint32_t* primitive_type;
74 uint32_t* primitiveID;
75 uint32_t* objectID;
77 int8_t* twosided_flag;
78 float* primitive_solid_fraction;
79
80 // ---- Global UUID lookup (indexed by global primitive position) ----
81 uint32_t* primitive_uuid;
82
83 // ---- Per-type geometry (also in SBT HitGroupData, mirrored here for easy access) ----
85 uint32_t* patch_UUIDs;
87 uint32_t* triangle_UUIDs;
88 float3* disk_centers;
89 float* disk_radii;
90 float3* disk_normals;
91 uint32_t* disk_UUIDs;
92 float3* tile_vertices;
93 uint32_t* tile_UUIDs;
95 uint32_t* voxel_UUIDs;
96 float3* bbox_vertices;
97 uint32_t* bbox_UUIDs;
98
99 // ---- Material buffers ----
100 float* rho;
101 float* tau;
102 float* rho_cam;
103 float* tau_cam;
104 float* specular_exponent;
105 float* specular_scale;
106
107 // ---- Radiation energy buffers ----
115 float* scatter_buff_bottom_cam;
117 float* Rsky;
118
119 // ---- Camera output buffers ----
120 uint32_t* camera_pixel_label;
121 float* camera_pixel_depth;
122
123 // ---- Source buffers ----
124 float3* source_positions;
125 float3* source_rotations;
126 float2* source_widths;
127 uint32_t* source_types;
130
131 // ---- Diffuse/sky buffers ----
139
140 // ---- Band launch flags ----
142
143 // ---- Texture/mask buffers ----
144 uint8_t* mask_data;
145 uint32_t* mask_offsets;
146 int32_t* mask_sizes;
147 int32_t* mask_IDs;
148 float2* uv_data;
149 int32_t* uv_IDs;
150
151 // ---- Scalar parameters ----
152 uint32_t Nprimitives;
153 uint32_t Nsources;
154 uint32_t Ncameras;
155 uint32_t Nbands_global;
156 uint32_t Nbands_launch;
157 uint32_t launch_offset;
158 uint32_t launch_count;
159 uint32_t rays_per_primitive;
160 uint32_t random_seed;
161 uint32_t launch_face;
162 uint32_t scattering_iteration;
163 uint32_t specular_reflection_enabled;
164 uint32_t camera_ID;
165 uint32_t bbox_UUID_base;
166
168 float3 sun_direction;
169 float solar_disk_cos_angle;
171 float3 camera_position;
172 float camera_lens_diameter;
173 float camera_focal_length;
174 float FOV_aspect_ratio;
175 float camera_HFOV;
176 int2 camera_resolution;
177 float camera_viewplane_length;
178 float camera_pixel_solid_angle;
179 int2 camera_pixel_offset;
180 int2 camera_resolution_full;
181
182 // ---- Launch grid ----
183 uint32_t launch_dim_x;
184 uint32_t launch_dim_y;
185};
186
187// ---------------------------------------------------------------------------
188// Helper: pack/unpack 64-bit pointer into two 32-bit OptiX payload registers
189// Device-only (requires OptiX device header)
190// ---------------------------------------------------------------------------
191#ifdef __CUDACC__
192static __forceinline__ __device__ void packPointer(void *ptr, uint32_t &u0, uint32_t &u1) {
193 const uint64_t uptr = reinterpret_cast<uint64_t>(ptr);
194 u0 = static_cast<uint32_t>(uptr >> 32);
195 u1 = static_cast<uint32_t>(uptr & 0xFFFFFFFFULL);
196}
197
198static __forceinline__ __device__ void *unpackPointer(uint32_t u0, uint32_t u1) {
199 const uint64_t uptr = (static_cast<uint64_t>(u0) << 32) | static_cast<uint64_t>(u1);
200 return reinterpret_cast<void *>(uptr);
201}
202
203static __forceinline__ __device__ PerRayData *getPayloadPRD() {
204 const uint32_t u0 = optixGetPayload_0();
205 const uint32_t u1 = optixGetPayload_1();
206 return reinterpret_cast<PerRayData *>(unpackPointer(u0, u1));
207}
208#endif // __CUDACC__
209
210#endif // OPTIX8_LAUNCH_PARAMS_H