blob: dd98a6e00ee81311dc0f69374ad8e182e7feabe3 [file] [log] [blame]
bsalomon@google.coma8e686e2011-08-16 15:45:58 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
bsalomon@google.comd4726202012-08-03 14:34:46 +00008// This is a GPU-backend specific test. It relies on static intializers to work
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00009
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000010#include "SkTypes.h"
11
12#if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
13
bsalomon6f7f2012015-03-16 14:00:52 -070014#include "GrAutoLocaleSetter.h"
bsalomon@google.com67b915d2013-02-04 16:13:32 +000015#include "GrContextFactory.h"
csmartdaltonbde96c62016-08-31 12:54:46 -070016#include "GrContextPriv.h"
Brian Salomon5ec9def2016-12-20 15:34:05 -050017#include "GrDrawOpTest.h"
robertphillipsa13e2022015-11-11 12:01:09 -080018#include "GrDrawingManager.h"
egdaniel8dd688b2015-01-22 10:16:09 -080019#include "GrPipeline.h"
Brian Salomon5ec9def2016-12-20 15:34:05 -050020#include "GrRenderTargetContextPriv.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
Brian Salomon89527432016-12-16 09:52:16 -050027#include "ops/GrDrawOp.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"
egdaniel64c47282015-11-13 06:54:19 -080034#include "glsl/GrGLSLFragmentProcessor.h"
egdaniel2d721d32015-11-11 13:06:05 -080035#include "glsl/GrGLSLFragmentShaderBuilder.h"
36#include "glsl/GrGLSLProgramBuilder.h"
bsalomon@google.comc3841b92012-08-02 18:11:43 +000037
joshualitt65171342014-10-09 07:25:36 -070038/*
bsalomon98b33eb2014-10-15 11:05:26 -070039 * A dummy processor which just tries to insert a massive key and verify that it can retrieve the
joshualitt65171342014-10-09 07:25:36 -070040 * whole thing correctly
41 */
42static const uint32_t kMaxKeySize = 1024;
43
egdaniel64c47282015-11-13 06:54:19 -080044class GLBigKeyProcessor : public GrGLSLFragmentProcessor {
joshualitt65171342014-10-09 07:25:36 -070045public:
robertphillips9cdb9922016-02-03 12:25:40 -080046 void emitCode(EmitArgs& args) override {
joshualitt6c891102015-05-13 08:51:49 -070047 // pass through
egdaniel4ca2e602015-11-18 08:01:26 -080048 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
bsalomonb5b60322015-09-14 12:26:33 -070049 if (args.fInputColor) {
egdaniel4ca2e602015-11-18 08:01:26 -080050 fragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor);
bsalomonb5b60322015-09-14 12:26:33 -070051 } else {
egdaniel4ca2e602015-11-18 08:01:26 -080052 fragBuilder->codeAppendf("%s = vec4(1.0);\n", args.fOutputColor);
bsalomonb5b60322015-09-14 12:26:33 -070053 }
joshualitt6c891102015-05-13 08:51:49 -070054 }
joshualitt65171342014-10-09 07:25:36 -070055
Brian Salomon94efbf52016-11-29 13:43:05 -050056 static void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder* b) {
joshualitt65171342014-10-09 07:25:36 -070057 for (uint32_t i = 0; i < kMaxKeySize; i++) {
58 b->add32(i);
joshualittd9097592014-10-07 08:37:36 -070059 }
joshualittd9097592014-10-07 08:37:36 -070060 }
61
joshualitt65171342014-10-09 07:25:36 -070062private:
egdaniel64c47282015-11-13 06:54:19 -080063 typedef GrGLSLFragmentProcessor INHERITED;
joshualitt65171342014-10-09 07:25:36 -070064};
65
joshualitteb2a6762014-12-04 11:35:33 -080066class BigKeyProcessor : public GrFragmentProcessor {
67public:
bungeman06ca8ec2016-06-09 08:01:03 -070068 static sk_sp<GrFragmentProcessor> Make() {
69 return sk_sp<GrFragmentProcessor>(new BigKeyProcessor);
joshualitteb2a6762014-12-04 11:35:33 -080070 }
71
mtklein36352bf2015-03-25 18:17:31 -070072 const char* name() const override { return "Big Ole Key"; }
joshualitteb2a6762014-12-04 11:35:33 -080073
egdaniel57d3b032015-11-13 11:57:27 -080074 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
robertphillips9cdb9922016-02-03 12:25:40 -080075 return new GLBigKeyProcessor;
joshualitteb2a6762014-12-04 11:35:33 -080076 }
77
78private:
Brian Salomon587e08f2017-01-27 10:59:27 -050079 BigKeyProcessor() : INHERITED(kNone_OptimizationFlags) { this->initClassID<BigKeyProcessor>(); }
Brian Salomon94efbf52016-11-29 13:43:05 -050080 virtual void onGetGLSLProcessorKey(const GrShaderCaps& caps,
egdaniel57d3b032015-11-13 11:57:27 -080081 GrProcessorKeyBuilder* b) const override {
wangyix4b3050b2015-08-04 07:59:37 -070082 GLBigKeyProcessor::GenKey(*this, caps, b);
83 }
mtklein36352bf2015-03-25 18:17:31 -070084 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
joshualitteb2a6762014-12-04 11:35:33 -080085
Brian Salomon0c26a9d2017-07-06 10:09:38 -040086 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
joshualitteb2a6762014-12-04 11:35:33 -080087
88 typedef GrFragmentProcessor INHERITED;
89};
90
91GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor);
92
Hal Canary6f6961e2017-01-31 13:50:44 -050093#if GR_TEST_UTILS
bungeman06ca8ec2016-06-09 08:01:03 -070094sk_sp<GrFragmentProcessor> BigKeyProcessor::TestCreate(GrProcessorTestData*) {
95 return BigKeyProcessor::Make();
joshualitteb2a6762014-12-04 11:35:33 -080096}
Hal Canary6f6961e2017-01-31 13:50:44 -050097#endif
joshualitteb2a6762014-12-04 11:35:33 -080098
bsalomonb5b60322015-09-14 12:26:33 -070099//////////////////////////////////////////////////////////////////////////////
100
101class BlockInputFragmentProcessor : public GrFragmentProcessor {
102public:
bungeman06ca8ec2016-06-09 08:01:03 -0700103 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor> fp) {
104 return sk_sp<GrFragmentProcessor>(new BlockInputFragmentProcessor(fp));
bsalomonb5b60322015-09-14 12:26:33 -0700105 }
106
107 const char* name() const override { return "Block Input"; }
108
egdaniel57d3b032015-11-13 11:57:27 -0800109 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLFP; }
bsalomonb5b60322015-09-14 12:26:33 -0700110
111private:
egdaniel64c47282015-11-13 06:54:19 -0800112 class GLFP : public GrGLSLFragmentProcessor {
bsalomonb5b60322015-09-14 12:26:33 -0700113 public:
114 void emitCode(EmitArgs& args) override {
Ethan Nicholas2983f402017-05-08 09:36:08 -0400115 this->emitChild(0, args);
bsalomonb5b60322015-09-14 12:26:33 -0700116 }
117
118 private:
egdaniel64c47282015-11-13 06:54:19 -0800119 typedef GrGLSLFragmentProcessor INHERITED;
bsalomonb5b60322015-09-14 12:26:33 -0700120 };
121
Brian Salomon587e08f2017-01-27 10:59:27 -0500122 BlockInputFragmentProcessor(sk_sp<GrFragmentProcessor> child)
123 : INHERITED(kNone_OptimizationFlags) {
bsalomonb5b60322015-09-14 12:26:33 -0700124 this->initClassID<BlockInputFragmentProcessor>();
bungeman06ca8ec2016-06-09 08:01:03 -0700125 this->registerChildProcessor(std::move(child));
bsalomonb5b60322015-09-14 12:26:33 -0700126 }
127
Brian Salomon94efbf52016-11-29 13:43:05 -0500128 void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {}
bsalomonb5b60322015-09-14 12:26:33 -0700129
130 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
131
bsalomonb5b60322015-09-14 12:26:33 -0700132 typedef GrFragmentProcessor INHERITED;
133};
134
135//////////////////////////////////////////////////////////////////////////////
136
joshualitt65171342014-10-09 07:25:36 -0700137/*
138 * Begin test code
139 */
140static const int kRenderTargetHeight = 1;
141static const int kRenderTargetWidth = 1;
142
Brian Osman11052242016-10-27 14:47:55 -0400143static sk_sp<GrRenderTargetContext> random_render_target_context(GrContext* context,
144 SkRandom* random,
145 const GrCaps* caps) {
robertphillips82ec6e52016-05-19 14:01:05 -0700146 GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin
147 : kBottomLeft_GrSurfaceOrigin;
Greg Daniel81e7bf82017-07-19 14:47:42 -0400148 int sampleCnt = random->nextBool() ? caps->getSampleCount(4, kRGBA_8888_GrPixelConfig) : 0;
joshualitt6c891102015-05-13 08:51:49 -0700149
Robert Phillipsdd3b3f42017-04-24 10:57:28 -0400150 sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext(
Brian Osman11052242016-10-27 14:47:55 -0400151 SkBackingFit::kExact,
152 kRenderTargetWidth,
153 kRenderTargetHeight,
154 kRGBA_8888_GrPixelConfig,
155 nullptr,
156 sampleCnt,
157 origin));
158 return renderTargetContext;
bsalomon@google.com91207482013-02-12 21:45:24 +0000159}
160
Hal Canary6f6961e2017-01-31 13:50:44 -0500161#if GR_TEST_UTILS
robertphillips28a838e2016-06-23 14:07:00 -0700162static void set_random_xpf(GrPaint* paint, GrProcessorTestData* d) {
Brian Salomona1633922017-01-09 11:46:10 -0500163 paint->setXPFactory(GrXPFactoryTestFactory::Get(d));
egdanielc2304142014-12-11 13:15:13 -0800164}
165
bungeman06ca8ec2016-06-09 08:01:03 -0700166static sk_sp<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d,
167 int minLevels, int maxLevels) {
wangyix059dffa2015-09-10 06:57:05 -0700168 SkASSERT(1 <= minLevels);
169 SkASSERT(minLevels <= maxLevels);
170
171 // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate.
172 // If returning a leaf node, make sure that it doesn't have children (e.g. another
173 // GrComposeEffect)
174 const float terminateProbability = 0.3f;
175 if (1 == minLevels) {
176 bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminateProbability);
177 if (terminate) {
bungeman06ca8ec2016-06-09 08:01:03 -0700178 sk_sp<GrFragmentProcessor> fp;
wangyix059dffa2015-09-10 06:57:05 -0700179 while (true) {
Brian Salomon1c053642017-07-24 10:16:19 -0400180 fp = GrFragmentProcessorTestFactory::Make(d);
wangyix059dffa2015-09-10 06:57:05 -0700181 SkASSERT(fp);
182 if (0 == fp->numChildProcessors()) {
183 break;
184 }
wangyix059dffa2015-09-10 06:57:05 -0700185 }
186 return fp;
187 }
188 }
189 // If we didn't terminate, choose either the left or right subtree to fulfill
190 // the minLevels requirement of this tree; the other child can have as few levels as it wants.
Brian Salomona12c1532017-02-13 12:41:44 -0500191 // Also choose a random xfer mode.
wangyix059dffa2015-09-10 06:57:05 -0700192 if (minLevels > 1) {
193 --minLevels;
194 }
bungeman06ca8ec2016-06-09 08:01:03 -0700195 sk_sp<GrFragmentProcessor> minLevelsChild(create_random_proc_tree(d, minLevels, maxLevels - 1));
196 sk_sp<GrFragmentProcessor> otherChild(create_random_proc_tree(d, 1, maxLevels - 1));
Mike Reed7d954ad2016-10-28 15:42:34 -0400197 SkBlendMode mode = static_cast<SkBlendMode>(d->fRandom->nextRangeU(0,
Brian Salomona12c1532017-02-13 12:41:44 -0500198 (int)SkBlendMode::kLastMode));
bungeman06ca8ec2016-06-09 08:01:03 -0700199 sk_sp<GrFragmentProcessor> fp;
wangyix059dffa2015-09-10 06:57:05 -0700200 if (d->fRandom->nextF() < 0.5f) {
bungeman06ca8ec2016-06-09 08:01:03 -0700201 fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(minLevelsChild),
202 std::move(otherChild), mode);
wangyix059dffa2015-09-10 06:57:05 -0700203 SkASSERT(fp);
204 } else {
bungeman06ca8ec2016-06-09 08:01:03 -0700205 fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(otherChild),
206 std::move(minLevelsChild), mode);
wangyix059dffa2015-09-10 06:57:05 -0700207 SkASSERT(fp);
208 }
209 return fp;
210}
211
robertphillips28a838e2016-06-23 14:07:00 -0700212static void set_random_color_coverage_stages(GrPaint* paint,
213 GrProcessorTestData* d,
Greg Daniel78325c12017-06-19 16:39:13 -0400214 int maxStages,
215 int maxTreeLevels) {
wangyix059dffa2015-09-10 06:57:05 -0700216 // Randomly choose to either create a linear pipeline of procs or create one proc tree
217 const float procTreeProbability = 0.5f;
218 if (d->fRandom->nextF() < procTreeProbability) {
bungeman06ca8ec2016-06-09 08:01:03 -0700219 sk_sp<GrFragmentProcessor> fp(create_random_proc_tree(d, 2, maxTreeLevels));
Robert Phillips1c9686b2017-06-30 08:40:28 -0400220 if (fp) {
221 paint->addColorFragmentProcessor(std::move(fp));
222 }
wangyix059dffa2015-09-10 06:57:05 -0700223 } else {
224 int numProcs = d->fRandom->nextULessThan(maxStages + 1);
225 int numColorProcs = d->fRandom->nextULessThan(numProcs + 1);
joshualitt65171342014-10-09 07:25:36 -0700226
wangyix059dffa2015-09-10 06:57:05 -0700227 for (int s = 0; s < numProcs;) {
Brian Salomon1c053642017-07-24 10:16:19 -0400228 sk_sp<GrFragmentProcessor> fp(GrFragmentProcessorTestFactory::Make(d));
wangyix059dffa2015-09-10 06:57:05 -0700229 SkASSERT(fp);
230
231 // finally add the stage to the correct pipeline in the drawstate
232 if (s < numColorProcs) {
robertphillips28a838e2016-06-23 14:07:00 -0700233 paint->addColorFragmentProcessor(std::move(fp));
wangyix059dffa2015-09-10 06:57:05 -0700234 } else {
robertphillips28a838e2016-06-23 14:07:00 -0700235 paint->addCoverageFragmentProcessor(std::move(fp));
wangyix059dffa2015-09-10 06:57:05 -0700236 }
237 ++s;
joshualitt65171342014-10-09 07:25:36 -0700238 }
joshualitt65171342014-10-09 07:25:36 -0700239 }
240}
241
Brian Salomon17726632017-05-12 14:09:46 -0400242static void set_random_state(GrPaint* paint, SkRandom* random) {
robertphillips28a838e2016-06-23 14:07:00 -0700243 if (random->nextBool()) {
244 paint->setDisableOutputConversionToSRGB(true);
joshualitt65171342014-10-09 07:25:36 -0700245 }
robertphillips28a838e2016-06-23 14:07:00 -0700246 if (random->nextBool()) {
247 paint->setAllowSRGBInputs(true);
joshualitt6c891102015-05-13 08:51:49 -0700248 }
joshualitt65171342014-10-09 07:25:36 -0700249}
250
Hal Canary6f6961e2017-01-31 13:50:44 -0500251#endif
joshualitt249af152014-09-15 11:41:13 -0700252
Hal Canary6f6961e2017-01-31 13:50:44 -0500253#if !GR_TEST_UTILS
254bool GrDrawingManager::ProgramUnitTest(GrContext*, int) { return true; }
255#else
Greg Daniel78325c12017-06-19 16:39:13 -0400256bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int maxLevels) {
csmartdaltonbde96c62016-08-31 12:54:46 -0700257 GrDrawingManager* drawingManager = context->contextPriv().drawingManager();
robertphillipsa13e2022015-11-11 12:01:09 -0800258
Robert Phillipse78b7252017-04-06 07:59:41 -0400259 sk_sp<GrTextureProxy> proxies[2];
260
joshualitt65171342014-10-09 07:25:36 -0700261 // setup dummy textures
bsalomonf2703d82014-10-28 14:33:06 -0700262 GrSurfaceDesc dummyDesc;
bsalomonbea01502015-07-16 10:00:28 -0700263 dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
Robert Phillipse78b7252017-04-06 07:59:41 -0400264 dummyDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
Brian Osman777b5632016-10-14 09:16:21 -0400265 dummyDesc.fConfig = kRGBA_8888_GrPixelConfig;
bsalomon@google.comd4726202012-08-03 14:34:46 +0000266 dummyDesc.fWidth = 34;
267 dummyDesc.fHeight = 18;
Robert Phillipse78b7252017-04-06 07:59:41 -0400268 proxies[0] = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
269 dummyDesc, SkBudgeted::kNo, nullptr, 0);
bsalomonf2703d82014-10-28 14:33:06 -0700270 dummyDesc.fFlags = kNone_GrSurfaceFlags;
Robert Phillipse78b7252017-04-06 07:59:41 -0400271 dummyDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
bsalomon@google.comd4726202012-08-03 14:34:46 +0000272 dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
273 dummyDesc.fWidth = 16;
274 dummyDesc.fHeight = 22;
Robert Phillipse78b7252017-04-06 07:59:41 -0400275 proxies[1] = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
276 dummyDesc, SkBudgeted::kNo, nullptr, 0);
bsalomon@google.comd4726202012-08-03 14:34:46 +0000277
Robert Phillipse78b7252017-04-06 07:59:41 -0400278 if (!proxies[0] || !proxies[1]) {
joshualitt65171342014-10-09 07:25:36 -0700279 SkDebugf("Could not allocate dummy textures");
bsalomone904c092014-07-17 10:50:59 -0700280 return false;
281 }
282
joshualitt54e0c122014-11-19 09:38:51 -0800283 // dummy scissor state
bsalomon3e791242014-12-17 13:43:13 -0800284 GrScissorState scissor;
joshualitt54e0c122014-11-19 09:38:51 -0800285
Brian Osman9f772a42017-07-10 13:03:50 -0400286 SkRandom random;
bsalomonf3261af2016-04-05 10:57:13 -0700287 static const int NUM_TESTS = 1024;
joshualitt6c891102015-05-13 08:51:49 -0700288 for (int t = 0; t < NUM_TESTS; t++) {
joshualitt65171342014-10-09 07:25:36 -0700289 // setup random render target(can fail)
Brian Osman11052242016-10-27 14:47:55 -0400290 sk_sp<GrRenderTargetContext> renderTargetContext(random_render_target_context(
291 context, &random, context->caps()));
292 if (!renderTargetContext) {
293 SkDebugf("Could not allocate renderTargetContext");
joshualittf5883a62016-01-13 07:47:38 -0800294 return false;
295 }
robertphillips0dfa62c2015-11-16 06:23:31 -0800296
Brian Salomon17726632017-05-12 14:09:46 -0400297 GrPaint paint;
Robert Phillipse78b7252017-04-06 07:59:41 -0400298 GrProcessorTestData ptd(&random, context, renderTargetContext.get(), proxies);
Greg Daniel78325c12017-06-19 16:39:13 -0400299 set_random_color_coverage_stages(&paint, &ptd, maxStages, maxLevels);
Brian Salomon17726632017-05-12 14:09:46 -0400300 set_random_xpf(&paint, &ptd);
301 set_random_state(&paint, &random);
302 GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint));
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000303 }
joshualitt6c891102015-05-13 08:51:49 -0700304 // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes)
Robert Phillips7ee385e2017-03-30 08:02:11 -0400305 drawingManager->flush(nullptr);
bsalomonb5b60322015-09-14 12:26:33 -0700306
307 // Validate that GrFPs work correctly without an input.
Robert Phillipsdd3b3f42017-04-24 10:57:28 -0400308 sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext(
Brian Osman11052242016-10-27 14:47:55 -0400309 SkBackingFit::kExact,
310 kRenderTargetWidth,
311 kRenderTargetHeight,
312 kRGBA_8888_GrPixelConfig,
313 nullptr));
314 if (!renderTargetContext) {
315 SkDebugf("Could not allocate a renderTargetContext");
robertphillips82ec6e52016-05-19 14:01:05 -0700316 return false;
317 }
318
Brian Salomon1c053642017-07-24 10:16:19 -0400319 int fpFactoryCnt = GrFragmentProcessorTestFactory::Count();
bsalomonb5b60322015-09-14 12:26:33 -0700320 for (int i = 0; i < fpFactoryCnt; ++i) {
321 // Since FP factories internally randomize, call each 10 times.
322 for (int j = 0; j < 10; ++j) {
Robert Phillipse78b7252017-04-06 07:59:41 -0400323 GrProcessorTestData ptd(&random, context, renderTargetContext.get(), proxies);
bsalomonb5b60322015-09-14 12:26:33 -0700324
Brian Salomon17726632017-05-12 14:09:46 -0400325 GrPaint paint;
326 paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
Brian Salomon1c053642017-07-24 10:16:19 -0400327 sk_sp<GrFragmentProcessor> fp(GrFragmentProcessorTestFactory::MakeIdx(i, &ptd));
bungeman06ca8ec2016-06-09 08:01:03 -0700328 sk_sp<GrFragmentProcessor> blockFP(
329 BlockInputFragmentProcessor::Make(std::move(fp)));
Brian Salomon17726632017-05-12 14:09:46 -0400330 paint.addColorFragmentProcessor(std::move(blockFP));
331 GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint));
Robert Phillips7ee385e2017-03-30 08:02:11 -0400332 drawingManager->flush(nullptr);
bsalomonb5b60322015-09-14 12:26:33 -0700333 }
334 }
335
bsalomon@google.comc3841b92012-08-02 18:11:43 +0000336 return true;
337}
Hal Canary6f6961e2017-01-31 13:50:44 -0500338#endif
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000339
Greg Danield895ca62017-06-19 14:39:43 -0400340static int get_glprograms_max_stages(const sk_gpu_test::ContextInfo& ctxInfo) {
341 GrContext* context = ctxInfo.grContext();
kkinnunen3e980c32015-12-23 01:33:00 -0800342 GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu());
Brian Salomone334c592017-05-15 11:00:58 -0400343 int maxStages = 6;
344 if (kGLES_GrGLStandard == gpu->glStandard()) {
345 // We've had issues with driver crashes and HW limits being exceeded with many effects on
346 // Android devices. We have passes on ARM devices with the default number of stages.
347 // TODO When we run ES 3.00 GLSL in more places, test again
348#ifdef SK_BUILD_FOR_ANDROID
349 if (kARM_GrGLVendor != gpu->ctxInfo().vendor()) {
350 maxStages = 1;
351 }
kkinnunen3e980c32015-12-23 01:33:00 -0800352#endif
Brian Salomone334c592017-05-15 11:00:58 -0400353 // On iOS we can exceed the maximum number of varyings. http://skbug.com/6627.
Brian Osman4e1868c2017-05-26 15:56:32 -0400354#ifdef SK_BUILD_FOR_IOS
Brian Salomone334c592017-05-15 11:00:58 -0400355 maxStages = 3;
356#endif
357 }
Greg Danield895ca62017-06-19 14:39:43 -0400358 if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType ||
359 ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) {
360 // On Angle D3D we will hit a limit of out variables if we use too many stages.
361 maxStages = 3;
362 }
Brian Salomone334c592017-05-15 11:00:58 -0400363 return maxStages;
364}
365
Greg Daniel78325c12017-06-19 16:39:13 -0400366static int get_glprograms_max_levels(const sk_gpu_test::ContextInfo& ctxInfo) {
367 // A full tree with 5 levels (31 nodes) may cause a program that exceeds shader limits
368 // (e.g. uniform or varying limits); maxTreeLevels should be a number from 1 to 4 inclusive.
369 int maxTreeLevels = 4;
370 // On iOS we can exceed the maximum number of varyings. http://skbug.com/6627.
371#ifdef SK_BUILD_FOR_IOS
372 maxTreeLevels = 2;
373#endif
374 if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType ||
375 ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) {
376 // On Angle D3D we will hit a limit of out variables if we use too many stages.
377 maxTreeLevels = 2;
378 }
379 return maxTreeLevels;
380}
381
Brian Salomone334c592017-05-15 11:00:58 -0400382static void test_glprograms(skiatest::Reporter* reporter, const sk_gpu_test::ContextInfo& ctxInfo) {
Greg Danield895ca62017-06-19 14:39:43 -0400383 int maxStages = get_glprograms_max_stages(ctxInfo);
kkinnunen3e980c32015-12-23 01:33:00 -0800384 if (maxStages == 0) {
385 return;
386 }
Greg Daniel78325c12017-06-19 16:39:13 -0400387 int maxLevels = get_glprograms_max_levels(ctxInfo);
388 if (maxLevels == 0) {
389 return;
390 }
Brian Osman9f772a42017-07-10 13:03:50 -0400391
392 // Disable this test on ANGLE D3D9 configurations. We keep hitting a D3D compiler bug.
393 // See skbug.com/6842 and anglebug.com/2098
394 if (sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType == ctxInfo.type()) {
395 return;
396 }
397
Greg Daniel78325c12017-06-19 16:39:13 -0400398 REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest(ctxInfo.grContext(), maxStages,
399 maxLevels));
kkinnunen3e980c32015-12-23 01:33:00 -0800400}
401
402DEF_GPUTEST(GLPrograms, reporter, /*factory*/) {
bsalomon3318ee72015-03-16 11:56:29 -0700403 // Set a locale that would cause shader compilation to fail because of , as decimal separator.
404 // skbug 3330
405#ifdef SK_BUILD_FOR_WIN
406 GrAutoLocaleSetter als("sv-SE");
407#else
408 GrAutoLocaleSetter als("sv_SE.UTF-8");
409#endif
410
joshualitt6c891102015-05-13 08:51:49 -0700411 // We suppress prints to avoid spew
bsalomon682c2692015-05-22 14:01:46 -0700412 GrContextOptions opts;
joshualitt6c891102015-05-13 08:51:49 -0700413 opts.fSuppressPrints = true;
bsalomon3724e572016-03-30 18:56:19 -0700414 sk_gpu_test::GrContextFactory debugFactory(opts);
Brian Salomone334c592017-05-15 11:00:58 -0400415 skiatest::RunWithGPUTestContexts(test_glprograms, &skiatest::IsRenderingGLContextType, reporter,
416 &debugFactory);
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000417}
418
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000419#endif