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

Side by Side Diff: tests/GLProgramsTest.cpp

Issue 356513003: Step towards variable length effect keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak comment 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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 // This is a GPU-backend specific test. It relies on static intializers to work 9 // This is a GPU-backend specific test. It relies on static intializers to work
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 12
13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
14 14
15 #include "GrBackendEffectFactory.h" 15 #include "GrBackendEffectFactory.h"
16 #include "GrContextFactory.h" 16 #include "GrContextFactory.h"
17 #include "GrDrawEffect.h" 17 #include "GrDrawEffect.h"
18 #include "effects/GrConfigConversionEffect.h" 18 #include "effects/GrConfigConversionEffect.h"
19 #include "gl/GrGpuGL.h" 19 #include "gl/GrGpuGL.h"
20 20
21 #include "SkChecksum.h" 21 #include "SkChecksum.h"
22 #include "SkRandom.h" 22 #include "SkRandom.h"
23 #include "Test.h" 23 #include "Test.h"
24 24
25 void GrGLProgramDesc::setRandom(SkRandom* random, 25 bool GrGLProgramDesc::setRandom(SkRandom* random,
26 const GrGpuGL* gpu, 26 const GrGpuGL* gpu,
27 const GrRenderTarget* dstRenderTarget, 27 const GrRenderTarget* dstRenderTarget,
28 const GrTexture* dstCopyTexture, 28 const GrTexture* dstCopyTexture,
29 const GrEffectStage* stages[], 29 const GrEffectStage* stages[],
30 int numColorStages, 30 int numColorStages,
31 int numCoverageStages, 31 int numCoverageStages,
32 int currAttribIndex) { 32 int currAttribIndex) {
33 int numEffects = numColorStages + numCoverageStages; 33 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k MaxVertexAttribCnt;
34 size_t keyLength = KeyLength(numEffects); 34
35 fKey.reset(keyLength); 35 int numStages = numColorStages + numCoverageStages;
36 *this->atOffset<uint32_t, kLengthOffset>() = static_cast<uint32_t>(keyLength ); 36 fKey.reset();
37 memset(this->header(), 0, kHeaderSize); 37
38 GR_STATIC_ASSERT(0 == kEffectKeyLengthsOffset % sizeof(uint32_t));
39
40 // Make room for everything up to and including the array of offsets to effe ct keys.
41 fKey.push_back_n(kEffectKeyLengthsOffset + sizeof(uint32_t) * numStages);
42
43 size_t offset = fKey.count();
44 int offsetIndex = 0;
45
46 bool dstRead = false;
47 bool fragPos = false;
48 bool vertexCode = false;
49 for (int s = 0; s < numStages; ++s) {
50 uint32_t* offsetLocation = reinterpret_cast<uint32_t*>(fKey.begin() +
51 kEffectKeyLengths Offset +
52 offsetIndex * siz eof(uint32_t));
53 *offsetLocation = offset;
54 ++offsetIndex;
55
56 const GrBackendEffectFactory& factory = stages[s]->getEffect()->getFacto ry();
57 GrDrawEffect drawEffect(*stages[s], useLocalCoords);
58 GrEffectKeyBuilder b(&fKey);
59 if (!factory.getGLEffectKey(drawEffect, gpu->glCaps(), &b)) {
60 fKey.reset();
61 return false;
62 }
63 if (stages[s]->getEffect()->willReadDstColor()) {
64 dstRead = true;
65 }
66 if (stages[s]->getEffect()->willReadFragmentPosition()) {
67 fragPos = true;
68 }
69 if (stages[s]->getEffect()->hasVertexCode()) {
70 vertexCode = true;
71 }
72
73 offset += b.size();
74 }
38 75
39 KeyHeader* header = this->header(); 76 KeyHeader* header = this->header();
77 memset(header, 0, kHeaderSize);
40 header->fEmitsPointSize = random->nextBool(); 78 header->fEmitsPointSize = random->nextBool();
41 79
42 header->fPositionAttributeIndex = 0; 80 header->fPositionAttributeIndex = 0;
43 81
44 // if the effects have used up all off the available attributes, 82 // if the effects have used up all off the available attributes,
45 // don't try to use color or coverage attributes as input 83 // don't try to use color or coverage attributes as input
46 do { 84 do {
47 header->fColorInput = static_cast<GrGLProgramDesc::ColorInput>( 85 header->fColorInput = static_cast<GrGLProgramDesc::ColorInput>(
48 random->nextULessThan(kColorInputCnt)); 86 random->nextULessThan(kColorInputCnt));
49 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && 87 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex &&
50 kAttribute_ColorInput == header->fColorInput); 88 kAttribute_ColorInput == header->fColorInput);
89
51 header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput ) ? 90 header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput ) ?
52 currAttribIndex++ : 91 currAttribIndex++ :
53 -1; 92 -1;
54 93
55 do { 94 do {
56 header->fCoverageInput = static_cast<GrGLProgramDesc::ColorInput>( 95 header->fCoverageInput = static_cast<GrGLProgramDesc::ColorInput>(
57 random->nextULessThan(kColorInputCnt)); 96 random->nextULessThan(kColorInputCnt));
58 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && 97 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex &&
59 kAttribute_ColorInput == header->fCoverageInput); 98 kAttribute_ColorInput == header->fCoverageInput);
60 header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_Colo rInput) ? 99 header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_Colo rInput) ?
61 currAttribIndex++ : 100 currAttribIndex++ :
62 -1; 101 -1;
63 102
64 #if GR_GL_EXPERIMENTAL_GS 103 #if GR_GL_EXPERIMENTAL_GS
65 header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->ne xtBool(); 104 header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->ne xtBool();
66 #endif 105 #endif
67 106
68 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k MaxVertexAttribCnt;
69 header->fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; 107 header->fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1;
70 108
71 header->fColorEffectCnt = numColorStages; 109 header->fColorEffectCnt = numColorStages;
72 header->fCoverageEffectCnt = numCoverageStages; 110 header->fCoverageEffectCnt = numCoverageStages;
73 111
74 bool dstRead = false;
75 bool fragPos = false;
76 bool vertexCode = false;
77 int numStages = numColorStages + numCoverageStages;
78 for (int s = 0; s < numStages; ++s) {
79 const GrBackendEffectFactory& factory = stages[s]->getEffect()->getFacto ry();
80 GrDrawEffect drawEffect(*stages[s], useLocalCoords);
81 this->effectKeys()[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
82 if (stages[s]->getEffect()->willReadDstColor()) {
83 dstRead = true;
84 }
85 if (stages[s]->getEffect()->willReadFragmentPosition()) {
86 fragPos = true;
87 }
88 if (stages[s]->getEffect()->hasVertexCode()) {
89 vertexCode = true;
90 }
91 }
92
93 if (dstRead) { 112 if (dstRead) {
94 header->fDstReadKey = GrGLShaderBuilder::KeyForDstRead(dstCopyTexture, g pu->glCaps()); 113 header->fDstReadKey = SkToU8(GrGLShaderBuilder::KeyForDstRead(dstCopyTex ture,
114 gpu->glCap s()));
95 } else { 115 } else {
96 header->fDstReadKey = 0; 116 header->fDstReadKey = 0;
97 } 117 }
98 if (fragPos) { 118 if (fragPos) {
99 header->fFragPosKey = GrGLShaderBuilder::KeyForFragmentPosition(dstRende rTarget, 119 header->fFragPosKey = SkToU8(GrGLShaderBuilder::KeyForFragmentPosition(d stRenderTarget,
100 gpu->gl Caps()); 120 g pu->glCaps()));
101 } else { 121 } else {
102 header->fFragPosKey = 0; 122 header->fFragPosKey = 0;
103 } 123 }
104 124
105 header->fHasVertexCode = vertexCode || 125 header->fHasVertexCode = vertexCode ||
106 useLocalCoords || 126 useLocalCoords ||
107 kAttribute_ColorInput == header->fColorInput || 127 kAttribute_ColorInput == header->fColorInput ||
108 kAttribute_ColorInput == header->fCoverageInput; 128 kAttribute_ColorInput == header->fCoverageInput;
109 129
110 CoverageOutput coverageOutput; 130 CoverageOutput coverageOutput;
111 bool illegalCoverageOutput; 131 bool illegalCoverageOutput;
112 do { 132 do {
113 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove rageOutputCnt)); 133 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove rageOutputCnt));
114 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() && 134 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() &&
115 CoverageOutputUsesSecondaryOutput(coverageOutpu t)) || 135 CoverageOutputUsesSecondaryOutput(coverageOutpu t)) ||
116 (!dstRead && kCombineWithDst_CoverageOutput == c overageOutput); 136 (!dstRead && kCombineWithDst_CoverageOutput == c overageOutput);
117 } while (illegalCoverageOutput); 137 } while (illegalCoverageOutput);
118 138
119 header->fCoverageOutput = coverageOutput; 139 header->fCoverageOutput = coverageOutput;
120 140
121 *this->checksum() = 0; 141 this->finalize();
122 *this->checksum() = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.get ()), keyLength); 142 return true;
123 fInitialized = true;
124 } 143 }
125 144
126 bool GrGpuGL::programUnitTest(int maxStages) { 145 bool GrGpuGL::programUnitTest(int maxStages) {
127 146
128 GrTextureDesc dummyDesc; 147 GrTextureDesc dummyDesc;
129 dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit; 148 dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit;
130 dummyDesc.fConfig = kSkia8888_GrPixelConfig; 149 dummyDesc.fConfig = kSkia8888_GrPixelConfig;
131 dummyDesc.fWidth = 34; 150 dummyDesc.fWidth = 34;
132 dummyDesc.fHeight = 18; 151 dummyDesc.fHeight = 18;
133 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0 )); 152 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0 ));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 214
196 for (int i = 0; i < numAttribs; ++i) { 215 for (int i = 0; i < numAttribs; ++i) {
197 attribIndices[i] = currAttribIndex++; 216 attribIndices[i] = currAttribIndex++;
198 } 217 }
199 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, 218 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage,
200 (effect.get(), attribIndices[0], a ttribIndices[1])); 219 (effect.get(), attribIndices[0], a ttribIndices[1]));
201 stages[s] = stage; 220 stages[s] = stage;
202 ++s; 221 ++s;
203 } 222 }
204 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum myTextures[1]; 223 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum myTextures[1];
205 pdesc.setRandom(&random, 224 if (!pdesc.setRandom(&random,
206 this, 225 this,
207 dummyTextures[0]->asRenderTarget(), 226 dummyTextures[0]->asRenderTarget(),
208 dstTexture, 227 dstTexture,
209 stages.get(), 228 stages.get(),
210 numColorStages, 229 numColorStages,
211 numCoverageStages, 230 numCoverageStages,
212 currAttribIndex); 231 currAttribIndex)) {
232 return false;
233 }
213 234
214 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this, 235 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this,
215 pdesc, 236 pdesc,
216 stages, 237 stages,
217 stages + numColorS tages)); 238 stages + numColorS tages));
218 for (int s = 0; s < numStages; ++s) { 239 for (int s = 0; s < numStages; ++s) {
219 SkDELETE(stages[s]); 240 SkDELETE(stages[s]);
220 } 241 }
221 if (NULL == program.get()) { 242 if (NULL == program.get()) {
222 return false; 243 return false;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); 282 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1));
262 GrConfigConversionEffect::Create(NULL, 283 GrConfigConversionEffect::Create(NULL,
263 false, 284 false,
264 GrConfigConversionEffect::kNone_PMConversio n, 285 GrConfigConversionEffect::kNone_PMConversio n,
265 SkMatrix::I()); 286 SkMatrix::I());
266 SkScalar matrix[20]; 287 SkScalar matrix[20];
267 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); 288 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix));
268 } 289 }
269 290
270 #endif 291 #endif
OLDNEW
« include/gpu/GrTBackendEffectFactory.h ('K') | « src/gpu/gl/GrGpuGL_program.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698