• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

codegen/23-Nov-2023-15,15712,648

dsl/23-Nov-2023-2,2821,661

generated/23-Nov-2023-7,9347,924

ir/23-Nov-2023-9,3666,335

lex/23-Nov-2023-1,3541,004

GLSL.std.450.hD23-Nov-20234 KiB13290

READMED23-Nov-20238.9 KiB170149

SkSLASTFile.hD23-Nov-2023536 3518

SkSLASTNode.cppD23-Nov-20238.5 KiB248236

SkSLASTNode.hD23-Nov-202315.3 KiB575424

SkSLAnalysis.cppD23-Nov-202350.5 KiB1,3121,037

SkSLAnalysis.hD23-Nov-20239.4 KiB239120

SkSLBuiltinTypes.cppD23-Nov-202314.1 KiB249209

SkSLBuiltinTypes.hD23-Nov-20235.5 KiB156117

SkSLCPP.hD23-Nov-20232.5 KiB7447

SkSLCPPUniformCTypes.cppD23-Nov-202311.2 KiB253180

SkSLCPPUniformCTypes.hD23-Nov-20234.7 KiB12150

SkSLCompiler.cppD23-Nov-202334.1 KiB937738

SkSLCompiler.hD23-Nov-20238.1 KiB253159

SkSLConstantFolder.cppD23-Nov-202323.3 KiB563451

SkSLConstantFolder.hD23-Nov-20232.5 KiB7227

SkSLContext.cppD23-Nov-2023376 208

SkSLContext.hD23-Nov-20231.2 KiB5425

SkSLDehydrator.cppD23-Nov-202324.6 KiB644599

SkSLDehydrator.hD23-Nov-20233 KiB14795

SkSLErrorReporter.hD23-Nov-20231.3 KiB5222

SkSLFileOutputStream.hD23-Nov-20231.5 KiB7958

SkSLIRGenerator.cppD23-Nov-202385.3 KiB2,0451,825

SkSLIRGenerator.hD23-Nov-202312.1 KiB292229

SkSLInliner.cppD23-Nov-202354.9 KiB1,198908

SkSLInliner.hD23-Nov-20234.9 KiB12780

SkSLIntrinsicList.hD23-Nov-20234 KiB11098

SkSLLexer.cppD23-Nov-202362.2 KiB809789

SkSLLexer.hD23-Nov-20232.9 KiB140120

SkSLMain.cppD23-Nov-202323.9 KiB561472

SkSLMangler.cppD23-Nov-20231.9 KiB5127

SkSLMangler.hD23-Nov-2023560 3516

SkSLMemoryLayout.hD23-Nov-20235.9 KiB174128

SkSLMemoryPool.hD23-Nov-2023999 4525

SkSLModifiersPool.hD23-Nov-2023797 3919

SkSLOperators.cppD23-Nov-202315.8 KiB404357

SkSLOperators.hD23-Nov-20233.2 KiB11257

SkSLOutputStream.cppD23-Nov-2023982 4127

SkSLOutputStream.hD23-Nov-20231.1 KiB5532

SkSLParser.cppD23-Nov-202377.4 KiB2,2021,999

SkSLParser.hD23-Nov-20238 KiB322172

SkSLPool.cppD23-Nov-20233.2 KiB12184

SkSLPool.hD23-Nov-20232.2 KiB7730

SkSLPosition.hD23-Nov-2023689 4020

SkSLProgramSettings.hD23-Nov-20233.7 KiB9039

SkSLRehydrator.cppD23-Nov-202326.1 KiB608579

SkSLRehydrator.hD23-Nov-20237.7 KiB248150

SkSLSampleUsage.cppD23-Nov-20231.9 KiB5637

SkSLSectionAndParameterHelper.cppD23-Nov-20232.8 KiB7261

SkSLSectionAndParameterHelper.hD23-Nov-20234.2 KiB11693

SkSLString.cppD23-Nov-20236 KiB257210

SkSLStringStream.hD23-Nov-20231.7 KiB9665

SkSLUtil.cppD23-Nov-20234.2 KiB8163

SkSLUtil.hD23-Nov-202314.9 KiB500399

sksl_fp_raw.skslD23-Nov-2023725 2014

sksl_frag.skslD23-Nov-2023538 139

sksl_geom.skslD23-Nov-2023654 2015

sksl_gpu.skslD23-Nov-202321.8 KiB594538

