hlslparser: Add missing "ldexp" HLSL intrinsic.

Had to simulate it with the "x * exp2(exp)" expression in GLSL, as GLSL only supports integer types as exponents in its native ldexp implementation, while HLSL solely uses floats.
This commit is contained in:
Kai Blaschke
2024-12-11 16:37:52 +01:00
parent e90dc28e35
commit e7e77baa96
2 changed files with 34 additions and 0 deletions

View File

@ -1019,6 +1019,23 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType*
m_writer.Write(")");
handled = true;
}
else if (String_Equal(functionName, "ldexp"))
{
/* HLSL has the second argument as float, while GLSL only supports ints, so we simulate the HLSL behaviour
* by using the equivalent "x * exp2(exp)" expression. */
HLSLExpression* argument[2];
if (GetFunctionArguments(functionCall, argument, 2) != 2)
{
Error("%s expects 2 arguments", functionName);
return;
}
m_writer.Write("(");
OutputExpression(argument[0], &functionCall->function->returnType);
m_writer.Write("*exp2(");
OutputExpression(argument[1], &functionCall->function->returnType);
m_writer.Write("))");
handled = true;
}
if (!handled)
{

View File

@ -620,6 +620,23 @@ const Intrinsic _intrinsic[] =
INTRINSIC_FLOAT2_FUNCTION( "step" ),
INTRINSIC_FLOAT2_FUNCTION( "reflect" ),
Intrinsic("ldexp", HLSLBaseType_Float, HLSLBaseType_Float, HLSLBaseType_Float),
Intrinsic("ldexp", HLSLBaseType_Float2, HLSLBaseType_Float2, HLSLBaseType_Float2),
Intrinsic("ldexp", HLSLBaseType_Float3, HLSLBaseType_Float3, HLSLBaseType_Float3),
Intrinsic("ldexp", HLSLBaseType_Float4, HLSLBaseType_Float4, HLSLBaseType_Float4),
Intrinsic("ldexp", HLSLBaseType_Float2x2, HLSLBaseType_Float2x2, HLSLBaseType_Float2x2),
Intrinsic("ldexp", HLSLBaseType_Float2x3, HLSLBaseType_Float2x3, HLSLBaseType_Float2x3),
Intrinsic("ldexp", HLSLBaseType_Float2x4, HLSLBaseType_Float2x4, HLSLBaseType_Float2x4),
Intrinsic("ldexp", HLSLBaseType_Float3x2, HLSLBaseType_Float3x2, HLSLBaseType_Float3x2),
Intrinsic("ldexp", HLSLBaseType_Float3x3, HLSLBaseType_Float3x3, HLSLBaseType_Float3x3),
Intrinsic("ldexp", HLSLBaseType_Float3x4, HLSLBaseType_Float3x4, HLSLBaseType_Float3x4),
Intrinsic("ldexp", HLSLBaseType_Float4x2, HLSLBaseType_Float4x2, HLSLBaseType_Float4x2),
Intrinsic("ldexp", HLSLBaseType_Float4x3, HLSLBaseType_Float4x3, HLSLBaseType_Float4x3),
Intrinsic("ldexp", HLSLBaseType_Float4x4, HLSLBaseType_Float4x4, HLSLBaseType_Float4x4),
Intrinsic("refract", HLSLBaseType_Float2, HLSLBaseType_Float2, HLSLBaseType_Float2, HLSLBaseType_Float),
Intrinsic("refract", HLSLBaseType_Float3, HLSLBaseType_Float3, HLSLBaseType_Float3, HLSLBaseType_Float),
Intrinsic("refract", HLSLBaseType_Float4, HLSLBaseType_Float4, HLSLBaseType_Float4, HLSLBaseType_Float),