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

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

Issue 582963002: Solo gp (Closed) Base URL: https://skia.googlesource.com/skia.git@no_peb
Patch Set: fix Created 6 years, 3 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 #ifndef GrGLProgramDesc_DEFINED 8 #ifndef GrGLProgramDesc_DEFINED
9 #define GrGLProgramDesc_DEFINED 9 #define GrGLProgramDesc_DEFINED
10 10
11 #include "GrGLEffect.h" 11 #include "GrGLProcessor.h"
12 #include "GrDrawState.h" 12 #include "GrDrawState.h"
13 #include "GrGpu.h" 13 #include "GrGpu.h"
14 14
15 class GrGpuGL; 15 class GrGpuGL;
16 16
17 #ifdef SK_DEBUG 17 #ifdef SK_DEBUG
18 // Optionally compile the experimental GS code. Set to SK_DEBUG so that debug build bots will 18 // Optionally compile the experimental GS code. Set to SK_DEBUG so that debug build bots will
19 // execute the code. 19 // execute the code.
20 #define GR_GL_EXPERIMENTAL_GS 1 20 #define GR_GL_EXPERIMENTAL_GS 1
21 #else 21 #else
(...skipping 19 matching lines...) Expand all
41 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset> (); } 41 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset> (); }
42 42
43 // Gets the a checksum of the key. Can be used as a hash value for a fast lo okup in a cache. 43 // Gets the a checksum of the key. Can be used as a hash value for a fast lo okup in a cache.
44 uint32_t getChecksum() const { return *this->atOffset<uint32_t, kChecksumOff set>(); } 44 uint32_t getChecksum() const { return *this->atOffset<uint32_t, kChecksumOff set>(); }
45 45
46 // For unit testing. 46 // For unit testing.
47 bool setRandom(SkRandom*, 47 bool setRandom(SkRandom*,
48 const GrGpuGL* gpu, 48 const GrGpuGL* gpu,
49 const GrRenderTarget* dummyDstRenderTarget, 49 const GrRenderTarget* dummyDstRenderTarget,
50 const GrTexture* dummyDstCopyTexture, 50 const GrTexture* dummyDstCopyTexture,
51 const GrEffectStage* geometryProcessor, 51 const GrGeometryStage* geometryProcessor,
52 const GrEffectStage* stages[], 52 const GrFragmentStage* stages[],
53 int numColorStages, 53 int numColorStages,
54 int numCoverageStages, 54 int numCoverageStages,
55 int currAttribIndex); 55 int currAttribIndex);
56 56
57 /** 57 /**
58 * Builds a program descriptor from a GrOptDrawState. Whether the primitive type is points, and 58 * Builds a program descriptor from a GrOptDrawState. Whether the primitive type is points, and
59 * the caps of the GrGpuGL are also inputs. It also outputs the color and co verage stages 59 * the caps of the GrGpuGL are also inputs. It also outputs the color and co verage stages
60 * referenced by the generated descriptor. Coverage stages from the drawStat e may be treated as 60 * referenced by the generated descriptor. Coverage stages from the drawStat e may be treated as
61 * color stages in the output. 61 * color stages in the output.
62 */ 62 */
63 static bool Build(const GrOptDrawState&, 63 static bool Build(const GrOptDrawState& optState,
bsalomon 2014/09/22 15:35:24 IMO param names that just repeat the type name are
64 GrGpu::DrawType drawType, 64 GrGpu::DrawType drawType,
65 GrBlendCoeff srcCoeff, 65 GrBlendCoeff srcCoeff,
66 GrBlendCoeff dstCoeff, 66 GrBlendCoeff dstCoeff,
67 const GrGpuGL* gpu, 67 const GrGpuGL* gpu,
68 const GrDeviceCoordTexture* dstCopy, 68 const GrDeviceCoordTexture* dstCopy,
69 const GrEffectStage** outGeometryProcessor, 69 const GrGeometryStage** geometryProcessor,
70 SkTArray<const GrEffectStage*, true>* outColorStages, 70 SkTArray<const GrFragmentStage*, true>* colorStages,
71 SkTArray<const GrEffectStage*, true>* outCoverageStages, 71 SkTArray<const GrFragmentStage*, true>* coverageStages,
72 GrGLProgramDesc* outDesc); 72 GrGLProgramDesc* desc);
73 73
74 bool hasGeometryProcessor() const { 74 bool hasGeometryProcessor() const {
75 return SkToBool(this->getHeader().fHasGeometryProcessor); 75 return SkToBool(this->getHeader().fHasGeometryProcessor);
76 } 76 }
77 77
78 int numColorEffects() const { 78 int numColorEffects() const {
79 return this->getHeader().fColorEffectCnt; 79 return this->getHeader().fColorEffectCnt;
80 } 80 }
81 81
82 int numCoverageEffects() const { 82 int numCoverageEffects() const {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O FFSET); 194 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O FFSET);
195 } 195 }
196 196
197 template<typename T, size_t OFFSET> const T* atOffset() const { 197 template<typename T, size_t OFFSET> const T* atOffset() const {
198 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin( )) + OFFSET); 198 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin( )) + OFFSET);
199 } 199 }
200 200
201 KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); } 201 KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); }
202 202
203 // Shared code between setRandom() and Build(). 203 // Shared code between setRandom() and Build().
204 static bool GetEffectKey(const GrEffectStage& stage, const GrGLCaps& caps, 204 static bool GetProcessorKey(const GrProcessorStage& stage,
205 bool useExplicitLocalCoords, GrEffectKeyBuilder* b, 205 const GrGLCaps& caps,
206 uint16_t* effectKeySize); 206 bool useExplicitLocalCoords,
207 GrProcessorKeyBuilder* b,
208 uint16_t* effectKeySize);
207 209
210 static bool GetGeometryProcessorKey(const GrGeometryStage& stage,
211 const GrGLCaps& caps,
212 bool useExplicitLocalCoords,
213 GrProcessorKeyBuilder* b,
214 uint16_t* effectKeySize);
208 void finalize(); 215 void finalize();
209 216
210 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead erOffset>(); } 217 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead erOffset>(); }
211 218
212 /** Used to provide effects' keys to their emitCode() function. */ 219 /** Used to provide effects' keys to their emitCode() function. */
213 class EffectKeyProvider { 220 class EffectKeyProvider {
214 public: 221 public:
215 enum EffectType { 222 enum EffectType {
216 kGeometryProcessor_EffectType, 223 kGeometryProcessor_EffectType,
217 kColor_EffectType, 224 kColor_EffectType,
218 kCoverage_EffectType, 225 kCoverage_EffectType,
219 }; 226 };
220 227
221 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc( desc) { 228 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc( desc) {
222 switch (type) { 229 switch (type) {
223 case kGeometryProcessor_EffectType: 230 case kGeometryProcessor_EffectType:
224 // there can be only one 231 // there can be only one
225 fBaseIndex = 0; 232 fBaseIndex = 0;
226 break; 233 break;
227 case kColor_EffectType: 234 case kColor_EffectType:
228 fBaseIndex = desc->hasGeometryProcessor() ? 1 : 0; 235 fBaseIndex = desc->hasGeometryProcessor() ? 1 : 0;
229 break; 236 break;
230 case kCoverage_EffectType: 237 case kCoverage_EffectType:
231 fBaseIndex = desc->numColorEffects() + (desc->hasGeometryPro cessor() ? 1 : 0); 238 fBaseIndex = desc->numColorEffects() + (desc->hasGeometryPro cessor() ? 1 : 0);
232 break; 239 break;
233 } 240 }
234 } 241 }
235 242
236 GrEffectKey get(int index) const { 243 GrProcessorKey get(int index) const {
237 const uint16_t* offsetsAndLengths = reinterpret_cast<const uint16_t* >( 244 const uint16_t* offsetsAndLengths = reinterpret_cast<const uint16_t* >(
238 fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset); 245 fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset);
239 // We store two uint16_ts per effect, one for the offset to the effe ct's key and one for 246 // We store two uint16_ts per effect, one for the offset to the effe ct's key and one for
240 // its length. Here we just need the offset. 247 // its length. Here we just need the offset.
241 uint16_t offset = offsetsAndLengths[2 * (fBaseIndex + index) + 0]; 248 uint16_t offset = offsetsAndLengths[2 * (fBaseIndex + index) + 0];
242 uint16_t length = offsetsAndLengths[2 * (fBaseIndex + index) + 1]; 249 uint16_t length = offsetsAndLengths[2 * (fBaseIndex + index) + 1];
243 // Currently effects must add to the key in units of uint32_t. 250 // Currently effects must add to the key in units of uint32_t.
244 SkASSERT(0 == (length % sizeof(uint32_t))); 251 SkASSERT(0 == (length % sizeof(uint32_t)));
245 return GrEffectKey(reinterpret_cast<const uint32_t*>(fDesc->fKey.beg in() + offset), 252 return GrProcessorKey(reinterpret_cast<const uint32_t*>(fDesc->fKey. begin() + offset),
246 length / sizeof(uint32_t)); 253 length / sizeof(uint32_t));
247 } 254 }
248 private: 255 private:
249 const GrGLProgramDesc* fDesc; 256 const GrGLProgramDesc* fDesc;
250 int fBaseIndex; 257 int fBaseIndex;
251 }; 258 };
252 259
253 enum { 260 enum {
254 kMaxPreallocEffects = 8, 261 kMaxPreallocEffects = 8,
255 kIntsPerEffect = 4, // This is an overestimate of the average ef fect key size. 262 kIntsPerEffect = 4, // This is an overestimate of the average ef fect key size.
256 kPreAllocSize = kEffectKeyOffsetsAndLengthOffset + 263 kPreAllocSize = kEffectKeyOffsetsAndLengthOffset +
257 kMaxPreallocEffects * sizeof(uint32_t) * kIntsPerEffect, 264 kMaxPreallocEffects * sizeof(uint32_t) * kIntsPerEffect,
258 }; 265 };
259 266
260 SkSTArray<kPreAllocSize, uint8_t, true> fKey; 267 SkSTArray<kPreAllocSize, uint8_t, true> fKey;
261 268
262 // GrGLProgram and GrGLShaderBuilder read the private fields to generate cod e. TODO: Split out 269 // GrGLProgram and GrGLShaderBuilder read the private fields to generate cod e. TODO: Split out
263 // part of GrGLShaderBuilder that is used by effects so that this header doe sn't need to be 270 // part of GrGLShaderBuilder that is used by effects so that this header doe sn't need to be
264 // visible to GrGLEffects. Then make public accessors as necessary and remov e friends. 271 // visible to GrGLProcessors. Then make public accessors as necessary and re move friends.
265 friend class GrGLProgram; 272 friend class GrGLProgram;
266 friend class GrGLProgramBuilder; 273 friend class GrGLProgramBuilder;
267 friend class GrGLFullProgramBuilder; 274 friend class GrGLFullProgramBuilder;
268 friend class GrGLFragmentOnlyProgramBuilder; 275 friend class GrGLFragmentOnlyProgramBuilder;
269 friend class GrGLVertexShaderBuilder; 276 friend class GrGLVertexShaderBuilder;
270 friend class GrGLFragmentShaderBuilder; 277 friend class GrGLFragmentShaderBuilder;
271 friend class GrGLGeometryShaderBuilder; 278 friend class GrGLGeometryShaderBuilder;
272 }; 279 };
273 280
274 #endif 281 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698