bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrGLProgramDesc_DEFINED |
| 9 | #define GrGLProgramDesc_DEFINED |
| 10 | |
| 11 | #include "GrGLEffect.h" |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame] | 12 | #include "GrDrawState.h" |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 13 | #include "GrGLShaderBuilder.h" |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 14 | |
| 15 | class GrGpuGL; |
| 16 | |
| 17 | // optionally compile the experimental GS code. Set to GR_DEBUG so that debug build bots will |
| 18 | // execute the code. |
| 19 | #define GR_GL_EXPERIMENTAL_GS GR_DEBUG |
| 20 | |
| 21 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 22 | /** This class describes a program to generate. It also serves as a program cache key. Very little |
| 23 | of this is GL-specific. There is the generation of GrGLEffect::EffectKeys and the dst-read part |
| 24 | of the key set by GrGLShaderBuilder. If the interfaces that set those portions were abstracted |
| 25 | to be API-neutral then so could this class. */ |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 26 | class GrGLProgramDesc { |
| 27 | public: |
| 28 | GrGLProgramDesc() { |
| 29 | // since we use this as part of a key we can't have any uninitialized padding |
| 30 | memset(this, 0, sizeof(GrGLProgramDesc)); |
| 31 | } |
| 32 | |
| 33 | // Returns this as a uint32_t array to be used as a key in the program cache |
| 34 | const uint32_t* asKey() const { |
| 35 | return reinterpret_cast<const uint32_t*>(this); |
| 36 | } |
| 37 | |
| 38 | // For unit testing. |
| 39 | void setRandom(SkMWCRandom*, |
| 40 | const GrGpuGL* gpu, |
bsalomon@google.com | b79d865 | 2013-03-29 20:30:50 +0000 | [diff] [blame] | 41 | const GrTexture* dummyDstTexture, |
bsalomon@google.com | 504976e | 2013-05-09 13:45:02 +0000 | [diff] [blame] | 42 | const GrEffectStage* stages[GrDrawState::kNumStages], |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 43 | int currAttribIndex); |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Builds a program descriptor from a GrDrawState. Whether the primitive type is points, the |
| 47 | * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also inputs. |
| 48 | */ |
| 49 | static void Build(const GrDrawState&, |
| 50 | bool isPoints, |
| 51 | GrDrawState::BlendOptFlags, |
| 52 | GrBlendCoeff srcCoeff, |
| 53 | GrBlendCoeff dstCoeff, |
| 54 | const GrGpuGL* gpu, |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 55 | const GrDeviceCoordTexture* dstCopy, |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 56 | GrGLProgramDesc* outDesc); |
| 57 | |
| 58 | private: |
| 59 | // Specifies where the initial color comes from before the stages are applied. |
| 60 | enum ColorInput { |
| 61 | kSolidWhite_ColorInput, |
| 62 | kTransBlack_ColorInput, |
| 63 | kAttribute_ColorInput, |
| 64 | kUniform_ColorInput, |
| 65 | |
| 66 | kColorInputCnt |
| 67 | }; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 68 | |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 69 | enum CoverageOutput { |
| 70 | // modulate color and coverage, write result as the color output. |
| 71 | kModulate_CoverageOutput, |
| 72 | // Writes color*coverage as the primary color output and also writes coverage as the |
| 73 | // secondary output. Only set if dual source blending is supported. |
| 74 | kSecondaryCoverage_CoverageOutput, |
| 75 | // Writes color*coverage as the primary color output and also writes coverage * (1 - colorA) |
| 76 | // as the secondary output. Only set if dual source blending is supported. |
| 77 | kSecondaryCoverageISA_CoverageOutput, |
| 78 | // Writes color*coverage as the primary color output and also writes coverage * |
| 79 | // (1 - colorRGB) as the secondary output. Only set if dual source blending is supported. |
| 80 | kSecondaryCoverageISC_CoverageOutput, |
| 81 | // Combines the coverage, dst, and color as coverage * color + (1 - coverage) * dst. This |
bsalomon@google.com | b515881 | 2013-05-13 18:50:25 +0000 | [diff] [blame^] | 82 | // can only be set if fDstReadKey is non-zero. |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 83 | kCombineWithDst_CoverageOutput, |
| 84 | |
| 85 | kCoverageOutputCnt |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 88 | static bool CoverageOutputUsesSecondaryOutput(CoverageOutput co) { |
| 89 | switch (co) { |
| 90 | case kSecondaryCoverage_CoverageOutput: // fallthru |
| 91 | case kSecondaryCoverageISA_CoverageOutput: |
| 92 | case kSecondaryCoverageISC_CoverageOutput: |
| 93 | return true; |
| 94 | default: |
| 95 | return false; |
| 96 | } |
| 97 | } |
| 98 | |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 99 | /** Non-zero if this stage has an effect */ |
| 100 | GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages]; |
| 101 | |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 102 | // To enable experimental geometry shader code (not for use in |
| 103 | // production) |
| 104 | #if GR_GL_EXPERIMENTAL_GS |
| 105 | bool fExperimentalGS; |
| 106 | #endif |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 107 | |
bsalomon@google.com | b515881 | 2013-05-13 18:50:25 +0000 | [diff] [blame^] | 108 | GrGLShaderBuilder::DstReadKey fDstReadKey; // set by GrGLShaderBuilder if there |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 109 | // are effects that must read the dst. |
| 110 | // Otherwise, 0. |
bsalomon@google.com | b515881 | 2013-05-13 18:50:25 +0000 | [diff] [blame^] | 111 | GrGLShaderBuilder::FragPosKey fFragPosKey; // set by GrGLShaderBuilder if there are |
| 112 | // effects that read the fragment position. |
| 113 | // Otherwise, 0. |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 114 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 115 | // should the FS discard if the coverage is zero (to avoid stencil manipulation) |
| 116 | SkBool8 fDiscardIfZeroCoverage; |
| 117 | |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 118 | uint8_t fColorInput; // casts to enum ColorInput |
| 119 | uint8_t fCoverageInput; // casts to enum ColorInput |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 120 | uint8_t fCoverageOutput; // casts to enum CoverageOutput |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 121 | |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 122 | int8_t fFirstCoverageStage; |
| 123 | SkBool8 fEmitsPointSize; |
| 124 | uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode |
| 125 | |
| 126 | int8_t fPositionAttributeIndex; |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 127 | int8_t fLocalCoordAttributeIndex; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 128 | int8_t fColorAttributeIndex; |
| 129 | int8_t fCoverageAttributeIndex; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 130 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 131 | // GrGLProgram and GrGLShaderBuilder read the private fields to generate code. TODO: Move all |
| 132 | // code generation to GrGLShaderBuilder (and maybe add getters rather than friending). |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 133 | friend class GrGLProgram; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 134 | friend class GrGLShaderBuilder; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | #endif |