diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/emit.cpp | 68 | ||||
| -rw-r--r-- | source/slang/slang-stdlib.cpp | 26 |
2 files changed, 84 insertions, 10 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(")"); diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index ff727cbb6..87c2c2e8a 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -341,9 +341,20 @@ __generic<T : __BuiltinFloatingPointType> __intrinsic T atan(T x); __generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic vector<T,N> atan(vector<T,N> x); __generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic matrix<T,N,M> atan(matrix<T,N,M> x); -__generic<T : __BuiltinFloatingPointType> __intrinsic T atan2(T y, T x); -__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic vector<T,N> atan2(vector<T,N> y, vector<T,N> x); -__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic matrix<T,N,M> atan2(matrix<T,N,M> y, matrix<T,N,M> x); +__generic<T : __BuiltinFloatingPointType> +__intrinsic(glsl,"atan($0,$1)") +__intrinsic +T atan2(T y, T x); + +__generic<T : __BuiltinFloatingPointType, let N : int> +__intrinsic(glsl,"atan($0,$1)") +__intrinsic +vector<T,N> atan2(vector<T,N> y, vector<T,N> x); + +__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> +__intrinsic(glsl,"atan($0,$1)") +__intrinsic +matrix<T,N,M> atan2(matrix<T,N,M> y, matrix<T,N,M> x); // Ceiling (HLSL SM 1.0) __generic<T : __BuiltinFloatingPointType> __intrinsic T ceil(T x); @@ -1324,7 +1335,6 @@ namespace Slang flavor |= (access << 8); - // emit a generic signature // TODO: allow for multisample count to come in as well... sb << "__generic<T = float4> "; @@ -1475,11 +1485,15 @@ namespace Slang // `SampleBias()` + sb << "__intrinsic(glsl, \"texture($p, $1, $2)\")\n"; + sb << "__intrinsic\n"; sb << "T SampleBias(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias);\n"; if( baseShape != TextureType::ShapeCube ) { + sb << "__intrinsic(glsl, \"textureOffset($p, $1, $2, $3)\")\n"; + sb << "__intrinsic\n"; sb << "T SampleBias(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; @@ -1533,12 +1547,16 @@ namespace Slang // `SampleLevel` + sb << "__intrinsic(glsl, \"textureLod($p, $1, $2)\")\n"; + sb << "__intrinsic\n"; sb << "T SampleLevel(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float level);\n"; if( baseShape != TextureType::ShapeCube ) { + sb << "__intrinsic(glsl, \"textureLodOffset($p, $1, $2, $3)\")\n"; + sb << "__intrinsic\n"; sb << "T SampleLevel(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float level, "; |
