Shader: Many fixes

This commit is contained in:
Jérôme Leclercq
2022-03-04 18:23:01 +01:00
parent 1919bd3302
commit a2f4f3c802
13 changed files with 161 additions and 84 deletions

View File

@@ -20,8 +20,13 @@ namespace Nz::ShaderAst
struct Module
{
struct Metadata
{
UInt32 shaderLangVersion;
};
std::shared_ptr<const Metadata> metadata;
MultiStatementPtr rootNode;
UInt32 shaderLangVersion;
};
}

View File

@@ -45,7 +45,6 @@ namespace Nz
struct EntryAttribute;
struct LayoutAttribute;
struct LocationAttribute;
struct NzslAttribute;
struct SetAttribute;
struct UnrollAttribute;
@@ -76,7 +75,6 @@ namespace Nz
void AppendAttribute(EntryAttribute entry);
void AppendAttribute(LayoutAttribute layout);
void AppendAttribute(LocationAttribute location);
void AppendAttribute(NzslAttribute nzslVersion);
void AppendAttribute(SetAttribute set);
void AppendAttribute(UnrollAttribute unroll);
void AppendCommentSection(const std::string& section);

View File

@@ -97,7 +97,7 @@ namespace Nz::ShaderBuilder
struct DeclareStruct
{
inline std::unique_ptr<ShaderAst::DeclareStructStatement> operator()(ShaderAst::StructDescription description) const;
inline std::unique_ptr<ShaderAst::DeclareStructStatement> operator()(ShaderAst::StructDescription description, ShaderAst::ExpressionValue<bool> isExported) const;
};
struct DeclareVariable

View File

@@ -189,6 +189,7 @@ namespace Nz::ShaderBuilder
case ShaderAst::PrimitiveType::Float32: return ShaderBuilder::Constant(SafeCast<float>(value));
case ShaderAst::PrimitiveType::Int32: return ShaderBuilder::Constant(SafeCast<Int32>(value));
case ShaderAst::PrimitiveType::UInt32: return ShaderBuilder::Constant(SafeCast<UInt32>(value));
case ShaderAst::PrimitiveType::String: return ShaderBuilder::Constant(value);
}
throw std::runtime_error("unexpected primitive type");
@@ -269,10 +270,11 @@ namespace Nz::ShaderBuilder
return declareOptionNode;
}
inline std::unique_ptr<ShaderAst::DeclareStructStatement> Impl::DeclareStruct::operator()(ShaderAst::StructDescription description) const
inline std::unique_ptr<ShaderAst::DeclareStructStatement> Impl::DeclareStruct::operator()(ShaderAst::StructDescription description, ShaderAst::ExpressionValue<bool> isExported) const
{
auto declareStructNode = std::make_unique<ShaderAst::DeclareStructStatement>();
declareStructNode->description = std::move(description);
declareStructNode->isExported = std::move(isExported);
return declareStructNode;
}

View File

@@ -82,6 +82,7 @@ namespace Nz::ShaderLang
const Token& Peek(std::size_t advance = 0);
std::vector<ShaderAst::ExprValue> ParseAttributes();
void ParseModuleStatement(std::vector<ShaderAst::ExprValue> attributes);
void ParseVariableDeclaration(std::string& name, ShaderAst::ExpressionValue<ShaderAst::ExpressionType>& type, ShaderAst::ExpressionPtr& initialValue);
// Statements
@@ -93,7 +94,6 @@ namespace Nz::ShaderLang
std::vector<ShaderAst::StatementPtr> ParseFunctionBody();
ShaderAst::StatementPtr ParseFunctionDeclaration(std::vector<ShaderAst::ExprValue> attributes = {});
ShaderAst::DeclareFunctionStatement::Parameter ParseFunctionParameter();
void ParseModuleStatement(std::vector<ShaderAst::ExprValue> attributes);
ShaderAst::StatementPtr ParseOptionDeclaration();
ShaderAst::StatementPtr ParseReturnStatement();
ShaderAst::StatementPtr ParseRootStatement(std::vector<ShaderAst::ExprValue> attributes = {});