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

Applying MaterialBindingAPI causes excessive recomposition #2343

Closed
deboisj opened this issue Mar 15, 2023 · 1 comment
Closed

Applying MaterialBindingAPI causes excessive recomposition #2343

deboisj opened this issue Mar 15, 2023 · 1 comment

Comments

@deboisj
Copy link

deboisj commented Mar 15, 2023

Description of Issue

Applying the MaterialBindingAPI api on prims is very expensive, by causing seemingly unecessary recomposition (?). See script bellow. Binding material without the schema applies is orders of magnitudes faster.

Also see this thread on the google-usd interest group where this issue was discussed : https://groups.google.com/g/usd-interest/c/kEnzWToBwnQ

Steps to Reproduce

from pxr import Usd, UsdShade, Sdf
import time

print("USD VERSION : " + str(Usd.GetVersion()))

def test(apply):
	print("---------------------------------")
	print("APPLYING SCHEMA : " + str(apply))

	stage = Usd.Stage.CreateInMemory()
	stage.DefinePrim("/root", "Xform")

	mat = UsdShade.Material.Define(stage, '/root/mat')
	shader = UsdShade.Shader.Define(stage, '/root/mat/usdps')
	shader.CreateIdAttr("UsdPreviewSurface")
	shader.CreateInput("diffuseColor", Sdf.ValueTypeNames.Float3).Set((1,0,0))
	mat.CreateSurfaceOutput().ConnectToSource(shader.ConnectableAPI(), "surface")

	primCount = 10000

	primPaths = []

	for i in range(primCount):
		p =  "/root/Object" + str(i)
		stage.DefinePrim(p, "Sphere")
		primPaths.append(p)

	startTime = time.time()
	for p in primPaths:
		prim = stage.GetPrimAtPath(p);
		if apply:
			prim.ApplyAPI(UsdShade.MaterialBindingAPI)
		UsdShade.MaterialBindingAPI(prim).Bind(mat)

	endTime = time.time()

	elapsed_time = endTime - startTime
	print('Execution time:', elapsed_time, 'seconds')
	# stage.Export("D:/tmp/test" + str(apply) + ".usda")
	
	

test(False) # only binding
test(True) # apply + binding

print("All done.")

On my end I get this output :

USD VERSION : (0, 22, 11)
---------------------------------
APPLYING SCHEMA : False
Execution time: 0.33567094802856445 seconds
---------------------------------
APPLYING SCHEMA : True
Execution time: 14.84079122543335 seconds
All done.

System Information (OS, Hardware)

Windows

Package Versions

22.11

@tallytalwar
Copy link
Contributor

Filed as internal issue #USD-8131

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

No branches or pull requests

2 participants