pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

wip/openvdb: Update from 8.0.0 to 8.1.0.



Module Name:	pkgsrc-wip
Committed By:	Paul Ripke <stix%stix.id.au@localhost>
Pushed By:	stix
Date:		Sun Aug 15 17:53:11 2021 +1000
Changeset:	e4eebac7a67e584bc21b2e943d21baf5846f41b7

Modified Files:
	openvdb/Makefile
	openvdb/PLIST
	openvdb/distinfo
Added Files:
	openvdb/patches/patch-cmake_FindTBB.cmake
	openvdb/patches/patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Rasterize__Points.cc
	openvdb/patches/patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Sample__Points.cc
	openvdb/patches/patch-openvdb_openvdb_CMakeLists.txt
	openvdb/patches/patch-openvdb_openvdb_cmd_openvdb__render.cc
	openvdb/patches/patch-openvdb_openvdb_io_Queue.cc
	openvdb/patches/patch-openvdb_openvdb_math_Coord.h
	openvdb/patches/patch-openvdb_openvdb_points_PointSample.h
	openvdb/patches/patch-openvdb_openvdb_tools_Composite.h
	openvdb/patches/patch-openvdb_openvdb_tools_Diagnostics.h
	openvdb/patches/patch-openvdb_openvdb_tools_Filter.h
	openvdb/patches/patch-openvdb_openvdb_tools_GridOperators.h
	openvdb/patches/patch-openvdb_openvdb_tools_LevelSetMeasure.h
	openvdb/patches/patch-openvdb_openvdb_tools_LevelSetTracker.h
	openvdb/patches/patch-openvdb_openvdb_tools_MeshToVolume.h
	openvdb/patches/patch-openvdb_openvdb_tools_Morphology.h
	openvdb/patches/patch-openvdb_openvdb_tools_ParticlesToLevelSet.h
	openvdb/patches/patch-openvdb_openvdb_tools_PointAdvect.h
	openvdb/patches/patch-openvdb_openvdb_tools_PointIndexGrid.h
	openvdb/patches/patch-openvdb_openvdb_tools_PointPartitioner.h
	openvdb/patches/patch-openvdb_openvdb_tools_PointsToMask.h
	openvdb/patches/patch-openvdb_openvdb_tools_VolumeAdvect.h
	openvdb/patches/patch-openvdb_openvdb_tools_VolumeToMesh.h
	openvdb/patches/patch-openvdb_openvdb_unittest_TestCoord.cc
	openvdb/patches/patch-openvdb_openvdb_unittest_TestFile.cc
	openvdb/patches/patch-openvdb_openvdb_unittest_TestUtil.cc
	openvdb/patches/patch-openvdb_openvdb_unittest_TestValueAccessor.cc
	openvdb/patches/patch-openvdb_openvdb_util_Threading.h

Log Message:
wip/openvdb: Update from 8.0.0 to 8.1.0.

Also patch support for tbb 2021.3.

Version 8.1.0 - June 11, 2021

- As of this release, support for grid ABI=5 has been removed.

New features:

- Added tools::erodeActiveValues, to match the existing
  tools::dilateActiveValues. New erosion tools support all tile policies and
  edge/vertex neighbor patterns.
- Added support for automatic filtering of active tiles in Filter by setting
  Filter::setProcessTiles. Active tiles are densified on demand, only when
  necessary.
- Added tools::visitNodesDepthFirst and tools::DepthFirstNodeVisitor which
  visit nodes in a tree or sub-tree in single-threaded depth-first order.
- Significant performance improvements to AX volume kernels, primarily due to
  improved vectorization. Performance scales depending on the available host
  CPU instruction set and scalability of the AX kernel. Trivial assignments
  profile upwards of 3x faster on AVX.
- Introduced Active Tile Streaming for volumes kernels. AX can now dynamically
  expand and collapse active nodes at all levels of a VDB tree on demand,
  switching on or off by checking the spatial access pattern of AX programs.
- Added tools::countActiveVoxels() for multi-threaded counting of active
  voxels, optionally by bounding box. The Tree::activeVoxelCount() method now
  uses this implementation.
- Added tools::memUsage() for multi-threaded counting of bytes of memory used.
  The Tree::memUsage() method now uses this implementation.
- Added tools::SumMergeOp that uses a parallel breadth-first algorithm to
  accelerate summing grids.

Improvements:

- Significant performance improvements to large dilations with
  tools::dilateActiveValues. Performance gains will improve relative to
  increases in the inputs size and dilation scheme.
- Added an optional argument to Tree::topologyUnion which preserves active
  tiles on the destination tree should they overlap leaf nodes from the source
  tree.
- Reduced the time spent in the hot path of initialize and uninitialize by
  leveraging atomics with double-checked locks. [Contributed by Ben FrantzDale]
- Extended DynamicNodeManager to allow for use with a const tree.
- Replace tbb::mutex with std::mutex and tbb::atomic with std::atomic as these
  have now been removed in TBB 2021. [Contributed by Ben FrantzDale].
- Significant performance improvements to tools::activate and tools::deactivate
  through use of the DynamicNodeManager to parallelize tile processing.
- Added degree() and radians() AX helper functions for converting radians to
  degrees and vice versa, respectively.
- Added adjoint(), cofactor() and inverse() AX matrix functions.
- Added sort(), argsort(), isfinite(), isinf() and isnan() AX utility and math
  functions.
- Added Vec4 argument support to normalize() AX function.
- Removed unused int16 AX modulo function signatures.
- Refactored the backend AX representation of strings with SSO support and
  heap allocation.
- Added new methods on the VolumeExecutable to control active tile streaming
  and node execution levels
- The deletepoint() AX function is now natively supported by the PointExecutable
- vdb_view: Fixed a bug which wouldn't reset the camera speed on focus
- vdb_view: Improved the drawing of PointDataGrids
- vdb_view: Improved the exception handling of BufferObjects and added support
  for drawing an array without index values

Bug Fixes:

- Fix a memory leak in AttributeArray when delayed-loading is disabled.
- Fixed a crash in OpenVDB AX when declaring arrays with non-scalar elements
  (unsupported) i.e. {"foo", 1, 2}, {1, {1,2}, 3} etc.
- Fixed a bug in OpenVDB AX which would cause an error when multiplying a vec3
  by a mat4.
- In OpenVDB AX, improved the error message produced when attempting to use a
  matrix literal (i.e. {1,2,3...}) in a binary expression (this is invalid but
  would previously print out bad IR).
- Fixed a non-deterministic failure in the TestStreamCompression unit test.
- Use copy-by-reference for the operator in a DynamicNodeManager to fix a
  performance regression.
- tools::deactivate now also works with a MaskTree.
- Fixed a memory leak in the OpenVDB AX parser
- Fixed an occurrence of undefined behavior in the OpenVDB AX visitor
- Fixed some memory leaks in the OpenVDB and OpenVDB AX unit tests
- Fixed a bug in AX which could cause string allocations in loops to overflow
  the stack
- Fixed a bug where the ValueOff iterator for the AX VolumeExecutable could
  remove child branches of a VDB tree.
- Fixed a crash in the AX Houdini SOP with an empty PointDataGrid input.
- Fixed all cases where PointIndex and PointData aliases were used instead of
  a templated type. [Reported by Karl Marrett]
- Fixed a crash when calling openvdb::points::pointOffsets with an empty
  PointDataGrid input.
- Add missing 8-bit and 16-bit attribute type registration.

API changes:

- Restructured the internals of Morphology.h and moved tools::activate and
  tools::deactivate to a new header, Activate.h.
- Deprecated tools::dilateVoxels and tools::erodeVoxels in favour of new
  morphology methods.
- The tools::Film class no longer has a saveExr method in any build
  configuration. Sample code for saving exrs from this object can be found in
  the command line render tool.
- Added ability to run tools::activate and tools::deactivate single-threaded.

Houdini:

- Updated the VDB Activate SOP and others to use the multi-threaded
  implementation for voxel dilation, providing a significant performance
  increase.
- Introduced the VDB AX SOP which provides an interface for running OpenVDB AX
  code in Houdini on VDB grids.
- Updated the VDB Smooth SOP to support the filtering of active tiles.
- Fixed a parameter warning in VDB AX SOP.
- Transfer Surface Attributes in Convert VDB SOP could use uninitialized
  memory.
- VDB Activate SOP now uses the multi-threaded tools::deactivate for much
  faster performance.
- Improved the formatting and updated the OpenVDB AX SOPs help card.
- The AX SOP utilizes the new Active Tile Streaming feature for Volumes. Grids
  will only be densified in areas where unique values are created.
- VDB Activate SOP dilation will affect tiles, changing its behavior from
  previous versions, but producing a more expected result.
- VDB Activate SOP has a world space dilation option.
- Introduced the VDB Merge SOP that merges multiple grids in parallel and is
  faster and more convenient to use than the VDB Combine SOP.
- Fix a bug where the VDB Rebuild SDF was not preserving metadata from the
  input grid.
- Fix a bug in VDB Resample SOP where input transform was not being used for
  voxel size and voxel scale transform modes.

Build:

- Dependency on OpenEXR's Half implementation has been removed from the core
  library by naturalizing the implementation into openvdb::math. This is fully
  bitwise compatible, but may require switching Half references to math::Half.
  The USE_IMATH_HALF build configuration can be used to switch back to OpenEXR
  based half.
- Blosc, Log4cplus, IlmBase, OpenEXR and TBB find modules now configure
  release and debug library variants. [Reported by Matthew Cong]
- Fixed an issue where FindBlosc wouldn't add zstd as a dep in non static
  builds BLOSC_USE_EXTERNAL_SOURCES.
