blob: a22927ee43ff5c7b5adb6274924a1dc70ddba98e [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
bsalomon6f7f2012015-03-16 14:00:52 -070015#include "GrAutoLocaleSetter.h"
joshualitt6c891102015-05-13 08:51:49 -070016#include "GrBatchTest.h"
bsalomon@google.com67b915d2013-02-04 16:13:32 +000017#include "GrContextFactory.h"
egdaniel605dd0f2014-11-12 08:35:25 -080018#include "GrInvariantOutput.h"
egdaniel8dd688b2015-01-22 10:16:09 -080019#include "GrPipeline.h"
bsalomon4061b122015-05-29 10:26:19 -070020#include "GrResourceProvider.h"
joshualitt2c93efe2014-11-06 12:57:13 -080021#include "GrTest.h"
egdaniel95131432014-12-09 11:15:43 -080022#include "GrXferProcessor.h"
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000023#include "SkChecksum.h"
tfarina@chromium.org223137f2012-11-21 22:38:36 +000024#include "SkRandom.h"
bsalomon@google.comc3841b92012-08-02 18:11:43 +000025#include "Test.h"
joshualitt74417822015-08-07 11:42:16 -070026
bsalomon16b99132015-08-13 14:55:50 -070027#include "batches/GrDrawBatch.h"
joshualitt74417822015-08-07 11:42:16 -070028
joshualitt2c93efe2014-11-06 12:57:13 -080029#include "effects/GrConfigConversionEffect.h"
egdaniel95131432014-12-09 11:15:43 -080030#include "effects/GrPorterDuffXferProcessor.h"
wangyix059dffa2015-09-10 06:57:05 -070031#include "effects/GrXfermodeFragmentProcessor.h"
joshualitt74417822015-08-07 11:42:16 -070032
jvanverth39edf762014-12-22 11:44:19 -080033#include "gl/GrGLGpu.h"
joshualitt2c93efe2014-11-06 12:57:13 -080034#include "gl/GrGLPathRendering.h"
joshualitt2c93efe2014-11-06 12:57:13 -080035#include "gl/builders/GrGLProgramBuilder.h"
bsalomon@google.comc3841b92012-08-02 18:11:43 +000036
joshualitt65171342014-10-09 07:25:36 -070037/*
bsalomon98b33eb2014-10-15 11:05:26 -070038 * A dummy processor which just tries to insert a massive key and verify that it can retrieve the
joshualitt65171342014-10-09 07:25:36 -070039 * whole thing correctly
40 */
41static const uint32_t kMaxKeySize = 1024;
42
joshualitt65171342014-10-09 07:25:36 -070043class GLBigKeyProcessor : public GrGLFragmentProcessor {
44public:
joshualitteb2a6762014-12-04 11:35:33 -080045 GLBigKeyProcessor(const GrProcessor&) {}
joshualittd9097592014-10-07 08:37:36 -070046
wangyix7c157a92015-07-22 15:08:53 -070047 virtual void emitCode(EmitArgs& args) override {
joshualitt6c891102015-05-13 08:51:49 -070048 // pass through
wangyix7c157a92015-07-22 15:08:53 -070049 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
bsalomonb5b60322015-09-14 12:26:33 -070050 if (args.fInputColor) {
51 fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor);
52 } else {
53 fsBuilder->codeAppendf("%s = vec4(1.0);\n", args.fOutputColor);
54 }
joshualitt6c891102015-05-13 08:51:49 -070055 }
joshualitt65171342014-10-09 07:25:36 -070056
jvanverthcfc18862015-04-28 08:48:20 -070057 static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
joshualitt65171342014-10-09 07:25:36 -070058 for (uint32_t i = 0; i < kMaxKeySize; i++) {
59 b->add32(i);
joshualittd9097592014-10-07 08:37:36 -070060 }
joshualittd9097592014-10-07 08:37:36 -070061 }
62
joshualitt65171342014-10-09 07:25:36 -070063private:
64 typedef GrGLFragmentProcessor INHERITED;
65};
66
joshualitteb2a6762014-12-04 11:35:33 -080067class BigKeyProcessor : public GrFragmentProcessor {
68public:
69 static GrFragmentProcessor* Create() {
mdempsky38f1f6f2015-08-27 12:57:01 -070070 static BigKeyProcessor gBigKeyProcessor;
71 return SkRef(&gBigKeyProcessor);
joshualitteb2a6762014-12-04 11:35:33 -080072 }
73
mtklein36352bf2015-03-25 18:17:31 -070074 const char* name() const override { return "Big Ole Key"; }
joshualitteb2a6762014-12-04 11:35:33 -080075
wangyixb1daa862015-08-18 11:29:31 -070076 GrGLFragmentProcessor* onCreateGLInstance() const override {
halcanary385fe4d2015-08-26 13:07:48 -070077 return new GLBigKeyProcessor(*this);
joshualitteb2a6762014-12-04 11:35:33 -080078 }
79
80private:
81 BigKeyProcessor() {
82 this->initClassID<BigKeyProcessor>();
83 }
wangyix4b3050b2015-08-04 07:59:37 -070084 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps,
85 GrProcessorKeyBuilder* b) const override {
86 GLBigKeyProcessor::GenKey(*this, caps, b);
87 }
mtklein36352bf2015-03-25 18:17:31 -070088 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
89 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { }
joshualitteb2a6762014-12-04 11:35:33 -080090
91 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
92
93 typedef GrFragmentProcessor INHERITED;
94};
95
96GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor);
97
bsalomonc21b09e2015-08-28 18:46:56 -070098const GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) {
joshualitteb2a6762014-12-04 11:35:33 -080099 return BigKeyProcessor::Create();
100}
101
bsalomonb5b60322015-09-14 12:26:33 -0700102//////////////////////////////////////////////////////////////////////////////
103
104class BlockInputFragmentProcessor : public GrFragmentProcessor {
105public:
106 static GrFragmentProcessor* Create(const GrFragmentProcessor* fp) {
107 return new BlockInputFragmentProcessor(fp);
108 }
109
110 const char* name() const override { return "Block Input"; }
111
112 GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLFP; }
113
114private:
115 class GLFP : public GrGLFragmentProcessor {
116 public:
117 void emitCode(EmitArgs& args) override {
bsalomon38ddbad2015-09-24 06:00:00 -0700118 this->emitChild(0, nullptr, args);
bsalomonb5b60322015-09-14 12:26:33 -0700119 }
120
121 private:
122 typedef GrGLFragmentProcessor INHERITED;
123 };
124
125 BlockInputFragmentProcessor(const GrFragmentProcessor* child) {
126 this->initClassID<BlockInputFragmentProcessor>();
127 this->registerChildProcessor(child);
128 }
129
130 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {}
131
132 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
133
134 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
135 inout->setToOther(kRGBA_GrColorComponentFlags, GrColor_WHITE,
136 GrInvariantOutput::kWillNot_ReadInput);
137 this->childProcessor(0).computeInvariantOutput(inout);
138 }
139
140 typedef GrFragmentProcessor INHERITED;
141};
142
143//////////////////////////////////////////////////////////////////////////////
144
joshualitt65171342014-10-09 07:25:36 -0700145/*
146 * Begin test code
147 */
148static const int kRenderTargetHeight = 1;
149static const int kRenderTargetWidth = 1;
150
bsalomon4061b122015-05-29 10:26:19 -0700151static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider, SkRandom* random,
bsalomon4b91f762015-05-19 09:29:46 -0700152 const GrCaps* caps) {
joshualitt65171342014-10-09 07:25:36 -0700153 // setup render target
154 GrTextureParams params;
bsalomonf2703d82014-10-28 14:33:06 -0700155 GrSurfaceDesc texDesc;
joshualitt65171342014-10-09 07:25:36 -0700156 texDesc.fWidth = kRenderTargetWidth;
157 texDesc.fHeight = kRenderTargetHeight;
bsalomonf2703d82014-10-28 14:33:06 -0700158 texDesc.fFlags = kRenderTarget_GrSurfaceFlag;
joshualitt65171342014-10-09 07:25:36 -0700159 texDesc.fConfig = kRGBA_8888_GrPixelConfig;
160 texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin :
161 kBottomLeft_GrSurfaceOrigin;
joshualitt15732062015-05-13 12:15:14 -0700162 texDesc.fSampleCnt = random->nextBool() == true ? SkTMin(4, caps->maxSampleCount()) : 0;
joshualitt6c891102015-05-13 08:51:49 -0700163
bsalomon8718aaf2015-02-19 07:24:21 -0800164 GrUniqueKey key;
165 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
joshualitt6c891102015-05-13 08:51:49 -0700166 GrUniqueKey::Builder builder(&key, kDomain, 2);
bsalomon24db3b12015-01-23 04:24:04 -0800167 builder[0] = texDesc.fOrigin;
joshualitt6c891102015-05-13 08:51:49 -0700168 builder[1] = texDesc.fSampleCnt;
bsalomon24db3b12015-01-23 04:24:04 -0800169 builder.finish();
joshualitt65171342014-10-09 07:25:36 -0700170
bsalomon4061b122015-05-29 10:26:19 -0700171 GrTexture* texture = textureProvider->findAndRefTextureByUniqueKey(key);
bsalomond27726e2014-10-12 05:40:00 -0700172 if (!texture) {
bsalomon4061b122015-05-29 10:26:19 -0700173 texture = textureProvider->createTexture(texDesc, true);
bsalomon37f9a262015-02-02 13:00:10 -0800174 if (texture) {
bsalomon4061b122015-05-29 10:26:19 -0700175 textureProvider->assignUniqueKeyToTexture(key, texture);
joshualittd9097592014-10-07 08:37:36 -0700176 }
joshualittd9097592014-10-07 08:37:36 -0700177 }
halcanary96fcdcc2015-08-27 07:41:13 -0700178 return texture ? texture->asRenderTarget() : nullptr;
bsalomon@google.com91207482013-02-12 21:45:24 +0000179}
180
joshualitt0067ff52015-07-08 14:26:19 -0700181static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestData* d) {
bsalomonb5b60322015-09-14 12:26:33 -0700182 SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Create(d));
egdanielc2304142014-12-11 13:15:13 -0800183 SkASSERT(xpf);
egdaniel8dd688b2015-01-22 10:16:09 -0800184 pipelineBuilder->setXPFactory(xpf.get());
egdanielc2304142014-12-11 13:15:13 -0800185}
186
wangyix059dffa2015-09-10 06:57:05 -0700187static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d,
188 int minLevels, int maxLevels) {
189 SkASSERT(1 <= minLevels);
190 SkASSERT(minLevels <= maxLevels);
191
192 // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate.
193 // If returning a leaf node, make sure that it doesn't have children (e.g. another
194 // GrComposeEffect)
195 const float terminateProbability = 0.3f;
196 if (1 == minLevels) {
197 bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminateProbability);
198 if (terminate) {
199 const GrFragmentProcessor* fp;
200 while (true) {
bsalomonb5b60322015-09-14 12:26:33 -0700201 fp = GrProcessorTestFactory<GrFragmentProcessor>::Create(d);
wangyix059dffa2015-09-10 06:57:05 -0700202 SkASSERT(fp);
203 if (0 == fp->numChildProcessors()) {
204 break;
205 }
206 fp->unref();
207 }
208 return fp;
209 }
210 }
211 // If we didn't terminate, choose either the left or right subtree to fulfill
212 // the minLevels requirement of this tree; the other child can have as few levels as it wants.
213 // Also choose a random xfer mode that's supported by CreateFrom2Procs().
214 if (minLevels > 1) {
215 --minLevels;
216 }
217 SkAutoTUnref<const GrFragmentProcessor> minLevelsChild(create_random_proc_tree(d, minLevels,
218 maxLevels - 1));
219 SkAutoTUnref<const GrFragmentProcessor> otherChild(create_random_proc_tree(d, 1,
220 maxLevels - 1));
221 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(d->fRandom->nextRangeU(0,
222 SkXfermode::kLastCoeffMode));
223 const GrFragmentProcessor* fp;
224 if (d->fRandom->nextF() < 0.5f) {
225 fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(minLevelsChild, otherChild, mode);
226 SkASSERT(fp);
227 } else {
228 fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(otherChild, minLevelsChild, mode);
229 SkASSERT(fp);
230 }
231 return fp;
232}
233
joshualitt0067ff52015-07-08 14:26:19 -0700234static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder,
235 GrProcessorTestData* d, int maxStages) {
wangyix059dffa2015-09-10 06:57:05 -0700236 // Randomly choose to either create a linear pipeline of procs or create one proc tree
237 const float procTreeProbability = 0.5f;
238 if (d->fRandom->nextF() < procTreeProbability) {
239 // A full tree with 5 levels (31 nodes) may exceed the max allowed length of the gl
240 // processor key; maxTreeLevels should be a number from 1 to 4 inclusive.
241 const int maxTreeLevels = 4;
bsalomonae59b772014-11-19 08:23:49 -0800242 SkAutoTUnref<const GrFragmentProcessor> fp(
wangyix059dffa2015-09-10 06:57:05 -0700243 create_random_proc_tree(d, 2, maxTreeLevels));
244 pipelineBuilder->addColorFragmentProcessor(fp);
245 } else {
246 int numProcs = d->fRandom->nextULessThan(maxStages + 1);
247 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1);
joshualitt65171342014-10-09 07:25:36 -0700248
wangyix059dffa2015-09-10 06:57:05 -0700249 for (int s = 0; s < numProcs;) {
250 SkAutoTUnref<const GrFragmentProcessor> fp(
bsalomonae4738f2015-09-15 15:33:27 -0700251 GrProcessorTestFactory<GrFragmentProcessor>::Create(d));
wangyix059dffa2015-09-10 06:57:05 -0700252 SkASSERT(fp);
253
254 // finally add the stage to the correct pipeline in the drawstate
255 if (s < numColorProcs) {
256 pipelineBuilder->addColorFragmentProcessor(fp);
257 } else {
258 pipelineBuilder->addCoverageFragmentProcessor(fp);
259 }
260 ++s;
joshualitt65171342014-10-09 07:25:36 -0700261 }
joshualitt65171342014-10-09 07:25:36 -0700262 }
263}
264
egdaniel8dd688b2015-01-22 10:16:09 -0800265static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* random) {
joshualitt65171342014-10-09 07:25:36 -0700266 int state = 0;
bsalomond79c5492015-04-27 10:07:04 -0700267 for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) {
joshualitt65171342014-10-09 07:25:36 -0700268 state |= random->nextBool() * i;
269 }
joshualitt6c891102015-05-13 08:51:49 -0700270
271 // If we don't have an MSAA rendertarget then we have to disable useHWAA
272 if ((state | GrPipelineBuilder::kHWAntialias_Flag) &&
vbuzinovdded6962015-06-12 08:59:45 -0700273 !pipelineBuilder->getRenderTarget()->isUnifiedMultisampled()) {
joshualitt6c891102015-05-13 08:51:49 -0700274 state &= ~GrPipelineBuilder::kHWAntialias_Flag;
275 }
egdaniel8dd688b2015-01-22 10:16:09 -0800276 pipelineBuilder->enableState(state);
joshualitt65171342014-10-09 07:25:36 -0700277}
278
joshualitt65171342014-10-09 07:25:36 -0700279// right now, the only thing we seem to care about in drawState's stencil is 'doesWrite()'
egdaniel8dd688b2015-01-22 10:16:09 -0800280static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* random) {
joshualitt65171342014-10-09 07:25:36 -0700281 GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil,
282 kReplace_StencilOp,
283 kReplace_StencilOp,
284 kAlways_StencilFunc,
285 0xffff,
286 0xffff,
287 0xffff);
288 GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil,
289 kKeep_StencilOp,
290 kKeep_StencilOp,
291 kNever_StencilFunc,
292 0xffff,
293 0xffff,
294 0xffff);
295
296 if (random->nextBool()) {
egdaniel8dd688b2015-01-22 10:16:09 -0800297 pipelineBuilder->setStencil(kDoesWriteStencil);
joshualitt65171342014-10-09 07:25:36 -0700298 } else {
egdaniel8dd688b2015-01-22 10:16:09 -0800299 pipelineBuilder->setStencil(kDoesNotWriteStencil);
joshualitt65171342014-10-09 07:25:36 -0700300 }
301}
joshualitt249af152014-09-15 11:41:13 -0700302
bsalomon4061b122015-05-29 10:26:19 -0700303bool GrDrawTarget::programUnitTest(GrContext* context, int maxStages) {
joshualitt65171342014-10-09 07:25:36 -0700304 // setup dummy textures
bsalomonf2703d82014-10-28 14:33:06 -0700305 GrSurfaceDesc dummyDesc;
bsalomonbea01502015-07-16 10:00:28 -0700306 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
bsalomon@google.comfec0bc32013-02-07 14:43:04 +0000307 dummyDesc.fConfig = kSkia8888_GrPixelConfig;
bsalomon@google.comd4726202012-08-03 14:34:46 +0000308 dummyDesc.fWidth = 34;
309 dummyDesc.fHeight = 18;
bsalomon4061b122015-05-29 10:26:19 -0700310 SkAutoTUnref<GrTexture> dummyTexture1(
halcanary96fcdcc2015-08-27 07:41:13 -0700311 context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
bsalomonf2703d82014-10-28 14:33:06 -0700312 dummyDesc.fFlags = kNone_GrSurfaceFlags;
bsalomon@google.comd4726202012-08-03 14:34:46 +0000313 dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
314 dummyDesc.fWidth = 16;
315 dummyDesc.fHeight = 22;
bsalomon4061b122015-05-29 10:26:19 -0700316 SkAutoTUnref<GrTexture> dummyTexture2(
halcanary96fcdcc2015-08-27 07:41:13 -0700317 context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
bsalomon@google.comd4726202012-08-03 14:34:46 +0000318
bsalomone904c092014-07-17 10:50:59 -0700319 if (!dummyTexture1 || ! dummyTexture2) {
joshualitt65171342014-10-09 07:25:36 -0700320 SkDebugf("Could not allocate dummy textures");
bsalomone904c092014-07-17 10:50:59 -0700321 return false;
322 }
323
joshualitt65171342014-10-09 07:25:36 -0700324 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
325
joshualitt54e0c122014-11-19 09:38:51 -0800326 // dummy scissor state
bsalomon3e791242014-12-17 13:43:13 -0800327 GrScissorState scissor;
joshualitt54e0c122014-11-19 09:38:51 -0800328
joshualitt6c891102015-05-13 08:51:49 -0700329 // wide open clip
joshualitt44701df2015-02-23 14:44:57 -0800330 GrClip clip;
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000331
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000332 SkRandom random;
joshualitt6c891102015-05-13 08:51:49 -0700333 static const int NUM_TESTS = 2048;
334 for (int t = 0; t < NUM_TESTS; t++) {
joshualitt65171342014-10-09 07:25:36 -0700335 // setup random render target(can fail)
bsalomon4061b122015-05-29 10:26:19 -0700336 SkAutoTUnref<GrRenderTarget> rt(random_render_target(
bsalomoneae62002015-07-31 13:59:30 -0700337 context->textureProvider(), &random, this->caps()));
joshualitt2c93efe2014-11-06 12:57:13 -0800338 if (!rt.get()) {
joshualitt65171342014-10-09 07:25:36 -0700339 SkDebugf("Could not allocate render target");
340 return false;
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000341 }
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000342
egdaniel8dd688b2015-01-22 10:16:09 -0800343 GrPipelineBuilder pipelineBuilder;
344 pipelineBuilder.setRenderTarget(rt.get());
joshualitt44701df2015-02-23 14:44:57 -0800345 pipelineBuilder.setClip(clip);
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000346
bsalomonabd30f52015-08-13 13:34:48 -0700347 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
joshualitt6c891102015-05-13 08:51:49 -0700348 SkASSERT(batch);
egdanielc0648242014-09-22 13:17:02 -0700349
joshualitt9cc17752015-07-09 06:28:14 -0700350 GrProcessorDataManager procDataManager;
351 GrProcessorTestData ptd(&random, context, &procDataManager, fGpu->caps(), dummyTextures);
joshualitt0067ff52015-07-08 14:26:19 -0700352 set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages);
353 set_random_xpf(&pipelineBuilder, &ptd);
egdaniel8dd688b2015-01-22 10:16:09 -0800354 set_random_state(&pipelineBuilder, &random);
355 set_random_stencil(&pipelineBuilder, &random);
joshualittd9097592014-10-07 08:37:36 -0700356
joshualitt1c735482015-07-13 08:08:25 -0700357 this->drawBatch(pipelineBuilder, batch);
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000358 }
joshualitt6c891102015-05-13 08:51:49 -0700359 // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes)
360 this->flush();
bsalomonb5b60322015-09-14 12:26:33 -0700361
362 // Validate that GrFPs work correctly without an input.
363 GrSurfaceDesc rtDesc;
364 rtDesc.fWidth = kRenderTargetWidth;
365 rtDesc.fHeight = kRenderTargetHeight;
366 rtDesc.fFlags = kRenderTarget_GrSurfaceFlag;
367 rtDesc.fConfig = kRGBA_8888_GrPixelConfig;
368 SkAutoTUnref<GrRenderTarget> rt(
369 fContext->textureProvider()->createTexture(rtDesc, false)->asRenderTarget());
370 int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count();
371 for (int i = 0; i < fpFactoryCnt; ++i) {
372 // Since FP factories internally randomize, call each 10 times.
373 for (int j = 0; j < 10; ++j) {
374 SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
375 SkASSERT(batch);
376 GrProcessorDataManager procDataManager;
377 GrProcessorTestData ptd(&random, context, &procDataManager, this->caps(),
378 dummyTextures);
379 GrPipelineBuilder builder;
380 builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref();
381 builder.setRenderTarget(rt);
382 builder.setClip(clip);
383
384 SkAutoTUnref<const GrFragmentProcessor> fp(
385 GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd));
386 SkAutoTUnref<const GrFragmentProcessor> blockFP(
387 BlockInputFragmentProcessor::Create(fp));
388 builder.addColorFragmentProcessor(blockFP);
389
390 this->drawBatch(builder, batch);
391 this->flush();
392 }
393 }
394
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000395 return true;
396}
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000397
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +0000398DEF_GPUTEST(GLPrograms, reporter, factory) {
bsalomon3318ee72015-03-16 11:56:29 -0700399 // Set a locale that would cause shader compilation to fail because of , as decimal separator.
400 // skbug 3330
401#ifdef SK_BUILD_FOR_WIN
402 GrAutoLocaleSetter als("sv-SE");
403#else
404 GrAutoLocaleSetter als("sv_SE.UTF-8");
405#endif
406
joshualitt6c891102015-05-13 08:51:49 -0700407 // We suppress prints to avoid spew
bsalomon682c2692015-05-22 14:01:46 -0700408 GrContextOptions opts;
joshualitt6c891102015-05-13 08:51:49 -0700409 opts.fSuppressPrints = true;
410 GrContextFactory debugFactory(opts);
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000411 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
joshualitt6c891102015-05-13 08:51:49 -0700412 GrContext* context = debugFactory.get(static_cast<GrContextFactory::GLContextType>(type));
bsalomon49f085d2014-09-05 13:34:00 -0700413 if (context) {
bsalomon861e1032014-12-16 07:33:49 -0800414 GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu());
joshualitt9e87fa72014-10-09 13:12:35 -0700415
416 /*
417 * For the time being, we only support the test with desktop GL or for android on
418 * ARM platforms
419 * TODO When we run ES 3.00 GLSL in more places, test again
420 */
421 int maxStages;
422 if (kGL_GrGLStandard == gpu->glStandard() ||
423 kARM_GrGLVendor == gpu->ctxInfo().vendor()) {
424 maxStages = 6;
425 } else if (kTegra3_GrGLRenderer == gpu->ctxInfo().renderer() ||
426 kOther_GrGLRenderer == gpu->ctxInfo().renderer()) {
427 maxStages = 1;
428 } else {
429 return;
430 }
bsalomon@google.com042a2862013-02-04 18:39:24 +0000431#if SK_ANGLE
432 // Some long shaders run out of temporary registers in the D3D compiler on ANGLE.
433 if (type == GrContextFactory::kANGLE_GLContextType) {
egdaniel305a8892015-02-17 11:18:38 -0800434 maxStages = 2;
bsalomon@google.com042a2862013-02-04 18:39:24 +0000435 }
436#endif
hendrikw885bf092015-08-27 10:38:39 -0700437#if SK_COMMAND_BUFFER
438 // Some long shaders run out of temporary registers in the D3D compiler on ANGLE.
439 // TODO(hendrikw): This only needs to happen with the ANGLE comand buffer backend.
440 if (type == GrContextFactory::kCommandBuffer_GLContextType) {
441 maxStages = 2;
442 }
443#endif
joshualitt2c93efe2014-11-06 12:57:13 -0800444 GrTestTarget target;
445 context->getTestTarget(&target);
bsalomon4061b122015-05-29 10:26:19 -0700446 REPORTER_ASSERT(reporter, target.target()->programUnitTest(context, maxStages));
bsalomon@google.com67b915d2013-02-04 16:13:32 +0000447 }
448 }
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000449}
450
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000451#endif