Skip to content

Commit

Permalink
GrTextureDomain: Go back to doing vector impl when modes are the same
Browse files Browse the repository at this point in the history
Doing it using scalars all the time caused a mysterious shader compilation
issue on Chromecast. In the past we've had similar problems for long shaders.

Change-Id: Ied667c1d4ae47fb4ae9eee62421a7ad52eecebba
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/258880
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
  • Loading branch information
bsalomon authored and Skia Commit-Bot committed Dec 9, 2019
1 parent 90bfd1c commit 095d246
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/gpu/effects/GrTextureDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode modeX, Mode modeY, i

static void append_wrap(GrGLSLShaderBuilder* builder, GrTextureDomain::Mode mode,
const char* inCoord, const char* domainStart, const char* domainEnd,
const char* out) {
bool is2D, const char* out) {
switch(mode) {
case GrTextureDomain::kIgnore_Mode:
builder->codeAppendf("%s = %s;\n", out, inCoord);
Expand All @@ -73,10 +73,11 @@ static void append_wrap(GrGLSLShaderBuilder* builder, GrTextureDomain::Mode mode
domainEnd, domainStart, domainStart);
break;
case GrTextureDomain::kMirrorRepeat_Mode: {
const char* type = is2D ? "float2" : "float";
builder->codeAppend("{");
builder->codeAppendf("float w = %s - %s;", domainEnd, domainStart);
builder->codeAppendf("float w2 = 2 * w;");
builder->codeAppendf("float m = mod(%s - %s, w2);", inCoord, domainStart);
builder->codeAppendf("%s w = %s - %s;", type, domainEnd, domainStart);
builder->codeAppendf("%s w2 = 2 * w;", type);
builder->codeAppendf("%s m = mod(%s - %s, w2);", type, inCoord, domainStart);
builder->codeAppendf("%s = mix(m, w2 - m, step(w, m)) + %s;", out, domainStart);
builder->codeAppend("}");
break;
Expand Down Expand Up @@ -163,18 +164,27 @@ void GrTextureDomain::GLDomain::sample(GrGLSLShaderBuilder* builder,
builder->codeAppend("float2 clampedCoord;");
SkString start;
SkString end;
// Apply x mode to the x coordinate using the left and right edges of the domain rect
// (stored as the x and z components of the domain uniform).
start.printf("%s.x", fDomainName.c_str());
end.printf("%s.z", fDomainName.c_str());
append_wrap(builder, textureDomain.modeX(), "origCoord.x", start.c_str(), end.c_str(),
"clampedCoord.x");
// Repeat the same logic for y.
start.printf("%s.y", fDomainName.c_str());
end.printf("%s.w", fDomainName.c_str());
append_wrap(builder, textureDomain.modeY(), "origCoord.y", start.c_str(), end.c_str(),
"clampedCoord.y");

bool is2D = textureDomain.modeX() == textureDomain.modeY();
if (is2D) {
// Doing the domain setup using vectors seems to avoid shader compilation issues on
// Chromecast, possibly due to reducing shader length.
start.printf("%s.xy", fDomainName.c_str());
end.printf("%s.zw", fDomainName.c_str());
append_wrap(builder, textureDomain.modeX(), "origCoord", start.c_str(), end.c_str(),
true, "clampedCoord");
} else {
// Apply x mode to the x coordinate using the left and right edges of the domain rect
// (stored as the x and z components of the domain uniform).
start.printf("%s.x", fDomainName.c_str());
end.printf("%s.z", fDomainName.c_str());
append_wrap(builder, textureDomain.modeX(), "origCoord.x", start.c_str(), end.c_str(),
false, "clampedCoord.x");
// Repeat the same logic for y.
start.printf("%s.y", fDomainName.c_str());
end.printf("%s.w", fDomainName.c_str());
append_wrap(builder, textureDomain.modeY(), "origCoord.y", start.c_str(), end.c_str(),
false, "clampedCoord.y");
}
// Sample 'appendSample' at the clamped coordinate location.
SkString color = appendSample("clampedCoord");

Expand Down

0 comments on commit 095d246

Please sign in to comment.