- Fixed Log4cplus interface language and missing interface libraries on Win32.
- Removed Jemalloc and Tbbmalloc logic from the core library builds.
- The variable CMAKE_MSVC_RUNTIME_LIBRARY is no longer set by the OpenVDB
  CMake. If CMAKE_MSVC_RUNTIME_LIBRARY is not explicitly provided, OpenVDB
  configures the static library with /MT(d) and the dynamic library with
  /MD(d). [Reported by Jérémie Dumas]
- Added support for ABI=9 and a CMake option OPENVDB_USE_FUTURE_ABI_9 to use
  it without errors.
- The value of CONCURRENT_MALLOC is now respected when building the vdb_ax
  command line binary.
- Added an option OPENVDB_ENABLE_UNINSTALL to allow the toggling of the
  uninstall build target. [Contributed by Jérémie Dumas]
- Improved the behavior of locating static zlib libraries when
  USE_STATIC_DEPENDENCIES is enabled.
- Fixed an issue where extra hboost libraries could not be found when building
  against Houdini 18.5 on Windows.
- Build fixes to OpenVDB AX for LLVM 12.
- Re-introduced the OPENVDB_DEPRECATED macro with an additional option that
  takes a message. Added support to disable deprecations throughout OpenVDB by
  defining OPENVDB_NO_DEPRECATION_WARNINGS
- Added an optional OPENVDB_TESTS variable to easily build a subset of the
  unit tests.
- Fixed various incorrect RPATH directory paths in CMake (introduced in 8.0.1)
  [Contributed by Ignacio Vizzo].
- Removed some unnecessary CMake for vdb_view
- The Windows defines NOMINMAX and _USE_MATH_DEFINES are now provided in
  Platform.h.
- Moved the logic from PlatformConfig.h into Platform.h.
- The version.h header is now an auto generated header (version.h.in)
  populated by CMake. The OpenVDB Version and ABI defines are computed from
  the installation settings. Importantly, the value of
  OPENVDB_ABI_VERSION_NUMBER now always matches the version used at build time.
- Added OPENVDB_USE_HALF, OPENVDB_USE_BLOSC and OPENVDB_USE_ZLIB as publicly
  available defines in version.h. These will be defined depending on the
  settings used to build OpenVDB.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=e4eebac7a67e584bc21b2e943d21baf5846f41b7

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 openvdb/Makefile                                   |   6 +-
 openvdb/PLIST                                      |   8 +-
 openvdb/distinfo                                   |  36 ++++-
 openvdb/patches/patch-cmake_FindTBB.cmake          |  50 +++++++
 ...vdb__houdini_SOP__OpenVDB__Rasterize__Points.cc |  33 +++++
 ...penvdb__houdini_SOP__OpenVDB__Sample__Points.cc |  67 +++++++++
 .../patches/patch-openvdb_openvdb_CMakeLists.txt   |  15 ++
 .../patch-openvdb_openvdb_cmd_openvdb__render.cc   |  38 +++++
 openvdb/patches/patch-openvdb_openvdb_io_Queue.cc  | 162 +++++++++++++++++++++
 openvdb/patches/patch-openvdb_openvdb_math_Coord.h |  17 +++
 .../patch-openvdb_openvdb_points_PointSample.h     |  36 +++++
 .../patch-openvdb_openvdb_tools_Composite.h        |  15 ++
 .../patch-openvdb_openvdb_tools_Diagnostics.h      |  72 +++++++++
 .../patches/patch-openvdb_openvdb_tools_Filter.h   |  52 +++++++
 .../patch-openvdb_openvdb_tools_GridOperators.h    |  40 +++++
 .../patch-openvdb_openvdb_tools_LevelSetMeasure.h  |  47 ++++++
 .../patch-openvdb_openvdb_tools_LevelSetTracker.h  |  55 +++++++
 .../patch-openvdb_openvdb_tools_MeshToVolume.h     |  63 ++++++++
 .../patch-openvdb_openvdb_tools_Morphology.h       |  25 ++++
 ...tch-openvdb_openvdb_tools_ParticlesToLevelSet.h |  58 ++++++++
 .../patch-openvdb_openvdb_tools_PointAdvect.h      |  50 +++++++
 .../patch-openvdb_openvdb_tools_PointIndexGrid.h   |  24 +++
 .../patch-openvdb_openvdb_tools_PointPartitioner.h |  25 ++++
 .../patch-openvdb_openvdb_tools_PointsToMask.h     |  39 +++++
 .../patch-openvdb_openvdb_tools_VolumeAdvect.h     |  39 +++++
 .../patch-openvdb_openvdb_tools_VolumeToMesh.h     |  25 ++++
 .../patch-openvdb_openvdb_unittest_TestCoord.cc    |  18 +++
 .../patch-openvdb_openvdb_unittest_TestFile.cc     |  56 +++++++
 .../patch-openvdb_openvdb_unittest_TestUtil.cc     |  15 ++
 ...h-openvdb_openvdb_unittest_TestValueAccessor.cc |  78 ++++++++++
 .../patches/patch-openvdb_openvdb_util_Threading.h |  58 ++++++++
 31 files changed, 1314 insertions(+), 8 deletions(-)

diffs:
diff --git a/openvdb/Makefile b/openvdb/Makefile
index 1626a59ab7..4dcfd30018 100644
--- a/openvdb/Makefile
+++ b/openvdb/Makefile
@@ -1,7 +1,7 @@
 # $NetBSD$
 
 DISTNAME=	openvdb-${PKGVERSION}
-PKGVERSION=	8.0.0
+PKGVERSION=	8.1.0
 CATEGORIES=	devel
 MASTER_SITES=	${MASTER_SITE_GITHUB:=AcademySoftwareFoundation/}
 GITHUB_PROJECT=	openvdb
@@ -22,10 +22,10 @@ pre-configure:
 	cd ${WRKSRC} && mkdir build
 
 .include "../../devel/blosc/buildlink3.mk"
-.include "../../graphics/openexr/buildlink3.mk"
-.include "../../graphics/ilmbase/buildlink3.mk"
 .include "../../devel/boost-headers/buildlink3.mk"
 .include "../../devel/boost-libs/buildlink3.mk"
 .include "../../devel/jemalloc/buildlink3.mk"
+.include "../../graphics/openexr/buildlink3.mk"
+.include "../../math/imath/buildlink3.mk"
 .include "../../parallel/threadingbuildingblocks/buildlink3.mk"
 .include "../../mk/bsd.pkg.mk"
diff --git a/openvdb/PLIST b/openvdb/PLIST
index e32f86557e..7a67c457cb 100644
--- a/openvdb/PLIST
+++ b/openvdb/PLIST
@@ -22,6 +22,8 @@ include/openvdb/math/ConjGradient.h
 include/openvdb/math/Coord.h
 include/openvdb/math/DDA.h
 include/openvdb/math/FiniteDifference.h
+include/openvdb/math/Half.h
+include/openvdb/math/HalfLimits.h
 include/openvdb/math/LegacyFrustum.h
 include/openvdb/math/Maps.h
 include/openvdb/math/Mat.h
@@ -59,9 +61,11 @@ include/openvdb/points/PointMove.h
 include/openvdb/points/PointSample.h
 include/openvdb/points/PointScatter.h
 include/openvdb/points/StreamCompression.h
+include/openvdb/tools/Activate.h
 include/openvdb/tools/ChangeBackground.h
 include/openvdb/tools/Clip.h
 include/openvdb/tools/Composite.h
+include/openvdb/tools/Count.h
 include/openvdb/tools/Dense.h
 include/openvdb/tools/DenseSparseTools.h
 include/openvdb/tools/Diagnostics.h
@@ -86,6 +90,7 @@ include/openvdb/tools/Merge.h
 include/openvdb/tools/MeshToVolume.h
 include/openvdb/tools/Morphology.h
 include/openvdb/tools/MultiResGrid.h
+include/openvdb/tools/NodeVisitor.h
 include/openvdb/tools/ParticleAtlas.h
 include/openvdb/tools/ParticlesToLevelSet.h
 include/openvdb/tools/PointAdvect.h
@@ -127,6 +132,7 @@ include/openvdb/util/Name.h
 include/openvdb/util/NodeMasks.h
 include/openvdb/util/NullInterrupter.h
 include/openvdb/util/PagedArray.h
+include/openvdb/util/Threading.h
 include/openvdb/util/Util.h
 include/openvdb/util/logging.h
 include/openvdb/version.h
@@ -143,5 +149,5 @@ lib/cmake/OpenVDB/OpenVDBMayaSetup.cmake
 lib/cmake/OpenVDB/OpenVDBUtils.cmake
 lib/libopenvdb.a
 lib/libopenvdb.so
-lib/libopenvdb.so.8.0
+lib/libopenvdb.so.8.1
 lib/libopenvdb.so.${PKGVERSION}
diff --git a/openvdb/distinfo b/openvdb/distinfo
index 5c09f6b9d9..2e5c42906b 100644
--- a/openvdb/distinfo
+++ b/openvdb/distinfo
@@ -1,6 +1,34 @@
 $NetBSD$
 
