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)."); |
Chris Dalton | 15f5184 | 2020-12-15 19:55:10 -0700 | [diff] [blame] | 23 | static DEFINE_bool(hwtess, false, "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 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 28 | static DEFINE_string(pr, "", |
| 29 | "Set of enabled gpu path renderers. Defined as a list of: " |
Robert Phillips | 84fd1c2 | 2021-03-23 13:18:36 -0400 | [diff] [blame] | 30 | "[~]none [~]dashline [~]ccpr [~]aahairline [~]aaconvex [~]aalinearizing " |
Chris Dalton | eae5c16 | 2020-12-29 10:18:21 -0700 | [diff] [blame] | 31 | "[~]small [~]tri [~]tess [~]all"); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 32 | |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 33 | static DEFINE_int(internalSamples, 4, "Number of samples for internal draws that use MSAA."); |
Chris Dalton | 5258623 | 2019-12-27 13:47:25 -0700 | [diff] [blame] | 34 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 35 | static DEFINE_bool(disableDriverCorrectnessWorkarounds, false, |
| 36 | "Disables all GPU driver correctness workarounds"); |
| 37 | |
Adlai Holler | d37a085 | 2021-04-22 11:08:12 -0400 | [diff] [blame] | 38 | static DEFINE_bool(dontReduceOpsTaskSplitting, false, |
| 39 | "Don't reorder tasks to reduce render passes"); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 40 | |
Adlai Holler | 8e2a8b2 | 2021-04-14 11:52:25 -0400 | [diff] [blame] | 41 | static DEFINE_int(gpuResourceCacheLimit, -1, |
| 42 | "Maximum number of bytes to use for budgeted GPU resources. " |
| 43 | "Default is -1, which means GrResourceCache::kDefaultMaxSize."); |
| 44 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 45 | static GpuPathRenderers get_named_pathrenderers_flags(const char* name) { |
| 46 | if (!strcmp(name, "none")) { |
| 47 | return GpuPathRenderers::kNone; |
| 48 | } else if (!strcmp(name, "dashline")) { |
| 49 | return GpuPathRenderers::kDashLine; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 50 | } else if (!strcmp(name, "ccpr")) { |
| 51 | return GpuPathRenderers::kCoverageCounting; |
| 52 | } else if (!strcmp(name, "aahairline")) { |
| 53 | return GpuPathRenderers::kAAHairline; |
| 54 | } else if (!strcmp(name, "aaconvex")) { |
| 55 | return GpuPathRenderers::kAAConvex; |
| 56 | } else if (!strcmp(name, "aalinearizing")) { |
| 57 | return GpuPathRenderers::kAALinearizing; |
| 58 | } else if (!strcmp(name, "small")) { |
| 59 | return GpuPathRenderers::kSmall; |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 60 | } else if (!strcmp(name, "tri")) { |
| 61 | return GpuPathRenderers::kTriangulating; |
Chris Dalton | eae5c16 | 2020-12-29 10:18:21 -0700 | [diff] [blame] | 62 | } else if (!strcmp(name, "tess")) { |
| 63 | return GpuPathRenderers::kTessellation; |
Chris Dalton | 37ae4b0 | 2019-12-28 14:51:11 -0700 | [diff] [blame] | 64 | } else if (!strcmp(name, "default")) { |
| 65 | return GpuPathRenderers::kDefault; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 66 | } |
John Stiles | 616da10 | 2020-06-12 14:07:41 -0400 | [diff] [blame] | 67 | SK_ABORT("error: unknown named path renderer \"%s\"\n", name); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static GpuPathRenderers collect_gpu_path_renderers_from_flags() { |
| 71 | if (FLAGS_pr.isEmpty()) { |
Chris Dalton | 37ae4b0 | 2019-12-28 14:51:11 -0700 | [diff] [blame] | 72 | return GpuPathRenderers::kDefault; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 73 | } |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 74 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 75 | GpuPathRenderers gpuPathRenderers = ('~' == FLAGS_pr[0][0]) |
Chris Dalton | 37ae4b0 | 2019-12-28 14:51:11 -0700 | [diff] [blame] | 76 | ? GpuPathRenderers::kDefault |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 77 | : GpuPathRenderers::kNone; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 78 | |
| 79 | for (int i = 0; i < FLAGS_pr.count(); ++i) { |
| 80 | const char* name = FLAGS_pr[i]; |
| 81 | if (name[0] == '~') { |
| 82 | gpuPathRenderers &= ~get_named_pathrenderers_flags(&name[1]); |
| 83 | } else { |
| 84 | gpuPathRenderers |= get_named_pathrenderers_flags(name); |
| 85 | } |
| 86 | } |
| 87 | return gpuPathRenderers; |
| 88 | } |
| 89 | |
| 90 | void SetCtxOptionsFromCommonFlags(GrContextOptions* ctxOptions) { |
| 91 | static std::unique_ptr<SkExecutor> gGpuExecutor = (0 != FLAGS_gpuThreads) |
| 92 | ? SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads) |
| 93 | : nullptr; |
| 94 | |
| 95 | ctxOptions->fExecutor = gGpuExecutor.get(); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 96 | ctxOptions->fAllowPathMaskCaching = FLAGS_cachePathMasks; |
Chris Dalton | d1e6716 | 2020-09-23 11:55:27 -0600 | [diff] [blame] | 97 | ctxOptions->fAllPathsVolatile = FLAGS_allPathsVolatile; |
Chris Dalton | ed6e827 | 2020-04-23 11:44:26 -0600 | [diff] [blame] | 98 | ctxOptions->fSuppressGeometryShaders = !FLAGS_gs; |
Chris Dalton | 4ac9aad | 2021-02-24 17:41:44 -0700 | [diff] [blame] | 99 | ctxOptions->fEnableExperimentalHardwareTessellation = FLAGS_hwtess; |
Chris Dalton | 3163428 | 2020-09-17 12:16:54 -0600 | [diff] [blame] | 100 | ctxOptions->fMaxTessellationSegmentsOverride = FLAGS_maxTessellationSegments; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 101 | ctxOptions->fGpuPathRenderers = collect_gpu_path_renderers_from_flags(); |
Chris Dalton | 5258623 | 2019-12-27 13:47:25 -0700 | [diff] [blame] | 102 | ctxOptions->fInternalMultisampleCount = FLAGS_internalSamples; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 103 | ctxOptions->fDisableDriverCorrectnessWorkarounds = FLAGS_disableDriverCorrectnessWorkarounds; |
Adlai Holler | 8e2a8b2 | 2021-04-14 11:52:25 -0400 | [diff] [blame] | 104 | ctxOptions->fResourceCacheLimitOverride = FLAGS_gpuResourceCacheLimit; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 105 | |
Adlai Holler | d37a085 | 2021-04-22 11:08:12 -0400 | [diff] [blame] | 106 | if (FLAGS_dontReduceOpsTaskSplitting) { |
Adlai Holler | 4d92e41 | 2021-04-20 15:47:59 +0000 | [diff] [blame] | 107 | ctxOptions->fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo; |
Adlai Holler | d37a085 | 2021-04-22 11:08:12 -0400 | [diff] [blame] | 108 | } else { |
| 109 | ctxOptions->fReduceOpsTaskSplitting = GrContextOptions::Enable::kYes; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 110 | } |
| 111 | } |