Handle a single input.
510 {
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)) {
518 }
519 } else if (arg == "--nosettings") {
520 if (!
set_flag(&honorSettings,
"settings",
false)) {
522 }
524 paths.push_back(arg);
525 } else {
528 }
529 }
530 if (paths.size() != 2) {
533 }
534
535 if (!honorSettings.has_value()) {
536 honorSettings = true;
537 }
538
539 const std::string& inputPath = paths[0];
540 const std::string& outputPath = paths[1];
560 } else {
561 printf(
"input filename must end in '.vert', '.frag', '.mvert', '.mfrag', '.compute', "
562 "'.rtb', '.rtcf', '.rts', '.privrts', or '.sksl'\n");
564 }
565
566 std::ifstream in(inputPath);
567 std::string
text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
568 if (in.rdstate()) {
569 printf(
"error reading '%s'\n", inputPath.c_str());
571 }
572
575 std::unique_ptr<SkSL::DebugTracePriv> debugTrace;
576 if (*honorSettings) {
579 }
580 }
581
582
583
584
588
589 auto emitCompileError = [&](const char* errorText) {
590
592 errorStream.writeText("### Compilation failed:\n\n");
593 errorStream.writeText(errorText);
594 errorStream.close();
595
596 puts(errorText);
597 };
598
599 auto compileProgram = [&](
const auto& writeFn) ->
ResultCode {
602 if (!
out.isValid()) {
603 printf(
"error writing '%s'\n", outputPath.c_str());
605 }
607 if (!program || !writeFn(
compiler, caps, *program,
out)) {
609 emitCompileError(
compiler.errorText().c_str());
611 }
613 printf(
"error writing '%s'\n", outputPath.c_str());
615 }
617 };
618
619 auto compileProgramAsRuntimeShader = [&](
const auto& writeFn) ->
ResultCode {
621 emitCompileError("Runtime shaders do not support vertex programs\n");
623 }
625
627 }
628 return compileProgram(writeFn);
629 };
630
637 });
641 return compileProgram(
646
649 return false;
650 }
651
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(),
658 spirv.size() / 4,
659 &disassembly,
661 return false;
662 }
663
664 out.write(disassembly.data(), disassembly.size());
665 return true;
666 });
668 return compileProgram(
674 return compileProgram(
680 return compileProgram(
686 return compileProgram(
700 compiler.errorReporter().
error({},
"code has no entrypoint");
701 return false;
702 }
703 bool wantTraceOps = (debugTrace != nullptr);
705 program, *
main->definition(), &skrpDebugTrace, wantTraceOps);
706 if (!rasterProg) {
707 compiler.errorReporter().error({},
"code is not supported");
708 return false;
709 }
711 return true;
712 });
719 public:
721 return std::string(
name) +
"_0";
722 }
723
726 return std::string(decl->
var()->
name());
727 }
728
729 void defineFunction(
const char* decl,
const char* body,
bool )
override {
730 fOutput += std::string(decl) + '{' + body + '}';
731 }
732
734
735 void defineStruct(
const char* definition)
override { fOutput += definition; }
736
737 void declareGlobal(
const char* declaration)
override { fOutput += declaration; }
738
739 std::string
sampleShader(
int index, std::string coords)
override {
740 return "child_" +
std::to_string(index) +
".eval(" + coords +
')';
741 }
742
745 }
746
749 }
750
752 return "toLinearSrgb(" +
color +
')';
753 }
755 return "fromLinearSrgb(" +
color +
')';
756 }
757
758 std::string fOutput;
759 };
760
761
762
763
764
765
766
767
768
769
770
771 Callbacks callbacks;
773 "_canvasColor", &callbacks);
775 return true;
776 });
777 } else {
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",
780 outputPath.c_str());
782 }
784}
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()
const std::string & str() const
std::string_view name() const
std::string description() const override
const uint8_t uint32_t uint32_t GError ** error
void ConvertProgram(const Program &program, const char *sampleCoords, const char *inputColor, const char *destColor, Callbacks *callbacks)
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)
DEF_SWITCHES_START aot vmservice shared library name
const myers::Point & get(const myers::Segment &)
constexpr bool starts_with(std::string_view str, std::string_view prefix)
static SkString to_string(int n)
const FunctionDeclaration * getFunction(const char *functionName) const
static std::unique_ptr< SkWStream > as_SkWStream(SkSL::OutputStream &s)
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)