diff options
| author | Yong He <yonghe@outlook.com> | 2019-01-28 09:45:42 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-28 09:45:42 -0800 |
| commit | 962f265df9e1b8549202a9b9543e1bead190638d (patch) | |
| tree | d11ff742f08a25469fa1a86c8b4d0061853fb63d /source/slang | |
| parent | 864c38ee72991f414f2478ccacb462bfb11b4bca (diff) | |
| parent | df9dc5710725d00630831b77ca7005e390383aa6 (diff) | |
Merge branch 'master' into yong-fix
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/emit.cpp | 17 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 53 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang.h | 53 |
3 files changed, 119 insertions, 4 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 536c72e11..dd6feb50d 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3002,9 +3002,19 @@ struct EmitVisitor } else { + // If it returns void -> then we don't need parenthesis + + const auto returnType = inst->getDataType(); + const bool isVoid = as<IRVoidType>(returnType) != nullptr; + + // We could determine here is the return type is void... if so no braces? + // General case: we are going to emit some more complex text. - Emit("("); + if (!isVoid) + { + Emit("("); + } char const* cursor = name.begin(); char const* end = name.end(); @@ -3364,7 +3374,10 @@ struct EmitVisitor } } - Emit(")"); + if (!isVoid) + { + Emit(")"); + } } } diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 541d12112..55457d864 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -365,9 +365,27 @@ bool any(matrix<T,N,M> x); // Reinterpret bits as a double (HLSL SM 5.0)
+
+__target_intrinsic(glsl, "packDouble2x32(uvec2($0, $1))")
+__glsl_extension(GL_ARB_gpu_shader5)
+double asdouble(uint lowbits, uint highbits);
+
double asdouble(uint lowbits, uint highbits);
// Reinterpret bits as a float (HLSL SM 4.0)
+__target_intrinsic(glsl, "intBitsToFloat")
+float asfloat(int x);
+__target_intrinsic(glsl, "uintBitsToFloat")
+float asfloat(uint x);
+
+__generic<let N : int>
+__target_intrinsic(glsl, "intBitsToFloat")
+vector<float,N> asfloat(vector< int,N> x);
+
+__generic<let N : int>
+__target_intrinsic(glsl, "uintBitsToFloat")
+vector<float,N> asfloat(vector<uint,N> x);
+
float asfloat( int x);
float asfloat(uint x);
__generic<let N : int> vector<float,N> asfloat(vector< int,N> x);
@@ -375,13 +393,27 @@ __generic<let N : int> vector<float,N> asfloat(vector<uint,N> x); __generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix< int,N,M> x);
__generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix<uint,N,M> x);
-
// Inverse sine (HLSL SM 1.0)
__generic<T : __BuiltinFloatingPointType> T asin(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> asin(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> asin(matrix<T,N,M> x);
// Reinterpret bits as an int (HLSL SM 4.0)
+
+__target_intrinsic(glsl, "floatBitsToInt")
+int asint(float x);
+
+__generic<let N : int>
+__target_intrinsic(glsl, "floatBitsToInt")
+vector<int,N> asint(vector<float,N> x);
+
+__target_intrinsic(glsl, "int($0)")
+int asint(uint x);
+
+__generic<let N : int>
+__target_intrinsic(glsl, "ivec$N0($0)")
+vector<int,N> asint(vector<uint,N> x);
+
int asint(float x);
int asint(uint x);
__generic<let N : int> vector<int,N> asint(vector<float,N> x);
@@ -390,9 +422,28 @@ __generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<float,N,M> x); __generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<uint,N,M> x);
// Reinterpret bits of double as a uint (HLSL SM 5.0)
+
+__target_intrinsic(glsl, "{ uvec2 v = unpackDouble2x32($0); $1 = v.x; $2 = v.y; }")
+__glsl_extension(GL_ARB_gpu_shader5)
+void asuint(double value, out uint lowbits, out uint highbits);
+
void asuint(double value, out uint lowbits, out uint highbits);
// Reinterpret bits as a uint (HLSL SM 4.0)
+__target_intrinsic(glsl, "floatBitsToUint")
+uint asuint(float x);
+
+__generic<let N : int>
+__target_intrinsic(glsl, "floatBitsToUint")
+vector<uint,N> asuint(vector<float,N> x);
+
+__target_intrinsic(glsl, "uint($0)")
+uint asuint(int x);
+
+__generic<let N : int>
+__target_intrinsic(glsl, "uvec$N0($0)")
+vector<uint,N> asuint(vector<int,N> x);
+
uint asuint(float x);
uint asuint(int x);
__generic<let N : int> vector<uint,N> asuint(vector<float,N> x);
diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h index 9fb06b4b0..df6dcea48 100644 --- a/source/slang/hlsl.meta.slang.h +++ b/source/slang/hlsl.meta.slang.h @@ -410,9 +410,27 @@ SLANG_RAW("bool any(matrix<T,N,M> x);\n") SLANG_RAW("\n") SLANG_RAW("\n") SLANG_RAW("// Reinterpret bits as a double (HLSL SM 5.0)\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl, \"packDouble2x32(uvec2($0, $1))\")\n") +SLANG_RAW("__glsl_extension(GL_ARB_gpu_shader5)\n") +SLANG_RAW("double asdouble(uint lowbits, uint highbits);\n") +SLANG_RAW("\n") SLANG_RAW("double asdouble(uint lowbits, uint highbits);\n") SLANG_RAW("\n") SLANG_RAW("// Reinterpret bits as a float (HLSL SM 4.0)\n") +SLANG_RAW("__target_intrinsic(glsl, \"intBitsToFloat\")\n") +SLANG_RAW("float asfloat(int x);\n") +SLANG_RAW("__target_intrinsic(glsl, \"uintBitsToFloat\")\n") +SLANG_RAW("float asfloat(uint x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<let N : int>\n") +SLANG_RAW("__target_intrinsic(glsl, \"intBitsToFloat\")\n") +SLANG_RAW("vector<float,N> asfloat(vector< int,N> x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<let N : int>\n") +SLANG_RAW("__target_intrinsic(glsl, \"uintBitsToFloat\")\n") +SLANG_RAW("vector<float,N> asfloat(vector<uint,N> x);\n") +SLANG_RAW("\n") SLANG_RAW("float asfloat( int x);\n") SLANG_RAW("float asfloat(uint x);\n") SLANG_RAW("__generic<let N : int> vector<float,N> asfloat(vector< int,N> x);\n") @@ -420,13 +438,27 @@ SLANG_RAW("__generic<let N : int> vector<float,N> asfloat(vector<uint,N> x);\n") SLANG_RAW("__generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix< int,N,M> x);\n") SLANG_RAW("__generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix<uint,N,M> x);\n") SLANG_RAW("\n") -SLANG_RAW("\n") SLANG_RAW("// Inverse sine (HLSL SM 1.0)\n") SLANG_RAW("__generic<T : __BuiltinFloatingPointType> T asin(T x);\n") SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> asin(vector<T,N> x);\n") SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> asin(matrix<T,N,M> x);\n") SLANG_RAW("\n") SLANG_RAW("// Reinterpret bits as an int (HLSL SM 4.0)\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl, \"floatBitsToInt\")\n") +SLANG_RAW("int asint(float x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<let N : int>\n") +SLANG_RAW("__target_intrinsic(glsl, \"floatBitsToInt\")\n") +SLANG_RAW("vector<int,N> asint(vector<float,N> x);\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl, \"int($0)\")\n") +SLANG_RAW("int asint(uint x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<let N : int>\n") +SLANG_RAW("__target_intrinsic(glsl, \"ivec$N0($0)\")\n") +SLANG_RAW("vector<int,N> asint(vector<uint,N> x);\n") +SLANG_RAW("\n") SLANG_RAW("int asint(float x);\n") SLANG_RAW("int asint(uint x);\n") SLANG_RAW("__generic<let N : int> vector<int,N> asint(vector<float,N> x);\n") @@ -435,9 +467,28 @@ SLANG_RAW("__generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<floa SLANG_RAW("__generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<uint,N,M> x);\n") SLANG_RAW("\n") SLANG_RAW("// Reinterpret bits of double as a uint (HLSL SM 5.0)\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl, \"{ uvec2 v = unpackDouble2x32($0); $1 = v.x; $2 = v.y; }\")\n") +SLANG_RAW("__glsl_extension(GL_ARB_gpu_shader5)\n") +SLANG_RAW("void asuint(double value, out uint lowbits, out uint highbits);\n") +SLANG_RAW("\n") SLANG_RAW("void asuint(double value, out uint lowbits, out uint highbits);\n") SLANG_RAW("\n") SLANG_RAW("// Reinterpret bits as a uint (HLSL SM 4.0)\n") +SLANG_RAW("__target_intrinsic(glsl, \"floatBitsToUint\")\n") +SLANG_RAW("uint asuint(float x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<let N : int>\n") +SLANG_RAW("__target_intrinsic(glsl, \"floatBitsToUint\")\n") +SLANG_RAW("vector<uint,N> asuint(vector<float,N> x);\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl, \"uint($0)\")\n") +SLANG_RAW("uint asuint(int x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<let N : int>\n") +SLANG_RAW("__target_intrinsic(glsl, \"uvec$N0($0)\")\n") +SLANG_RAW("vector<uint,N> asuint(vector<int,N> x);\n") +SLANG_RAW("\n") SLANG_RAW("uint asuint(float x);\n") SLANG_RAW("uint asuint(int x);\n") SLANG_RAW("__generic<let N : int> vector<uint,N> asuint(vector<float,N> x);\n") |
