-
Notifications
You must be signed in to change notification settings - Fork 407
WGSL/WebGPU GLSL ShaderGenerator #2407
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
WGSL/WebGPU GLSL ShaderGenerator #2407
Conversation
…erator. * Derive WgslShaderGenerator and similar classes from VkShaderGenerator. * Create virtual function under ShaderGenerator.h to specify member variable name of LightData.type. (shifting to LightData.light_type for WGSL)
…r2D. * Refactor mx_microfacet_specular.glsl to extract out mx_latlong_map_lookup. * Add shader code: mx_image*_wgsl.glsl, mx_environment*_wgsl.glsl, and mx_hextiled*_wgsl.glsl * Update stdlib_genglsl_impl.mtlx to add genglsl_wgsl implementations. * Add "glsl_wgsl" target type.
|
|
|
No testing done with Js currently. Likely something would need to change around the LightData struct so it can use LightData.light_type instead of LightData.type to have Js work with WebGPU/WGSL. |
|
Hi @scotbrew greatly appreciate you getting this work started 👍🏽 I briefly looked at the changes and think you are addressing all the key areas wrt the sampler split. However, I see that we will have to duplicate major blocks of shader code for minor differences in function call. Could we introduce a Based on suggestion from Niklas slack I think we want to use |
|
@ashwinbhat , the #define is a great idea for a way to minimize the branching of the code. I was not seeing a way for the WgslShaderGenerator to specify the GenOptions from the context in the constructor. We can leave adding a GenOption as a phase2 if wanting to pull it back to Vulkan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
i was hoping we could virtualize or modularize the lookups more but the raw code is pretty ugly. Even though there is duplication I'm not really a big fan of compiler directives in code, but I guess that's good enough for now. I was hoping that the image functions at least had emitted headers to branch on but that does not seem to be the case.
-
I'd prefer virtualization instead of introducing tests for a specific generator.
-
It should be pretty straight-forward to add in
genwgsltest and that should give you pretty good base-line unit test coverate. If there is way to validate the code, then we can look at adding something to CI later on via thegenerateshader.pyscript. If you something that users can run to perform any validation would be good to document this.
Replace constructed string with static for virtual function getLightDataTypevarString(). Change return type to string&. This more closely follows the MaterialX class conventions.
|
I've combed over the changes to streamline a bit further. PR should be ready for final review. |
kwokcb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great with some minor items:
- It would be good to expose the environment texture / sampler uniform names as a courtesy to implementors so they know what uniforms to use for binding.
I can't think of any other way to make the source code cleaner than what's done here with the preprocessor directive.
- I think the sampler gradient call syntax is incorrect ?
Thanks.
* Creating T_ENV_RADIANCE_TEXTURE and T_ENV_RADIANCE_SAMPLER * Creating HW::ENV_RADIANCE_TEXTURE and HW::ENV_RADIANCE_SAMPLER * Updating _tokenSubstitutions() for new strings.
scotbrew
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all comments and suggestions.
JGamache-autodesk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from missing WGSL forbidden keywords in the Syntax, everything else looks fine to me.
Add full list of WGSL Keywords and Reserved Words https://www.w3.org/TR/WGSL/#keyword-summary https://www.w3.org/TR/WGSL/#reserved-words
Signed-off-by: Jonathan Stone <[email protected]>
Signed-off-by: Jonathan Stone <[email protected]>
Signed-off-by: Jonathan Stone <[email protected]>
|
@scotbrew Oh, I just noticed that our render validation tests are returning all-black renders with this PR! I've confirmed the same results locally on my Windows machine, and here are the current renders from the Viewer and Graph Editor with this PR: Viewer: Graph Editor: |
|
Looking back through recent GitHub Actions runs, here's the first one I see where the render validation tests are returning black renders, in case that helps to track down the cause: https://github.com/AcademySoftwareFoundation/MaterialX/actions/runs/15331741009 |
|
That is definitely one to catch and fix before fully integrating. Updates:
|
Fix issue introduced when refactoring code to use ShaderGenerator::emitFunctionDefinitionParameter(). OutputPorts need to use _syntax->getOutputTypeName() instead of _syntax->getTypeName(). Fix commit from "WGSL: Refactor shader code and CompountNode shader gen" (sha: 131d322)
|
For code spot-checking, a comparison was done between the standard_surface_look_brass_tiled shader code generated by the latest PR2407 code and latest main branch. Everything looks as expected.
|
jstone-lucasfilm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for this contribution, @scotbrew, and I believe this looks ready to go!
Further in the future, I'd be interested in trying additional strategies to reduce the interface duplication in the hardware implementations of our image nodes, but the benefits of this initial implementation greatly outweigh those minor issues.
8eaf80c
into
AcademySoftwareFoundation:main



Adding WgslShaderGenerator and its support classes to generate WGSL-compliant GLSL code. This is targeted to allow USD to render MaterialX shaders with the WebGPU implementation.
Main changes:
Pull Request Sections:
(filenames: *_wgsl.glsl)(using#define HW_SEPARATE_SAMPLERSin glsl shader code)or refactoring a few .glsl files.and adding 2 baseclass virtual functions.Issues Resolved:
This PR addresses the following logged issues.