PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.17k stars 1.23k forks source link

Non-deterministic composition with nested instancing and inherits / specializes arcs #3201

Open chrizzFTD opened 3 months ago

chrizzFTD commented 3 months ago

Description of Issue

Hello USD team, big fan!

I've encountered an issue where nested instancing + use of inherits / specializes leads to non-deterministic composition. I'd like to clarify if it's a bug or expected behavior from miss-use of these features.

Steps to Reproduce

Short version (visual check):

  1. Unzip broadcast_nested_instances.zip (it contains broadcast_nested_instances.usdz)
  2. Open broadcast_nested_instances.usdz in USDView and take a look at the viewport
  3. Re-open the same file through File -> Reopen Stage a couple of times. Without changing anything, the same stage composes differently:

non_deterministic_composition

Long version (Stats and variant selection check):

  1. Download and unzip the same broadcast_nested_instances.usdz file
  2. Save this python script and update the stage filepath to where broadcast_nested_instances.usdz is downloaded:

    """This script checks for the current "color" variant selection from an instanced "Window" model, as well as total prototype prim count.
    
    Results will differ per script execution.
    """
    from pxr import Usd, UsdUtils
    stage = Usd.Stage.Open("/path/to/downloaded/broadcast_nested_instances.usdz")
    window_instance_path = "/Catalogue/Model/Blocks/Block_With_Inherited_Windows/Building1/Windows/Window"
    window_instance = stage.GetPrimAtPath(window_instance_path)
    window_color_selection = window_instance.GetVariantSet("color").GetVariantSelection()
    print(f"Window color: {window_color_selection}")
    stats = UsdUtils.ComputeUsdStageStats(stage)
    print(f"Total Prototypes Prim Count: {stats['prototypes']['primCounts']['totalPrimCount']}")
  3. Run the script once to see the output of current color variant selected and total prototype prim count:
    Window color: blue
    Total Prototypes Prim Count: 17
  4. Run the python script a couple of times; the print output will be different from time to time, e.g in a bash shell:
    for i in `seq 10`;do python /path/to/check_composition.py;done

    outputs:

    Window color: red
    Total Prototypes Prim Count: 20
    Window color: 
    Total Prototypes Prim Count: 14
    Window color: blue
    Total Prototypes Prim Count: 17
    Window color: blue
    ...
    Total Prototypes Prim Count: 17
    Window color: 
    Total Prototypes Prim Count: 14
    Window color: blue
    Total Prototypes Prim Count: 17
  5. Note how values for window color vary between red, blue, "", as well as total prototype prim count between 14, 17, 20.

For convenience, I am also attaching a zip with the split usd files (before running usdzip): broadcast_nested_instances_uncompressed.zip

It contains the following files:

City-Entry-Assembly.1.usda
Model-Blocks-Block.1.usda
Model-Blocks-Block_With_Inherited_Windows.1.usda
Model-Blocks-Block_With_Specialized_Windows.1.usda
Model-Buildings-Multi_Story_Building.1.usda
Model-Elements-Window.1.usda

And the same issue will appear when opening City-Entry-Assembly.1.usda in usdview

Details on the structure

For full context, click for the long description on the composition choices (it's quite long): ![broadcast_nested_instances](https://github.com/user-attachments/assets/82df2268-e67e-4c66-8a6f-c2e0f692d469)

Expectations

This is what I would expect to see:

image

I'm also at SIGGRAPH this week, in case anyone wants to speak in person 😄

System Information (OS, Hardware)

Package Versions

Build Flags

Thanks!

jesschimein commented 3 months ago

Filed as internal issue #USD-9919

spiffmon commented 3 months ago

There should be no way to misuse the composition arcs or instancing that does not produce error output (eg. introducing a reference cycle), so this surely sounds like a bug to me. Thanks for the great report- we’ll have a look!