Skip to content

Commit a1d3e96

Browse files
committed
[wasm] Add wasm support for building pxr/usd
- Enable usd folder in pxr/CMakeLists.txt - Make appropriate changes to calculate the size of `Sdf_SizeofPropPathNode` and `Sdf_SizeofPrimPathNode` - Fix static checks to adapt to the architecture type The following tests fail under wasm due to issues finding the pluging information in the filesystem or the fact that we are building a static library: ``` testArDefaultResolver_CPP testArThreadedAssetCreation testSdfAttributeBlocking_Cpp testSdfHardToReach testSdfLayerHints testSdfMetaDataPlugInfo testSdfTextFile testSdfTextFile_1.1 testSdfZipFile_CPP testSdfUsdzResolver testPcpIterator testPcpPathTranslation_HardToReach testPcpHardToReach testUsdAttributeBlockingCpp testUsdAttributeInterpolationCpp testUsdAttributeLimitsCpp testUsdCreateAttributeCpp testUsdHardToReach testUsdTemplatedIO testUsdPrimGetDescendants testUsdInstancingCpp testUsdMetadataCpp testUsdStageNoPython testUsdStageNotification testUsdStageThreading testUsdThreadedAuthoring testUsdResolveTarget testUsdSchemaBase testUsdSchemaRegistryCpp testUsdTimeValueAuthoringCpp testUsdSplinesCpp testUsdUsdzBugGHSA01 testUsdUsdcBugGHSA02 testUsdGeomCreateAttribute testUsdGeomIsA testUsdGeomHasAPI testUsdGeomXformCache testUsdShadeHasConnectableAPI testUsdUIAccessibilityAPI ```
1 parent ecea8d8 commit a1d3e96

File tree

13 files changed

+263
-178
lines changed

13 files changed

+263
-178
lines changed

pxr/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ pxr_core_prologue()
22

33
add_subdirectory(external)
44
add_subdirectory(base)
5-
if (NOT EMSCRIPTEN)
6-
add_subdirectory(usd)
7-
endif()
5+
add_subdirectory(usd)
86

97
if (${PXR_BUILD_EXEC})
108
add_subdirectory(exec)

pxr/usd/ar/CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,6 @@ pxr_register_test(testArDefaultResolver
265265
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArDefaultResolver"
266266
)
267267

