Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef GrGLProgramBuilder_DEFINED | 8 #ifndef GrGLProgramBuilder_DEFINED |
| 9 #define GrGLProgramBuilder_DEFINED | 9 #define GrGLProgramBuilder_DEFINED |
| 10 | 10 |
| 11 #include "GrPipeline.h" | 11 #include "GrPipeline.h" |
| 12 #include "gl/GrGLProgramDataManager.h" | 12 #include "gl/GrGLProgramDataManager.h" |
| 13 #include "gl/GrGLUniformHandler.h" | 13 #include "gl/GrGLUniformHandler.h" |
| 14 #include "gl/GrGLVaryingHandler.h" | 14 #include "gl/GrGLVaryingHandler.h" |
| 15 #include "glsl/GrGLSLPrimitiveProcessor.h" | |
| 16 #include "glsl/GrGLSLProgramBuilder.h" | 15 #include "glsl/GrGLSLProgramBuilder.h" |
| 17 #include "glsl/GrGLSLProgramDataManager.h" | 16 #include "glsl/GrGLSLProgramDataManager.h" |
| 18 #include "glsl/GrGLSLTextureSampler.h" | |
| 19 #include "glsl/GrGLSLXferProcessor.h" | |
| 20 | 17 |
| 21 class GrFragmentProcessor; | 18 class GrFragmentProcessor; |
| 22 class GrGLContextInfo; | 19 class GrGLContextInfo; |
| 23 class GrGLSLShaderBuilder; | 20 class GrGLSLShaderBuilder; |
| 24 class GrGLSLCaps; | 21 class GrGLSLCaps; |
| 25 | 22 |
| 26 /** | |
| 27 * The below struct represent processors installed in programs. | |
| 28 */ | |
| 29 template <class Proc> | |
|
egdaniel
2016/01/13 17:01:58
Glad to kill this whole crazy setup
| |
| 30 struct GrGLInstalledProc { | |
| 31 SkDEBUGCODE(int fSamplersIdx;) | |
| 32 SkAutoTDelete<Proc> fGLProc; | |
| 33 }; | |
| 34 | |
| 35 typedef GrGLInstalledProc<GrGLSLPrimitiveProcessor> GrGLInstalledGeoProc; | |
| 36 typedef GrGLInstalledProc<GrGLSLXferProcessor> GrGLInstalledXferProc; | |
| 37 typedef GrGLInstalledProc<GrGLSLFragmentProcessor> GrGLInstalledFragProc; | |
| 38 | |
| 39 struct GrGLInstalledFragProcs : public SkRefCnt { | |
| 40 virtual ~GrGLInstalledFragProcs(); | |
| 41 SkSTArray<8, GrGLInstalledFragProc*, true> fProcs; | |
| 42 }; | |
| 43 | |
| 44 /* | 23 /* |
| 45 * Please note - no diamond problems because of virtual inheritance. Also, both base classes | 24 * Please note - no diamond problems because of virtual inheritance. Also, both base classes |
|
bsalomon
2016/01/13 17:49:19
Can you remove/modify this comment? I don't think
egdaniel
2016/01/13 19:59:49
Done.
| |
| 46 * are pure virtual with no data members. This is the base class for program bu ilding. | 25 * are pure virtual with no data members. This is the base class for program bu ilding. |
| 47 * Subclasses are nearly identical but each has their own way of emitting transf orms. State for | 26 * Subclasses are nearly identical but each has their own way of emitting transf orms. State for |
| 48 * each of the elements of the shader pipeline, ie vertex, fragment, geometry, e tc, lives in those | 27 * each of the elements of the shader pipeline, ie vertex, fragment, geometry, e tc, lives in those |
| 49 * respective builders | 28 * respective builders |
| 50 */ | 29 */ |
| 51 class GrGLProgramBuilder : public GrGLSLProgramBuilder { | 30 class GrGLProgramBuilder : public GrGLSLProgramBuilder { |
| 52 public: | 31 public: |
| 53 /** Generates a shader program. | 32 /** Generates a shader program. |
| 54 * | 33 * |
| 55 * The program implements what is specified in the stages given as input. | 34 * The program implements what is specified in the stages given as input. |
| 56 * After successful generation, the builder result objects are available | 35 * After successful generation, the builder result objects are available |
| 57 * to be used. | 36 * to be used. |
| 58 * @return true if generation was successful. | 37 * @return true if generation was successful. |
| 59 */ | 38 */ |
| 60 static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*); | 39 static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*); |
| 61 | 40 |
| 41 const GrCaps* caps() const override; | |
| 62 const GrGLSLCaps* glslCaps() const override; | 42 const GrGLSLCaps* glslCaps() const override; |
| 63 | 43 |
| 44 | |
|
joshualitt
2016/01/13 17:58:24
\n
egdaniel
2016/01/13 19:59:49
Done.
| |
| 64 GrGLGpu* gpu() const { return fGpu; } | 45 GrGLGpu* gpu() const { return fGpu; } |
| 65 | 46 |
| 66 private: | 47 private: |
| 67 GrGLProgramBuilder(GrGLGpu*, const DrawArgs&); | 48 GrGLProgramBuilder(GrGLGpu*, const DrawArgs&); |
| 68 | 49 |
| 69 // Generates a possibly mangled name for a stage variable and writes it to t he fragment shader. | |
| 70 // If GrGLSLExpr4 has a valid name then it will use that instead | |
| 71 void nameExpression(GrGLSLExpr4*, const char* baseName); | |
| 72 bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage ); | |
| 73 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu t); | |
| 74 void emitAndInstallProc(const GrFragmentProcessor&, | |
| 75 int index, | |
| 76 const GrGLSLExpr4& input, | |
| 77 GrGLSLExpr4* output); | |
| 78 | |
| 79 void emitAndInstallProc(const GrPrimitiveProcessor&, | |
| 80 GrGLSLExpr4* outputColor, | |
| 81 GrGLSLExpr4* outputCoverage); | |
| 82 | |
| 83 // these emit functions help to keep the createAndEmitProcessors template ge neral | |
| 84 void emitAndInstallProc(const GrFragmentProcessor&, | |
| 85 int index, | |
| 86 const char* outColor, | |
| 87 const char* inColor); | |
| 88 void emitAndInstallProc(const GrPrimitiveProcessor&, | |
| 89 const char* outColor, | |
| 90 const char* outCoverage); | |
| 91 void emitAndInstallXferProc(const GrXferProcessor&, | |
| 92 const GrGLSLExpr4& colorIn, | |
| 93 const GrGLSLExpr4& coverageIn, | |
| 94 bool ignoresCoverage); | |
| 95 void emitFSOutputSwizzle(bool hasSecondaryOutput); | |
| 96 | |
| 97 void verify(const GrPrimitiveProcessor&); | |
| 98 void verify(const GrXferProcessor&); | |
| 99 void verify(const GrFragmentProcessor&); | |
| 100 template <class Proc> | |
| 101 void emitSamplers(const GrProcessor&, | 50 void emitSamplers(const GrProcessor&, |
| 102 GrGLSLTextureSampler::TextureSamplerArray* outSamplers, | 51 GrGLSLTextureSampler::TextureSamplerArray* outSamplers) ov erride; |
| 103 GrGLInstalledProc<Proc>*); | |
| 104 | 52 |
| 105 bool compileAndAttachShaders(GrGLSLShaderBuilder& shader, | 53 bool compileAndAttachShaders(GrGLSLShaderBuilder& shader, |
| 106 GrGLuint programId, | 54 GrGLuint programId, |
| 107 GrGLenum type, | 55 GrGLenum type, |
| 108 SkTDArray<GrGLuint>* shaderIds); | 56 SkTDArray<GrGLuint>* shaderIds); |
| 109 GrGLProgram* finalize(); | 57 GrGLProgram* finalize(); |
| 110 void bindProgramResourceLocations(GrGLuint programID); | 58 void bindProgramResourceLocations(GrGLuint programID); |
| 111 bool checkLinkStatus(GrGLuint programID); | 59 bool checkLinkStatus(GrGLuint programID); |
| 112 void resolveProgramResourceLocations(GrGLuint programID); | 60 void resolveProgramResourceLocations(GrGLuint programID); |
| 113 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs ); | 61 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs ); |
| 114 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); | 62 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); |
| 115 | 63 |
| 116 // Subclasses create different programs | 64 // Subclasses create different programs |
| 117 GrGLProgram* createProgram(GrGLuint programID); | 65 GrGLProgram* createProgram(GrGLuint programID); |
| 118 | 66 |
| 119 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } | 67 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } |
| 120 const GrGLSLUniformHandler* uniformHandler() const override { return &fUnifo rmHandler; } | 68 const GrGLSLUniformHandler* uniformHandler() const override { return &fUnifo rmHandler; } |
| 121 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } | 69 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } |
| 122 | 70 |
| 123 // reset is called by program creator between each processor's emit code. I t increments the | |
| 124 // stage offset for variable name mangling, and also ensures verfication var iables in the | |
| 125 // fragment shader are cleared. | |
| 126 void reset() { | |
| 127 this->addStage(); | |
| 128 fFS.reset(); | |
| 129 } | |
| 130 void addStage() { fStageIndex++; } | |
| 131 | |
| 132 class AutoStageAdvance { | |
| 133 public: | |
| 134 AutoStageAdvance(GrGLProgramBuilder* pb) | |
| 135 : fPB(pb) { | |
| 136 fPB->reset(); | |
| 137 // Each output to the fragment processor gets its own code section | |
| 138 fPB->fFS.nextStage(); | |
| 139 } | |
| 140 ~AutoStageAdvance() {} | |
| 141 private: | |
| 142 GrGLProgramBuilder* fPB; | |
| 143 }; | |
| 144 | |
| 145 GrGLInstalledGeoProc* fGeometryProcessor; | |
| 146 GrGLInstalledXferProc* fXferProcessor; | |
| 147 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; | |
| 148 | 71 |
| 149 GrGLGpu* fGpu; | 72 GrGLGpu* fGpu; |
| 150 GrGLSLPrimitiveProcessor::TransformsIn fCoordTransforms; | |
| 151 GrGLSLPrimitiveProcessor::TransformsOut fOutCoords; | |
| 152 typedef GrGLSLUniformHandler::UniformHandle UniformHandle; | 73 typedef GrGLSLUniformHandler::UniformHandle UniformHandle; |
| 153 SkTArray<UniformHandle> fSamplerUniforms; | 74 SkTArray<UniformHandle> fSamplerUniforms; |
| 154 | 75 |
| 155 GrGLVaryingHandler fVaryingHandler; | 76 GrGLVaryingHandler fVaryingHandler; |
| 156 GrGLUniformHandler fUniformHandler; | 77 GrGLUniformHandler fUniformHandler; |
| 157 | 78 |
| 158 typedef GrGLSLProgramBuilder INHERITED; | 79 typedef GrGLSLProgramBuilder INHERITED; |
| 159 }; | 80 }; |
| 160 #endif | 81 #endif |
| OLD | NEW |