Shader/MultiStatement: Remove sectionName

This commit is contained in:
Jérôme Leclercq 2022-03-12 16:23:13 +01:00
parent b595a5d4ec
commit 5a9a55ee7e
8 changed files with 48 additions and 20 deletions

View File

@ -609,9 +609,6 @@ namespace Nz::ShaderAst
inline bool Compare(const MultiStatement& lhs, const MultiStatement& rhs) inline bool Compare(const MultiStatement& lhs, const MultiStatement& rhs)
{ {
if (!Compare(lhs.sectionName, rhs.sectionName))
return false;
if (!Compare(lhs.statements, rhs.statements)) if (!Compare(lhs.statements, rhs.statements))
return false; return false;

View File

@ -422,7 +422,6 @@ namespace Nz::ShaderAst
NodeType GetType() const override; NodeType GetType() const override;
void Visit(AstStatementVisitor& visitor) override; void Visit(AstStatementVisitor& visitor) override;
std::string sectionName;
std::vector<StatementPtr> statements; std::vector<StatementPtr> statements;
}; };

View File

@ -236,7 +236,6 @@ namespace Nz::ShaderAst
StatementPtr AstCloner::Clone(MultiStatement& node) StatementPtr AstCloner::Clone(MultiStatement& node)
{ {
auto clone = std::make_unique<MultiStatement>(); auto clone = std::make_unique<MultiStatement>();
clone->sectionName = node.sectionName;
clone->statements.reserve(node.statements.size()); clone->statements.reserve(node.statements.size());
for (auto& statement : node.statements) for (auto& statement : node.statements)
clone->statements.push_back(CloneStatement(statement)); clone->statements.push_back(CloneStatement(statement));

View File

@ -347,8 +347,6 @@ namespace Nz::ShaderAst
void AstSerializerBase::Serialize(MultiStatement& node) void AstSerializerBase::Serialize(MultiStatement& node)
{ {
Value(node.sectionName);
Container(node.statements); Container(node.statements);
for (auto& statement : node.statements) for (auto& statement : node.statements)
Node(statement); Node(statement);

View File

@ -1536,7 +1536,6 @@ namespace Nz::ShaderAst
StatementPtr SanitizeVisitor::Clone(MultiStatement& node) StatementPtr SanitizeVisitor::Clone(MultiStatement& node)
{ {
auto clone = std::make_unique<MultiStatement>(); auto clone = std::make_unique<MultiStatement>();
clone->sectionName = node.sectionName;
clone->statements.reserve(node.statements.size()); clone->statements.reserve(node.statements.size());
std::vector<StatementPtr>* previousList = m_context->currentStatementList; std::vector<StatementPtr>* previousList = m_context->currentStatementList;

View File

@ -205,13 +205,30 @@ namespace Nz
targetModule->rootNode->Visit(state.previsitor); 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 // Code generation
AppendHeader(); AppendHeader();
for (const auto& importedModule : targetModule->importedModules) for (const auto& importedModule : targetModule->importedModules)
{ {
AppendComment("Module " + importedModule.module->metadata->moduleId.ToString());
AppendLine();
m_currentState->moduleSuffix = importedModule.identifier; m_currentState->moduleSuffix = importedModule.identifier;
importedModule.module->rootNode->Visit(*this); importedModule.module->rootNode->Visit(*this);
AppendLine();
}
if (!targetModule->importedModules.empty())
{
AppendComment("Main file");
AppendLine();
} }
m_currentState->moduleSuffix = {}; m_currentState->moduleSuffix = {};
@ -514,6 +531,21 @@ namespace Nz
AppendLine(); AppendLine();
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 // Extensions
std::vector<std::string> requiredExtensions; std::vector<std::string> requiredExtensions;
@ -1278,13 +1310,7 @@ namespace Nz
void GlslWriter::Visit(ShaderAst::MultiStatement& node) void GlslWriter::Visit(ShaderAst::MultiStatement& node)
{ {
if (!node.sectionName.empty())
AppendComment(node.sectionName);
AppendStatementList(node.statements); AppendStatementList(node.statements);
if (!node.sectionName.empty())
AppendComment("End: " + node.sectionName);
} }
void GlslWriter::Visit(ShaderAst::NoOpStatement& /*node*/) void GlslWriter::Visit(ShaderAst::NoOpStatement& /*node*/)

View File

@ -1184,13 +1184,7 @@ namespace Nz
void LangWriter::Visit(ShaderAst::MultiStatement& node) void LangWriter::Visit(ShaderAst::MultiStatement& node)
{ {
if (!node.sectionName.empty())
AppendComment(node.sectionName);
AppendStatementList(node.statements); AppendStatementList(node.statements);
if (!node.sectionName.empty())
AppendComment("End: " + node.sectionName);
} }
void LangWriter::Visit(ShaderAst::NoOpStatement& /*node*/) void LangWriter::Visit(ShaderAst::NoOpStatement& /*node*/)

View File

@ -77,6 +77,8 @@ fn main(input: InputData) -> OutputData
REQUIRE_NOTHROW(shaderModule = Nz::ShaderAst::Sanitize(*shaderModule, sanitizeOpt)); REQUIRE_NOTHROW(shaderModule = Nz::ShaderAst::Sanitize(*shaderModule, sanitizeOpt));
ExpectGLSL(*shaderModule, R"( ExpectGLSL(*shaderModule, R"(
// Module ad3aed6e-0619-4a26-b5ce-abc2ec0836c4
struct Data__181c45e9 struct Data__181c45e9
{ {
float value; float value;
@ -97,6 +99,9 @@ struct OutputData__181c45e9
float value; float value;
}; };
// Main file
layout(std140) uniform _NzBinding_block layout(std140) uniform _NzBinding_block
{ {
Data__181c45e9 data; Data__181c45e9 data;
@ -277,15 +282,23 @@ fn main(input: InputData) -> OutputData
REQUIRE_NOTHROW(shaderModule = Nz::ShaderAst::Sanitize(*shaderModule, sanitizeOpt)); REQUIRE_NOTHROW(shaderModule = Nz::ShaderAst::Sanitize(*shaderModule, sanitizeOpt));
ExpectGLSL(*shaderModule, R"( ExpectGLSL(*shaderModule, R"(
// Module ad3aed6e-0619-4a26-b5ce-abc2ec0836c4
struct Data__181c45e9 struct Data__181c45e9
{ {
float value; float value;
}; };
// Module 7a548506-89e6-4944-897f-4f695a8bca01
struct Block__e528265d struct Block__e528265d
{ {
Data__181c45e9 data; Data__181c45e9 data;
}; };
// Module e66c6e98-fc37-4390-a7e1-c81508ff8e49
struct InputData__26cce136 struct InputData__26cce136
{ {
float value; float value;
@ -296,6 +309,9 @@ struct OutputData__26cce136
float value; float value;
}; };
// Main file
layout(std140) uniform _NzBinding_block layout(std140) uniform _NzBinding_block
{ {