Home | History | Annotate | only in /external/skqp/src/sksl
Up to higher level directory
NameDateSize
ast/22-Oct-2020
GLSL.std.450.h22-Oct-20204K
ir/22-Oct-2020
lex/22-Oct-2020
README22-Oct-20208.5K
sksl.inc22-Oct-202028.5K
sksl_enums.inc22-Oct-2020992
sksl_fp.inc22-Oct-20201.1K
sksl_frag.inc22-Oct-2020912
sksl_geom.inc22-Oct-2020675
sksl_pipeline.inc22-Oct-2020711
sksl_vert.inc22-Oct-2020317
SkSLCFGGenerator.cpp22-Oct-202027.2K
SkSLCFGGenerator.h22-Oct-20205.8K
SkSLCodeGenerator.h22-Oct-2020812
SkSLCompiler.cpp22-Oct-202060K
SkSLCompiler.h22-Oct-20205.8K
SkSLContext.h22-Oct-202020.1K
SkSLCPP.h22-Oct-20201.1K
SkSLCPPCodeGenerator.cpp22-Oct-202050K
SkSLCPPCodeGenerator.h22-Oct-20204.7K
SkSLCPPUniformCTypes.cpp22-Oct-20209.9K
SkSLCPPUniformCTypes.h22-Oct-20205.5K
SkSLDefines.h22-Oct-2020936
SkSLErrorReporter.h22-Oct-2020573
SkSLFileOutputStream.h22-Oct-20201.5K
SkSLGLSLCodeGenerator.cpp22-Oct-202060.2K
SkSLGLSLCodeGenerator.h22-Oct-20207.2K
SkSLHCodeGenerator.cpp22-Oct-202015.2K
SkSLHCodeGenerator.h22-Oct-20202.6K
SkSLInterpreter.cpp22-Oct-202018.7K
SkSLInterpreter.h22-Oct-20201.7K
SkSLIRGenerator.cpp22-Oct-2020101.4K
SkSLIRGenerator.h22-Oct-20209.1K
SkSLJIT.cpp22-Oct-202091.2K
SkSLJIT.h22-Oct-202013.2K
SkSLLexer.cpp22-Oct-202088.6K
SkSLLexer.h22-Oct-20204.2K
SkSLMain.cpp22-Oct-20205.5K
SkSLMemoryLayout.h22-Oct-20204.8K
SkSLMetalCodeGenerator.cpp22-Oct-202058.6K
SkSLMetalCodeGenerator.h22-Oct-20208.4K
SkSLOutputStream.cpp22-Oct-2020690
SkSLOutputStream.h22-Oct-2020772
SkSLParser.cpp22-Oct-202071.5K
SkSLParser.h22-Oct-20208K
SkSLPipelineStageCodeGenerator.cpp22-Oct-20208K
SkSLPipelineStageCodeGenerator.h22-Oct-20201.8K
SkSLPosition.h22-Oct-2020634
SkSLSectionAndParameterHelper.h22-Oct-20205.9K
SkSLSPIRVCodeGenerator.cpp22-Oct-2020146.2K
SkSLSPIRVCodeGenerator.h22-Oct-202012.8K
SkSLString.cpp22-Oct-20207K
SkSLString.h22-Oct-20204.1K
SkSLStringStream.h22-Oct-20201.5K
SkSLUtil.cpp22-Oct-2020564
SkSLUtil.h22-Oct-202010.9K
spirv.h22-Oct-202027.7K