sksl_public.skslD23-Nov-20235.1 KiB144128

sksl_rt_colorfilter.skslD23-Nov-202381 32

sksl_rt_shader.skslD23-Nov-2023122 53

sksl_vert.skslD23-Nov-2023254 107

spirv.hD23-Nov-202327.7 KiB871780

README

1Overview
2========
3
4SkSL ("Skia Shading Language") is a variant of GLSL which is used as Skia's
5internal shading language. SkSL is, at its heart, a single standardized version
6of GLSL which avoids all of the various version and dialect differences found
7in GLSL "in the wild", but it does bring a few of its own changes to the table.
8
9Skia uses the SkSL compiler to convert SkSL code to GLSL, GLSL ES, or SPIR-V
10before handing it over to the graphics driver.
11
12
13Differences from GLSL
14=====================
15
16* Precision modifiers are not used. 'float', 'int', and 'uint' are always high
17  precision. New types 'half', 'short', and 'ushort' are medium precision (we
18  do not use low precision).
19* Vector types are named <base type><columns>, so float2 instead of vec2 and
20  bool4 instead of bvec4
21* Matrix types are named <base type><columns>x<rows>, so float2x3 instead of
22  mat2x3 and double4x4 instead of dmat4
23* "@if" and "@switch" are static versions of if and switch. They behave exactly
24  the same as if and switch in all respects other than it being a compile-time
25  error to use a non-constant expression as a test.
26* GLSL caps can be referenced via the syntax 'sk_Caps.<name>', e.g.
27  sk_Caps.canUseAnyFunctionInShader. The value will be a constant boolean or int,
28  as appropriate. As SkSL supports constant folding and branch elimination, this
29  means that an 'if' statement which statically queries a cap will collapse down
30  to the chosen branch, meaning that:
31
32    if (sk_Caps.externalTextureSupport)
33        do_something();
34    else
35        do_something_else();
36
37  will compile as if you had written either 'do_something();' or
38  'do_something_else();', depending on whether that cap is enabled or not.
39* no #version statement is required, and it will be ignored if present
40* the output color is sk_FragColor (do not declare it)
41* use sk_Position instead of gl_Position. sk_Position is in device coordinates
42  rather than normalized coordinates.
43* use sk_PointSize instead of gl_PointSize
44* use sk_VertexID instead of gl_VertexID
45* use sk_InstanceID instead of gl_InstanceID
46* the fragment coordinate is sk_FragCoord, and is always relative to the upper
47  left.
48* use sk_Clockwise instead of gl_FrontFacing. This is always relative to an
49  upper left origin.
50* you do not need to include ".0" to make a number a float (meaning that
51  "float2(x, y) * 4" is perfectly legal in SkSL, unlike GLSL where it would
52  often have to be expressed "float2(x, y) * 4.0". There is no performance
53  penalty for this, as the number is converted to a float at compile time)
54* type suffixes on numbers (1.0f, 0xFFu) are both unnecessary and unsupported
55* creating a smaller vector from a larger vector (e.g. float2(float3(1))) is
56  intentionally disallowed, as it is just a wordier way of performing a swizzle.
57  Use swizzles instead.
58* Swizzle components, in addition to the normal rgba / xyzw components, can also
59  be LTRB (meaning "left/top/right/bottom", for when we store rectangles in
60  vectors), and may also be the constants '0' or '1' to produce a constant 0 or
61  1 in that channel instead of selecting anything from the source vector.
62  foo.rgb1 is equivalent to float4(foo.rgb, 1).
63* All texture functions are named "sample", e.g. sample(sampler2D, float3) is
64  equivalent to GLSL's textureProj(sampler2D, float3).
65* Functions support the 'inline' modifier, which causes the compiler to ignore
66  its normal inlining heuristics and inline the function if at all possible
67* some built-in functions and one or two rarely-used language features are not
68  yet supported (sorry!)
69
70
71SkSL Fragment Processors
72========================
73
74********************************************************************************
75*** IMPORTANT: You must set gn arg "skia_compile_processors = true" to cause ***
76*** .fp files to be recompiled! In order for compilation to succeed, you     ***
77*** must run bin/fetch-clang-format (once) to install our blessed version.   ***
78********************************************************************************
79
80An extension of SkSL allows for the creation of fragment processors in pure
81SkSL. The program defines its inputs similarly to a normal SkSL program (with
82'in' and 'uniform' variables), but the 'main()' function represents only this
83fragment processor's portion of the overall fragment shader. The 'main' function
84can optionally have a 'float2' parameter that holds the sample coordinates the
85processor is evaluated at.
86
87Processors do not need to declare this parameter if they do not rely on local
88coordinates or only invoke child processors using the no-arg and matrix-based
89sample() functions.
90
91Within an '.fp' fragment processor file:
92
93* C++ code can be embedded in sections of the form:
94
95  @section_name { <arbitrary C++ code> }
96
97  Supported section are:
98    @header            (in the .h file, outside the class declaration)
99    @headerEnd         (at the end of the .h file)
100    @class             (in the .h file, inside the class declaration)
101    @cpp               (in the .cpp file)
102    @cppEnd            (at the end of the .cpp file)
103    @constructorParams (extra parameters to the constructor, comma-separated)
104    @constructor       (replaces the default constructor)
105    @initializers      (constructor initializer list, comma-separated)
106    @emitCode          (extra code for the emitCode function)
107    @fields            (extra private fields, each terminated with a semicolon)
108    @make              (replaces the default Make function)
109    @clone             (replaces the default clone() function)
110    @dumpInfo          (replaces the default dumpInfo() function)
111    @setData(<pdman>)  (extra code for the setData function, where <pdman> is
112                        the name of the GrGLSLProgramDataManager)
113    @test(<testData>)  (the body of the TestCreate function, where <testData> is
114                        the name of the GrProcessorTestData* parameter)
115    @samplerParams(<sampler>)
116                       (the sampler params to attach to the named sampler2D)
117* global 'in' variables represent data passed to the fragment processor at
118  construction time. These variables become constructor parameters and are
119  stored in fragment processor fields. By default float2/half2 maps to SkPoints,
120  and float4/half4 maps to SkRects (in x, y, width, height) order. Similarly,
121  int2/short2 maps to SkIPoint and int4/half4 maps to SkIRect. Use ctype
122  (below) to override this default mapping.
123* global variables support an additional 'ctype' layout key, providing the type
124  they should be represented as from within the C++ code. For instance, you can
125  use 'layout(ctype=SkPMColor4f) in half4 color;' to create a variable that looks
126  like a half4 on the SkSL side of things, and a SkPMColor4f on the C++ side of
127  things.
128* 'uniform' variables become, as one would expect, top-level uniforms. By
129  default they do not have any data provided to them; you will need to provide
130  them with data via the @setData section.
131* 'in uniform' variables are uniforms that are automatically wired up to
132  fragment processor constructor parameters. The fragment processor will accept
133  a parameter representing the uniform's value, and automatically plumb it
134  through to the uniform's value in its generated setData() function.
135* 'in uniform' variables support a 'tracked' flag in the layout that will
136  have the generated code automatically implement state tracking on the uniform
137  value to minimize GPU calls.
138* Uniform variables support an additional 'when' layout key.
139  'layout(when=foo) uniform int x;' means that this uniform will only be
140  emitted when the 'foo' expression is true.
141* 'in' variables support an additional 'key' layout key.
142  'layout(key) in uniform int x;' means that this uniform should be included in
143  the program's key. Matrix variables additionally support 'key=identity',
144  which causes the key to consider only whether or not the matrix is an
145  identity matrix.
146* child processors can be declared with 'in fragmentProcessor <name>;', and can
147  be invoked by calling 'sample(<name>)' or 'sample(<name>, <inputColor>)'.
148  The first variant emits the child with a solid white input color. The second
149  variant emits the child with the result of the 2nd argument's expression,
150  which must evaluate to a half4. The process function returns a half4.
151  Invoking 'sample()' on a null fragment processor will return the inputColor
152  unchanged (this defaults to solid white if not explicitly specified).
153
154
155Creating a new .fp file
156=======================
157
1581. Ensure that you have set gn arg "skia_compile_processors = true"
1592. Create your new .fp file, generally under src/gpu/effects.
1603. Add the .fp file to sksl.gni.
1614. Build Skia. This will cause the .fp file to be compiled, resulting in a new
162   .cpp and .h file for the fragment processor.
1635. Add the .cpp and .h files to gpu.gni.
1646. Add the new processor's ClassID (k<ProcessorName>_ClassID) to
165   GrProcessor::ClassID.
1667. At this point you can reference the new fragment processor from within Skia.
167
168Once you have done this initial setup, simply re-build Skia to pick up any
169changes to the .fp file.
170