diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index aa1ca54a775d..6c0a1de9140c 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -179,4 +179,13 @@ config_setting( values = {"define": "NO_SCS=ON"}, ) +# We are exploring adding USD support to Drake. For the moment, it is opt-in. +# See https://github.com/PixarAnimationStudios/OpenUSD for details. +# Use `--define=WITH_USD=ON` on the bazel command line to enable it. +# (In CI, --config=everything also enables it on Ubuntu.) +config_setting( + name = "with_usd", + values = {"define": "WITH_USD=ON"}, +) + add_lint_tests() diff --git a/tools/ubuntu-jammy.bazelrc b/tools/ubuntu-jammy.bazelrc index ab3e8a4464aa..a1f74b104347 100644 --- a/tools/ubuntu-jammy.bazelrc +++ b/tools/ubuntu-jammy.bazelrc @@ -9,3 +9,7 @@ build:clang --action_env=CC=clang-14 build:clang --action_env=CXX=clang++-14 build:clang --host_action_env=CC=clang-14 build:clang --host_action_env=CXX=clang++-14 + +# In CI (but only in CI), we want to test the opt-in USD build support. +# TODO(jwnimmer-tri) We should try to enable USD by default on all platforms. +build:everything --define=WITH_USD=ON diff --git a/tools/ubuntu-noble.bazelrc b/tools/ubuntu-noble.bazelrc index ab3e8a4464aa..a1f74b104347 100644 --- a/tools/ubuntu-noble.bazelrc +++ b/tools/ubuntu-noble.bazelrc @@ -9,3 +9,7 @@ build:clang --action_env=CC=clang-14 build:clang --action_env=CXX=clang++-14 build:clang --host_action_env=CC=clang-14 build:clang --host_action_env=CXX=clang++-14 + +# In CI (but only in CI), we want to test the opt-in USD build support. +# TODO(jwnimmer-tri) We should try to enable USD by default on all platforms. +build:everything --define=WITH_USD=ON diff --git a/tools/workspace/cmake_configure_file.py b/tools/workspace/cmake_configure_file.py index 7097821870f2..da35414924af 100644 --- a/tools/workspace/cmake_configure_file.py +++ b/tools/workspace/cmake_configure_file.py @@ -120,8 +120,8 @@ def _transform_autoconf(*, line, definitions, strict): return line, used_vars -# Looks like "set(VAR value)". -_set_var = re.compile(r'^\s*set\s*\(\s*(.+)\s+(.+)\s*\)\s*$') +# Looks like "set(VAR value)", maybe with an end-of-line comment. +_set_var = re.compile(r'^\s*set\s*\(\s*(.+)\s+(.+)\s*\)\s*(#.*)?$') # From a line of CMakeLists.txt, return a set(...) key-value pair, if found. @@ -129,7 +129,7 @@ def _extract_definition(line, prior_definitions): match = _set_var.match(line) if not match: return dict() - var, value = match.groups() + var, value, _ = match.groups() try: value, _ = _transform_cmake( line=value, diff --git a/tools/workspace/default.bzl b/tools/workspace/default.bzl index 41c95fe7426c..138efbe5e3a6 100644 --- a/tools/workspace/default.bzl +++ b/tools/workspace/default.bzl @@ -61,9 +61,11 @@ load("//tools/workspace/nasm:repository.bzl", "nasm_repository") load("//tools/workspace/net_sf_jchart2d:repository.bzl", "net_sf_jchart2d_repository") # noqa load("//tools/workspace/nlohmann_internal:repository.bzl", "nlohmann_internal_repository") # noqa load("//tools/workspace/nlopt_internal:repository.bzl", "nlopt_internal_repository") # noqa +load("//tools/workspace/onetbb_internal:repository.bzl", "onetbb_internal_repository") # noqa load("//tools/workspace/openblas:repository.bzl", "openblas_repository") load("//tools/workspace/opencl:repository.bzl", "opencl_repository") load("//tools/workspace/opengl:repository.bzl", "opengl_repository") +load("//tools/workspace/openusd_internal:repository.bzl", "openusd_internal_repository") # noqa load("//tools/workspace/org_apache_xmlgraphics_commons:repository.bzl", "org_apache_xmlgraphics_commons_repository") # noqa load("//tools/workspace/osqp_internal:repository.bzl", "osqp_internal_repository") # noqa load("//tools/workspace/picosha2_internal:repository.bzl", "picosha2_internal_repository") # noqa @@ -239,12 +241,16 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS): nlohmann_internal_repository(name = "nlohmann_internal", mirrors = mirrors) # noqa if "nlopt_internal" not in excludes: nlopt_internal_repository(name = "nlopt_internal", mirrors = mirrors) + if "onetbb_internal" not in excludes: + onetbb_internal_repository(name = "onetbb_internal", mirrors = mirrors) if "openblas" not in excludes: openblas_repository(name = "openblas") if "opencl" not in excludes: opencl_repository(name = "opencl") if "opengl" not in excludes: opengl_repository(name = "opengl") + if "openusd_internal" not in excludes: + openusd_internal_repository(name = "openusd_internal", mirrors = mirrors) # noqa if "org_apache_xmlgraphics_commons" not in excludes: org_apache_xmlgraphics_commons_repository(name = "org_apache_xmlgraphics_commons", mirrors = mirrors) # noqa if "osqp_internal" not in excludes: diff --git a/tools/workspace/mosek/repository.bzl b/tools/workspace/mosek/repository.bzl index 085036b1d3a8..2c6f064ad371 100644 --- a/tools/workspace/mosek/repository.bzl +++ b/tools/workspace/mosek/repository.bzl @@ -110,7 +110,8 @@ def _impl(repository_ctx): else: files = [ # We use the the MOSEKā„¢ copy of libtbb. The version of libtbb - # available in Ubuntu is too old. + # available in Ubuntu is too old. Anytime we change this, we must + # also sync our @onetbb_internal version number to match this. "bin/libtbb.so.12", "bin/libtbb.so.12.8", "bin/libmosek64.so.{}.{}".format( diff --git a/tools/workspace/onetbb_internal/BUILD.bazel b/tools/workspace/onetbb_internal/BUILD.bazel new file mode 100644 index 000000000000..67914ea7e0a0 --- /dev/null +++ b/tools/workspace/onetbb_internal/BUILD.bazel @@ -0,0 +1,3 @@ +load("//tools/lint:lint.bzl", "add_lint_tests") + +add_lint_tests() diff --git a/tools/workspace/onetbb_internal/package.BUILD.bazel b/tools/workspace/onetbb_internal/package.BUILD.bazel new file mode 100644 index 000000000000..0d47f1025890 --- /dev/null +++ b/tools/workspace/onetbb_internal/package.BUILD.bazel @@ -0,0 +1,20 @@ +# -*- bazel -*- + +cc_library( + name = "tbb", + hdrs = glob([ + "include/oneapi/*.h", + "include/oneapi/tbb/*.h", + "include/oneapi/tbb/detail/*.h", + ]), + includes = [ + "include/oneapi", + ], + deps = [ + # TODO(jwnimmer-tri) This should just be the TBB runtime, not the + # entirety of MOSEK. We'll need to clean that up before we enable + # WITH_USD in Drake's installed packages. + "@mosek", + ], + visibility = ["//visibility:public"], +) diff --git a/tools/workspace/onetbb_internal/repository.bzl b/tools/workspace/onetbb_internal/repository.bzl new file mode 100644 index 000000000000..f3e86242ae5f --- /dev/null +++ b/tools/workspace/onetbb_internal/repository.bzl @@ -0,0 +1,17 @@ +load("//tools/workspace:github.bzl", "github_archive") + +def onetbb_internal_repository( + name, + mirrors = None): + github_archive( + name = name, + repository = "oneapi-src/oneTBB", + commit = "v2021.8.0", + # TODO(jwnimmer-tri) We are using the TBB headers from this repository, + # but the TBB library from MOSEK's binary release. We'll probably need + # some tooling to keep all of that in sync, but for now we'll just pin. + commit_pin = 1, + sha256 = "eee380323bb7ce864355ed9431f85c43955faaae9e9bce35c62b372d7ffd9f8b", # noqa + build_file = ":package.BUILD.bazel", + mirrors = mirrors, + ) diff --git a/tools/workspace/openusd_internal/BUILD.bazel b/tools/workspace/openusd_internal/BUILD.bazel new file mode 100644 index 000000000000..acd7d29e1d70 --- /dev/null +++ b/tools/workspace/openusd_internal/BUILD.bazel @@ -0,0 +1,33 @@ +load("//tools/workspace:generate_file.bzl", "generate_file") +load("//tools/lint:lint.bzl", "add_lint_tests") + +# TODO(jwnimmer-tri) To prove that the @openusd_internal build system is +# working properly, here we perform a smoke test of `usdcat --help`. Once +# we have enough real unit tests in Drake that call into USD and prove out +# the build, we should remove this simple smoke test. + +alias( + name = "usdcat", + actual = "@openusd_internal//:usdcat", + tags = [ + # Only compile this binary when the usdcat_help test needs it. + "manual", + ], +) + +generate_file( + name = "empty.sh", + # When WITH_USD is off, this serves as a test stub dummy. + content = "echo 'WITH_USD is not ON'", +) + +sh_test( + name = "usdcat_help", + srcs = select({ + "//tools:with_usd": [":usdcat"], + "//conditions:default": ["empty.sh"], + }), + args = ["--help"], +) + +add_lint_tests() diff --git a/tools/workspace/openusd_internal/defs.bzl b/tools/workspace/openusd_internal/defs.bzl new file mode 100644 index 000000000000..9a9153ba806c --- /dev/null +++ b/tools/workspace/openusd_internal/defs.bzl @@ -0,0 +1,52 @@ +load("@drake//tools/skylark:cc.bzl", "cc_library") +load("@drake//tools/workspace/openusd_internal:lock/files.bzl", "FILES") + +def pxr_library( + name, + *, + subdir): + """Defines a cc_library in the spirit of OpenUSD's pxr_library CMake macro. + + The srcs, hdrs, and deps are not passed as an argument to this function. + Instead, they are loaded from the `lock/files.bzl` database. + + Args: + name: Matches the upstream name (the first argument in CMake). + subdir: The subdirectory under `OpenUSD/pxr` (e.g. "base/arch"). + """ + attrs = FILES[subdir] + srcs = [ + subdir + "/" + x + ".cpp" + for x in attrs["PUBLIC_CLASSES"] + attrs["PRIVATE_CLASSES"] + ] + [ + subdir + "/" + x + for x in attrs["CPPFILES"] + ] + hdrs = [ + subdir + "/" + x + ".h" + for x in attrs["PUBLIC_CLASSES"] + attrs["PRIVATE_CLASSES"] + ] + [ + subdir + "/" + x + for x in attrs["PUBLIC_HEADERS"] + attrs["PRIVATE_HEADERS"] + ] + defines = [ + # In Drake we use the oneAPI flavor of TBB, which is not the default + # in OpenUSD, so we need to opt-in. + "PXR_ONETBB_SUPPORT_ENABLED", + # OpenUSD still has calls to deprecated TBB functions, so we need to + # opt-in to some vestigial parts of TBB. + "TBB_ALLOCATOR_TRAITS_BROKEN", + ] + deps = attrs["LIBRARIES"] + [ + ":pxr_h", + "@onetbb_internal//:tbb", + # TODO(jwnimmer-tri) We also need to list some @boost here. + ] + cc_library( + name = name, + srcs = srcs, + hdrs = hdrs, + defines = defines, + copts = ["-w"], + deps = deps, + ) diff --git a/tools/workspace/openusd_internal/lock/files.bzl b/tools/workspace/openusd_internal/lock/files.bzl new file mode 100644 index 000000000000..a92a4e92dc2b --- /dev/null +++ b/tools/workspace/openusd_internal/lock/files.bzl @@ -0,0 +1,954 @@ +# TODO(jwnimmer-tri) Generate this content automatically by parsing upstream's +# CMakeLists.txt files where they call `pxr_library(...)`. +FILES = { + "pxr/base/arch": { + "LIBRARIES": [], + "PUBLIC_CLASSES": [ + "align", + "attributes", + "daemon", + "debugger", + "demangle", + "env", + "error", + "errno", + "fileSystem", + "function", + "hash", + "library", + "mallocHook", + "regex", + "stackTrace", + "symbols", + "systemInfo", + "threads", + "timing", + "virtualMemory", + "vsnprintf", + ], + "PUBLIC_HEADERS": [ + "api.h", + "buildMode.h", + "defines.h", + "export.h", + "functionLite.h", + "hints.h", + "inttypes.h", + "math.h", + "pragmas.h", + ], + "PRIVATE_CLASSES": [], + "PRIVATE_HEADERS": [ + "testArchAbi.h", + "testArchUtil.h", + ], + "CPPFILES": [ + "assumptions.cpp", + "initConfig.cpp", + ], + }, + "pxr/base/gf": { + "LIBRARIES": [ + "arch", + "tf", + ], + "PUBLIC_CLASSES": [ + "bbox3d", + "camera", + "dualQuatd", + "dualQuatf", + "dualQuath", + "frustum", + "gamma", + "half", + "homogeneous", + "ilmbase_half", + "interval", + "line", + "line2d", + "lineSeg", + "lineSeg2d", + "math", + "matrixData", + "matrix2d", + "matrix2f", + "matrix3f", + "matrix3d", + "matrix4f", + "matrix4d", + "multiInterval", + "plane", + "quatd", + "quatf", + "quath", + "quaternion", + "range1d", + "range1f", + "range2d", + "range2f", + "range3d", + "range3f", + "ray", + "rect2i", + "rotation", + "size2", + "size3", + "transform", + "vec2d", + "vec2f", + "vec2h", + "vec2i", + "vec3d", + "vec3f", + "vec3h", + "vec3i", + "vec4d", + "vec4f", + "vec4h", + "vec4i", + ], + "PUBLIC_HEADERS": [ + "api.h", + "declare.h", + "ilmbase_halfLimits.h", + "limits.h", + "traits.h", + ], + "PRIVATE_CLASSES": [ + "ostreamHelpers", + ], + "PRIVATE_HEADERS": [ + "ilmbase_eLut.h", + "ilmbase_toFloat.h", + ], + "CPPFILES": [], + }, + "pxr/base/js": { + "LIBRARIES": [ + "tf", + ], + "PUBLIC_CLASSES": [ + "json", + "utils", + "value", + ], + "PUBLIC_HEADERS": [ + "api.h", + "converter.h", + "types.h", + ], + "PRIVATE_CLASSES": [], + "PRIVATE_HEADERS": [ + "rapidjson/allocators.h", + "rapidjson/document.h", + "rapidjson/encodedstream.h", + "rapidjson/encodings.h", + "rapidjson/error/en.h", + "rapidjson/error/error.h", + "rapidjson/filereadstream.h", + "rapidjson/filewritestream.h", + "rapidjson/fwd.h", + "rapidjson/internal/biginteger.h", + "rapidjson/internal/diyfp.h", + "rapidjson/internal/dtoa.h", + "rapidjson/internal/ieee754.h", + "rapidjson/internal/itoa.h", + "rapidjson/internal/meta.h", + "rapidjson/internal/pow10.h", + "rapidjson/internal/regex.h", + "rapidjson/internal/stack.h", + "rapidjson/internal/strfunc.h", + "rapidjson/internal/strtod.h", + "rapidjson/internal/swap.h", + "rapidjson/istreamwrapper.h", + "rapidjson/memorybuffer.h", + "rapidjson/memorystream.h", + "rapidjson/msinttypes/inttypes.h", + "rapidjson/msinttypes/stdint.h", + "rapidjson/ostreamwrapper.h", + "rapidjson/pointer.h", + "rapidjson/prettywriter.h", + "rapidjson/rapidjson.h", + "rapidjson/reader.h", + "rapidjson/schema.h", + "rapidjson/stream.h", + "rapidjson/stringbuffer.h", + "rapidjson/writer.h", + # TODO(jwnimmer-tri) This file is missing in upstream's list. + # Once we start auto-generating this files.bzl listing, we'll + # need to patch upstream to declare this correctly. + "rapidjson/internal/clzll.h", + ], + "CPPFILES": [], + }, + "pxr/base/plug": { + "LIBRARIES": [ + "arch", + "tf", + "js", + "trace", + "work", + ], + "PUBLIC_CLASSES": [ + "interfaceFactory", + "notice", + "plugin", + "registry", + "staticInterface", + ], + "PUBLIC_HEADERS": [ + "api.h", + "thisPlugin.h", + ], + "PRIVATE_CLASSES": [ + "debugCodes", + "info", + "testPlugBase", + ], + "PRIVATE_HEADERS": [], + "CPPFILES": [ + "initConfig.cpp", + ], + }, + "pxr/base/tf": { + "LIBRARIES": [ + "arch", + ], + "PUBLIC_CLASSES": [ + "anyUniquePtr", + "anyWeakPtr", + "atomicOfstreamWrapper", + "bigRWMutex", + "bitUtils", + "debug", + "debugNotice", + "denseHashMap", + "denseHashSet", + "diagnostic", + "diagnosticBase", + "diagnosticHelper", + "diagnosticMgr", + "dl", + "enum", + "envSetting", + "error", + "errorMark", + "errorTransport", + "exception", + "expiryNotifier", + "fastCompression", + "fileUtils", + "getenv", + "hash", + "iterator", + "mallocTag", + "notice", + "nullPtr", + "ostreamMethods", + "pathUtils", + "patternMatcher", + "pointerAndBits", + "pyLock", + "pyObjWrapper", + "pyTracing", + "refBase", + "refCount", + "refPtr", + "refPtrTracker", + "regTest", + "registryManager", + "safeOutputFile", + "scoped", + "scopeDescription", + "setenv", + "singleton", + "smallVector", + "spinRWMutex", + "stackTrace", + "stacked", + "status", + "stl", + "stopwatch", + "stringUtils", + "templateString", + "tf", + "token", + "type", + "typeFunctions", + "typeNotice", + "warning", + "weakBase", + "weakPtr", + "weakPtrFacade", + ], + "PUBLIC_HEADERS": [ + "api.h", + "callContext.h", + "cxxCast.h", + "declarePtrs.h", + "diagnosticLite.h", + "functionTraits.h", + "functionRef.h", + "hashmap.h", + "hashset.h", + "instantiateSingleton.h", + "instantiateStacked.h", + "instantiateType.h", + "meta.h", + "pxrCLI11/CLI11.h", + "pxrPEGTL/pegtl.h", + "pxrTslRobinMap/robin_growth_policy.h", + "pxrTslRobinMap/robin_hash.h", + "pxrTslRobinMap/robin_map.h", + "pxrTslRobinMap/robin_set.h", + "preprocessorUtils.h", + "preprocessorUtilsLite.h", + "safeTypeCompare.h", + "span.h", + "staticData.h", + "staticTokens.h", + "typeInfoMap.h", + "type_Impl.h", + ], + "PRIVATE_CLASSES": [ + "atomicRenameUtil", + "debugCodes", + "noticeRegistry", + ], + "PRIVATE_HEADERS": [ + "scopeDescriptionPrivate.h", + "pxrDoubleConversion/ieee.h", + "pxrDoubleConversion/utils.h", + "pxrDoubleConversion/double-conversion.h", + "pxrDoubleConversion/bignum-dtoa.h", + "pxrDoubleConversion/bignum.h", + "pxrDoubleConversion/cached-powers.h", + "pxrDoubleConversion/diy-fp.h", + "pxrDoubleConversion/fast-dtoa.h", + "pxrDoubleConversion/fixed-dtoa.h", + "pxrDoubleConversion/strtod.h", + "pxrLZ4/lz4.h", + "pyWeakObject.h", + ], + "CPPFILES": [ + "initConfig.cpp", + "preprocessorUtils.cpp", + "pxrDoubleConversion/double-conversion.cc", + "pxrDoubleConversion/bignum-dtoa.cc", + "pxrDoubleConversion/bignum.cc", + "pxrDoubleConversion/cached-powers.cc", + "pxrDoubleConversion/diy-fp.cc", + "pxrDoubleConversion/fast-dtoa.cc", + "pxrDoubleConversion/fixed-dtoa.cc", + "pxrDoubleConversion/strtod.cc", + "pxrLZ4/lz4.cpp", + ], + }, + "pxr/base/trace": { + "LIBRARIES": [ + "arch", + "js", + "tf", + ], + "PUBLIC_CLASSES": [ + "aggregateTree", + "aggregateNode", + "category", + "collection", + "collectionNotice", + "collector", + "counterAccumulator", + "dataBuffer", + "dynamicKey", + "event", + "eventContainer", + "eventData", + "eventList", + "eventNode", + "eventTree", + "key", + "reporter", + "reporterBase", + "reporterDataSourceBase", + "reporterDataSourceCollection", + "reporterDataSourceCollector", + "serialization", + "staticKeyData", + "threads", + ], + "PUBLIC_HEADERS": [ + "api.h", + "concurrentList.h", + "stringHash.h", + "trace.h", + ], + "PRIVATE_CLASSES": [ + "aggregateTreeBuilder", + "eventTreeBuilder", + "jsonSerialization", + ], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, + "pxr/base/vt": { + "LIBRARIES": [ + "arch", + "tf", + "gf", + "trace", + ], + "PUBLIC_CLASSES": [ + "array", + "dictionary", + "functions", + "hash", + "streamOut", + "types", + "value", + ], + "PUBLIC_HEADERS": [ + "api.h", + "traits.h", + "typeHeaders.h", + "visitValue.h", + ], + "PRIVATE_CLASSES": [], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, + "pxr/base/work": { + "LIBRARIES": [ + "tf", + "trace", + ], + "PUBLIC_CLASSES": [ + "detachedTask", + "dispatcher", + "loops", + "reduce", + "singularTask", + "threadLimits", + "utils", + ], + "PUBLIC_HEADERS": [ + "api.h", + "withScopedParallelism.h", + ], + "PRIVATE_CLASSES": [], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, + "pxr/usd/ar": { + "LIBRARIES": [ + "arch", + "js", + "plug", + "tf", + "vt", + ], + "PUBLIC_CLASSES": [ + "asset", + "assetInfo", + "defaultResolver", + "defaultResolverContext", + "definePackageResolver", + "defineResolver", + "filesystemAsset", + "filesystemWritableAsset", + "inMemoryAsset", + "notice", + "packageResolver", + "packageUtils", + "resolvedPath", + "resolver", + "resolverContext", + "resolverContextBinder", + "resolverScopedCache", + "timestamp", + "writableAsset", + ], + "PUBLIC_HEADERS": [ + "api.h", + "ar.h", + "defineResolverContext.h", + "threadLocalScopedCache.h", + ], + "PRIVATE_CLASSES": [], + "PRIVATE_HEADERS": [ + "debugCodes.h", + "testenv/TestArURIResolver_plugin.h", + ], + "CPPFILES": [ + "debugCodes.cpp", + ], + }, + "pxr/usd/kind": { + "LIBRARIES": [ + "tf", + "plug", + ], + "PUBLIC_CLASSES": [ + "registry", + ], + "PUBLIC_HEADERS": [ + "api.h", + ], + "PRIVATE_CLASSES": [], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, + "pxr/usd/ndr": { + "LIBRARIES": [ + "tf", + "plug", + "vt", + "work", + "ar", + "sdf", + ], + "PUBLIC_CLASSES": [ + "debugCodes", + "declare", + "discoveryPlugin", + "filesystemDiscovery", + "filesystemDiscoveryHelpers", + "node", + "parserPlugin", + "property", + "registry", + ], + "PUBLIC_HEADERS": [ + "api.h", + "nodeDiscoveryResult.h", + ], + "PRIVATE_CLASSES": [], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, + "pxr/usd/pcp": { + "LIBRARIES": [ + "tf", + "trace", + "vt", + "sdf", + "work", + "ar", + ], + "PUBLIC_CLASSES": [ + "arc", + "cache", + "changes", + "composeSite", + "dependency", + "dynamicFileFormatContext", + "dynamicFileFormatDependencyData", + "dynamicFileFormatInterface", + "errors", + "expressionVariables", + "expressionVariablesDependencyData", + "expressionVariablesSource", + "instanceKey", + "iterator", + "layerStack", + "layerStackIdentifier", + "mapExpression", + "mapFunction", + "namespaceEdits", + "node", + "pathTranslation", + "primIndex", + "propertyIndex", + "site", + "strengthOrdering", + "targetIndex", + "types", + ], + "PUBLIC_HEADERS": [ + "api.h", + ], + "PRIVATE_CLASSES": [ + "debugCodes", + "dependencies", + "diagnostic", + "instancing", + "layerStackRegistry", + "node_Iterator", + "primIndex_Graph", + "primIndex_StackFrame", + "statistics", + "utils", + ], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, + "pxr/usd/sdf": { + "LIBRARIES": [ + "ar", + "arch", + "gf", + "tf", + "trace", + "vt", + "work", + ], + "PUBLIC_CLASSES": [ + "abstractData", + "allowed", + "assetPath", + "attributeSpec", + "changeBlock", + "changeList", + "children", + "childrenPolicies", + "childrenProxy", + "childrenUtils", + "childrenView", + "cleanupEnabler", + "copyUtils", + "data", + "declareHandles", + "fileFormat", + "identity", + "layer", + "layerOffset", + "layerStateDelegate", + "layerTree", + "layerUtils", + "listProxy", + "listEditor", + "listEditorProxy", + "listOp", + "mapEditProxy", + "mapEditor", + "namespaceEdit", + "notice", + "opaqueValue", + "path", + "pathExpression", + "pathExpressionEval", + "pathNode", + "pathTable", + "payload", + "pool", + "predicateExpression", + "predicateLibrary", + "primSpec", + "propertySpec", + "proxyPolicies", + "proxyTypes", + "pseudoRootSpec", + "reference", + "relationshipSpec", + "schema", + "site", + "siteUtils", + "spec", + "specType", + "textFileFormat", + "timeCode", + "tokens", + "types", + "valueTypeName", + "variableExpression", + "variantSetSpec", + "variantSpec", + "textFileFormat.tab", + ], + "PUBLIC_HEADERS": [ + "api.h", + "accessorHelpers.h", + "declareSpec.h", + "invoke.hpp", + "layerHints.h", + "predicateExpressionParser.h", + "predicateProgram.h", + "schemaTypeRegistration.h", + ], + "PRIVATE_CLASSES": [ + "assetPathResolver", + "changeManager", + "cleanupTracker", + "connectionListEditor", + "debugCodes", + "fileFormatRegistry", + "fileIO", + "fileIO_Common", + "layerRegistry", + "listOpListEditor", + "parserHelpers", + "parserValueContext", + "subLayerListEditor", + "textParserContext", + "valueTypeRegistry", + "variableExpressionImpl", + "variableExpressionParser", + "vectorListEditor", + ], + "PRIVATE_HEADERS": [ + "instantiatePool.h", + "valueTypePrivate.h", + ], + "CPPFILES": [ + "textFileFormat.lex.cpp", + ], + }, + "pxr/usd/sdr": { + "LIBRARIES": [ + "tf", + "vt", + "ar", + "ndr", + "sdf", + ], + "PUBLIC_CLASSES": [ + "debugCodes", + "registry", + "shaderMetadataHelpers", + "shaderNode", + "shaderProperty", + ], + "PUBLIC_HEADERS": [ + "api.h", + "declare.h", + ], + "PRIVATE_CLASSES": [], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, + "pxr/usd/usd": { + "LIBRARIES": [ + "arch", + "kind", + "pcp", + "sdf", + "ar", + "plug", + "tf", + "trace", + "vt", + "work", + ], + "PUBLIC_CLASSES": [ + "apiSchemaBase", + "attribute", + "clipsAPI", + "attributeQuery", + "collectionAPI", + "collectionMembershipQuery", + "collectionPredicateLibrary", + "common", + "crateInfo", + "debugCodes", + "editContext", + "editTarget", + "errors", + "flattenUtils", + "inherits", + "interpolation", + "modelAPI", + "notice", + "object", + "payloads", + "prim", + "primCompositionQuery", + "primData", + "primDataHandle", + "primDefinition", + "primFlags", + "primRange", + "primTypeInfo", + "property", + "references", + "relationship", + "resolveInfo", + "resolveTarget", + "resolver", + "schemaBase", + "schemaRegistry", + "specializes", + "stage", + "stageCache", + "stageCacheContext", + "stageLoadRules", + "stagePopulationMask", + "timeCode", + "tokens", + "typed", + "usdFileFormat", + "usdaFileFormat", + "usdcFileFormat", + "usdzFileFormat", + "variantSets", + "zipFile", + # TODO(jwnimmer-tri) This class is documented as "work in progress" + # upstream and doesn't compile correctly inside Drake, so we skip + # it. Once we start auto-generating this files.bzl listing, we'll + # probably need to patch upstream to skip it, too. + # "namespaceEditor", + ], + "PUBLIC_HEADERS": [ + "api.h", + ], + "PRIVATE_CLASSES": [ + "clip", + "clipCache", + "clipSet", + "clipSetDefinition", + "crateData", + "crateFile", + "instanceCache", + "instanceKey", + "integerCoding", + "interpolators", + "primTypeInfoCache", + "usdzResolver", + "valueUtils", + ], + "PRIVATE_HEADERS": [ + "crateDataTypes.h", + "crateValueInliners.h", + "listEditImpl.h", + "wrapUtils.h", + "testenv/TestUsdResolverChangedResolver.h", + # TODO(jwnimmer-tri) This file is missing in upstream's list. + # Once we start auto-generating this files.bzl listing, we'll + # need to patch upstream to declare this correctly. + "shared.h", + ], + "CPPFILES": [], + }, + "pxr/usd/usdGeom": { + "LIBRARIES": [ + "js", + "tf", + "plug", + "vt", + "sdf", + "trace", + "usd", + "work", + ], + "PUBLIC_CLASSES": [ + "debugCodes", + "tokens", + "bboxCache", + "constraintTarget", + "xformCache", + "basisCurves", + "boundable", + "boundableComputeExtent", + "camera", + "capsule", + "capsule_1", + "cone", + "cube", + "curves", + "cylinder", + "cylinder_1", + "hermiteCurves", + "imageable", + "gprim", + "mesh", + "metrics", + "modelAPI", + "motionAPI", + "nurbsCurves", + "nurbsPatch", + "plane", + "pointBased", + "pointInstancer", + "points", + "primvar", + "primvarsAPI", + "scope", + "sphere", + "subset", + "visibilityAPI", + "xform", + "xformable", + "xformOp", + "xformCommonAPI", + ], + "PUBLIC_HEADERS": [ + "api.h", + ], + "PRIVATE_CLASSES": [ + "samplingUtils", + ], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, + "pxr/usd/usdShade": { + "LIBRARIES": [ + "tf", + "vt", + "js", + "sdf", + "ndr", + "sdr", + "usd", + "usdGeom", + ], + "PUBLIC_CLASSES": [ + "connectableAPI", + "connectableAPIBehavior", + "coordSysAPI", + "input", + "material", + "materialBindingAPI", + "nodeDefAPI", + "output", + "shader", + "shaderDefParser", + "shaderDefUtils", + "nodeGraph", + "tokens", + "udimUtils", + "utils", + ], + "PUBLIC_HEADERS": [ + "api.h", + "types.h", + ], + "PRIVATE_CLASSES": [], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, + "pxr/usd/usdUtils": { + "LIBRARIES": [ + "arch", + "tf", + "gf", + "sdf", + "usd", + "usdGeom", + "usdShade", + ], + "PUBLIC_CLASSES": [ + "authoring", + "coalescingDiagnosticDelegate", + "conditionalAbortDiagnosticDelegate", + "debugCodes", + "dependencies", + "flattenLayerStack", + "introspection", + "pipeline", + "registeredVariantSet", + "sparseValueWriter", + "stageCache", + "stitch", + "stitchClips", + "timeCodeRange", + "usdzPackage", + ], + "PUBLIC_HEADERS": [ + "api.h", + ], + "PRIVATE_CLASSES": [ + "assetLocalization", + "assetLocalizationDelegate", + ], + "PRIVATE_HEADERS": [], + "CPPFILES": [], + }, +} diff --git a/tools/workspace/openusd_internal/package.BUILD.bazel b/tools/workspace/openusd_internal/package.BUILD.bazel new file mode 100644 index 000000000000..bb4fe93a8b14 --- /dev/null +++ b/tools/workspace/openusd_internal/package.BUILD.bazel @@ -0,0 +1,87 @@ +# -*- bazel -*- + +load("@drake//tools/skylark:cc.bzl", "cc_binary", "cc_library") +load( + "@drake//tools/workspace:cmake_configure_file.bzl", + "cmake_configure_file", +) +load("@drake//tools/workspace/openusd_internal:defs.bzl", "pxr_library") + +package(default_visibility = ["//visibility:private"]) + +cmake_configure_file( + name = "config_genrule", + src = "pxr/pxr.h.in", + out = "pxr/pxr.h", + cmakelists = [ + "cmake/defaults/Version.cmake", + ], + defines = [ + # Match the upstream default. + "PXR_PREFER_SAFETY_OVER_SPEED", + # We don't need Python. + "PXR_PYTHON_SUPPORT_ENABLED=0", + # Use Drake-specific namespaces. + "PXR_USE_NAMESPACES=1", + "PXR_EXTERNAL_NAMESPACE=drake_vendor_pxr", + "PXR_INTERNAL_NAMESPACE=drake_vendor_pxrInternal", + # Re-implement the math from OpenUSD/cmake/Version.cmake. + "PXR_VERSION=(@PXR_MAJOR_VERSION@ * 10000 + @PXR_MINOR_VERSION@ * 100 + @PXR_PATCH_VERSION@)", # noqa + ], +) + +cc_library(name = "pxr_h", hdrs = [":pxr/pxr.h"]) + +pxr_library(name = "ar", subdir = "pxr/usd/ar") +pxr_library(name = "arch", subdir = "pxr/base/arch") +pxr_library(name = "gf", subdir = "pxr/base/gf") +pxr_library(name = "js", subdir = "pxr/base/js") +pxr_library(name = "kind", subdir = "pxr/usd/kind") +pxr_library(name = "ndr", subdir = "pxr/usd/ndr") +pxr_library(name = "pcp", subdir = "pxr/usd/pcp") +pxr_library(name = "plug", subdir = "pxr/base/plug") +pxr_library(name = "sdf", subdir = "pxr/usd/sdf") +pxr_library(name = "sdr", subdir = "pxr/usd/sdr") +pxr_library(name = "tf", subdir = "pxr/base/tf") +pxr_library(name = "trace", subdir = "pxr/base/trace") +pxr_library(name = "usd", subdir = "pxr/usd/usd") +pxr_library(name = "usdGeom", subdir = "pxr/usd/usdGeom") +pxr_library(name = "usdShade", subdir = "pxr/usd/usdShade") +pxr_library(name = "usdUtils", subdir = "pxr/usd/usdUtils") +pxr_library(name = "vt", subdir = "pxr/base/vt") +pxr_library(name = "work", subdir = "pxr/base/work") + +cc_library( + name = "openusd", + deps = [ + ":ar", + ":arch", + ":gf", + ":js", + ":kind", + ":ndr", + ":pcp", + ":plug", + ":sdf", + ":sdr", + ":tf", + ":trace", + ":usd", + ":usdGeom", + ":usdShade", + ":usdUtils", + ":vt", + ":work", + ], + visibility = ["//visibility:public"], +) + +cc_binary( + name = "usdcat", + srcs = ["pxr/usd/bin/usdcat/usdcat.cpp"], + copts = ["-w"], + deps = [":openusd"], + visibility = [ + "@drake//tools/workspace/openusd_internal:__pkg__", + ], +) diff --git a/tools/workspace/openusd_internal/patches/onetbb.patch b/tools/workspace/openusd_internal/patches/onetbb.patch new file mode 100644 index 000000000000..4f84d4ee0ee6 --- /dev/null +++ b/tools/workspace/openusd_internal/patches/onetbb.patch @@ -0,0 +1,1490 @@ +[openusd_internal] Switch TBB to oneAPI + +This is copied from the upstream pull request: + https://github.com/PixarAnimationStudios/OpenUSD/pull/2825 + +Many thanks to wangcan for contributing it! + + +diff --git cmake/defaults/Packages.cmake cmake/defaults/Packages.cmake +index 7ae4b287f..d0d3a4546 100644 +--- cmake/defaults/Packages.cmake ++++ cmake/defaults/Packages.cmake +@@ -152,8 +152,18 @@ endif() + + + # --TBB +-find_package(TBB REQUIRED COMPONENTS tbb) ++option(OneTBB_CMAKE_ENABLE "Disable cmake build for oneTbb defaultly" OFF) ++if(WIN32) ++ find_package(TBB REQUIRED COMPONENTS tbb12) ++else() ++ find_package(TBB REQUIRED COMPONENTS tbb) ++endif() ++ + add_definitions(${TBB_DEFINITIONS}) ++if(OneTBB_CMAKE_ENABLE) ++ add_definitions(-DPXR_ONETBB_SUPPORT_ENABLED) ++endif() ++message("OpenUSD find tbb libraries ${TBB_LIBRARIES}") + + # --math + if(WIN32) +diff --git cmake/modules/FindTBB.cmake cmake/modules/FindTBB.cmake +index 9bf69a022..7b70cdc5a 100644 +--- cmake/modules/FindTBB.cmake ++++ cmake/modules/FindTBB.cmake +@@ -72,7 +72,7 @@ + # * TBB_VERSION_MAJOR - The major version + # * TBB_VERSION_MINOR - The minor version + # * TBB_INTERFACE_VERSION - The interface version number defined in +-# tbb/tbb_stddef.h. ++# tbb/tbb_stddef.h or oneapi/tbb/version.h when OneTBB_CMAKE_ENABLE enabled. + # * TBB__LIBRARY_RELEASE - The path of the TBB release version of + # , where may be tbb, tbb_debug, + # tbbmalloc, tbbmalloc_debug, tbb_preview, or +@@ -197,7 +197,12 @@ if(NOT TBB_FOUND) + ################################## + + if(TBB_INCLUDE_DIRS) +- file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file) ++ if(OneTBB_CMAKE_ENABLE) ++ file(READ "${TBB_INCLUDE_DIRS}/oneapi/tbb/version.h" _tbb_version_file) ++ else() ++ file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file) ++ endif() ++ + string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" + TBB_VERSION_MAJOR "${_tbb_version_file}") + string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" +@@ -210,16 +215,20 @@ if(NOT TBB_FOUND) + ################################## + # Find TBB components + ################################## ++ set(TBB_TARGET_COMPONENT tbb) ++ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") ++ set(TBB_TARGET_COMPONENT tbb12) ++ endif() + + if(TBB_VERSION VERSION_LESS 4.3) +- set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc tbb) ++ set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc ${TBB_TARGET_COMPONENT}) + else() +- set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc tbb) ++ set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc ${TBB_TARGET_COMPONENT}) + endif() + + # Find each component + foreach(_comp ${TBB_SEARCH_COMPOMPONENTS}) +- if(";${TBB_FIND_COMPONENTS};tbb;" MATCHES ";${_comp};") ++ if(";${TBB_FIND_COMPONENTS};${TBB_TARGET_COMPONENT};" MATCHES ";${_comp};") + + # Search for the libraries + find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp} +@@ -234,12 +243,15 @@ if(NOT TBB_FOUND) + + if(TBB_${_comp}_LIBRARY_DEBUG) + list(APPEND TBB_LIBRARIES_DEBUG "${TBB_${_comp}_LIBRARY_DEBUG}") ++ set(TBB_tbb_LIBRARY_DEBUG "${TBB_${_comp}_LIBRARY_DEBUG}") + endif() + if(TBB_${_comp}_LIBRARY_RELEASE) + list(APPEND TBB_LIBRARIES_RELEASE "${TBB_${_comp}_LIBRARY_RELEASE}") ++ set(TBB_tbb_LIBRARY_RELEASE "${TBB_${_comp}_LIBRARY_RELEASE}") + endif() + if(TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE} AND NOT TBB_${_comp}_LIBRARY) + set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}}") ++ set(TBB_tbb_LIBRARY "${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}}") + endif() + + if(TBB_${_comp}_LIBRARY AND EXISTS "${TBB_${_comp}_LIBRARY}") +@@ -252,6 +264,7 @@ if(NOT TBB_FOUND) + mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE) + mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG) + mark_as_advanced(TBB_${_comp}_LIBRARY) ++ mark_as_advanced(TBB_tbb_LIBRARY) + + endif() + endforeach() +@@ -284,12 +297,12 @@ if(NOT TBB_FOUND) + ################################## + + if(NOT CMAKE_VERSION VERSION_LESS 3.0 AND TBB_FOUND) +- add_library(TBB::tbb SHARED IMPORTED) +- set_target_properties(TBB::tbb PROPERTIES ++ add_library(TBB::${TBB_TARGET_COMPONENT} SHARED IMPORTED) ++ set_target_properties(TBB::${TBB_TARGET_COMPONENT} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS} + IMPORTED_LOCATION ${TBB_LIBRARIES}) + if(TBB_LIBRARIES_RELEASE AND TBB_LIBRARIES_DEBUG) +- set_target_properties(TBB::tbb PROPERTIES ++ set_target_properties(TBB::${TBB_TARGET_COMPONENT} PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "$<$,$>:TBB_USE_DEBUG=1>" + IMPORTED_LOCATION_DEBUG ${TBB_LIBRARIES_DEBUG} + IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_LIBRARIES_DEBUG} +@@ -297,9 +310,9 @@ if(NOT TBB_FOUND) + IMPORTED_LOCATION_MINSIZEREL ${TBB_LIBRARIES_RELEASE} + ) + elseif(TBB_LIBRARIES_RELEASE) +- set_target_properties(TBB::tbb PROPERTIES IMPORTED_LOCATION ${TBB_LIBRARIES_RELEASE}) ++ set_target_properties(TBB::${TBB_TARGET_COMPONENT} PROPERTIES IMPORTED_LOCATION ${TBB_LIBRARIES_RELEASE}) + else() +- set_target_properties(TBB::tbb PROPERTIES ++ set_target_properties(TBB::${TBB_TARGET_COMPONENT} PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}" + IMPORTED_LOCATION ${TBB_LIBRARIES_DEBUG} + ) +diff --git extras/usd/examples/usdObj/pch.h extras/usd/examples/usdObj/pch.h +index 6a8744cbc..aaed5d63e 100644 +--- extras/usd/examples/usdObj/pch.h ++++ extras/usd/examples/usdObj/pch.h +@@ -166,7 +166,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git extras/usd/examples/usdSchemaExamples/pch.h extras/usd/examples/usdSchemaExamples/pch.h +index 47666439a..507bf5a06 100644 +--- extras/usd/examples/usdSchemaExamples/pch.h ++++ extras/usd/examples/usdSchemaExamples/pch.h +@@ -168,7 +168,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/base/plug/pch.h pxr/base/plug/pch.h +index 98b6fc782..a4276a8dc 100644 +--- pxr/base/plug/pch.h ++++ pxr/base/plug/pch.h +@@ -183,7 +183,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/base/tf/pch.h pxr/base/tf/pch.h +index 64e232c84..b4257503c 100644 +--- pxr/base/tf/pch.h ++++ pxr/base/tf/pch.h +@@ -242,7 +242,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/base/tf/testenv/error.cpp pxr/base/tf/testenv/error.cpp +index e8eed44a4..7c895113b 100644 +--- pxr/base/tf/testenv/error.cpp ++++ pxr/base/tf/testenv/error.cpp +@@ -29,7 +29,11 @@ + + #include "pxr/base/arch/functionLite.h" + ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++#include ++#else + #include ++#endif + + #define FILENAME "error.cpp" + +@@ -195,7 +199,11 @@ Test_TfErrorThreadTransport() + printf("Creating TfErrorMark\n"); + TfErrorMark m; + printf("Launching thread\n"); ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ std::thread t([&transport]() { _ThreadTask(&transport); }); ++#else + tbb::tbb_thread t([&transport]() { _ThreadTask(&transport); }); ++#endif + TF_AXIOM(m.IsClean()); + t.join(); + printf("Thread completed, posting error.\n"); +diff --git pxr/base/trace/pch.h pxr/base/trace/pch.h +index 25f4b5d6c..6b51e59de 100644 +--- pxr/base/trace/pch.h ++++ pxr/base/trace/pch.h +@@ -178,7 +178,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/base/vt/pch.h pxr/base/vt/pch.h +index 75f03bee2..62c737d26 100644 +--- pxr/base/vt/pch.h ++++ pxr/base/vt/pch.h +@@ -171,7 +171,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/base/work/detachedTask.h pxr/base/work/detachedTask.h +index 876fee68c..5e0f9cc34 100644 +--- pxr/base/work/detachedTask.h ++++ pxr/base/work/detachedTask.h +@@ -36,12 +36,18 @@ + + PXR_NAMESPACE_OPEN_SCOPE + ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++#define TBB_TASK_CONST const ++#else ++#define TBB_TASK_CONST ++#endif ++ + template + struct Work_DetachedTask + { + explicit Work_DetachedTask(Fn &&fn) : _fn(std::move(fn)) {} + explicit Work_DetachedTask(Fn const &fn) : _fn(fn) {} +- void operator()() { ++ void operator()() TBB_TASK_CONST { + TfErrorMark m; + _fn(); + m.Clear(); +diff --git pxr/base/work/dispatcher.cpp pxr/base/work/dispatcher.cpp +index adba7dff3..5af742983 100644 +--- pxr/base/work/dispatcher.cpp ++++ pxr/base/work/dispatcher.cpp +@@ -35,24 +35,36 @@ WorkDispatcher::WorkDispatcher() + { + _waitCleanupFlag.clear(); + ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ _taskGroup = new tbb::task_group(_context); ++#else + // The concurrent_wait flag used with the task_group_context ensures + // the ref count will remain at 1 after all predecessor tasks are + // completed, so we don't need to keep resetting it in Wait(). + _rootTask = new(tbb::task::allocate_root(_context)) tbb::empty_task; + _rootTask->set_ref_count(1); ++#endif + } + + WorkDispatcher::~WorkDispatcher() + { + Wait(); ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ delete _taskGroup; ++#else + tbb::task::destroy(*_rootTask); ++#endif + } + + void + WorkDispatcher::Wait() + { + // Wait for tasks to complete. +- _rootTask->wait_for_all(); ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ _taskGroup->wait(); ++#else ++ _rootTask->wait_for_all(); ++#endif + + // If we take the flag from false -> true, we do the cleanup. + if (_waitCleanupFlag.test_and_set() == false) { +diff --git pxr/base/work/dispatcher.h pxr/base/work/dispatcher.h +index 2c499d6ab..ee0341892 100644 +--- pxr/base/work/dispatcher.h ++++ pxr/base/work/dispatcher.h +@@ -35,6 +35,9 @@ + + #include + #include ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++#include ++#endif + + #include + #include +@@ -103,7 +106,11 @@ public: + + template + inline void Run(Callable &&c) { ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ _taskGroup->run(std::forward(c)); ++#else + _rootTask->spawn(_MakeInvokerTask(std::forward(c))); ++#endif + } + + template +@@ -133,6 +140,7 @@ public: + private: + typedef tbb::concurrent_vector _ErrorTransports; + ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + // Function invoker helper that wraps the invocation with an ErrorMark so we + // can transmit errors that occur back to the thread that Wait() s for tasks + // to complete. +@@ -164,6 +172,7 @@ private: + _InvokerTask::type>( + std::forward(fn), &_errors); + } ++#endif + + // Helper function that removes errors from \p m and stores them in a new + // entry in \p errors. +@@ -172,8 +181,14 @@ private: + + // Task group context and associated root task that allows us to cancel + // tasks invoked directly by this dispatcher. ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ tbb::detail::d1::task_group_context _context; ++ tbb::detail::d1::task_group *_taskGroup; ++#else + tbb::task_group_context _context; + tbb::empty_task* _rootTask; ++#endif ++ + + // The error transports we use to transmit errors in other threads back to + // this thread. +diff --git pxr/base/work/pch.h pxr/base/work/pch.h +index 228b18d0d..e3a3275c1 100644 +--- pxr/base/work/pch.h ++++ pxr/base/work/pch.h +@@ -110,7 +110,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +@@ -121,4 +123,8 @@ + #include + #include + #include ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++#include ++#else + #include ++#endif +diff --git pxr/base/work/threadLimits.cpp pxr/base/work/threadLimits.cpp +index bc629b812..9c85a5455 100644 +--- pxr/base/work/threadLimits.cpp ++++ pxr/base/work/threadLimits.cpp +@@ -29,7 +29,11 @@ + + #include "pxr/base/tf/envSetting.h" + ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++#include ++#else + #include ++#endif + #include + + #include +@@ -58,16 +62,25 @@ TF_DEFINE_ENV_SETTING( + + PXR_NAMESPACE_OPEN_SCOPE + ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + // We create a task_scheduler_init instance at static initialization time if + // PXR_WORK_THREAD_LIMIT is set to a nonzero value. Otherwise this stays NULL. + static tbb::task_scheduler_init *_tbbTaskSchedInit; ++#else ++static unsigned kThreadLimit = 0; ++static tbb::global_control *_tbbGlobalControl; ++#endif + + unsigned + WorkGetPhysicalConcurrencyLimit() + { + // Use TBB here, since it pays attention to the affinity mask on Linux and + // Windows. ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + return tbb::task_scheduler_init::default_num_threads(); ++#else ++ return tbb::info::default_concurrency(); ++#endif + } + + // This function always returns an actual thread count >= 1. +@@ -123,7 +136,12 @@ Work_InitializeThreading() + // previously initialized by the hosting environment (e.g. if we are running + // as a plugin to another application.) + if (settingVal) { ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + _tbbTaskSchedInit = new tbb::task_scheduler_init(threadLimit); ++#else ++ _tbbGlobalControl = new tbb::global_control(tbb::global_control::max_allowed_parallelism, threadLimit); ++ kThreadLimit = threadLimit; ++#endif + } + } + static int _forceInitialization = (Work_InitializeThreading(), 0); +@@ -162,12 +180,20 @@ WorkSetConcurrencyLimit(unsigned n) + // According to the documentation that should be the case, but we should + // make sure. If we do decide to delete it, we have to make sure to + // note that it has already been initialized. ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + if (_tbbTaskSchedInit) { +- _tbbTaskSchedInit->terminate(); + _tbbTaskSchedInit->initialize(threadLimit); + } else { + _tbbTaskSchedInit = new tbb::task_scheduler_init(threadLimit); + } ++#else ++ kThreadLimit = threadLimit; ++ if(_tbbGlobalControl) ++ { ++ delete _tbbGlobalControl; ++ } ++ _tbbGlobalControl = new tbb::global_control(tbb::global_control::max_allowed_parallelism, threadLimit); ++#endif + } + + void +@@ -185,7 +211,11 @@ WorkSetConcurrencyLimitArgument(int n) + unsigned + WorkGetConcurrencyLimit() + { ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + return tbb::this_task_arena::max_concurrency(); ++#else ++ return kThreadLimit > 0 ? kThreadLimit: tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism); ++#endif + } + + bool +diff --git pxr/imaging/garch/pch.h pxr/imaging/garch/pch.h +index 7ef3bd8af..3b285471b 100644 +--- pxr/imaging/garch/pch.h ++++ pxr/imaging/garch/pch.h +@@ -145,7 +145,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #ifdef PXR_PYTHON_SUPPORT_ENABLED +diff --git pxr/imaging/glf/pch.h pxr/imaging/glf/pch.h +index 9a7e85a6c..787e461cf 100644 +--- pxr/imaging/glf/pch.h ++++ pxr/imaging/glf/pch.h +@@ -199,7 +199,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/imaging/hd/pch.h pxr/imaging/hd/pch.h +index 604861b7b..57c3b018c 100644 +--- pxr/imaging/hd/pch.h ++++ pxr/imaging/hd/pch.h +@@ -152,7 +152,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/imaging/hdGp/pch.h pxr/imaging/hdGp/pch.h +index bf09080c2..cb0cdd6bd 100644 +--- pxr/imaging/hdGp/pch.h ++++ pxr/imaging/hdGp/pch.h +@@ -120,7 +120,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/imaging/hdMtlx/pch.h pxr/imaging/hdMtlx/pch.h +index bf8ff6a36..7395a347f 100644 +--- pxr/imaging/hdMtlx/pch.h ++++ pxr/imaging/hdMtlx/pch.h +@@ -139,7 +139,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/imaging/hdSt/pch.h pxr/imaging/hdSt/pch.h +index 196960f7b..8692a6ad0 100644 +--- pxr/imaging/hdSt/pch.h ++++ pxr/imaging/hdSt/pch.h +@@ -170,7 +170,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/imaging/hdar/pch.h pxr/imaging/hdar/pch.h +index 56d867c1c..43c9b79e2 100644 +--- pxr/imaging/hdar/pch.h ++++ pxr/imaging/hdar/pch.h +@@ -131,7 +131,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/imaging/hdsi/pch.h pxr/imaging/hdsi/pch.h +index 1662d7e8b..f1ec0b6a4 100644 +--- pxr/imaging/hdsi/pch.h ++++ pxr/imaging/hdsi/pch.h +@@ -119,7 +119,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #ifdef PXR_PYTHON_SUPPORT_ENABLED + #include "pxr/base/tf/pySafePython.h" +diff --git pxr/imaging/hdx/pch.h pxr/imaging/hdx/pch.h +index 33ddb1b5d..2022667b3 100644 +--- pxr/imaging/hdx/pch.h ++++ pxr/imaging/hdx/pch.h +@@ -152,7 +152,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/imaging/hgiMetal/pch.h pxr/imaging/hgiMetal/pch.h +index 877bc45ee..21bd16ffa 100644 +--- pxr/imaging/hgiMetal/pch.h ++++ pxr/imaging/hgiMetal/pch.h +@@ -141,7 +141,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/imaging/plugin/hdEmbree/pch.h pxr/imaging/plugin/hdEmbree/pch.h +index 771022980..fb0e5a6ba 100644 +--- pxr/imaging/plugin/hdEmbree/pch.h ++++ pxr/imaging/plugin/hdEmbree/pch.h +@@ -154,7 +154,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/imaging/plugin/hdStorm/pch.h pxr/imaging/plugin/hdStorm/pch.h +index 33c5124a9..284efd6ca 100644 +--- pxr/imaging/plugin/hdStorm/pch.h ++++ pxr/imaging/plugin/hdStorm/pch.h +@@ -141,7 +141,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/ar/pch.h pxr/usd/ar/pch.h +index b3333376f..7303ee2a4 100644 +--- pxr/usd/ar/pch.h ++++ pxr/usd/ar/pch.h +@@ -166,7 +166,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/ndr/pch.h pxr/usd/ndr/pch.h +index 897ad796b..2b88557eb 100644 +--- pxr/usd/ndr/pch.h ++++ pxr/usd/ndr/pch.h +@@ -198,7 +198,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/pcp/mapExpression.cpp pxr/usd/pcp/mapExpression.cpp +index d8f90d7ee..f5830cc14 100644 +--- pxr/usd/pcp/mapExpression.cpp ++++ pxr/usd/pcp/mapExpression.cpp +@@ -238,7 +238,11 @@ PcpMapExpression::_Node::New( _Op op_, + // Check for existing instance to re-use + _NodeMap::accessor accessor; + if (_nodeRegistry->map.insert(accessor, key) || ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + accessor->second->_refCount.fetch_and_increment() == 0) { ++#else ++ accessor->second->_refCount.fetch_add(1, std::memory_order_relaxed) == 0) { ++#endif + // Either there was no node in the table, or there was but it had + // begun dying (another client dropped its refcount to 0). We have + // to create a new node in the table. When the client that is +@@ -388,7 +392,11 @@ intrusive_ptr_add_ref(PcpMapExpression::_Node* p) + void + intrusive_ptr_release(PcpMapExpression::_Node* p) + { ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + if (p->_refCount.fetch_and_decrement() == 1) ++#else ++ if (p->_refCount.fetch_sub(1, std::memory_order_relaxed) == 1) ++#endif + delete p; + } + +diff --git pxr/usd/pcp/mapExpression.h pxr/usd/pcp/mapExpression.h +index 9c8920141..f8f698e8f 100644 +--- pxr/usd/pcp/mapExpression.h ++++ pxr/usd/pcp/mapExpression.h +@@ -30,7 +30,9 @@ + + #include + ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + + #include +@@ -267,7 +269,11 @@ private: // data + struct _NodeMap; + static TfStaticData<_NodeMap> _nodeRegistry; + ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + mutable tbb::atomic _refCount; ++#else ++ mutable std::atomic _refCount; ++#endif + mutable Value _cachedValue; + mutable std::set<_Node*> _dependentExpressions; + Value _valueForVariable; +diff --git pxr/usd/pcp/pch.h pxr/usd/pcp/pch.h +index a7180637d..5828e4dc8 100644 +--- pxr/usd/pcp/pch.h ++++ pxr/usd/pcp/pch.h +@@ -194,7 +194,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/plugin/usdAbc/pch.h pxr/usd/plugin/usdAbc/pch.h +index f5c7e6fb6..2daa8d6d3 100644 +--- pxr/usd/plugin/usdAbc/pch.h ++++ pxr/usd/plugin/usdAbc/pch.h +@@ -206,7 +206,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/plugin/usdDraco/pch.h pxr/usd/plugin/usdDraco/pch.h +index aff99924d..a1506ac40 100644 +--- pxr/usd/plugin/usdDraco/pch.h ++++ pxr/usd/plugin/usdDraco/pch.h +@@ -169,7 +169,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/sdf/changeManager.cpp pxr/usd/sdf/changeManager.cpp +index 7ea592d04..d5b58c483 100644 +--- pxr/usd/sdf/changeManager.cpp ++++ pxr/usd/sdf/changeManager.cpp +@@ -34,7 +34,11 @@ + #include "pxr/base/tf/instantiateSingleton.h" + #include "pxr/base/tf/stackTrace.h" + ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#else ++#include ++#endif + + using std::string; + using std::vector; +@@ -150,9 +154,17 @@ Sdf_ChangeManager::_ProcessRemoveIfInert(_Data *data) + TF_VERIFY(data->outermostBlock); + } + ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + static tbb::atomic & ++#else ++static std::atomic & ++#endif + _InitChangeSerialNumber() { ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + static tbb::atomic value; ++#else ++ static std::atomic value; ++#endif + value = 1; + return value; + } +@@ -191,8 +203,14 @@ Sdf_ChangeManager::_SendNotices(_Data *data) + } + + // Obtain a serial number for this round of change processing. ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + static tbb::atomic &changeSerialNumber = _InitChangeSerialNumber(); + size_t serialNumber = changeSerialNumber.fetch_and_increment(); ++#else ++ static std::atomic &changeSerialNumber = _InitChangeSerialNumber(); ++ size_t serialNumber = changeSerialNumber.fetch_add(1, std::memory_order_relaxed); ++#endif ++ + + // Send global notice. + SdfNotice::LayersDidChange(changes, serialNumber).Send(); +diff --git pxr/usd/sdf/pch.h pxr/usd/sdf/pch.h +index 0728ebe68..4ee12b616 100644 +--- pxr/usd/sdf/pch.h ++++ pxr/usd/sdf/pch.h +@@ -225,7 +225,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usd/crateData.cpp pxr/usd/usd/crateData.cpp +index 9fc96b377..41c086f18 100644 +--- pxr/usd/usd/crateData.cpp ++++ pxr/usd/usd/crateData.cpp +@@ -803,8 +803,11 @@ private: + TfAutoMallocTag tag("field data"); + auto &fieldValuePairs = + liveFieldSets[FieldSetIndex(fsBegin-fieldSets.begin())]; +- ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ TaskOpenFieldData task(this, _crateFile.get(), fsBegin, fsEnd, fields, fieldValuePairs); ++#endif + dispatcher.Run( ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + [this, fsBegin, fsEnd, &fields, &fieldValuePairs]() mutable { + try{ + // XXX Won't need first two tags when bug #132031 is +@@ -826,7 +829,11 @@ private: + } catch (...) { + TF_RUNTIME_ERROR("Encountered unknown exception"); + } +- }); ++ } ++#else ++ task ++#endif ++ ); + } + + dispatcher.Wait(); +@@ -1058,6 +1065,56 @@ private: + SdfSpecType specType; + }; + ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ struct TaskOpenFieldData { ++ typedef std::pair FieldValuePair; ++ typedef Usd_Shared<_FieldValuePairVector> SharedFieldValuePairVector; ++ TaskOpenFieldData(Usd_CrateDataImpl* owner, CrateFile* crateFile, vector::iterator begin, vector::iterator end, ++ vector &fields, SharedFieldValuePairVector &fieldValuePairs) ++ :m_owner(owner), ++ m_crateFile(crateFile), ++ m_begin(begin), ++ m_end(end), ++ m_fields(fields), ++ m_fieldValuePairs(fieldValuePairs) ++ { ++ ++ } ++ ++ void operator()() const { ++ try{ ++ // XXX Won't need first two tags when bug #132031 is ++ // addressed ++ TfAutoMallocTag tag( ++ "Usd", "Usd_CrateDataImpl::Open", "field data"); ++ auto &pairs = m_fieldValuePairs.GetMutable(); ++ vector::const_iterator begin = m_begin; ++ pairs.resize(m_end-begin); ++ for (size_t i = 0; begin != m_end; ++begin, ++i) { ++ auto const &field = m_fields[begin->value]; ++ pairs[i].first = ++ m_crateFile->GetToken(field.tokenIndex); ++ pairs[i].second = m_owner->_UnpackForField(field.valueRep); ++ } ++ } catch (const std::exception &e){ ++ TF_RUNTIME_ERROR("Encountered exception: %s %s", ++ e.what(), m_crateFile->GetAssetPath().c_str()); ++ ++ } catch (...) { ++ TF_RUNTIME_ERROR("Encountered unknown exception"); ++ } ++ } ++ ++ private: ++ Usd_CrateDataImpl *m_owner; ++ CrateFile *m_crateFile; ++ vector::iterator m_begin; ++ vector::iterator m_end; ++ vector m_fields; ++ SharedFieldValuePairVector m_fieldValuePairs; ++ }; ++#endif ++ + using _HashMap = pxr_tsl::robin_map< + SdfPath, _SpecData, SdfPath::Hash, std::equal_to, + std::allocator>, +diff --git pxr/usd/usd/crateFile.cpp pxr/usd/usd/crateFile.cpp +index 333a3edfb..db438bef0 100644 +--- pxr/usd/usd/crateFile.cpp ++++ pxr/usd/usd/crateFile.cpp +@@ -3700,6 +3700,7 @@ CrateFile::_ReadPathsImpl(Reader reader, + if (hasSibling) { + // Branch off a parallel task for the sibling subtree. + auto siblingOffset = reader.template Read(); ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + dispatcher.Run( + [this, reader, + siblingOffset, &dispatcher, parentPath]() mutable { +@@ -3710,6 +3711,10 @@ CrateFile::_ReadPathsImpl(Reader reader, + reader.Seek(siblingOffset); + _ReadPathsImpl
(reader, dispatcher, parentPath); + }); ++#else ++ TaskReadPath task(this, &reader, siblingOffset, &dispatcher, parentPath); ++ dispatcher.Run(task); ++#endif + } + // Have a child (may have also had a sibling). Reset parent path. + parentPath = _paths[h.index.value]; +@@ -3836,6 +3841,7 @@ CrateFile::_BuildDecompressedPathsImpl( + return; + } + #endif ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + dispatcher.Run( + [this, &pathIndexes, &elementTokenIndexes, &jumps, + siblingIndex, &dispatcher, parentPath]() mutable { +@@ -3847,6 +3853,10 @@ CrateFile::_BuildDecompressedPathsImpl( + pathIndexes, elementTokenIndexes, jumps, + siblingIndex, parentPath, dispatcher); + }); ++#else ++ TaskBuildDecompressedpath task(this, pathIndexes, elementTokenIndexes, jumps, siblingIndex, &dispatcher, parentPath); ++ dispatcher.Run(task); ++#endif + } + // Have a child (may have also had a sibling). Reset parent path. + parentPath = _paths[pathIndexes[thisIndex]]; +diff --git pxr/usd/usd/crateFile.h pxr/usd/usd/crateFile.h +index 67b1aa385..864e7c38d 100644 +--- pxr/usd/usd/crateFile.h ++++ pxr/usd/usd/crateFile.h +@@ -338,10 +338,29 @@ private: + class _Impl { + friend class _FileMapping; + ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ class tbb_hash ++ { ++ public: ++ tbb_hash() {} ++ ++ template ++ std::size_t operator () (const Key& z) const ++ { ++ return TfHash::Combine( ++ reinterpret_cast(z.GetAddr()), ++ z.GetNumBytes() ++ ); ++ } ++ }; ++#endif ++ + // This is a foreign data source for VtArray that refers into a + // memory-mapped region, and shares in the lifetime of the mapping. + struct ZeroCopySource : public Vt_ArrayForeignDataSource { +- explicit ZeroCopySource(_Impl *m, ++ ZeroCopySource() = default; ++ ++ ZeroCopySource(_Impl *m, + void const *addr, + size_t numBytes); + +@@ -422,7 +441,11 @@ private: + ArchConstFileMapping _mapping; + char const *_start; + int64_t _length; ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ tbb::concurrent_unordered_set _outstandingRanges; ++#else + tbb::concurrent_unordered_set _outstandingRanges; ++#endif + }; + + public: +@@ -666,6 +689,69 @@ public: + SdfSpecType specType; + }; + ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ template ++ struct TaskReadPath { ++ TaskReadPath(CrateFile* owner, Reader *reader, int64_t offset, WorkDispatcher* dispatcher, SdfPath path) ++ :m_owner(owner), ++ m_reader(reader), ++ m_offset(offset), ++ m_dispatcher(dispatcher), ++ m_path(path) ++ { ++ ++ } ++ ++ void operator()() const{ ++ TfAutoMallocTag tag( ++ "Usd", "Usd_CrateDataImpl::Open", ++ "Usd_CrateFile::CrateFile::Open", "_ReadPaths"); ++ m_reader->Seek(m_offset); ++ m_owner->_ReadPathsImpl
(*m_reader, *m_dispatcher, m_path); ++ } ++ ++ private: ++ CrateFile *m_owner = nullptr; ++ Reader *m_reader; ++ int64_t m_offset = 0; ++ WorkDispatcher *m_dispatcher = nullptr; ++ SdfPath m_path; ++ }; ++ ++ struct TaskBuildDecompressedpath { ++ TaskBuildDecompressedpath(CrateFile* owner, vector const &pathIndexes, vector const &elementTokenIndexes, vector const &jumps, ++ int64_t offset, WorkDispatcher* dispatcher, SdfPath path) ++ :m_owner(owner), ++ m_pathIndexes(pathIndexes), ++ m_elementTokenIndexes(elementTokenIndexes), ++ m_jumps(jumps), ++ m_offset(offset), ++ m_dispatcher(dispatcher), ++ m_path(path) ++ { ++ ++ } ++ ++ void operator()() const{ ++ TfAutoMallocTag tag( ++ "Usd", "Usd_CrateDataImpl::Open", ++ "Usd_CrateFile::CrateFile::Open", "_ReadPaths"); ++ m_owner->_BuildDecompressedPathsImpl( ++ m_pathIndexes, m_elementTokenIndexes, m_jumps, ++ m_offset, m_path, *m_dispatcher); ++ } ++ ++ private: ++ CrateFile *m_owner = nullptr; ++ vector m_pathIndexes; ++ vector m_elementTokenIndexes; ++ vector m_jumps; ++ int64_t m_offset = 0; ++ WorkDispatcher *m_dispatcher = nullptr; ++ SdfPath m_path; ++ }; ++#endif ++ + ~CrateFile(); + + static bool CanRead(string const &assetPath); +diff --git pxr/usd/usd/pch.h pxr/usd/usd/pch.h +index d360999d4..00b77d42f 100644 +--- pxr/usd/usd/pch.h ++++ pxr/usd/usd/pch.h +@@ -227,7 +227,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdGeom/bboxCache.cpp pxr/usd/usdGeom/bboxCache.cpp +index 454f97bcb..428e3697c 100644 +--- pxr/usd/usdGeom/bboxCache.cpp ++++ pxr/usd/usdGeom/bboxCache.cpp +@@ -49,6 +49,12 @@ + + PXR_NAMESPACE_OPEN_SCOPE + ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++#define TBB_TASK_CONST const ++#else ++#define TBB_TASK_CONST ++#endif ++ + namespace { + + // For code that knows at compile time whether we need to apply a transform. +@@ -99,9 +105,13 @@ public: + explicit operator bool() const { + return _owner; + } +- void operator()() { ++ void operator()() TBB_TASK_CONST { + // Do not save state here; all state should be accumulated externally. ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ _owner->_ResolvePrim(const_cast<_BBoxTask*>(this), _primContext, _inverseComponentCtm); ++#else + _owner->_ResolvePrim(this, _primContext, _inverseComponentCtm); ++#endif + } + _ThreadXformCache* GetXformCaches() { return _xfCaches; } + }; +@@ -126,9 +136,21 @@ private: + { + _PrototypeTask() : numDependencies(0) { } + ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ _PrototypeTask(const _PrototypeTask& other) ++ { ++ dependentPrototypes = other.dependentPrototypes; ++ numDependencies.store(other.numDependencies.load(std::memory_order_relaxed), std::memory_order_relaxed); ++ } ++#endif ++ + // Number of dependencies -- prototype prims that must be resolved + // before this prototype can be resolved. ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ std::atomic numDependencies; ++#else + tbb::atomic numDependencies; ++#endif + + // List of prototype prims that depend on this prototype. + std::vector<_PrimContext> dependentPrototypes; +@@ -172,9 +194,17 @@ private: + void _PopulateTasksForPrototype(const _PrimContext& prototypePrim, + _PrototypeTaskMap* prototypeTasks) + { ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ const std::pair pair = std::make_pair( ++ std::ref(prototypePrim), _PrototypeTask() ++ ); ++ std::pair<_PrototypeTaskMap::iterator, bool> prototypeTaskStatus = ++ prototypeTasks->insert(pair); ++#else + std::pair<_PrototypeTaskMap::iterator, bool> prototypeTaskStatus = +- prototypeTasks->insert(std::make_pair( ++ prototypeTasks->insert(std::make_pair( + prototypePrim, _PrototypeTask())); ++#endif + if (!prototypeTaskStatus.second) { + return; + } +@@ -220,7 +250,11 @@ private: + _PrototypeTask& dependentPrototypeData = + prototypeTasks->find(dependentPrototype)->second; + if (dependentPrototypeData.numDependencies ++#ifdef PXR_ONETBB_SUPPORT_ENABLED ++ .fetch_sub(1, std::memory_order_relaxed) == 1){ ++#else + .fetch_and_decrement() == 1){ ++#endif + dispatcher->Run( + &_PrototypeBBoxResolver::_ExecuteTaskForPrototype, + this, dependentPrototype, prototypeTasks, xfCaches, +diff --git pxr/usd/usdGeom/pch.h pxr/usd/usdGeom/pch.h +index 824c5b0f9..8fd26001f 100644 +--- pxr/usd/usdGeom/pch.h ++++ pxr/usd/usdGeom/pch.h +@@ -181,7 +181,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdHydra/pch.h pxr/usd/usdHydra/pch.h +index 5ba9df4c2..bf8da3d43 100644 +--- pxr/usd/usdHydra/pch.h ++++ pxr/usd/usdHydra/pch.h +@@ -162,7 +162,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdLux/pch.h pxr/usd/usdLux/pch.h +index 8fe34cb95..53493fce2 100644 +--- pxr/usd/usdLux/pch.h ++++ pxr/usd/usdLux/pch.h +@@ -177,7 +177,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdMedia/pch.h pxr/usd/usdMedia/pch.h +index 7802ec3e2..1cf939142 100644 +--- pxr/usd/usdMedia/pch.h ++++ pxr/usd/usdMedia/pch.h +@@ -170,7 +170,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdMtlx/pch.h pxr/usd/usdMtlx/pch.h +index 5eba44e7e..74eae71fa 100644 +--- pxr/usd/usdMtlx/pch.h ++++ pxr/usd/usdMtlx/pch.h +@@ -193,7 +193,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdPhysics/pch.h pxr/usd/usdPhysics/pch.h +index 824c5b0f9..8fd26001f 100644 +--- pxr/usd/usdPhysics/pch.h ++++ pxr/usd/usdPhysics/pch.h +@@ -181,7 +181,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdProc/pch.h pxr/usd/usdProc/pch.h +index f40455a1c..4b0085676 100644 +--- pxr/usd/usdProc/pch.h ++++ pxr/usd/usdProc/pch.h +@@ -165,7 +165,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdRender/pch.h pxr/usd/usdRender/pch.h +index 7802ec3e2..1cf939142 100644 +--- pxr/usd/usdRender/pch.h ++++ pxr/usd/usdRender/pch.h +@@ -170,7 +170,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdRi/pch.h pxr/usd/usdRi/pch.h +index 905d2a123..4f59dd994 100644 +--- pxr/usd/usdRi/pch.h ++++ pxr/usd/usdRi/pch.h +@@ -173,7 +173,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdShade/pch.h pxr/usd/usdShade/pch.h +index 698ab0ca6..720ca3f0d 100644 +--- pxr/usd/usdShade/pch.h ++++ pxr/usd/usdShade/pch.h +@@ -179,7 +179,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdSkel/pch.h pxr/usd/usdSkel/pch.h +index a4205ac46..5836259c3 100644 +--- pxr/usd/usdSkel/pch.h ++++ pxr/usd/usdSkel/pch.h +@@ -180,7 +180,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdUI/pch.h pxr/usd/usdUI/pch.h +index 47666439a..507bf5a06 100644 +--- pxr/usd/usdUI/pch.h ++++ pxr/usd/usdUI/pch.h +@@ -168,7 +168,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdUtils/pch.h pxr/usd/usdUtils/pch.h +index 3a108ee5e..31e73f23e 100644 +--- pxr/usd/usdUtils/pch.h ++++ pxr/usd/usdUtils/pch.h +@@ -215,7 +215,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usd/usdVol/pch.h pxr/usd/usdVol/pch.h +index 7802ec3e2..1cf939142 100644 +--- pxr/usd/usdVol/pch.h ++++ pxr/usd/usdVol/pch.h +@@ -170,7 +170,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usdImaging/usdAppUtils/pch.h pxr/usdImaging/usdAppUtils/pch.h +index 70b9602d5..15b906455 100644 +--- pxr/usdImaging/usdAppUtils/pch.h ++++ pxr/usdImaging/usdAppUtils/pch.h +@@ -173,7 +173,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usdImaging/usdImaging/pch.h pxr/usdImaging/usdImaging/pch.h +index 35ea5620e..d46bb736c 100644 +--- pxr/usdImaging/usdImaging/pch.h ++++ pxr/usdImaging/usdImaging/pch.h +@@ -173,7 +173,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usdImaging/usdImagingGL/pch.h pxr/usdImaging/usdImagingGL/pch.h +index b9dfa7e41..17ca7465c 100644 +--- pxr/usdImaging/usdImagingGL/pch.h ++++ pxr/usdImaging/usdImagingGL/pch.h +@@ -186,7 +186,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usdImaging/usdProcImaging/pch.h pxr/usdImaging/usdProcImaging/pch.h +index 32358e284..3c5f46010 100644 +--- pxr/usdImaging/usdProcImaging/pch.h ++++ pxr/usdImaging/usdProcImaging/pch.h +@@ -161,7 +161,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usdImaging/usdRiPxrImaging/pch.h pxr/usdImaging/usdRiPxrImaging/pch.h +index 6ad2d403b..e244541df 100644 +--- pxr/usdImaging/usdRiPxrImaging/pch.h ++++ pxr/usdImaging/usdRiPxrImaging/pch.h +@@ -169,7 +169,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usdImaging/usdSkelImaging/pch.h pxr/usdImaging/usdSkelImaging/pch.h +index 69caaac23..39fcc7f11 100644 +--- pxr/usdImaging/usdSkelImaging/pch.h ++++ pxr/usdImaging/usdSkelImaging/pch.h +@@ -169,7 +169,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usdImaging/usdVolImaging/pch.h pxr/usdImaging/usdVolImaging/pch.h +index 0fd54d571..410b8b4e3 100644 +--- pxr/usdImaging/usdVolImaging/pch.h ++++ pxr/usdImaging/usdVolImaging/pch.h +@@ -167,7 +167,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include +diff --git pxr/usdImaging/usdviewq/pch.h pxr/usdImaging/usdviewq/pch.h +index 2b6f4d782..fa6057600 100644 +--- pxr/usdImaging/usdviewq/pch.h ++++ pxr/usdImaging/usdviewq/pch.h +@@ -164,7 +164,9 @@ + #include + #include + #include ++#ifndef PXR_ONETBB_SUPPORT_ENABLED + #include ++#endif + #include + #include + #include diff --git a/tools/workspace/openusd_internal/repository.bzl b/tools/workspace/openusd_internal/repository.bzl new file mode 100644 index 000000000000..89d63e95b31b --- /dev/null +++ b/tools/workspace/openusd_internal/repository.bzl @@ -0,0 +1,16 @@ +load("//tools/workspace:github.bzl", "github_archive") + +def openusd_internal_repository( + name, + mirrors = None): + github_archive( + name = name, + repository = "PixarAnimationStudios/OpenUSD", + commit = "v23.11", + sha256 = "2add389b121568f3dfb9b7e4f4551a6c8445ae353f1725a0753c8ce5639c4f83", # noqa + build_file = ":package.BUILD.bazel", + patches = [ + ":patches/onetbb.patch", + ], + mirrors = mirrors, + )