blob: 75032bdbe6a168b8b0a3daba063b0c9794823711 [file] [log] [blame]
bsalomon@google.coma8e686e2011-08-16 15:45:58 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
bsalomon@google.comd4726202012-08-03 14:34:46 +00009// This is a GPU-backend specific test. It relies on static intializers to work
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000010
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000011#include "SkTypes.h"
12
13#if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
14
joshualitt65171342014-10-09 07:25:36 -070015#include "GrTBackendProcessorFactory.h"
bsalomon@google.com67b915d2013-02-04 16:13:32 +000016#include "GrContextFactory.h"
egdanielc0648242014-09-22 13:17:02 -070017#include "GrOptDrawState.h"
bsalomon@google.coma04e8e82012-08-27 12:53:13 +000018#include "effects/GrConfigConversionEffect.h"
joshualitt47bb3822014-10-07 16:43:25 -070019#include "gl/builders/GrGLProgramBuilder.h"
kkinnunenec56e452014-08-25 22:21:16 -070020#include "gl/GrGLPathRendering.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000021#include "gl/GrGpuGL.h"
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000022#include "SkChecksum.h"
tfarina@chromium.org223137f2012-11-21 22:38:36 +000023#include "SkRandom.h"
bsalomon@google.comc3841b92012-08-02 18:11:43 +000024#include "Test.h"
25
joshualitt65171342014-10-09 07:25:36 -070026/*
27 * A dummy effect which just tries to insert a massive key and verify that it can retrieve the
28 * whole thing correctly
29 */
30static const uint32_t kMaxKeySize = 1024;
31
32class GLBigKeyProcessor;
33
34class BigKeyProcessor : public GrFragmentProcessor {
35public:
36 static GrFragmentProcessor* Create() {
37 GR_CREATE_STATIC_FRAGMENT_PROCESSOR(gBigKeyProcessor, BigKeyProcessor, ())
38 return SkRef(gBigKeyProcessor);
joshualittbd769d02014-09-04 08:56:46 -070039 }
joshualitt65171342014-10-09 07:25:36 -070040
41 static const char* Name() { return "Big ol' Key"; }
42
43 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE {
44 return GrTBackendFragmentProcessorFactory<BigKeyProcessor>::getInstance();
joshualittd9097592014-10-07 08:37:36 -070045 }
joshualitt65171342014-10-09 07:25:36 -070046
47 typedef GLBigKeyProcessor GLProcessor;
48
49private:
50 BigKeyProcessor() { }
51 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE { return true; }
52 virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { }
53
54 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
55
56 typedef GrFragmentProcessor INHERITED;
57};
58
59GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor);
60
61GrFragmentProcessor* BigKeyProcessor::TestCreate(SkRandom*,
62 GrContext*,
63 const GrDrawTargetCaps&,
64 GrTexture*[]) {
65 return BigKeyProcessor::Create();
joshualittd9097592014-10-07 08:37:36 -070066}
67
joshualitt65171342014-10-09 07:25:36 -070068class GLBigKeyProcessor : public GrGLFragmentProcessor {
69public:
70 GLBigKeyProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
71 : INHERITED(factory) {}
joshualittd9097592014-10-07 08:37:36 -070072
joshualitt15988992014-10-09 15:04:05 -070073 virtual void emitCode(GrGLFPBuilder* builder,
joshualitt65171342014-10-09 07:25:36 -070074 const GrFragmentProcessor& fp,
75 const GrProcessorKey& key,
76 const char* outputColor,
77 const char* inputColor,
78 const TransformedCoordsArray&,
79 const TextureSamplerArray&) {
80 for (uint32_t i = 0; i < kMaxKeySize; i++) {
81 SkASSERT(key.get32(i) == i);
joshualittd9097592014-10-07 08:37:36 -070082 }
joshualitt65171342014-10-09 07:25:36 -070083 }
84
85 static void GenKey(const GrProcessor& processor, const GrGLCaps&, GrProcessorKeyBuilder* b) {
86 for (uint32_t i = 0; i < kMaxKeySize; i++) {
87 b->add32(i);
joshualittd9097592014-10-07 08:37:36 -070088 }
joshualittd9097592014-10-07 08:37:36 -070089 }
90
joshualitt65171342014-10-09 07:25:36 -070091private:
92 typedef GrGLFragmentProcessor INHERITED;
93};
94
95/*
96 * Begin test code
97 */
98static const int kRenderTargetHeight = 1;
99static const int kRenderTargetWidth = 1;
100
101static GrRenderTarget* random_render_target(GrGpuGL* gpu,
102 const GrCacheID& cacheId,
103 SkRandom* random) {
104 // setup render target
105 GrTextureParams params;
106 GrTextureDesc texDesc;
107 texDesc.fWidth = kRenderTargetWidth;
108 texDesc.fHeight = kRenderTargetHeight;
109 texDesc.fFlags = kRenderTarget_GrTextureFlagBit;
110 texDesc.fConfig = kRGBA_8888_GrPixelConfig;
111 texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin :
112 kBottomLeft_GrSurfaceOrigin;
113
114 GrTexture* texture = gpu->getContext()->findAndRefTexture(texDesc, cacheId, &params);
115 if (NULL == texture) {
116 texture = gpu->getContext()->createTexture(&params, texDesc, cacheId, 0, 0);
117 if (NULL == texture) {
118 return NULL;
joshualittd9097592014-10-07 08:37:36 -0700119 }
joshualittd9097592014-10-07 08:37:36 -0700120 }
joshualitt65171342014-10-09 07:25:36 -0700121 return texture->asRenderTarget();
bsalomon@google.com91207482013-02-12 21:45:24 +0000122}
123
joshualitt249af152014-09-15 11:41:13 -0700124// TODO clean this up, we have to do this to test geometry processors but there has got to be
125// a better way. In the mean time, we actually fill out these generic vertex attribs below with
126// the correct vertex attribs from the GP. We have to ensure, however, we don't try to add more
joshualitt65171342014-10-09 07:25:36 -0700127// than two attributes. In addition, we 'pad' the below array with GPs up to 6 entries, 4 fixed
128// function vertex attributes and 2 GP custom attributes.
129GrVertexAttrib kGenericVertexAttribs[] = {
joshualitt249af152014-09-15 11:41:13 -0700130 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
joshualittb0a8a372014-09-23 09:50:21 -0700131 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding },
joshualitt65171342014-10-09 07:25:36 -0700132 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding },
133 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding },
134 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding },
joshualittb0a8a372014-09-23 09:50:21 -0700135 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding }
joshualitt249af152014-09-15 11:41:13 -0700136};
137
138/*
139 * convert sl type to vertexattrib type, not a complete implementation, only use for debugging
140 */
joshualitt65171342014-10-09 07:25:36 -0700141static GrVertexAttribType convert_sltype_to_attribtype(GrSLType type) {
joshualitt249af152014-09-15 11:41:13 -0700142 switch (type) {
143 case kFloat_GrSLType:
144 return kFloat_GrVertexAttribType;
145 case kVec2f_GrSLType:
146 return kVec2f_GrVertexAttribType;
147 case kVec3f_GrSLType:
148 return kVec3f_GrVertexAttribType;
149 case kVec4f_GrSLType:
150 return kVec4f_GrVertexAttribType;
151 default:
152 SkFAIL("Type isn't convertible");
153 return kFloat_GrVertexAttribType;
154 }
155}
joshualitt65171342014-10-09 07:25:36 -0700156// end test hack
joshualitt249af152014-09-15 11:41:13 -0700157
joshualitt65171342014-10-09 07:25:36 -0700158static void setup_random_ff_attribute(GrVertexAttribBinding binding, GrVertexAttribType type,
159 SkRandom* random, int* attribIndex, int* runningStride) {
160 if (random->nextBool()) {
161 kGenericVertexAttribs[*attribIndex].fType = type;
162 kGenericVertexAttribs[*attribIndex].fOffset = *runningStride;
163 kGenericVertexAttribs[*attribIndex].fBinding = binding;
164 *runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[(*attribIndex)++].fType);
165 }
166}
167
168static void set_random_gp(GrGpuGL* gpu, SkRandom* random, GrTexture* dummyTextures[]) {
169 GrProgramElementRef<const GrGeometryProcessor> gp(
170 GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random,
171 gpu->getContext(),
172 *gpu->caps(),
173 dummyTextures));
174 SkASSERT(gp);
175
176 // we have to set dummy vertex attributes, first we setup the fixed function attributes
177 // always leave the position attribute untouched in the array
178 int attribIndex = 1;
179 int runningStride = GrVertexAttribTypeSize(kGenericVertexAttribs[0].fType);
180
181 // local coords
182 setup_random_ff_attribute(kLocalCoord_GrVertexAttribBinding, kVec2f_GrVertexAttribType,
183 random, &attribIndex, &runningStride);
184
185 // color
186 setup_random_ff_attribute(kColor_GrVertexAttribBinding, kVec4f_GrVertexAttribType,
187 random, &attribIndex, &runningStride);
188
189 // coverage
190 setup_random_ff_attribute(kCoverage_GrVertexAttribBinding, kVec4f_GrVertexAttribType,
191 random, &attribIndex, &runningStride);
192
193 // Update the geometry processor attributes
194 const GrGeometryProcessor::VertexAttribArray& v = gp->getVertexAttribs();
195 int numGPAttribs = v.count();
196 SkASSERT(numGPAttribs <= GrGeometryProcessor::kMaxVertexAttribs &&
197 GrGeometryProcessor::kMaxVertexAttribs == 2);
198
199 // we actually can't overflow if kMaxVertexAttribs == 2, but GCC 4.8 wants more proof
200 int maxIndex = SK_ARRAY_COUNT(kGenericVertexAttribs);
201 for (int i = 0; i < numGPAttribs && i + attribIndex < maxIndex; i++) {
202 kGenericVertexAttribs[i + attribIndex].fType =
203 convert_sltype_to_attribtype(v[i].getType());
204 kGenericVertexAttribs[i + attribIndex].fOffset = runningStride;
205 kGenericVertexAttribs[i + attribIndex].fBinding = kGeometryProcessor_GrVertexAttribBinding;
206 runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[i + attribIndex].fType);
207 }
208
209 // update the vertex attributes with the ds
210 GrDrawState* ds = gpu->drawState();
211 ds->setVertexAttribs<kGenericVertexAttribs>(attribIndex + numGPAttribs, runningStride);
212 ds->setGeometryProcessor(gp);
213}
214
215static void set_random_color_coverage_stages(GrGpuGL* gpu,
216 int maxStages,
217 bool usePathRendering,
218 SkRandom* random,
219 GrTexture* dummyTextures[]) {
220 int numProcs = random->nextULessThan(maxStages + 1);
221 int numColorProcs = random->nextULessThan(numProcs + 1);
222
223 int currTextureCoordSet = 0;
224 for (int s = 0; s < numProcs;) {
225 GrProgramElementRef<GrFragmentProcessor> fp(
226 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(random,
227 gpu->getContext(),
228 *gpu->caps(),
229 dummyTextures));
230 SkASSERT(fp);
231
232 // don't add dst color reads to coverage stage
233 if (s >= numColorProcs && fp->willReadDstColor()) {
234 continue;
235 }
236
237 // If adding this effect would exceed the max texture coord set count then generate a
238 // new random effect.
239 if (usePathRendering && gpu->glPathRendering()->texturingMode() ==
240 GrGLPathRendering::FixedFunction_TexturingMode) {;
241 int numTransforms = fp->numTransforms();
242 if (currTextureCoordSet + numTransforms >
243 gpu->glCaps().maxFixedFunctionTextureCoords()) {
244 continue;
245 }
246 currTextureCoordSet += numTransforms;
247 }
248
249 // finally add the stage to the correct pipeline in the drawstate
250 GrDrawState* ds = gpu->drawState();
251 if (s < numColorProcs) {
252 ds->addColorProcessor(fp);
253 } else {
254 ds->addCoverageProcessor(fp);
255 }
256 ++s;
257 }
258}
259
260// There are only a few cases of random colors which interest us
261enum ColorMode {
262 kAllOnes_ColorMode,
263 kAllZeros_ColorMode,
264 kAlphaOne_ColorMode,
265 kRandom_ColorMode,
266 kLast_ColorMode = kRandom_ColorMode
267};
268
269static void set_random_color(GrGpuGL* gpu, SkRandom* random) {
270 ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1));
271 GrColor color;
272 switch (colorMode) {
273 case kAllOnes_ColorMode:
274 color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF);
275 break;
276 case kAllZeros_ColorMode:
277 color = GrColorPackRGBA(0, 0, 0, 0);
278 break;
279 case kAlphaOne_ColorMode:
280 color = GrColorPackRGBA(random->nextULessThan(256),
281 random->nextULessThan(256),
282 random->nextULessThan(256),
283 0xFF);
284 break;
285 case kRandom_ColorMode:
286 uint8_t alpha = random->nextULessThan(256);
287 color = GrColorPackRGBA(random->nextRangeU(0, alpha),
288 random->nextRangeU(0, alpha),
289 random->nextRangeU(0, alpha),
290 alpha);
291 break;
292 }
293 GrColorIsPMAssert(color);
294 gpu->drawState()->setColor(color);
295}
296
297// There are only a few cases of random coverages which interest us
298enum CoverageMode {
299 kZero_CoverageMode,
300 kFF_CoverageMode,
301 kRandom_CoverageMode,
302 kLast_CoverageMode = kRandom_CoverageMode
303};
304
305static void set_random_coverage(GrGpuGL* gpu, SkRandom* random) {
306 CoverageMode coverageMode = CoverageMode(random->nextULessThan(kLast_CoverageMode + 1));
307 uint8_t coverage;
308 switch (coverageMode) {
309 case kZero_CoverageMode:
310 coverage = 0;
311 break;
312 case kFF_CoverageMode:
313 coverage = 0xFF;
314 break;
315 case kRandom_CoverageMode:
316 coverage = uint8_t(random->nextU());
317 break;
318 }
319 gpu->drawState()->setCoverage(coverage);
320}
321
322static void set_random_hints(GrGpuGL* gpu, SkRandom* random) {
323 for (int i = 1; i <= GrDrawState::kLast_Hint; i <<= 1) {
324 gpu->drawState()->setHint(GrDrawState::Hints(i), random->nextBool());
325 }
326}
327
328static void set_random_state(GrGpuGL* gpu, SkRandom* random) {
329 int state = 0;
330 for (int i = 1; i <= GrDrawState::kLastPublicStateBit; i <<= 1) {
331 state |= random->nextBool() * i;
332 }
333 gpu->drawState()->enableState(state);
334}
335
336// this function will randomly pick non-self referencing blend modes
337static void set_random_blend_func(GrGpuGL* gpu, SkRandom* random) {
338 GrBlendCoeff src;
339 do {
340 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPublicGrBlendCoeff));
341 } while (GrBlendCoeffRefsSrc(src));
342
343 GrBlendCoeff dst;
344 do {
345 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPublicGrBlendCoeff));
346 } while (GrBlendCoeffRefsDst(dst));
347
348 gpu->drawState()->setBlendFunc(src, dst);
349}
350
351// right now, the only thing we seem to care about in drawState's stencil is 'doesWrite()'
352static void set_random_stencil(GrGpuGL* gpu, SkRandom* random) {
353 GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil,
354 kReplace_StencilOp,
355 kReplace_StencilOp,
356 kAlways_StencilFunc,
357 0xffff,
358 0xffff,
359 0xffff);
360 GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil,
361 kKeep_StencilOp,
362 kKeep_StencilOp,
363 kNever_StencilFunc,
364 0xffff,
365 0xffff,
366 0xffff);
367
368 if (random->nextBool()) {
369 gpu->drawState()->setStencil(kDoesWriteStencil);
370 } else {
371 gpu->drawState()->setStencil(kDoesNotWriteStencil);
372 }
373}
joshualitt249af152014-09-15 11:41:13 -0700374
bsalomon@google.com042a2862013-02-04 18:39:24 +0000375bool GrGpuGL::programUnitTest(int maxStages) {
joshualitt65171342014-10-09 07:25:36 -0700376 // setup dummy textures
bsalomon@google.comd4726202012-08-03 14:34:46 +0000377 GrTextureDesc dummyDesc;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000378 dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit;
bsalomon@google.comfec0bc32013-02-07 14:43:04 +0000379 dummyDesc.fConfig = kSkia8888_GrPixelConfig;
bsalomon@google.comd4726202012-08-03 14:34:46 +0000380 dummyDesc.fWidth = 34;
381 dummyDesc.fHeight = 18;
382 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0));
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000383 dummyDesc.fFlags = kNone_GrTextureFlags;
bsalomon@google.comd4726202012-08-03 14:34:46 +0000384 dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
385 dummyDesc.fWidth = 16;
386 dummyDesc.fHeight = 22;
387 SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0));
388
bsalomone904c092014-07-17 10:50:59 -0700389 if (!dummyTexture1 || ! dummyTexture2) {
joshualitt65171342014-10-09 07:25:36 -0700390 SkDebugf("Could not allocate dummy textures");
bsalomone904c092014-07-17 10:50:59 -0700391 return false;
392 }
393
joshualitt65171342014-10-09 07:25:36 -0700394 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
395
396 // Setup texture cache id key
397 const GrCacheID::Domain glProgramsDomain = GrCacheID::GenerateDomain();
398 GrCacheID::Key key;
399 memset(&key, 0, sizeof(key));
400 key.fData32[0] = kRenderTargetWidth;
401 key.fData32[1] = kRenderTargetHeight;
402 GrCacheID glProgramsCacheID(glProgramsDomain, key);
403
404 // setup clip
405 SkRect screen =
406 SkRect::MakeWH(SkIntToScalar(kRenderTargetWidth), SkIntToScalar(kRenderTargetHeight));
407
408 SkClipStack stack;
409 stack.clipDevRect(screen, SkRegion::kReplace_Op, false);
410
411 // wrap the SkClipStack in a GrClipData
412 GrClipData clipData;
413 clipData.fClipStack = &stack;
414 this->setClip(&clipData);
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000415
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000416 SkRandom random;
joshualitt65171342014-10-09 07:25:36 -0700417 static const int NUM_TESTS = 512;
418 for (int t = 0; t < NUM_TESTS;) {
419 // setup random render target(can fail)
420 GrRenderTarget* rtPtr = random_render_target(this, glProgramsCacheID, &random);
421 if (!rtPtr) {
422 SkDebugf("Could not allocate render target");
423 return false;
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000424 }
joshualitt65171342014-10-09 07:25:36 -0700425 GrTGpuResourceRef<GrRenderTarget> rt(SkRef(rtPtr), kWrite_GrIOType);
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000426
joshualitt65171342014-10-09 07:25:36 -0700427 GrDrawState* ds = this->drawState();
428 ds->setRenderTarget(rt.get());
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000429
joshualitt65171342014-10-09 07:25:36 -0700430 // if path rendering we have to setup a couple of things like the draw type
egdanielae444962014-09-22 12:29:52 -0700431 bool usePathRendering = this->glCaps().pathRenderingSupport() && random.nextBool();
egdanielc0648242014-09-22 13:17:02 -0700432
egdanielae444962014-09-22 12:29:52 -0700433 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType :
434 GrGpu::kDrawPoints_DrawType;
commit-bot@chromium.org8e919ad2013-10-21 14:48:23 +0000435
joshualitt65171342014-10-09 07:25:36 -0700436 // twiddle drawstate knobs randomly
egdanielae444962014-09-22 12:29:52 -0700437 bool hasGeometryProcessor = usePathRendering ? false : random.nextBool();
joshualittbd769d02014-09-04 08:56:46 -0700438 if (hasGeometryProcessor) {
joshualitt65171342014-10-09 07:25:36 -0700439 set_random_gp(this, &random, dummyTextures);
joshualittd9097592014-10-07 08:37:36 -0700440 }
joshualitt65171342014-10-09 07:25:36 -0700441 set_random_color_coverage_stages(this, maxStages - hasGeometryProcessor, usePathRendering,
442 &random, dummyTextures);
443 set_random_color(this, &random);
444 set_random_coverage(this, &random);
445 set_random_hints(this, &random);
446 set_random_state(this, &random);
447 set_random_blend_func(this, &random);
448 set_random_stencil(this, &random);
joshualittd9097592014-10-07 08:37:36 -0700449
joshualitt65171342014-10-09 07:25:36 -0700450 // create optimized draw state, setup readDst texture if required, and build a descriptor
451 // and program. ODS creation can fail, so we have to check
452 SkAutoTUnref<GrOptDrawState> ods(GrOptDrawState::Create(this->getDrawState(),
453 *this->caps(),
454 drawType));
455 if (!ods.get()) {
456 ds->reset();
457 continue;
joshualittd9097592014-10-07 08:37:36 -0700458 }
joshualitt65171342014-10-09 07:25:36 -0700459 GrGLProgramDesc desc;
460 GrDeviceCoordTexture dstCopy;
461
462 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) {
463 SkDebugf("Couldn't setup dst read texture");
bsalomon848faf02014-07-11 10:01:02 -0700464 return false;
465 }
joshualitt65171342014-10-09 07:25:36 -0700466 if (!GrGLProgramDesc::Build(*ods,
467 drawType,
joshualitt65171342014-10-09 07:25:36 -0700468 this,
469 dstCopy.texture() ? &dstCopy : NULL,
joshualitt65171342014-10-09 07:25:36 -0700470 &desc)) {
471 SkDebugf("Failed to generate GL program descriptor");
472 return false;
joshualittd9097592014-10-07 08:37:36 -0700473 }
joshualitta5305a12014-10-10 17:47:00 -0700474 SkAutoTUnref<GrGLProgram> program(
475 GrGLProgramBuilder::CreateProgram(*ods, desc, drawType, this));
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000476 if (NULL == program.get()) {
joshualitt65171342014-10-09 07:25:36 -0700477 SkDebugf("Failed to create program!");
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000478 return false;
479 }
joshualitt249af152014-09-15 11:41:13 -0700480
481 // We have to reset the drawstate because we might have added a gp
joshualitt65171342014-10-09 07:25:36 -0700482 ds->reset();
483
484 // because occasionally optimized drawstate creation will fail for valid reasons, we only
485 // want to increment on success
486 ++t;
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000487 }
488 return true;
489}
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000490
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +0000491DEF_GPUTEST(GLPrograms, reporter, factory) {
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000492 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
493 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type));
bsalomon49f085d2014-09-05 13:34:00 -0700494 if (context) {
bsalomon@google.com042a2862013-02-04 18:39:24 +0000495 GrGpuGL* gpu = static_cast<GrGpuGL*>(context->getGpu());
joshualitt9e87fa72014-10-09 13:12:35 -0700496
497 /*
498 * For the time being, we only support the test with desktop GL or for android on
499 * ARM platforms
500 * TODO When we run ES 3.00 GLSL in more places, test again
501 */
502 int maxStages;
503 if (kGL_GrGLStandard == gpu->glStandard() ||
504 kARM_GrGLVendor == gpu->ctxInfo().vendor()) {
505 maxStages = 6;
506 } else if (kTegra3_GrGLRenderer == gpu->ctxInfo().renderer() ||
507 kOther_GrGLRenderer == gpu->ctxInfo().renderer()) {
508 maxStages = 1;
509 } else {
510 return;
511 }
bsalomon@google.com042a2862013-02-04 18:39:24 +0000512#if SK_ANGLE
513 // Some long shaders run out of temporary registers in the D3D compiler on ANGLE.
514 if (type == GrContextFactory::kANGLE_GLContextType) {
515 maxStages = 3;
516 }
517#endif
518 REPORTER_ASSERT(reporter, gpu->programUnitTest(maxStages));
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000519 }
520 }
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000521}
522
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000523#endif