diff options
| -rw-r--r-- | source/slang/slang-emit-metal.cpp | 15 | ||||
| -rw-r--r-- | tests/metal/matrix-negate.slang | 11 |
2 files changed, 26 insertions, 0 deletions
diff --git a/source/slang/slang-emit-metal.cpp b/source/slang/slang-emit-metal.cpp index e6e2a3ec5..45a9e60ad 100644 --- a/source/slang/slang-emit-metal.cpp +++ b/source/slang/slang-emit-metal.cpp @@ -701,6 +701,21 @@ bool MetalSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inO m_writer->emit(")"); return true; } + case kIROp_Neg: + { + if (as<IRMatrixType>(inst->getOperand(0)->getDataType())) + { + // Metal does not support negate operator on matrices, + // we should emit "(matrix(0) - op0)" instead. + m_writer->emit("("); + emitType(inst->getDataType()); + m_writer->emit("(0) - "); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(")"); + return true; + } + break; + } case kIROp_Mul: { // Component-wise multiplication needs to be special cased, diff --git a/tests/metal/matrix-negate.slang b/tests/metal/matrix-negate.slang new file mode 100644 index 000000000..f6ae6816f --- /dev/null +++ b/tests/metal/matrix-negate.slang @@ -0,0 +1,11 @@ +//TEST:SIMPLE(filecheck=CHECK): -target metal + +// CHECK: (matrix<float,int(4),int(4)>{{.*}}(0) - + +RWStructuredBuffer<float4> output; + +[numthreads(1,1,1)] +void computeMain(uniform float4x4 m) +{ + output[0] = (-m)[0]; +}
\ No newline at end of file |
