Remove legacy runtime effect main signature

Chromium has been updated: http://crrev.com/c/2375932

Bug: skia:10613
Change-Id: I375ed986c7f2d031950776698534a922d83b9e61
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313379
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
Brian Osman 2020-08-26 09:27:39 -04:00 committed by Skia Commit-Bot
parent 38e81a5398
commit 44820a99b7
4 changed files with 6 additions and 112 deletions

View File

@ -347,25 +347,12 @@ static skvm::Color program_fn(skvm::Builder* p,
auto push = [&](skvm::F32 x) { stack.push_back(x); };
auto pop = [&]{ skvm::F32 x = stack.back(); stack.pop_back(); return x; };
#ifdef SK_USE_LEGACY_RUNTIME_EFFECT_SIGNATURE
// main(inout half4 color) or main(float2 local, inout half4 color)
SkASSERT(fn.getParameterCount() == 4 || fn.getParameterCount() == 6);
if (fn.getParameterCount() == 6) {
push(local.x);
push(local.y);
}
push(inColor.r);
push(inColor.g);
push(inColor.b);
push(inColor.a);
#else
// half4 main() or half4 main(float2 local)
SkASSERT(fn.getParameterCount() == 0 || fn.getParameterCount() == 2);
if (fn.getParameterCount() == 2) {
push(local.x);
push(local.y);
}
#endif
for (int i = 0; i < fn.getLocalCount(); i++) {
push(p->splat(0.0f));
@ -600,39 +587,21 @@ static skvm::Color program_fn(skvm::Builder* p,
} break;
case Inst::kReturn: {
#ifdef SK_USE_LEGACY_RUNTIME_EFFECT_SIGNATURE
SkAssertResult(u8() == 0);
SkASSERT(ip == end);
#else
SkAssertResult(u8() == 4);
// We'd like to assert that (ip == end) -> there is only one return, but ByteCode
// always includes a kReturn/0 at the end of each function, as a precaution.
// SkASSERT(ip == end);
SkASSERT(stack.size() >= 4);
skvm::F32 a = pop(),
b = pop(),
g = pop(),
r = pop();
return { r, g, b, a };
#endif
} break;
}
}
#ifdef SK_USE_LEGACY_RUNTIME_EFFECT_SIGNATURE
for (int i = 0; i < fn.getLocalCount(); i++) {
pop();
}
SkASSERT(stack.size() == (size_t)fn.getParameterCount());
skvm::F32 a = pop(),
b = pop(),
g = pop(),
r = pop();
return { r, g, b, a };
#else
SkUNREACHABLE;
return {};
#endif
}
static sk_sp<SkData> get_xformed_uniforms(const SkRuntimeEffect* effect,

View File

@ -11,25 +11,6 @@
#include "include/private/SkColorData.h"
sk_sp<SkColorFilter> SkOverdrawColorFilter::MakeWithSkColors(const SkColor colors[kNumColors]) {
#ifdef SK_USE_LEGACY_RUNTIME_EFFECT_SIGNATURE
auto [effect, err] = SkRuntimeEffect::Make(SkString(R"(
uniform half4 color0;
uniform half4 color1;
uniform half4 color2;
uniform half4 color3;
uniform half4 color4;
uniform half4 color5;
void main(inout half4 color) {
half alpha = 255.0 * color.a;
color = alpha < 0.5 ? color0
: alpha < 1.5 ? color1
: alpha < 2.5 ? color2
: alpha < 3.5 ? color3
: alpha < 4.5 ? color4 : color5;
}
)"));
#else
auto [effect, err] = SkRuntimeEffect::Make(SkString(R"(
uniform half4 color0;
uniform half4 color1;
@ -50,19 +31,14 @@ sk_sp<SkColorFilter> SkOverdrawColorFilter::MakeWithSkColors(const SkColor color
return color;
}
)"));
#endif
if (effect) {
auto data = SkData::MakeUninitialized(kNumColors * sizeof(SkPMColor4f));
SkPMColor4f* premul = (SkPMColor4f*)data->writable_data();
for (int i = 0; i < kNumColors; ++i) {
premul[i] = SkColor4f::FromColor(colors[i]).premul();
}
#ifdef SK_USE_LEGACY_RUNTIME_EFFECT_SIGNATURE
return effect->makeColorFilter(std::move(data));
#else
sk_sp<SkColorFilter> input = nullptr;
return effect->makeColorFilter(std::move(data), &input, 1);
#endif
}
return nullptr;
}

View File

@ -45,13 +45,7 @@ public:
std::unique_ptr<GrFragmentProcessor> clone() const override;
bool usesExplicitReturn() const override {
#ifdef SK_USE_LEGACY_RUNTIME_EFFECT_SIGNATURE
return false;
#else
return true;
#endif
}
bool usesExplicitReturn() const override { return true; }
private:
using ShaderErrorHandler = GrContextOptions::ShaderErrorHandler;

View File

@ -936,37 +936,10 @@ void IRGenerator::convertFunction(const ASTNode& f) {
return parameters[idx]->fType == *fContext.fFloat2_Type &&
parameters[idx]->fModifiers.fFlags == 0;
};
#ifdef SK_USE_LEGACY_RUNTIME_EFFECT_SIGNATURE
auto paramIsColor = [&](int idx) {
return parameters[idx]->fType == *fContext.fHalf4_Type &&
parameters[idx]->fModifiers.fFlags == (Modifiers::kIn_Flag | Modifiers::kOut_Flag);
};
#endif
if (funcData.fName == "main") {
switch (fKind) {
case Program::kPipelineStage_Kind: {
#ifdef SK_USE_LEGACY_RUNTIME_EFFECT_SIGNATURE
// void main(inout half4) -or- void main(float2, inout half4)
bool valid = (*returnType == *fContext.fVoid_Type);
switch (parameters.size()) {
case 2:
valid &= paramIsCoords(0) && paramIsColor(1);
break;
case 1:
valid &= paramIsColor(0);
break;
default:
valid &= false;
}
if (!valid) {
fErrors.error(f.fOffset, "pipeline stage 'main' must be declared "
"void main(inout half4) or "
"void main(float2, inout half4)");
return;
}
break;
#else
// half4 main() -or- half4 main(float2)
bool valid = (*returnType == *fContext.fHalf4_Type) &&
((parameters.size() == 0) ||
@ -977,15 +950,10 @@ void IRGenerator::convertFunction(const ASTNode& f) {
return;
}
break;
#endif
}
}
case Program::kFragmentProcessor_Kind: {
bool valid = parameters.size() <= 1;
if (parameters.size() == 1) {
valid = parameters[0]->fType == *fContext.fFloat2_Type &&
parameters[0]->fModifiers.fFlags == 0;
}
bool valid = (parameters.size() == 0) ||
(parameters.size() == 1 && paramIsCoords(0));
if (!valid) {
fErrors.error(f.fOffset, ".fp 'main' must be declared main() or main(float2)");
return;
@ -1075,25 +1043,12 @@ void IRGenerator::convertFunction(const ASTNode& f) {
fCurrentFunction = decl;
std::shared_ptr<SymbolTable> old = fSymbolTable;
AutoSymbolTable table(this);
if (funcData.fName == "main" && fKind == Program::kPipelineStage_Kind) {
#ifdef SK_USE_LEGACY_RUNTIME_EFFECT_SIGNATURE
if (parameters.size() == 2) {
parameters[0]->fModifiers.fLayout.fBuiltin = SK_MAIN_COORDS_BUILTIN;
parameters[1]->fModifiers.fLayout.fBuiltin = SK_OUTCOLOR_BUILTIN;
} else {
SkASSERT(parameters.size() == 1);
parameters[0]->fModifiers.fLayout.fBuiltin = SK_OUTCOLOR_BUILTIN;
}
#else
if (funcData.fName == "main" && (fKind == Program::kPipelineStage_Kind ||
fKind == Program::kFragmentProcessor_Kind)) {
if (parameters.size() == 1) {
SkASSERT(paramIsCoords(0));
parameters[0]->fModifiers.fLayout.fBuiltin = SK_MAIN_COORDS_BUILTIN;
}
#endif
} else if (funcData.fName == "main" && fKind == Program::kFragmentProcessor_Kind) {
if (parameters.size() == 1) {
parameters[0]->fModifiers.fLayout.fBuiltin = SK_MAIN_COORDS_BUILTIN;
}
}
for (size_t i = 0; i < parameters.size(); i++) {
fSymbolTable->addWithoutOwnership(parameters[i]->fName, decl->fParameters[i]);