-SHA1 (openvdb-8.0.0.tar.gz) = 24dacda69973601271e6799ab43f6b9ebc06d0a4
-RMD160 (openvdb-8.0.0.tar.gz) = e524ad28957fdb1ffd7a88585ad6c9ef5ebb0603
-SHA512 (openvdb-8.0.0.tar.gz) = b26dea41e5305bbe023362241b82dda7e168f8df9526270e6b214f8442ce7e2135889d79a1944928478ae1a2b24866381b3be4d2d1af7a5726e39724055a6e78
-Size (openvdb-8.0.0.tar.gz) = 2285328 bytes
+SHA1 (openvdb-8.1.0.tar.gz) = 04b37736a8f3dbddcb7e42c3908ff9645868bf8d
+RMD160 (openvdb-8.1.0.tar.gz) = 307b60cc2de21c74ed8e5a45a23a57a4c51fc78e
+SHA512 (openvdb-8.1.0.tar.gz) = 081ccedb122ff9bd73e0cd7ff083ad0ff0165e0cf6305187edcbe90ff12f01ec085c91ad5c52c53596035e0c2afd5b8801e6c00374b0fc4b0cc111f5c7f37eb5
+Size (openvdb-8.1.0.tar.gz) = 2619432 bytes
+SHA1 (patch-cmake_FindTBB.cmake) = 4e5dee93840c8a1d8ce31583c6e875c7c7180268
+SHA1 (patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Rasterize__Points.cc) = d64161cac2347281e3b3dbf8ab34d38a3f92caa1
+SHA1 (patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Sample__Points.cc) = 1f185f9c4e9c32fffc27053a32294723d2364fb0
+SHA1 (patch-openvdb_openvdb_CMakeLists.txt) = 95068c5079daf3b285ed15d10dda2224042d3f17
+SHA1 (patch-openvdb_openvdb_cmd_openvdb__render.cc) = 5d2167a5c14fe5360f26dbcaca9f09ce94dabb23
+SHA1 (patch-openvdb_openvdb_io_Queue.cc) = 3a02113c6b07648af1b661c675212cd0790b2c86
+SHA1 (patch-openvdb_openvdb_math_Coord.h) = d261d2bf4c00f2cdf14b78f02f43d70c51761d99
+SHA1 (patch-openvdb_openvdb_points_PointSample.h) = 6785dc257378446b1caa95b04be1e5db10756b4d
+SHA1 (patch-openvdb_openvdb_tools_Composite.h) = c0bd2fd327682c49291933449b15716ae097958d
+SHA1 (patch-openvdb_openvdb_tools_Diagnostics.h) = 4f7ce9c442ea0e902b454467b7b03d75966abfd3
+SHA1 (patch-openvdb_openvdb_tools_Filter.h) = dd37877e5a7a1583fad2ed353bc4a8af657ef408
+SHA1 (patch-openvdb_openvdb_tools_GridOperators.h) = eac78c96cf36d2e856bc591a8adafc0b5c7e8986
+SHA1 (patch-openvdb_openvdb_tools_LevelSetMeasure.h) = 9c62e8fb16cf54ebf507315a1fe90af882cae4d8
+SHA1 (patch-openvdb_openvdb_tools_LevelSetTracker.h) = 1bad499c1b3b6cb66805455f5cba761fa0a774dd
+SHA1 (patch-openvdb_openvdb_tools_MeshToVolume.h) = b47f5ac643ceb9c32863a70bf9e5728b4adbe99f
+SHA1 (patch-openvdb_openvdb_tools_Morphology.h) = c9fed6e406035593c3c8212307fa3a689038c03a
+SHA1 (patch-openvdb_openvdb_tools_ParticlesToLevelSet.h) = ffeba2704012065592dcb29e38e8d0933348503e
+SHA1 (patch-openvdb_openvdb_tools_PointAdvect.h) = b74f2df8d0f41b6ad3c5e7a5fb4f49b4d7da49bb
+SHA1 (patch-openvdb_openvdb_tools_PointIndexGrid.h) = 113af065622c8d4cca89eb606561cc7888342acb
+SHA1 (patch-openvdb_openvdb_tools_PointPartitioner.h) = ce7b7ca3ccead1b2a31f4cc0e35cb22e11eee6e0
+SHA1 (patch-openvdb_openvdb_tools_PointsToMask.h) = 60c613290e4ea40e9c91954e566fe470e2b181ef
+SHA1 (patch-openvdb_openvdb_tools_VolumeAdvect.h) = 579fc1394af8c9fbbf156597bb027a4017968887
+SHA1 (patch-openvdb_openvdb_tools_VolumeToMesh.h) = 1d1615a4d1dc7c53be83e23b7a59aa3c987423e1
+SHA1 (patch-openvdb_openvdb_unittest_TestCoord.cc) = 3080befabc463c2ad18f3285248fac14eb3867e1
+SHA1 (patch-openvdb_openvdb_unittest_TestFile.cc) = a51f1fcd654b9072af8a21e4ba6d283939149b02
+SHA1 (patch-openvdb_openvdb_unittest_TestUtil.cc) = 064bf5cfb851983ca35c402d190a769e69b30729
+SHA1 (patch-openvdb_openvdb_unittest_TestValueAccessor.cc) = 3ef52d06678d52cc6699b3e73c82a2d997b700fb
+SHA1 (patch-openvdb_openvdb_util_Threading.h) = f688e5a1cbd13eecc25c07862dd31fdf3a1d5f7e
diff --git a/openvdb/patches/patch-cmake_FindTBB.cmake b/openvdb/patches/patch-cmake_FindTBB.cmake
new file mode 100644
index 0000000000..ba56f04bd4
--- /dev/null
+++ b/openvdb/patches/patch-cmake_FindTBB.cmake
@@ -0,0 +1,50 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- cmake/FindTBB.cmake.orig	2021-06-11 21:38:41.000000000 +0000
++++ cmake/FindTBB.cmake
+@@ -169,8 +169,22 @@ find_path(Tbb_INCLUDE_DIR tbb/tbb_stddef
+   PATH_SUFFIXES ${CMAKE_INSTALL_INCLUDEDIR} include
+ )
+ 
+-if(EXISTS "${Tbb_INCLUDE_DIR}/tbb/tbb_stddef.h")
+-  file(STRINGS "${Tbb_INCLUDE_DIR}/tbb/tbb_stddef.h"
++set(_tbb_version_file "${Tbb_INCLUDE_DIR}/tbb/tbb_stddef.h")
++
++if(NOT EXISTS ${_tbb_version_file})
++  # From TBB 2021, tbb_stddef is removed and the directory include/tbb is
++  # simply an alias for include/oneapi/tbb. Try and find the version header
++  # in oneapi/tbb
++  find_path(Tbb_INCLUDE_DIR oneapi/tbb/version.h
++    ${_FIND_TBB_ADDITIONAL_OPTIONS}
++    PATHS ${_TBB_INCLUDE_SEARCH_DIRS}
++    PATH_SUFFIXES ${CMAKE_INSTALL_INCLUDEDIR} include
++  )
++  set(_tbb_version_file "${Tbb_INCLUDE_DIR}/oneapi/tbb/version.h")
++endif()
++
++if(EXISTS ${_tbb_version_file})
++  file(STRINGS ${_tbb_version_file}
+     _tbb_version_major_string REGEX "#define TBB_VERSION_MAJOR "
+   )
+   string(REGEX REPLACE "#define TBB_VERSION_MAJOR" ""
+@@ -178,7 +192,7 @@ if(EXISTS "${Tbb_INCLUDE_DIR}/tbb/tbb_st
+   )
+   string(STRIP "${_tbb_version_major_string}" Tbb_VERSION_MAJOR)
+ 
+-  file(STRINGS "${Tbb_INCLUDE_DIR}/tbb/tbb_stddef.h"
++  file(STRINGS ${_tbb_version_file}
+      _tbb_version_minor_string REGEX "#define TBB_VERSION_MINOR "
+   )
+   string(REGEX REPLACE "#define TBB_VERSION_MINOR" ""
+@@ -192,6 +206,8 @@ if(EXISTS "${Tbb_INCLUDE_DIR}/tbb/tbb_st
+   set(Tbb_VERSION ${Tbb_VERSION_MAJOR}.${Tbb_VERSION_MINOR})
+ endif()
+ 
++unset(_tbb_version_file)
++
+ # ------------------------------------------------------------------------
+ #  Search for TBB lib DIR
+ # ------------------------------------------------------------------------
diff --git a/openvdb/patches/patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Rasterize__Points.cc b/openvdb/patches/patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Rasterize__Points.cc
new file mode 100644
index 0000000000..60c141aa2b
--- /dev/null
+++ b/openvdb/patches/patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Rasterize__Points.cc
@@ -0,0 +1,33 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Rasterize_Points.cc.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Rasterize_Points.cc
+@@ -20,6 +20,7 @@
+ #include <openvdb/tools/GridTransformer.h>
+ #include <openvdb/tools/PointIndexGrid.h>
+ #include <openvdb/tools/Prune.h>
++#include <openvdb/util/Threading.h>
+ 
+ #include <CH/CH_Manager.h>
+ #include <CVEX/CVEX_Context.h>
+@@ -786,7 +787,7 @@ struct ConstructCandidateVoxelMask
+         for (size_t n = range.begin(), N = range.end(); n != N; ++n) {
+ 
+             if (this->wasInterrupted()) {
+-                tbb::task::self().cancel_group_execution();
++                openvdb::util::cancelGroupExecution();
+                 break;
+             }
+ 
+@@ -2092,7 +2093,7 @@ struct RasterizePoints
+         for (size_t n = range.begin(), N = range.end(); n != N; ++n) {
+ 
+             if (this->wasInterrupted()) {
+-                tbb::task::self().cancel_group_execution();
++                openvdb::util::cancelGroupExecution();
+                 break;
+             }
+ 
diff --git a/openvdb/patches/patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Sample__Points.cc b/openvdb/patches/patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Sample__Points.cc
new file mode 100644
index 0000000000..23e5463d83
--- /dev/null
+++ b/openvdb/patches/patch-openvdb__houdini_openvdb__houdini_SOP__OpenVDB__Sample__Points.cc
@@ -0,0 +1,67 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Sample_Points.cc.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Sample_Points.cc
+@@ -16,13 +16,11 @@
+ #include <openvdb_houdini/SOP_NodeVDB.h>
+ 
+ #include <openvdb/tools/Interpolation.h>  // for box sampler
++#include <openvdb/util/Threading.h>
+ #include <openvdb/points/PointCount.h>
+ #include <openvdb/points/PointSample.h>
+ #include <openvdb/points/IndexFilter.h>   // for MultiGroupFilter
+ 
+-#include <tbb/tick_count.h>                 // for timing
+-#include <tbb/task.h>                       // for cancel
+-
+ #include <UT/UT_Interrupt.h>
+ #include <GA/GA_PageHandle.h>
+ #include <GA/GA_PageIterator.h>
+@@ -38,6 +36,7 @@
+ #include <stdexcept>
+ #include <string>
+ #include <vector>
++#include <chrono>
+ 
+ 
+ 
+@@ -327,7 +326,7 @@ public:
+     {
+ 
+         if (mInterrupter->wasInterrupted()) {
+-            tbb::task::self().cancel_group_execution();
++            openvdb::util::cancelGroupExecution();
+         }
+         const GridType& grid = UTvdbGridCast<GridType>(mGrid);
+         // task local grid accessor
+@@ -481,7 +480,7 @@ SOP_OpenVDB_Sample_Points::Cache::cookVD
+         int numUnnamedGrids = 0;
+ 
+         // start time
+-        tbb::tick_count time_start = tbb::tick_count::now();
++        auto time_start = std::chrono::steady_clock::now();
+         UT_AutoInterrupt progress("Sampling from VDB grids");
+ 
+         for (hvdb::VdbPrimCIterator it(bGdp, group); it; ++it) {
+@@ -707,14 +706,16 @@ SOP_OpenVDB_Sample_Points::Cache::cookVD
+         }
+ 
+         // timing: end time
+-        tbb::tick_count time_end = tbb::tick_count::now();
++        auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
++            std::chrono::steady_clock::now() - time_start);
++        const double seconds = double(duration.count()) / 1000.0;
+ 
+         if (verbose) {
+             std::cout << "Sampling " << nPoints + nVDBPoints << " points in "
+                       << numVectorGrids << " vector grid" << (numVectorGrids == 1 ? "" : "s")
+                       << " and " << numScalarGrids << " scalar grid"
+                           << (numScalarGrids == 1 ? "" : "s")
+-                      << " took " << (time_end - time_start).seconds() << " seconds\n "
++                      << " took " << seconds << " seconds\n "
+                       << (threaded ? "threaded" : "non-threaded") << std::endl;
+         }
+ 
diff --git a/openvdb/patches/patch-openvdb_openvdb_CMakeLists.txt b/openvdb/patches/patch-openvdb_openvdb_CMakeLists.txt
new file mode 100644
index 0000000000..063b87d932
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_CMakeLists.txt
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/CMakeLists.txt.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/CMakeLists.txt
+@@ -434,6 +434,7 @@ set(OPENVDB_LIBRARY_UTIL_INCLUDE_FILES
+   util/NodeMasks.h
+   util/NullInterrupter.h
+   util/PagedArray.h
++  util/Threading.h
+   util/Util.h
+ )
+ 
diff --git a/openvdb/patches/patch-openvdb_openvdb_cmd_openvdb__render.cc b/openvdb/patches/patch-openvdb_openvdb_cmd_openvdb__render.cc
new file mode 100644
index 0000000000..ff4118a7e4
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_cmd_openvdb__render.cc
@@ -0,0 +1,38 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/cmd/openvdb_render.cc.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/cmd/openvdb_render.cc
+@@ -19,7 +19,14 @@
+ #include <OpenEXR/ImfHeader.h>
+ #include <OpenEXR/ImfOutputFile.h>
+ #include <OpenEXR/ImfPixelType.h>
+-#include <tbb/task_scheduler_init.h>
++
++// tbb/task_scheduler_init.h was removed in TBB 2021. The best construct to swap
++// to is tbb/global_control (for executables). global_control was only officially
++// added in TBB 2019U4 but exists in 2018 as a preview feature. To avoid more
++// compile time branching (as we still support 2018), we use it in 2018 too by
++// enabling the below define.
++#define TBB_PREVIEW_GLOBAL_CONTROL
++#include <tbb/global_control.h>
+ #include <tbb/tick_count.h>
+ 
+ #include <algorithm>
+@@ -606,8 +613,12 @@ main(int argc, char *argv[])
+     }
+ 
+     try {
+-        tbb::task_scheduler_init schedulerInit(
+-            (opts.threads == 0) ? tbb::task_scheduler_init::automatic : opts.threads);
++        std::unique_ptr<tbb::global_control> control;
++        if (opts.threads > 0) {
++            // note, opts.threads == 0 means use all threads (default), so don't
++            // manually create a tbb::global_control in this case
++            control.reset(new tbb::global_control(tbb::global_control::max_allowed_parallelism, opts.threads));
++        }
+ 
+         openvdb::initialize();
+ 
diff --git a/openvdb/patches/patch-openvdb_openvdb_io_Queue.cc b/openvdb/patches/patch-openvdb_openvdb_io_Queue.cc
new file mode 100644
index 0000000000..8ce9eb9e9e
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_io_Queue.cc
@@ -0,0 +1,162 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/io/Queue.cc.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/io/Queue.cc
+@@ -5,20 +5,22 @@
+ /// @author Peter Cucka
+ 
+ #include "Queue.h"
+-
+ #include "File.h"
+ #include "Stream.h"
+-#include <openvdb/Exceptions.h>
+-#include <openvdb/util/logging.h>
++#include "openvdb/Exceptions.h"
++#include "openvdb/util/logging.h"
++
+ #include <tbb/concurrent_hash_map.h>
+-#include <tbb/task.h>
+-#include <tbb/tbb_thread.h> // for tbb::this_tbb_thread::sleep()
+-#include <tbb/tick_count.h>
++#include <tbb/task_arena.h>
++
++#include <thread>
+ #include <algorithm> // for std::max()
+ #include <atomic>
+ #include <iostream>
+ #include <map>
+ #include <mutex>
++#include <chrono>
++
+ 
+ namespace openvdb {
+ OPENVDB_USE_VERSION_NAMESPACE
+@@ -28,18 +30,19 @@ namespace io {
+ namespace {
+ 
+ // Abstract base class for queuable TBB tasks that adds a task completion callback
+-class Task: public tbb::task
++class Task
+ {
+ public:
+     Task(Queue::Id id): mId(id) {}
+-    ~Task() override {}
++    virtual ~Task() {}
+ 
+     Queue::Id id() const { return mId; }
+ 
+     void setNotifier(Queue::Notifier& notifier) { mNotify = notifier; }
++    virtual void execute() const = 0;
+ 
+ protected:
+-    void notify(Queue::Status status) { if (mNotify) mNotify(this->id(), status); }
++    void notify(Queue::Status status) const { if (mNotify) mNotify(this->id(), status); }
+ 
+ private:
+     Queue::Id mId;
+@@ -48,7 +51,7 @@ private:
+ 
+ 
+ // Queuable TBB task that writes one or more grids to a .vdb file or an output stream
+-class OutputTask: public Task
++class OutputTask : public Task
+ {
+ public:
+     OutputTask(Queue::Id id, const GridCPtrVec& grids, const Archive& archive,
+@@ -56,10 +59,10 @@ public:
+         : Task(id)
+         , mGrids(grids)
+         , mArchive(archive.copy())
+-        , mMetadata(metadata)
+-    {}
++        , mMetadata(metadata) {}
++    ~OutputTask() override {}
+ 
+-    tbb::task* execute() override
++    void execute() const override
+     {
+         Queue::Status status = Queue::FAILED;
+         try {
+@@ -69,10 +72,8 @@ public:
+             if (const char* msg = e.what()) {
+                 OPENVDB_LOG_ERROR(msg);
+             }
+-        } catch (...) {
+-        }
++        } catch (...) {}
+         this->notify(status);
+-        return nullptr; // no successor to this task
+     }
+ 
+ private:
+@@ -94,7 +95,6 @@ struct Queue::Impl
+     /// @todo Provide more information than just "succeeded" or "failed"?
+     using StatusMap = tbb::concurrent_hash_map<Queue::Id, Queue::Status>;
+ 
+-
+     Impl()
+         : mTimeout(Queue::DEFAULT_TIMEOUT)
+         , mCapacity(Queue::DEFAULT_CAPACITY)
+@@ -159,12 +159,15 @@ struct Queue::Impl
+ 
+     bool canEnqueue() const { return mNumTasks < Int64(mCapacity); }
+ 
+-    void enqueue(Task& task)
++    void enqueue(OutputTask& task)
+     {
+-        tbb::tick_count start = tbb::tick_count::now();
++        auto start = std::chrono::steady_clock::now();
+         while (!canEnqueue()) {
+-            tbb::this_tbb_thread::sleep(tbb::tick_count::interval_t(0.5/*sec*/));
+-            if ((tbb::tick_count::now() - start).seconds() > double(mTimeout)) {
++            std::this_thread::sleep_for(/*0.5s*/std::chrono::milliseconds(500));
++            auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
++                std::chrono::steady_clock::now() - start);
++            const double seconds = double(duration.count()) / 1000.0;
++            if (seconds > double(mTimeout)) {
+                 OPENVDB_THROW(RuntimeError,
+                     "unable to queue I/O task; " << mTimeout << "-second time limit expired");
+             }
+@@ -173,7 +176,10 @@ struct Queue::Impl
+             std::placeholders::_1, std::placeholders::_2);
+         task.setNotifier(notify);
+         this->setStatus(task.id(), Queue::PENDING);
+-        tbb::task::enqueue(task);
++
++        // get the global task arena
++        tbb::task_arena arena(tbb::task_arena::attach{});
++        arena.enqueue([task = std::move(task)] { task.execute(); });
+         ++mNumTasks;
+     }
+ 
+@@ -204,7 +210,7 @@ Queue::~Queue()
+     /// (e.g., by keeping a static registry of queues that also dispatches
+     /// or blocks notifications)?
+     while (mImpl->mNumTasks > 0) {
+-        tbb::this_tbb_thread::sleep(tbb::tick_count::interval_t(0.5/*sec*/));
++        std::this_thread::sleep_for(/*0.5s*/std::chrono::milliseconds(500));
+     }
+ }
+ 
+@@ -290,16 +296,8 @@ Queue::Id
+ Queue::writeGridVec(const GridCPtrVec& grids, const Archive& archive, const MetaMap& metadata)
+ {
+     const Queue::Id taskId = mImpl->mNextId++;
+-    // From the "GUI Thread" chapter in the TBB Design Patterns guide
+-    OutputTask* task =
+-        new(tbb::task::allocate_root()) OutputTask(taskId, grids, archive, metadata);
+-    try {
+-        mImpl->enqueue(*task);
+-    } catch (openvdb::RuntimeError&) {
+-        // Destroy the task if it could not be enqueued, then rethrow the exception.
+-        tbb::task::destroy(*task);
+-        throw;
+-    }
++    OutputTask task(taskId, grids, archive, metadata);
++    mImpl->enqueue(task);
+     return taskId;
+ }
+ 
diff --git a/openvdb/patches/patch-openvdb_openvdb_math_Coord.h b/openvdb/patches/patch-openvdb_openvdb_math_Coord.h
new file mode 100644
index 0000000000..73fc1e9c3b
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_math_Coord.h
@@ -0,0 +1,17 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/math/Coord.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/math/Coord.h
+@@ -13,8 +13,7 @@
+ #include "Math.h"
+ #include "Vec3.h"
+ 
+-namespace tbb { class split; } // forward declaration
+-
++#include <tbb/blocked_range.h> // for tbb::split
+ 
+ namespace openvdb {
+ OPENVDB_USE_VERSION_NAMESPACE
diff --git a/openvdb/patches/patch-openvdb_openvdb_points_PointSample.h b/openvdb/patches/patch-openvdb_openvdb_points_PointSample.h
new file mode 100644
index 0000000000..6ca5625a48
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_points_PointSample.h
@@ -0,0 +1,36 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/points/PointSample.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/points/PointSample.h
+@@ -10,8 +10,9 @@
+ #ifndef OPENVDB_POINTS_POINT_SAMPLE_HAS_BEEN_INCLUDED
+ #define OPENVDB_POINTS_POINT_SAMPLE_HAS_BEEN_INCLUDED
+ 
+-#include <openvdb/util/NullInterrupter.h>
+-#include <openvdb/tools/Interpolation.h>
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Threading.h"
++#include "openvdb/tools/Interpolation.h"
+ 
+ #include "PointDataGrid.h"
+ #include "PointAttribute.h"
+@@ -19,7 +20,6 @@
+ #include <sstream>
+ #include <type_traits>
+ 
+-
+ namespace openvdb {
+ OPENVDB_USE_VERSION_NAMESPACE
+ namespace OPENVDB_VERSION_NAME {
+@@ -299,7 +299,7 @@ private:
+             using TargetHandleT = AttributeWriteHandle<typename SamplerWrapperT::ValueType>;
+ 
+             if (util::wasInterrupted(interrupter)) {
+-                tbb::task::self().cancel_group_execution();
++                util::cancelGroupExecution();
+                 return;
+             }
+ 
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_Composite.h b/openvdb/patches/patch-openvdb_openvdb_tools_Composite.h
new file mode 100644
index 0000000000..72bf3cd9aa
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_Composite.h
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/Composite.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/Composite.h
+@@ -24,7 +24,6 @@
+ #include <tbb/parallel_for.h>
+ #include <tbb/parallel_reduce.h>
+ #include <tbb/task_group.h>
+-#include <tbb/task_scheduler_init.h>
+ 
+ #include <type_traits>
+ #include <functional>
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_Diagnostics.h b/openvdb/patches/patch-openvdb_openvdb_tools_Diagnostics.h
new file mode 100644
index 0000000000..0e4ca7cbf3
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_Diagnostics.h
@@ -0,0 +1,72 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/Diagnostics.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/Diagnostics.h
+@@ -11,14 +11,17 @@
+ #ifndef OPENVDB_TOOLS_DIAGNOSTICS_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_DIAGNOSTICS_HAS_BEEN_INCLUDED
+ 
+-#include <openvdb/Grid.h>
+-#include <openvdb/math/Math.h>
+-#include <openvdb/math/Vec3.h>
+-#include <openvdb/math/Stencils.h>
+-#include <openvdb/math/Operators.h>
+-#include <openvdb/tree/LeafManager.h>
++#include "openvdb/Grid.h"
++#include "openvdb/math/Math.h"
++#include "openvdb/math/Vec3.h"
++#include "openvdb/math/Stencils.h"
++#include "openvdb/math/Operators.h"
++#include "openvdb/tree/LeafManager.h"
++#include "openvdb/util/Threading.h"
++
+ #include <tbb/blocked_range.h>
+ #include <tbb/parallel_reduce.h>
++
+ #include <cmath> // for std::isnan(), std::isfinite()
+ #include <set>
+ #include <sstream>
+@@ -26,7 +29,6 @@
+ #include <type_traits>
+ #include <vector>
+ 
+-
+ namespace openvdb {
+ OPENVDB_USE_VERSION_NAMESPACE
+ namespace OPENVDB_VERSION_NAME {
+@@ -1160,13 +1162,13 @@ InactiveVoxelValues<TreeType>::operator(
+ {
+     typename TreeType::LeafNodeType::ValueOffCIter iter;
+ 
+-    for (size_t n = range.begin(); n < range.end() && !tbb::task::self().is_cancelled(); ++n) {
++    for (size_t n = range.begin(); n < range.end() && !util::isGroupExecutionCancelled(); ++n) {
+         for (iter = mLeafArray.leaf(n).cbeginValueOff(); iter; ++iter) {
+             mInactiveValues.insert(iter.getValue());
+         }
+ 
+         if (mInactiveValues.size() > mNumValues) {
+-            tbb::task::self().cancel_group_execution();
++            util::cancelGroupExecution();
+         }
+     }
+ }
+@@ -1250,14 +1252,14 @@ template<typename TreeType>
+ inline void
+ InactiveTileValues<TreeType>::operator()(IterRange& range)
+ {
+-    for (; range && !tbb::task::self().is_cancelled(); ++range) {
++    for (; range && !util::isGroupExecutionCancelled(); ++range) {
+         typename TreeType::ValueOffCIter iter = range.iterator();
+         for (; iter; ++iter) {
+             mInactiveValues.insert(iter.getValue());
+         }
+ 
+         if (mInactiveValues.size() > mNumValues) {
+-            tbb::task::self().cancel_group_execution();
++            util::cancelGroupExecution();
+         }
+     }
+ }
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_Filter.h b/openvdb/patches/patch-openvdb_openvdb_tools_Filter.h
new file mode 100644
index 0000000000..733db65dbb
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_Filter.h
@@ -0,0 +1,52 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/Filter.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/Filter.h
+@@ -14,21 +14,24 @@
+ #ifndef OPENVDB_TOOLS_FILTER_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_FILTER_HAS_BEEN_INCLUDED
+ 
+-#include <tbb/parallel_for.h>
+-#include <openvdb/Types.h>
+-#include <openvdb/math/Math.h>
+-#include <openvdb/math/Stencils.h>
+-#include <openvdb/math/Transform.h>
+-#include <openvdb/tree/NodeManager.h>
+-#include <openvdb/tree/LeafManager.h>
+-#include <openvdb/util/NullInterrupter.h>
+-#include <openvdb/util/Util.h>
+-#include <openvdb/Grid.h>
++#include "openvdb/Types.h"
++#include "openvdb/Grid.h"
++#include "openvdb/math/Math.h"
++#include "openvdb/math/Stencils.h"
++#include "openvdb/math/Transform.h"
++#include "openvdb/tree/NodeManager.h"
++#include "openvdb/tree/LeafManager.h"
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Util.h"
++#include "openvdb/util/Threading.h"
+ #include "Interpolation.h"
++
++#include <tbb/parallel_for.h>
++#include <tbb/concurrent_vector.h>
++
+ #include <algorithm> // for std::max()
+ #include <functional>
+ #include <type_traits>
+-#include <tbb/concurrent_vector.h>
+ 
+ namespace openvdb {
+ OPENVDB_USE_VERSION_NAMESPACE
+@@ -833,7 +836,7 @@ inline bool
+ Filter<GridT, MaskT, InterruptT>::wasInterrupted()
+ {
+     if (util::wasInterrupted(mInterrupter)) {
+-        tbb::task::self().cancel_group_execution();
++        util::cancelGroupExecution();
+         return true;
+     }
+     return false;
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_GridOperators.h b/openvdb/patches/patch-openvdb_openvdb_tools_GridOperators.h
new file mode 100644
index 0000000000..e3d1cfcb25
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_GridOperators.h
@@ -0,0 +1,40 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/GridOperators.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/GridOperators.h
+@@ -9,14 +9,15 @@
+ #ifndef OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
+ 
+-#include <openvdb/Grid.h>
+-#include <openvdb/math/Operators.h>
+-#include <openvdb/util/NullInterrupter.h>
+-#include <openvdb/tree/LeafManager.h>
+-#include <openvdb/tree/ValueAccessor.h>
++#include "openvdb/Grid.h"
++#include "openvdb/math/Operators.h"
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Threading.h"
++#include "openvdb/tree/LeafManager.h"
++#include "openvdb/tree/ValueAccessor.h"
+ #include "ValueTransformer.h" // for tools::foreach()
+-#include <tbb/parallel_for.h>
+ 
++#include <tbb/parallel_for.h>
+ 
+ namespace openvdb {
+ OPENVDB_USE_VERSION_NAMESPACE
+@@ -383,7 +384,9 @@ public:
+     /// TBB threads only!
+     void operator()(const typename LeafManagerT::LeafRange& range) const
+     {
+-        if (util::wasInterrupted(mInterrupt)) tbb::task::self().cancel_group_execution();
++        if (util::wasInterrupted(mInterrupt)) {
++            util::cancelGroupExecution();
++        }
+ 
+         for (typename LeafManagerT::LeafRange::Iterator leaf=range.begin(); leaf; ++leaf) {
+             for (typename OutLeafT::ValueOnIter value=leaf->beginValueOn(); value; ++value) {
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_LevelSetMeasure.h b/openvdb/patches/patch-openvdb_openvdb_tools_LevelSetMeasure.h
new file mode 100644
index 0000000000..c403196042
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_LevelSetMeasure.h
@@ -0,0 +1,47 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/LevelSetMeasure.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/LevelSetMeasure.h
+@@ -8,18 +8,21 @@
+ #ifndef OPENVDB_TOOLS_LEVELSETMEASURE_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_LEVELSETMEASURE_HAS_BEEN_INCLUDED
+ 
+-#include <openvdb/math/Math.h>
+-#include <openvdb/Types.h>
+-#include <openvdb/Grid.h>
+-#include <openvdb/tree/LeafManager.h>
+-#include <openvdb/tree/ValueAccessor.h>
+-#include <openvdb/math/FiniteDifference.h>
+-#include <openvdb/math/Operators.h>
+-#include <openvdb/math/Stencils.h>
+-#include <openvdb/util/NullInterrupter.h>
++#include "openvdb/Types.h"
++#include "openvdb/Grid.h"
++#include "openvdb/tree/LeafManager.h"
++#include "openvdb/tree/ValueAccessor.h"
++#include "openvdb/math/Math.h"
++#include "openvdb/math/FiniteDifference.h"
++#include "openvdb/math/Operators.h"
++#include "openvdb/math/Stencils.h"
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Threading.h"
++
+ #include <tbb/parallel_for.h>
+ #include <tbb/parallel_sort.h>
+ #include <tbb/parallel_invoke.h>
++
+ #include <type_traits>
+ 
+ namespace openvdb {
+@@ -329,7 +332,7 @@ inline bool
+ LevelSetMeasure<GridT, InterruptT>::checkInterrupter()
+ {
+     if (util::wasInterrupted(mInterrupter)) {
+-        tbb::task::self().cancel_group_execution();
++        util::cancelGroupExecution();
+         return false;
+     }
+     return true;
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_LevelSetTracker.h b/openvdb/patches/patch-openvdb_openvdb_tools_LevelSetTracker.h
new file mode 100644
index 0000000000..fc3f0cae62
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_LevelSetTracker.h
@@ -0,0 +1,55 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/LevelSetTracker.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/LevelSetTracker.h
+@@ -12,24 +12,26 @@
+ #ifndef OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED
+ 
+-#include <tbb/parallel_for.h>
+-#include <openvdb/Types.h>
+-#include <openvdb/math/Math.h>
+-#include <openvdb/math/FiniteDifference.h>
+-#include <openvdb/math/Operators.h>
+-#include <openvdb/math/Stencils.h>
+-#include <openvdb/math/Transform.h>
+-#include <openvdb/Grid.h>
+-#include <openvdb/util/NullInterrupter.h>
+-#include <openvdb/tree/ValueAccessor.h>
+-#include <openvdb/tree/LeafManager.h>
++#include "openvdb/Types.h"
++#include "openvdb/Grid.h"
++#include "openvdb/math/Math.h"
++#include "openvdb/math/FiniteDifference.h"
++#include "openvdb/math/Operators.h"
++#include "openvdb/math/Stencils.h"
++#include "openvdb/math/Transform.h"
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Threading.h"
++#include "openvdb/tree/ValueAccessor.h"
++#include "openvdb/tree/LeafManager.h"
+ #include "ChangeBackground.h"// for changeLevelSetBackground
+ #include "Morphology.h"//for dilateActiveValues
+ #include "Prune.h"// for pruneLevelSet
++
++#include <tbb/parallel_for.h>
++
+ #include <functional>
+ #include <type_traits>
+ 
+-
+ namespace openvdb {
+ OPENVDB_USE_VERSION_NAMESPACE
+ namespace OPENVDB_VERSION_NAME {
+@@ -383,7 +385,7 @@ LevelSetTracker<GridT, InterruptT>::
+ checkInterrupter()
+ {
+     if (util::wasInterrupted(mInterrupter)) {
+-        tbb::task::self().cancel_group_execution();
++        util::cancelGroupExecution();
+         return false;
+     }
+     return true;
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_MeshToVolume.h b/openvdb/patches/patch-openvdb_openvdb_tools_MeshToVolume.h
new file mode 100644
index 0000000000..bb060b5b14
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_MeshToVolume.h
@@ -0,0 +1,63 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/MeshToVolume.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/MeshToVolume.h
+@@ -16,12 +16,13 @@
+ #ifndef OPENVDB_TOOLS_MESH_TO_VOLUME_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_MESH_TO_VOLUME_HAS_BEEN_INCLUDED
+ 
+-#include <openvdb/Platform.h> // for OPENVDB_HAS_CXX11
+-#include <openvdb/Types.h>
+-#include <openvdb/math/FiniteDifference.h> // for GodunovsNormSqrd
+-#include <openvdb/math/Proximity.h> // for closestPointOnTriangleToPoint
+-#include <openvdb/util/NullInterrupter.h>
+-#include <openvdb/util/Util.h>
++#include "openvdb/Platform.h" // for OPENVDB_HAS_CXX11
++#include "openvdb/Types.h"
++#include "openvdb/math/FiniteDifference.h" // for GodunovsNormSqrd
++#include "openvdb/math/Proximity.h" // for closestPointOnTriangleToPoint
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Util.h"
++#include "openvdb/util/Threading.h"
+ 
+ #include "ChangeBackground.h"
+ #include "Prune.h" // for pruneInactive and pruneLevelSet
+@@ -33,7 +34,7 @@
+ #include <tbb/parallel_reduce.h>
+ #include <tbb/partitioner.h>
+ #include <tbb/task_group.h>
+-#include <tbb/task_scheduler_init.h>
++#include <tbb/task_arena.h>
+ 
+ #include <algorithm> // for std::sort()
+ #include <cmath> // for std::isfinite(), std::isnan()
+@@ -1132,7 +1133,7 @@ inline void
+ fillArray(ValueType* array, const ValueType val, const size_t length)
+ {
+     const auto grainSize = std::max<size_t>(
+-        length / tbb::task_scheduler_init::default_num_threads(), 1024);
++        length / tbb::this_task_arena::max_concurrency(), 1024);
+     const tbb::blocked_range<size_t> range(0, length, grainSize);
+     tbb::parallel_for(range, FillArray<ValueType>(array, val), tbb::simple_partitioner());
+ }
+@@ -1989,7 +1990,7 @@ public:
+         for (size_t n = range.begin(), N = range.end(); n < N; ++n) {
+ 
+             if (this->wasInterrupted()) {
+-                tbb::task::self().cancel_group_execution();
++                util::cancelGroupExecution();
+                 break;
+             }
+ 
+@@ -2143,7 +2144,7 @@ private:
+ 
+         while (!coordList.empty()) {
+             if (interrupter && interrupter->wasInterrupted()) {
+-                tbb::task::self().cancel_group_execution();
++                util::cancelGroupExecution();
+                 break;
+             }
+             for (Int32 pass = 0; pass < 1048576 && !coordList.empty(); ++pass) {
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_Morphology.h b/openvdb/patches/patch-openvdb_openvdb_tools_Morphology.h
new file mode 100644
index 0000000000..07460cc931
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_Morphology.h
@@ -0,0 +1,25 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/Morphology.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/Morphology.h
+@@ -24,7 +24,7 @@
+ #include "openvdb/tree/ValueAccessor.h"
+ #include "openvdb/tree/LeafManager.h"
+ 
+-#include <tbb/task_scheduler_init.h>
++#include <tbb/task_arena.h>
+ #include <tbb/enumerable_thread_specific.h>
+ #include <tbb/parallel_for.h>
+ 
+@@ -726,7 +726,7 @@ void Morphology<TreeType>::dilateVoxels(
+         }
+ 
+         // @note this grain size is used for optimal threading
+-        const size_t numThreads = size_t(tbb::task_scheduler_init::default_num_threads());
++        const size_t numThreads = size_t(tbb::this_task_arena::max_concurrency());
+         const size_t subTreeSize = math::Max(size_t(1), array.size()/(2*numThreads));
+ 
+         // perform recursive dilation to sub trees
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_ParticlesToLevelSet.h b/openvdb/patches/patch-openvdb_openvdb_tools_ParticlesToLevelSet.h
new file mode 100644
index 0000000000..c7e72c8b70
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_ParticlesToLevelSet.h
@@ -0,0 +1,58 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/ParticlesToLevelSet.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/ParticlesToLevelSet.h
+@@ -62,19 +62,23 @@
+ #ifndef OPENVDB_TOOLS_PARTICLES_TO_LEVELSET_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_PARTICLES_TO_LEVELSET_HAS_BEEN_INCLUDED
+ 
+-#include <tbb/parallel_reduce.h>
+-#include <tbb/blocked_range.h>
+-#include <openvdb/Types.h>
+-#include <openvdb/Grid.h>
+-#include <openvdb/math/Math.h>
+-#include <openvdb/math/Transform.h>
+-#include <openvdb/tree/LeafManager.h>
+-#include <openvdb/util/logging.h>
+-#include <openvdb/util/NullInterrupter.h>
++#include "openvdb/Types.h"
++#include "openvdb/Grid.h"
++#include "openvdb/math/Math.h"
++#include "openvdb/math/Transform.h"
++#include "openvdb/tree/LeafManager.h"
++#include "openvdb/util/logging.h"
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Threading.h"
++
+ #include "Composite.h" // for csgUnion()
+ #include "PointPartitioner.h"
+ #include "Prune.h"
+ #include "SignedFloodFill.h"
++
++#include <tbb/parallel_reduce.h>
++#include <tbb/blocked_range.h>
++
+ #include <functional>
+ #include <iostream>
+ #include <type_traits>
+@@ -738,7 +742,7 @@ private:
+         for (Coord c = lo; c.x() <= hi.x(); ++c.x()) {
+             //only check interrupter every 32'th scan in x
+             if (!(count++ & ((1<<5)-1)) && util::wasInterrupted(mParent.mInterrupter)) {
+-                tbb::task::self().cancel_group_execution();
++                util::cancelGroupExecution();
+                 return false;
+             }
+             const Real x2 = math::Pow2(c.x() - P[0]);
+@@ -804,7 +808,7 @@ private:
+         // Densely fill the remaining regions.
+         for (const auto& bbox: padding) {
+             if (util::wasInterrupted(mParent.mInterrupter)) {
+-                tbb::task::self().cancel_group_execution();
++                util::cancelGroupExecution();
+                 return false;
+             }
+             const Coord &bmin = bbox.min(), &bmax = bbox.max();
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_PointAdvect.h b/openvdb/patches/patch-openvdb_openvdb_tools_PointAdvect.h
new file mode 100644
index 0000000000..a9325f06f0
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_PointAdvect.h
@@ -0,0 +1,50 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/PointAdvect.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/PointAdvect.h
+@@ -10,16 +10,19 @@
+ #ifndef OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED
+ 
+-#include <openvdb/openvdb.h>
+-#include <openvdb/math/Math.h>             // min
+-#include <openvdb/Types.h>                 // Vec3 types and version number
+-#include <openvdb/Grid.h>                  // grid
+-#include <openvdb/util/NullInterrupter.h>
++#include "openvdb/openvdb.h"
++#include "openvdb/Types.h"                 // Vec3 types and version number
++#include "openvdb/Grid.h"                  // grid
++#include "openvdb/math/Math.h"             // min
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Threading.h"
+ #include "Interpolation.h"                 // sampling
+ #include "VelocityFields.h"                // VelocityIntegrator
++
+ #include <tbb/blocked_range.h>             // threading
+ #include <tbb/parallel_for.h>              // threading
+ #include <tbb/task.h>                      // for cancel
++
+ #include <vector>
+ 
+ 
+@@ -167,7 +170,7 @@ public:
+     void operator() (const tbb::blocked_range<size_t> &range) const
+     {
+         if (mInterrupter && mInterrupter->wasInterrupted()) {
+-            tbb::task::self().cancel_group_execution();
++            util::cancelGroupExecution();
+         }
+ 
+         VelocityFieldIntegrator  velField(*mVelGrid);
+@@ -307,7 +310,7 @@ public:
+     void operator() (const tbb::blocked_range<size_t> &range) const
+     {
+         if (mInterrupter && mInterrupter->wasInterrupted()) {
+-            tbb::task::self().cancel_group_execution();
++            util::cancelGroupExecution();
+         }
+ 
+         VelocityIntegratorType velField(*mVelGrid);
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_PointIndexGrid.h b/openvdb/patches/patch-openvdb_openvdb_tools_PointIndexGrid.h
new file mode 100644
index 0000000000..d569e2f4dd
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_PointIndexGrid.h
@@ -0,0 +1,24 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/PointIndexGrid.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/PointIndexGrid.h
+@@ -16,6 +16,7 @@
+ #ifndef OPENVDB_TOOLS_POINT_INDEX_GRID_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_POINT_INDEX_GRID_HAS_BEEN_INCLUDED
+ 
++#include "openvdb/util/Threading.h"
+ #include "PointPartitioner.h"
+ 
+ #include <openvdb/version.h>
+@@ -355,7 +356,7 @@ struct ValidPartitioningOp
+     void operator()(LeafT &leaf, size_t /*leafIndex*/) const
+     {
+         if ((*mHasChanged)) {
+-            tbb::task::self().cancel_group_execution();
++            util::cancelGroupExecution();
+             return;
+         }
+ 
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_PointPartitioner.h b/openvdb/patches/patch-openvdb_openvdb_tools_PointPartitioner.h
new file mode 100644
index 0000000000..c802be5267
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_PointPartitioner.h
@@ -0,0 +1,25 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/PointPartitioner.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/PointPartitioner.h
+@@ -23,7 +23,7 @@
+ 
+ #include <tbb/blocked_range.h>
+ #include <tbb/parallel_for.h>
+-#include <tbb/task_scheduler_init.h>
++#include <tbb/task_arena.h>
+ 
+ #include <algorithm>
+ #include <cmath> // for std::isfinite()
+@@ -764,7 +764,7 @@ inline void binAndSegment(
+     using IndexPairListMap = std::map<Coord, IndexPairListPtr>;
+     using IndexPairListMapPtr = std::shared_ptr<IndexPairListMap>;
+ 
+-    size_t numTasks = 1, numThreads = size_t(tbb::task_scheduler_init::default_num_threads());
++    size_t numTasks = 1, numThreads = size_t(tbb::this_task_arena::max_concurrency());
+     if (points.size() > (numThreads * 2)) numTasks = numThreads * 2;
+     else if (points.size() > numThreads) numTasks = numThreads;
+ 
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_PointsToMask.h b/openvdb/patches/patch-openvdb_openvdb_tools_PointsToMask.h
new file mode 100644
index 0000000000..81e3b2a07d
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_PointsToMask.h
@@ -0,0 +1,39 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/PointsToMask.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/PointsToMask.h
+@@ -46,14 +46,18 @@
+ #ifndef OPENVDB_TOOLS_POINTSTOMASK_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_POINTSTOMASK_HAS_BEEN_INCLUDED
+ 
++
++#include "openvdb/openvdb.h" // for MaskGrid
++#include "openvdb/Grid.h"
++#include "openvdb/Types.h"
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Threading.h"
++
+ #include <tbb/enumerable_thread_specific.h>
+ #include <tbb/parallel_for.h>
+ #include <tbb/parallel_reduce.h>
+ #include <tbb/blocked_range.h>
+-#include <openvdb/openvdb.h> // for MaskGrid
+-#include <openvdb/Grid.h>
+-#include <openvdb/Types.h>
+-#include <openvdb/util/NullInterrupter.h>
++
+ #include <vector>
+ 
+ 
+@@ -150,7 +154,7 @@ private:
+     bool interrupt() const
+     {
+         if (mInterrupter && util::wasInterrupted(mInterrupter)) {
+-            tbb::task::self().cancel_group_execution();
++            util::cancelGroupExecution();
+             return true;
+         }
+         return false;
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_VolumeAdvect.h b/openvdb/patches/patch-openvdb_openvdb_tools_VolumeAdvect.h
new file mode 100644
index 0000000000..eef7939abe
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_VolumeAdvect.h
@@ -0,0 +1,39 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/VolumeAdvect.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/VolumeAdvect.h
+@@ -13,15 +13,18 @@
+ #ifndef OPENVDB_TOOLS_VOLUME_ADVECT_HAS_BEEN_INCLUDED
+ #define OPENVDB_TOOLS_VOLUME_ADVECT_HAS_BEEN_INCLUDED
+ 
+-#include <tbb/parallel_for.h>
+-#include <openvdb/Types.h>
+-#include <openvdb/math/Math.h>
+-#include <openvdb/util/NullInterrupter.h>
++#include "openvdb/Types.h"
++#include "openvdb/math/Math.h"
++#include "openvdb/util/NullInterrupter.h"
++#include "openvdb/util/Threading.h"
+ #include "Interpolation.h"// for Sampler
+ #include "VelocityFields.h" // for VelocityIntegrator
+ #include "Morphology.h"//for dilateActiveValues
+ #include "Prune.h"// for prune
+ #include "Statistics.h" // for extrema
++
++#include <tbb/parallel_for.h>
++
+ #include <functional>
+ 
+ 
+@@ -294,7 +297,7 @@ private:
+     bool interrupt() const
+     {
+         if (mInterrupter && util::wasInterrupted(mInterrupter)) {
+-            tbb::task::self().cancel_group_execution();
++            util::cancelGroupExecution();
+             return true;
+         }
+         return false;
diff --git a/openvdb/patches/patch-openvdb_openvdb_tools_VolumeToMesh.h b/openvdb/patches/patch-openvdb_openvdb_tools_VolumeToMesh.h
new file mode 100644
index 0000000000..465a74e2cd
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_tools_VolumeToMesh.h
@@ -0,0 +1,25 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/tools/VolumeToMesh.h.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/tools/VolumeToMesh.h
+@@ -18,7 +18,7 @@
+ #include <tbb/blocked_range.h>
+ #include <tbb/parallel_for.h>
+ #include <tbb/parallel_reduce.h>
+-#include <tbb/task_scheduler_init.h>
++#include <tbb/task_arena.h>
+ 
+ #include <cmath> // for std::isfinite()
+ #include <map>
+@@ -388,7 +388,7 @@ inline void
+ fillArray(ValueType* array, const ValueType& val, const size_t length)
+ {
+     const auto grainSize = std::max<size_t>(
+-        length / tbb::task_scheduler_init::default_num_threads(), 1024);
++        length / tbb::this_task_arena::max_concurrency(), 1024);
+     const tbb::blocked_range<size_t> range(0, length, grainSize);
+     tbb::parallel_for(range, FillArray<ValueType>(array, val), tbb::simple_partitioner());
+ }
diff --git a/openvdb/patches/patch-openvdb_openvdb_unittest_TestCoord.cc b/openvdb/patches/patch-openvdb_openvdb_unittest_TestCoord.cc
new file mode 100644
index 0000000000..77b0ab9add
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_unittest_TestCoord.cc
@@ -0,0 +1,18 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/unittest/TestCoord.cc.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/unittest/TestCoord.cc
+@@ -2,9 +2,9 @@
+ // SPDX-License-Identifier: MPL-2.0
+ 
+ #include <openvdb/Types.h>
++#include <openvdb/math/Coord.h>
+ 
+ #include <gtest/gtest.h>
+-#include <tbb/tbb_stddef.h> // for tbb::split
+ 
+ #include <unordered_map>
+ #include <sstream>
diff --git a/openvdb/patches/patch-openvdb_openvdb_unittest_TestFile.cc b/openvdb/patches/patch-openvdb_openvdb_unittest_TestFile.cc
new file mode 100644
index 0000000000..b3d6587d5b
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_unittest_TestFile.cc
@@ -0,0 +1,56 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/unittest/TestFile.cc.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/unittest/TestFile.cc
+@@ -13,8 +13,11 @@
+ #include <openvdb/version.h>
+ #include <openvdb/openvdb.h>
+ #include "util.h" // for unittest_util::makeSphere()
++
+ #include <gtest/gtest.h>
+-#include <tbb/tbb_thread.h> // for tbb::this_tbb_thread::sleep()
++
++#include <thread>
++#include <chrono>
+ #include <algorithm> // for std::sort()
+ #include <cstdio> // for remove() and rename()
+ #include <fstream>
+@@ -2345,12 +2348,14 @@ TEST_F(TestFile, testAsync)
+             helper.insert(id, filename);
+         }
+ 
+-        tbb::tick_count start = tbb::tick_count::now();
++        auto start = std::chrono::steady_clock::now();
+         while (!helper.ids.empty()) {
+-            if ((tbb::tick_count::now() - start).seconds() > 60) break; // time out after 1 minute
++            auto duration = std::chrono::duration_cast<std::chrono::seconds>(
++                std::chrono::steady_clock::now() - start);
++            if (size_t(duration.count()) > 60)  break; // time out after 1 minute
+ 
+             // Wait one second for tasks to complete.
+-            tbb::this_tbb_thread::sleep(tbb::tick_count::interval_t(1.0/*sec*/));
++            std::this_thread::sleep_for(std::chrono::seconds(1));
+ 
+             // Poll each task in the pending map.
+             std::set<io::Queue::Id> ids = helper.ids; // iterate over a copy
+@@ -2380,7 +2385,7 @@ TEST_F(TestFile, testAsync)
+             helper.insert(id, filename);
+         }
+         while (!queue.empty()) {
+-            tbb::this_tbb_thread::sleep(tbb::tick_count::interval_t(1.0/*sec*/));
++            std::this_thread::sleep_for(std::chrono::seconds(1));
+         }
+     }
+     {
+@@ -2405,7 +2410,7 @@ TEST_F(TestFile, testAsync)
+         EXPECT_THROW(queue.write(grids, io::Stream(file2)), openvdb::RuntimeError);
+ 
+         while (!queue.empty()) {
+-            tbb::this_tbb_thread::sleep(tbb::tick_count::interval_t(1.0/*sec*/));
++            std::this_thread::sleep_for(std::chrono::seconds(1));
+         }
+     }
+ }
diff --git a/openvdb/patches/patch-openvdb_openvdb_unittest_TestUtil.cc b/openvdb/patches/patch-openvdb_openvdb_unittest_TestUtil.cc
new file mode 100644
index 0000000000..493f195800
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_unittest_TestUtil.cc
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/unittest/TestUtil.cc.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/unittest/TestUtil.cc
+@@ -8,7 +8,6 @@
+ 
+ #include <gtest/gtest.h>
+ 
+-#include <tbb/task_scheduler_init.h>
+ #include <tbb/enumerable_thread_specific.h>
+ #include <tbb/parallel_for.h>
+ #include <tbb/blocked_range.h>
diff --git a/openvdb/patches/patch-openvdb_openvdb_unittest_TestValueAccessor.cc b/openvdb/patches/patch-openvdb_openvdb_unittest_TestValueAccessor.cc
new file mode 100644
index 0000000000..dcb1cc16c6
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_unittest_TestValueAccessor.cc
@@ -0,0 +1,78 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/unittest/TestValueAccessor.cc.orig	2021-06-11 21:38:41.000000000 +0000
++++ openvdb/openvdb/unittest/TestValueAccessor.cc
+@@ -378,22 +378,21 @@ TEST_F(TestValueAccessor, testMultithrea
+     //using AccessorT = openvdb::tree::ValueAccessor<Tree4Type>;
+ 
+     // Task to perform multiple reads through a shared accessor
+-    struct ReadTask: public tbb::task {
++    struct ReadTask {
+         AccessorT& acc;
+         ReadTask(AccessorT& c): acc(c) {}
+-        tbb::task* execute()
++        void execute()
+         {
+             for (int i = -MAX_COORD; i < MAX_COORD; ++i) {
+                 ASSERT_DOUBLES_EXACTLY_EQUAL(double(i), acc.getValue(openvdb::Coord(i)));
+             }
+-            return nullptr;
+         }
+     };
+     // Task to perform multiple writes through a shared accessor
+-    struct WriteTask: public tbb::task {
++    struct WriteTask {
+         AccessorT& acc;
+         WriteTask(AccessorT& c): acc(c) {}
+-        tbb::task* execute()
++        void execute()
+         {
+             for (int i = -MAX_COORD; i < MAX_COORD; ++i) {
+                 float f = acc.getValue(openvdb::Coord(i));
+@@ -401,26 +400,20 @@ TEST_F(TestValueAccessor, testMultithrea
+                 acc.setValue(openvdb::Coord(i), float(i));
+                 ASSERT_DOUBLES_EXACTLY_EQUAL(float(i), acc.getValue(openvdb::Coord(i)));
+             }
+-            return nullptr;
+         }
+     };
+     // Parent task to spawn multiple parallel read and write tasks
+-    struct RootTask: public tbb::task {
++    struct RootTask {
+         AccessorT& acc;
+         RootTask(AccessorT& c): acc(c) {}
+-        tbb::task* execute()
++        void execute()
+         {
+-            ReadTask* r[3]; WriteTask* w[3];
++            tbb::task_group tasks;
+             for (int i = 0; i < 3; ++i) {
+-                r[i] = new(allocate_child()) ReadTask(acc);
+-                w[i] = new(allocate_child()) WriteTask(acc);
++                tasks.run([&] { ReadTask r(acc); r.execute(); });
++                tasks.run([&] { WriteTask w(acc); w.execute(); });
+             }
+-            set_ref_count(6 /*children*/ + 1 /*wait*/);
+-            for (int i = 0; i < 3; ++i) {
+-                spawn(*r[i]); spawn(*w[i]);
+-            }
+-            wait_for_all();
+-            return nullptr;
++            tasks.wait();
+         }
+     };
+ 
+@@ -432,8 +425,8 @@ TEST_F(TestValueAccessor, testMultithrea
+     }
+ 
+     // Run multiple read and write tasks in parallel.
+-    RootTask& root = *new(tbb::task::allocate_root()) RootTask(acc);
+-    tbb::task::spawn_root_and_wait(root);
++    RootTask root(acc);
++    root.execute();
+ 
+ #undef MAX_COORD
+ }
diff --git a/openvdb/patches/patch-openvdb_openvdb_util_Threading.h b/openvdb/patches/patch-openvdb_openvdb_util_Threading.h
new file mode 100644
index 0000000000..26a8b23b7b
--- /dev/null
+++ b/openvdb/patches/patch-openvdb_openvdb_util_Threading.h
@@ -0,0 +1,58 @@
+$NetBSD$
+
+Support tbb 2021.3 from
+https://github.com/AcademySoftwareFoundation/openvdb/commit/5b0ec82307c603adb147cee4bc1a925d407141f5
+
+--- openvdb/openvdb/util/Threading.h.orig	2021-08-11 09:50:26.288237592 +0000
++++ openvdb/openvdb/util/Threading.h
+@@ -0,0 +1,50 @@
++// Copyright Contributors to the OpenVDB Project
++// SPDX-License-Identifier: MPL-2.0
++//
++/// @file Threading.h
++
++#ifndef OPENVDB_UTIL_THREADING_HAS_BEEN_INCLUDED
++#define OPENVDB_UTIL_THREADING_HAS_BEEN_INCLUDED
++
++#include "openvdb/version.h"
++
++/// @note tbb/blocked_range.h is the ONLY include that persists from TBB 2020
++///   to TBB 2021 that itself includes the TBB specific version header files.
++///   In TBB 2020, the version header was called tbb/stddef.h. In 2021, it's
++///   called tbb/version.h. We include tbb/blocked_range.h here to indirectly
++///   access the version defines in a consistent way so that downstream
++///   software doesn't need to provide compile time defines.
++#include <tbb/blocked_range.h>
++#include <tbb/task.h>
++#include <tbb/task_group.h>
++
++namespace openvdb {
++OPENVDB_USE_VERSION_NAMESPACE
++namespace OPENVDB_VERSION_NAME {
++namespace util {
++
++inline bool cancelGroupExecution()
++{
++#if TBB_INTERFACE_VERSION_MAJOR >= 12
++	auto ctx = tbb::task::current_context();
++	return ctx ? ctx->cancel_group_execution() : false;
++#else
++    return tbb::task::self().cancel_group_execution();
++#endif
++}
++
++inline bool isGroupExecutionCancelled()
++{
++#if TBB_INTERFACE_VERSION_MAJOR >= 12
++	auto ctx = tbb::task::current_context();
++	return ctx ? ctx->is_group_execution_cancelled() : false;
++#else
++    return tbb::task::self().is_cancelled();
++#endif
++}
++
++} // namespace util
++} // namespace OPENVDB_VERSION_NAME
++} // namespace openvdb
++
++#endif // OPENVDB_UTIL_THREADING_HAS_BEEN_INCLUDED


Home | Main Index | Thread Index | Old Index