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/slang-stdlib.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'source/slang/slang-stdlib.cpp') 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 __intrinsic T atan(T x); __generic __intrinsic vector atan(vector x); __generic __intrinsic matrix atan(matrix x); -__generic __intrinsic T atan2(T y, T x); -__generic __intrinsic vector atan2(vector y, vector x); -__generic __intrinsic matrix atan2(matrix y, matrix x); +__generic +__intrinsic(glsl,"atan($0,$1)") +__intrinsic +T atan2(T y, T x); + +__generic +__intrinsic(glsl,"atan($0,$1)") +__intrinsic +vector atan2(vector y, vector x); + +__generic +__intrinsic(glsl,"atan($0,$1)") +__intrinsic +matrix atan2(matrix y, matrix x); // Ceiling (HLSL SM 1.0) __generic __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 "; @@ -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, "; -- cgit v1.2.3