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

Properly cast argument types in GLSL #785

Merged
merged 1 commit into from
Feb 28, 2024
Merged
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
28 changes: 5 additions & 23 deletions vendor/hlslparser/src/GLSLGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,50 +971,32 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType*
}
else if (String_Equal(functionName, "rsqrt"))
{
HLSLExpression* argument[1];
if (GetFunctionArguments(functionCall, argument, 1) != 1)
{
Error("rsqrt expects 1 argument");
return;
}
/* The documentation says that these functions return NaN for negative
* arguments. However, testing with DX9 shader model 3 shows that they
* most definitely do take the absolute value of the argument and do
* NOT return NaN.
* See https://github.com/projectM-visualizer/projectm/issues/724
*/
m_writer.Write("inversesqrt(abs(");
OutputExpression(argument[0]);
OutputExpressionList(functionCall->argument, functionCall->function->argument);
m_writer.Write("))");
handled = true;
}
else if (String_Equal(functionName, "sqrt") ||
String_Equal(functionName, "log") ||
String_Equal(functionName, "log2"))
{
HLSLExpression* argument[1];
if (GetFunctionArguments(functionCall, argument, 1) != 1)
{
Error("%s expects 1 argument", functionName);
return;
}
/* See rsqrt above */
m_writer.Write("%s(abs(", functionName);
OutputExpression(argument[0]);
OutputExpressionList(functionCall->argument, functionCall->function->argument);
m_writer.Write("))");
handled = true;
}
else if (String_Equal(functionName, "log10"))
{
HLSLExpression* argument[1];
if (GetFunctionArguments(functionCall, argument, 1) != 1)
{
Error("%s expects 1 argument", functionName);
return;
}
/* See rsqrt above regarding abs(). */
m_writer.Write("(log(abs(");
OutputExpression(argument[0]);
OutputExpressionList(functionCall->argument, functionCall->function->argument);
m_writer.Write("))/log(10.0))");
handled = true;
}
Expand All @@ -1031,9 +1013,9 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType*
* the abs() call for compatibility across drivers.
*/
m_writer.Write("pow(abs(");
OutputExpression(argument[0]);
OutputExpression(argument[0], &functionCall->function->returnType);
m_writer.Write("),");
OutputExpression(argument[1]);
OutputExpression(argument[1], &functionCall->function->returnType);
m_writer.Write(")");
handled = true;
}
Expand Down