Shader: Fix import of already compiled module

This commit is contained in:
SirLynix 2022-04-19 18:30:40 +02:00
parent 993f4e7c78
commit 36e5356c22
1 changed files with 10 additions and 1 deletions

View File

@ -1752,8 +1752,17 @@ namespace Nz::ShaderAst
ModulePtr sanitizedModule = std::make_shared<Module>(targetModule->metadata);
// Remap already used indices
IndexRemapperVisitor::Callbacks indexCallbacks;
indexCallbacks.constIndexGenerator = [this](std::size_t /*previousIndex*/) { return m_context->constantValues.RegisterNewIndex(true); };
indexCallbacks.funcIndexGenerator = [this](std::size_t /*previousIndex*/) { return m_context->functions.RegisterNewIndex(true); };
indexCallbacks.structIndexGenerator = [this](std::size_t /*previousIndex*/) { return m_context->structs.RegisterNewIndex(true); };
indexCallbacks.varIndexGenerator = [this](std::size_t /*previousIndex*/) { return m_context->variableTypes.RegisterNewIndex(true); };
sanitizedModule->rootNode = StaticUniquePointerCast<MultiStatement>(RemapIndices(*targetModule->rootNode, indexCallbacks));
std::string error;
sanitizedModule->rootNode = SanitizeInternal(*targetModule->rootNode, &error);
sanitizedModule->rootNode = SanitizeInternal(*sanitizedModule->rootNode, &error);
if (!sanitizedModule->rootNode)
throw ShaderLang::CompilerModuleCompilationFailedError{ node.sourceLocation, node.moduleName, error };