Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkExecutor.h" |
| 9 | #include "include/gpu/GrContextOptions.h" |
| 10 | #include "tools/flags/CommonFlags.h" |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 11 | |
| 12 | DEFINE_int(gpuThreads, |
| 13 | 2, |
| 14 | "Create this many extra threads to assist with GPU work, " |
| 15 | "including software path rendering. Defaults to two."); |
| 16 | |
| 17 | static DEFINE_bool(cachePathMasks, true, |
| 18 | "Allows path mask textures to be cached in GPU configs."); |
Chris Dalton | d1e6716 | 2020-09-23 11:55:27 -0600 | [diff] [blame^] | 19 | static DEFINE_bool(allPathsVolatile, false, |
| 20 | "Causes all GPU paths to be processed as if 'setIsVolatile' had been called."); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 21 | |
Chris Dalton | ed6e827 | 2020-04-23 11:44:26 -0600 | [diff] [blame] | 22 | static DEFINE_bool(gs, true, "Enables support for geometry shaders (if hw allows)."); |
| 23 | static DEFINE_bool(ts, true, "Enables support for tessellation shaders (if hw allows.)."); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 24 | |
Chris Dalton | 3163428 | 2020-09-17 12:16:54 -0600 | [diff] [blame] | 25 | static DEFINE_int(maxTessellationSegments, 0, |
| 26 | "Overrides the max number of tessellation segments supported by the caps."); |
| 27 | |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 28 | static DEFINE_bool(cc, false, "Allow coverage counting shortcuts to render paths?"); |
| 29 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 30 | static DEFINE_string(pr, "", |
| 31 | "Set of enabled gpu path renderers. Defined as a list of: " |
Chris Dalton | 0a22b1e | 2020-03-26 11:52:15 -0600 | [diff] [blame] | 32 | "[~]none [~]dashline [~]tess [~]nvpr [~]ccpr [~]aahairline [~]aaconvex " |
| 33 | "[~]aalinearizing [~]small [~]tri] [~]all"); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 34 | |
Chris Dalton | 5258623 | 2019-12-27 13:47:25 -0700 | [diff] [blame] | 35 | static DEFINE_int(internalSamples, 4, |
| 36 | "Number of samples for internal draws that use MSAA or mixed samples."); |
| 37 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 38 | static DEFINE_bool(disableDriverCorrectnessWorkarounds, false, |
| 39 | "Disables all GPU driver correctness workarounds"); |
| 40 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 41 | static DEFINE_bool(reduceOpsTaskSplitting, false, "Improve opsTask sorting"); |
| 42 | static DEFINE_bool(dontReduceOpsTaskSplitting, false, "Allow more opsTask splitting"); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 43 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 44 | static GpuPathRenderers get_named_pathrenderers_flags(const char* name) { |
| 45 | if (!strcmp(name, "none")) { |
| 46 | return GpuPathRenderers::kNone; |
| 47 | } else if (!strcmp(name, "dashline")) { |
| 48 | return GpuPathRenderers::kDashLine; |
Chris Dalton | 0a22b1e | 2020-03-26 11:52:15 -0600 | [diff] [blame] | 49 | } else if (!strcmp(name, "tess")) { |
| 50 | return GpuPathRenderers::kTessellation; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 51 | } else if (!strcmp(name, "nvpr")) { |
| 52 | return GpuPathRenderers::kStencilAndCover; |
| 53 | } else if (!strcmp(name, "ccpr")) { |
| 54 | return GpuPathRenderers::kCoverageCounting; |
| 55 | } else if (!strcmp(name, "aahairline")) { |
| 56 | return GpuPathRenderers::kAAHairline; |
| 57 | } else if (!strcmp(name, "aaconvex")) { |
| 58 | return GpuPathRenderers::kAAConvex; |
| 59 | } else if (!strcmp(name, "aalinearizing")) { |
| 60 | return GpuPathRenderers::kAALinearizing; |
| 61 | } else if (!strcmp(name, "small")) { |
| 62 | return GpuPathRenderers::kSmall; |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 63 | } else if (!strcmp(name, "tri")) { |
| 64 | return GpuPathRenderers::kTriangulating; |
Chris Dalton | 37ae4b0 | 2019-12-28 14:51:11 -0700 | [diff] [blame] | 65 | } else if (!strcmp(name, "default")) { |
| 66 | return GpuPathRenderers::kDefault; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 67 | } |
John Stiles | 616da10 | 2020-06-12 14:07:41 -0400 | [diff] [blame] | 68 | SK_ABORT("error: unknown named path renderer \"%s\"\n", name); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static GpuPathRenderers collect_gpu_path_renderers_from_flags() { |
| 72 | if (FLAGS_pr.isEmpty()) { |
Chris Dalton | 37ae4b0 | 2019-12-28 14:51:11 -0700 | [diff] [blame] | 73 | return GpuPathRenderers::kDefault; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 74 | } |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 75 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 76 | GpuPathRenderers gpuPathRenderers = ('~' == FLAGS_pr[0][0]) |
Chris Dalton | 37ae4b0 | 2019-12-28 14:51:11 -0700 | [diff] [blame] | 77 | ? GpuPathRenderers::kDefault |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 78 | : GpuPathRenderers::kNone; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 79 | |
| 80 | for (int i = 0; i < FLAGS_pr.count(); ++i) { |
| 81 | const char* name = FLAGS_pr[i]; |
| 82 | if (name[0] == '~') { |
| 83 | gpuPathRenderers &= ~get_named_pathrenderers_flags(&name[1]); |
| 84 | } else { |
| 85 | gpuPathRenderers |= get_named_pathrenderers_flags(name); |
| 86 | } |
| 87 | } |
| 88 | return gpuPathRenderers; |
| 89 | } |
| 90 | |
| 91 | void SetCtxOptionsFromCommonFlags(GrContextOptions* ctxOptions) { |
| 92 | static std::unique_ptr<SkExecutor> gGpuExecutor = (0 != FLAGS_gpuThreads) |
| 93 | ? SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads) |
| 94 | : nullptr; |
| 95 | |
| 96 | ctxOptions->fExecutor = gGpuExecutor.get(); |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 97 | ctxOptions->fDisableCoverageCountingPaths = !FLAGS_cc; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 98 | ctxOptions->fAllowPathMaskCaching = FLAGS_cachePathMasks; |
Chris Dalton | d1e6716 | 2020-09-23 11:55:27 -0600 | [diff] [blame^] | 99 | ctxOptions->fAllPathsVolatile = FLAGS_allPathsVolatile; |
Chris Dalton | ed6e827 | 2020-04-23 11:44:26 -0600 | [diff] [blame] | 100 | ctxOptions->fSuppressGeometryShaders = !FLAGS_gs; |
| 101 | ctxOptions->fSuppressTessellationShaders = !FLAGS_ts; |
Chris Dalton | 3163428 | 2020-09-17 12:16:54 -0600 | [diff] [blame] | 102 | ctxOptions->fMaxTessellationSegmentsOverride = FLAGS_maxTessellationSegments; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 103 | ctxOptions->fGpuPathRenderers = collect_gpu_path_renderers_from_flags(); |
Chris Dalton | 5258623 | 2019-12-27 13:47:25 -0700 | [diff] [blame] | 104 | ctxOptions->fInternalMultisampleCount = FLAGS_internalSamples; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 105 | ctxOptions->fDisableDriverCorrectnessWorkarounds = FLAGS_disableDriverCorrectnessWorkarounds; |
| 106 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 107 | if (FLAGS_reduceOpsTaskSplitting) { |
| 108 | SkASSERT(!FLAGS_dontReduceOpsTaskSplitting); |
Greg Daniel | 9313874 | 2019-08-22 17:15:39 -0400 | [diff] [blame] | 109 | ctxOptions->fReduceOpsTaskSplitting = GrContextOptions::Enable::kYes; |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 110 | } else if (FLAGS_dontReduceOpsTaskSplitting) { |
Greg Daniel | 9313874 | 2019-08-22 17:15:39 -0400 | [diff] [blame] | 111 | ctxOptions->fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 112 | } |
| 113 | } |