Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
impeller::compiler::CompilerSkSL Class Reference

#include <spirv_sksl.h>

Inheritance diagram for impeller::compiler::CompilerSkSL:

Public Member Functions

 CompilerSkSL (std::vector< uint32_t > spirv_)
 
 CompilerSkSL (const uint32_t *ir_, size_t word_count)
 
 CompilerSkSL (const spirv_cross::ParsedIR &ir_)
 
 CompilerSkSL (spirv_cross::ParsedIR &&ir_)
 
std::string compile () override
 

Private Member Functions

void emit_header () override
 
void emit_uniform (const spirv_cross::SPIRVariable &var) override
 
void emit_function_prototype (spirv_cross::SPIRFunction &func, const spirv_cross::Bitset &return_flags) override
 
std::string image_type_glsl (const spirv_cross::SPIRType &type, uint32_t id=0, bool member=false) override
 
std::string builtin_to_glsl (spv::BuiltIn builtin, spv::StorageClass storage) override
 
std::string to_texture_op (const spirv_cross::Instruction &i, bool sparse, bool *forward, spirv_cross::SmallVector< uint32_t > &inherited_expressions) override
 
std::string to_function_name (const spirv_cross::CompilerGLSL::TextureFunctionNameArguments &args) override
 
std::string to_function_args (const spirv_cross::CompilerGLSL::TextureFunctionArguments &args, bool *p_forward) override
 

Detailed Description

Definition at line 19 of file spirv_sksl.h.

Constructor & Destructor Documentation

◆ CompilerSkSL() [1/4]

impeller::compiler::CompilerSkSL::CompilerSkSL ( std::vector< uint32_t >  spirv_)
inlineexplicit

Definition at line 21 of file spirv_sksl.h.

22 : CompilerGLSL(std::move(spirv_)) {}

◆ CompilerSkSL() [2/4]

impeller::compiler::CompilerSkSL::CompilerSkSL ( const uint32_t *  ir_,
size_t  word_count 
)
inline

Definition at line 24 of file spirv_sksl.h.

25 : CompilerGLSL(ir_, word_count) {}

◆ CompilerSkSL() [3/4]

impeller::compiler::CompilerSkSL::CompilerSkSL ( const spirv_cross::ParsedIR &  ir_)
inlineexplicit

Definition at line 27 of file spirv_sksl.h.

28 : spirv_cross::CompilerGLSL(ir_) {}

◆ CompilerSkSL() [4/4]

impeller::compiler::CompilerSkSL::CompilerSkSL ( spirv_cross::ParsedIR &&  ir_)
inlineexplicit

Definition at line 30 of file spirv_sksl.h.

31 : spirv_cross::CompilerGLSL(std::move(ir_)) {}

Member Function Documentation

◆ builtin_to_glsl()

std::string impeller::compiler::CompilerSkSL::builtin_to_glsl ( spv::BuiltIn  builtin,
spv::StorageClass  storage 
)
overrideprivate

Definition at line 409 of file spirv_sksl.cc.

410 {
411 std::string gl_builtin = CompilerGLSL::builtin_to_glsl(builtin, storage);
412 switch (builtin) {
413 case BuiltInFragCoord:
414 return "flutter_FragCoord";
415 default:
416 FLUTTER_CROSS_THROW("Builtin '" + gl_builtin + "' is not supported.");
417 break;
418 }
419
420 return "???";
421}
#define FLUTTER_CROSS_THROW(x)
Definition spirv_sksl.cc:22

◆ compile()

std::string impeller::compiler::CompilerSkSL::compile ( )
override

Definition at line 24 of file spirv_sksl.cc.

24 {
25 ir.fixup_reserved_names();
26
27 if (get_execution_model() != ExecutionModelFragment) {
28 FLUTTER_CROSS_THROW("Only fragment shaders are supported.'");
29 return "";
30 }
31
32 options.es = false;
33 options.version = 100;
34 options.vulkan_semantics = false;
35 options.enable_420pack_extension = false;
36 options.flatten_multidimensional_arrays = true;
37
38 backend.allow_precision_qualifiers = false;
39 backend.basic_int16_type = "short";
40 backend.basic_int_type = "int";
41 backend.basic_uint16_type = "ushort";
42 backend.basic_uint_type = "uint";
43 backend.double_literal_suffix = false;
44 backend.float_literal_suffix = false;
45 backend.long_long_literal_suffix = false;
46 backend.needs_row_major_load_workaround = true;
47 backend.nonuniform_qualifier = "";
48 backend.support_precise_qualifier = false;
49 backend.uint32_t_literal_suffix = false;
50 backend.use_array_constructor = true;
51 backend.workgroup_size_is_hidden = true;
52
53 fixup_user_functions();
54
55 fixup_anonymous_struct_names();
56 fixup_type_alias();
57 reorder_type_alias();
58 build_function_control_flow_graphs_and_analyze();
59 fixup_image_load_store_access();
60 update_active_builtins();
61 analyze_image_and_sampler_usage();
62 analyze_interlocked_resource_usage();
63
64 uint32_t pass_count = 0;
65 do {
66 reset(pass_count);
67
68 // Move constructor for this type is broken on GCC 4.9 ...
69 buffer.reset();
70
72 emit_resources();
73
74 emit_function(get<SPIRFunction>(ir.default_entry_point), Bitset());
75
76 pass_count++;
77 } while (is_forcing_recompilation());
78
79 statement("half4 main(float2 iFragCoord)");
80 begin_scope();
81 statement(" flutter_FragCoord = float4(iFragCoord, 0, 0);");
82 statement(" FLT_main();");
83 statement(" return " + output_name_ + ";");
84 end_scope();
85
86 return buffer.str();
87}
const char * options
const char * backend
m reset()
static const uint8_t buffer[]

