blob: ddd9e1070550da30e801370bd6634b509d36a68e [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
Ethan Nicholasdaed2592021-03-04 14:30:25 -050011#include "include/private/SkSLDefines.h"
Ethan Nicholasee49efc2021-04-09 15:33:53 -040012#include "include/private/SkSLProgramKind.h"
John Stiles270cec22021-02-17 12:59:36 -050013
Ethan Nicholas55a63af2021-05-18 10:12:58 -040014#include <vector>
15
John Stiles270cec22021-02-17 12:59:36 -050016namespace SkSL {
17
Ethan Nicholas55a63af2021-05-18 10:12:58 -040018class ExternalFunction;
19
John Stiles270cec22021-02-17 12:59:36 -050020/**
John Stiles270cec22021-02-17 12:59:36 -050021 * Holds the compiler settings for a program.
22 */
23struct ProgramSettings {
Brian Salomon40242242021-07-06 19:04:18 +000024 // if false, sk_FragCoord is exactly the same as gl_FragCoord. If true, the y coordinate
25 // must be flipped.
26 bool fFlipY = false;
John Stiles270cec22021-02-17 12:59:36 -050027 // If true the destination fragment color is read sk_FragColor. It must be declared inout.
28 bool fFragColorIsInOut = false;
29 // if true, Setting objects (e.g. sk_Caps.fbFetchSupport) should be replaced with their
30 // constant equivalents during compilation
31 bool fReplaceSettings = true;
32 // if true, all halfs are forced to be floats
33 bool fForceHighPrecision = false;
34 // if true, add -0.5 bias to LOD of all texture lookups
35 bool fSharpenTextures = false;
Brian Salomon40242242021-07-06 19:04:18 +000036 // if the program needs to create an RTHeight uniform, this is its offset in the uniform
John Stiles270cec22021-02-17 12:59:36 -050037 // buffer
Brian Salomon40242242021-07-06 19:04:18 +000038 int fRTHeightOffset = -1;
39 // if the program needs to create an RTHeight uniform and is creating spriv, this is the
John Stiles270cec22021-02-17 12:59:36 -050040 // binding and set number of the uniform buffer.
Brian Salomon40242242021-07-06 19:04:18 +000041 int fRTHeightBinding = -1;
42 int fRTHeightSet = -1;
John Stiles270cec22021-02-17 12:59:36 -050043 // If layout(set=S, binding=B) is not specified for a uniform, these values will be used.
44 // At present, zero is always used by our backends.
45 int fDefaultUniformSet = 0;
46 int fDefaultUniformBinding = 0;
John Stiles66c53b92021-02-20 08:00:43 -050047 // Enables the SkSL optimizer.
John Stiles270cec22021-02-17 12:59:36 -050048 bool fOptimize = true;
John Stiles0bfeae62021-03-11 09:09:42 -050049 // (Requires fOptimize = true) Removes any uncalled functions other than main(). Note that a
John Stiles66c53b92021-02-20 08:00:43 -050050 // function which starts out being used may end up being uncalled after optimization.
51 bool fRemoveDeadFunctions = true;
John Stiles0bfeae62021-03-11 09:09:42 -050052 // (Requires fOptimize = true) Removes global variables which are never used.
53 bool fRemoveDeadVariables = true;
John Stiles66c53b92021-02-20 08:00:43 -050054 // (Requires fOptimize = true) When greater than zero, enables the inliner. The threshold value
55 // sets an upper limit on the acceptable amount of code growth from inlining.
56 int fInlineThreshold = SkSL::kDefaultInlineThreshold;
John Stiles9d26af92021-03-23 09:25:33 -040057 // If true, every function in the generated program will be given the `noinline` modifier.
58 bool fForceNoInline = false;
John Stiles270cec22021-02-17 12:59:36 -050059 // If true, implicit conversions to lower precision numeric types are allowed
60 // (eg, float to half)
61 bool fAllowNarrowingConversions = false;
62 // If true, then Debug code will run SPIR-V output through the validator to ensure its
63 // correctness
64 bool fValidateSPIRV = true;
65 // If true, any synthetic uniforms must use push constant syntax
66 bool fUsePushConstants = false;
67 // Permits static if/switch statements to be used with non-constant tests. This is used when
68 // producing H and CPP code; the static tests don't have to have constant values *yet*, but
69 // the generated code will contain a static test which then does have to be a constant.
70 bool fPermitInvalidStaticTests = false;
John Stiles65d7ab22021-04-28 15:14:09 -040071 // If true, configurations which demand strict ES2 conformance (runtime effects, generic
72 // programs, and SkVM rendering) will fail during compilation if ES2 restrictions are violated.
73 bool fEnforceES2Restrictions = true;
Ethan Nicholas55a63af2021-05-18 10:12:58 -040074 // If true, the DSL should automatically mangle symbol names.
75 bool fDSLMangling = true;
76 // If true, the DSL should automatically mark variables declared upon creation.
77 bool fDSLMarkVarsDeclared = false;
78 // External functions available for use in runtime effects. These values are registered in the
79 // symbol table of the Program, but ownership is *not* transferred. It is up to the caller to
80 // keep them alive.
81 const std::vector<std::unique_ptr<ExternalFunction>>* fExternalFunctions = nullptr;
John Stiles270cec22021-02-17 12:59:36 -050082};
83
84/**
85 * All the configuration data for a given program.
86 */
87struct ProgramConfig {
88 ProgramKind fKind;
89 ProgramSettings fSettings;
John Stilesca107c92021-02-19 09:54:44 -050090
91 bool strictES2Mode() const {
John Stiles65d7ab22021-04-28 15:14:09 -040092 return fSettings.fEnforceES2Restrictions &&
Brian Osman552fcb92021-04-28 17:41:57 -040093 (fKind == ProgramKind::kRuntimeColorFilter ||
John Stiles65d7ab22021-04-28 15:14:09 -040094 fKind == ProgramKind::kRuntimeShader ||
95 fKind == ProgramKind::kGeneric);
John Stilesca107c92021-02-19 09:54:44 -050096 }
John Stiles270cec22021-02-17 12:59:36 -050097};
98
99} // namespace SkSL
100
101#endif