More ctype cleanup in SkSL

- Remove ctypes that were entirely unused
- Remove explicit selection of default ctypes
- After that, only two ctype tokens are needed (SkPMColor4f and SkV4)
  ... remove all of the others from the parser

Change-Id: I2322aab73a19127b3b26850aefdad6140ea0f7e7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/410057
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2021-05-18 15:33:10 -04:00 committed by Skia Commit-Bot
parent 60e52284d5
commit 1391170bee
12 changed files with 24 additions and 79 deletions

View File

@ -52,24 +52,18 @@ struct Layout {
}; };
enum class CType { enum class CType {
kDefault, kDefault, // Default for:
kBool, kFloat, // float, half
kFloat, kInt32, // int, short
kFloat2, kSkRect, // float4, half4
kFloat3, kSkIRect, // int4, short4
kFloat4,
kInt32,
kSkRect,
kSkIRect,
kSkPMColor4f, kSkPMColor4f,
kSkPMColor,
kSkV4, kSkV4,
kSkPoint, kSkPoint, // float2, half2
kSkIPoint, kSkIPoint, // int2, short2
kSkMatrix, kSkMatrix, // float3x3, half3x3
kSkM44, kSkM44, // float4x4, half4x4
kGrSurfaceProxyView, kGrFragmentProcessor, // fragmentProcessor
kGrFragmentProcessor,
}; };
static const char* CTypeToStr(CType ctype) { static const char* CTypeToStr(CType ctype) {
@ -86,8 +80,6 @@ struct Layout {
return "SkIRect"; return "SkIRect";
case CType::kSkPMColor4f: case CType::kSkPMColor4f:
return "SkPMColor4f"; return "SkPMColor4f";
case CType::kSkPMColor:
return "SkPMColor";
case CType::kSkV4: case CType::kSkV4:
return "SkV4"; return "SkV4";
case CType::kSkPoint: case CType::kSkPoint:
@ -98,8 +90,6 @@ struct Layout {
return "SkMatrix"; return "SkMatrix";
case CType::kSkM44: case CType::kSkM44:
return "SkM44"; return "SkM44";
case CType::kGrSurfaceProxyView:
return "GrSurfaceProxyView";
case CType::kGrFragmentProcessor: case CType::kGrFragmentProcessor:
return "std::unique_ptr<GrFragmentProcessor>"; return "std::unique_ptr<GrFragmentProcessor>";
default: default:

View File

@ -14,7 +14,7 @@ layout (
max_vertices = 1, max_vertices = 1,
invocations = 1, invocations = 1,
when = one, when = one,
ctype = int) ctype = SkPMColor4f)
void on_return() {} void on_return() {}
void on_param( void on_param(
@ -34,4 +34,4 @@ layout (
max_vertices = 1, max_vertices = 1,
invocations = 1, invocations = 1,
when = one, when = one,
ctype = int) float x) {} ctype = SkPMColor4f) float x) {}

View File

@ -14,7 +14,7 @@ layout (
max_vertices = 1, max_vertices = 1,
invocations = 1, invocations = 1,
when = one, when = one,
ctype = int, ctype = SkPMColor4f,
origin_upper_left, origin_upper_left,
push_constant, push_constant,
@ -31,5 +31,5 @@ layout (
max_vertices = 2, max_vertices = 2,
invocations = 2, invocations = 2,
when = two, when = two,
ctype = float ctype = SkV4
) float x; ) float x;

View File

@ -7,8 +7,8 @@
in fragmentProcessor inputFP; in fragmentProcessor inputFP;
layout(key) in GrClipEdgeType edgeType; layout(key) in GrClipEdgeType edgeType;
layout(ctype=SkRect) in float4 rect; in float4 rect;
layout(ctype=SkRect) float4 prevRect = float4(-1); float4 prevRect = float4(-1);
uniform float4 rectUniform; uniform float4 rectUniform;
@optimizationFlags { @optimizationFlags {

View File

@ -6,7 +6,7 @@
*/ */
in fragmentProcessor inputFP; in fragmentProcessor inputFP;
layout(ctype=SkM44) in uniform half4x4 m; in uniform half4x4 m;
layout(ctype=SkV4) in uniform half4 v; layout(ctype=SkV4) in uniform half4 v;
layout(key) in bool unpremulInput; layout(key) in bool unpremulInput;
layout(key) in bool clampRGBOutput; layout(key) in bool clampRGBOutput;

View File

@ -6,9 +6,9 @@
*/ */
in fragmentProcessor src; in fragmentProcessor src;
layout(ctype=SkIRect) in int4 bounds; in int4 bounds;
uniform float4 boundsUniform; uniform float4 boundsUniform;
layout(ctype=SkRect) in float4 srcRect; in float4 srcRect;
in uniform float xInvZoom; in uniform float xInvZoom;
in uniform float yInvZoom; in uniform float yInvZoom;
in uniform float xInvInset; in uniform float xInvInset;

View File

@ -7,10 +7,10 @@
in fragmentProcessor inputFP; in fragmentProcessor inputFP;
in float sigma; in float sigma;
layout(ctype=SkRect) in float4 rect; in float4 rect;
in uniform half cornerRadius; in uniform half cornerRadius;
in fragmentProcessor ninePatchFP; in fragmentProcessor ninePatchFP;
layout(ctype=SkRect) uniform float4 proxyRect; uniform float4 proxyRect;
uniform half blurRadius; uniform half blurRadius;
@header { @header {

View File

@ -111,13 +111,6 @@ void Parser::InitLayoutMap() {
TOKEN(CTYPE, "ctype"); TOKEN(CTYPE, "ctype");
TOKEN(SKPMCOLOR4F, "SkPMColor4f"); TOKEN(SKPMCOLOR4F, "SkPMColor4f");
TOKEN(SKV4, "SkV4"); TOKEN(SKV4, "SkV4");
TOKEN(SKRECT, "SkRect");
TOKEN(SKIRECT, "SkIRect");
TOKEN(SKPMCOLOR, "SkPMColor");
TOKEN(SKM44, "SkM44");
TOKEN(BOOL, "bool");
TOKEN(INT, "int");
TOKEN(FLOAT, "float");
#undef TOKEN #undef TOKEN
} }
@ -848,20 +841,6 @@ Layout::CType Parser::layoutCType() {
return Layout::CType::kSkPMColor4f; return Layout::CType::kSkPMColor4f;
case LayoutToken::SKV4: case LayoutToken::SKV4:
return Layout::CType::kSkV4; return Layout::CType::kSkV4;
case LayoutToken::SKRECT:
return Layout::CType::kSkRect;
case LayoutToken::SKIRECT:
return Layout::CType::kSkIRect;
case LayoutToken::SKPMCOLOR:
return Layout::CType::kSkPMColor;
case LayoutToken::BOOL:
return Layout::CType::kBool;
case LayoutToken::INT:
return Layout::CType::kInt32;
case LayoutToken::FLOAT:
return Layout::CType::kFloat;
case LayoutToken::SKM44:
return Layout::CType::kSkM44;
default: default:
break; break;
} }

View File

@ -54,13 +54,6 @@ public:
CTYPE, CTYPE,
SKPMCOLOR4F, SKPMCOLOR4F,
SKV4, SKV4,
SKRECT,
SKIRECT,
SKPMCOLOR,
SKM44,
BOOL,
INT,
FLOAT,
}; };
Parser(const char* text, size_t length, SymbolTable& symbols, ErrorReporter& errors); Parser(const char* text, size_t length, SymbolTable& symbols, ErrorReporter& errors);

View File

@ -165,12 +165,6 @@ String CPPCodeGenerator::formatRuntimeValue(const Type& type,
} }
if (type == *fContext.fTypes.fFloat4 || type == *fContext.fTypes.fHalf4) { if (type == *fContext.fTypes.fFloat4 || type == *fContext.fTypes.fHalf4) {
switch (layout.fCType) { switch (layout.fCType) {
case Layout::CType::kSkPMColor:
formatArgs->push_back("SkGetPackedR32(" + cppCode + ") / 255.0");
formatArgs->push_back("SkGetPackedG32(" + cppCode + ") / 255.0");
formatArgs->push_back("SkGetPackedB32(" + cppCode + ") / 255.0");
formatArgs->push_back("SkGetPackedA32(" + cppCode + ") / 255.0");
break;
case Layout::CType::kSkPMColor4f: case Layout::CType::kSkPMColor4f:
formatArgs->push_back(cppCode + ".fR"); formatArgs->push_back(cppCode + ".fR");
formatArgs->push_back(cppCode + ".fG"); formatArgs->push_back(cppCode + ".fG");

View File

@ -156,12 +156,6 @@ String DSLCPPCodeGenerator::formatRuntimeValue(const Type& type,
} }
if (type == *fContext.fTypes.fFloat4 || type == *fContext.fTypes.fHalf4) { if (type == *fContext.fTypes.fFloat4 || type == *fContext.fTypes.fHalf4) {
switch (layout.fCType) { switch (layout.fCType) {
case Layout::CType::kSkPMColor:
formatArgs->push_back("SkGetPackedR32(" + cppCode + ") / 255.0");
formatArgs->push_back("SkGetPackedG32(" + cppCode + ") / 255.0");
formatArgs->push_back("SkGetPackedB32(" + cppCode + ") / 255.0");
formatArgs->push_back("SkGetPackedA32(" + cppCode + ") / 255.0");
break;
case Layout::CType::kSkPMColor4f: case Layout::CType::kSkPMColor4f:
formatArgs->push_back(cppCode + ".fR"); formatArgs->push_back(cppCode + ".fR");
formatArgs->push_back(cppCode + ".fG"); formatArgs->push_back(cppCode + ".fG");

View File

@ -52,16 +52,13 @@ Layout::CType HCodeGenerator::ParameterCType(const Context& context, const Type&
} }
if (type == *context.fTypes.fFloat || type == *context.fTypes.fHalf) { if (type == *context.fTypes.fFloat || type == *context.fTypes.fHalf) {
return Layout::CType::kFloat; return Layout::CType::kFloat;
} else if (type == *context.fTypes.fInt || } else if (type == *context.fTypes.fInt || type == *context.fTypes.fShort) {
type == *context.fTypes.fShort) {
return Layout::CType::kInt32; return Layout::CType::kInt32;
} else if (type == *context.fTypes.fFloat2 || type == *context.fTypes.fHalf2) { } else if (type == *context.fTypes.fFloat2 || type == *context.fTypes.fHalf2) {
return Layout::CType::kSkPoint; return Layout::CType::kSkPoint;
} else if (type == *context.fTypes.fInt2 || } else if (type == *context.fTypes.fInt2 || type == *context.fTypes.fShort2) {
type == *context.fTypes.fShort2) {
return Layout::CType::kSkIPoint; return Layout::CType::kSkIPoint;
} else if (type == *context.fTypes.fInt4 || } else if (type == *context.fTypes.fInt4 || type == *context.fTypes.fShort4) {
type == *context.fTypes.fShort4) {
return Layout::CType::kSkIRect; return Layout::CType::kSkIRect;
} else if (type == *context.fTypes.fFloat4 || type == *context.fTypes.fHalf4) { } else if (type == *context.fTypes.fFloat4 || type == *context.fTypes.fHalf4) {
return Layout::CType::kSkRect; return Layout::CType::kSkRect;
@ -69,8 +66,6 @@ Layout::CType HCodeGenerator::ParameterCType(const Context& context, const Type&
return Layout::CType::kSkMatrix; return Layout::CType::kSkMatrix;
} else if (type == *context.fTypes.fFloat4x4 || type == *context.fTypes.fHalf4x4) { } else if (type == *context.fTypes.fFloat4x4 || type == *context.fTypes.fHalf4x4) {
return Layout::CType::kSkM44; return Layout::CType::kSkM44;
} else if (type.typeKind() == Type::TypeKind::kSampler) {
return Layout::CType::kGrSurfaceProxyView;
} else if (type.isFragmentProcessor()) { } else if (type.isFragmentProcessor()) {
return Layout::CType::kGrFragmentProcessor; return Layout::CType::kGrFragmentProcessor;
} }