Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/optix/device_impl.cpp
| Show First 20 Lines • Show All 1,026 Lines • ▼ Show 20 Lines | bool OptiXDevice::build_optix_bvh(BVHOptiX *bvh, | ||||
| /* Allocate required output buffers. */ | /* Allocate required output buffers. */ | ||||
| device_only_memory<char> temp_mem(this, "optix temp as build mem"); | device_only_memory<char> temp_mem(this, "optix temp as build mem"); | ||||
| temp_mem.alloc_to_device(align_up(sizes.tempSizeInBytes, 8) + 8); | temp_mem.alloc_to_device(align_up(sizes.tempSizeInBytes, 8) + 8); | ||||
| if (!temp_mem.device_pointer) { | if (!temp_mem.device_pointer) { | ||||
| /* Make sure temporary memory allocation succeeded. */ | /* Make sure temporary memory allocation succeeded. */ | ||||
| return false; | return false; | ||||
| } | } | ||||
| device_only_memory<char> &out_data = bvh->as_data; | device_only_memory<char> &out_data = *bvh->as_data; | ||||
| if (operation == OPTIX_BUILD_OPERATION_BUILD) { | if (operation == OPTIX_BUILD_OPERATION_BUILD) { | ||||
| assert(out_data.device == this); | assert(out_data.device == this); | ||||
| out_data.alloc_to_device(sizes.outputSizeInBytes); | out_data.alloc_to_device(sizes.outputSizeInBytes); | ||||
| if (!out_data.device_pointer) { | if (!out_data.device_pointer) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | if (!bvh->params.top_level) { | ||||
| /* Refit is only possible in viewport for now (because AS is built with | /* Refit is only possible in viewport for now (because AS is built with | ||||
| * OPTIX_BUILD_FLAG_ALLOW_UPDATE only there, see above). */ | * OPTIX_BUILD_FLAG_ALLOW_UPDATE only there, see above). */ | ||||
| OptixBuildOperation operation = OPTIX_BUILD_OPERATION_BUILD; | OptixBuildOperation operation = OPTIX_BUILD_OPERATION_BUILD; | ||||
| if (refit && !use_fast_trace_bvh) { | if (refit && !use_fast_trace_bvh) { | ||||
| assert(bvh_optix->traversable_handle != 0); | assert(bvh_optix->traversable_handle != 0); | ||||
| operation = OPTIX_BUILD_OPERATION_UPDATE; | operation = OPTIX_BUILD_OPERATION_UPDATE; | ||||
| } | } | ||||
| else { | else { | ||||
| bvh_optix->as_data.free(); | bvh_optix->as_data->free(); | ||||
| bvh_optix->traversable_handle = 0; | bvh_optix->traversable_handle = 0; | ||||
| } | } | ||||
| /* Build bottom level acceleration structures (BLAS). */ | /* Build bottom level acceleration structures (BLAS). */ | ||||
| Geometry *const geom = bvh->geometry[0]; | Geometry *const geom = bvh->geometry[0]; | ||||
| if (geom->geometry_type == Geometry::HAIR) { | if (geom->geometry_type == Geometry::HAIR) { | ||||
| /* Build BLAS for curve primitives. */ | /* Build BLAS for curve primitives. */ | ||||
| Hair *const hair = static_cast<Hair *const>(geom); | Hair *const hair = static_cast<Hair *const>(geom); | ||||
| ▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | else if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) { | ||||
| progress.set_error("Failed to build OptiX acceleration structure"); | progress.set_error("Failed to build OptiX acceleration structure"); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| unsigned int num_instances = 0; | unsigned int num_instances = 0; | ||||
| unsigned int max_num_instances = 0xFFFFFFFF; | unsigned int max_num_instances = 0xFFFFFFFF; | ||||
| bvh_optix->as_data.free(); | bvh_optix->as_data->free(); | ||||
| bvh_optix->traversable_handle = 0; | bvh_optix->traversable_handle = 0; | ||||
| bvh_optix->motion_transform_data.free(); | bvh_optix->motion_transform_data->free(); | ||||
| optixDeviceContextGetProperty(context, | optixDeviceContextGetProperty(context, | ||||
| OPTIX_DEVICE_PROPERTY_LIMIT_MAX_INSTANCE_ID, | OPTIX_DEVICE_PROPERTY_LIMIT_MAX_INSTANCE_ID, | ||||
| &max_num_instances, | &max_num_instances, | ||||
| sizeof(max_num_instances)); | sizeof(max_num_instances)); | ||||
| /* Do not count first bit, which is used to distinguish instanced and non-instanced objects. */ | /* Do not count first bit, which is used to distinguish instanced and non-instanced objects. */ | ||||
| max_num_instances >>= 1; | max_num_instances >>= 1; | ||||
| if (bvh->objects.size() > max_num_instances) { | if (bvh->objects.size() > max_num_instances) { | ||||
| Show All 16 Lines | if (motion_blur) { | ||||
| OPTIX_TRANSFORM_BYTE_ALIGNMENT); | OPTIX_TRANSFORM_BYTE_ALIGNMENT); | ||||
| const size_t motion_keys = max(ob->get_motion().size(), 2) - 2; | const size_t motion_keys = max(ob->get_motion().size(), 2) - 2; | ||||
| total_motion_transform_size = total_motion_transform_size + | total_motion_transform_size = total_motion_transform_size + | ||||
| sizeof(OptixSRTMotionTransform) + | sizeof(OptixSRTMotionTransform) + | ||||
| motion_keys * sizeof(OptixSRTData); | motion_keys * sizeof(OptixSRTData); | ||||
| } | } | ||||
| } | } | ||||
| assert(bvh_optix->motion_transform_data.device == this); | assert(bvh_optix->motion_transform_data->device == this); | ||||
| bvh_optix->motion_transform_data.alloc_to_device(total_motion_transform_size); | bvh_optix->motion_transform_data->alloc_to_device(total_motion_transform_size); | ||||
| } | } | ||||
| for (Object *ob : bvh->objects) { | for (Object *ob : bvh->objects) { | ||||
| /* Skip non-traceable objects. */ | /* Skip non-traceable objects. */ | ||||
| if (!ob->is_traceable()) { | if (!ob->is_traceable()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | for (Object *ob : bvh->objects) { | ||||
| size_t motion_keys = max(ob->get_motion().size(), 2) - 2; | size_t motion_keys = max(ob->get_motion().size(), 2) - 2; | ||||
| size_t motion_transform_size = sizeof(OptixSRTMotionTransform) + | size_t motion_transform_size = sizeof(OptixSRTMotionTransform) + | ||||
| motion_keys * sizeof(OptixSRTData); | motion_keys * sizeof(OptixSRTData); | ||||
| const CUDAContextScope scope(this); | const CUDAContextScope scope(this); | ||||
| motion_transform_offset = align_up(motion_transform_offset, | motion_transform_offset = align_up(motion_transform_offset, | ||||
| OPTIX_TRANSFORM_BYTE_ALIGNMENT); | OPTIX_TRANSFORM_BYTE_ALIGNMENT); | ||||
| CUdeviceptr motion_transform_gpu = bvh_optix->motion_transform_data.device_pointer + | CUdeviceptr motion_transform_gpu = bvh_optix->motion_transform_data->device_pointer + | ||||
| motion_transform_offset; | motion_transform_offset; | ||||
| motion_transform_offset += motion_transform_size; | motion_transform_offset += motion_transform_size; | ||||
| /* Allocate host side memory for motion transform and fill it with transform data. */ | /* Allocate host side memory for motion transform and fill it with transform data. */ | ||||
| OptixSRTMotionTransform &motion_transform = *reinterpret_cast<OptixSRTMotionTransform *>( | OptixSRTMotionTransform &motion_transform = *reinterpret_cast<OptixSRTMotionTransform *>( | ||||
| new uint8_t[motion_transform_size]); | new uint8_t[motion_transform_size]); | ||||
| motion_transform.child = handle; | motion_transform.child = handle; | ||||
| motion_transform.motionOptions.numKeys = ob->get_motion().size(); | motion_transform.motionOptions.numKeys = ob->get_motion().size(); | ||||
| ▲ Show 20 Lines • Show All 139 Lines • Show Last 20 Lines | |||||