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

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

Issue 379113004: Makes GrGLProgramDesc's key store the lengths as well as offsets of the effect keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@key
Patch Set: fix typo Created 6 years, 5 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 static inline bool get_key_and_update_stats(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 bool* setTrueIfReadsDst, 21 uint16_t* effectKeySize,
22 bool* setTrueIfReadsPos, 22 bool* setTrueIfReadsDst,
23 bool* setTrueIfHasVertexCode) { 23 bool* setTrueIfReadsPos,
24 bool* setTrueIfHasVertexCode) {
24 const GrBackendEffectFactory& factory = stage.getEffect()->getFactory(); 25 const GrBackendEffectFactory& factory = stage.getEffect()->getFactory();
25 GrDrawEffect drawEffect(stage, useExplicitLocalCoords); 26 GrDrawEffect drawEffect(stage, useExplicitLocalCoords);
26 if (stage.getEffect()->willReadDstColor()) { 27 if (stage.getEffect()->willReadDstColor()) {
27 *setTrueIfReadsDst = true; 28 *setTrueIfReadsDst = true;
28 } 29 }
29 if (stage.getEffect()->willReadFragmentPosition()) { 30 if (stage.getEffect()->willReadFragmentPosition()) {
30 *setTrueIfReadsPos = true; 31 *setTrueIfReadsPos = true;
31 } 32 }
32 if (stage.getEffect()->hasVertexCode()) { 33 if (stage.getEffect()->hasVertexCode()) {
33 *setTrueIfHasVertexCode = true; 34 *setTrueIfHasVertexCode = true;
34 } 35 }
35 return factory.getGLEffectKey(drawEffect, caps, b); 36 factory.getGLEffectKey(drawEffect, caps, b);
37 size_t size = b->size();
38 if (size > SK_MaxU16) {
39 return false;
40 }
41 *effectKeySize = SkToU16(size);
42 if (!GrGLProgramEffects::GenEffectMetaKey(drawEffect, caps, b)) {
43 return false;
44 }
45 return true;
36 } 46 }
37 47
38 bool GrGLProgramDesc::Build(const GrDrawState& drawState, 48 bool GrGLProgramDesc::Build(const GrDrawState& drawState,
39 GrGpu::DrawType drawType, 49 GrGpu::DrawType drawType,
40 GrDrawState::BlendOptFlags blendOpts, 50 GrDrawState::BlendOptFlags blendOpts,
41 GrBlendCoeff srcCoeff, 51 GrBlendCoeff srcCoeff,
42 GrBlendCoeff dstCoeff, 52 GrBlendCoeff dstCoeff,
43 const GrGpuGL* gpu, 53 const GrGpuGL* gpu,
44 const GrDeviceCoordTexture* dstCopy, 54 const GrDeviceCoordTexture* dstCopy,
45 SkTArray<const GrEffectStage*, true>* colorStages, 55 SkTArray<const GrEffectStage*, true>* colorStages,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // We use vertexshader-less shader programs only when drawing paths. 108 // We use vertexshader-less shader programs only when drawing paths.
99 bool hasVertexCode = !(GrGpu::kDrawPath_DrawType == drawType || 109 bool hasVertexCode = !(GrGpu::kDrawPath_DrawType == drawType ||
100 GrGpu::kDrawPaths_DrawType == drawType); 110 GrGpu::kDrawPaths_DrawType == drawType);
101 int numStages = 0; 111 int numStages = 0;
102 if (!skipColor) { 112 if (!skipColor) {
103 numStages += drawState.numColorStages() - firstEffectiveColorStage; 113 numStages += drawState.numColorStages() - firstEffectiveColorStage;
104 } 114 }
105 if (!skipCoverage) { 115 if (!skipCoverage) {
106 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage ; 116 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage ;
107 } 117 }
108 GR_STATIC_ASSERT(0 == kEffectKeyLengthsOffset % sizeof(uint32_t)); 118 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t));
109 // Make room for everything up to and including the array of offsets to effe ct keys. 119 // Make room for everything up to and including the array of offsets to effe ct keys.
110 desc->fKey.reset(); 120 desc->fKey.reset();
111 desc->fKey.push_back_n(kEffectKeyLengthsOffset + sizeof(uint32_t) * numStage s); 121 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint32_ t) * numStages);
112 122
113 size_t offset = desc->fKey.count(); 123 int offsetAndSizeIndex = 0;
114 int offsetIndex = 0;
115 124
116 bool effectKeySuccess = true; 125 bool effectKeySuccess = true;
117 if (!skipColor) { 126 if (!skipColor) {
118 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) { 127 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) {
119 uint32_t* offsetLocation = reinterpret_cast<uint32_t*>(desc->fKey.be gin() + 128 uint16_t* offsetAndSize =
120 kEffectKeyLen gthsOffset + 129 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset +
121 offsetIndex * sizeof(uint32_t)); 130 offsetAndSizeIndex * 2 * sizeof(uint 16_t));
122 *offsetLocation = offset;
123 ++offsetIndex;
124 131
125 GrEffectKeyBuilder b(&desc->fKey); 132 GrEffectKeyBuilder b(&desc->fKey);
126 effectKeySuccess |= get_key_and_update_stats(drawState.getColorStage (s), gpu->glCaps(), 133 uint16_t effectKeySize;
127 requiresLocalCoordAttri b, &b, &readsDst, 134 uint32_t effectOffset = desc->fKey.count();
128 &readFragPosition, &has VertexCode); 135 effectKeySuccess |= GetEffectKeyAndUpdateStats(
129 offset += b.size(); 136 drawState.getColorStage(s), gpu->glCaps(),
137 requiresLocalCoordAttrib, &b,
138 &effectKeySize, &readsDst,
139 &readFragPosition, &hasVertexCode);
140 effectKeySuccess |= (effectOffset <= SK_MaxU16);
141
142 offsetAndSize[0] = SkToU16(effectOffset);
143 offsetAndSize[1] = effectKeySize;
144 ++offsetAndSizeIndex;
130 } 145 }
131 } 146 }
132 if (!skipCoverage) { 147 if (!skipCoverage) {
133 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage s(); ++s) { 148 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage s(); ++s) {
134 uint32_t* offsetLocation = reinterpret_cast<uint32_t*>(desc->fKey.be gin() + 149 uint16_t* offsetAndSize =
135 kEffectKeyLen gthsOffset + 150 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset +
136 offsetIndex * sizeof(uint32_t)); 151 offsetAndSizeIndex * 2 * sizeof(uint 16_t));
137 *offsetLocation = offset; 152
138 ++offsetIndex;
139 GrEffectKeyBuilder b(&desc->fKey); 153 GrEffectKeyBuilder b(&desc->fKey);
140 effectKeySuccess |= get_key_and_update_stats(drawState.getCoverageSt age(s), 154 uint16_t effectKeySize;
141 gpu->glCaps(), requires LocalCoordAttrib, 155 uint32_t effectOffset = desc->fKey.count();
142 &b, &readsDst, &readFra gPosition, 156 effectKeySuccess |= GetEffectKeyAndUpdateStats(
143 &hasVertexCode); 157 drawState.getCoverageStage(s), gpu->glCaps() ,
144 offset += b.size(); 158 requiresLocalCoordAttrib, &b,
159 &effectKeySize, &readsDst,
160 &readFragPosition, &hasVertexCode);
161 effectKeySuccess |= (effectOffset <= SK_MaxU16);
162
163 offsetAndSize[0] = SkToU16(effectOffset);
164 offsetAndSize[1] = effectKeySize;
165 ++offsetAndSizeIndex;
145 } 166 }
146 } 167 }
147 if (!effectKeySuccess) { 168 if (!effectKeySuccess) {
148 desc->fKey.reset(); 169 desc->fKey.reset();
149 return false; 170 return false;
150 } 171 }
151 172
152 KeyHeader* header = desc->header(); 173 KeyHeader* header = desc->header();
153 // make sure any padding in the header is zeroed. 174 // make sure any padding in the header is zeroed.
154 memset(desc->header(), 0, kHeaderSize); 175 memset(desc->header(), 0, kHeaderSize);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 *checksum = 0; 324 *checksum = 0;
304 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); 325 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength);
305 } 326 }
306 327
307 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { 328 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) {
308 size_t keyLength = other.keyLength(); 329 size_t keyLength = other.keyLength();
309 fKey.reset(keyLength); 330 fKey.reset(keyLength);
310 memcpy(fKey.begin(), other.fKey.begin(), keyLength); 331 memcpy(fKey.begin(), other.fKey.begin(), keyLength);
311 return *this; 332 return *this;
312 } 333 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698