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

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

Issue 2351753002: Revert of Stop flattening GrCoordTransforms in parent GrFragmentProcessors. (Closed)
Patch Set: Created 4 years, 3 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/GrGLSLFragmentProcessor.h ('k') | src/gpu/glsl/GrGLSLGeometryProcessor.h » ('j') | 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 2015 Google Inc. 2 * Copyright 2015 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 "GrGLSLFragmentProcessor.h" 8 #include "GrGLSLFragmentProcessor.h"
9 #include "GrFragmentProcessor.h" 9 #include "GrFragmentProcessor.h"
10 #include "GrProcessor.h" 10 #include "GrProcessor.h"
(...skipping 25 matching lines...) Expand all
36 36
37 void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu tColor, 37 void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu tColor,
38 const char* outputColor, EmitArg s& args) { 38 const char* outputColor, EmitArg s& args) {
39 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 39 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
40 40
41 fragBuilder->onBeforeChildProcEmitCode(); // call first so mangleString is updated 41 fragBuilder->onBeforeChildProcEmitCode(); // call first so mangleString is updated
42 42
43 const GrFragmentProcessor& childProc = args.fFp.childProcessor(childIndex); 43 const GrFragmentProcessor& childProc = args.fFp.childProcessor(childIndex);
44 44
45 /* 45 /*
46 * TODO: Move textures and buffers to the iterator model used by coords. 46 * We now want to find the subset of coords and samplers that belong to the child and its
47 * We now want to find the subset of samplers that belong to the child and i ts descendants and 47 * descendants and put that into childCoords and childSamplers. To do so, we 'll do a forwards
48 * put that into childSamplers. To do so, we'll do a forwards linear search. 48 * linear search.
49 * 49 *
50 * Explanation: 50 * Explanation:
51 * Each GrFragmentProcessor has a copy of all the textures of itself and all procs in its 51 * Each GrFragmentProcessor has a copy of all the transforms and textures of itself and
52 * subtree. For example, suppose we have frag proc A, who has two children B and D. B has a 52 * all procs in its subtree. For example, suppose we have frag proc A, who h as two children B
53 * child C, and D has two children E and F. Each frag proc's textures array contains its own 53 * and D. B has a child C, and D has two children E and F. Each frag proc's transforms array
54 * textures, followed by the textures of all its descendants (i.e. preorder traversal). Suppose 54 * contains its own transforms, followed by the transforms of all its descen dants (i.e. preorder
55 * procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 textures respectively. 55 * traversal). Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 transfor ms respectively.
56 * 56 *
57 * (A) 57 * (A)
58 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] 58 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2]
59 * / \ 59 * / \
60 * / \ 60 * / \
61 * (B) (D) 61 * (B) (D)
62 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] 62 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2]
63 * / / \ 63 * / / \
64 * / / \ 64 * / / \
65 * (C) (E) (F) 65 * (C) (E) (F)
66 * [c1] [e1,e2,e3] [f1,f2] 66 * [c1] [e1,e2,e3] [f1,f2]
67 * 67 *
68 * So if we're inside proc A's emitCode, and A is about to call emitCode on proc D, we want the 68 * So if we're inside proc A's emitCode, and A is about to call emitCode on proc D, we want the
69 * EmitArgs that's passed onto D to only contain its and its descendants' te xtures. The 69 * EmitArgs that's passed onto D to only contain its and its descendants' co ords. The
70 * EmitArgs given to A would contain the textures [a1,b1,b2,c1,d1,e1,e2,e3,f 1,f2], and we want 70 * EmitArgs given to A would contain the transforms [a1,b1,b2,c1,d1,e1,e2,e3 ,f1,f2], and we want
71 * to extract the subset [d1,e1,e2,e3,f1,f2] to pass on to D. We can do this with a linear 71 * to extract the subset [d1,e1,e2,e3,f1,f2] to pass on to D. We can do this with a linear
72 * search since we know that A has 1 texture (using A.numTexturesExclChildre n()), and B's 72 * search since we know that A has 1 transform (using A.numTransformsExclChi ldren()), and B's
73 * subtree has 3 textures (using B.numTextures()), so we know the start of D 's textures is 73 * subtree has 3 transforms (using B.numTransforms()), so we know the start of D's transforms is
74 * 4 after the start of A's textures. 74 * 4 after the start of A's transforms.
75 * Textures work the same way as textures. 75 * Textures work the same way as transforms.
76 */ 76 */
77 int firstCoordAt = args.fFp.numTransformsExclChildren();
77 int firstTextureAt = args.fFp.numTexturesExclChildren(); 78 int firstTextureAt = args.fFp.numTexturesExclChildren();
78 int firstBufferAt = args.fFp.numBuffersExclChildren(); 79 int firstBufferAt = args.fFp.numBuffersExclChildren();
79 for (int i = 0; i < childIndex; ++i) { 80 for (int i = 0; i < childIndex; ++i) {
81 firstCoordAt += args.fFp.childProcessor(i).numTransforms();
80 firstTextureAt += args.fFp.childProcessor(i).numTextures(); 82 firstTextureAt += args.fFp.childProcessor(i).numTextures();
81 firstBufferAt += args.fFp.childProcessor(i).numBuffers(); 83 firstBufferAt += args.fFp.childProcessor(i).numBuffers();
82 } 84 }
85 SkTArray<GrShaderVar> childCoords;
83 const SamplerHandle* childTexSamplers = nullptr; 86 const SamplerHandle* childTexSamplers = nullptr;
84 const SamplerHandle* childBufferSamplers = nullptr; 87 const SamplerHandle* childBufferSamplers = nullptr;
88 if (childProc.numTransforms() > 0) {
89 childCoords.push_back_n(childProc.numTransforms(), &args.fTransformedCoo rds[firstCoordAt]);
90 }
85 if (childProc.numTextures() > 0) { 91 if (childProc.numTextures() > 0) {
86 childTexSamplers = &args.fTexSamplers[firstTextureAt]; 92 childTexSamplers = &args.fTexSamplers[firstTextureAt];
87 } 93 }
88 if (childProc.numBuffers() > 0) { 94 if (childProc.numBuffers() > 0) {
89 childBufferSamplers = &args.fBufferSamplers[firstBufferAt]; 95 childBufferSamplers = &args.fBufferSamplers[firstBufferAt];
90 } 96 }
91 97
92 // emit the code for the child in its own scope 98 // emit the code for the child in its own scope
93 fragBuilder->codeAppend("{\n"); 99 fragBuilder->codeAppend("{\n");
94 fragBuilder->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex, 100 fragBuilder->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex,
95 fragBuilder->getMangleString().c_str(), childProc.n ame()); 101 fragBuilder->getMangleString().c_str(), childProc.n ame());
96 EmitArgs childArgs(fragBuilder, 102 EmitArgs childArgs(fragBuilder,
97 args.fUniformHandler, 103 args.fUniformHandler,
98 args.fGLSLCaps, 104 args.fGLSLCaps,
99 childProc, 105 childProc,
100 outputColor, 106 outputColor,
101 inputColor, 107 inputColor,
102 args.fTransformedCoords.childTransforms(childIndex), 108 childCoords,
103 childTexSamplers, 109 childTexSamplers,
104 childBufferSamplers, 110 childBufferSamplers,
105 args.fGpImplementsDistanceVector); 111 args.fGpImplementsDistanceVector);
106 this->childProcessor(childIndex)->emitCode(childArgs); 112 this->childProcessor(childIndex)->emitCode(childArgs);
107 fragBuilder->codeAppend("}\n"); 113 fragBuilder->codeAppend("}\n");
108 114
109 fragBuilder->onAfterChildProcEmitCode(); 115 fragBuilder->onAfterChildProcEmitCode();
110 } 116 }
111
112 //////////////////////////////////////////////////////////////////////////////
113
114 using TransformedCoordVars = GrGLSLFragmentProcessor::TransformedCoordVars;
115 TransformedCoordVars TransformedCoordVars::childTransforms(int childIdx) const {
116 const GrFragmentProcessor* child = &fFP->childProcessor(childIdx);
117 GrFragmentProcessor::Iter iter(fFP);
118 int numToSkip = 0;
119 while (true) {
120 const GrFragmentProcessor* fp = iter.next();
121 if (fp == child) {
122 return TransformedCoordVars(child, fTransformedVars + numToSkip);
123 }
124 numToSkip += fp->numCoordTransforms();
125 }
126 }
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLFragmentProcessor.h ('k') | src/gpu/glsl/GrGLSLGeometryProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698