blob: 0253a9c8d24c12b4f10245b7aa9c4c48d7f1d365 [file] [log] [blame]
John Stiles270cec22021-02-17 12:59:36 -05001/*
2 * Copyright 2016 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#ifndef SKSL_PROGRAMSETTINGS
9#define SKSL_PROGRAMSETTINGS
10
11#include "src/sksl/SkSLDefines.h"
12
13namespace SkSL {
14
15/**
16 * SkSL supports several different program kinds.
17 */
18enum class ProgramKind : int8_t {
19 kFragment,
20 kVertex,
21 kGeometry,
22 kFragmentProcessor,
23 kRuntimeEffect,
24 kGeneric,
25};
26
27/**
28 * Holds the compiler settings for a program.
29 */
30struct ProgramSettings {
31 // if false, sk_FragCoord is exactly the same as gl_FragCoord. If true, the y coordinate
32 // must be flipped.
33 bool fFlipY = false;
34 // If true the destination fragment color is read sk_FragColor. It must be declared inout.
35 bool fFragColorIsInOut = false;
36 // if true, Setting objects (e.g. sk_Caps.fbFetchSupport) should be replaced with their
37 // constant equivalents during compilation
38 bool fReplaceSettings = true;
39 // if true, all halfs are forced to be floats
40 bool fForceHighPrecision = false;
41 // if true, add -0.5 bias to LOD of all texture lookups
42 bool fSharpenTextures = false;
43 // if the program needs to create an RTHeight uniform, this is its offset in the uniform
44 // buffer
45 int fRTHeightOffset = -1;
46 // if the program needs to create an RTHeight uniform and is creating spriv, this is the
47 // binding and set number of the uniform buffer.
48 int fRTHeightBinding = -1;
49 int fRTHeightSet = -1;
50 // If layout(set=S, binding=B) is not specified for a uniform, these values will be used.
51 // At present, zero is always used by our backends.
52 int fDefaultUniformSet = 0;
53 int fDefaultUniformBinding = 0;
John Stiles66c53b92021-02-20 08:00:43 -050054 // Enables the SkSL optimizer.
John Stiles270cec22021-02-17 12:59:36 -050055 bool fOptimize = true;
John Stiles66c53b92021-02-20 08:00:43 -050056 // (Requires fOptimize = true) Remove any uncalled functions other than main(). Note that a
57 // function which starts out being used may end up being uncalled after optimization.
58 bool fRemoveDeadFunctions = true;
John Stiles0c7312a2021-02-24 11:31:32 -050059 // (Requires fOptimize = true) Performs control-flow analysis, constant propagation, and various
60 // other optimizations that are currently implemented as part of the control-flow system.
61 // Turning this off will also disable error-checking for unreachable code and unassigned vars.
John Stiles03467a52021-03-04 15:19:48 +000062 bool fControlFlowAnalysis = true;
John Stiles0c7312a2021-02-24 11:31:32 -050063 // (Requires fOptimize = true AND fControlFlowAnalysis = true) Uses the control-flow graph to
64 // detect and eliminate code within a function that has become unreachable due to optimization.
John Stiles03467a52021-03-04 15:19:48 +000065 bool fDeadCodeElimination = true;
John Stiles66c53b92021-02-20 08:00:43 -050066 // (Requires fOptimize = true) When greater than zero, enables the inliner. The threshold value
67 // sets an upper limit on the acceptable amount of code growth from inlining.
68 int fInlineThreshold = SkSL::kDefaultInlineThreshold;
John Stiles270cec22021-02-17 12:59:36 -050069 // If true, implicit conversions to lower precision numeric types are allowed
70 // (eg, float to half)
71 bool fAllowNarrowingConversions = false;
72 // If true, then Debug code will run SPIR-V output through the validator to ensure its
73 // correctness
74 bool fValidateSPIRV = true;
75 // If true, any synthetic uniforms must use push constant syntax
76 bool fUsePushConstants = false;
77 // Permits static if/switch statements to be used with non-constant tests. This is used when
78 // producing H and CPP code; the static tests don't have to have constant values *yet*, but
79 // the generated code will contain a static test which then does have to be a constant.
80 bool fPermitInvalidStaticTests = false;
81};
82
83/**
84 * All the configuration data for a given program.
85 */
86struct ProgramConfig {
87 ProgramKind fKind;
88 ProgramSettings fSettings;
John Stilesca107c92021-02-19 09:54:44 -050089
90 bool strictES2Mode() const {
91 return fKind == ProgramKind::kRuntimeEffect || fKind == ProgramKind::kGeneric;
92 }
John Stiles270cec22021-02-17 12:59:36 -050093};
94
95} // namespace SkSL
96
97#endif