Skip to content

Commit

Permalink
Update generateshader for data library referencing (AcademySoftwareFo…
Browse files Browse the repository at this point in the history
…undation#2071)

This changelist updates the generateshader.py script to take advantage of data library referencing. i.e. `Document::setDataLibrary`.

In this context, the use of data library referencing should be noticeably more efficient than data library importing when multiple documents are being processed.
  • Loading branch information
jstone-lucasfilm authored Oct 16, 2024
1 parent 4057541 commit eaebfc3
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions python/Scripts/generateshader.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,33 @@ def main():
parser.add_argument(dest='inputFilename', help='Path to input document or folder containing input documents.')
opts = parser.parse_args()

filelist = getMaterialXFiles(opts.inputFilename)

for inputFilename in filelist:
# Load standard and custom data libraries.
stdlib = mx.createDocument()
searchPath = mx.getDefaultDataSearchPath()
libraryFolders = []
if opts.paths:
for pathList in opts.paths:
for path in pathList:
searchPath.append(path)
if opts.libraries:
for libraryList in opts.libraries:
for library in libraryList:
libraryFolders.append(library)
libraryFolders.extend(mx.getDefaultDataLibraryFolders())
mx.loadLibraries(libraryFolders, searchPath, stdlib)

# Generate shaders for each input document.
for inputFilename in getMaterialXFiles(opts.inputFilename):
doc = mx.createDocument()
try:
mx.readFromXmlFile(doc, inputFilename)
doc.setDataLibrary(stdlib)
except mx.ExceptionFileMissing as err:
print('Generation failed: "', err, '"')
sys.exit(-1)

print('---------- Generate code for file: ', inputFilename, '--------------------')

stdlib = mx.createDocument()
searchPath = mx.getDefaultDataSearchPath()
searchPath.append(os.path.dirname(inputFilename))
libraryFolders = []
if opts.paths:
for pathList in opts.paths:
for path in pathList:
searchPath.append(path)
if opts.libraries:
for libraryList in opts.libraries:
for library in libraryList:
libraryFolders.append(library)
libraryFolders.extend(mx.getDefaultDataLibraryFolders())
try:
mx.loadLibraries(libraryFolders, searchPath, stdlib)
doc.importLibrary(stdlib)
except Exception as err:
print('Generation failed: "', err, '"')
sys.exit(-1)

valid, msg = doc.validate()
if not valid:
print('Validation warnings for input document:')
Expand All @@ -108,8 +103,10 @@ def main():
else:
shadergen = mx_gen_glsl.GlslShaderGenerator.create()

codeSearchPath = searchPath
codeSearchPath.append(os.path.dirname(inputFilename))
context = mx_gen_shader.GenContext(shadergen)
context.registerSourceCodeSearchPath(searchPath)
context.registerSourceCodeSearchPath(codeSearchPath)

# If we're generating Vulkan-compliant GLSL then set the binding context
if opts.vulkanCompliantGlsl:
Expand Down

0 comments on commit eaebfc3

Please sign in to comment.