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

Side by Side Diff: src/gpu/gl/GrGLShaderBuilder.h

Issue 14925010: Move loops that chain together effects into GrGLShaderBuilder from GrGLProgram. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Address comments and fix for emitting code for skipped effects Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLProgramDesc.h ('k') | src/gpu/gl/GrGLShaderBuilder.cpp » ('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 2012 Google Inc. 2 * Copyright 2012 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 #ifndef GrGLShaderBuilder_DEFINED 8 #ifndef GrGLShaderBuilder_DEFINED
9 #define GrGLShaderBuilder_DEFINED 9 #define GrGLShaderBuilder_DEFINED
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 void init(GrGLShaderBuilder* builder, 64 void init(GrGLShaderBuilder* builder,
65 uint32_t configComponentMask, 65 uint32_t configComponentMask,
66 const char* swizzle, 66 const char* swizzle,
67 int idx) { 67 int idx) {
68 GrAssert(!this->isInitialized()); 68 GrAssert(!this->isInitialized());
69 GrAssert(0 != configComponentMask); 69 GrAssert(0 != configComponentMask);
70 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor m); 70 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUnifor m);
71 71
72 GrAssert(NULL != builder); 72 GrAssert(NULL != builder);
73 SkString name; 73 SkString name;
74 name.printf("Sampler%d_", idx); 74 name.printf("Sampler%d", idx);
75 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S haderType, 75 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_S haderType,
76 kSampler2D_GrSLType, 76 kSampler2D_GrSLType,
77 name.c_str()); 77 name.c_str());
78 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUnifor m); 78 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUnifor m);
79 79
80 fConfigComponentMask = configComponentMask; 80 fConfigComponentMask = configComponentMask;
81 memcpy(fSwizzle, swizzle, 4); 81 memcpy(fSwizzle, swizzle, 4);
82 } 82 }
83 83
84 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) { 84 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 /** 269 /**
270 * Interfaces used by GrGLProgram. 270 * Interfaces used by GrGLProgram.
271 * TODO: Hide these from the GrEffects using friend or splitting this into t wo related classes. 271 * TODO: Hide these from the GrEffects using friend or splitting this into t wo related classes.
272 * Also, GrGLProgram's shader string construction should be moved to this cl ass. 272 * Also, GrGLProgram's shader string construction should be moved to this cl ass.
273 */ 273 */
274 274
275 /** Called after building is complete to get the final shader string. */ 275 /** Called after building is complete to get the final shader string. */
276 void getShader(ShaderType, SkString*) const; 276 void getShader(ShaderType, SkString*) const;
277 277
278 void setCurrentStage(int stageIdx) { fCurrentStageIdx = stageIdx; } 278 /**
279 void setNonStage() { fCurrentStageIdx = kNonStageIdx; } 279 * Adds code for effects. effectStages contains the effects to add. effectKe ys[i] is the key
280 // TODO: move remainder of shader code generation to this class and call thi s privately 280 * generated from effectStages[i]. An entry in effectStages can be NULL, in which case it is
281 // Handles of sampler uniforms generated for the effect are appended to samp lerHandles. 281 * skipped. Moreover, if the corresponding key is GrGLEffect::NoEffectKey th en it is skipped.
282 GrGLEffect* createAndEmitGLEffect( 282 * inOutFSColor specifies the input color to the first stage and is updated to be the
283 const GrEffectStage& stage, 283 * output color of the last stage. fsInOutColorKnownValue specifies whether the input color
284 GrBackendEffectFactory::EffectKey key, 284 * has a known constant value and is updated to refer to the status of the o utput color.
285 const char* fsInColor, // NULL means no incoming color 285 * The handles to texture samplers for effectStage[i] are added to effectSam plerHandles[i]. The
286 const char* fsOutColor, 286 * glEffects array is updated to contain the GrGLEffect generated for each e ntry in
287 SkTArray<GrGLUniformManager::UniformHandle, true >* samplerHandles); 287 * effectStages.
288 */
289 void emitEffects(const GrEffectStage* effectStages[],
290 const GrBackendEffectFactory::EffectKey effectKeys[],
291 int effectCnt,
292 SkString* inOutFSColor,
293 GrSLConstantVec* fsInOutColorKnownValue,
294 SkTArray<GrGLUniformManager::UniformHandle, true>* effectSa mplerHandles[],
295 GrGLEffect* glEffects[]);
288 296
289 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei ghtUniform; } 297 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei ghtUniform; }
290 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const { 298 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const {
291 return fDstCopyTopLeftUniform; 299 return fDstCopyTopLeftUniform;
292 } 300 }
293 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const { 301 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const {
294 return fDstCopyScaleUniform; 302 return fDstCopyScaleUniform;
295 } 303 }
296 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const { 304 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const {
297 return fDstCopySampler.fSamplerUniform; 305 return fDstCopySampler.fSamplerUniform;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 339
332 VarArray fVSAttrs; 340 VarArray fVSAttrs;
333 VarArray fVSOutputs; 341 VarArray fVSOutputs;
334 VarArray fGSInputs; 342 VarArray fGSInputs;
335 VarArray fGSOutputs; 343 VarArray fGSOutputs;
336 VarArray fFSInputs; 344 VarArray fFSInputs;
337 SkString fGSHeader; // layout qualifiers specific to GS 345 SkString fGSHeader; // layout qualifiers specific to GS
338 VarArray fFSOutputs; 346 VarArray fFSOutputs;
339 347
340 private: 348 private:
341 enum { 349 class CodeStage : GrNoncopyable {
342 kNonStageIdx = -1, 350 public:
343 }; 351 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {}
352
353 bool inStageCode() const {
354 this->validate();
355 return NULL != fEffectStage;
356 }
357
358 const GrEffectStage* effectStage() const {
359 this->validate();
360 return fEffectStage;
361 }
362
363 int stageIndex() const {
364 this->validate();
365 return fCurrentIndex;
366 }
367
368 class AutoStageRestore : GrNoncopyable {
369 public:
370 AutoStageRestore(CodeStage* codeStage, const GrEffectStage* newStage ) {
371 GrAssert(NULL != codeStage);
372 fSavedIndex = codeStage->fCurrentIndex;
373 fSavedEffectStage = codeStage->fEffectStage;
374
375 if (NULL == newStage) {
376 codeStage->fCurrentIndex = -1;
377 } else {
378 codeStage->fCurrentIndex = codeStage->fNextIndex++;
379 }
380 codeStage->fEffectStage = newStage;
381
382 fCodeStage = codeStage;
383 }
384 ~AutoStageRestore() {
385 fCodeStage->fCurrentIndex = fSavedIndex;
386 fCodeStage->fEffectStage = fSavedEffectStage;
387 }
388 private:
389 CodeStage* fCodeStage;
390 int fSavedIndex;
391 const GrEffectStage* fSavedEffectStage;
392 };
393 private:
394 void validate() const { GrAssert((NULL == fEffectStage) == (-1 == fCurre ntIndex)); }
395 int fNextIndex;
396 int fCurrentIndex;
397 const GrEffectStage* fEffectStage;
398 } fCodeStage;
344 399
345 /** 400 /**
346 * Features that should only be enabled by GrGLShaderBuilder itself. 401 * Features that should only be enabled by GrGLShaderBuilder itself.
347 */ 402 */
348 enum GLSLPrivateFeature { 403 enum GLSLPrivateFeature {
349 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, 404 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1,
350 kEXTShaderFramebufferFetch_GLSLPrivateFeature, 405 kEXTShaderFramebufferFetch_GLSLPrivateFeature,
351 kNVShaderFramebufferFetch_GLSLPrivateFeature, 406 kNVShaderFramebufferFetch_GLSLPrivateFeature,
352 }; 407 };
353 bool enablePrivateFeature(GLSLPrivateFeature); 408 bool enablePrivateFeature(GLSLPrivateFeature);
354 409
355 // If we ever have VS/GS features we can expand this to take a bitmask of Sh aderType and track 410 // If we ever have VS/GS features we can expand this to take a bitmask of Sh aderType and track
356 // the enables separately for each shader. 411 // the enables separately for each shader.
357 void addFSFeature(uint32_t featureBit, const char* extensionName); 412 void addFSFeature(uint32_t featureBit, const char* extensionName);
358 413
414 // Generates a name for a variable. The generated string will be name prefix ed by the prefix
415 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp ecific if we're
416 // generating stage code.
417 void nameVariable(SkString* out, char prefix, const char* name);
418
359 // Interpretation of DstReadKey when generating code 419 // Interpretation of DstReadKey when generating code
360 enum { 420 enum {
361 kNoDstRead_DstReadKey = 0, 421 kNoDstRead_DstReadKey = 0,
362 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read. 422 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read.
363 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alpha only. 423 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alpha only.
364 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-le ft. 424 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-le ft.
365 }; 425 };
366 426
367 const GrGLContextInfo& fCtxInfo; 427 const GrGLContextInfo& fCtxInfo;
368 GrGLUniformManager& fUniformManager; 428 GrGLUniformManager& fUniformManager;
369 int fCurrentStageIdx;
370 uint32_t fFSFeaturesAddedMask; 429 uint32_t fFSFeaturesAddedMask;
371 SkString fFSFunctions; 430 SkString fFSFunctions;
372 SkString fFSExtensions; 431 SkString fFSExtensions;
373 432
374 bool fUsesGS; 433 bool fUsesGS;
375 434
376 SkString fFSCode; 435 SkString fFSCode;
377 SkString fVSCode; 436 SkString fVSCode;
378 SkString fGSCode; 437 SkString fGSCode;
379 438
380 bool fSetupFragPosition; 439 bool fSetupFragPosition;
381 TextureSampler fDstCopySampler; 440 TextureSampler fDstCopySampler;
382 441
383 GrGLUniformManager::UniformHandle fRTHeightUniform; 442 GrGLUniformManager::UniformHandle fRTHeightUniform;
384 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform; 443 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform;
385 GrGLUniformManager::UniformHandle fDstCopyScaleUniform; 444 GrGLUniformManager::UniformHandle fDstCopyScaleUniform;
386 445
387 SkSTArray<10, AttributePair, true> fEffectAttributes; 446 SkSTArray<10, AttributePair, true> fEffectAttributes;
388 447
389 GrGLShaderVar* fPositionVar; 448 GrGLShaderVar* fPositionVar;
390 GrGLShaderVar* fLocalCoordsVar; 449 GrGLShaderVar* fLocalCoordsVar;
391 450
392 }; 451 };
393 452
394 #endif 453 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramDesc.h ('k') | src/gpu/gl/GrGLShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698