| 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 |
|
| 8 |
#include "tools/flags/CommonFlagsGanesh.h" |
| 9 |
|
| 10 |
#include "include/core/SkExecutor.h" |
| 11 |
#include "include/gpu/ganesh/GrContextOptions.h" |
| 12 |
|
| 13 |
// Defined in CommonFlagsConfig |
| 14 |
DECLARE_int(gpuThreads) |
| 15 |
DECLARE_int(internalSamples) |
| 16 |
|
| 17 |
namespace CommonFlags { |
| 18 |
|
| 19 |
static DEFINE_bool(cachePathMasks, true, |
| 20 |
"Allows path mask textures to be cached in GPU configs."); |
| 21 |
static DEFINE_bool(failFlushTimeCallbacks, false, |
| 22 |
"Causes all flush-time callbacks to fail."); |
| 23 |
static DEFINE_bool(allPathsVolatile, false, |
| 24 |
"Causes all GPU paths to be processed as if 'setIsVolatile' had been called."); |
| 25 |
|
| 26 |
static DEFINE_string(pr, "", |
| 27 |
"Set of enabled gpu path renderers. Defined as a list of: " |
| 28 |
"[~]none [~]dashline [~]aahairline [~]aaconvex [~]aalinearizing [~]small [~]tri " |
| 29 |
"[~]atlas [~]tess [~]all"); |
| 30 |
|
| 31 |
static DEFINE_int(maxAtlasSize, -1, |
| 32 |
"Maximum width and height of internal texture atlases, or default value if negative."); |
| 33 |
|
| 34 |
static DEFINE_bool(disableDriverCorrectnessWorkarounds, false, |
| 35 |
"Disables all GPU driver correctness workarounds"); |
| 36 |
|
| 37 |
static DEFINE_bool(dontReduceOpsTaskSplitting, false, |
| 38 |
"Don't reorder tasks to reduce render passes"); |
| 39 |
|
| 40 |
static DEFINE_int(gpuResourceCacheLimit, -1, |
| 41 |
"Maximum number of bytes to use for budgeted GPU resources. " |
| 42 |
"Default is -1, which means GrResourceCache::kDefaultMaxSize."); |
| 43 |
|
| 44 |
static DEFINE_bool(allowMSAAOnNewIntel, false, |
| 45 |
"Allows MSAA to be enabled on newer intel GPUs."); |
| 46 |
|
| 47 |
static GpuPathRenderers get_named_pathrenderers_flags(const char* name) { |
| 48 |
if (!strcmp(name, "none")) { |
| 49 |
return GpuPathRenderers::kNone; |
| 50 |
} else if (!strcmp(name, "dashline")) { |
| 51 |
return GpuPathRenderers::kDashLine; |
| 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; |
| 60 |
} else if (!strcmp(name, "tri")) { |
| 61 |
return GpuPathRenderers::kTriangulating; |
| 62 |
} else if (!strcmp(name, "atlas")) { |
| 63 |
return GpuPathRenderers::kAtlas; |
| 64 |
} else if (!strcmp(name, "tess")) { |
| 65 |
return GpuPathRenderers::kTessellation; |
| 66 |
} else if (!strcmp(name, "default")) { |
| 67 |
return GpuPathRenderers::kDefault; |
| 68 |
} |
| 69 |
SK_ABORT("error: unknown named path renderer \"%s\"\n", name); |
| 70 |
} |
| 71 |
|
| 72 |
static GpuPathRenderers collect_gpu_path_renderers_from_flags() { |
| 73 |
if (FLAGS_pr.isEmpty()) { |
| 74 |
return GpuPathRenderers::kDefault; |
| 75 |
} |
| 76 |
|
| 77 |
GpuPathRenderers gpuPathRenderers = ('~' == FLAGS_pr[0][0]) |
| 78 |
? GpuPathRenderers::kDefault |
| 79 |
: GpuPathRenderers::kNone; |
| 80 |
|
| 81 |
for (int i = 0; i < FLAGS_pr.size(); ++i) { |
| 82 |
const char* name = FLAGS_pr[i]; |
| 83 |
if (name[0] == '~') { |
| 84 |
gpuPathRenderers &= ~get_named_pathrenderers_flags(&name[1]); |
| 85 |
} else { |
| 86 |
gpuPathRenderers |= get_named_pathrenderers_flags(name); |
| 87 |
} |
| 88 |
} |
| 89 |
return gpuPathRenderers; |
| 90 |
} |
| 91 |
|
| 92 |
void SetCtxOptions(GrContextOptions* ctxOptions) { |
| 93 |
static std::unique_ptr<SkExecutor> gGpuExecutor = (0 != FLAGS_gpuThreads) |
| 94 |
? SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads) |
| 95 |
: nullptr; |
| 96 |
|
| 97 |
ctxOptions->fExecutor = gGpuExecutor.get(); |
| 98 |
ctxOptions->fAllowPathMaskCaching = FLAGS_cachePathMasks; |
| 99 |
ctxOptions->fFailFlushTimeCallbacks = FLAGS_failFlushTimeCallbacks; |
| 100 |
ctxOptions->fAllPathsVolatile = FLAGS_allPathsVolatile; |
| 101 |
ctxOptions->fGpuPathRenderers = collect_gpu_path_renderers_from_flags(); |
| 102 |
ctxOptions->fDisableDriverCorrectnessWorkarounds = FLAGS_disableDriverCorrectnessWorkarounds; |
| 103 |
ctxOptions->fResourceCacheLimitOverride = FLAGS_gpuResourceCacheLimit; |
| 104 |
|
| 105 |
if (FLAGS_internalSamples >= 0) { |
| 106 |
ctxOptions->fInternalMultisampleCount = FLAGS_internalSamples; |
| 107 |
} |
| 108 |
if (FLAGS_maxAtlasSize >= 0) { |
| 109 |
ctxOptions->fMaxTextureAtlasSize = FLAGS_maxAtlasSize; |
| 110 |
} |
| 111 |
|
| 112 |
if (FLAGS_dontReduceOpsTaskSplitting) { |
| 113 |
ctxOptions->fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo; |
| 114 |
} else { |
| 115 |
ctxOptions->fReduceOpsTaskSplitting = GrContextOptions::Enable::kYes; |
| 116 |
} |
| 117 |
ctxOptions->fAllowMSAAOnNewIntel = FLAGS_allowMSAAOnNewIntel; |
| 118 |
} |
| 119 |
|
| 120 |
} // namespace CommonFlags |