summaryrefslogtreecommitdiffstats
path: root/source/slang/emit.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-07 13:15:08 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-07 13:15:08 -0700
commit20ac581f09a9451f7c84cb0a1ae8764f5e9349be (patch)
treedc373bfa94c813e97700ff1513ada772a87f96d8 /source/slang/emit.cpp
parentc0bcb9c358e22a5c61c3efe77a14a368632bac70 (diff)
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`
Diffstat (limited to 'source/slang/emit.cpp')
-rw-r--r--source/slang/emit.cpp68
1 files changed, 62 insertions, 6 deletions
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<MemberExpressionSyntaxNode>())
+ {
+ 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<MemberExpressionSyntaxNode>())
+ {
+ auto base = memberExpr->BaseExpression;
+ if (auto baseTextureType = base->Type->As<TextureType>())
+ {
+ 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(")");