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

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