◆ emit_function_prototype()

void impeller::compiler::CompilerSkSL::emit_function_prototype ( spirv_cross::SPIRFunction &  func,
const spirv_cross::Bitset &  return_flags 
)
overrideprivate

Definition at line 371 of file spirv_sksl.cc.

372 {
373 // If this is not the entrypoint, then no special processsing for SkSL is
374 // required.
375 if (func.self != ir.default_entry_point) {
376 CompilerGLSL::emit_function_prototype(func, return_flags);
377 return;
378 }
379
380 auto& type = get<SPIRType>(func.return_type);
381 if (type.basetype != SPIRType::Void) {
383 "Return type of the entrypoint function must be 'void'");
384 }
385
386 if (func.arguments.size() != 0) {
388 "The entry point function should not acept any parameters.");
389 }
390
391 processing_entry_point = true;
392
393 // If this is the entrypoint of a fragment shader, then GLSL requires the
394 // prototype to be "void main()", and so it is safe to rewrite as
395 // "void FLT_main()".
396 statement("void FLT_main()");
397}

◆ emit_header()

void impeller::compiler::CompilerSkSL::emit_header ( )
overrideprivate

Definition at line 113 of file spirv_sksl.cc.

113 {
114 statement("// This SkSL shader is autogenerated by spirv-cross.");
115 statement("");
116 statement("float4 flutter_FragCoord;");
117 statement("");
118}

◆ emit_uniform()

void impeller::compiler::CompilerSkSL::emit_uniform ( const spirv_cross::SPIRVariable &  var)
overrideprivate

Definition at line 120 of file spirv_sksl.cc.

120 {
121 auto& type = get<SPIRType>(var.basetype);
122 if (type.basetype == SPIRType::UInt && is_legacy()) {
123 FLUTTER_CROSS_THROW("SkSL does not support unsigned integers: '" +
124 get_name(var.self) + "'");
125 }
126
127 add_resource_name(var.self);
128 statement(variable_decl(var), ";");
129
130 // The Flutter FragmentProgram implementation passes additional uniforms along
131 // with shader uniforms that encode the shader width and height.
132 if (type.basetype == SPIRType::SampledImage) {
133 std::string name = to_name(var.self);
134 statement("uniform half2 " + name + "_size;");
135 }
136}
const char * name
Definition fuchsia.cc:50

◆ image_type_glsl()

std::string impeller::compiler::CompilerSkSL::image_type_glsl ( const spirv_cross::SPIRType &  type,
uint32_t  id = 0,
bool  member = false 
)
overrideprivate

Definition at line 399 of file spirv_sksl.cc.

401 {
402 if (type.basetype != SPIRType::SampledImage || type.image.dim != Dim2D) {
403 FLUTTER_CROSS_THROW("Only sampler2D uniform image types are supported.");
404 return "???";
405 }
406 return "shader";
407}

◆ to_function_args()

std::string impeller::compiler::CompilerSkSL::to_function_args ( const spirv_cross::CompilerGLSL::TextureFunctionArguments &  args,
bool *  p_forward 
)
overrideprivate

Definition at line 442 of file spirv_sksl.cc.

443 {
444 std::string name = to_expression(args.base.img);
445
446 std::string glsl_args = CompilerGLSL::to_function_args(args, p_forward);
447 // SkSL only supports coordinates. All other arguments to texture are
448 // unsupported and will generate invalid SkSL.
449 if (args.grad_x || args.grad_y || args.lod || args.offset || args.sample ||
450 args.min_lod || args.sparse_texel || args.bias || args.component) {
452 "Only sampler and position arguments are supported in texture() "
453 "calls.");
454 }
455
456 // GLSL puts the shader as the first argument, but in SkSL the shader is
457 // implicitly passed as the reciever of the 'eval' method. Therefore, the
458 // shader is removed from the GLSL argument list.
459 std::string no_shader;
460 auto npos = glsl_args.find(", "); // The first ','.
461 if (npos != std::string::npos) {
462 no_shader = glsl_args.substr(npos + 1); // The string after the first ','.
463 }
464
465 if (no_shader.empty()) {
466 FLUTTER_CROSS_THROW("Unexpected shader sampling arguments: '(" + glsl_args +
467 ")'");
468 return "()";
469 }
470
471 return name + "_size * (" + no_shader + ")";
472}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ to_function_name()

std::string impeller::compiler::CompilerSkSL::to_function_name ( const spirv_cross::CompilerGLSL::TextureFunctionNameArguments &  args)
overrideprivate

Definition at line 436 of file spirv_sksl.cc.

437 {
438 std::string name = to_expression(args.base.img);
439 return name + ".eval";
440}

◆ to_texture_op()

std::string impeller::compiler::CompilerSkSL::to_texture_op ( const spirv_cross::Instruction &  i,
bool  sparse,
bool *  forward,
spirv_cross::SmallVector< uint32_t > &  inherited_expressions 
)
overrideprivate

Definition at line 423 of file spirv_sksl.cc.

427 {
428 auto op = static_cast<Op>(i.op);
429 if (op != OpImageSampleImplicitLod) {
430 FLUTTER_CROSS_THROW("Only simple shader sampling is supported.");
431 return "???";
432 }
433 return CompilerGLSL::to_texture_op(i, sparse, forward, inherited_expressions);
434}

The documentation for this class was generated from the following files: