summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-11-08 18:52:15 -0500
committerTim Foley <tfoleyNV@users.noreply.github.com>2019-11-08 15:52:15 -0800
commit6ee483dc6ddbd372fb509319e0b70f7fc6152278 (patch)
treea631abf02ae0faa01232236e8d6b2bb06d8f9859
parent0ac010a72e777b2c284583fcb8554abee83d8ff5 (diff)
Fix problem when getting default value for a bool, was producing 0, which on glsl could not be coerced. (#1117)
-rw-r--r--source/slang/slang-lower-to-ir.cpp2
-rw-r--r--tests/bugs/bool-init.slang31
-rw-r--r--tests/bugs/bool-init.slang.expected.txt4
3 files changed, 37 insertions, 0 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index 93084fedd..e2689ffd1 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -2088,6 +2088,8 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
break;
case BaseType::Bool:
+ return LoweredValInfo::simple(getBuilder()->getBoolValue(false));
+
case BaseType::Int8:
case BaseType::Int16:
case BaseType::Int:
diff --git a/tests/bugs/bool-init.slang b/tests/bugs/bool-init.slang
new file mode 100644
index 000000000..95b577c33
--- /dev/null
+++ b/tests/bugs/bool-init.slang
@@ -0,0 +1,31 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute,vulkan):COMPARE_COMPUTE_EX:-vk -slang -compute
+
+struct Thing
+{
+ bool a;
+ bool b;
+};
+
+//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)
+{
+ Thing thing = {};
+ int index = int(dispatchThreadID.x);
+
+ if (index % 3)
+ {
+ thing.a = (index & 1) != 0;
+ }
+ else
+ {
+ thing.b = (index & 2) != 0;
+ }
+
+ int v = (thing.a ? 2 : 0) + (thing.b ? 1: 0);
+
+ outputBuffer[index] = v;
+} \ No newline at end of file
diff --git a/tests/bugs/bool-init.slang.expected.txt b/tests/bugs/bool-init.slang.expected.txt
new file mode 100644
index 000000000..96d2eb1bf
--- /dev/null
+++ b/tests/bugs/bool-init.slang.expected.txt
@@ -0,0 +1,4 @@
+0
+2
+0
+1