Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/device_optix.cpp
| Show First 20 Lines • Show All 875 Lines • ▼ Show 20 Lines | for (Object *ob : bvh->objects) { | ||||
| 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) { | ||||
| // The center step for motion vertices is not stored in the attribute | |||||
| const float3 *keys = mesh->curve_keys.data(); | const float3 *keys = mesh->curve_keys.data(); | ||||
| size_t center_step = (num_motion_steps - 1) / 2; | size_t center_step = (num_motion_steps - 1) / 2; | ||||
| // The center step for motion vertices is not stored in the attribute | |||||
| if (step != center_step) { | if (step != center_step) { | ||||
| keys = motion_keys->data_float3() + | size_t attr_offset = (step > center_step) ? step - 1 : step; | ||||
| (step > center_step ? step - 1 : step) * num_segments; | // Technically this is a float4 array, but sizeof(float3) is the same as sizeof(float4) | ||||
| keys = motion_keys->data_float3() + attr_offset * mesh->curve_keys.size(); | |||||
| } | } | ||||
| for (size_t i = step * num_segments, j = 0; j < num_curves; ++j) { | size_t i = step * num_segments; | ||||
| for (size_t j = 0; j < num_curves; ++j) { | |||||
| const Mesh::Curve c = mesh->get_curve(j); | const Mesh::Curve c = mesh->get_curve(j); | ||||
| for (size_t k = 0; k < c.num_segments(); ++i, ++k) { | for (size_t k = 0; k < c.num_segments(); ++i, ++k) { | ||||
| BoundBox bounds = BoundBox::empty; | BoundBox bounds = BoundBox::empty; | ||||
| c.bounds_grow(k, keys, mesh->curve_radius.data(), bounds); | c.bounds_grow(k, keys, mesh->curve_radius.data(), bounds); | ||||
| aabb_data[i].minX = bounds.min.x; | aabb_data[i].minX = bounds.min.x; | ||||
| aabb_data[i].minY = bounds.min.y; | aabb_data[i].minY = bounds.min.y; | ||||
| aabb_data[i].minZ = bounds.min.z; | aabb_data[i].minZ = bounds.min.z; | ||||
| aabb_data[i].maxX = bounds.max.x; | aabb_data[i].maxX = bounds.max.x; | ||||
| aabb_data[i].maxY = bounds.max.y; | aabb_data[i].maxY = bounds.max.y; | ||||
| aabb_data[i].maxZ = bounds.max.z; | aabb_data[i].maxZ = bounds.max.z; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| // Upload AABB data to GPU | // Upload AABB data to GPU | ||||
| aabb_data.copy_to_device(); | aabb_data.copy_to_device(); | ||||
| vector<device_ptr> aabb_ptrs; | vector<device_ptr> aabb_ptrs; | ||||
| aabb_ptrs.reserve(num_motion_steps); | aabb_ptrs.reserve(num_motion_steps); | ||||
| for (size_t step = 0; step < num_motion_steps; ++step) { | for (size_t step = 0; step < num_motion_steps; ++step) { | ||||
| aabb_ptrs.push_back(aabb_data.device_pointer + step * num_segments * sizeof(OptixAabb)); | aabb_ptrs.push_back(aabb_data.device_pointer + step * num_segments * sizeof(OptixAabb)); | ||||
| } | } | ||||
| // Disable visibility test anyhit program, since it is already checked during intersection | // Disable visibility test anyhit program, since it is already checked during intersection | ||||
| // Those trace calls that require anyhit can force it with OPTIX_RAY_FLAG_ENFORCE_ANYHIT | // Those trace calls that require anyhit can force it with OPTIX_RAY_FLAG_ENFORCE_ANYHIT | ||||
| unsigned int build_flags = OPTIX_GEOMETRY_FLAG_DISABLE_ANYHIT; | unsigned int build_flags = OPTIX_GEOMETRY_FLAG_DISABLE_ANYHIT; | ||||
| OptixBuildInput build_input = {}; | OptixBuildInput build_input = {}; | ||||
| build_input.type = OPTIX_BUILD_INPUT_TYPE_CUSTOM_PRIMITIVES; | build_input.type = OPTIX_BUILD_INPUT_TYPE_CUSTOM_PRIMITIVES; | ||||
| build_input.aabbArray.aabbBuffers = (CUdeviceptr *)aabb_ptrs.data(); | build_input.aabbArray.aabbBuffers = (CUdeviceptr *)aabb_ptrs.data(); | ||||
| build_input.aabbArray.numPrimitives = num_segments; | build_input.aabbArray.numPrimitives = num_segments; | ||||
| build_input.aabbArray.strideInBytes = sizeof(OptixAabb); | build_input.aabbArray.strideInBytes = sizeof(OptixAabb); | ||||
| build_input.aabbArray.flags = &build_flags; | build_input.aabbArray.flags = &build_flags; | ||||
| build_input.aabbArray.numSbtRecords = 1; | build_input.aabbArray.numSbtRecords = 1; | ||||
| build_input.aabbArray.primitiveIndexOffset = mesh->prim_offset; | build_input.aabbArray.primitiveIndexOffset = mesh->prim_offset; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | for (Object *ob : bvh->objects) { | ||||
| vector<device_ptr> vertex_ptrs; | vector<device_ptr> vertex_ptrs; | ||||
| vertex_ptrs.reserve(num_motion_steps); | vertex_ptrs.reserve(num_motion_steps); | ||||
| for (size_t step = 0; step < num_motion_steps; ++step) { | for (size_t step = 0; step < num_motion_steps; ++step) { | ||||
| vertex_ptrs.push_back(vertex_data.device_pointer + num_verts * step * sizeof(float3)); | vertex_ptrs.push_back(vertex_data.device_pointer + num_verts * step * sizeof(float3)); | ||||
| } | } | ||||
| // No special build flags for triangle primitives | // No special build flags for triangle primitives | ||||
| unsigned int build_flags = OPTIX_GEOMETRY_FLAG_NONE; | unsigned int build_flags = OPTIX_GEOMETRY_FLAG_NONE; | ||||
| OptixBuildInput build_input = {}; | OptixBuildInput build_input = {}; | ||||
| build_input.type = OPTIX_BUILD_INPUT_TYPE_TRIANGLES; | build_input.type = OPTIX_BUILD_INPUT_TYPE_TRIANGLES; | ||||
| build_input.triangleArray.vertexBuffers = (CUdeviceptr *)vertex_ptrs.data(); | build_input.triangleArray.vertexBuffers = (CUdeviceptr *)vertex_ptrs.data(); | ||||
| build_input.triangleArray.numVertices = num_verts; | build_input.triangleArray.numVertices = num_verts; | ||||
| build_input.triangleArray.vertexFormat = OPTIX_VERTEX_FORMAT_FLOAT3; | build_input.triangleArray.vertexFormat = OPTIX_VERTEX_FORMAT_FLOAT3; | ||||
| build_input.triangleArray.vertexStrideInBytes = sizeof(float3); | build_input.triangleArray.vertexStrideInBytes = sizeof(float3); | ||||
| build_input.triangleArray.indexBuffer = index_data.device_pointer; | build_input.triangleArray.indexBuffer = index_data.device_pointer; | ||||
| build_input.triangleArray.numIndexTriplets = mesh->num_triangles(); | build_input.triangleArray.numIndexTriplets = mesh->num_triangles(); | ||||
| ▲ Show 20 Lines • Show All 983 Lines • Show Last 20 Lines | |||||