From 84645e3c679581d191406b2d7ab93c3f6c5e3a63 Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Thu, 9 Feb 2017 13:57:14 -0500 Subject: re-land of skslc type constructor cleanups BUG=skia: Change-Id: I953be07e2389dd4a9e7dcce0ddfd7505b309bda1 Reviewed-on: https://skia-review.googlesource.com/8265 Reviewed-by: Ethan Nicholas Commit-Queue: Ethan Nicholas --- src/sksl/SkSLSPIRVCodeGenerator.cpp | 62 +++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'src/sksl/SkSLSPIRVCodeGenerator.cpp') diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index 9c8a5d0001..1158f94826 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -1500,6 +1500,37 @@ SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, SkWStream& o return result; } +void SPIRVCodeGenerator::writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type, + SkWStream& out) { + FloatLiteral zero(fContext, Position(), 0); + SpvId zeroId = this->writeFloatLiteral(zero); + std::vector columnIds; + for (int column = 0; column < type.columns(); column++) { + this->writeOpCode(SpvOpCompositeConstruct, 3 + type.rows(), + out); + this->writeWord(this->getType(type.componentType().toCompound(fContext, type.rows(), 1)), + out); + SpvId columnId = this->nextId(); + this->writeWord(columnId, out); + columnIds.push_back(columnId); + for (int row = 0; row < type.columns(); row++) { + this->writeWord(row == column ? diagonal : zeroId, out); + } + } + this->writeOpCode(SpvOpCompositeConstruct, 3 + type.columns(), + out); + this->writeWord(this->getType(type), out); + this->writeWord(id, out); + for (SpvId id : columnIds) { + this->writeWord(id, out); + } +} + +void SPIRVCodeGenerator::writeMatrixCopy(SpvId id, SpvId src, const Type& srcType, + const Type& dstType, SkWStream& out) { + ABORT("unimplemented"); +} + SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, SkWStream& out) { ASSERT(c.fType.kind() == Type::kMatrix_Kind); // go ahead and write the arguments so we don't try to write new instructions in the middle of @@ -1511,33 +1542,10 @@ SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, SkWStream SpvId result = this->nextId(); int rows = c.fType.rows(); int columns = c.fType.columns(); - // FIXME this won't work to create a matrix from another matrix - if (arguments.size() == 1) { - // with a single argument, a matrix will have all of its diagonal entries equal to the - // argument and its other values equal to zero - // FIXME this won't work for int matrices - FloatLiteral zero(fContext, Position(), 0); - SpvId zeroId = this->writeFloatLiteral(zero); - std::vector columnIds; - for (int column = 0; column < columns; column++) { - this->writeOpCode(SpvOpCompositeConstruct, 3 + c.fType.rows(), - out); - this->writeWord(this->getType(c.fType.componentType().toCompound(fContext, rows, 1)), - out); - SpvId columnId = this->nextId(); - this->writeWord(columnId, out); - columnIds.push_back(columnId); - for (int row = 0; row < c.fType.columns(); row++) { - this->writeWord(row == column ? arguments[0] : zeroId, out); - } - } - this->writeOpCode(SpvOpCompositeConstruct, 3 + columns, - out); - this->writeWord(this->getType(c.fType), out); - this->writeWord(result, out); - for (SpvId id : columnIds) { - this->writeWord(id, out); - } + if (arguments.size() == 1 && c.fArguments[0]->fType.kind() == Type::kScalar_Kind) { + this->writeUniformScaleMatrix(result, arguments[0], c.fType, out); + } else if (arguments.size() == 1 && c.fArguments[0]->fType.kind() == Type::kMatrix_Kind) { + this->writeMatrixCopy(result, arguments[0], c.fArguments[0]->fType, c.fType, out); } else { std::vector columnIds; int currentCount = 0; -- cgit v1.2.3