Shader: Change module system (no longer based on path)

This commit is contained in:
Jérôme Leclercq
2022-03-13 15:07:43 +01:00
parent 80f9556f8c
commit e40e8eb204
40 changed files with 224 additions and 271 deletions

View File

@@ -228,7 +228,7 @@ namespace Nz::ShaderAst
StatementPtr AstCloner::Clone(ImportStatement& node)
{
auto clone = std::make_unique<ImportStatement>();
clone->modulePath = node.modulePath;
clone->moduleName = node.moduleName;
return clone;
}

View File

@@ -340,9 +340,7 @@ namespace Nz::ShaderAst
void AstSerializerBase::Serialize(ImportStatement& node)
{
Container(node.modulePath);
for (auto& path : node.modulePath)
Value(path);
Value(node.moduleName);
}
void AstSerializerBase::Serialize(MultiStatement& node)
@@ -385,6 +383,7 @@ namespace Nz::ShaderAst
void ShaderAstSerializer::SerializeModule(ModulePtr& module)
{
m_stream << module->metadata->moduleName;
m_stream << module->metadata->moduleId;
m_stream << module->metadata->shaderLangVersion;
@@ -604,6 +603,7 @@ namespace Nz::ShaderAst
void ShaderAstUnserializer::SerializeModule(ModulePtr& module)
{
std::shared_ptr<Module::Metadata> metadata = std::make_shared<Module::Metadata>();
m_stream >> metadata->moduleName;
m_stream >> metadata->moduleId;
m_stream >> metadata->shaderLangVersion;

View File

@@ -1448,27 +1448,9 @@ namespace Nz::ShaderAst
if (!m_context->options.moduleResolver)
return static_unique_pointer_cast<ImportStatement>(AstCloner::Clone(node));
auto ModulePathAsString = [&]() -> std::string
{
std::ostringstream ss;
bool first = true;
for (const std::string& part : node.modulePath)
{
if (!first)
ss << "/";
ss << part;
first = false;
}
return ss.str();
};
ModulePtr targetModule = m_context->options.moduleResolver->Resolve(node.modulePath);
ModulePtr targetModule = m_context->options.moduleResolver->Resolve(node.moduleName);
if (!targetModule)
throw AstError{ "module " + ModulePathAsString() + " not found" };
throw AstError{ "module " + node.moduleName + " not found" };
std::size_t moduleIndex;
@@ -1500,7 +1482,7 @@ namespace Nz::ShaderAst
std::string error;
sanitizedModule->rootNode = SanitizeInternal(*targetModule->rootNode, &error);
if (!sanitizedModule)
throw AstError{ "module " + ModulePathAsString() + " compilation failed: " + error };
throw AstError{ "module " + node.moduleName + " compilation failed: " + error };
moduleIndex = m_context->modules.size();