Skip to content

Commit 808f021

Browse files
brianosmanSkia Commit-Bot
authored andcommitted
Improve error handling in SkSL ByteCode
- Allow for $floatLiteral and $intLiteral when determining type categories. These could slip into the IR, leading to asserts. - We weren't propagating the source text in specialize(), so errors in the ByteCodeGenerator would actually assert about a missing fSource. It's held by unique_ptr on Program, so we wastefully clone the string, but we don't have that many specializations yet, so not too bad? Change-Id: I9c79acfb084e6dc8628625dea039c085ec46dba7 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265598 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
1 parent ea7711d commit 808f021

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

samplecode/Sample3D.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,6 @@ class SamplePointLight3D : public Sample3DView {
406406
}
407407

408408
void onDrawContent(SkCanvas* canvas) override {
409-
if (canvas->getGrContext() == nullptr) {
410-
return;
411-
}
412409
SkM44 clickM = canvas->experimental_getLocalToDevice();
413410

414411
canvas->save();

src/sksl/SkSLByteCodeGenerator.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ static TypeCategory type_category(const Type& type) {
1919
default:
2020
if (type.fName == "bool") {
2121
return TypeCategory::kBool;
22-
} else if (type.fName == "int" || type.fName == "short") {
22+
} else if (type.fName == "int" ||
23+
type.fName == "short" ||
24+
type.fName == "$intLiteral") {
2325
return TypeCategory::kSigned;
24-
} else if (type.fName == "uint" || type.fName == "ushort") {
26+
} else if (type.fName == "uint" ||
27+
type.fName == "ushort") {
2528
return TypeCategory::kUnsigned;
2629
} else {
27-
SkASSERT(type.fName == "float" || type.fName == "half");
30+
SkASSERT(type.fName == "float" ||
31+
type.fName == "half" ||
32+
type.fName == "$floatLiteral");
2833
return TypeCategory::kFloat;
2934
}
3035
ABORT("unsupported type: %s\n", type.displayName().c_str());
@@ -979,7 +984,8 @@ void ByteCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
979984
void ByteCodeGenerator::writeIntrinsicCall(const FunctionCall& c) {
980985
auto found = fIntrinsics.find(c.fFunction.fName);
981986
if (found == fIntrinsics.end()) {
982-
fErrors.error(c.fOffset, "unsupported intrinsic function");
987+
fErrors.error(c.fOffset, String::printf("Unsupported intrinsic: '%s'",
988+
String(c.fFunction.fName).c_str()));
983989
return;
984990
}
985991
int count = SlotCount(c.fArguments[0]->fType);

src/sksl/SkSLCompiler.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,8 +1481,9 @@ std::unique_ptr<Program> Compiler::specialize(
14811481
for (auto iter = inputs.begin(); iter != inputs.end(); ++iter) {
14821482
settings.fArgs.insert(*iter);
14831483
}
1484+
std::unique_ptr<String> sourceCopy(new String(*program.fSource));
14841485
std::unique_ptr<Program> result(new Program(program.fKind,
1485-
nullptr,
1486+
std::move(sourceCopy),
14861487
settings,
14871488
program.fContext,
14881489
program.fInheritedElements,
@@ -1621,9 +1622,12 @@ std::unique_ptr<ByteCode> Compiler::toByteCode(Program& program) {
16211622
if (!this->optimize(program)) {
16221623
return nullptr;
16231624
}
1625+
fSource = program.fSource.get();
16241626
std::unique_ptr<ByteCode> result(new ByteCode());
16251627
ByteCodeGenerator cg(fContext.get(), &program, this, result.get());
1626-
if (cg.generateCode()) {
1628+
bool success = cg.generateCode();
1629+
fSource = nullptr;
1630+
if (success) {
16271631
return result;
16281632
}
16291633
#else

0 commit comments

Comments
 (0)