Skip to content

Commit

Permalink
[usd] Add test for usdz O(n^2) performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
marsupial committed Jul 29, 2021
1 parent 48b98a4 commit 2d30f0e
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pxr/usd/usd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ pxr_build_test(testUsdUsdzResolver
testenv/testUsdUsdzResolver.cpp
)

pxr_build_test(testUsdUsdzLargeArchive
LIBRARIES
tf
usd
usdGeom
CPPFILES
testenv/testUsdUsdzLargeArchive.cpp
)

pxr_install_test_dir(
SRC testenv/testUsdAppliedAPISchemas
DEST testUsdAppliedAPISchemas
Expand Down Expand Up @@ -646,6 +655,11 @@ pxr_install_test_dir(
DEST testUsdZipFile
)

pxr_install_test_dir(
SRC testenv/testUsdUsdzLargeArchive
DEST testUsdUsdzLargeArchive
)

pxr_register_test(testUsdAppliedAPISchemas
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdAppliedAPISchemas"
Expand Down Expand Up @@ -1084,3 +1098,7 @@ pxr_register_test(testUsdUsdzResolver
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUsdzResolver"
EXPECTED_RETURN_CODE 0
)
pxr_register_test(testUsdUsdzLargeArchive
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUsdzLargeArchive"
EXPECTED_RETURN_CODE 0
)
106 changes: 106 additions & 0 deletions pxr/usd/usd/testenv/testUsdUsdzLargeArchive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// Copyright 2021 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//

#include "pxr/pxr.h"

#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdGeom/mesh.h"

#include <ctime>
#include <iostream>

PXR_NAMESPACE_USING_DIRECTIVE;

static bool
AttributesEqual(UsdAttribute a, UsdAttribute b)
{
if (a.IsValid() != b.IsValid()) {
return false;
}
if (!a.IsValid()) {
return true;
}
VtValue va, vb;
if (!a.Get(&va) || !b.Get(&vb)) {
return false;
}
return va == vb;
}

// Test that calling ArResolver::OpenAsset on a file within a .usdz
// file produces the expected result.
static void
TestOpenLargeArchive()
{
std::cout << "TestOpenLargeArchive...";
const std::string usdzFile("test.usdz");
const auto startTime = std::clock();
auto stage = UsdStage::Open(usdzFile);
const auto endTime = std::clock();

// Testing the time to open is possibly not the greatest, but the file in question
// took over 15 seconds without caching, and less than 2.5 seconds with;
// So conservatively, we should be able to open it in 5 seconds in processor time ?
//
const auto elapsedTime = float(endTime - startTime) / CLOCKS_PER_SEC;
std::cout << "stage creation took " << elapsedTime << std::endl;

if (!stage) {
TF_FATAL_ERROR("Failed to load stage at '%s'", usdzFile.c_str());
}
if (elapsedTime > 5.f) {
TF_FATAL_ERROR("Open of '%s' took %f seconds in proc time", usdzFile.c_str(), elapsedTime);
}

UsdPrim scene = stage->GetPrimAtPath(SdfPath("/scene"));
TF_AXIOM(scene);

UsdGeomMesh baseMesh;
size_t numChildren = 0;
for (UsdPrim child : scene.GetAllChildren()) {
TF_AXIOM(child.IsA<UsdGeomMesh>());

UsdGeomMesh mesh(child);
if (baseMesh) {
TF_AXIOM(AttributesEqual(baseMesh.GetFaceVertexCountsAttr(), mesh.GetFaceVertexCountsAttr()));
TF_AXIOM(AttributesEqual(baseMesh.GetFaceVertexIndicesAttr(), mesh.GetFaceVertexIndicesAttr()));
TF_AXIOM(AttributesEqual(baseMesh.GetPointsAttr(), mesh.GetPointsAttr()));
TF_AXIOM(AttributesEqual(baseMesh.GetSubdivisionSchemeAttr(), mesh.GetSubdivisionSchemeAttr()));
}
else {
baseMesh = std::move(mesh);
}
++numChildren;
}
TF_AXIOM(numChildren == 25000);
}

int main(int argc, char** argv)
{
TestOpenLargeArchive();

std::cout << "Passed!" << std::endl;

return EXIT_SUCCESS;
}
Binary file not shown.

0 comments on commit 2d30f0e

Please sign in to comment.