Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usdValidation: usdUtils: CompressionValidator #3449

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

beersandrew
Copy link
Contributor

@beersandrew beersandrew commented Dec 3, 2024

Description of Change(s)

Link to proposal (if applicable)

Fixes Issue(s)

Note: This PR is a replacement for #3400

Checklist

[X] I have created this PR based on the dev branch

[X] I have followed the coding conventions

[X] I have added unit tests that exercise this functionality (Reference:
testing guidelines)

[X] I have verified that all unit tests pass with the proposed changes

[X] I have submitted a signed Contributor License Agreement (Reference:
Contributor License Agreement instructions)

@@ -97,12 +98,55 @@ _PackageEncapsulationValidator(const UsdStagePtr &usdStage)
return errors;
}

static UsdValidationErrorVector
_CompressionValidator(const UsdStagePtr& usdStage) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tallytalwar I've come across something in this validator that's not clear to me.

My expectation from reading the description from the existing CompressionChecker is that this test should make sure that files within the USDZ file itself were not compressed. So I've created a sample file like this (in this repo as compressedUsdaInside.usdz). However this file fails here, before it can get to the usdchecker code.

If I try a different approach of compressing the usdz itself, it also fails early here.

Do you know how to reproduce the nicer errors from usdchecker itself? (Similar situation with ByteAlignmentChecker as well)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why its failing on parsing the "compressed" "usda" file is because I think usda extension makes it load the usda file plugin, which when parsing tries to see if the file header has the usda magic cookie and if not it fails. If you stick with this approach only maybe use a different extension for this file.
  2. usdz is an archival format, so the code checks if it has any compression on it or not.

Maybe add a compressed asset to usdz file like a compressed jpeg/png?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried compressing a jpg and adding it to the usdz, and I've tried including a zip file as an asset and then including it in the usdz as well. I'm still unable to trigger the CompressionChecker in the existing complianceChecker.py usdchecker version

@jesschimein
Copy link
Collaborator

Filed as internal issue #USD-10492

@jesschimein
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@tallytalwar tallytalwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic is fine, but I was thinking we can split this up into a UsdzPackageValidator and a UsdzRootPackageValidator with appropriate keywords.

Both validators are stage level validators:

  • RootPackageValidator: will do compression error logic, byle alignment logic and extension validation logic just for the rootLayer, if the rootLayer is a package.
  • UsdzPackageValidator: will do all the same validation checks for all packages found in the stage.

A lot of the actual validation code itself can be shared between the 2 validator methods.

This way we can do this: https://github.com/PixarAnimationStudios/OpenUSD/blob/dev/pxr/usdValidation/bin/usdchecker/usdchecker.cpp#L572-L575

Let me know what you think about this and feel free to ping on aswf slack if you want to discuss this more?

Thanks

Comment on lines +107 to +154
if (!zipFile)
{
return {};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this check above doing the ArSplitPackageRelativePathOuter

rootLayer, SdfPath(fileName))
},
TfStringPrintf(
("File '%s' in package '%s' has "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra "()" here? TfStringPrintf(("File .... instead of TfStringPrintf("File..

@beersandrew beersandrew force-pushed the validation-usdUtils-CompressionValidator branch from b325222 to 14c4f8f Compare December 12, 2024 19:20
- removed unnecessary parenthesis on error messages
- move early exit condition earlier
- update the validation logic to always check for both compression & byteAlignment, either only at the root level or at all levels
- added a test to test a referenced usdz file that has internal byte alignment and compression errors
- added example test usd files
@beersandrew beersandrew force-pushed the validation-usdUtils-CompressionValidator branch from 55acc80 to 8229bd9 Compare December 16, 2024 01:32
@beersandrew beersandrew marked this pull request as ready for review December 16, 2024 01:32
_GetUsdzPackageErrors(const SdfLayerHandle &rootLayer)
{
const UsdZipFile zipFile = UsdZipFile::Open(rootLayer->GetRealPath().c_str());
if (!zipFile)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tallytalwar I noticed testing locally that when passing a .usda file in here, this if statement does not filter out the .usda layer, which I anticipated that it would. All of the errors are still coming back correctly but I wanted to ask if there was some other condition to put here to exit out early as I couldn't find something on the UsdZipFile class that was applicable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah looks like from the code it works even if the layer is a usda layer, as it goes through ArAsset. I will confirm internally if thats anticipated.

// Verify internal compression and byte misalignment errors occur
TF_AXIOM(errors.size() == 3);

const std::string fullErrorPath = ArchGetCwd() +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tallytalwar Two things about this line.

  1. It seems in the validator itself, if I pass in a root level myFile.usdz, the ArSplitPackageRelativePathOuter will get the package path that i want, as in, only myFile.usdz however passing in parentFile.usda that references myFile.usdz the error message has the full real path in the error message
  2. If the above is okay as is, I wanted to join these paths here in a platform agnostic way and I thought there was some library function to join these paths so it would work everywhere as this as written seems it's the wrong direction for Windows, and it seemed wrong to write some helper function here to deal with the correct slashes. I did find other tests that used only this slash, but let me know if this should be changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I fully understand, 1.

But for 2, there is: https://github.com/PixarAnimationStudios/OpenUSD/blob/dev/pxr/base/tf/stringUtils.h#L677-L689 which you can use to do a platform agnostic way of concatenating paths, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To rephrase 1, this line: https://github.com/PixarAnimationStudios/OpenUSD/pull/3449/files#diff-d9adee7401f280af5ec4cc8aa666b4fb0d767ea269bedc2750dcc333503af6aaR156 behaves differently whether it's the root package or an internal package.

  • When it's a root package the value will be : "rootPackage.usdz" (or whatever the name of the file is)
  • When it's an internal package the value will be : "/fully/qualified/path/of/package/internalPackage.usdz" (where this is the path on disk or would be the path on disk of the internal package.

I think this is less of an issue now that you've reminded me of 2. (Thanks!) but I wanted to point it out as the error messages are different in these cases where sometimes the fully qualified path is there and other times it's not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, yeah I think I can reason about that (will also confirm internally), but the reference path to internal package gets fully resolved relative to its referenced location, in order to locate the asset, and that causes the paths to be absolute.

@jesschimein
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jesschimein
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@tallytalwar tallytalwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just couple of more small notes to be addressed; will sync in when done. Thanks Andy

- don't unnecessarily capture assets & unresolvedPaths for this validator
- fixed a missing const
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants