src/core/SkShaderCodeDictionary.cpp
std::string SkShaderInfo::toSkSL() const {
    // The uniforms are mangled by having their index in 'fEntries' as a suffix (i.e., "_%d")
    std::string result = skgpu::graphite::GetMtlUniforms(2, "FS", fBlockReaders);

    int binding = 0;
    result += skgpu::graphite::GetMtlTexturesAndSamplers(fBlockReaders, &binding);
    result += "layout(location = 0, index = 0) out half4 sk_FragColor;\n";
    result += "void main() {\n";

    std::string lastOutputVar = "initialColor";

    // TODO: what is the correct initial color to feed in?
    add_indent(&result, 1);
    SkSL::String::appendf(&result, "    half4 %s = half4(0.0);", lastOutputVar.c_str());

    for (int entryIndex = 0; entryIndex < (int) fBlockReaders.size(); ++entryIndex) {
        lastOutputVar = this->emitGlueCodeForEntry(&entryIndex, lastOutputVar, &result, 1);
    }

    SkSL::String::appendf(&result, "    sk_FragColor = %s;\n", lastOutputVar.c_str());
    result += "}\n";

    return result;
}
// The current, incomplete, model for shader construction is:
//   each static code snippet (which can have an arbitrary signature) gets emitted once as a
//            preamble
//   glue code is then generated w/in the "main" method. The glue code is responsible for:
//            1) gathering the correct (mangled) uniforms
//            2) passing the uniforms and any other parameters to the helper method
//   The result of the last code snippet is then copied into "sk_FragColor".
// Note: that each entry's 'fStaticFunctionName' field must match the name of a function in the
// Graphite pre-compiled module, located at `src/sksl/sksl_graphite_frag.sksl`.
The current, incomplete, model for shader construction is:
each static code snippet (which can have an arbitrary signature) gets emitted once as a
preamble
glue code is then generated w/in the "main" method. The glue code is responsible for:
1) gathering the correct (mangled) uniforms
2) passing the uniforms and any other parameters to the helper method
The result of the last code snippet is then copied into "sk_FragColor".
Note: that each entry's 'fStaticFunctionName' field must match the name of a function in the
Graphite pre-compiled module, located at `src/sksl/sksl_graphite_frag.sksl`.
The current incomplete model for shader construction is : each static code snippet ( which can have an arbitrary signature ) gets emitted once as a preamble glue code is then generated w / in the " main " method . The glue code is responsible for : 1 ) gathering the correct ( mangled ) uniforms 2 ) passing the uniforms and any other parameters to the helper method The result of the last code snippet is then copied into " sk_FragColor " . Note : that each entry ' s ' fStaticFunctionName ' field must match the name of a function in the Graphite pre - compiled module located at ` src / sksl / sksl_graphite_frag . sksl ` .
std::string SkShaderInfo::toSkSL() const {
    std::string result = skgpu::graphite::GetMtlUniforms(2, "FS", fBlockReaders);
    int binding = 0;
    result += skgpu::graphite::GetMtlTexturesAndSamplers(fBlockReaders, &binding);
    result += "layout(location = 0, index = 0) out half4 sk_FragColor;\n";
    result += "void main() {\n";
    std::string lastOutputVar = "initialColor";
    add_indent(&result, 1);
    SkSL::String::appendf(&result, "    half4 %s = half4(0.0);", lastOutputVar.c_str());
    for (int entryIndex = 0; entryIndex < (int) fBlockReaders.size(); ++entryIndex) {
        lastOutputVar = this->emitGlueCodeForEntry(&entryIndex, lastOutputVar, &result, 1);
    }
    SkSL::String::appendf(&result, "    sk_FragColor = %s;\n", lastOutputVar.c_str());
    result += "}\n";
    return result;
}
std :: string SkShaderInfo :: toSkSL ( ) const { std :: string result = skgpu :: graphite :: GetMtlUniforms ( 2 , " " , fBlockReaders ) ; int binding = 0 ; result += skgpu :: graphite :: GetMtlTexturesAndSamplers ( fBlockReaders , & binding ) ; result += " \n " ; result += " \n " ; std :: string lastOutputVar = " " ; add_indent ( & result , 1 ) ; SkSL :: String :: appendf ( & result , " " , lastOutputVar . c_str ( ) ) ; for ( int entryIndex = 0 ; entryIndex < ( int ) fBlockReaders . size ( ) ; ++ entryIndex ) { lastOutputVar = this -> emitGlueCodeForEntry ( & entryIndex , lastOutputVar , & result , 1 ) ; } SkSL :: String :: appendf ( & result , " \n " , lastOutputVar . c_str ( ) ) ; result += " \n " ; return result ; }
The current, incomplete, model for shader construction is:
each static code snippet (which can have an arbitrary signature) gets emitted once as a
preamble
glue code is then generated w/in the "main" method.
The current incomplete model for shader construction is : each static code snippet ( which can have an arbitrary signature ) gets emitted once as a preamble glue code is then generated w / in the " main " method .
// The uniforms are mangled by having their index in 'fEntries' as a suffix (i.e., "_%d") // TODO: what is the correct initial color to feed in?