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

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

Issue 367643004: Implement NVPR on GLES (Closed) Base URL: https://skia.googlesource.com/skia.git@02-path-program-fragment
Patch Set: address review comments (rebase to separated patches) Created 6 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "GrGLProgramDesc.h" 8 #include "GrGLProgramDesc.h"
9 #include "GrBackendEffectFactory.h" 9 #include "GrBackendEffectFactory.h"
10 #include "GrDrawEffect.h" 10 #include "GrDrawEffect.h"
11 #include "GrEffect.h" 11 #include "GrEffect.h"
12 #include "GrGLShaderBuilder.h" 12 #include "GrGLShaderBuilder.h"
13 #include "GrGpuGL.h" 13 #include "GrGpuGL.h"
14 14
15 #include "SkChecksum.h" 15 #include "SkChecksum.h"
16 16
17 bool GrGLProgramDesc::GetEffectKeyAndUpdateStats(const GrEffectStage& stage, 17 bool GrGLProgramDesc::GetEffectKeyAndUpdateStats(const GrEffectStage& stage,
18 const GrGLCaps& caps, 18 const GrGLCaps& caps,
19 bool useExplicitLocalCoords, 19 bool useExplicitLocalCoords,
20 GrEffectKeyBuilder* b, 20 GrEffectKeyBuilder* b,
21 uint16_t* effectKeySize, 21 uint16_t* effectKeySize,
22 bool* setTrueIfReadsDst, 22 bool* setTrueIfReadsDst,
23 bool* setTrueIfReadsPos, 23 bool* setTrueIfReadsPos,
24 bool* setTrueIfHasVertexCode) { 24 bool* setTrueIfRequiresVertexSh ader) {
25 const GrBackendEffectFactory& factory = stage.getEffect()->getFactory(); 25 const GrBackendEffectFactory& factory = stage.getEffect()->getFactory();
26 GrDrawEffect drawEffect(stage, useExplicitLocalCoords); 26 GrDrawEffect drawEffect(stage, useExplicitLocalCoords);
27 if (stage.getEffect()->willReadDstColor()) { 27 if (stage.getEffect()->willReadDstColor()) {
28 *setTrueIfReadsDst = true; 28 *setTrueIfReadsDst = true;
29 } 29 }
30 if (stage.getEffect()->willReadFragmentPosition()) { 30 if (stage.getEffect()->willReadFragmentPosition()) {
31 *setTrueIfReadsPos = true; 31 *setTrueIfReadsPos = true;
32 } 32 }
33 if (stage.getEffect()->hasVertexCode()) { 33 if (stage.getEffect()->requiresVertexShader()) {
34 *setTrueIfHasVertexCode = true; 34 *setTrueIfRequiresVertexShader = true;
35 } 35 }
36 factory.getGLEffectKey(drawEffect, caps, b); 36 factory.getGLEffectKey(drawEffect, caps, b);
37 size_t size = b->size(); 37 size_t size = b->size();
38 if (size > SK_MaxU16) { 38 if (size > SK_MaxU16) {
39 *effectKeySize = 0; // suppresses a warning. 39 *effectKeySize = 0; // suppresses a warning.
40 return false; 40 return false;
41 } 41 }
42 *effectKeySize = SkToU16(size); 42 *effectKeySize = SkToU16(size);
43 if (!GrGLProgramEffects::GenEffectMetaKey(drawEffect, caps, b)) { 43 if (!GrGLProgramEffects::GenEffectMetaKey(drawEffect, caps, b)) {
44 return false; 44 return false;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // to a canonical value to avoid duplicate programs with different keys. 95 // to a canonical value to avoid duplicate programs with different keys.
96 96
97 bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute() ; 97 bool requiresColorAttrib = !skipColor && drawState.hasColorVertexAttribute() ;
98 bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAt tribute(); 98 bool requiresCoverageAttrib = !skipCoverage && drawState.hasCoverageVertexAt tribute();
99 // we only need the local coords if we're actually going to generate effect code 99 // we only need the local coords if we're actually going to generate effect code
100 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && 100 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) &&
101 drawState.hasLocalCoordAttribute(); 101 drawState.hasLocalCoordAttribute();
102 102
103 bool readsDst = false; 103 bool readsDst = false;
104 bool readFragPosition = false; 104 bool readFragPosition = false;
105 // We use vertexshader-less shader programs only when drawing paths. 105
106 bool hasVertexCode = !(GrGpu::kDrawPath_DrawType == drawType || 106 // Provide option for shader programs without vertex shader only when drawin g paths.
107 GrGpu::kDrawPaths_DrawType == drawType); 107 bool requiresVertexShader = !GrGpu::IsPathRenderingDrawType(drawType);
108
108 int numStages = 0; 109 int numStages = 0;
109 if (!skipColor) { 110 if (!skipColor) {
110 numStages += drawState.numColorStages() - firstEffectiveColorStage; 111 numStages += drawState.numColorStages() - firstEffectiveColorStage;
111 } 112 }
112 if (!skipCoverage) { 113 if (!skipCoverage) {
113 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage ; 114 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage ;
114 } 115 }
115 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); 116 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t));
116 // Make room for everything up to and including the array of offsets to effe ct keys. 117 // Make room for everything up to and including the array of offsets to effe ct keys.
117 desc->fKey.reset(); 118 desc->fKey.reset();
118 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_ t) * numStages); 119 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_ t) * numStages);
119 120
120 int offsetAndSizeIndex = 0; 121 int offsetAndSizeIndex = 0;
121
122 bool effectKeySuccess = true; 122 bool effectKeySuccess = true;
123 if (!skipColor) { 123 if (!skipColor) {
124 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) { 124 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) {
125 uint16_t* offsetAndSize = 125 uint16_t* offsetAndSize =
126 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + 126 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset +
127 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); 127 offsetAndSizeIndex * 2 * sizeof(uint 16_t));
128 128
129 GrEffectKeyBuilder b(&desc->fKey); 129 GrEffectKeyBuilder b(&desc->fKey);
130 uint16_t effectKeySize; 130 uint16_t effectKeySize;
131 uint32_t effectOffset = desc->fKey.count(); 131 uint32_t effectOffset = desc->fKey.count();
132 effectKeySuccess |= GetEffectKeyAndUpdateStats( 132 effectKeySuccess |= GetEffectKeyAndUpdateStats(
133 drawState.getColorStage(s), gpu->glCaps(), 133 drawState.getColorStage(s), gpu->glCaps(),
134 requiresLocalCoordAttrib, &b, 134 requiresLocalCoordAttrib, &b,
135 &effectKeySize, &readsDst, 135 &effectKeySize, &readsDst,
136 &readFragPosition, &hasVertexCode); 136 &readFragPosition, &requiresVertexShader);
137 effectKeySuccess |= (effectOffset <= SK_MaxU16); 137 effectKeySuccess |= (effectOffset <= SK_MaxU16);
138 138
139 offsetAndSize[0] = SkToU16(effectOffset); 139 offsetAndSize[0] = SkToU16(effectOffset);
140 offsetAndSize[1] = effectKeySize; 140 offsetAndSize[1] = effectKeySize;
141 ++offsetAndSizeIndex; 141 ++offsetAndSizeIndex;
142 } 142 }
143 } 143 }
144 if (!skipCoverage) { 144 if (!skipCoverage) {
145 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage s(); ++s) { 145 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage s(); ++s) {
146 uint16_t* offsetAndSize = 146 uint16_t* offsetAndSize =
147 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + 147 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset +
148 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); 148 offsetAndSizeIndex * 2 * sizeof(uint 16_t));
149 149
150 GrEffectKeyBuilder b(&desc->fKey); 150 GrEffectKeyBuilder b(&desc->fKey);
151 uint16_t effectKeySize; 151 uint16_t effectKeySize;
152 uint32_t effectOffset = desc->fKey.count(); 152 uint32_t effectOffset = desc->fKey.count();
153 effectKeySuccess |= GetEffectKeyAndUpdateStats( 153 effectKeySuccess |= GetEffectKeyAndUpdateStats(
154 drawState.getCoverageStage(s), gpu->glCaps() , 154 drawState.getCoverageStage(s), gpu->glCaps() ,
155 requiresLocalCoordAttrib, &b, 155 requiresLocalCoordAttrib, &b,
156 &effectKeySize, &readsDst, 156 &effectKeySize, &readsDst,
157 &readFragPosition, &hasVertexCode); 157 &readFragPosition, &requiresVertexShader);
158 effectKeySuccess |= (effectOffset <= SK_MaxU16); 158 effectKeySuccess |= (effectOffset <= SK_MaxU16);
159 159
160 offsetAndSize[0] = SkToU16(effectOffset); 160 offsetAndSize[0] = SkToU16(effectOffset);
161 offsetAndSize[1] = effectKeySize; 161 offsetAndSize[1] = effectKeySize;
162 ++offsetAndSizeIndex; 162 ++offsetAndSizeIndex;
163 } 163 }
164 } 164 }
165 if (!effectKeySuccess) { 165 if (!effectKeySuccess) {
166 desc->fKey.reset(); 166 desc->fKey.reset();
167 return false; 167 return false;
168 } 168 }
169 169
170 KeyHeader* header = desc->header(); 170 KeyHeader* header = desc->header();
171 // make sure any padding in the header is zeroed. 171 // make sure any padding in the header is zeroed.
172 memset(desc->header(), 0, kHeaderSize); 172 memset(desc->header(), 0, kHeaderSize);
173 173
174 // Because header is a pointer into the dynamic array, we can't push any new data into the key 174 // Because header is a pointer into the dynamic array, we can't push any new data into the key
175 // below here. 175 // below here.
176 176
177 header->fHasVertexCode = hasVertexCode || requiresLocalCoordAttrib; 177 header->fRequiresVertexShader = requiresVertexShader || requiresLocalCoordAt trib;
178 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; 178 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType;
179 179
180 // Currently the experimental GS will only work with triangle prims (and it doesn't do anything 180 // Currently the experimental GS will only work with triangle prims (and it doesn't do anything
181 // other than pass through values from the VS to the FS anyway). 181 // other than pass through values from the VS to the FS anyway).
182 #if GR_GL_EXPERIMENTAL_GS 182 #if GR_GL_EXPERIMENTAL_GS
183 #if 0 183 #if 0
184 header->fExperimentalGS = gpu->caps().geometryShaderSupport(); 184 header->fExperimentalGS = gpu->caps().geometryShaderSupport();
185 #else 185 #else
186 header->fExperimentalGS = false; 186 header->fExperimentalGS = false;
187 #endif 187 #endif
188 #endif 188 #endif
189 bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->p athRenderingSupport(); 189 bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->p athRenderingSupport();
190 190
191 if (defaultToUniformInputs && !requiresColorAttrib && inputColorIsUsed) { 191 if (defaultToUniformInputs && !requiresColorAttrib && inputColorIsUsed) {
192 header->fColorInput = kUniform_ColorInput; 192 header->fColorInput = kUniform_ColorInput;
193 } else { 193 } else {
194 header->fColorInput = kAttribute_ColorInput; 194 header->fColorInput = kAttribute_ColorInput;
195 header->fHasVertexCode = true; 195 header->fRequiresVertexShader = true;
196 } 196 }
197 197
198 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.ge tCoverageColor(); 198 bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.ge tCoverageColor();
199 199
200 if ((covIsSolidWhite || !inputCoverageIsUsed) && !skipCoverage) { 200 if ((covIsSolidWhite || !inputCoverageIsUsed) && !skipCoverage) {
201 header->fCoverageInput = kSolidWhite_ColorInput; 201 header->fCoverageInput = kSolidWhite_ColorInput;
202 } else if (defaultToUniformInputs && !requiresCoverageAttrib && inputCoverag eIsUsed) { 202 } else if (defaultToUniformInputs && !requiresCoverageAttrib && inputCoverag eIsUsed) {
203 header->fCoverageInput = kUniform_ColorInput; 203 header->fCoverageInput = kUniform_ColorInput;
204 } else { 204 } else {
205 header->fCoverageInput = kAttribute_ColorInput; 205 header->fCoverageInput = kAttribute_ColorInput;
206 header->fHasVertexCode = true; 206 header->fRequiresVertexShader = true;
207 } 207 }
208 208
209 if (readsDst) { 209 if (readsDst) {
210 SkASSERT(NULL != dstCopy || gpu->caps()->dstReadInShaderSupport()); 210 SkASSERT(NULL != dstCopy || gpu->caps()->dstReadInShaderSupport());
211 const GrTexture* dstCopyTexture = NULL; 211 const GrTexture* dstCopyTexture = NULL;
212 if (NULL != dstCopy) { 212 if (NULL != dstCopy) {
213 dstCopyTexture = dstCopy->texture(); 213 dstCopyTexture = dstCopy->texture();
214 } 214 }
215 header->fDstReadKey = GrGLShaderBuilder::KeyForDstRead(dstCopyTexture, g pu->glCaps()); 215 header->fDstReadKey = GrGLShaderBuilder::KeyForDstRead(dstCopyTexture, g pu->glCaps());
216 SkASSERT(0 != header->fDstReadKey); 216 SkASSERT(0 != header->fDstReadKey);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 *checksum = 0; 315 *checksum = 0;
316 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); 316 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength);
317 } 317 }
318 318
319 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { 319 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) {
320 size_t keyLength = other.keyLength(); 320 size_t keyLength = other.keyLength();
321 fKey.reset(keyLength); 321 fKey.reset(keyLength);
322 memcpy(fKey.begin(), other.fKey.begin(), keyLength); 322 memcpy(fKey.begin(), other.fKey.begin(), keyLength);
323 return *this; 323 return *this;
324 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698