summaryrefslogtreecommitdiff
path: root/source/slang/hlsl.meta.slang
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-10-12 13:53:42 -0700
committerGitHub <noreply@github.com>2017-10-12 13:53:42 -0700
commit575230b93370fea86ecccb53fba73927280e917b (patch)
tree3f4a3402d435418663edd4a963ed3245b81a4526 /source/slang/hlsl.meta.slang
parent9a231a5efb0ddce635e7e40c2d5b086ff4bd389a (diff)
Work towards target-specific function overloads (#210)
* Checkpoint: interface conformance work - Add explicit definition of `saturate` for the GLSL target, which calls through to `clamp` - Needed to add explicit initializer to `__BuiltinFloatingPointType` to allow initialization from a single `float`, so that the `saturate` implementation can be sure that it can initialize a `T` from `0.0` or `1.0`. - This triggered errors in overload resolution, because the logic in place could not figure out that the `T` of the outer generic (`saturate<T>()`) conformed to the interface required by the callee. At this point I have the call to the scalar `clamp()` getting past type-checking, but not the vector or matrix cases. * More fixups for overload resolution inside generics - Make sure value parameters are treated the same as type parameters: we only want to solve for the parameters of the generic actually being applied, and not accidentally generate constraints for outer generics (e.g., when checking the body of a generic function). - Make sure that the diagnostics stuff uses the correct source manager when expanding the location of a builtin. * Fixes for function redeclaration - Handle case of redeclaring a generic function - Enumerate siblings in the parent of the *generic* not the parent of the *function* - Add logic to compare generic signatures - When generic signatures match, specialize functions to compatible generic arguments before comparing the function signatures - Fix redeclaration logic to *not* detect prefix/postifx operators as redeclarations of one another - Build an explicit representation of function redeclaration groups - First declaration is the "primary" and others are stored in a linked list - Make overload resolution handle redeclared functions - Only consider the primary declaration and skip others
Diffstat (limited to 'source/slang/hlsl.meta.slang')
-rw-r--r--source/slang/hlsl.meta.slang31
1 files changed, 31 insertions, 0 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 442903e6f..81e9931e8 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -842,6 +842,37 @@ __generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__target_intrinsic(glsl, "clamp($0, 0, 1)")
matrix<T,N,M> saturate(matrix<T,N,M> x);
+__generic<T : __BuiltinFloatingPointType>
+__specialized_for_target(glsl)
+T saturate(T x)
+{
+ return clamp(x, T(0), T(1));
+}
+
+__generic<T : __BuiltinFloatingPointType, let N : int>
+__specialized_for_target(glsl)
+vector<T,N> saturate(vector<T,N> x)
+{
+ return clamp(x,
+ vector<T,N>(T(0)),
+ vector<T,N>(T(1)));
+}
+
+// HACK: need a helper to turn a scalar into a matrix,
+// because GLSL and HLSL disagree on the semantics of
+// constructing a matrix from a single scalar.
+__generic<T, let N : int, let M : int>
+matrix<T,N,M> __scalarToMatrix(T value);
+
+__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
+__specialized_for_target(glsl)
+matrix<T,N,M> saturate(matrix<T,N,M> x)
+{
+ return clamp(x,
+ __scalarToMatrix<T,N,M>(T(0)),
+ __scalarToMatrix<T,N,M>(T(1)));
+}
+
// Extract sign of value
__generic<T : __BuiltinSignedArithmeticType> __intrinsic_op int sign(T x);