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

Side by Side Diff: src/gpu/gl/GrGLProgram.cpp

Issue 1192463003: Don't call bindTexture from GrGLProgram (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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/gl/GrGLProgram.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.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 2011 Google Inc. 2 * Copyright 2011 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 "GrGLProgram.h" 8 #include "GrGLProgram.h"
9 9
10 #include "GrAllocator.h" 10 #include "GrAllocator.h"
(...skipping 16 matching lines...) Expand all
27 27
28 //////////////////////////////////////////////////////////////////////////////// /////////////////// 28 //////////////////////////////////////////////////////////////////////////////// ///////////////////
29 29
30 GrGLProgram::GrGLProgram(GrGLGpu* gpu, 30 GrGLProgram::GrGLProgram(GrGLGpu* gpu,
31 const GrProgramDesc& desc, 31 const GrProgramDesc& desc,
32 const BuiltinUniformHandles& builtinUniforms, 32 const BuiltinUniformHandles& builtinUniforms,
33 GrGLuint programID, 33 GrGLuint programID,
34 const UniformInfoArray& uniforms, 34 const UniformInfoArray& uniforms,
35 GrGLInstalledGeoProc* geometryProcessor, 35 GrGLInstalledGeoProc* geometryProcessor,
36 GrGLInstalledXferProc* xferProcessor, 36 GrGLInstalledXferProc* xferProcessor,
37 GrGLInstalledFragProcs* fragmentProcessors) 37 GrGLInstalledFragProcs* fragmentProcessors,
38 SkTArray<UniformHandle>* passSamplerUniforms)
38 : fColor(GrColor_ILLEGAL) 39 : fColor(GrColor_ILLEGAL)
39 , fCoverage(0) 40 , fCoverage(0)
40 , fDstTextureUnit(-1) 41 , fDstTextureUnit(-1)
41 , fBuiltinUniformHandles(builtinUniforms) 42 , fBuiltinUniformHandles(builtinUniforms)
42 , fProgramID(programID) 43 , fProgramID(programID)
43 , fGeometryProcessor(geometryProcessor) 44 , fGeometryProcessor(geometryProcessor)
44 , fXferProcessor(xferProcessor) 45 , fXferProcessor(xferProcessor)
45 , fFragmentProcessors(SkRef(fragmentProcessors)) 46 , fFragmentProcessors(SkRef(fragmentProcessors))
46 , fDesc(desc) 47 , fDesc(desc)
47 , fGpu(gpu) 48 , fGpu(gpu)
48 , fProgramDataManager(gpu, uniforms) { 49 , fProgramDataManager(gpu, uniforms) {
49 this->initSamplerUniforms(); 50 fSamplerUniforms.swap(passSamplerUniforms);
51 // Assign texture units to sampler uniforms one time up front.
52 GL_CALL(UseProgram(fProgramID));
53 for (int i = 0; i < fSamplerUniforms.count(); i++) {
54 fProgramDataManager.setSampler(fSamplerUniforms[i], i);
55 }
50 } 56 }
51 57
52 GrGLProgram::~GrGLProgram() { 58 GrGLProgram::~GrGLProgram() {
53 if (fProgramID) { 59 if (fProgramID) {
54 GL_CALL(DeleteProgram(fProgramID)); 60 GL_CALL(DeleteProgram(fProgramID));
55 } 61 }
56 } 62 }
57 63
58 void GrGLProgram::abandon() { 64 void GrGLProgram::abandon() {
59 fProgramID = 0; 65 fProgramID = 0;
60 } 66 }
61 67
62 void GrGLProgram::initSamplerUniforms() { 68 ///////////////////////////////////////////////////////////////////////////////
63 GL_CALL(UseProgram(fProgramID)); 69
64 GrGLint texUnitIdx = 0; 70 template <class Proc>
65 this->initSamplers(fGeometryProcessor.get(), &texUnitIdx); 71 static void append_texture_bindings(const Proc* ip,
66 if (fXferProcessor.get()) { 72 const GrProcessor& processor,
67 this->initSamplers(fXferProcessor.get(), &texUnitIdx); 73 SkTArray<const GrTextureAccess*>* textureBin dings) {
68 } 74 if (int numTextures = processor.numTextures()) {
69 int numProcs = fFragmentProcessors->fProcs.count(); 75 SkASSERT(textureBindings->count() == ip->fSamplersIdx);
70 for (int i = 0; i < numProcs; i++) { 76 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu res);
71 this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx); 77 int i = 0;
78 do {
79 bindings[i] = &processor.textureAccess(i);
80 } while (++i < numTextures);
joshualitt 2015/06/18 15:51:27 why not just a regular for loop?
Chris Dalton 2015/06/18 18:13:51 Philosophical reasons I guess. No need for a top t
72 } 81 }
73 } 82 }
74 83
75 template <class Proc> 84 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc,
76 void GrGLProgram::initSamplers(Proc* ip, int* texUnitIdx) { 85 const GrPipeline& pipeline,
77 SkTArray<typename Proc::Sampler, true>& samplers = ip->fSamplers; 86 const GrBatchTracker& batchTracker,
78 int numSamplers = samplers.count(); 87 SkTArray<const GrTextureAccess*>* textureBindings) {
79 for (int s = 0; s < numSamplers; ++s) {
80 SkASSERT(samplers[s].fUniform.isValid());
81 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx);
82 samplers[s].fTextureUnit = (*texUnitIdx)++;
83 }
84 }
85
86 template <class Proc>
87 void GrGLProgram::bindTextures(const Proc* ip, const GrProcessor& processor) {
88 const SkTArray<typename Proc::Sampler, true>& samplers = ip->fSamplers;
89 int numSamplers = samplers.count();
90 SkASSERT(numSamplers == processor.numTextures());
91 for (int s = 0; s < numSamplers; ++s) {
92 SkASSERT(samplers[s].fTextureUnit >= 0);
93 const GrTextureAccess& textureAccess = processor.textureAccess(s);
94 fGpu->bindTexture(samplers[s].fTextureUnit,
95 textureAccess.getParams(),
96 static_cast<GrGLTexture*>(textureAccess.getTexture())) ;
97 }
98 }
99
100
101 ///////////////////////////////////////////////////////////////////////////////
102
103 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrPipeline & pipeline,
104 const GrBatchTracker& batchTracker) {
105 this->setRenderTargetState(primProc, pipeline); 88 this->setRenderTargetState(primProc, pipeline);
106 89
107 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses 90 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses
108 // of GLProgram determine how to set coord transforms 91 // of GLProgram determine how to set coord transforms
109 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, batchTra cker); 92 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, batchTra cker);
110 this->bindTextures(fGeometryProcessor.get(), primProc); 93 append_texture_bindings(fGeometryProcessor.get(), primProc, textureBindings) ;
94
95 this->setFragmentData(primProc, pipeline, textureBindings);
111 96
112 const GrXferProcessor& xp = *pipeline.getXferProcessor(); 97 const GrXferProcessor& xp = *pipeline.getXferProcessor();
113 fXferProcessor->fGLProc->setData(fProgramDataManager, xp); 98 fXferProcessor->fGLProc->setData(fProgramDataManager, xp);
114 this->bindTextures(fXferProcessor.get(), xp); 99 append_texture_bindings(fXferProcessor.get(), xp, textureBindings);
115
116 this->setFragmentData(primProc, pipeline);
117 100
118 // Some of GrGLProgram subclasses need to update state here 101 // Some of GrGLProgram subclasses need to update state here
119 this->didSetData(); 102 this->didSetData();
120 } 103 }
121 104
122 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc, 105 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc,
123 const GrPipeline& pipeline) { 106 const GrPipeline& pipeline,
107 SkTArray<const GrTextureAccess*>* textureBindi ngs) {
124 int numProcessors = fFragmentProcessors->fProcs.count(); 108 int numProcessors = fFragmentProcessors->fProcs.count();
125 for (int e = 0; e < numProcessors; ++e) { 109 for (int e = 0; e < numProcessors; ++e) {
126 const GrPendingFragmentStage& stage = pipeline.getFragmentStage(e); 110 const GrPendingFragmentStage& stage = pipeline.getFragmentStage(e);
127 const GrProcessor& processor = *stage.processor(); 111 const GrProcessor& processor = *stage.processor();
128 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr ocessor); 112 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr ocessor);
129 this->setTransformData(primProc, 113 this->setTransformData(primProc,
130 stage, 114 stage,
131 e, 115 e,
132 fFragmentProcessors->fProcs[e]); 116 fFragmentProcessors->fProcs[e]);
133 this->bindTextures(fFragmentProcessors->fProcs[e], processor); 117 append_texture_bindings(fFragmentProcessors->fProcs[e], processor, textu reBindings);
134 } 118 }
135 } 119 }
136 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc, 120 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc,
137 const GrPendingFragmentStage& processor, 121 const GrPendingFragmentStage& processor,
138 int index, 122 int index,
139 GrGLInstalledFragProc* ip) { 123 GrGLInstalledFragProc* ip) {
140 GrGLGeometryProcessor* gp = 124 GrGLGeometryProcessor* gp =
141 static_cast<GrGLGeometryProcessor*>(fGeometryProcessor.get()->fGLPro c.get()); 125 static_cast<GrGLGeometryProcessor*>(fGeometryProcessor.get()->fGLPro c.get());
142 gp->setTransformData(primProc, fProgramDataManager, index, 126 gp->setTransformData(primProc, fProgramDataManager, index,
143 processor.processor()->coordTransforms()); 127 processor.processor()->coordTransforms());
(...skipping 30 matching lines...) Expand all
174 158
175 //////////////////////////////////////////////////////////////////////////////// ///////// 159 //////////////////////////////////////////////////////////////////////////////// /////////
176 160
177 GrGLNvprProgram::GrGLNvprProgram(GrGLGpu* gpu, 161 GrGLNvprProgram::GrGLNvprProgram(GrGLGpu* gpu,
178 const GrProgramDesc& desc, 162 const GrProgramDesc& desc,
179 const BuiltinUniformHandles& builtinUniforms, 163 const BuiltinUniformHandles& builtinUniforms,
180 GrGLuint programID, 164 GrGLuint programID,
181 const UniformInfoArray& uniforms, 165 const UniformInfoArray& uniforms,
182 GrGLInstalledGeoProc* primProc, 166 GrGLInstalledGeoProc* primProc,
183 GrGLInstalledXferProc* xferProcessor, 167 GrGLInstalledXferProc* xferProcessor,
184 GrGLInstalledFragProcs* fragmentProcessors) 168 GrGLInstalledFragProcs* fragmentProcessors,
169 SkTArray<UniformHandle>* passSamplerUniforms)
185 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, 170 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
186 xferProcessor, fragmentProcessors) { 171 xferProcessor, fragmentProcessors, passSamplerUniforms) {
187 } 172 }
188 void GrGLNvprProgram::didSetData() { 173 void GrGLNvprProgram::didSetData() {
189 GrGLPathProcessor* pathProc = 174 GrGLPathProcessor* pathProc =
190 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge t()); 175 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge t());
191 pathProc->didSetData(fGpu->glPathRendering()); 176 pathProc->didSetData(fGpu->glPathRendering());
192 } 177 }
193 178
194 void GrGLNvprProgram::setTransformData(const GrPrimitiveProcessor& primProc, 179 void GrGLNvprProgram::setTransformData(const GrPrimitiveProcessor& primProc,
195 const GrPendingFragmentStage& proc, 180 const GrPendingFragmentStage& proc,
196 int index, 181 int index,
197 GrGLInstalledFragProc* ip) { 182 GrGLInstalledFragProc* ip) {
198 GrGLPathProcessor* pathProc = 183 GrGLPathProcessor* pathProc =
199 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge t()); 184 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge t());
200 pathProc->setTransformData(primProc, index, proc.processor()->coordTransform s(), 185 pathProc->setTransformData(primProc, index, proc.processor()->coordTransform s(),
201 fGpu->glPathRendering(), fProgramID); 186 fGpu->glPathRendering(), fProgramID);
202 } 187 }
203 188
204 void GrGLNvprProgram::onSetRenderTargetState(const GrPrimitiveProcessor& primPro c, 189 void GrGLNvprProgram::onSetRenderTargetState(const GrPrimitiveProcessor& primPro c,
205 const GrPipeline& pipeline) { 190 const GrPipeline& pipeline) {
206 SkASSERT(!primProc.willUseGeoShader() && primProc.numAttribs() == 0); 191 SkASSERT(!primProc.willUseGeoShader() && primProc.numAttribs() == 0);
207 const GrRenderTarget* rt = pipeline.getRenderTarget(); 192 const GrRenderTarget* rt = pipeline.getRenderTarget();
208 SkISize size; 193 SkISize size;
209 size.set(rt->width(), rt->height()); 194 size.set(rt->width(), rt->height());
210 const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>(); 195 const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>();
211 fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(), 196 fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(),
212 size, rt->origin()); 197 size, rt->origin());
213 } 198 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698