17 SLOptixAccelStruct::SLOptixAccelStruct()
19 _accelBuildOptions.buildFlags = OPTIX_BUILD_FLAG_ALLOW_UPDATE |
20 OPTIX_BUILD_FLAG_ALLOW_RANDOM_VERTEX_ACCESS |
21 OPTIX_BUILD_FLAG_PREFER_FAST_TRACE;
22 _buffer =
new SLOptixCudaBuffer<void>();
25 SLOptixAccelStruct::~SLOptixAccelStruct()
30 void SLOptixAccelStruct::buildAccelerationStructure()
32 OptixDeviceContext context = SLOptix::context;
34 _accelBuildOptions.operation = OPTIX_BUILD_OPERATION_BUILD;
36 OPTIX_CHECK(optixAccelComputeMemoryUsage(
43 SLOptixCudaBuffer<void> temp_buffer = SLOptixCudaBuffer<void>();
44 temp_buffer.alloc(_accelBufferSizes.tempSizeInBytes);
47 _buffer =
new SLOptixCudaBuffer<void>();
48 _buffer->alloc(_accelBufferSizes.outputSizeInBytes);
50 SLOptixCudaBuffer<OptixAabb> aabbBuffer = SLOptixCudaBuffer<OptixAabb>();
51 aabbBuffer.alloc(
sizeof(OptixAabb));
52 SLOptixCudaBuffer<size_t> compactedSize = SLOptixCudaBuffer<size_t>();
53 compactedSize.alloc(
sizeof(
size_t));
55 OptixAccelEmitDesc emitProperty[1];
56 emitProperty[0].type = OPTIX_PROPERTY_TYPE_AABBS;
57 emitProperty[0].result = aabbBuffer.devicePointer();
59 OPTIX_CHECK(optixAccelBuild(
65 temp_buffer.devicePointer(),
66 _accelBufferSizes.tempSizeInBytes,
67 _buffer->devicePointer(),
68 _accelBufferSizes.outputSizeInBytes,
73 CUDA_SYNC_CHECK(SLOptix::stream);
76 aabbBuffer.download(&aabb);
79 void SLOptixAccelStruct::updateAccelerationStructure()
81 OptixDeviceContext context = SLOptix::context;
83 _accelBuildOptions.operation = OPTIX_BUILD_OPERATION_UPDATE;
85 SLOptixCudaBuffer<void> temp_buffer = SLOptixCudaBuffer<void>();
86 temp_buffer.alloc(_accelBufferSizes.tempUpdateSizeInBytes);
88 OPTIX_CHECK(optixAccelBuild(
94 temp_buffer.devicePointer(),
95 _accelBufferSizes.tempUpdateSizeInBytes,
96 _buffer->devicePointer(),
97 _accelBufferSizes.outputSizeInBytes,