added PLS support to SkSL

Bug: skia:
Change-Id: I77fb0861c8cba0f86e3d0521d2ad77e204487d21
Reviewed-on: https://skia-review.googlesource.com/c/99921
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2019-01-11 10:31:48 -05:00 committed by Skia Commit-Bot
parent 28db53d0d9
commit a7ceb50f50
10 changed files with 813 additions and 661 deletions

View File

@ -1112,6 +1112,15 @@ void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
if (modifiers.fFlags & Modifiers::kConst_Flag) {
this->write("const ");
}
if (modifiers.fFlags & Modifiers::kPLS_Flag) {
this->write("__pixel_localEXT ");
}
if (modifiers.fFlags & Modifiers::kPLSIn_Flag) {
this->write("__pixel_local_inEXT ");
}
if (modifiers.fFlags & Modifiers::kPLSOut_Flag) {
this->write("__pixel_local_outEXT ");
}
if (usesPrecisionModifiers()) {
if (modifiers.fFlags & Modifiers::kLowp_Flag) {
this->write("lowp ");
@ -1460,7 +1469,8 @@ void GLSLCodeGenerator::writeProgramElement(const ProgramElement& e) {
this->writeVarDeclarations(decl, true);
this->writeLine();
} else if (builtin == SK_FRAGCOLOR_BUILTIN &&
fProgram.fSettings.fCaps->mustDeclareFragmentShaderOutput()) {
fProgram.fSettings.fCaps->mustDeclareFragmentShaderOutput() &&
((VarDeclaration&) *decl.fVars[0]).fVar->fWriteCount) {
if (fProgram.fSettings.fFragColorIsInOut) {
this->write("inout ");
} else {

View File

@ -822,8 +822,8 @@ std::unique_ptr<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTInte
bool foundRTAdjust = false;
for (size_t i = 0; i < intf.fDeclarations.size(); i++) {
std::unique_ptr<VarDeclarations> decl = this->convertVarDeclarations(
*intf.fDeclarations[i],
Variable::kGlobal_Storage);
*intf.fDeclarations[i],
Variable::kInterfaceBlock_Storage);
if (!decl) {
return nullptr;
}

File diff suppressed because it is too large Load Diff

View File

@ -87,6 +87,12 @@ struct Token {
BUFFER,
#undef HASSIDEEFFECTS
HASSIDEEFFECTS,
#undef PLS
PLS,
#undef PLSIN
PLSIN,
#undef PLSOUT
PLSOUT,
#undef STRUCT
STRUCT,
#undef LAYOUT

View File

@ -913,7 +913,8 @@ Layout Parser::layout() {
}
/* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | MEDIUMP | HIGHP | FLAT | NOPERSPECTIVE |
READONLY | WRITEONLY | COHERENT | VOLATILE | RESTRICT | BUFFER)* */
READONLY | WRITEONLY | COHERENT | VOLATILE | RESTRICT | BUFFER | PLS | PLSIN |
PLSOUT)* */
Modifiers Parser::modifiers() {
Layout layout = this->layout();
int flags = 0;
@ -989,6 +990,18 @@ Modifiers Parser::modifiers() {
this->nextToken();
flags |= Modifiers::kHasSideEffects_Flag;
break;
case Token::PLS:
this->nextToken();
flags |= Modifiers::kPLS_Flag;
break;
case Token::PLSIN:
this->nextToken();
flags |= Modifiers::kPLSIn_Flag;
break;
case Token::PLSOUT:
this->nextToken();
flags |= Modifiers::kPLSOut_Flag;
break;
default:
return Modifiers(layout, flags);
}

View File

@ -64,6 +64,7 @@ struct Layout {
kR8,
kRGBA8I,
kR8I,
kRG16F,
};
// used by SkSL processors
@ -103,6 +104,7 @@ struct Layout {
case Format::kR8: return "r8";
case Format::kRGBA8I: return "rgba8i";
case Format::kR8I: return "r8i";
case Format::kRG16F: return "rg16f";
}
ABORT("Unexpected format");
}
@ -132,6 +134,9 @@ struct Layout {
} else if (str == "r8i") {
*format = Format::kR8I;
return true;
} else if (str == "rg16f") {
*format = Format::kRG16F;
return true;
}
return false;
}

View File

@ -33,7 +33,10 @@ struct Modifiers {
kVolatile_Flag = 1 << 12,
kRestrict_Flag = 1 << 13,
kBuffer_Flag = 1 << 14,
kHasSideEffects_Flag = 1 << 15
kHasSideEffects_Flag = 1 << 15,
kPLS_Flag = 1 << 16,
kPLSIn_Flag = 1 << 17,
kPLSOut_Flag = 1 << 18,
};
Modifiers()
@ -88,7 +91,15 @@ struct Modifiers {
if (fFlags & kHasSideEffects_Flag) {
result += "sk_has_side_effects ";
}
if (fFlags & kPLS_Flag) {
result += "__pixel_localEXT ";
}
if (fFlags & kPLSIn_Flag) {
result += "__pixel_local_inEXT ";
}
if (fFlags & kPLSOut_Flag) {
result += "__pixel_local_outEXT ";
}
if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) {
result += "inout ";
} else if (fFlags & kIn_Flag) {

View File

@ -25,6 +25,7 @@ struct Expression;
struct Variable : public Symbol {
enum Storage {
kGlobal_Storage,
kInterfaceBlock_Storage,
kLocal_Storage,
kParameter_Storage
};
@ -52,7 +53,9 @@ struct Variable : public Symbol {
}
bool dead() const {
return !fWriteCount || (!fReadCount && !(fModifiers.fFlags & Modifiers::kOut_Flag));
return !fWriteCount || (!fReadCount && !(fModifiers.fFlags & (Modifiers::kOut_Flag |
Modifiers::kPLS_Flag |
Modifiers::kPLSOut_Flag)));
}
mutable Modifiers fModifiers;

View File

@ -33,6 +33,9 @@ VOLATILE = "volatile"
RESTRICT = "restrict"
BUFFER = "buffer"
HASSIDEEFFECTS = "sk_has_side_effects"
PLS = "__pixel_localEXT"
PLSIN = "__pixel_local_inEXT"
PLSOUT = "__pixel_local_outEXT"
STRUCT = "struct"
LAYOUT = "layout"
PRECISION = "precision"

View File

@ -145,7 +145,6 @@ DEF_TEST(SkSLOperators, r) {
"}",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" float x = 1.0, y = 2.0;\n"
" int z = 3;\n"
@ -265,7 +264,6 @@ DEF_TEST(SkSLStructs, r) {
"}",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"struct A {\n"
" int x;\n"
" int y;\n"
@ -425,7 +423,6 @@ DEF_TEST(SkSLModifiersDeclaration, r) {
"void main() { }",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"layout (blend_support_all_equations) out ;\n"
"layout (blend_support_all_equations) out ;\n"
"layout (blend_support_multiply) out ;\n"
@ -473,7 +470,6 @@ DEF_TEST(SkSLHex, r) {
"}",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" int i1 = 0;\n"
" i1++;\n"
@ -509,7 +505,6 @@ DEF_TEST(SkSLVectorConstructors, r) {
"float2 v7 = float2(int2(1, 2));",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"vec2 v1 = vec2(1.0);\n"
"vec2 v2 = vec2(1.0, 2.0);\n"
"vec2 v3 = vec2(1.0);\n"
@ -526,7 +521,6 @@ DEF_TEST(SkSLArrayConstructors, r) {
"float4x4 test3[] = float4x4[]();",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"float test1[] = float[](1.0, 2.0, 3.0, 4.0);\n"
"vec2 test2[] = vec2[](vec2(1.0, 2.0), vec2(3.0, 4.0));\n"
"mat4 test3[] = mat4[]();\n");
@ -1098,7 +1092,6 @@ DEF_TEST(SkSLOffset, r) {
"} test;",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"struct Test {\n"
" layout (offset = 0) int x;\n"
" layout (offset = 4) int y;\n"
@ -1664,7 +1657,6 @@ DEF_TEST(SkSLDeadLoopVar, r) {
"}",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" for (; true; ) {\n"
" break;\n"
@ -1763,7 +1755,6 @@ DEF_TEST(SkSLTypePrecision, r) {
"double4x2 d42 = double4x2(1, 2, 3, 4, 5, 6, 7, 8);",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"float f = 1.0;\n"
"float h = 2.0;\n"
"double d = 3.0;\n"
@ -1783,7 +1774,6 @@ DEF_TEST(SkSLTypePrecision, r) {
*SkSL::ShaderCapsFactory::UsesPrecisionModifiers(),
"#version 400\n"
"precision mediump float;\n"
"out mediump vec4 sk_FragColor;\n"
"highp float f = 1.0;\n"
"mediump float h = 2.0;\n"
"highp vec2 f2 = vec2(1.0, 2.0);\n"
@ -1832,7 +1822,6 @@ DEF_TEST(SkSLNumberConversions, r) {
"float f2f = f;",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"int s = int(sqrt(1.0));\n"
"int i = int(sqrt(1.0));\n"
"uint us = uint(sqrt(1.0));\n"
@ -2060,7 +2049,6 @@ DEF_TEST(SkSLWorkaroundAddAndTrueToLoopCondition, r) {
"}",
*SkSL::ShaderCapsFactory::AddAndTrueToLoopCondition(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" int c = 0;\n"
" for (int i = 0;(i < 4 || c < 10) && true; ++i) {\n"