diff --git a/include/Nazara/Shader/Ast/AstCompare.inl b/include/Nazara/Shader/Ast/AstCompare.inl index 575735ab1..66ad7e59f 100644 --- a/include/Nazara/Shader/Ast/AstCompare.inl +++ b/include/Nazara/Shader/Ast/AstCompare.inl @@ -609,9 +609,6 @@ namespace Nz::ShaderAst inline bool Compare(const MultiStatement& lhs, const MultiStatement& rhs) { - if (!Compare(lhs.sectionName, rhs.sectionName)) - return false; - if (!Compare(lhs.statements, rhs.statements)) return false; diff --git a/include/Nazara/Shader/Ast/Nodes.hpp b/include/Nazara/Shader/Ast/Nodes.hpp index 95970687b..2e6921332 100644 --- a/include/Nazara/Shader/Ast/Nodes.hpp +++ b/include/Nazara/Shader/Ast/Nodes.hpp @@ -422,7 +422,6 @@ namespace Nz::ShaderAst NodeType GetType() const override; void Visit(AstStatementVisitor& visitor) override; - std::string sectionName; std::vector statements; }; diff --git a/src/Nazara/Shader/Ast/AstCloner.cpp b/src/Nazara/Shader/Ast/AstCloner.cpp index af4bb3677..5dfaf253b 100644 --- a/src/Nazara/Shader/Ast/AstCloner.cpp +++ b/src/Nazara/Shader/Ast/AstCloner.cpp @@ -236,7 +236,6 @@ namespace Nz::ShaderAst StatementPtr AstCloner::Clone(MultiStatement& node) { auto clone = std::make_unique(); - clone->sectionName = node.sectionName; clone->statements.reserve(node.statements.size()); for (auto& statement : node.statements) clone->statements.push_back(CloneStatement(statement)); diff --git a/src/Nazara/Shader/Ast/AstSerializer.cpp b/src/Nazara/Shader/Ast/AstSerializer.cpp index 83d3a92dd..c889d3492 100644 --- a/src/Nazara/Shader/Ast/AstSerializer.cpp +++ b/src/Nazara/Shader/Ast/AstSerializer.cpp @@ -347,8 +347,6 @@ namespace Nz::ShaderAst void AstSerializerBase::Serialize(MultiStatement& node) { - Value(node.sectionName); - Container(node.statements); for (auto& statement : node.statements) Node(statement); diff --git a/src/Nazara/Shader/Ast/SanitizeVisitor.cpp b/src/Nazara/Shader/Ast/SanitizeVisitor.cpp index f5d01152a..035d096b7 100644 --- a/src/Nazara/Shader/Ast/SanitizeVisitor.cpp +++ b/src/Nazara/Shader/Ast/SanitizeVisitor.cpp @@ -1536,7 +1536,6 @@ namespace Nz::ShaderAst StatementPtr SanitizeVisitor::Clone(MultiStatement& node) { auto clone = std::make_unique(); - clone->sectionName = node.sectionName; clone->statements.reserve(node.statements.size()); std::vector* previousList = m_context->currentStatementList; diff --git a/src/Nazara/Shader/GlslWriter.cpp b/src/Nazara/Shader/GlslWriter.cpp index 1369ca1ee..698c0eb11 100644 --- a/src/Nazara/Shader/GlslWriter.cpp +++ b/src/Nazara/Shader/GlslWriter.cpp @@ -205,13 +205,30 @@ namespace Nz targetModule->rootNode->Visit(state.previsitor); + if (!state.previsitor.entryPoint) + throw std::runtime_error("not entry point found"); + + assert(state.previsitor.entryPoint->entryStage.HasValue()); + m_currentState->stage = state.previsitor.entryPoint->entryStage.GetResultingValue(); + // Code generation AppendHeader(); for (const auto& importedModule : targetModule->importedModules) { + AppendComment("Module " + importedModule.module->metadata->moduleId.ToString()); + AppendLine(); + m_currentState->moduleSuffix = importedModule.identifier; importedModule.module->rootNode->Visit(*this); + + AppendLine(); + } + + if (!targetModule->importedModules.empty()) + { + AppendComment("Main file"); + AppendLine(); } m_currentState->moduleSuffix = {}; @@ -514,6 +531,21 @@ namespace Nz AppendLine(); AppendLine(); + // Comments + std::string fileTitle; + + assert(m_currentState->stage); + switch (*m_currentState->stage) + { + case ShaderStageType::Fragment: fileTitle += "fragment shader - "; break; + case ShaderStageType::Vertex: fileTitle += "vertex shader - "; break; + } + + fileTitle += "this file was generated by Nazara Engine"; + + AppendComment(fileTitle); + AppendLine(); + // Extensions std::vector requiredExtensions; @@ -1278,13 +1310,7 @@ namespace Nz void GlslWriter::Visit(ShaderAst::MultiStatement& node) { - if (!node.sectionName.empty()) - AppendComment(node.sectionName); - AppendStatementList(node.statements); - - if (!node.sectionName.empty()) - AppendComment("End: " + node.sectionName); } void GlslWriter::Visit(ShaderAst::NoOpStatement& /*node*/) diff --git a/src/Nazara/Shader/LangWriter.cpp b/src/Nazara/Shader/LangWriter.cpp index 866b6fa97..8e98e5a1f 100644 --- a/src/Nazara/Shader/LangWriter.cpp +++ b/src/Nazara/Shader/LangWriter.cpp @@ -1184,13 +1184,7 @@ namespace Nz void LangWriter::Visit(ShaderAst::MultiStatement& node) { - if (!node.sectionName.empty()) - AppendComment(node.sectionName); - AppendStatementList(node.statements); - - if (!node.sectionName.empty()) - AppendComment("End: " + node.sectionName); } void LangWriter::Visit(ShaderAst::NoOpStatement& /*node*/) diff --git a/tests/Engine/Shader/ModuleTests.cpp b/tests/Engine/Shader/ModuleTests.cpp index 196997eb5..8b2095b47 100644 --- a/tests/Engine/Shader/ModuleTests.cpp +++ b/tests/Engine/Shader/ModuleTests.cpp @@ -77,6 +77,8 @@ fn main(input: InputData) -> OutputData REQUIRE_NOTHROW(shaderModule = Nz::ShaderAst::Sanitize(*shaderModule, sanitizeOpt)); ExpectGLSL(*shaderModule, R"( +// Module ad3aed6e-0619-4a26-b5ce-abc2ec0836c4 + struct Data__181c45e9 { float value; @@ -97,6 +99,9 @@ struct OutputData__181c45e9 float value; }; +// Main file + + layout(std140) uniform _NzBinding_block { Data__181c45e9 data; @@ -277,15 +282,23 @@ fn main(input: InputData) -> OutputData REQUIRE_NOTHROW(shaderModule = Nz::ShaderAst::Sanitize(*shaderModule, sanitizeOpt)); ExpectGLSL(*shaderModule, R"( +// Module ad3aed6e-0619-4a26-b5ce-abc2ec0836c4 + struct Data__181c45e9 { float value; }; +// Module 7a548506-89e6-4944-897f-4f695a8bca01 + + struct Block__e528265d { Data__181c45e9 data; }; + +// Module e66c6e98-fc37-4390-a7e1-c81508ff8e49 + struct InputData__26cce136 { float value; @@ -296,6 +309,9 @@ struct OutputData__26cce136 float value; }; +// Main file + + layout(std140) uniform _NzBinding_block {