diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-16 22:10:10 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-16 22:10:10 -0800 |
| commit | 9c9e1f701242b59dead94426a25f2ad5d3bcf66d (patch) | |
| tree | a5ebe51754ab40ea300177b2cc56a979337d2e80 | |
| parent | 0a6ffee0c633e28a42a676fb7ddeb5f7d151a6db (diff) | |
Support matrix negation in metal backend. (#5891)
| -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 |
