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

Side by Side Diff: tests/GLProgramsTest.cpp

Issue 15252004: Make GrGLProgramDesc's key variable length by compacting the effect key array (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: address comments, fix unit test Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGpuGL_program.cpp ('k') | no next file » | 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 /* 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 "gl/GrGpuGL.h" 15 #include "gl/GrGpuGL.h"
16 #include "GrBackendEffectFactory.h" 16 #include "GrBackendEffectFactory.h"
17 #include "GrContextFactory.h" 17 #include "GrContextFactory.h"
18 #include "GrDrawEffect.h" 18 #include "GrDrawEffect.h"
19 #include "effects/GrConfigConversionEffect.h" 19 #include "effects/GrConfigConversionEffect.h"
20 20
21 #include "SkChecksum.h"
21 #include "SkRandom.h" 22 #include "SkRandom.h"
22 #include "Test.h" 23 #include "Test.h"
23 24
24 void GrGLProgramDesc::setRandom(SkMWCRandom* random, 25 void GrGLProgramDesc::setRandom(SkMWCRandom* random,
25 const GrGpuGL* gpu, 26 const GrGpuGL* gpu,
26 const GrTexture* dstTexture, 27 const GrRenderTarget* dstRenderTarget,
27 const GrEffectStage* stages[GrDrawState::kNumSta ges], 28 const GrTexture* dstCopyTexture,
29 const GrEffectStage* stages[],
30 int numColorStages,
31 int numCoverageStages,
28 int currAttribIndex) { 32 int currAttribIndex) {
29 fEmitsPointSize = random->nextBool(); 33 int numEffects = numColorStages + numCoverageStages;
34 size_t keyLength = KeyLength(numEffects);
35 fKey.reset(keyLength);
36 *this->atOffset<uint32_t, kLengthOffset>() = static_cast<uint32_t>(keyLength );
37 memset(this->header(), 0, kHeaderSize);
30 38
31 fPositionAttributeIndex = 0; 39 KeyHeader* header = this->header();
40 header->fEmitsPointSize = random->nextBool();
41
42 header->fPositionAttributeIndex = 0;
32 43
33 // if the effects have used up all off the available attributes, 44 // if the effects have used up all off the available attributes,
34 // don't try to use color or coverage attributes as input 45 // don't try to use color or coverage attributes as input
35 do { 46 do {
36 fColorInput = random->nextULessThan(kColorInputCnt); 47 header->fColorInput = random->nextULessThan(kColorInputCnt);
37 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && 48 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex &&
38 kAttribute_ColorInput == fColorInput); 49 kAttribute_ColorInput == header->fColorInput);
39 fColorAttributeIndex = (fColorInput == kAttribute_ColorInput) ? currAttribIn dex++ : -1; 50 header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput ) ?
51 currAttribIndex++ :
52 -1;
40 53
41 do { 54 do {
42 fCoverageInput = random->nextULessThan(kColorInputCnt); 55 header->fCoverageInput = random->nextULessThan(kColorInputCnt);
43 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex && 56 } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex &&
44 kAttribute_ColorInput == fCoverageInput); 57 kAttribute_ColorInput == header->fCoverageInput);
45 fCoverageAttributeIndex = (fCoverageInput == kAttribute_ColorInput) ? currAt tribIndex++ : -1; 58 header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_Colo rInput) ?
59 currAttribIndex++ :
60 -1;
46 61
47 fColorFilterXfermode = random->nextULessThan(SkXfermode::kLastCoeffMode + 1) ; 62 header->fColorFilterXfermode = random->nextULessThan(SkXfermode::kLastCoeffM ode + 1);
48
49 fFirstCoverageStage = random->nextULessThan(GrDrawState::kNumStages);
50 63
51 #if GR_GL_EXPERIMENTAL_GS 64 #if GR_GL_EXPERIMENTAL_GS
52 fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool() ; 65 header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->ne xtBool();
53 #endif 66 #endif
54 67
55 fDiscardIfZeroCoverage = random->nextBool(); 68 header->fDiscardIfZeroCoverage = random->nextBool();
56 69
57 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k MaxVertexAttribCnt; 70 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k MaxVertexAttribCnt;
58 fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; 71 header->fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1;
72
73 header->fColorEffectCnt = numColorStages;
74 header->fCoverageEffectCnt = numCoverageStages;
59 75
60 bool dstRead = false; 76 bool dstRead = false;
61 for (int s = 0; s < GrDrawState::kNumStages; ++s) { 77 bool fragPos = false;
62 if (NULL != stages[s]) { 78 int numStages = numColorStages + numCoverageStages;
63 const GrBackendEffectFactory& factory = (*stages[s]->getEffect())->g etFactory(); 79 for (int s = 0; s < numStages; ++s) {
64 GrDrawEffect drawEffect(*stages[s], useLocalCoords); 80 const GrBackendEffectFactory& factory = (*stages[s]->getEffect())->getFa ctory();
65 fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()); 81 GrDrawEffect drawEffect(*stages[s], useLocalCoords);
66 if ((*stages[s]->getEffect())->willReadDstColor()) { 82 this->effectKeys()[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
67 dstRead = true; 83 if ((*stages[s]->getEffect())->willReadDstColor()) {
68 } 84 dstRead = true;
85 }
86 if ((*stages[s]->getEffect())->willReadFragmentPosition()) {
87 fragPos = true;
69 } 88 }
70 } 89 }
71 90
72 if (dstRead) { 91 if (dstRead) {
73 this->fDstReadKey = GrGLShaderBuilder::KeyForDstRead(dstTexture, gpu->gl Caps()); 92 header->fDstReadKey = GrGLShaderBuilder::KeyForDstRead(dstCopyTexture, g pu->glCaps());
93 } else {
94 header->fDstReadKey = 0;
95 }
96 if (fragPos) {
97 header->fFragPosKey = GrGLShaderBuilder::KeyForFragmentPosition(dstRende rTarget,
98 gpu->gl Caps());
99 } else {
100 header->fFragPosKey = 0;
74 } 101 }
75 102
76 CoverageOutput coverageOutput; 103 CoverageOutput coverageOutput;
77 bool illegalCoverageOutput; 104 bool illegalCoverageOutput;
78 do { 105 do {
79 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove rageOutputCnt)); 106 coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCove rageOutputCnt));
80 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() && 107 illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() &&
81 CoverageOutputUsesSecondaryOutput(coverageOutpu t)) || 108 CoverageOutputUsesSecondaryOutput(coverageOutpu t)) ||
82 (!dstRead && kCombineWithDst_CoverageOutput == c overageOutput); 109 (!dstRead && kCombineWithDst_CoverageOutput == c overageOutput);
83 } while (illegalCoverageOutput); 110 } while (illegalCoverageOutput);
84 111
85 fCoverageOutput = coverageOutput; 112 header->fCoverageOutput = coverageOutput;
113
114 *this->checksum() = 0;
115 *this->checksum() = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.get ()), keyLength);
116 fInitialized = true;
86 } 117 }
87 118
88 bool GrGpuGL::programUnitTest(int maxStages) { 119 bool GrGpuGL::programUnitTest(int maxStages) {
89 120
90 maxStages = GrMin(maxStages, (int)GrDrawState::kNumStages); 121 maxStages = GrMin(maxStages, (int)GrDrawState::kNumStages);
91 122
92 GrTextureDesc dummyDesc; 123 GrTextureDesc dummyDesc;
124 dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit;
93 dummyDesc.fConfig = kSkia8888_GrPixelConfig; 125 dummyDesc.fConfig = kSkia8888_GrPixelConfig;
94 dummyDesc.fWidth = 34; 126 dummyDesc.fWidth = 34;
95 dummyDesc.fHeight = 18; 127 dummyDesc.fHeight = 18;
96 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0 )); 128 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0 ));
129 dummyDesc.fFlags = kNone_GrTextureFlags;
97 dummyDesc.fConfig = kAlpha_8_GrPixelConfig; 130 dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
98 dummyDesc.fWidth = 16; 131 dummyDesc.fWidth = 16;
99 dummyDesc.fHeight = 22; 132 dummyDesc.fHeight = 22;
100 SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0 )); 133 SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0 ));
101 134
102 static const int NUM_TESTS = 512; 135 static const int NUM_TESTS = 512;
103 136
104 SkMWCRandom random; 137 SkMWCRandom random;
105 for (int t = 0; t < NUM_TESTS; ++t) { 138 for (int t = 0; t < NUM_TESTS; ++t) {
106 139
107 #if 0 140 #if 0
108 GrPrintf("\nTest Program %d\n-------------\n", t); 141 GrPrintf("\nTest Program %d\n-------------\n", t);
109 static const int stop = -1; 142 static const int stop = -1;
110 if (t == stop) { 143 if (t == stop) {
111 int breakpointhere = 9; 144 int breakpointhere = 9;
112 } 145 }
113 #endif 146 #endif
114 147
115 GrGLProgramDesc pdesc; 148 GrGLProgramDesc pdesc;
116 const GrEffectStage* stages[GrDrawState::kNumStages];
117 memset(stages, 0, sizeof(stages));
118 149
119 int currAttribIndex = 1; // we need to always leave room for position 150 int currAttribIndex = 1; // we need to always leave room for position
120 int attribIndices[2]; 151 int attribIndices[2];
121 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; 152 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
122 for (int s = 0; s < maxStages; ++s) {
123 // enable the stage?
124 if (random.nextBool()) {
125 SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::Crea teStage(
126 &random,
127 this->getContext(),
128 *this->caps(),
129 dummyTextures));
130 int numAttribs = (*effect)->numVertexAttribs();
131 153
132 // If adding this effect would exceed the max attrib count then generate a 154 int numStages = random.nextULessThan(maxStages + 1);
133 // new random effect. 155 int numColorStages = random.nextULessThan(numStages + 1);
134 if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttrib Cnt) { 156 int numCoverageStages = numStages - numColorStages;
135 --s; 157
136 continue; 158 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages);
137 } 159
138 for (int i = 0; i < numAttribs; ++i) { 160 for (int s = 0; s < numStages; ++s) {
139 attribIndices[i] = currAttribIndex++; 161 SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::CreateSt age(
140 } 162 &ran dom,
141 GrEffectStage* stage = SkNEW(GrEffectStage); 163 this ->getContext(),
142 stage->setEffect(effect.get(), attribIndices[0], attribIndices[1 ]); 164 *thi s->caps(),
143 stages[s] = stage; 165 dumm yTextures));
166 int numAttribs = (*effect)->numVertexAttribs();
167
168 // If adding this effect would exceed the max attrib count then gene rate a
169 // new random effect.
170 if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttribCnt) {
171 --s;
172 continue;
144 } 173 }
174 for (int i = 0; i < numAttribs; ++i) {
175 attribIndices[i] = currAttribIndex++;
176 }
177 GrEffectStage* stage = SkNEW(GrEffectStage);
178 stage->setEffect(effect.get(), attribIndices[0], attribIndices[1]);
179 stages[s] = stage;
145 } 180 }
146 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum myTextures[1]; 181 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum myTextures[1];
147 pdesc.setRandom(&random, this, dstTexture, stages, currAttribIndex); 182 pdesc.setRandom(&random,
183 this,
184 dummyTextures[0]->asRenderTarget(),
185 dstTexture,
186 stages.get(),
187 numColorStages,
188 numCoverageStages,
189 currAttribIndex);
148 190
149 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(), 191 SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(),
150 pdesc, 192 pdesc,
151 stages)); 193 stages.get()));
152 for (int s = 0; s < maxStages; ++s) { 194 for (int s = 0; s < numStages; ++s) {
153 SkDELETE(stages[s]); 195 SkDELETE(stages[s]);
154 } 196 }
155 if (NULL == program.get()) { 197 if (NULL == program.get()) {
156 return false; 198 return false;
157 } 199 }
158 } 200 }
159 return true; 201 return true;
160 } 202 }
161 203
162 static void GLProgramsTest(skiatest::Reporter* reporter, GrContextFactory* facto ry) { 204 static void GLProgramsTest(skiatest::Reporter* reporter, GrContextFactory* facto ry) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar 1); 237 SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar 1);
196 GrConfigConversionEffect::Create(NULL, 238 GrConfigConversionEffect::Create(NULL,
197 false, 239 false,
198 GrConfigConversionEffect::kNone_PMConversio n, 240 GrConfigConversionEffect::kNone_PMConversio n,
199 SkMatrix::I()); 241 SkMatrix::I());
200 SkScalar matrix[20]; 242 SkScalar matrix[20];
201 SkColorMatrixFilter cmf(matrix); 243 SkColorMatrixFilter cmf(matrix);
202 } 244 }
203 245
204 #endif 246 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL_program.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698