268-
pxr_register_test(testArDefaultResolver_CPP
269-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArDefaultResolver_CPP"
270-
)
271-
272268
pxr_register_test(testArOpenAsset
273269
PYTHON
274270
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArOpenAsset"
@@ -298,6 +294,15 @@ pxr_register_test(testArResolverContext_CPP
298294
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArResolverContext_CPP"
299295
)
300296

301-
pxr_register_test(testArThreadedAssetCreation
302-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArThreadedAssetCreation"
303-
)
297+
# Note the following tests are disabled when building for emscripten due to
298+
# plugin loading failures. Emscripten cannot locate plugInfo.json files for
299+
# ArDefaultResolver in the virtual filesystem.
300+
if (NOT EMSCRIPTEN)
301+
pxr_register_test(testArDefaultResolver_CPP
302+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArDefaultResolver_CPP"
303+
)
304+
305+
pxr_register_test(testArThreadedAssetCreation
306+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArThreadedAssetCreation"
307+
)
308+
endif()

pxr/usd/pcp/CMakeLists.txt

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,22 +2065,11 @@ pxr_register_test(testPcpMuseum_VariantSpecializesAndReference
20652065
DIFF_COMPARE compositionResults_VariantSpecializesAndReference.txt
20662066
)
20672067

2068-
pxr_register_test(testPcpIterator
2069-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpIterator"
2070-
DIFF_COMPARE iteration_results.txt
2071-
EXPECTED_RETURN_CODE 0
2072-
)
2073-
20742068
pxr_register_test(testPcpMapExpression
20752069
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpMapExpression"
20762070
EXPECTED_RETURN_CODE 0
20772071
)
20782072

2079-
pxr_register_test(testPcpPathTranslation_HardToReach
2080-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpPathTranslation_HardToReach"
2081-
EXPECTED_RETURN_CODE 0
2082-
)
2083-
20842073
pxr_register_test(testPcpCache
20852074
PYTHON
20862075
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCache"
@@ -2099,10 +2088,26 @@ pxr_register_test(testPcpDependencies
20992088
EXPECTED_RETURN_CODE 0
21002089
)
21012090

2102-
pxr_register_test(testPcpHardToReach
2103-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpHardToReach"
2104-
EXPECTED_RETURN_CODE 0
2105-
)
2091+
# Note the following tests are disabled when building for emscripten due to
2092+
# plugin loading failures. Emscripten cannot locate plugInfo.json files in
2093+
# the virtual filesystem.
2094+
if (NOT EMSCRIPTEN)
2095+
pxr_register_test(testPcpIterator
2096+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpIterator"
2097+
DIFF_COMPARE iteration_results.txt
2098+
EXPECTED_RETURN_CODE 0
2099+
)
2100+
2101+
pxr_register_test(testPcpPathTranslation_HardToReach
2102+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpPathTranslation_HardToReach"
2103+
EXPECTED_RETURN_CODE 0
2104+
)
2105+
2106+
pxr_register_test(testPcpHardToReach
2107+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpHardToReach"
2108+
EXPECTED_RETURN_CODE 0
2109+
)
2110+
endif()
21062111

21072112
pxr_register_test(testPcpInstanceKey
21082113
PYTHON

pxr/usd/sdf/CMakeLists.txt

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,6 @@ pxr_register_test(testSdfAttributeBlocking
535535
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfAttributeBlocking"
536536
)
537537

538-
pxr_register_test(testSdfAttributeBlocking_Cpp
539-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfAttributeBlocking_Cpp"
540-
)
541-
542538
pxr_register_test(testSdfBatchNamespaceEdit
543539
PYTHON
544540
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfBatchNamespaceEdit"
@@ -579,10 +575,6 @@ pxr_register_test(testSdfDetachedLayerEnvVar2
579575
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfDetachedLayer"
580576
)
581577

582-
pxr_register_test(testSdfHardToReach
583-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfHardToReach"
584-
)
585-
586578
pxr_register_test(testSdfFileFormat
587579
PYTHON
588580
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfFileFormat"
@@ -603,10 +595,6 @@ pxr_register_test(testSdfLayer
603595
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfLayer"
604596
)
605597

606-
pxr_register_test(testSdfLayerHints
607-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfLayerHints"
608-
)
609-
610598
pxr_register_test(testSdfLayerMuting
611599
PYTHON
612600
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfLayerMuting"
@@ -631,10 +619,6 @@ pxr_register_test(testSdfListOp
631619
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfListOp"
632620
)
633621

634-
pxr_register_test(testSdfMetaDataPlugInfo
635-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfMetaDataPlugInfo"
636-
)
637-
638622
pxr_register_test(testSdfPathExpression
639623
PYTHON
640624
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfPathExpression"
@@ -720,16 +704,6 @@ pxr_register_test(testSdfTargetFileFormat
720704
PYTHON
721705
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfTargetFileFormat"
722706
)
723-
pxr_register_test(testSdfTextFile
724-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfTextFile"
725-
EXPECTED_RETURN_CODE 0
726-
)
727-
pxr_register_test(testSdfTextFile_1.1
728-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfTextFile"
729-
EXPECTED_RETURN_CODE 0
730-
ENV
731-
USD_WRITE_NEW_USDA_FILES_AS_VERSION=1.1
732-
)
733707
pxr_register_test(testSdfTimeCode
734708
PYTHON
735709
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfTimeCode"
@@ -750,14 +724,6 @@ pxr_register_test(testSdfZipFileLimits
750724
ENV
751725
SDF_MAX_ZIPFILE_SIZE=195
752726
)
753-
pxr_register_test(testSdfZipFile_CPP
754-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfZipFile_CPP"
755-
EXPECTED_RETURN_CODE 0
756-
)
757-
pxr_register_test(testSdfUsdzResolver
758-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfUsdzResolver"
759-
EXPECTED_RETURN_CODE 0
760-
)
761727
pxr_register_test(testSdfVariableExpression
762728
PYTHON
763729
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfVariableExpression"
@@ -780,3 +746,46 @@ pxr_register_test(testSdfUsdcInvalidPrimChildren
780746
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfUsdcInvalidPrimChildren"
781747
EXPECTED_RETURN_CODE 0
782748
)
749+
750+
# Note the following tests are disabled when building for emscripten due to
751+
# plugin loading failures. These tests fail because Emscripten cannot locate
752+
# plugInfo.json files in the virtual filesystem.
753+
if (NOT EMSCRIPTEN)
754+
pxr_register_test(testSdfAttributeBlocking_Cpp
755+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfAttributeBlocking_Cpp"
756+
)
757+
758+
pxr_register_test(testSdfHardToReach
759+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfHardToReach"
760+
)
761+
762+
pxr_register_test(testSdfLayerHints
763+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfLayerHints"
764+
)
765+
766+
pxr_register_test(testSdfMetaDataPlugInfo
767+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfMetaDataPlugInfo"
768+
)
769+
770+
pxr_register_test(testSdfTextFile
771+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfTextFile"
772+
EXPECTED_RETURN_CODE 0
773+
)
774+
775+
pxr_register_test(testSdfTextFile_1.1
776+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfTextFile"
777+
EXPECTED_RETURN_CODE 0
778+
ENV
779+
USD_WRITE_NEW_USDA_FILES_AS_VERSION=1.1
780+
)
781+
782+
pxr_register_test(testSdfZipFile_CPP
783+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfZipFile_CPP"
784+
EXPECTED_RETURN_CODE 0
785+
)
786+
787+
pxr_register_test(testSdfUsdzResolver
788+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testSdfUsdzResolver"
789+
EXPECTED_RETURN_CODE 0
790+
)
791+
endif()

pxr/usd/sdf/path.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ void TfDelegatedCountDecrement(Sdf_PathNode const *) noexcept;
4545
struct Sdf_PathPrimTag;
4646
struct Sdf_PathPropTag;
4747

48+
// SdfPath always contains two 32-bit handles (primPart and propPart), regardless of architecture.
49+
static constexpr size_t Sdf_SizeofSdfPath = 2 * sizeof(uint32_t);
50+
4851
// These are validated below.
49-
static constexpr size_t Sdf_SizeofPrimPathNode = sizeof(void *) * 3;
50-
static constexpr size_t Sdf_SizeofPropPathNode = sizeof(void *) * 3;
52+
static constexpr size_t Sdf_SizeofPrimPathNode = sizeof(TfToken) + 2 * sizeof(unsigned int) + sizeof(void*);
53+
// Property nodes can have either TfToken or SdfPath members. SdfPath (8 bytes) is larger than
54+
// TfToken (4 bytes) on 32-bit architectures. Use the larger size to accommodate all node types.
55+
static constexpr size_t Sdf_SizeofPropPathNode =
56+
(sizeof(TfToken) > Sdf_SizeofSdfPath ? sizeof(TfToken) : Sdf_SizeofSdfPath) + 2 * sizeof(unsigned int) + sizeof(void*);
5157

5258
using Sdf_PathPrimPartPool = Sdf_Pool<
5359
Sdf_PathPrimTag, Sdf_SizeofPrimPathNode, /*regionBits=*/8>;
@@ -1424,7 +1430,11 @@ PXR_NAMESPACE_CLOSE_SCOPE
14241430
PXR_NAMESPACE_OPEN_SCOPE
14251431

14261432
static_assert(Sdf_SizeofPrimPathNode == sizeof(Sdf_PrimPathNode), "");
1427-
static_assert(Sdf_SizeofPropPathNode == sizeof(Sdf_PrimPropertyPathNode), "");
1433+
// Property pool must be sized for the largest property node type.
1434+
// Sdf_TargetPathNode has an SdfPath member (8 bytes) which is larger than TfToken (4 bytes on 32-bit).
1435+
static_assert(Sdf_SizeofPropPathNode >= sizeof(Sdf_PrimPropertyPathNode), "");
1436+
static_assert(Sdf_SizeofPropPathNode >= sizeof(Sdf_RelationalAttributePathNode), "");
1437+
static_assert(Sdf_SizeofPropPathNode >= sizeof(Sdf_TargetPathNode), "");
14281438

14291439
PXR_NAMESPACE_CLOSE_SCOPE
14301440

pxr/usd/sdf/pathNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ SDF_INSTANTIATE_POOL(Sdf_PathPropTag, Sdf_SizeofPropPathNode, /*regionBits=*/8);
3838

3939
// Size of path nodes is important, so we want the compiler to tell us if it
4040
// changes.
41-
static_assert(sizeof(Sdf_PrimPathNode) == 3 * sizeof(void *), "");
42-
static_assert(sizeof(Sdf_PrimPropertyPathNode) == 3 * sizeof(void *), "");
41+
static_assert(sizeof(Sdf_PrimPathNode) == sizeof(TfToken) + 2 * sizeof(unsigned int) + sizeof(void*), "");
42+
static_assert(sizeof(Sdf_PrimPropertyPathNode) == sizeof(TfToken) + 2 * sizeof(unsigned int) + sizeof(void*), "");
4343

4444
struct Sdf_PathNodePrivateAccess
4545
{

pxr/usd/sdr/declare.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class SdrVersion {
109109
SDR_API
110110
std::size_t GetHash() const
111111
{
112-
return (static_cast<std::size_t>(_major) << 32) +
112+
return (static_cast<std::size_t>(_major) << (sizeof(std::size_t) * 4)) +
113113
static_cast<std::size_t>(_minor);
114114
}
115115

0 commit comments

Comments
 (0)