blob: 1ec6a7310e79b5b5f87d1e3e2044c739c9551672 [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/*
bsalomon98b33eb2014-10-15 11:05:26 -070027 * A dummy processor which just tries to insert a massive key and verify that it can retrieve the
joshualitt65171342014-10-09 07:25:36 -070028 * whole thing correctly
29 */
30static const uint32_t kMaxKeySize = 1024;
31
32class GLBigKeyProcessor;
33
34class BigKeyProcessor : public GrFragmentProcessor {
35public:
36 static GrFragmentProcessor* Create() {
bsalomon98b33eb2014-10-15 11:05:26 -070037 GR_CREATE_STATIC_PROCESSOR(gBigKeyProcessor, BigKeyProcessor, ())
joshualitt65171342014-10-09 07:25:36 -070038 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() { }
bsalomon0e08fc12014-10-15 08:19:04 -070051 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE { return true; }
joshualitt65171342014-10-09 07:25:36 -070052 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
bsalomond27726e2014-10-12 05:40:00 -0700114 SkAutoTUnref<GrTexture> texture(
115 gpu->getContext()->findAndRefTexture(texDesc, cacheId, &params));
116 if (!texture) {
117 texture.reset(gpu->getContext()->createTexture(&params, texDesc, cacheId, 0, 0));
118 if (!texture) {
joshualitt65171342014-10-09 07:25:36 -0700119 return NULL;
joshualittd9097592014-10-07 08:37:36 -0700120 }
joshualittd9097592014-10-07 08:37:36 -0700121 }
bsalomond27726e2014-10-12 05:40:00 -0700122 return SkRef(texture->asRenderTarget());
bsalomon@google.com91207482013-02-12 21:45:24 +0000123}
124
joshualitt249af152014-09-15 11:41:13 -0700125// TODO clean this up, we have to do this to test geometry processors but there has got to be
126// a better way. In the mean time, we actually fill out these generic vertex attribs below with
127// 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 -0700128// than two attributes. In addition, we 'pad' the below array with GPs up to 6 entries, 4 fixed
129// function vertex attributes and 2 GP custom attributes.
130GrVertexAttrib kGenericVertexAttribs[] = {
joshualitt249af152014-09-15 11:41:13 -0700131 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
joshualittb0a8a372014-09-23 09:50:21 -0700132 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding },
joshualitt65171342014-10-09 07:25:36 -0700133 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding },
134 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding },
135 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding },
joshualittb0a8a372014-09-23 09:50:21 -0700136 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding }
joshualitt249af152014-09-15 11:41:13 -0700137};
138
139/*
140 * convert sl type to vertexattrib type, not a complete implementation, only use for debugging
141 */
joshualitt65171342014-10-09 07:25:36 -0700142static GrVertexAttribType convert_sltype_to_attribtype(GrSLType type) {
joshualitt249af152014-09-15 11:41:13 -0700143 switch (type) {
144 case kFloat_GrSLType:
145 return kFloat_GrVertexAttribType;
146 case kVec2f_GrSLType:
147 return kVec2f_GrVertexAttribType;
148 case kVec3f_GrSLType:
149 return kVec3f_GrVertexAttribType;
150 case kVec4f_GrSLType:
151 return kVec4f_GrVertexAttribType;
152 default:
153 SkFAIL("Type isn't convertible");
154 return kFloat_GrVertexAttribType;
155 }
156}
joshualitt65171342014-10-09 07:25:36 -0700157// end test hack
joshualitt249af152014-09-15 11:41:13 -0700158
joshualitt65171342014-10-09 07:25:36 -0700159static void setup_random_ff_attribute(GrVertexAttribBinding binding, GrVertexAttribType type,
160 SkRandom* random, int* attribIndex, int* runningStride) {
161 if (random->nextBool()) {
162 kGenericVertexAttribs[*attribIndex].fType = type;
163 kGenericVertexAttribs[*attribIndex].fOffset = *runningStride;
164 kGenericVertexAttribs[*attribIndex].fBinding = binding;
165 *runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[(*attribIndex)++].fType);
166 }
167}
168
169static void set_random_gp(GrGpuGL* gpu, SkRandom* random, GrTexture* dummyTextures[]) {
170 GrProgramElementRef<const GrGeometryProcessor> gp(
171 GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random,
172 gpu->getContext(),
173 *gpu->caps(),
174 dummyTextures));
175 SkASSERT(gp);
176
177 // we have to set dummy vertex attributes, first we setup the fixed function attributes
178 // always leave the position attribute untouched in the array
179 int attribIndex = 1;
180 int runningStride = GrVertexAttribTypeSize(kGenericVertexAttribs[0].fType);
181
182 // local coords
183 setup_random_ff_attribute(kLocalCoord_GrVertexAttribBinding, kVec2f_GrVertexAttribType,
184 random, &attribIndex, &runningStride);
185
186 // color
187 setup_random_ff_attribute(kColor_GrVertexAttribBinding, kVec4f_GrVertexAttribType,
188 random, &attribIndex, &runningStride);
189
190 // coverage
191 setup_random_ff_attribute(kCoverage_GrVertexAttribBinding, kVec4f_GrVertexAttribType,
192 random, &attribIndex, &runningStride);
193
194 // Update the geometry processor attributes
195 const GrGeometryProcessor::VertexAttribArray& v = gp->getVertexAttribs();
196 int numGPAttribs = v.count();
197 SkASSERT(numGPAttribs <= GrGeometryProcessor::kMaxVertexAttribs &&
198 GrGeometryProcessor::kMaxVertexAttribs == 2);
199
200 // we actually can't overflow if kMaxVertexAttribs == 2, but GCC 4.8 wants more proof
201 int maxIndex = SK_ARRAY_COUNT(kGenericVertexAttribs);
202 for (int i = 0; i < numGPAttribs && i + attribIndex < maxIndex; i++) {
203 kGenericVertexAttribs[i + attribIndex].fType =
204 convert_sltype_to_attribtype(v[i].getType());
205 kGenericVertexAttribs[i + attribIndex].fOffset = runningStride;
206 kGenericVertexAttribs[i + attribIndex].fBinding = kGeometryProcessor_GrVertexAttribBinding;
207 runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[i + attribIndex].fType);
208 }
209
210 // update the vertex attributes with the ds
211 GrDrawState* ds = gpu->drawState();
212 ds->setVertexAttribs<kGenericVertexAttribs>(attribIndex + numGPAttribs, runningStride);
213 ds->setGeometryProcessor(gp);
214}
215
216static void set_random_color_coverage_stages(GrGpuGL* gpu,
217 int maxStages,
218 bool usePathRendering,
219 SkRandom* random,
220 GrTexture* dummyTextures[]) {
221 int numProcs = random->nextULessThan(maxStages + 1);
222 int numColorProcs = random->nextULessThan(numProcs + 1);
223
224 int currTextureCoordSet = 0;
225 for (int s = 0; s < numProcs;) {
226 GrProgramElementRef<GrFragmentProcessor> fp(
227 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(random,
228 gpu->getContext(),
229 *gpu->caps(),
230 dummyTextures));
231 SkASSERT(fp);
232
233 // don't add dst color reads to coverage stage
234 if (s >= numColorProcs && fp->willReadDstColor()) {
235 continue;
236 }
237
238 // If adding this effect would exceed the max texture coord set count then generate a
239 // new random effect.
240 if (usePathRendering && gpu->glPathRendering()->texturingMode() ==
241 GrGLPathRendering::FixedFunction_TexturingMode) {;
242 int numTransforms = fp->numTransforms();
243 if (currTextureCoordSet + numTransforms >
244 gpu->glCaps().maxFixedFunctionTextureCoords()) {
245 continue;
246 }
247 currTextureCoordSet += numTransforms;
248 }
249
250 // finally add the stage to the correct pipeline in the drawstate
251 GrDrawState* ds = gpu->drawState();
252 if (s < numColorProcs) {
253 ds->addColorProcessor(fp);
254 } else {
255 ds->addCoverageProcessor(fp);
256 }
257 ++s;
258 }
259}
260
261// There are only a few cases of random colors which interest us
262enum ColorMode {
263 kAllOnes_ColorMode,
264 kAllZeros_ColorMode,
265 kAlphaOne_ColorMode,
266 kRandom_ColorMode,
267 kLast_ColorMode = kRandom_ColorMode
268};
269
270static void set_random_color(GrGpuGL* gpu, SkRandom* random) {
271 ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1));
272 GrColor color;
273 switch (colorMode) {
274 case kAllOnes_ColorMode:
275 color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF);
276 break;
277 case kAllZeros_ColorMode:
278 color = GrColorPackRGBA(0, 0, 0, 0);
279 break;
280 case kAlphaOne_ColorMode:
281 color = GrColorPackRGBA(random->nextULessThan(256),
282 random->nextULessThan(256),
283 random->nextULessThan(256),
284 0xFF);
285 break;
286 case kRandom_ColorMode:
287 uint8_t alpha = random->nextULessThan(256);
288 color = GrColorPackRGBA(random->nextRangeU(0, alpha),
289 random->nextRangeU(0, alpha),
290 random->nextRangeU(0, alpha),
291 alpha);
292 break;
293 }
294 GrColorIsPMAssert(color);
295 gpu->drawState()->setColor(color);
296}
297
298// There are only a few cases of random coverages which interest us
299enum CoverageMode {
300 kZero_CoverageMode,
301 kFF_CoverageMode,
302 kRandom_CoverageMode,
303 kLast_CoverageMode = kRandom_CoverageMode
304};
305
306static void set_random_coverage(GrGpuGL* gpu, SkRandom* random) {
307 CoverageMode coverageMode = CoverageMode(random->nextULessThan(kLast_CoverageMode + 1));
308 uint8_t coverage;
309 switch (coverageMode) {
310 case kZero_CoverageMode:
311 coverage = 0;
312 break;
313 case kFF_CoverageMode:
314 coverage = 0xFF;
315 break;
316 case kRandom_CoverageMode:
317 coverage = uint8_t(random->nextU());
318 break;
319 }
320 gpu->drawState()->setCoverage(coverage);
321}
322
323static void set_random_hints(GrGpuGL* gpu, SkRandom* random) {
324 for (int i = 1; i <= GrDrawState::kLast_Hint; i <<= 1) {
325 gpu->drawState()->setHint(GrDrawState::Hints(i), random->nextBool());
326 }
327}
328
329static void set_random_state(GrGpuGL* gpu, SkRandom* random) {
330 int state = 0;
331 for (int i = 1; i <= GrDrawState::kLastPublicStateBit; i <<= 1) {
332 state |= random->nextBool() * i;
333 }
334 gpu->drawState()->enableState(state);
335}
336
337// this function will randomly pick non-self referencing blend modes
338static void set_random_blend_func(GrGpuGL* gpu, SkRandom* random) {
339 GrBlendCoeff src;
340 do {
341 src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPublicGrBlendCoeff));
342 } while (GrBlendCoeffRefsSrc(src));
343
344 GrBlendCoeff dst;
345 do {
346 dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPublicGrBlendCoeff));
347 } while (GrBlendCoeffRefsDst(dst));
348
349 gpu->drawState()->setBlendFunc(src, dst);
350}
351
352// right now, the only thing we seem to care about in drawState's stencil is 'doesWrite()'
353static void set_random_stencil(GrGpuGL* gpu, SkRandom* random) {
354 GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil,
355 kReplace_StencilOp,
356 kReplace_StencilOp,
357 kAlways_StencilFunc,
358 0xffff,
359 0xffff,
360 0xffff);
361 GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil,
362 kKeep_StencilOp,
363 kKeep_StencilOp,
364 kNever_StencilFunc,
365 0xffff,
366 0xffff,
367 0xffff);
368
369 if (random->nextBool()) {
370 gpu->drawState()->setStencil(kDoesWriteStencil);
371 } else {
372 gpu->drawState()->setStencil(kDoesNotWriteStencil);
373 }
374}
joshualitt249af152014-09-15 11:41:13 -0700375
bsalomon@google.com042a2862013-02-04 18:39:24 +0000376bool GrGpuGL::programUnitTest(int maxStages) {
joshualitt65171342014-10-09 07:25:36 -0700377 // setup dummy textures
bsalomon@google.comd4726202012-08-03 14:34:46 +0000378 GrTextureDesc dummyDesc;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000379 dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit;
bsalomon@google.comfec0bc32013-02-07 14:43:04 +0000380 dummyDesc.fConfig = kSkia8888_GrPixelConfig;
bsalomon@google.comd4726202012-08-03 14:34:46 +0000381 dummyDesc.fWidth = 34;
382 dummyDesc.fHeight = 18;
383 SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0));
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000384 dummyDesc.fFlags = kNone_GrTextureFlags;
bsalomon@google.comd4726202012-08-03 14:34:46 +0000385 dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
386 dummyDesc.fWidth = 16;
387 dummyDesc.fHeight = 22;
388 SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0));
389
bsalomone904c092014-07-17 10:50:59 -0700390 if (!dummyTexture1 || ! dummyTexture2) {
joshualitt65171342014-10-09 07:25:36 -0700391 SkDebugf("Could not allocate dummy textures");
bsalomone904c092014-07-17 10:50:59 -0700392 return false;
393 }
394
joshualitt65171342014-10-09 07:25:36 -0700395 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
396
397 // Setup texture cache id key
398 const GrCacheID::Domain glProgramsDomain = GrCacheID::GenerateDomain();
399 GrCacheID::Key key;
400 memset(&key, 0, sizeof(key));
401 key.fData32[0] = kRenderTargetWidth;
402 key.fData32[1] = kRenderTargetHeight;
403 GrCacheID glProgramsCacheID(glProgramsDomain, key);
404
405 // setup clip
406 SkRect screen =
407 SkRect::MakeWH(SkIntToScalar(kRenderTargetWidth), SkIntToScalar(kRenderTargetHeight));
408
409 SkClipStack stack;
410 stack.clipDevRect(screen, SkRegion::kReplace_Op, false);
411
412 // wrap the SkClipStack in a GrClipData
413 GrClipData clipData;
414 clipData.fClipStack = &stack;
415 this->setClip(&clipData);
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000416
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000417 SkRandom random;
joshualitt65171342014-10-09 07:25:36 -0700418 static const int NUM_TESTS = 512;
419 for (int t = 0; t < NUM_TESTS;) {
420 // setup random render target(can fail)
bsalomond27726e2014-10-12 05:40:00 -0700421 SkAutoTUnref<GrRenderTarget> rt(random_render_target(this, glProgramsCacheID, &random));
422 if (!rt) {
joshualitt65171342014-10-09 07:25:36 -0700423 SkDebugf("Could not allocate render target");
424 return false;
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000425 }
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