diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-07-07 13:15:08 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-07-07 13:15:08 -0700 |
| commit | 20ac581f09a9451f7c84cb0a1ae8764f5e9349be (patch) | |
| tree | dc373bfa94c813e97700ff1513ada772a87f96d8 /source/slang/slang-stdlib.cpp | |
| parent | c0bcb9c358e22a5c61c3efe77a14a368632bac70 (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/slang-stdlib.cpp')
| -rw-r--r-- | source/slang/slang-stdlib.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
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, "; |
