blob: 4f15944e75000fee16e47a7013eb83e368a53e2a [file] [log] [blame]
Mike Kleinc6142d82019-03-25 10:54:59 -05001/*
2 * Copyright 2014 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkExecutor.h"
9#include "include/gpu/GrContextOptions.h"
10#include "tools/flags/CommonFlags.h"
Mike Kleinc6142d82019-03-25 10:54:59 -050011
12DEFINE_int(gpuThreads,
13 2,
14 "Create this many extra threads to assist with GPU work, "
15 "including software path rendering. Defaults to two.");
16
17static DEFINE_bool(cachePathMasks, true,
18 "Allows path mask textures to be cached in GPU configs.");
19
Chris Daltoned6e8272020-04-23 11:44:26 -060020static DEFINE_bool(gs, true, "Enables support for geometry shaders (if hw allows).");
21static DEFINE_bool(ts, true, "Enables support for tessellation shaders (if hw allows.).");
Mike Kleinc6142d82019-03-25 10:54:59 -050022
Chris Daltona8fbeba2019-03-30 00:31:23 -060023static DEFINE_bool(cc, false, "Allow coverage counting shortcuts to render paths?");
24
Mike Kleinc6142d82019-03-25 10:54:59 -050025static DEFINE_string(pr, "",
26 "Set of enabled gpu path renderers. Defined as a list of: "
Chris Dalton0a22b1e2020-03-26 11:52:15 -060027 "[~]none [~]dashline [~]tess [~]nvpr [~]ccpr [~]aahairline [~]aaconvex "
28 "[~]aalinearizing [~]small [~]tri] [~]all");
Mike Kleinc6142d82019-03-25 10:54:59 -050029
Chris Dalton52586232019-12-27 13:47:25 -070030static DEFINE_int(internalSamples, 4,
31 "Number of samples for internal draws that use MSAA or mixed samples.");
32
Mike Kleinc6142d82019-03-25 10:54:59 -050033static DEFINE_bool(disableDriverCorrectnessWorkarounds, false,
34 "Disables all GPU driver correctness workarounds");
35
Greg Danielf41b2bd2019-08-22 16:19:24 -040036static DEFINE_bool(reduceOpsTaskSplitting, false, "Improve opsTask sorting");
37static DEFINE_bool(dontReduceOpsTaskSplitting, false, "Allow more opsTask splitting");
Mike Kleinc6142d82019-03-25 10:54:59 -050038
Mike Kleinc6142d82019-03-25 10:54:59 -050039static GpuPathRenderers get_named_pathrenderers_flags(const char* name) {
40 if (!strcmp(name, "none")) {
41 return GpuPathRenderers::kNone;
42 } else if (!strcmp(name, "dashline")) {
43 return GpuPathRenderers::kDashLine;
Chris Dalton0a22b1e2020-03-26 11:52:15 -060044 } else if (!strcmp(name, "tess")) {
45 return GpuPathRenderers::kTessellation;
Mike Kleinc6142d82019-03-25 10:54:59 -050046 } else if (!strcmp(name, "nvpr")) {
47 return GpuPathRenderers::kStencilAndCover;
48 } else if (!strcmp(name, "ccpr")) {
49 return GpuPathRenderers::kCoverageCounting;
50 } else if (!strcmp(name, "aahairline")) {
51 return GpuPathRenderers::kAAHairline;
52 } else if (!strcmp(name, "aaconvex")) {
53 return GpuPathRenderers::kAAConvex;
54 } else if (!strcmp(name, "aalinearizing")) {
55 return GpuPathRenderers::kAALinearizing;
56 } else if (!strcmp(name, "small")) {
57 return GpuPathRenderers::kSmall;
Chris Dalton17dc4182020-03-25 16:18:16 -060058 } else if (!strcmp(name, "tri")) {
59 return GpuPathRenderers::kTriangulating;
Chris Dalton37ae4b02019-12-28 14:51:11 -070060 } else if (!strcmp(name, "default")) {
61 return GpuPathRenderers::kDefault;
Mike Kleinc6142d82019-03-25 10:54:59 -050062 }
John Stiles616da102020-06-12 14:07:41 -040063 SK_ABORT("error: unknown named path renderer \"%s\"\n", name);
Mike Kleinc6142d82019-03-25 10:54:59 -050064}
65
66static GpuPathRenderers collect_gpu_path_renderers_from_flags() {
67 if (FLAGS_pr.isEmpty()) {
Chris Dalton37ae4b02019-12-28 14:51:11 -070068 return GpuPathRenderers::kDefault;
Mike Kleinc6142d82019-03-25 10:54:59 -050069 }
Chris Daltona8fbeba2019-03-30 00:31:23 -060070
Mike Kleinc6142d82019-03-25 10:54:59 -050071 GpuPathRenderers gpuPathRenderers = ('~' == FLAGS_pr[0][0])
Chris Dalton37ae4b02019-12-28 14:51:11 -070072 ? GpuPathRenderers::kDefault
Chris Daltona8fbeba2019-03-30 00:31:23 -060073 : GpuPathRenderers::kNone;
Mike Kleinc6142d82019-03-25 10:54:59 -050074
75 for (int i = 0; i < FLAGS_pr.count(); ++i) {
76 const char* name = FLAGS_pr[i];
77 if (name[0] == '~') {
78 gpuPathRenderers &= ~get_named_pathrenderers_flags(&name[1]);
79 } else {
80 gpuPathRenderers |= get_named_pathrenderers_flags(name);
81 }
82 }
83 return gpuPathRenderers;
84}
85
86void SetCtxOptionsFromCommonFlags(GrContextOptions* ctxOptions) {
87 static std::unique_ptr<SkExecutor> gGpuExecutor = (0 != FLAGS_gpuThreads)
88 ? SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads)
89 : nullptr;
90
91 ctxOptions->fExecutor = gGpuExecutor.get();
Chris Daltona8fbeba2019-03-30 00:31:23 -060092 ctxOptions->fDisableCoverageCountingPaths = !FLAGS_cc;
Mike Kleinc6142d82019-03-25 10:54:59 -050093 ctxOptions->fAllowPathMaskCaching = FLAGS_cachePathMasks;
Chris Daltoned6e8272020-04-23 11:44:26 -060094 ctxOptions->fSuppressGeometryShaders = !FLAGS_gs;
95 ctxOptions->fSuppressTessellationShaders = !FLAGS_ts;
Mike Kleinc6142d82019-03-25 10:54:59 -050096 ctxOptions->fGpuPathRenderers = collect_gpu_path_renderers_from_flags();
Chris Dalton52586232019-12-27 13:47:25 -070097 ctxOptions->fInternalMultisampleCount = FLAGS_internalSamples;
Mike Kleinc6142d82019-03-25 10:54:59 -050098 ctxOptions->fDisableDriverCorrectnessWorkarounds = FLAGS_disableDriverCorrectnessWorkarounds;
99
Greg Danielf41b2bd2019-08-22 16:19:24 -0400100 if (FLAGS_reduceOpsTaskSplitting) {
101 SkASSERT(!FLAGS_dontReduceOpsTaskSplitting);
Greg Daniel93138742019-08-22 17:15:39 -0400102 ctxOptions->fReduceOpsTaskSplitting = GrContextOptions::Enable::kYes;
Greg Danielf41b2bd2019-08-22 16:19:24 -0400103 } else if (FLAGS_dontReduceOpsTaskSplitting) {
Greg Daniel93138742019-08-22 17:15:39 -0400104 ctxOptions->fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
Mike Kleinc6142d82019-03-25 10:54:59 -0500105 }
106}