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

Fix Metal shader errors with MaterialX 1.39 #3519

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pxr/imaging/hdSt/materialXShaderGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,17 @@ HdStMaterialXShaderGen<Base>::_EmitMxInitFunction(
emitLine("u_envIrradiance = HdGetSampler_domeLightFallback()", mxStage);
emitLine("u_envRadiance = HdGetSampler_domeLightFallback()", mxStage);
emitLine("#endif", mxStage, false);
emitLine("u_envRadianceMips = textureQueryLevels(u_envRadiance)", mxStage);
}
else {
if (std::is_same_v<Base, MaterialX::MslShaderGenerator>) {
// Msl has this wrapped in a MetalTexture class
emitLine("u_envRadianceMips = textureQueryLevels(u_envRadiance.tex)", mxStage);
}
else {
emitLine("u_envRadianceMips = textureQueryLevels(u_envRadiance)", mxStage);
}
}
emitLine("u_envRadianceMips = textureQueryLevels(u_envRadiance)", mxStage);
Base::emitLineBreak(mxStage);

// Initialize MaterialX Texture samplers with HdGetSampler equivalents
Expand Down Expand Up @@ -1309,12 +1318,12 @@ HdStMaterialXShaderGenMsl::_EmitMxFunctions(
mx::GenContext& mxContext,
mx::ShaderStage& mxStage) const
{
mx::ShaderGenerator::emitLibraryInclude(
"pbrlib/" + mx::GlslShaderGenerator::TARGET
+ "/lib/mx_microfacet.glsl", mxContext, mxStage);
mx::ShaderGenerator::emitLibraryInclude(
"stdlib/" + mx::MslShaderGenerator::TARGET
+ "/lib/mx_math.metal", mxContext, mxStage);
mx::ShaderGenerator::emitLibraryInclude(
"pbrlib/" + mx::GlslShaderGenerator::TARGET
+ "/lib/mx_microfacet.glsl", mxContext, mxStage);
_EmitConstantsUniformsAndTypeDefs(
mxContext, mxStage,_syntax->getConstantQualifier());

Expand Down
4 changes: 3 additions & 1 deletion pxr/imaging/hgiMetal/shaderGenerator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ void _Init(
"template <typename T>\n"
"T mod(T y, T x) { return fmod(y, x); }\n\n"
"template <typename T>\n"
"T atan(T y, T x) { return atan2(y, x); }\n\n"
"T atan(T y_over_x) { return ::atan(y_over_x); }\n\n"
"template <typename T>\n"
"T atan(T y, T x) { return ::atan2(y, x); }\n\n"
"template <typename T>\n"
"T bitfieldReverse(T x) { return reverse_bits(x); }\n\n"
"template <typename T>\n"
Expand Down
Loading