Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Naming
  • Loading branch information
bdero committed Dec 11, 2023
commit ea36c732c3992c0e4f5faa3e895b3e1bdbaa65fb
43 changes: 24 additions & 19 deletions impeller/compiler/impellerc_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,58 +50,63 @@ bool Main(const fml::CommandLine& command_line) {
if (!switches.iplr_bundle.empty()) {
auto json = nlohmann::json::parse(switches.iplr_bundle);
if (!json.is_object()) {
std::cerr << "The IPLR bundle spec must be a JSON object." << std::endl;
std::cerr << "The shader bundle must be a JSON object." << std::endl;
return false;
}

/// Bundle parsing.

IPLRBundleEntries bundle_entries_result;
for (auto& [bundle_name, bundle_value] : json.items()) {
if (!bundle_value.is_object()) {
std::cerr << "Invalid IPLR bundle entry \"" << bundle_name
std::cerr << "Invalid bundle entry \"" << bundle_name
<< "\": Entry is not a JSON object." << std::endl;
return false;
}

/// Shader parsing.

IPLRBundleEntry bundle_entry_result;
for (auto& [stage_name, stage_value] : bundle_value.items()) {
if (bundle_entry_result.find(stage_name) == bundle_entry_result.end()) {
std::cerr << "Duplicate IPLR bundle stage entry \"" << stage_name
<< "\" in bundle \"" << bundle_name << "\"." << std::endl;
for (auto& [shader_name, shader_value] : bundle_value.items()) {
if (bundle_entry_result.find(shader_name) ==
bundle_entry_result.end()) {
std::cerr << "Duplicate shader \"" << shader_name << "\" in bundle \""
<< bundle_name << "\"." << std::endl;
return false;
}
if (!bundle_value.is_object()) {
std::cerr << "Invalid IPLR bundle stage entry \"" << stage_name
std::cerr << "Invalid shader entry \"" << shader_name
<< "\" in bundle \"" << bundle_name
<< "\": Entry is not a JSON object." << std::endl;
return false;
}

IPLRStageEntry stage_result;
IPLRShaderEntry stage_result;

stage_result.language = stage_value.contains("language")
? ToSourceLanguage(stage_value["language"])
stage_result.language = shader_value.contains("language")
? ToSourceLanguage(shader_value["language"])
: SourceLanguage::kGLSL;
if (stage_result.language == SourceLanguage::kUnknown) {
std::cerr << "Invalid IPLR bundle stage entry \"" << stage_name
std::cerr << "Invalid shader entry \"" << shader_name
<< "\" in bundle \"" << bundle_name
<< "\": Unknown language type \"" << stage_value["language"]
<< "\"." << std::endl;
<< "\": Unknown language type \""
<< shader_value["language"] << "\"." << std::endl;
return false;
}

if (!stage_value.contains("name")) {
std::cerr << "Duplicate IPLR bundle stage entry \"" << stage_name
if (!shader_value.contains("name")) {
std::cerr << "Duplicate IPLR bundle stage entry \"" << shader_name
<< "\" in bundle \"" << bundle_name << "\": Entry ."
<< std::endl;
return false;
}
stage_result.source_file_name = stage_value["name"];
stage_result.source_file_name = shader_value["name"];

stage_result.entry_point = stage_value.contains("entry_point")
? stage_value["entry_point"]
stage_result.entry_point = shader_value.contains("entry_point")
? shader_value["entry_point"]
: "main";

bundle_entry_result[stage_name] = stage_result;
bundle_entry_result[shader_name] = stage_result;
}
bundle_entries_result[bundle_name] = bundle_entry_result;
}
Expand Down
5 changes: 3 additions & 2 deletions impeller/compiler/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ enum class SourceLanguage {
kHLSL,
};

struct IPLRStageEntry {
struct IPLRShaderEntry {
std::string source_file_name;
SourceType type;
SourceLanguage language;
std::string entry_point;
};

using IPLRBundleEntry = std::map<std::string, IPLRStageEntry>;
using IPLRBundleEntry = std::map<std::string, IPLRShaderEntry>;

using IPLRBundleEntries = std::map<std::string, IPLRBundleEntry>;

Expand Down