1cb93a386Sopenharmony_ciOverview 2cb93a386Sopenharmony_ci======== 3cb93a386Sopenharmony_ci 4cb93a386Sopenharmony_ciSkSL ("Skia Shading Language") is a variant of GLSL which is used as Skia's 5cb93a386Sopenharmony_ciinternal shading language. SkSL is, at its heart, a single standardized version 6cb93a386Sopenharmony_ciof GLSL which avoids all of the various version and dialect differences found 7cb93a386Sopenharmony_ciin GLSL "in the wild", but it does bring a few of its own changes to the table. 8cb93a386Sopenharmony_ci 9cb93a386Sopenharmony_ciSkia uses the SkSL compiler to convert SkSL code to GLSL, GLSL ES, or SPIR-V 10cb93a386Sopenharmony_cibefore handing it over to the graphics driver. 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ciDifferences from GLSL 14cb93a386Sopenharmony_ci===================== 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_ci* Precision modifiers are not used. 'float', 'int', and 'uint' are always high 17cb93a386Sopenharmony_ci precision. New types 'half', 'short', and 'ushort' are medium precision (we 18cb93a386Sopenharmony_ci do not use low precision). 19cb93a386Sopenharmony_ci* Vector types are named <base type><columns>, so float2 instead of vec2 and 20cb93a386Sopenharmony_ci bool4 instead of bvec4 21cb93a386Sopenharmony_ci* Matrix types are named <base type><columns>x<rows>, so float2x3 instead of 22cb93a386Sopenharmony_ci mat2x3 and double4x4 instead of dmat4 23cb93a386Sopenharmony_ci* "@if" and "@switch" are static versions of if and switch. They behave exactly 24cb93a386Sopenharmony_ci the same as if and switch in all respects other than it being a compile-time 25cb93a386Sopenharmony_ci error to use a non-constant expression as a test. 26cb93a386Sopenharmony_ci* GLSL caps can be referenced via the syntax 'sk_Caps.<name>', e.g. 27cb93a386Sopenharmony_ci sk_Caps.canUseAnyFunctionInShader. The value will be a constant boolean or int, 28cb93a386Sopenharmony_ci as appropriate. As SkSL supports constant folding and branch elimination, this 29cb93a386Sopenharmony_ci means that an 'if' statement which statically queries a cap will collapse down 30cb93a386Sopenharmony_ci to the chosen branch, meaning that: 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci if (sk_Caps.externalTextureSupport) 33cb93a386Sopenharmony_ci do_something(); 34cb93a386Sopenharmony_ci else 35cb93a386Sopenharmony_ci do_something_else(); 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_ci will compile as if you had written either 'do_something();' or 38cb93a386Sopenharmony_ci 'do_something_else();', depending on whether that cap is enabled or not. 39cb93a386Sopenharmony_ci* no #version statement is required, and it will be ignored if present 40cb93a386Sopenharmony_ci* the output color is sk_FragColor (do not declare it) 41cb93a386Sopenharmony_ci* use sk_Position instead of gl_Position. sk_Position is in device coordinates 42cb93a386Sopenharmony_ci rather than normalized coordinates. 43cb93a386Sopenharmony_ci* use sk_PointSize instead of gl_PointSize 44cb93a386Sopenharmony_ci* use sk_VertexID instead of gl_VertexID 45cb93a386Sopenharmony_ci* use sk_InstanceID instead of gl_InstanceID 46cb93a386Sopenharmony_ci* the fragment coordinate is sk_FragCoord, and is always relative to the upper 47cb93a386Sopenharmony_ci left. 48cb93a386Sopenharmony_ci* use sk_Clockwise instead of gl_FrontFacing. This is always relative to an 49cb93a386Sopenharmony_ci upper left origin. 50cb93a386Sopenharmony_ci* you do not need to include ".0" to make a number a float (meaning that 51cb93a386Sopenharmony_ci "float2(x, y) * 4" is perfectly legal in SkSL, unlike GLSL where it would 52cb93a386Sopenharmony_ci often have to be expressed "float2(x, y) * 4.0". There is no performance 53cb93a386Sopenharmony_ci penalty for this, as the number is converted to a float at compile time) 54cb93a386Sopenharmony_ci* type suffixes on numbers (1.0f, 0xFFu) are both unnecessary and unsupported 55cb93a386Sopenharmony_ci* creating a smaller vector from a larger vector (e.g. float2(float3(1))) is 56cb93a386Sopenharmony_ci intentionally disallowed, as it is just a wordier way of performing a swizzle. 57cb93a386Sopenharmony_ci Use swizzles instead. 58cb93a386Sopenharmony_ci* Swizzle components, in addition to the normal rgba / xyzw components, can also 59cb93a386Sopenharmony_ci be LTRB (meaning "left/top/right/bottom", for when we store rectangles in 60cb93a386Sopenharmony_ci vectors), and may also be the constants '0' or '1' to produce a constant 0 or 61cb93a386Sopenharmony_ci 1 in that channel instead of selecting anything from the source vector. 62cb93a386Sopenharmony_ci foo.rgb1 is equivalent to float4(foo.rgb, 1). 63cb93a386Sopenharmony_ci* All texture functions are named "sample", e.g. sample(sampler2D, float3) is 64cb93a386Sopenharmony_ci equivalent to GLSL's textureProj(sampler2D, float3). 65cb93a386Sopenharmony_ci* Functions support the 'inline' modifier, which causes the compiler to ignore 66cb93a386Sopenharmony_ci its normal inlining heuristics and inline the function if at all possible 67cb93a386Sopenharmony_ci* some built-in functions and one or two rarely-used language features are not 68cb93a386Sopenharmony_ci yet supported (sorry!) 69