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

Side by Side Diff: src/gpu/GrProgramDesc.h

Issue 2318523006: Merge GrGLSLProgramDesc into GrProgramDesc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: build fix, VS is too nice Created 4 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
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrProgramDesc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 GrProgramDesc_DEFINED 8 #ifndef GrProgramDesc_DEFINED
9 #define GrProgramDesc_DEFINED 9 #define GrProgramDesc_DEFINED
10 10
11 #include "GrColor.h" 11 #include "GrColor.h"
12 #include "GrTypesPriv.h" 12 #include "GrTypesPriv.h"
13 #include "SkOpts.h" 13 #include "SkOpts.h"
14 #include "SkTArray.h" 14 #include "SkTArray.h"
15 15
16 /** This class describes a program to generate. It also serves as a program cach e key. Very little 16 class GrGLSLCaps;
17 of this is GL-specific. The GL-specific parts could be factored out into a s ubclass. */ 17 class GrPipeline;
18 class GrPrimitiveProcessor;
19
20 /** This class describes a program to generate. It also serves as a program cach e key */
18 class GrProgramDesc { 21 class GrProgramDesc {
19 public: 22 public:
20 // Creates an uninitialized key that must be populated by GrGpu::buildProgra mDesc() 23 // Creates an uninitialized key that must be populated by GrGpu::buildProgra mDesc()
21 GrProgramDesc() {} 24 GrProgramDesc() {}
22 25
26 /**
27 * Builds a program descriptor
bsalomon 2016/09/07 13:41:15 Note that finalize must be called after Build()?
egdaniel 2016/09/07 13:53:38 Done.
28 *
29 * @param GrPrimitiveProcessor The geometry
30 * @param GrPipeline The optimized drawstate. The descriptor will represent a program
31 * which this optstate can use to draw with. The opts tate contains
32 * general draw information, as well as the specific c olor, geometry,
33 * and coverage stages which will be used to generate the GL Program for
34 * this optstate.
35 * @param GrGLSLCaps Capabilities of the GLSL backend.
36 * @param GrProgramDesc The built and finalized descriptor
37 **/
38 static bool Build(GrProgramDesc*,
39 const GrPrimitiveProcessor&,
40 const GrPipeline&,
41 const GrGLSLCaps&);
42
23 // Returns this as a uint32_t array to be used as a key in the program cache . 43 // Returns this as a uint32_t array to be used as a key in the program cache .
24 const uint32_t* asKey() const { 44 const uint32_t* asKey() const {
25 return reinterpret_cast<const uint32_t*>(fKey.begin()); 45 return reinterpret_cast<const uint32_t*>(fKey.begin());
26 } 46 }
27 47
28 // Gets the number of bytes in asKey(). It will be a 4-byte aligned value. W hen comparing two 48 // Gets the number of bytes in asKey(). It will be a 4-byte aligned value. W hen comparing two
29 // keys the size of either key can be used with memcmp() since the lengths t hemselves begin the 49 // keys the size of either key can be used with memcmp() since the lengths t hemselves begin the
30 // keys and thus the memcmp will exit early if the keys are of different len gths. 50 // keys and thus the memcmp will exit early if the keys are of different len gths.
31 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset> (); } 51 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset> (); }
32 52
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 110
91 int numCoverageEffects() const { 111 int numCoverageEffects() const {
92 return this->header().fCoverageEffectCnt; 112 return this->header().fCoverageEffectCnt;
93 } 113 }
94 114
95 int numTotalEffects() const { return this->numColorEffects() + this->numCove rageEffects(); } 115 int numTotalEffects() const { return this->numColorEffects() + this->numCove rageEffects(); }
96 116
97 // This should really only be used internally, base classes should return th eir own headers 117 // This should really only be used internally, base classes should return th eir own headers
98 const KeyHeader& header() const { return *this->atOffset<KeyHeader, kHeaderO ffset>(); } 118 const KeyHeader& header() const { return *this->atOffset<KeyHeader, kHeaderO ffset>(); }
99 119
100 protected:
101 template<typename T, size_t OFFSET> T* atOffset() {
102 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O FFSET);
103 }
104
105 template<typename T, size_t OFFSET> const T* atOffset() const {
106 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin( )) + OFFSET);
107 }
108
109 void finalize() { 120 void finalize() {
110 int keyLength = fKey.count(); 121 int keyLength = fKey.count();
111 SkASSERT(0 == (keyLength % 4)); 122 SkASSERT(0 == (keyLength % 4));
112 *(this->atOffset<uint32_t, GrProgramDesc::kLengthOffset>()) = SkToU32(ke yLength); 123 *(this->atOffset<uint32_t, GrProgramDesc::kLengthOffset>()) = SkToU32(ke yLength);
113 124
114 uint32_t* checksum = this->atOffset<uint32_t, GrProgramDesc::kChecksumOf fset>(); 125 uint32_t* checksum = this->atOffset<uint32_t, GrProgramDesc::kChecksumOf fset>();
115 *checksum = 0; // We'll hash through these bytes, so make sure they're initialized. 126 *checksum = 0; // We'll hash through these bytes, so make sure they're initialized.
116 *checksum = SkOpts::hash(fKey.begin(), keyLength); 127 *checksum = SkOpts::hash(fKey.begin(), keyLength);
117 } 128 }
118 129
130 protected:
131 template<typename T, size_t OFFSET> T* atOffset() {
132 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O FFSET);
133 }
134
135 template<typename T, size_t OFFSET> const T* atOffset() const {
136 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin( )) + OFFSET);
137 }
138
119 // The key, stored in fKey, is composed of four parts: 139 // The key, stored in fKey, is composed of four parts:
120 // 1. uint32_t for total key length. 140 // 1. uint32_t for total key length.
121 // 2. uint32_t for a checksum. 141 // 2. uint32_t for a checksum.
122 // 3. Header struct defined above. Also room for extensions to the header 142 // 3. Header struct defined above.
123 // 4. A Backend specific payload. Room is preallocated for this 143 // 4. A Backend specific payload. Room is preallocated for this
bsalomon 2016/09/07 13:41:15 Update this to say part 4 is the per-processor key
egdaniel 2016/09/07 13:53:38 Done.
124 enum KeyOffsets { 144 enum KeyOffsets {
125 // Part 1. 145 // Part 1.
126 kLengthOffset = 0, 146 kLengthOffset = 0,
127 // Part 2. 147 // Part 2.
128 kChecksumOffset = kLengthOffset + sizeof(uint32_t), 148 kChecksumOffset = kLengthOffset + sizeof(uint32_t),
129 // Part 3. 149 // Part 3.
130 kHeaderOffset = kChecksumOffset + sizeof(uint32_t), 150 kHeaderOffset = kChecksumOffset + sizeof(uint32_t),
131 kHeaderSize = SkAlign4(2 * sizeof(KeyHeader)), 151 kHeaderSize = SkAlign4(sizeof(KeyHeader)),
152 // Part 4.
153 // This is the offset into the backenend specific part of the key, which includes
154 // per-processor keys.
155 kProcessorKeysOffset = kHeaderOffset + kHeaderSize,
132 }; 156 };
133 157
134 enum { 158 enum {
135 kMaxPreallocProcessors = 8, 159 kMaxPreallocProcessors = 8,
136 kIntsPerProcessor = 4, // This is an overestimate of the average effect key size. 160 kIntsPerProcessor = 4, // This is an overestimate of the average effect key size.
137 kPreAllocSize = kHeaderOffset + kHeaderSize + 161 kPreAllocSize = kHeaderOffset + kHeaderSize +
138 kMaxPreallocProcessors * sizeof(uint32_t) * kIntsPerProc essor, 162 kMaxPreallocProcessors * sizeof(uint32_t) * kIntsPerProc essor,
139 }; 163 };
140 164
141 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; } 165 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; }
142 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; } 166 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; }
143 167
144 private: 168 private:
145 SkSTArray<kPreAllocSize, uint8_t, true> fKey; 169 SkSTArray<kPreAllocSize, uint8_t, true> fKey;
146 }; 170 };
147 171
148 #endif 172 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrProgramDesc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698