From 925f52d03b731c49c1a2b52c6ced53169a1df669 Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Wed, 19 Jul 2017 10:42:50 -0400 Subject: [PATCH] fixed SPIR-V int->uint conversion Bug: skia: Change-Id: I31c035ac5839d60521ee9d8f73c879776ef5d22d Reviewed-on: https://skia-review.googlesource.com/24621 Commit-Queue: Ethan Nicholas Reviewed-by: Brian Salomon --- src/sksl/SkSLSPIRVCodeGenerator.cpp | 22 +++++++++++++++++++++- src/sksl/SkSLSPIRVCodeGenerator.h | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index 6426fc8ace..7204cbc357 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -1519,7 +1519,7 @@ SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, OutputStream this->writeInstruction(SpvOpConvertFToS, this->getType(c.fType), result, parameter, out); } else if (c.fArguments[0]->fType == *fContext.fUInt_Type) { - this->writeInstruction(SpvOpSatConvertUToS, this->getType(c.fType), result, parameter, + this->writeInstruction(SpvOpBitcast, this->getType(c.fType), result, parameter, out); } else if (c.fArguments[0]->fType == *fContext.fInt_Type) { return parameter; @@ -1527,6 +1527,24 @@ SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, OutputStream return result; } +SpvId SPIRVCodeGenerator::writeUIntConstructor(const Constructor& c, OutputStream& out) { + ASSERT(c.fType == *fContext.fUInt_Type); + ASSERT(c.fArguments.size() == 1); + ASSERT(c.fArguments[0]->fType.isNumber()); + SpvId result = this->nextId(); + SpvId parameter = this->writeExpression(*c.fArguments[0], out); + if (c.fArguments[0]->fType == *fContext.fFloat_Type) { + this->writeInstruction(SpvOpConvertFToU, this->getType(c.fType), result, parameter, + out); + } else if (c.fArguments[0]->fType == *fContext.fInt_Type) { + this->writeInstruction(SpvOpBitcast, this->getType(c.fType), result, parameter, + out); + } else if (c.fArguments[0]->fType == *fContext.fUInt_Type) { + return parameter; + } + return result; +} + void SPIRVCodeGenerator::writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type, OutputStream& out) { FloatLiteral zero(fContext, Position(), 0); @@ -1642,6 +1660,8 @@ SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, OutputStream& o return this->writeFloatConstructor(c, out); } else if (c.fType == *fContext.fInt_Type) { return this->writeIntConstructor(c, out); + } else if (c.fType == *fContext.fUInt_Type) { + return this->writeUIntConstructor(c, out); } switch (c.fType.kind()) { case Type::kVector_Kind: diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h index 1ce9d0c3fa..4500abbff1 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.h +++ b/src/sksl/SkSLSPIRVCodeGenerator.h @@ -153,6 +153,8 @@ private: SpvId writeIntConstructor(const Constructor& c, OutputStream& out); + SpvId writeUIntConstructor(const Constructor& c, OutputStream& out); + /** * Writes a matrix with the diagonal entries all equal to the provided expression, and all other * entries equal to zero.