diff --git a/engine/src/flutter/impeller/compiler/reflector.cc b/engine/src/flutter/impeller/compiler/reflector.cc index ef451f1b8e..3492c4ea6e 100644 --- a/engine/src/flutter/impeller/compiler/reflector.cc +++ b/engine/src/flutter/impeller/compiler/reflector.cc @@ -239,6 +239,8 @@ std::optional Reflector::GenerateTemplateArguments() const { }); } + root["bind_prototype"] = EmitBindPrototypes(shader_resources); + return root; } @@ -656,5 +658,54 @@ std::string Reflector::GetMemberNameAtIndex( return stream.str(); } +std::vector Reflector::ReflectBindPrototypes( + const spirv_cross::ShaderResources& resources) const { + std::vector prototypes; + for (const auto& sampled_image : resources.sampled_images) { + auto& proto = prototypes.emplace_back(BindPrototype{}); + proto.return_type = "void"; + proto.name = + SPrintF("Bind%s", ConvertToCamelCase(sampled_image.name).c_str()); + { + std::stringstream stream; + stream << "Bind combined image sampler for resource named " + << sampled_image.name << "."; + proto.docstring = stream.str(); + } + proto.args.push_back(BindPrototypeArgument{ + .type_name = "Command&", + .argument_name = "command", + }); + proto.args.push_back(BindPrototypeArgument{ + .type_name = "Texture&", + .argument_name = "texture", + }); + proto.args.push_back(BindPrototypeArgument{ + .type_name = "Sampler&", + .argument_name = "sampler", + }); + } + return prototypes; +} + +nlohmann::json::array_t Reflector::EmitBindPrototypes( + const spirv_cross::ShaderResources& resources) const { + const auto prototypes = ReflectBindPrototypes(resources); + nlohmann::json::array_t result; + for (const auto& res : prototypes) { + auto& item = result.emplace_back(nlohmann::json::object_t{}); + item["return_type"] = res.return_type; + item["name"] = res.name; + item["docstring"] = res.docstring; + auto& args = item["args"] = nlohmann::json::array_t{}; + for (const auto& arg : res.args) { + auto& json_arg = args.emplace_back(nlohmann::json::object_t{}); + json_arg["type_name"] = arg.type_name; + json_arg["argument_name"] = arg.argument_name; + } + } + return result; +} + } // namespace compiler } // namespace impeller diff --git a/engine/src/flutter/impeller/compiler/reflector.h b/engine/src/flutter/impeller/compiler/reflector.h index 615423675e..ee94d8afae 100644 --- a/engine/src/flutter/impeller/compiler/reflector.h +++ b/engine/src/flutter/impeller/compiler/reflector.h @@ -51,9 +51,21 @@ class Reflector { std::vector members; }; + struct BindPrototypeArgument { + std::string type_name; + std::string argument_name; + }; + + struct BindPrototype { + std::string name; + std::string return_type; + std::string docstring; + std::vector args; + }; + const Options options_; const std::shared_ptr ir_; - // TODO: There is no reason this needs to the MSL subtype. + // TODO(csg): There is no reason this needs to the MSL subtype. const std::shared_ptr compiler_; std::unique_ptr template_arguments_; std::shared_ptr reflection_header_; @@ -84,6 +96,12 @@ class Reflector { std::optional ReflectStructDefinition( const spirv_cross::TypeID& type_id) const; + std::vector ReflectBindPrototypes( + const spirv_cross::ShaderResources& resources) const; + + nlohmann::json::array_t EmitBindPrototypes( + const spirv_cross::ShaderResources& resources) const; + std::optional ReflectPerVertexStructDefinition( const spirv_cross::SmallVector& stage_inputs) const; @@ -99,6 +117,8 @@ class Reflector { std::vector ReadStructMembers( const spirv_cross::TypeID& type_id) const; + bool IsVertexShader() const; + FML_DISALLOW_COPY_AND_ASSIGN(Reflector); };