From 20ac581f09a9451f7c84cb0a1ae8764f5e9349be Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 7 Jul 2017 13:15:08 -0700 Subject: Add GLSL equivalents for some stdlib operations. - Map HLSL `atan2(y,x)` to GLSL `atan(y,x)` - Add support for `$p` escape in `__intrinsic` modifier, which allows generating GLSL texture-sampler pairs more easily - Also added a `$o` escape to represent the base object in an OOP-style call (`obj.F(...)`) - This isn't used in the texture functions right now, because getting the right GLSL texture type in this context is a bit thorny (the prefix depends on the generic parameter being used) - Used the `$p` capability to add mappings for `SampleBias` and `SampleLevel` --- source/slang/emit.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 6 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 2496480ce..6a10c4f03 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -1506,13 +1506,69 @@ struct EmitVisitor assert(cursor != end); char d = *cursor++; - assert(('0' <= d) && (d <= '9')); - UInt argIndex = d - '0'; - assert((0 <= argIndex) && (argIndex < argCount)); - Emit("("); - EmitExpr(callExpr->Arguments[argIndex]); - Emit(")"); + switch (d) + { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + { + // Simple case: emit one of the direct arguments to the call + UInt argIndex = d - '0'; + assert((0 <= argIndex) && (argIndex < argCount)); + Emit("("); + EmitExpr(callExpr->Arguments[argIndex]); + Emit(")"); + } + break; + + case 'o': + // For a call using object-oriented syntax, this + // expands to the "base" object used for the call + if (auto memberExpr = callExpr->FunctionExpr.As()) + { + Emit("("); + EmitExpr(memberExpr->BaseExpression); + Emit(")"); + } + else + { + assert(!"unexpected"); + } + break; + + case 'p': + // If we are calling a D3D texturing operation in the form t.Foo(s, ...), + // then this form will pair up the t and s arguments as needed for a GLSL + // texturing operation. + assert(argCount > 0); + if (auto memberExpr = callExpr->FunctionExpr.As()) + { + auto base = memberExpr->BaseExpression; + if (auto baseTextureType = base->Type->As()) + { + emitGLSLTextureOrTextureSamplerType(baseTextureType, "sampler"); + Emit("("); + EmitExpr(memberExpr->BaseExpression); + Emit(","); + EmitExpr(callExpr->Arguments[0]); + Emit(")"); + } + else + { + assert(!"unexpected"); + } + + } + else + { + assert(!"unexpected"); + } + break; + + default: + assert(!"unexpected"); + break; + } } Emit(")"); -- cgit v1.2.3