summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-02-13 12:35:40 -0500
committerGitHub <noreply@github.com>2020-02-13 12:35:40 -0500
commitfd61c775f2e0e744c4bbbc2672d42e17c6863c1c (patch)
tree753df099b956914081d78a20678b09bd558d00d3
parentf07834e19a34d5f9c03d681083b5ba30e262889d (diff)
* Fix for unary - on glsl (#1222)
* Test to check fix
-rw-r--r--source/slang/slang-emit-c-like.cpp30
-rw-r--r--tests/bugs/negative-literal.slang14
-rw-r--r--tests/bugs/negative-literal.slang.expected.txt4
3 files changed, 39 insertions, 9 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 2212cf9cc..5f784cba3 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -1967,19 +1967,31 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
needClose = maybeEmitParens(outerPrec, prec);
- // If it's a BitNot, but the data type is bool special case to !
- if (emitOp == EmitOp::BitNot && as<IRBoolType>(inst->getDataType()))
+ switch (inst->op)
{
- m_writer->emit("!");
- }
- else
- {
- m_writer->emit(prec.op);
+ case kIROp_BitNot:
+ {
+ // If it's a BitNot, but the data type is bool special case to !
+ m_writer->emit(as<IRBoolType>(inst->getDataType()) ? "!" : prec.op);
+ break;
+ }
+ case kIROp_Not:
+ {
+ m_writer->emit(prec.op);
+ break;
+ }
+ case kIROp_Neg:
+ {
+ // Emit a space after the unary -, so if we are followed by a negative literal we don't end up with --
+ // which some downstream compilers determine to be decrement.
+ m_writer->emit("- ");
+ break;
+ }
}
-
+
emitOperand(operand, rightSide(prec, outerPrec));
break;
- }
+ }
case kIROp_Load:
{
auto base = inst->getOperand(0);
diff --git a/tests/bugs/negative-literal.slang b/tests/bugs/negative-literal.slang
new file mode 100644
index 000000000..586cd601c
--- /dev/null
+++ b/tests/bugs/negative-literal.slang
@@ -0,0 +1,14 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -compile-arg -O3
+//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):out,name outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ float v = asfloat((int(dispatchThreadID.x) & -2147483648) | 1065353216);
+ outputBuffer[dispatchThreadID.x] = v;
+}
diff --git a/tests/bugs/negative-literal.slang.expected.txt b/tests/bugs/negative-literal.slang.expected.txt
new file mode 100644
index 000000000..cc5e55ab6
--- /dev/null
+++ b/tests/bugs/negative-literal.slang.expected.txt
@@ -0,0 +1,4 @@
+3F800000
+3F800000
+3F800000
+3F800000