Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/device_optix.cpp
| Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | # endif | ||||
| // Need CUDA kernel module for some utility functions | // Need CUDA kernel module for some utility functions | ||||
| CUmodule cuda_module = NULL; | CUmodule cuda_module = NULL; | ||||
| CUmodule cuda_filter_module = NULL; | CUmodule cuda_filter_module = NULL; | ||||
| // All necessary OptiX kernels are in one module | // All necessary OptiX kernels are in one module | ||||
| OptixModule optix_module = NULL; | OptixModule optix_module = NULL; | ||||
| OptixPipeline pipelines[NUM_PIPELINES] = {}; | OptixPipeline pipelines[NUM_PIPELINES] = {}; | ||||
| bool motion_blur = false; | |||||
| bool need_texture_info = false; | bool need_texture_info = false; | ||||
| device_vector<SbtRecord> sbt_data; | device_vector<SbtRecord> sbt_data; | ||||
| device_vector<TextureInfo> texture_info; | device_vector<TextureInfo> texture_info; | ||||
| device_only_memory<KernelParams> launch_params; | device_only_memory<KernelParams> launch_params; | ||||
| vector<device_only_memory<uint8_t>> blas; | vector<device_only_memory<uint8_t>> blas; | ||||
| OptixTraversableHandle tlas_handle = 0; | OptixTraversableHandle tlas_handle = 0; | ||||
| map<device_memory *, CUDAMem> cuda_mem_map; | map<device_memory *, CUDAMem> cuda_mem_map; | ||||
| ▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | |||||
| # ifdef WITH_CYCLES_DEBUG | # ifdef WITH_CYCLES_DEBUG | ||||
| pipeline_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW | | pipeline_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW | | ||||
| OPTIX_EXCEPTION_FLAG_TRACE_DEPTH; | OPTIX_EXCEPTION_FLAG_TRACE_DEPTH; | ||||
| # else | # else | ||||
| pipeline_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE; | pipeline_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE; | ||||
| # endif | # endif | ||||
| pipeline_options.pipelineLaunchParamsVariableName = "__params"; // See kernel_globals.h | pipeline_options.pipelineLaunchParamsVariableName = "__params"; // See kernel_globals.h | ||||
| if (requested_features.use_object_motion) { | // Keep track of whether motion blur is enabled, so to enable/disable motion in BVH builds | ||||
| // This is necessary since objects may be reported to have motion if the Vector pass is | |||||
| // active, but may still need to be rendered without motion blur if that isn't active as well | |||||
| motion_blur = requested_features.use_object_motion; | |||||
| if (motion_blur) { | |||||
| pipeline_options.usesMotionBlur = true; | pipeline_options.usesMotionBlur = true; | ||||
| // Motion blur can insert motion transforms into the traversal graph | // Motion blur can insert motion transforms into the traversal graph | ||||
| // It is no longer a two-level graph then, so need to set flags to allow any configuration | // It is no longer a two-level graph then, so need to set flags to allow any configuration | ||||
| pipeline_options.traversableGraphFlags = OPTIX_TRAVERSABLE_GRAPH_FLAG_ALLOW_ANY; | pipeline_options.traversableGraphFlags = OPTIX_TRAVERSABLE_GRAPH_FLAG_ALLOW_ANY; | ||||
| } | } | ||||
| { // Load and compile PTX module with OptiX kernels | { // Load and compile PTX module with OptiX kernels | ||||
| string ptx_data; | string ptx_data; | ||||
| ▲ Show 20 Lines • Show All 518 Lines • ▼ Show 20 Lines | for (Object *ob : bvh->objects) { | ||||
| // Build BLAS for curve primitives | // Build BLAS for curve primitives | ||||
| if (bvh->params.primitive_mask & PRIMITIVE_ALL_CURVE && mesh->num_curves() > 0) { | if (bvh->params.primitive_mask & PRIMITIVE_ALL_CURVE && mesh->num_curves() > 0) { | ||||
| const size_t num_curves = mesh->num_curves(); | const size_t num_curves = mesh->num_curves(); | ||||
| const size_t num_segments = mesh->num_segments(); | const size_t num_segments = mesh->num_segments(); | ||||
| size_t num_motion_steps = 1; | size_t num_motion_steps = 1; | ||||
| Attribute *motion_keys = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | Attribute *motion_keys = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | ||||
| if (mesh->use_motion_blur && motion_keys) { | if (motion_blur && mesh->use_motion_blur && motion_keys) { | ||||
| num_motion_steps = mesh->motion_steps; | num_motion_steps = mesh->motion_steps; | ||||
| } | } | ||||
| device_vector<OptixAabb> aabb_data(this, "temp_aabb_data", MEM_READ_ONLY); | device_vector<OptixAabb> aabb_data(this, "temp_aabb_data", MEM_READ_ONLY); | ||||
| aabb_data.alloc(num_segments * num_motion_steps); | aabb_data.alloc(num_segments * num_motion_steps); | ||||
| // Get AABBs for each motion step | // Get AABBs for each motion step | ||||
| for (size_t step = 0; step < num_motion_steps; ++step) { | for (size_t step = 0; step < num_motion_steps; ++step) { | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | for (Object *ob : bvh->objects) { | ||||
| } | } | ||||
| // Build BLAS for triangle primitives | // Build BLAS for triangle primitives | ||||
| if (bvh->params.primitive_mask & PRIMITIVE_ALL_TRIANGLE && mesh->num_triangles() > 0) { | if (bvh->params.primitive_mask & PRIMITIVE_ALL_TRIANGLE && mesh->num_triangles() > 0) { | ||||
| const size_t num_verts = mesh->verts.size(); | const size_t num_verts = mesh->verts.size(); | ||||
| size_t num_motion_steps = 1; | size_t num_motion_steps = 1; | ||||
| Attribute *motion_keys = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | Attribute *motion_keys = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | ||||
| if (mesh->use_motion_blur && motion_keys) { | if (motion_blur && mesh->use_motion_blur && motion_keys) { | ||||
| num_motion_steps = mesh->motion_steps; | num_motion_steps = mesh->motion_steps; | ||||
| } | } | ||||
| device_vector<int> index_data(this, "temp_index_data", MEM_READ_ONLY); | device_vector<int> index_data(this, "temp_index_data", MEM_READ_ONLY); | ||||
| index_data.alloc(mesh->triangles.size()); | index_data.alloc(mesh->triangles.size()); | ||||
| memcpy(index_data.data(), mesh->triangles.data(), mesh->triangles.size() * sizeof(int)); | memcpy(index_data.data(), mesh->triangles.data(), mesh->triangles.size() * sizeof(int)); | ||||
| device_vector<float3> vertex_data(this, "temp_vertex_data", MEM_READ_ONLY); | device_vector<float3> vertex_data(this, "temp_vertex_data", MEM_READ_ONLY); | ||||
| vertex_data.alloc(num_verts * num_motion_steps); | vertex_data.alloc(num_verts * num_motion_steps); | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | for (Object *ob : bvh->objects) { | ||||
| // Set user instance ID to object index | // Set user instance ID to object index | ||||
| instance.instanceId = ob->get_device_index(); | instance.instanceId = ob->get_device_index(); | ||||
| // Volumes have a special bit set in the visibility mask so a trace can mask only volumes | // Volumes have a special bit set in the visibility mask so a trace can mask only volumes | ||||
| // See 'scene_intersect_volume' in bvh.h | // See 'scene_intersect_volume' in bvh.h | ||||
| instance.visibilityMask = (ob->mesh->has_volume ? 3 : 1); | instance.visibilityMask = (ob->mesh->has_volume ? 3 : 1); | ||||
| // Insert motion traversable if object has motion | // Insert motion traversable if object has motion | ||||
| if (ob->use_motion()) { | if (motion_blur && ob->use_motion()) { | ||||
| blas.emplace_back(this, "motion_transform"); | blas.emplace_back(this, "motion_transform"); | ||||
| device_only_memory<uint8_t> &motion_transform_gpu = blas.back(); | device_only_memory<uint8_t> &motion_transform_gpu = blas.back(); | ||||
| motion_transform_gpu.alloc_to_device(sizeof(OptixSRTMotionTransform) + | motion_transform_gpu.alloc_to_device(sizeof(OptixSRTMotionTransform) + | ||||
| (max(ob->motion.size(), 2) - 2) * | (max(ob->motion.size(), 2) - 2) * | ||||
| sizeof(OptixSRTData)); | sizeof(OptixSRTData)); | ||||
| // 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 *>( | ||||
| ▲ Show 20 Lines • Show All 918 Lines • Show Last 20 Lines | |||||