summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2019-01-28 09:45:42 -0800
committerGitHub <noreply@github.com>2019-01-28 09:45:42 -0800
commit962f265df9e1b8549202a9b9543e1bead190638d (patch)
treed11ff742f08a25469fa1a86c8b4d0061853fb63d
parent864c38ee72991f414f2478ccacb462bfb11b4bca (diff)
parentdf9dc5710725d00630831b77ca7005e390383aa6 (diff)
Merge branch 'master' into yong-fix
-rw-r--r--source/slang/emit.cpp17
-rw-r--r--source/slang/hlsl.meta.slang53
-rw-r--r--source/slang/hlsl.meta.slang.h53
-rw-r--r--tests/compute/bit-cast-double.slang21
-rw-r--r--tests/compute/bit-cast-double.slang.expected.txt4
-rw-r--r--tests/compute/bit-cast.slang42
-rw-r--r--tests/compute/bit-cast.slang.expected.txt12
7 files changed, 198 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")
diff --git a/tests/compute/bit-cast-double.slang b/tests/compute/bit-cast-double.slang
new file mode 100644
index 000000000..27d0b48cf
--- /dev/null
+++ b/tests/compute/bit-cast-double.slang
@@ -0,0 +1,21 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ double d = double(dispatchThreadID.x);
+
+ uint hi, low;
+ asuint(d, low, hi);
+
+ // Reconstruct
+ double r = asdouble(low, hi);
+
+ outputBuffer[dispatchThreadID.x] = int(r);
+} \ No newline at end of file
diff --git a/tests/compute/bit-cast-double.slang.expected.txt b/tests/compute/bit-cast-double.slang.expected.txt
new file mode 100644
index 000000000..bc856dafa
--- /dev/null
+++ b/tests/compute/bit-cast-double.slang.expected.txt
@@ -0,0 +1,4 @@
+0
+1
+2
+3
diff --git a/tests/compute/bit-cast.slang b/tests/compute/bit-cast.slang
new file mode 100644
index 000000000..050b84f30
--- /dev/null
+++ b/tests/compute/bit-cast.slang
@@ -0,0 +1,42 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ const int id = asint(dispatchThreadID.x);
+
+ {
+ int4 i4 = int4(id, id + 1, id + 2, id + 3);
+ uint3 u3 = asuint(i4.xyz);
+ int2 i2 = asint(u3.xy);
+ uint u1 = asuint(i2.x);
+
+ outputBuffer[id + 0] = int(u1);
+ }
+
+ {
+ uint v = asuint(id);
+ uint4 u4 = uint4(v, v + 1, v + 2, v + 3);
+ int3 i3 = asint(u4.xyz);
+ uint2 u2 = asuint(i3.xy);
+ int i1 = asint(u2.x);
+
+ outputBuffer[id + 4] = i1;
+ }
+
+ {
+ int4 i4 = int4(id, id + 1, id + 2, id + 3);
+ float4 f4 = asfloat(i4);
+ uint3 u3 = asuint(f4.xyz);
+ float2 f2 = asfloat(u3.xy);
+ int i1 = asint(id);
+
+ outputBuffer[id + 8] = i1;
+ }
+} \ No newline at end of file
diff --git a/tests/compute/bit-cast.slang.expected.txt b/tests/compute/bit-cast.slang.expected.txt
new file mode 100644
index 000000000..f5414793f
--- /dev/null
+++ b/tests/compute/bit-cast.slang.expected.txt
@@ -0,0 +1,12 @@
+0
+1
+2
+3
+0
+1
+2
+3
+0
+1
+2
+3 \ No newline at end of file