Skip to content

Commit

Permalink
Support matrix negation in metal backend. (#5891)
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Dec 17, 2024
1 parent 0a6ffee commit 9c9e1f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions source/slang/slang-emit-metal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions tests/metal/matrix-negate.slang
Original file line number Diff line number Diff line change
@@ -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];
}

0 comments on commit 9c9e1f7

Please sign in to comment.