warp-lang 0.9.0__py3-none-win_amd64.whl → 0.11.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of warp-lang might be problematic. Click here for more details.
- warp/__init__.py +15 -7
- warp/__init__.pyi +1 -0
- warp/bin/warp-clang.dll +0 -0
- warp/bin/warp.dll +0 -0
- warp/build.py +22 -443
- warp/build_dll.py +384 -0
- warp/builtins.py +998 -488
- warp/codegen.py +1307 -739
- warp/config.py +5 -3
- warp/constants.py +6 -0
- warp/context.py +1291 -548
- warp/dlpack.py +31 -31
- warp/fabric.py +326 -0
- warp/fem/__init__.py +27 -0
- warp/fem/cache.py +389 -0
- warp/fem/dirichlet.py +181 -0
- warp/fem/domain.py +263 -0
- warp/fem/field/__init__.py +101 -0
- warp/fem/field/field.py +149 -0
- warp/fem/field/nodal_field.py +299 -0
- warp/fem/field/restriction.py +21 -0
- warp/fem/field/test.py +181 -0
- warp/fem/field/trial.py +183 -0
- warp/fem/geometry/__init__.py +19 -0
- warp/fem/geometry/closest_point.py +70 -0
- warp/fem/geometry/deformed_geometry.py +271 -0
- warp/fem/geometry/element.py +744 -0
- warp/fem/geometry/geometry.py +186 -0
- warp/fem/geometry/grid_2d.py +373 -0
- warp/fem/geometry/grid_3d.py +435 -0
- warp/fem/geometry/hexmesh.py +953 -0
- warp/fem/geometry/partition.py +376 -0
- warp/fem/geometry/quadmesh_2d.py +532 -0
- warp/fem/geometry/tetmesh.py +840 -0
- warp/fem/geometry/trimesh_2d.py +577 -0
- warp/fem/integrate.py +1616 -0
- warp/fem/operator.py +191 -0
- warp/fem/polynomial.py +213 -0
- warp/fem/quadrature/__init__.py +2 -0
- warp/fem/quadrature/pic_quadrature.py +245 -0
- warp/fem/quadrature/quadrature.py +294 -0
- warp/fem/space/__init__.py +292 -0
- warp/fem/space/basis_space.py +489 -0
- warp/fem/space/collocated_function_space.py +105 -0
- warp/fem/space/dof_mapper.py +236 -0
- warp/fem/space/function_space.py +145 -0
- warp/fem/space/grid_2d_function_space.py +267 -0
- warp/fem/space/grid_3d_function_space.py +306 -0
- warp/fem/space/hexmesh_function_space.py +352 -0
- warp/fem/space/partition.py +350 -0
- warp/fem/space/quadmesh_2d_function_space.py +369 -0
- warp/fem/space/restriction.py +160 -0
- warp/fem/space/shape/__init__.py +15 -0
- warp/fem/space/shape/cube_shape_function.py +738 -0
- warp/fem/space/shape/shape_function.py +103 -0
- warp/fem/space/shape/square_shape_function.py +611 -0
- warp/fem/space/shape/tet_shape_function.py +567 -0
- warp/fem/space/shape/triangle_shape_function.py +429 -0
- warp/fem/space/tetmesh_function_space.py +292 -0
- warp/fem/space/topology.py +295 -0
- warp/fem/space/trimesh_2d_function_space.py +221 -0
- warp/fem/types.py +77 -0
- warp/fem/utils.py +495 -0
- warp/native/array.h +164 -55
- warp/native/builtin.h +150 -174
- warp/native/bvh.cpp +75 -328
- warp/native/bvh.cu +406 -23
- warp/native/bvh.h +37 -45
- warp/native/clang/clang.cpp +136 -24
- warp/native/crt.cpp +1 -76
- warp/native/crt.h +111 -104
- warp/native/cuda_crt.h +1049 -0
- warp/native/cuda_util.cpp +15 -3
- warp/native/cuda_util.h +3 -1
- warp/native/cutlass/tools/library/scripts/conv2d_operation.py +463 -0
- warp/native/cutlass/tools/library/scripts/conv3d_operation.py +321 -0
- warp/native/cutlass/tools/library/scripts/gemm_operation.py +988 -0
- warp/native/cutlass/tools/library/scripts/generator.py +4625 -0
- warp/native/cutlass/tools/library/scripts/library.py +799 -0
- warp/native/cutlass/tools/library/scripts/manifest.py +402 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/docs/source/conf.py +96 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/profile/conv/conv2d_f16_sm80.py +106 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/profile/gemm/gemm_f32_sm80.py +91 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/setup.py +80 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/__init__.py +48 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/arguments.py +118 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/c_types.py +241 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/compiler.py +432 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/conv2d_operation.py +631 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/epilogue.py +1026 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/frontend.py +104 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/gemm_operation.py +1276 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/library.py +744 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/memory_manager.py +74 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/operation.py +110 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/parser.py +619 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/reduction_operation.py +398 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/tensor_ref.py +70 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/__init__.py +4 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/conv2d_testbed.py +646 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/gemm_grouped_testbed.py +235 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/gemm_testbed.py +557 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/profiler.py +70 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/type_hint.py +39 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/__init__.py +1 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/device.py +76 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/reference_model.py +255 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/__init__.py +0 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +201 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +177 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +98 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +95 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_few_channels_f16nhwc_f16nhwc_f16nhwc_tensor_op_f32_sm80.py +163 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_fixed_channels_f16nhwc_f16nhwc_f16nhwc_tensor_op_f32_sm80.py +187 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +309 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +54 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +96 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +107 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_strided_dgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +253 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +97 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +242 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +96 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +107 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/run_all_tests.py +10 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/frontend/test_frontend.py +146 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/__init__.py +0 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_bf16_sm80.py +96 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f16_sm80.py +447 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f32_sm80.py +146 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f64_sm80.py +102 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_grouped_sm80.py +203 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_s8_sm80.py +229 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/run_all_tests.py +9 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/unit/test_sm80.py +453 -0
- warp/native/cutlass/tools/library/scripts/rank_2k_operation.py +398 -0
- warp/native/cutlass/tools/library/scripts/rank_k_operation.py +387 -0
- warp/native/cutlass/tools/library/scripts/rt.py +796 -0
- warp/native/cutlass/tools/library/scripts/symm_operation.py +400 -0
- warp/native/cutlass/tools/library/scripts/trmm_operation.py +407 -0
- warp/native/cutlass_gemm.cu +5 -3
- warp/native/exports.h +1240 -949
- warp/native/fabric.h +228 -0
- warp/native/hashgrid.cpp +4 -4
- warp/native/hashgrid.h +22 -2
- warp/native/initializer_array.h +2 -2
- warp/native/intersect.h +22 -7
- warp/native/intersect_adj.h +8 -8
- warp/native/intersect_tri.h +13 -16
- warp/native/marching.cu +157 -161
- warp/native/mat.h +119 -19
- warp/native/matnn.h +2 -2
- warp/native/mesh.cpp +108 -83
- warp/native/mesh.cu +243 -6
- warp/native/mesh.h +1547 -458
- warp/native/nanovdb/NanoVDB.h +1 -1
- warp/native/noise.h +272 -329
- warp/native/quat.h +51 -8
- warp/native/rand.h +45 -35
- warp/native/range.h +6 -2
- warp/native/reduce.cpp +157 -0
- warp/native/reduce.cu +348 -0
- warp/native/runlength_encode.cpp +62 -0
- warp/native/runlength_encode.cu +46 -0
- warp/native/scan.cu +11 -13
- warp/native/scan.h +1 -0
- warp/native/solid_angle.h +442 -0
- warp/native/sort.cpp +13 -0
- warp/native/sort.cu +9 -1
- warp/native/sparse.cpp +338 -0
- warp/native/sparse.cu +545 -0
- warp/native/spatial.h +2 -2
- warp/native/temp_buffer.h +30 -0
- warp/native/vec.h +126 -24
- warp/native/volume.h +120 -0
- warp/native/warp.cpp +658 -53
- warp/native/warp.cu +660 -68
- warp/native/warp.h +112 -12
- warp/optim/__init__.py +1 -0
- warp/optim/linear.py +922 -0
- warp/optim/sgd.py +92 -0
- warp/render/render_opengl.py +392 -152
- warp/render/render_usd.py +11 -11
- warp/sim/__init__.py +2 -2
- warp/sim/articulation.py +385 -185
- warp/sim/collide.py +21 -8
- warp/sim/import_mjcf.py +297 -106
- warp/sim/import_urdf.py +389 -210
- warp/sim/import_usd.py +198 -97
- warp/sim/inertia.py +17 -18
- warp/sim/integrator_euler.py +14 -8
- warp/sim/integrator_xpbd.py +161 -19
- warp/sim/model.py +795 -291
- warp/sim/optimizer.py +2 -6
- warp/sim/render.py +65 -3
- warp/sim/utils.py +3 -0
- warp/sparse.py +1227 -0
- warp/stubs.py +665 -223
- warp/tape.py +66 -15
- warp/tests/__main__.py +3 -6
- warp/tests/assets/curlnoise_golden.npy +0 -0
- warp/tests/assets/pnoise_golden.npy +0 -0
- warp/tests/assets/torus.usda +105 -105
- warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
- warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
- warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
- warp/tests/aux_test_unresolved_func.py +14 -0
- warp/tests/aux_test_unresolved_symbol.py +14 -0
- warp/tests/disabled_kinematics.py +239 -0
- warp/tests/run_coverage_serial.py +31 -0
- warp/tests/test_adam.py +103 -106
- warp/tests/test_arithmetic.py +128 -74
- warp/tests/test_array.py +1497 -211
- warp/tests/test_array_reduce.py +150 -0
- warp/tests/test_atomic.py +64 -28
- warp/tests/test_bool.py +99 -0
- warp/tests/test_builtins_resolution.py +1292 -0
- warp/tests/test_bvh.py +75 -43
- warp/tests/test_closest_point_edge_edge.py +54 -57
- warp/tests/test_codegen.py +233 -128
- warp/tests/test_compile_consts.py +28 -20
- warp/tests/test_conditional.py +108 -24
- warp/tests/test_copy.py +10 -12
- warp/tests/test_ctypes.py +112 -88
- warp/tests/test_dense.py +21 -14
- warp/tests/test_devices.py +98 -0
- warp/tests/test_dlpack.py +136 -108
- warp/tests/test_examples.py +277 -0
- warp/tests/test_fabricarray.py +955 -0
- warp/tests/test_fast_math.py +15 -11
- warp/tests/test_fem.py +1271 -0
- warp/tests/test_fp16.py +53 -19
- warp/tests/test_func.py +187 -74
- warp/tests/test_generics.py +194 -49
- warp/tests/test_grad.py +180 -116
- warp/tests/test_grad_customs.py +176 -0
- warp/tests/test_hash_grid.py +52 -37
- warp/tests/test_import.py +10 -23
- warp/tests/test_indexedarray.py +577 -24
- warp/tests/test_intersect.py +18 -9
- warp/tests/test_large.py +141 -0
- warp/tests/test_launch.py +251 -15
- warp/tests/test_lerp.py +64 -65
- warp/tests/test_linear_solvers.py +154 -0
- warp/tests/test_lvalue.py +493 -0
- warp/tests/test_marching_cubes.py +12 -13
- warp/tests/test_mat.py +508 -2778
- warp/tests/test_mat_lite.py +115 -0
- warp/tests/test_mat_scalar_ops.py +2889 -0
- warp/tests/test_math.py +103 -9
- warp/tests/test_matmul.py +305 -69
- warp/tests/test_matmul_lite.py +410 -0
- warp/tests/test_mesh.py +71 -14
- warp/tests/test_mesh_query_aabb.py +41 -25
- warp/tests/test_mesh_query_point.py +325 -34
- warp/tests/test_mesh_query_ray.py +39 -22
- warp/tests/test_mlp.py +30 -22
- warp/tests/test_model.py +92 -89
- warp/tests/test_modules_lite.py +39 -0
- warp/tests/test_multigpu.py +88 -114
- warp/tests/test_noise.py +12 -11
- warp/tests/test_operators.py +16 -20
- warp/tests/test_options.py +11 -11
- warp/tests/test_pinned.py +17 -18
- warp/tests/test_print.py +32 -11
- warp/tests/test_quat.py +275 -129
- warp/tests/test_rand.py +18 -16
- warp/tests/test_reload.py +38 -34
- warp/tests/test_rounding.py +50 -43
- warp/tests/test_runlength_encode.py +190 -0
- warp/tests/test_smoothstep.py +9 -11
- warp/tests/test_snippet.py +143 -0
- warp/tests/test_sparse.py +460 -0
- warp/tests/test_spatial.py +276 -243
- warp/tests/test_streams.py +110 -85
- warp/tests/test_struct.py +331 -85
- warp/tests/test_tape.py +39 -21
- warp/tests/test_torch.py +118 -89
- warp/tests/test_transient_module.py +12 -13
- warp/tests/test_types.py +614 -0
- warp/tests/test_utils.py +494 -0
- warp/tests/test_vec.py +354 -1987
- warp/tests/test_vec_lite.py +73 -0
- warp/tests/test_vec_scalar_ops.py +2099 -0
- warp/tests/test_volume.py +457 -293
- warp/tests/test_volume_write.py +124 -134
- warp/tests/unittest_serial.py +35 -0
- warp/tests/unittest_suites.py +341 -0
- warp/tests/unittest_utils.py +568 -0
- warp/tests/unused_test_misc.py +71 -0
- warp/tests/{test_debug.py → walkthough_debug.py} +3 -17
- warp/thirdparty/appdirs.py +36 -45
- warp/thirdparty/unittest_parallel.py +549 -0
- warp/torch.py +72 -30
- warp/types.py +1744 -713
- warp/utils.py +360 -350
- warp_lang-0.11.0.dist-info/LICENSE.md +36 -0
- warp_lang-0.11.0.dist-info/METADATA +238 -0
- warp_lang-0.11.0.dist-info/RECORD +332 -0
- {warp_lang-0.9.0.dist-info → warp_lang-0.11.0.dist-info}/WHEEL +1 -1
- warp/bin/warp-clang.exp +0 -0
- warp/bin/warp-clang.lib +0 -0
- warp/bin/warp.exp +0 -0
- warp/bin/warp.lib +0 -0
- warp/tests/test_all.py +0 -215
- warp/tests/test_array_scan.py +0 -60
- warp/tests/test_base.py +0 -208
- warp/tests/test_unresolved_func.py +0 -7
- warp/tests/test_unresolved_symbol.py +0 -7
- warp_lang-0.9.0.dist-info/METADATA +0 -20
- warp_lang-0.9.0.dist-info/RECORD +0 -177
- /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
- /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
- /warp/tests/{test_square.py → aux_test_square.py} +0 -0
- {warp_lang-0.9.0.dist-info → warp_lang-0.11.0.dist-info}/top_level.txt +0 -0
warp/native/bvh.cu
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#include "warp.h"
|
|
10
10
|
#include "cuda_util.h"
|
|
11
11
|
#include "bvh.h"
|
|
12
|
+
#include "sort.h"
|
|
12
13
|
|
|
13
14
|
#include <vector>
|
|
14
15
|
#include <algorithm>
|
|
@@ -16,25 +17,32 @@
|
|
|
16
17
|
#include <cuda.h>
|
|
17
18
|
#include <cuda_runtime_api.h>
|
|
18
19
|
|
|
20
|
+
#define THRUST_IGNORE_CUB_VERSION_CHECK
|
|
21
|
+
|
|
22
|
+
#include <cub/cub.cuh>
|
|
23
|
+
|
|
24
|
+
|
|
19
25
|
namespace wp
|
|
20
26
|
{
|
|
21
27
|
|
|
22
|
-
__global__ void bvh_refit_kernel(int n, const int* __restrict__ parents, int* __restrict__ child_count, BVHPackedNodeHalf* __restrict__
|
|
28
|
+
__global__ void bvh_refit_kernel(int n, const int* __restrict__ parents, int* __restrict__ child_count, BVHPackedNodeHalf* __restrict__ node_lowers, BVHPackedNodeHalf* __restrict__ node_uppers, const vec3* item_lowers, const vec3* item_uppers)
|
|
23
29
|
{
|
|
24
30
|
int index = blockDim.x*blockIdx.x + threadIdx.x;
|
|
25
31
|
|
|
26
32
|
if (index < n)
|
|
27
33
|
{
|
|
28
|
-
bool leaf =
|
|
34
|
+
bool leaf = node_lowers[index].b;
|
|
29
35
|
|
|
30
36
|
if (leaf)
|
|
31
37
|
{
|
|
32
38
|
// update the leaf node
|
|
33
|
-
const int leaf_index =
|
|
34
|
-
const bounds3& b = bounds[leaf_index];
|
|
39
|
+
const int leaf_index = node_lowers[index].i;
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
vec3 lower = item_lowers[leaf_index];
|
|
42
|
+
vec3 upper = item_uppers[leaf_index];
|
|
43
|
+
|
|
44
|
+
make_node(node_lowers+index, lower, leaf_index, true);
|
|
45
|
+
make_node(node_uppers+index, upper, 0, false);
|
|
38
46
|
}
|
|
39
47
|
else
|
|
40
48
|
{
|
|
@@ -59,6 +67,214 @@ __global__ void bvh_refit_kernel(int n, const int* __restrict__ parents, int* __
|
|
|
59
67
|
// if we have are the last thread (such that the parent node is now complete)
|
|
60
68
|
// then update its bounds and move onto the the next parent in the hierarchy
|
|
61
69
|
if (finished == 1)
|
|
70
|
+
{
|
|
71
|
+
const int left_child = node_lowers[parent].i;
|
|
72
|
+
const int right_child = node_uppers[parent].i;
|
|
73
|
+
|
|
74
|
+
vec3 left_lower = vec3(node_lowers[left_child].x,
|
|
75
|
+
node_lowers[left_child].y,
|
|
76
|
+
node_lowers[left_child].z);
|
|
77
|
+
|
|
78
|
+
vec3 left_upper = vec3(node_uppers[left_child].x,
|
|
79
|
+
node_uppers[left_child].y,
|
|
80
|
+
node_uppers[left_child].z);
|
|
81
|
+
|
|
82
|
+
vec3 right_lower = vec3(node_lowers[right_child].x,
|
|
83
|
+
node_lowers[right_child].y,
|
|
84
|
+
node_lowers[right_child].z);
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
vec3 right_upper = vec3(node_uppers[right_child].x,
|
|
88
|
+
node_uppers[right_child].y,
|
|
89
|
+
node_uppers[right_child].z);
|
|
90
|
+
|
|
91
|
+
// union of child bounds
|
|
92
|
+
vec3 lower = min(left_lower, right_lower);
|
|
93
|
+
vec3 upper = max(left_upper, right_upper);
|
|
94
|
+
|
|
95
|
+
// write new BVH nodes
|
|
96
|
+
make_node(node_lowers+parent, lower, left_child, false);
|
|
97
|
+
make_node(node_uppers+parent, upper, right_child, false);
|
|
98
|
+
|
|
99
|
+
// move onto processing the parent
|
|
100
|
+
index = parent;
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
{
|
|
104
|
+
// parent not ready (we are the first child), terminate thread
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
void bvh_refit_device(BVH& bvh)
|
|
113
|
+
{
|
|
114
|
+
ContextGuard guard(bvh.context);
|
|
115
|
+
|
|
116
|
+
// clear child counters
|
|
117
|
+
memset_device(WP_CURRENT_CONTEXT, bvh.node_counts, 0, sizeof(int)*bvh.max_nodes);
|
|
118
|
+
|
|
119
|
+
wp_launch_device(WP_CURRENT_CONTEXT, bvh_refit_kernel, bvh.num_items, (bvh.num_items, bvh.node_parents, bvh.node_counts, bvh.node_lowers, bvh.node_uppers, bvh.item_lowers, bvh.item_uppers));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
124
|
+
|
|
125
|
+
// Create a linear BVH as described in Fast and Simple Agglomerative LBVH construction
|
|
126
|
+
// this is a bottom-up clustering method that outputs one node per-leaf
|
|
127
|
+
//
|
|
128
|
+
class LinearBVHBuilderGPU
|
|
129
|
+
{
|
|
130
|
+
public:
|
|
131
|
+
|
|
132
|
+
LinearBVHBuilderGPU();
|
|
133
|
+
~LinearBVHBuilderGPU();
|
|
134
|
+
|
|
135
|
+
// takes a bvh (host ref), and pointers to the GPU lower and upper bounds for each triangle
|
|
136
|
+
void build(BVH& bvh, const vec3* item_lowers, const vec3* item_uppers, int num_items, bounds3* total_bounds);
|
|
137
|
+
|
|
138
|
+
private:
|
|
139
|
+
|
|
140
|
+
// temporary data used during building
|
|
141
|
+
int* indices;
|
|
142
|
+
int* keys;
|
|
143
|
+
int* deltas;
|
|
144
|
+
int* range_lefts;
|
|
145
|
+
int* range_rights;
|
|
146
|
+
int* num_children;
|
|
147
|
+
|
|
148
|
+
// bounds data when total item bounds built on GPU
|
|
149
|
+
vec3* total_lower;
|
|
150
|
+
vec3* total_upper;
|
|
151
|
+
vec3* total_inv_edges;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
////////////////////////////////////////////////////////
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
__global__ void compute_morton_codes(const vec3* __restrict__ item_lowers, const vec3* __restrict__ item_uppers, int n, const vec3* grid_lower, const vec3* grid_inv_edges, int* __restrict__ indices, int* __restrict__ keys)
|
|
159
|
+
{
|
|
160
|
+
const int index = blockDim.x*blockIdx.x + threadIdx.x;
|
|
161
|
+
|
|
162
|
+
if (index < n)
|
|
163
|
+
{
|
|
164
|
+
vec3 lower = item_lowers[index];
|
|
165
|
+
vec3 upper = item_uppers[index];
|
|
166
|
+
|
|
167
|
+
vec3 center = 0.5f*(lower+upper);
|
|
168
|
+
|
|
169
|
+
vec3 local = cw_mul((center-grid_lower[0]), grid_inv_edges[0]);
|
|
170
|
+
|
|
171
|
+
// 10-bit Morton codes stored in lower 30bits (1024^3 effective resolution)
|
|
172
|
+
int key = morton3<1024>(local[0], local[1], local[2]);
|
|
173
|
+
|
|
174
|
+
indices[index] = index;
|
|
175
|
+
keys[index] = key;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// calculate the index of the first differing bit between two adjacent Morton keys
|
|
180
|
+
__global__ void compute_key_deltas(const int* __restrict__ keys, int* __restrict__ deltas, int n)
|
|
181
|
+
{
|
|
182
|
+
const int index = blockDim.x*blockIdx.x + threadIdx.x;
|
|
183
|
+
|
|
184
|
+
if (index < n)
|
|
185
|
+
{
|
|
186
|
+
int a = keys[index];
|
|
187
|
+
int b = keys[index+1];
|
|
188
|
+
|
|
189
|
+
int x = a^b;
|
|
190
|
+
|
|
191
|
+
deltas[index] = x;// __clz(x);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
__global__ void build_leaves(const vec3* __restrict__ item_lowers, const vec3* __restrict__ item_uppers, int n, const int* __restrict__ indices, int* __restrict__ range_lefts, int* __restrict__ range_rights, BVHPackedNodeHalf* __restrict__ lowers, BVHPackedNodeHalf* __restrict__ uppers)
|
|
196
|
+
{
|
|
197
|
+
const int index = blockDim.x*blockIdx.x + threadIdx.x;
|
|
198
|
+
|
|
199
|
+
if (index < n)
|
|
200
|
+
{
|
|
201
|
+
const int item = indices[index];
|
|
202
|
+
|
|
203
|
+
vec3 lower = item_lowers[item];
|
|
204
|
+
vec3 upper = item_uppers[item];
|
|
205
|
+
|
|
206
|
+
// write leaf nodes
|
|
207
|
+
lowers[index] = make_node(lower, item, true);
|
|
208
|
+
uppers[index] = make_node(upper, item, false);
|
|
209
|
+
|
|
210
|
+
// write leaf key ranges
|
|
211
|
+
range_lefts[index] = index;
|
|
212
|
+
range_rights[index] = index;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// this bottom-up process assigns left and right children and combines bounds to form internal nodes
|
|
217
|
+
// there is one thread launched per-leaf node, each thread calculates it's parent node and assigns
|
|
218
|
+
// itself to either the left or right parent slot, the last child to complete the parent and moves
|
|
219
|
+
// up the hierarchy
|
|
220
|
+
__global__ void build_hierarchy(int n, int* root, const int* __restrict__ deltas, int* __restrict__ num_children, volatile int* __restrict__ range_lefts, volatile int* __restrict__ range_rights, volatile int* __restrict__ parents, volatile BVHPackedNodeHalf* __restrict__ lowers, volatile BVHPackedNodeHalf* __restrict__ uppers)
|
|
221
|
+
{
|
|
222
|
+
int index = blockDim.x*blockIdx.x + threadIdx.x;
|
|
223
|
+
|
|
224
|
+
if (index < n)
|
|
225
|
+
{
|
|
226
|
+
const int internal_offset = n;
|
|
227
|
+
|
|
228
|
+
for (;;)
|
|
229
|
+
{
|
|
230
|
+
int left = range_lefts[index];
|
|
231
|
+
int right = range_rights[index];
|
|
232
|
+
|
|
233
|
+
// check if we are the root node, if so then store out our index and terminate
|
|
234
|
+
if (left == 0 && right == n-1)
|
|
235
|
+
{
|
|
236
|
+
*root = index;
|
|
237
|
+
parents[index] = -1;
|
|
238
|
+
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
int childCount = 0;
|
|
243
|
+
|
|
244
|
+
int parent;
|
|
245
|
+
|
|
246
|
+
if (left == 0 || (right != n-1 && deltas[right] < deltas[left-1]))
|
|
247
|
+
{
|
|
248
|
+
parent = right + internal_offset;
|
|
249
|
+
|
|
250
|
+
// set parent left child
|
|
251
|
+
parents[index] = parent;
|
|
252
|
+
lowers[parent].i = index;
|
|
253
|
+
range_lefts[parent] = left;
|
|
254
|
+
|
|
255
|
+
// ensure above writes are visible to all threads
|
|
256
|
+
__threadfence();
|
|
257
|
+
|
|
258
|
+
childCount = atomicAdd(&num_children[parent], 1);
|
|
259
|
+
}
|
|
260
|
+
else
|
|
261
|
+
{
|
|
262
|
+
parent = left + internal_offset - 1;
|
|
263
|
+
|
|
264
|
+
// set parent right child
|
|
265
|
+
parents[index] = parent;
|
|
266
|
+
uppers[parent].i = index;
|
|
267
|
+
range_rights[parent] = right;
|
|
268
|
+
|
|
269
|
+
// ensure above writes are visible to all threads
|
|
270
|
+
__threadfence();
|
|
271
|
+
|
|
272
|
+
childCount = atomicAdd(&num_children[parent], 1);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// if we have are the last thread (such that the parent node is now complete)
|
|
276
|
+
// then update its bounds and move onto the the next parent in the hierarchy
|
|
277
|
+
if (childCount == 1)
|
|
62
278
|
{
|
|
63
279
|
const int left_child = lowers[parent].i;
|
|
64
280
|
const int right_child = uppers[parent].i;
|
|
@@ -72,15 +288,15 @@ __global__ void bvh_refit_kernel(int n, const int* __restrict__ parents, int* __
|
|
|
72
288
|
uppers[left_child].z);
|
|
73
289
|
|
|
74
290
|
vec3 right_lower = vec3(lowers[right_child].x,
|
|
75
|
-
|
|
76
|
-
|
|
291
|
+
lowers[right_child].y,
|
|
292
|
+
lowers[right_child].z);
|
|
77
293
|
|
|
78
294
|
|
|
79
295
|
vec3 right_upper = vec3(uppers[right_child].x,
|
|
80
|
-
|
|
81
|
-
|
|
296
|
+
uppers[right_child].y,
|
|
297
|
+
uppers[right_child].z);
|
|
82
298
|
|
|
83
|
-
//
|
|
299
|
+
// bounds_union of child bounds
|
|
84
300
|
vec3 lower = min(left_lower, right_lower);
|
|
85
301
|
vec3 upper = max(left_upper, right_upper);
|
|
86
302
|
|
|
@@ -100,30 +316,158 @@ __global__ void bvh_refit_kernel(int n, const int* __restrict__ parents, int* __
|
|
|
100
316
|
}
|
|
101
317
|
}
|
|
102
318
|
|
|
319
|
+
CUDA_CALLABLE inline vec3 Vec3Max(const vec3& a, const vec3& b) { return wp::max(a, b); }
|
|
320
|
+
CUDA_CALLABLE inline vec3 Vec3Min(const vec3& a, const vec3& b) { return wp::min(a, b); }
|
|
103
321
|
|
|
104
|
-
void
|
|
322
|
+
__global__ void compute_total_bounds(const vec3* item_lowers, const vec3* item_uppers, vec3* total_lower, vec3* total_upper, int num_items)
|
|
105
323
|
{
|
|
106
|
-
|
|
324
|
+
typedef cub::BlockReduce<vec3, 256> BlockReduce;
|
|
107
325
|
|
|
108
|
-
|
|
109
|
-
|
|
326
|
+
__shared__ typename BlockReduce::TempStorage temp_storage;
|
|
327
|
+
|
|
328
|
+
const int blockStart = blockDim.x*blockIdx.x;
|
|
329
|
+
const int numValid = ::min(num_items-blockStart, blockDim.x);
|
|
330
|
+
|
|
331
|
+
const int tid = blockStart + threadIdx.x;
|
|
332
|
+
|
|
333
|
+
if (tid < num_items)
|
|
334
|
+
{
|
|
335
|
+
vec3 lower = item_lowers[tid];
|
|
336
|
+
vec3 upper = item_uppers[tid];
|
|
337
|
+
|
|
338
|
+
vec3 block_upper = BlockReduce(temp_storage).Reduce(upper, Vec3Max, numValid);
|
|
339
|
+
|
|
340
|
+
// sync threads because second reduce uses same temp storage as first
|
|
341
|
+
__syncthreads();
|
|
342
|
+
|
|
343
|
+
vec3 block_lower = BlockReduce(temp_storage).Reduce(lower, Vec3Min, numValid);
|
|
110
344
|
|
|
111
|
-
|
|
345
|
+
if (threadIdx.x == 0)
|
|
346
|
+
{
|
|
347
|
+
// write out block results, expanded by the radius
|
|
348
|
+
atomic_max(total_upper, block_upper);
|
|
349
|
+
atomic_min(total_lower, block_lower);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// compute inverse edge length, this is just done on the GPU to avoid a CPU->GPU sync point
|
|
355
|
+
__global__ void compute_total_inv_edges(const vec3* total_lower, const vec3* total_upper, vec3* total_inv_edges)
|
|
356
|
+
{
|
|
357
|
+
vec3 edges = (total_upper[0]-total_lower[0]);
|
|
358
|
+
edges += vec3(0.0001f);
|
|
359
|
+
|
|
360
|
+
total_inv_edges[0] = vec3(1.0f/edges[0], 1.0f/edges[1], 1.0f/edges[2]);
|
|
112
361
|
}
|
|
113
362
|
|
|
114
|
-
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
LinearBVHBuilderGPU::LinearBVHBuilderGPU()
|
|
366
|
+
: indices(NULL)
|
|
367
|
+
, keys(NULL)
|
|
368
|
+
, deltas(NULL)
|
|
369
|
+
, range_lefts(NULL)
|
|
370
|
+
, range_rights(NULL)
|
|
371
|
+
, num_children(NULL)
|
|
372
|
+
, total_lower(NULL)
|
|
373
|
+
, total_upper(NULL)
|
|
374
|
+
, total_inv_edges(NULL)
|
|
115
375
|
{
|
|
116
|
-
|
|
376
|
+
total_lower = (vec3*)alloc_temp_device(WP_CURRENT_CONTEXT, sizeof(vec3));
|
|
377
|
+
total_upper = (vec3*)alloc_temp_device(WP_CURRENT_CONTEXT, sizeof(vec3));
|
|
378
|
+
total_inv_edges = (vec3*)alloc_temp_device(WP_CURRENT_CONTEXT, sizeof(vec3));
|
|
379
|
+
}
|
|
117
380
|
|
|
118
|
-
|
|
381
|
+
LinearBVHBuilderGPU::~LinearBVHBuilderGPU()
|
|
382
|
+
{
|
|
383
|
+
free_temp_device(WP_CURRENT_CONTEXT, total_lower);
|
|
384
|
+
free_temp_device(WP_CURRENT_CONTEXT, total_upper);
|
|
385
|
+
free_temp_device(WP_CURRENT_CONTEXT, total_inv_edges);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
void LinearBVHBuilderGPU::build(BVH& bvh, const vec3* item_lowers, const vec3* item_uppers, int num_items, bounds3* total_bounds)
|
|
391
|
+
{
|
|
392
|
+
// allocate temporary memory used during building
|
|
393
|
+
indices = (int*)alloc_temp_device(WP_CURRENT_CONTEXT, sizeof(int)*num_items*2); // *2 for radix sort
|
|
394
|
+
keys = (int*)alloc_temp_device(WP_CURRENT_CONTEXT, sizeof(int)*num_items*2); // *2 for radix sort
|
|
395
|
+
deltas = (int*)alloc_temp_device(WP_CURRENT_CONTEXT, sizeof(int)*num_items); // highest differenting bit between keys for item i and i+1
|
|
396
|
+
range_lefts = (int*)alloc_temp_device(WP_CURRENT_CONTEXT, sizeof(int)*bvh.max_nodes);
|
|
397
|
+
range_rights = (int*)alloc_temp_device(WP_CURRENT_CONTEXT, sizeof(int)*bvh.max_nodes);
|
|
398
|
+
num_children = (int*)alloc_temp_device(WP_CURRENT_CONTEXT, sizeof(int)*bvh.max_nodes);
|
|
399
|
+
|
|
400
|
+
// if total bounds supplied by the host then we just
|
|
401
|
+
// compute our edge length and upload it to the GPU directly
|
|
402
|
+
if (total_bounds)
|
|
119
403
|
{
|
|
120
|
-
|
|
404
|
+
// calculate Morton codes
|
|
405
|
+
vec3 edges = (*total_bounds).edges();
|
|
406
|
+
edges += vec3(0.0001f);
|
|
407
|
+
|
|
408
|
+
vec3 inv_edges = vec3(1.0f/edges[0], 1.0f/edges[1], 1.0f/edges[2]);
|
|
409
|
+
|
|
410
|
+
memcpy_h2d(WP_CURRENT_CONTEXT, total_lower, &total_bounds->lower[0], sizeof(vec3));
|
|
411
|
+
memcpy_h2d(WP_CURRENT_CONTEXT, total_upper, &total_bounds->upper[0], sizeof(vec3));
|
|
412
|
+
memcpy_h2d(WP_CURRENT_CONTEXT, total_inv_edges, &inv_edges[0], sizeof(vec3));
|
|
413
|
+
}
|
|
414
|
+
else
|
|
415
|
+
{
|
|
416
|
+
static vec3 upper(-FLT_MAX);
|
|
417
|
+
static vec3 lower(FLT_MAX);
|
|
418
|
+
|
|
419
|
+
memcpy_h2d(WP_CURRENT_CONTEXT, total_lower, &lower, sizeof(lower));
|
|
420
|
+
memcpy_h2d(WP_CURRENT_CONTEXT, total_upper, &upper, sizeof(upper));
|
|
421
|
+
|
|
422
|
+
// compute the total bounds on the GPU
|
|
423
|
+
wp_launch_device(WP_CURRENT_CONTEXT, compute_total_bounds, num_items, (item_lowers, item_uppers, total_lower, total_upper, num_items));
|
|
424
|
+
|
|
425
|
+
// compute the total edge length
|
|
426
|
+
wp_launch_device(WP_CURRENT_CONTEXT, compute_total_inv_edges, 1, (total_lower, total_upper, total_inv_edges));
|
|
121
427
|
}
|
|
428
|
+
|
|
429
|
+
// assign 30-bit Morton code based on the centroid of each triangle and bounds for each leaf
|
|
430
|
+
wp_launch_device(WP_CURRENT_CONTEXT, compute_morton_codes, num_items, (item_lowers, item_uppers, num_items, total_lower, total_inv_edges, indices, keys));
|
|
431
|
+
|
|
432
|
+
// sort items based on Morton key (note the 32-bit sort key corresponds to the template parameter to morton3, i.e. 3x9 bit keys combined)
|
|
433
|
+
radix_sort_pairs_device(WP_CURRENT_CONTEXT, keys, indices, num_items);
|
|
434
|
+
|
|
435
|
+
// calculate deltas between adjacent keys
|
|
436
|
+
wp_launch_device(WP_CURRENT_CONTEXT, compute_key_deltas, num_items, (keys, deltas, num_items-1));
|
|
437
|
+
|
|
438
|
+
// initialize leaf nodes
|
|
439
|
+
wp_launch_device(WP_CURRENT_CONTEXT, build_leaves, num_items, (item_lowers, item_uppers, num_items, indices, range_lefts, range_rights, bvh.node_lowers, bvh.node_uppers));
|
|
440
|
+
|
|
441
|
+
// reset children count, this is our atomic counter so we know when an internal node is complete, only used during building
|
|
442
|
+
memset_device(WP_CURRENT_CONTEXT, num_children, 0, sizeof(int)*bvh.max_nodes);
|
|
443
|
+
|
|
444
|
+
// build the tree and internal node bounds
|
|
445
|
+
wp_launch_device(WP_CURRENT_CONTEXT, build_hierarchy, num_items, (num_items, bvh.root, deltas, num_children, range_lefts, range_rights, bvh.node_parents, bvh.node_lowers, bvh.node_uppers));
|
|
446
|
+
|
|
447
|
+
// free temporary memory
|
|
448
|
+
free_temp_device(WP_CURRENT_CONTEXT, indices);
|
|
449
|
+
free_temp_device(WP_CURRENT_CONTEXT, keys);
|
|
450
|
+
free_temp_device(WP_CURRENT_CONTEXT, deltas);
|
|
451
|
+
|
|
452
|
+
free_temp_device(WP_CURRENT_CONTEXT, range_lefts);
|
|
453
|
+
free_temp_device(WP_CURRENT_CONTEXT, range_rights);
|
|
454
|
+
free_temp_device(WP_CURRENT_CONTEXT, num_children);
|
|
455
|
+
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
void bvh_destroy_device(wp::BVH& bvh)
|
|
459
|
+
{
|
|
460
|
+
ContextGuard guard(bvh.context);
|
|
461
|
+
|
|
462
|
+
free_device(WP_CURRENT_CONTEXT, bvh.node_lowers); bvh.node_lowers = NULL;
|
|
463
|
+
free_device(WP_CURRENT_CONTEXT, bvh.node_uppers); bvh.node_uppers = NULL;
|
|
464
|
+
free_device(WP_CURRENT_CONTEXT, bvh.node_parents); bvh.node_parents = NULL;
|
|
465
|
+
free_device(WP_CURRENT_CONTEXT, bvh.node_counts); bvh.node_counts = NULL;
|
|
466
|
+
free_device(WP_CURRENT_CONTEXT, bvh.root); bvh.root = NULL;
|
|
122
467
|
}
|
|
123
468
|
|
|
124
469
|
} // namespace wp
|
|
125
470
|
|
|
126
|
-
// refit to data stored in the bvh
|
|
127
471
|
|
|
128
472
|
void bvh_refit_device(uint64_t id)
|
|
129
473
|
{
|
|
@@ -131,12 +475,51 @@ void bvh_refit_device(uint64_t id)
|
|
|
131
475
|
if (bvh_get_descriptor(id, bvh))
|
|
132
476
|
{
|
|
133
477
|
ContextGuard guard(bvh.context);
|
|
134
|
-
wp_launch_device(WP_CURRENT_CONTEXT, wp::set_bounds_from_lowers_and_uppers, bvh.num_bounds, (bvh.num_bounds, bvh.bounds, bvh.lowers, bvh.uppers));
|
|
135
478
|
|
|
136
|
-
bvh_refit_device(bvh
|
|
479
|
+
bvh_refit_device(bvh);
|
|
137
480
|
}
|
|
481
|
+
}
|
|
138
482
|
|
|
483
|
+
uint64_t bvh_create_device(void* context, wp::vec3* lowers, wp::vec3* uppers, int num_items)
|
|
484
|
+
{
|
|
485
|
+
ContextGuard guard(context);
|
|
486
|
+
|
|
487
|
+
wp::BVH bvh_host;
|
|
488
|
+
bvh_host.num_items = num_items;
|
|
489
|
+
bvh_host.max_nodes = 2*num_items;
|
|
490
|
+
bvh_host.node_lowers = (wp::BVHPackedNodeHalf*)alloc_device(WP_CURRENT_CONTEXT, sizeof(wp::BVHPackedNodeHalf)*bvh_host.max_nodes);
|
|
491
|
+
bvh_host.node_uppers = (wp::BVHPackedNodeHalf*)alloc_device(WP_CURRENT_CONTEXT, sizeof(wp::BVHPackedNodeHalf)*bvh_host.max_nodes);
|
|
492
|
+
bvh_host.node_parents = (int*)alloc_device(WP_CURRENT_CONTEXT, sizeof(int)*bvh_host.max_nodes);
|
|
493
|
+
bvh_host.node_counts = (int*)alloc_device(WP_CURRENT_CONTEXT, sizeof(int)*bvh_host.max_nodes);
|
|
494
|
+
bvh_host.root = (int*)alloc_device(WP_CURRENT_CONTEXT, sizeof(int));
|
|
495
|
+
bvh_host.item_lowers = lowers;
|
|
496
|
+
bvh_host.item_uppers = uppers;
|
|
497
|
+
|
|
498
|
+
bvh_host.context = context ? context : cuda_context_get_current();
|
|
499
|
+
|
|
500
|
+
wp::LinearBVHBuilderGPU builder;
|
|
501
|
+
builder.build(bvh_host, lowers, uppers, num_items, NULL);
|
|
502
|
+
|
|
503
|
+
// create device-side BVH descriptor
|
|
504
|
+
wp::BVH* bvh_device = (wp::BVH*)alloc_device(WP_CURRENT_CONTEXT, sizeof(wp::BVH));
|
|
505
|
+
memcpy_h2d(WP_CURRENT_CONTEXT, bvh_device, &bvh_host, sizeof(wp::BVH));
|
|
506
|
+
|
|
507
|
+
uint64_t bvh_id = (uint64_t)bvh_device;
|
|
508
|
+
wp::bvh_add_descriptor(bvh_id, bvh_host);
|
|
509
|
+
|
|
510
|
+
return bvh_id;
|
|
139
511
|
}
|
|
140
512
|
|
|
141
513
|
|
|
514
|
+
void bvh_destroy_device(uint64_t id)
|
|
515
|
+
{
|
|
516
|
+
wp::BVH bvh;
|
|
517
|
+
if (wp::bvh_get_descriptor(id, bvh))
|
|
518
|
+
{
|
|
519
|
+
wp::bvh_destroy_device(bvh);
|
|
520
|
+
wp::bvh_rem_descriptor(id);
|
|
142
521
|
|
|
522
|
+
// free descriptor
|
|
523
|
+
free_device(WP_CURRENT_CONTEXT, (void*)id);
|
|
524
|
+
}
|
|
525
|
+
}
|
warp/native/bvh.h
CHANGED
|
@@ -103,7 +103,6 @@ CUDA_CALLABLE inline bounds3 bounds_intersection(const bounds3& a, const bounds3
|
|
|
103
103
|
return bounds3(max(a.lower, b.lower), min(a.upper, b.upper));
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
|
|
107
106
|
struct BVHPackedNodeHalf
|
|
108
107
|
{
|
|
109
108
|
float x;
|
|
@@ -114,7 +113,7 @@ struct BVHPackedNodeHalf
|
|
|
114
113
|
};
|
|
115
114
|
|
|
116
115
|
struct BVH
|
|
117
|
-
{
|
|
116
|
+
{
|
|
118
117
|
BVHPackedNodeHalf* node_lowers;
|
|
119
118
|
BVHPackedNodeHalf* node_uppers;
|
|
120
119
|
|
|
@@ -124,31 +123,22 @@ struct BVH
|
|
|
124
123
|
|
|
125
124
|
int max_depth;
|
|
126
125
|
int max_nodes;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
int num_nodes;
|
|
127
|
+
|
|
128
|
+
// pointer (CPU or GPU) to a single integer index in node_lowers, node_uppers
|
|
129
|
+
// representing the root of the tree, this is not always the first node
|
|
130
|
+
// for bottom-up builders
|
|
131
|
+
int* root;
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
int
|
|
133
|
+
// item bounds are not owned by the BVH but by the caller
|
|
134
|
+
vec3* item_lowers;
|
|
135
|
+
vec3* item_uppers;
|
|
136
|
+
int num_items;
|
|
135
137
|
|
|
138
|
+
// cuda context
|
|
136
139
|
void* context;
|
|
137
140
|
};
|
|
138
141
|
|
|
139
|
-
BVH bvh_create(const bounds3* bounds, int num_bounds);
|
|
140
|
-
|
|
141
|
-
void bvh_destroy_host(BVH& bvh);
|
|
142
|
-
void bvh_destroy_device(BVH& bvh);
|
|
143
|
-
|
|
144
|
-
void bvh_refit_host(BVH& bvh, const bounds3* bounds);
|
|
145
|
-
void bvh_refit_device(BVH& bvh, const bounds3* bounds);
|
|
146
|
-
|
|
147
|
-
// copy host BVH to device
|
|
148
|
-
BVH bvh_clone(void* context, const BVH& bvh_host);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
142
|
CUDA_CALLABLE inline BVHPackedNodeHalf make_node(const vec3& bound, int child, bool leaf)
|
|
153
143
|
{
|
|
154
144
|
BVHPackedNodeHalf n;
|
|
@@ -161,7 +151,7 @@ CUDA_CALLABLE inline BVHPackedNodeHalf make_node(const vec3& bound, int child, b
|
|
|
161
151
|
return n;
|
|
162
152
|
}
|
|
163
153
|
|
|
164
|
-
// variation of make_node through volatile pointers used in
|
|
154
|
+
// variation of make_node through volatile pointers used in build_hierarchy
|
|
165
155
|
CUDA_CALLABLE inline void make_node(volatile BVHPackedNodeHalf* n, const vec3& bound, int child, bool leaf)
|
|
166
156
|
{
|
|
167
157
|
n->x = bound[0];
|
|
@@ -210,7 +200,7 @@ CUDA_CALLABLE inline BVH bvh_get(uint64_t id)
|
|
|
210
200
|
CUDA_CALLABLE inline int bvh_get_num_bounds(uint64_t id)
|
|
211
201
|
{
|
|
212
202
|
BVH bvh = bvh_get(id);
|
|
213
|
-
return bvh.
|
|
203
|
+
return bvh.num_items;
|
|
214
204
|
}
|
|
215
205
|
|
|
216
206
|
|
|
@@ -219,11 +209,20 @@ CUDA_CALLABLE inline int bvh_get_num_bounds(uint64_t id)
|
|
|
219
209
|
struct bvh_query_t
|
|
220
210
|
{
|
|
221
211
|
CUDA_CALLABLE bvh_query_t()
|
|
212
|
+
: bvh(),
|
|
213
|
+
stack(),
|
|
214
|
+
count(0),
|
|
215
|
+
is_ray(false),
|
|
216
|
+
input_lower(),
|
|
217
|
+
input_upper(),
|
|
218
|
+
bounds_nr(0)
|
|
219
|
+
{}
|
|
220
|
+
|
|
221
|
+
// Required for adjoint computations.
|
|
222
|
+
CUDA_CALLABLE inline bvh_query_t& operator+=(const bvh_query_t& other)
|
|
222
223
|
{
|
|
224
|
+
return *this;
|
|
223
225
|
}
|
|
224
|
-
CUDA_CALLABLE bvh_query_t(int)
|
|
225
|
-
{
|
|
226
|
-
} // for backward pass
|
|
227
226
|
|
|
228
227
|
BVH bvh;
|
|
229
228
|
|
|
@@ -256,17 +255,8 @@ CUDA_CALLABLE inline bvh_query_t bvh_query(
|
|
|
256
255
|
query.bvh = bvh;
|
|
257
256
|
query.is_ray = is_ray;
|
|
258
257
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (bvh.num_nodes == 0)
|
|
262
|
-
{
|
|
263
|
-
query.count = 0;
|
|
264
|
-
return query;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// optimization: make the latest
|
|
268
|
-
|
|
269
|
-
query.stack[0] = bvh.root;
|
|
258
|
+
// optimization: make the latest
|
|
259
|
+
query.stack[0] = *bvh.root;
|
|
270
260
|
query.count = 1;
|
|
271
261
|
query.input_lower = lower;
|
|
272
262
|
query.input_upper = upper;
|
|
@@ -421,17 +411,19 @@ CUDA_CALLABLE inline void adj_bvh_query_next(bvh_query_t& query, int& index, bvh
|
|
|
421
411
|
|
|
422
412
|
}
|
|
423
413
|
|
|
414
|
+
CUDA_CALLABLE bool bvh_get_descriptor(uint64_t id, BVH& bvh);
|
|
415
|
+
CUDA_CALLABLE void bvh_add_descriptor(uint64_t id, const BVH& bvh);
|
|
416
|
+
CUDA_CALLABLE void bvh_rem_descriptor(uint64_t id);
|
|
424
417
|
|
|
418
|
+
#if !__CUDA_ARCH__
|
|
425
419
|
|
|
420
|
+
void bvh_destroy_host(wp::BVH& bvh);
|
|
421
|
+
void bvh_refit_host(wp::BVH& bvh);
|
|
426
422
|
|
|
427
|
-
|
|
428
|
-
void
|
|
429
|
-
void bvh_rem_descriptor(uint64_t id);
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
423
|
+
void bvh_destroy_device(wp::BVH& bvh);
|
|
424
|
+
void bvh_refit_device(uint64_t id);
|
|
434
425
|
|
|
426
|
+
#endif
|
|
435
427
|
|
|
436
428
|
} // namespace wp
|
|
437
429
|
|