README

      1 Overview
      2 ========
      3 
      4 SkSL ("Skia Shading Language") is a variant of GLSL which is used as Skia's
      5 internal shading language. SkSL is, at its heart, a single standardized version
      6 of GLSL which avoids all of the various version and dialect differences found
      7 in GLSL "in the wild", but it does bring a few of its own changes to the table.
      8 
      9 Skia uses the SkSL compiler to convert SkSL code to GLSL, GLSL ES, or SPIR-V
     10 before handing it over to the graphics driver.
     11 
     12 
     13 Differences 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.sampleVariablesSupport. 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 * Use texture() instead of textureProj(), e.g. texture(sampler2D, float3) is
     59   equivalent to GLSL's textureProj(sampler2D, float3)
     60 * Render target width and height are available via sk_Width and sk_Height
     61 * some built-in functions and one or two rarely-used language features are not
     62   yet supported (sorry!)
     63 
     64 SkSL is still under development, and is expected to diverge further from GLSL
     65 over time.
     66 
     67 
     68 SkSL Fragment Processors
     69 ========================
     70 
     71 ********************************************************************************
     72 *** IMPORTANT: You must set gn arg "skia_compile_processors = true" to cause ***
     73 *** .fp files to be recompiled! In order for compilation to succeed, you     ***
     74 *** must run bin/fetch-clang-format (once) to install our blessed version.   ***
     75 ********************************************************************************
     76 
     77 An extension of SkSL allows for the creation of fragment processors in pure
     78 SkSL. The program defines its inputs similarly to a normal SkSL program (with
     79 'in' and 'uniform' variables), but the 'main()' function represents only this
     80 fragment processor's portion of the overall fragment shader.
     81 
     82 Within an '.fp' fragment processor file:
     83 
     84 * C++ code can be embedded in sections of the form:
     85 
     86   @section_name { <arbitrary C++ code> }
     87 
     88   Supported section are:
     89     @header            (in the .h file, outside the class declaration)
     90     @headerEnd         (at the end of the .h file)
     91     @class             (in the .h file, inside the class declaration)
     92     @cpp               (in the .cpp file)
     93     @cppEnd            (at the end of the .cpp file)
     94     @constructorParams (extra parameters to the constructor, comma-separated)
     95     @constructor       (replaces the default constructor)
     96     @initializers      (constructor initializer list, comma-separated)
     97     @emitCode          (extra code for the emitCode function)
     98     @fields            (extra private fields, each terminated with a semicolon)
     99     @make              (replaces the default Make function)
    100     @clone             (replaces the default clone() function)
    101     @setData(<pdman>)  (extra code for the setData function, where <pdman> is
    102                         the name of the GrGLSLProgramDataManager)
    103     @test(<testData>)  (the body of the TestCreate function, where <testData> is
    104                         the name of the GrProcessorTestData* parameter)
    105     @coordTransform(<sampler>)
    106                        (the matrix to attach to the named sampler2D's
    107                         GrCoordTransform)
    108     @samplerParams(<sampler>)
    109                        (the sampler params to attach to the named sampler2D)
    110 * global 'in' variables represent data passed to the fragment processor at
    111   construction time. These variables become constructor parameters and are
    112   stored in fragment processor fields. By default float2/half2 maps to SkPoints,
    113   and float4/half4 maps to SkRects (in x, y, width, height) order. Similarly,
    114   int2/short2 maps to SkIPoint and int4/half4 maps to SkIRect. Use ctype
    115   (below) to override this default mapping.
    116 * global variables support an additional 'ctype' layout key, providing the type
    117   they should be represented as from within the C++ code. For instance, you can
    118   use 'layout(ctype=SkPMColor4f) in half4 color;' to create a variable that looks
    119   like a half4 on the SkSL side of things, and a SkPMColor4f on the C++ side of
    120   things.
    121 * 'uniform' variables become, as one would expect, top-level uniforms. By
    122   default they do not have any data provided to them; you will need to provide
    123   them with data via the @setData section.
    124 * 'in uniform' variables are uniforms that are automatically wired up to
    125   fragment processor constructor parameters. The fragment processor will accept
    126   a parameter representing the uniform's value, and automatically plumb it
    127   through to the uniform's value in its generated setData() function.
    128 * 'in uniform' variables support a 'tracked' flag in the layout that will
    129   have the generated code automatically implement state tracking on the uniform
    130   value to minimize GPU calls.
    131 * the 'sk_TransformedCoords2D' array provides access to 2D transformed
    132   coordinates. sk_TransformedCoords2D[0] is equivalent to calling
    133   fragBuilder->ensureCoords2D(args.fTransformedCoords[0]) (and the result is
    134   cached, so you need not worry about using the value repeatedly).
    135 * Uniform variables support an additional 'when' layout key.
    136   'layout(when=foo) uniform int x;' means that this uniform will only be
    137   emitted when the 'foo' expression is true.
    138 * 'in' variables support an additional 'key' layout key.
    139   'layout(key) uniform int x;' means that this uniform should be included in
    140   the program's key. Matrix variables additionally support 'key=identity',
    141   which causes the key to consider only whether or not the matrix is an
    142   identity matrix.
    143 * child processors can be declared with 'in fragmentProcessor <name>;', and can
    144   be invoked by calling 'process(<name>)' or 'process(<name>, <inputColor>)'.
    145   The first variant emits the child with a solid white input color. The second
    146   variant emits the child with the result of the 2nd argument's expression,
    147   which must evaluate to a half4. The process function returns a half4.
    148 
    149 
    150 Creating a new .fp file
    151 =======================
    152 
    153 1. Ensure that you have set gn arg "skia_compile_processors = true"
    154 2. Create your new .fp file, generally under src/gpu/effects.
    155 3. Add the .fp file to sksl.gni.
    156 4. Build Skia. This will cause the .fp file to be compiled, resulting in a new
    157    .cpp and .h file for the fragment processor.
    158 5. Add the .cpp and .h files to gpu.gni.
    159 6. Add the new processor's ClassID (k<ProcessorName>_ClassID) to
    160    GrProcessor::ClassID.
    161 7. At this point you can reference the new fragment processor from within Skia.
    162 
    163 Once you have done this initial setup, simply re-build Skia to pick up any
    164 changes to the .fp file.
    165