Start working on the bind prototypes.

This commit is contained in:
Chinmay Garde
2021-07-10 17:59:13 -07:00
committed by Dan Field
parent 0bcd04b68f
commit 8926870817
2 changed files with 72 additions and 1 deletions

View File

@@ -239,6 +239,8 @@ std::optional<nlohmann::json> 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::BindPrototype> Reflector::ReflectBindPrototypes(
const spirv_cross::ShaderResources& resources) const {
std::vector<BindPrototype> 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

View File

@@ -51,9 +51,21 @@ class Reflector {
std::vector<StructMember> 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<BindPrototypeArgument> args;
};
const Options options_;
const std::shared_ptr<const spirv_cross::ParsedIR> 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<const spirv_cross::CompilerMSL> compiler_;
std::unique_ptr<const nlohmann::json> template_arguments_;
std::shared_ptr<fml::Mapping> reflection_header_;
@@ -84,6 +96,12 @@ class Reflector {
std::optional<StructDefinition> ReflectStructDefinition(
const spirv_cross::TypeID& type_id) const;
std::vector<BindPrototype> ReflectBindPrototypes(
const spirv_cross::ShaderResources& resources) const;
nlohmann::json::array_t EmitBindPrototypes(
const spirv_cross::ShaderResources& resources) const;
std::optional<StructDefinition> ReflectPerVertexStructDefinition(
const spirv_cross::SmallVector<spirv_cross::Resource>& stage_inputs)
const;
@@ -99,6 +117,8 @@ class Reflector {
std::vector<StructMember> ReadStructMembers(
const spirv_cross::TypeID& type_id) const;
bool IsVertexShader() const;
FML_DISALLOW_COPY_AND_ASSIGN(Reflector);
};