summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-c-like.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-12-08 14:56:20 -0800
committerGitHub <noreply@github.com>2022-12-08 14:56:20 -0800
commit41eb19e65a0974e23048bd7b3b1eb1e2f569b1d0 (patch)
treec6cde57da4d3415d86d09213936a48d3d26e07e1 /source/slang/slang-emit-c-like.cpp
parent468bb7ecf65c000c308adae511bf65a1ca4cc412 (diff)
Auto-diff for matrix operations. (#2559)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-emit-c-like.cpp')
-rw-r--r--source/slang/slang-emit-c-like.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index cadab5690..dd40b7856 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -1778,7 +1778,6 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
case kIROp_MakeVector:
case kIROp_MakeMatrix:
- case kIROp_MakeMatrixFromScalar:
case kIROp_MatrixReshape:
case kIROp_VectorReshape:
case kIROp_CastFloatToInt:
@@ -1789,6 +1788,25 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
emitType(inst->getDataType());
emitArgs(inst);
break;
+ case kIROp_MakeMatrixFromScalar:
+ {
+ emitType(inst->getDataType());
+ auto matrixType = as<IRMatrixType>(inst->getDataType());
+ SLANG_RELEASE_ASSERT(matrixType);
+ auto columnCount = as<IRIntLit>(matrixType->getColumnCount());
+ SLANG_RELEASE_ASSERT(columnCount);
+ auto rowCount = as<IRIntLit>(matrixType->getRowCount());
+ SLANG_RELEASE_ASSERT(rowCount);
+ m_writer->emit("(");
+ for (IRIntegerValue i = 0; i < rowCount->getValue() * columnCount->getValue(); i++)
+ {
+ if (i != 0)
+ m_writer->emit(", ");
+ emitOperand(inst->getOperand(0), getInfo(EmitOp::General));
+ }
+ m_writer->emit(")");
+ }
+ break;
case kIROp_AllocObj:
m_writer->emit("new ");
m_writer->emit(getName(inst->getDataType()));