31#include "spirv-tools/libspirv.hpp"
57 fBytesWritten +=
size;
60 void flush()
override {}
61 size_t bytesWritten()
const override {
return fBytesWritten; }
68 return std::make_unique<Adapter>(
s);
75 str->resize(str->length() - strlen(
suffix));
84 caps->fVersionDeclString =
"#version 400";
85 caps->fAddAndTrueToLoopCondition =
true;
86 return caps.release();
94 caps->fVersionDeclString =
"#version 400";
95 caps->fCanUseFractForNegativeValues =
false;
96 return caps.release();
104 caps->fVersionDeclString =
"#version 400";
105 caps->fCanUseFragCoord =
false;
106 return caps.release();
114 caps->fVersionDeclString =
"#version 400";
115 caps->fCanUseMinAndAbsTogether =
false;
116 return caps.release();
124 caps->fCanUseVoidInSequenceExpressions =
false;
125 return caps.release();
134 caps->fDualSourceBlendingSupport =
true;
135 return caps.release();
143 caps->fVersionDeclString =
"#version 400";
144 caps->fEmulateAbsIntFunction =
true;
145 return caps.release();
153 caps->fFBFetchSupport =
true;
154 caps->fFBFetchColorName =
"FramebufferFragColor";
155 return caps.release();
163 caps->fMustDeclareFragmentFrontFacing =
true;
164 return caps.release();
172 caps->fVersionDeclString =
"#version 400";
173 caps->fMustForceNegatedAtanParamToFloat =
true;
174 return caps.release();
182 caps->fVersionDeclString =
"#version 400";
183 caps->fMustForceNegatedLdexpParamToMultiply =
true;
184 return caps.release();
192 caps->fMustGuardDivisionEvenAfterExplicitZeroCheck =
true;
193 return caps.release();
201 caps->fVersionDeclString =
"#version 400";
202 caps->fBuiltinDeterminantSupport =
false;
203 return caps.release();
211 caps->fVersionDeclString =
"#version 400";
212 caps->fBuiltinFMASupport =
false;
213 return caps.release();
221 caps->fVersionDeclString =
"#version 400";
222 caps->fExternalTextureSupport =
false;
223 return caps.release();
231 caps->fVersionDeclString =
"#version 400";
232 caps->fRemovePowWithConstantExponent =
true;
233 return caps.release();
241 caps->fVersionDeclString =
"#version 400";
242 caps->fRewriteDoWhileLoops =
true;
243 return caps.release();
251 caps->fRewriteMatrixComparisons =
true;
252 caps->fUsesPrecisionModifiers =
true;
253 return caps.release();
261 caps->fVersionDeclString =
"#version 400";
262 caps->fRewriteMatrixVectorMultiply =
true;
263 return caps.release();
271 caps->fVersionDeclString =
"#version 400";
272 caps->fRewriteSwitchStatements =
true;
273 return caps.release();
281 caps->fVersionDeclString =
"#version 400";
282 caps->fShaderDerivativeSupport =
true;
283 caps->fSampleMaskSupport =
true;
284 return caps.release();
292 caps->fVersionDeclString =
"#version 400";
293 caps->fShaderDerivativeSupport =
true;
294 caps->fShaderDerivativeExtensionString =
"GL_OES_standard_derivatives";
295 caps->fUsesPrecisionModifiers =
true;
296 return caps.release();
304 caps->fVersionDeclString =
"#version 400";
305 caps->fUnfoldShortCircuitAsTernary =
true;
306 return caps.release();
314 caps->fVersionDeclString =
"#version 400";
315 caps->fUsesPrecisionModifiers =
true;
316 return caps.release();
324 caps->fVersionDeclString =
"#version 110";
326 return caps.release();
334 caps->fVersionDeclString =
"#version 450 core";
335 return caps.release();
347 std::unique_ptr<SkSL::DebugTracePriv>* debugTrace) {
351 static constexpr char kPragmaSettings[] =
"/*#pragma settings ";
352 const char* settingsPtr = strstr(
text.c_str(), kPragmaSettings);
353 if (settingsPtr !=
nullptr) {
356 settingsPtr += strlen(kPragmaSettings) - 1;
358 const char* settingsEnd = strstr(settingsPtr,
"*/");
359 if (settingsEnd !=
nullptr) {
360 std::string settingsText{settingsPtr, size_t(settingsEnd - settingsPtr)};
365 const size_t startingLength = settingsText.length();
367 if (
consume_suffix(&settingsText,
" AddAndTrueToLoopCondition")) {
368 *caps = Factory::AddAndTrueToLoopCondition();
370 if (
consume_suffix(&settingsText,
" CannotUseFractForNegativeValues")) {
371 *caps = Factory::CannotUseFractForNegativeValues();
374 *caps = Factory::CannotUseFragCoord();
376 if (
consume_suffix(&settingsText,
" CannotUseMinAndAbsTogether")) {
377 *caps = Factory::CannotUseMinAndAbsTogether();
379 if (
consume_suffix(&settingsText,
" CannotUseVoidInSequenceExpressions")) {
380 *caps = Factory::CannotUseVoidInSequenceExpressions();
383 *caps = Factory::DualSourceBlending();
386 *caps = Factory::Default();
389 *caps = Factory::EmulateAbsIntFunction();
392 *caps = Factory::FramebufferFetchSupport();
394 if (
consume_suffix(&settingsText,
" MustGuardDivisionEvenAfterExplicitZeroCheck")) {
395 *caps = Factory::MustGuardDivisionEvenAfterExplicitZeroCheck();
397 if (
consume_suffix(&settingsText,
" MustDeclareFragmentFrontFacing")) {
398 *caps = Factory::MustDeclareFragmentFrontFacing();
400 if (
consume_suffix(&settingsText,
" MustForceNegatedAtanParamToFloat")) {
401 *caps = Factory::MustForceNegatedAtanParamToFloat();
403 if (
consume_suffix(&settingsText,
" MustForceNegatedLdexpParamToMultiply")) {
404 *caps = Factory::MustForceNegatedLdexpParamToMultiply();
406 if (
consume_suffix(&settingsText,
" NoBuiltinDeterminantSupport")) {
407 *caps = Factory::NoBuiltinDeterminantSupport();
410 *caps = Factory::NoBuiltinFMASupport();
413 *caps = Factory::NoExternalTextureSupport();
415 if (
consume_suffix(&settingsText,
" RemovePowWithConstantExponent")) {
416 *caps = Factory::RemovePowWithConstantExponent();
419 *caps = Factory::RewriteDoWhileLoops();
422 *caps = Factory::RewriteSwitchStatements();
424 if (
consume_suffix(&settingsText,
" RewriteMatrixVectorMultiply")) {
425 *caps = Factory::RewriteMatrixVectorMultiply();
428 *caps = Factory::RewriteMatrixComparisons();
430 if (
consume_suffix(&settingsText,
" ShaderDerivativeExtensionString")) {
431 *caps = Factory::ShaderDerivativeExtensionString();
433 if (
consume_suffix(&settingsText,
" UnfoldShortCircuitAsTernary")) {
434 *caps = Factory::UnfoldShortCircuitAsTernary();
437 *caps = Factory::UsesPrecisionModifiers();
440 *caps = Factory::Version110();
443 *caps = Factory::Version450Core();
445 if (
consume_suffix(&settingsText,
" AllowNarrowingConversions")) {
446 settings->fAllowNarrowingConversions =
true;
449 settings->fForceHighPrecision =
true;
462 settings->fInlineThreshold = INT_MAX;
469 *debugTrace = std::make_unique<SkSL::DebugTracePriv>();
472 if (settingsText.empty()) {
475 if (settingsText.length() == startingLength) {
476 printf(
"Unrecognized #pragma settings: %s\n", settingsText.c_str());
490 printf(
"usage: skslc <input> <output> <flags>\n"
491 " skslc <worklist>\n"
494 "--settings: honor embedded /*#pragma settings*/ comments.\n"
495 "--nosettings: ignore /*#pragma settings*/ comments\n");
499 if (
flag->has_value()) {
500 printf(
"%s flag was specified multiple times\n",
name);
511 std::optional<bool> honorSettings;
512 std::vector<std::string> paths;
513 for (
size_t i = 1;
i <
args.size(); ++
i) {
514 const std::string& arg =
args[
i];
515 if (arg ==
"--settings") {
516 if (!
set_flag(&honorSettings,
"settings",
true)) {
519 }
else if (arg ==
"--nosettings") {
520 if (!
set_flag(&honorSettings,
"settings",
false)) {
524 paths.push_back(arg);
530 if (paths.size() != 2) {
535 if (!honorSettings.has_value()) {
536 honorSettings =
true;
539 const std::string& inputPath = paths[0];
540 const std::string& outputPath = paths[1];
561 printf(
"input filename must end in '.vert', '.frag', '.mvert', '.mfrag', '.compute', "
562 "'.rtb', '.rtcf', '.rts', '.privrts', or '.sksl'\n");
566 std::ifstream in(inputPath);
567 std::string
text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
569 printf(
"error reading '%s'\n", inputPath.c_str());
575 std::unique_ptr<SkSL::DebugTracePriv> debugTrace;
576 if (*honorSettings) {
589 auto emitCompileError = [&](
const char* errorText) {
592 errorStream.
writeText(
"### Compilation failed:\n\n");
599 auto compileProgram = [&](
const auto& writeFn) ->
ResultCode {
602 if (!
out.isValid()) {
603 printf(
"error writing '%s'\n", outputPath.c_str());
607 if (!program || !writeFn(
compiler, caps, *program,
out)) {
609 emitCompileError(
compiler.errorText().c_str());
613 printf(
"error writing '%s'\n", outputPath.c_str());
619 auto compileProgramAsRuntimeShader = [&](
const auto& writeFn) ->
ResultCode {
621 emitCompileError(
"Runtime shaders do not support vertex programs\n");
628 return compileProgram(writeFn);
641 return compileProgram(
652 spvtools::SpirvTools
tools(SPV_ENV_VULKAN_1_0);
653 const std::string& spirv(assembly.
str());
654 std::string disassembly;
655 uint32_t
options = spvtools::SpirvTools::kDefaultDisassembleOption;
656 options |= SPV_BINARY_TO_TEXT_OPTION_INDENT;
657 if (!
tools.Disassemble((
const uint32_t*)spirv.data(),
664 out.write(disassembly.data(), disassembly.size());
668 return compileProgram(
674 return compileProgram(
680 return compileProgram(
686 return compileProgram(
700 compiler.errorReporter().
error({},
"code has no entrypoint");
703 bool wantTraceOps = (debugTrace !=
nullptr);
705 program, *
main->definition(), &skrpDebugTrace, wantTraceOps);
707 compiler.errorReporter().error({},
"code is not supported");
721 return std::string(
name) +
"_0";
726 return std::string(decl->
var()->
name());
729 void defineFunction(
const char* decl,
const char* body,
bool )
override {
730 fOutput += std::string(decl) +
'{' + body +
'}';
735 void defineStruct(
const char* definition)
override { fOutput += definition; }
737 void declareGlobal(
const char* declaration)
override { fOutput += declaration; }
739 std::string
sampleShader(
int index, std::string coords)
override {
740 return "child_" +
std::to_string(index) +
".eval(" + coords +
')';
752 return "toLinearSrgb(" +
color +
')';
755 return "fromLinearSrgb(" +
color +
')';
773 "_canvasColor", &callbacks);
778 printf(
"expected output path to end with one of: .glsl, .html, .metal, .hlsl, .wgsl, "
779 ".spirv, .asm.vert, .asm.frag, .asm.comp, .skrp, .stage (got '%s')\n",
793 std::vector<std::string>
args;
794 for (
int index=0; index<argc; ++index) {
ResultCode ProcessWorklist(const char *worklistPath, const std::function< ResultCode(SkSpan< std::string > args)> &processCommandFn)
static const SkSL::ShaderCaps * Version110()
static const SkSL::ShaderCaps * UsesPrecisionModifiers()
static const SkSL::ShaderCaps * NoExternalTextureSupport()
static const SkSL::ShaderCaps * CannotUseFractForNegativeValues()
static const SkSL::ShaderCaps * MustForceNegatedLdexpParamToMultiply()
static const SkSL::ShaderCaps * UnfoldShortCircuitAsTernary()
static const SkSL::ShaderCaps * AddAndTrueToLoopCondition()
static const SkSL::ShaderCaps * CannotUseVoidInSequenceExpressions()
static const SkSL::ShaderCaps * RewriteSwitchStatements()
static const SkSL::ShaderCaps * NoBuiltinDeterminantSupport()
static const SkSL::ShaderCaps * MustForceNegatedAtanParamToFloat()
static const SkSL::ShaderCaps * RemovePowWithConstantExponent()
static const SkSL::ShaderCaps * Version450Core()
static const SkSL::ShaderCaps * MustGuardDivisionEvenAfterExplicitZeroCheck()
static const SkSL::ShaderCaps * NoBuiltinFMASupport()
static const SkSL::ShaderCaps * SampleMaskSupport()
static const SkSL::ShaderCaps * ShaderDerivativeExtensionString()
static const SkSL::ShaderCaps * RewriteMatrixComparisons()
static const SkSL::ShaderCaps * CannotUseMinAndAbsTogether()
static const SkSL::ShaderCaps * RewriteDoWhileLoops()
static const SkSL::ShaderCaps * RewriteMatrixVectorMultiply()
static const SkSL::ShaderCaps * EmulateAbsIntFunction()
static const SkSL::ShaderCaps * FramebufferFetchSupport()
static const SkSL::ShaderCaps * CannotUseFragCoord()
static const SkSL::ShaderCaps * MustDeclareFragmentFrontFacing()
static const SkSL::ShaderCaps * DualSourceBlending()
void writeText(const char *s) override
virtual std::string sampleShader(int index, std::string coords)=0
virtual std::string sampleBlender(int index, std::string src, std::string dst)=0
virtual void defineStruct(const char *definition)=0
virtual void declareFunction(const char *declaration)=0
virtual std::string toLinearSrgb(std::string color)=0
virtual void declareGlobal(const char *declaration)=0
virtual std::string sampleColorFilter(int index, std::string color)=0
virtual std::string fromLinearSrgb(std::string color)=0
virtual void defineFunction(const char *declaration, const char *body, bool isMain)=0
virtual std::string declareUniform(const VarDeclaration *)=0
virtual std::string getMangledName(const char *name)
static const ShaderCaps * Standalone()
static std::unique_ptr< ShaderCaps > MakeShaderCaps()
const std::string & str() const
std::string_view name() const
std::string description() const override
virtual bool write(const void *buffer, size_t size)=0
virtual size_t bytesWritten() const =0
FlutterSemanticsFlag flag
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
size_t raster_pipeline_highp_stride
void ConvertProgram(const Program &program, const char *sampleCoords, const char *inputColor, const char *destColor, Callbacks *callbacks)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
bool ToSPIRV(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToWGSL(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToGLSL(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToMetal(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToHLSL(Program &program, const ShaderCaps *caps, OutputStream &out)
std::unique_ptr< RP::Program > MakeRasterPipelineProgram(const SkSL::Program &program, const FunctionDefinition &function, DebugTracePriv *debugTrace, bool writeTraceOps)
std::string PrettyPrint(const std::string &string)
SKSHAPER_API sk_sp< Factory > Factory()
DEF_SWITCHES_START aot vmservice shared library name
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
const myers::Point & get(const myers::Segment &)
constexpr bool starts_with(std::string_view str, std::string_view prefix)
constexpr bool ends_with(std::string_view str, std::string_view suffix)
static SkString to_string(int n)
int main(int argc, const char **argv)
const FunctionDeclaration * getFunction(const char *functionName) const
static std::unique_ptr< SkWStream > as_SkWStream(SkSL::OutputStream &s)
static ResultCode process_command(SkSpan< std::string > args)
static bool consume_suffix(std::string *str, const char suffix[])
void SkDebugf(const char format[],...)
static bool set_flag(std::optional< bool > *flag, const char *name, bool value)
static bool detect_shader_settings(const std::string &text, SkSL::ProgramSettings *settings, const SkSL::ShaderCaps **caps, std::unique_ptr< SkSL::DebugTracePriv > *debugTrace)