Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/gpu/glsl/GrGLSLXferProcessor.cpp

Issue 2248403003: Fix various issues with framebuffer fetch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "glsl/GrGLSLXferProcessor.h" 8 #include "glsl/GrGLSLXferProcessor.h"
9 9
10 #include "GrXferProcessor.h" 10 #include "GrXferProcessor.h"
11 #include "glsl/GrGLSLFragmentShaderBuilder.h" 11 #include "glsl/GrGLSLFragmentShaderBuilder.h"
12 #include "glsl/GrGLSLProgramDataManager.h" 12 #include "glsl/GrGLSLProgramDataManager.h"
13 #include "glsl/GrGLSLUniformHandler.h" 13 #include "glsl/GrGLSLUniformHandler.h"
14 14
15 void GrGLSLXferProcessor::emitCode(const EmitArgs& args) { 15 void GrGLSLXferProcessor::emitCode(const EmitArgs& args) {
16 if (!args.fXP.willReadDstColor()) { 16 if (!args.fXP.willReadDstColor()) {
17 this->emitOutputsForBlendState(args); 17 this->emitOutputsForBlendState(args);
18 return; 18 return;
19 } 19 }
20 20
21 GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder; 21 GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder;
22 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; 22 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
23 const char* dstColor = fragBuilder->dstColor(); 23 const char* dstColor = fragBuilder->dstColor();
24 24
25 bool needsLocalOutColor = false;
26
25 if (args.fXP.getDstTexture()) { 27 if (args.fXP.getDstTexture()) {
26 bool topDown = kTopLeft_GrSurfaceOrigin == args.fXP.getDstTexture()->ori gin(); 28 bool topDown = kTopLeft_GrSurfaceOrigin == args.fXP.getDstTexture()->ori gin();
27 29
28 if (args.fInputCoverage) { 30 if (args.fInputCoverage) {
29 // We don't think any shaders actually output negative coverage, but just as a safety 31 // We don't think any shaders actually output negative coverage, but just as a safety
30 // check for floating point precision errors we compare with <= here 32 // check for floating point precision errors we compare with <= here
31 fragBuilder->codeAppendf("if (all(lessThanEqual(%s, vec4(0)))) {" 33 fragBuilder->codeAppendf("if (all(lessThanEqual(%s, vec4(0)))) {"
32 " discard;" 34 " discard;"
33 "}", args.fInputCoverage); 35 "}", args.fInputCoverage);
34 } 36 }
(...skipping 17 matching lines...) Expand all
52 fragBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;", 54 fragBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;",
53 fragPos, dstTopLeftName, dstCoordScaleName); 55 fragPos, dstTopLeftName, dstCoordScaleName);
54 56
55 if (!topDown) { 57 if (!topDown) {
56 fragBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;"); 58 fragBuilder->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;");
57 } 59 }
58 60
59 fragBuilder->codeAppendf("vec4 %s = ", dstColor); 61 fragBuilder->codeAppendf("vec4 %s = ", dstColor);
60 fragBuilder->appendTextureLookup(args.fTexSamplers[0], "_dstTexCoord", k Vec2f_GrSLType); 62 fragBuilder->appendTextureLookup(args.fTexSamplers[0], "_dstTexCoord", k Vec2f_GrSLType);
61 fragBuilder->codeAppend(";"); 63 fragBuilder->codeAppend(";");
64 } else {
65 needsLocalOutColor = args.fGLSLCaps->requiresLocalOutputColorForFBFetch( );
66 }
67
68 const char* outColor = "_localColorOut";
69 if (!needsLocalOutColor) {
70 outColor = args.fOutputPrimary;
71 } else {
72 fragBuilder->codeAppendf("vec4 %s;", outColor);
62 } 73 }
63 74
64 this->emitBlendCodeForDstRead(fragBuilder, 75 this->emitBlendCodeForDstRead(fragBuilder,
65 uniformHandler, 76 uniformHandler,
66 args.fInputColor, 77 args.fInputColor,
67 args.fInputCoverage, 78 args.fInputCoverage,
68 dstColor, 79 dstColor,
69 args.fOutputPrimary, 80 outColor,
70 args.fOutputSecondary, 81 args.fOutputSecondary,
71 args.fXP); 82 args.fXP);
83 if (needsLocalOutColor) {
84 fragBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, outColor);
85 }
72 } 86 }
73 87
74 void GrGLSLXferProcessor::setData(const GrGLSLProgramDataManager& pdm, const GrX ferProcessor& xp) { 88 void GrGLSLXferProcessor::setData(const GrGLSLProgramDataManager& pdm, const GrX ferProcessor& xp) {
75 if (xp.getDstTexture()) { 89 if (xp.getDstTexture()) {
76 if (fDstTopLeftUni.isValid()) { 90 if (fDstTopLeftUni.isValid()) {
77 pdm.set2f(fDstTopLeftUni, static_cast<float>(xp.dstTextureOffset().f X), 91 pdm.set2f(fDstTopLeftUni, static_cast<float>(xp.dstTextureOffset().f X),
78 static_cast<float>(xp.dstTextureOffset().fY)); 92 static_cast<float>(xp.dstTextureOffset().fY));
79 pdm.set2f(fDstScaleUni, 1.f / xp.getDstTexture()->width(), 93 pdm.set2f(fDstScaleUni, 1.f / xp.getDstTexture()->width(),
80 1.f / xp.getDstTexture()->height()); 94 1.f / xp.getDstTexture()->height());
81 } else { 95 } else {
(...skipping 17 matching lines...) Expand all
99 fragBuilder->codeAppendf("%s *= %s;", outColor, srcCoverage); 113 fragBuilder->codeAppendf("%s *= %s;", outColor, srcCoverage);
100 fragBuilder->codeAppendf("%s = %s;", outColorSecondary, srcCoverage) ; 114 fragBuilder->codeAppendf("%s = %s;", outColorSecondary, srcCoverage) ;
101 } else { 115 } else {
102 fragBuilder->codeAppendf("%s = vec4(1.0);", outColorSecondary); 116 fragBuilder->codeAppendf("%s = vec4(1.0);", outColorSecondary);
103 } 117 }
104 } else if (srcCoverage) { 118 } else if (srcCoverage) {
105 fragBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", 119 fragBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;",
106 outColor, srcCoverage, outColor, srcCoverage, d stColor); 120 outColor, srcCoverage, outColor, srcCoverage, d stColor);
107 } 121 }
108 } 122 }
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698