diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-emit-cpp.cpp | 47 | ||||
| -rw-r--r-- | source/slang/slang-emit-glsl.cpp | 1 |
3 files changed, 47 insertions, 3 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index dd40b7856..fbcd0dbbd 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_MatrixReshape: case kIROp_VectorReshape: case kIROp_CastFloatToInt: case kIROp_CastIntToFloat: @@ -1822,6 +1821,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO m_writer->emit(")"); break; case kIROp_MakeVectorFromScalar: + case kIROp_MatrixReshape: case kIROp_CastPtrToInt: case kIROp_CastIntToPtr: { diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp index fad0c94f9..87b620ed2 100644 --- a/source/slang/slang-emit-cpp.cpp +++ b/source/slang/slang-emit-cpp.cpp @@ -1178,6 +1178,7 @@ void CPPSourceEmitter::_emitInitDefinition(const UnownedStringSlice& funcName, c writer->emit("{ "); const Index paramCount = Index(funcType->getParamCount()); + bool handled = false; if (IRVectorType* vecType = as<IRVectorType>(retType)) { @@ -1211,7 +1212,7 @@ void CPPSourceEmitter::_emitInitDefinition(const UnownedStringSlice& funcName, c writer->emit("."); writer->emit(elemNames[paramSubIndex]); - paramSubIndex ++; + paramSubIndex++; if (paramSubIndex >= paramElementCount) { @@ -1226,9 +1227,51 @@ void CPPSourceEmitter::_emitInitDefinition(const UnownedStringSlice& funcName, c } } } + handled = true; } - else + else if (IRMatrixType* matType = as<IRMatrixType>(retType)) + { + if (paramCount != 1) + goto fallback; + + auto paramMat = as<IRMatrixType>(funcType->getParamType(0)); + if (!paramMat) + goto fallback; + + // We are constructing a matrix from a differently sized matrix. + + Index rows = Index(getIntVal(matType->getRowCount())); + Index cols = Index(getIntVal(matType->getColumnCount())); + Index paramRows = Index(getIntVal(paramMat->getRowCount())); + Index paramCols = Index(getIntVal(paramMat->getColumnCount())); + char elementNames[] = { 'x', 'y', 'z', 'w' }; + + for (Index r = 0; r < rows; r++) + { + for (Index c = 0; c < cols; c++) + { + if (r != 0 || c != 0) + writer->emit(", "); + + if (r < paramRows && c < paramCols && c < 4) + { + writer->emitRawText("a.rows["); + writer->emit(r); + writer->emitRawText("]."); + writer->emitChar(elementNames[c]); + } + else + { + writer->emit("0"); + } + } + } + handled = true; + } +fallback: + if (!handled) { + // Fallback default: just use all params to construct. for (Index i = 0; i < paramCount; ++i) { if (i > 0) diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 6dbeba204..e3bd771df 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -1475,6 +1475,7 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu switch (inst->getOp()) { case kIROp_MakeVectorFromScalar: + case kIROp_MatrixReshape: { // Simple constructor call EmitOpInfo outerPrec = inOuterPrec; |
