Shader: Replace const for with [unroll] attribute
This commit is contained in:
@@ -460,10 +460,10 @@ namespace Nz::ShaderAst
|
||||
|
||||
bool Compare(const ForEachStatement& lhs, const ForEachStatement& rhs)
|
||||
{
|
||||
if (!Compare(lhs.isConst, rhs.isConst))
|
||||
if (!Compare(lhs.varName, rhs.varName))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.varName, rhs.varName))
|
||||
if (!Compare(lhs.unroll, rhs.unroll))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.expression, rhs.expression))
|
||||
@@ -498,6 +498,9 @@ namespace Nz::ShaderAst
|
||||
|
||||
inline bool Compare(const WhileStatement& lhs, const WhileStatement& rhs)
|
||||
{
|
||||
if (!Compare(lhs.unroll, rhs.unroll))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.condition, rhs.condition))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Nz
|
||||
Layout, //< Struct layout (struct only) - has argument style
|
||||
Location, //< Location (struct member only) - has argument index
|
||||
Set, //< Binding set (external var only) - has argument index
|
||||
Unroll, //< Unroll (for/for each only) - has argument mode
|
||||
};
|
||||
|
||||
enum class BinaryType
|
||||
@@ -106,6 +107,13 @@ namespace Nz
|
||||
SampleTexture = 2,
|
||||
};
|
||||
|
||||
enum class LoopUnroll
|
||||
{
|
||||
Always,
|
||||
Hint,
|
||||
Never
|
||||
};
|
||||
|
||||
enum class MemoryLayout
|
||||
{
|
||||
Std140
|
||||
|
||||
@@ -345,11 +345,11 @@ namespace Nz::ShaderAst
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
AttributeValue<LoopUnroll> unroll;
|
||||
std::optional<std::size_t> varIndex;
|
||||
std::string varName;
|
||||
ExpressionPtr expression;
|
||||
StatementPtr statement;
|
||||
bool isConst = false;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API MultiStatement : Statement
|
||||
@@ -379,6 +379,7 @@ namespace Nz::ShaderAst
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
AttributeValue<LoopUnroll> unroll;
|
||||
ExpressionPtr condition;
|
||||
StatementPtr body;
|
||||
};
|
||||
|
||||
@@ -118,6 +118,8 @@ namespace Nz::ShaderAst
|
||||
|
||||
void SanitizeIdentifier(std::string& identifier);
|
||||
|
||||
void Validate(WhileStatement& node);
|
||||
|
||||
void Validate(AccessIndexExpression& node);
|
||||
void Validate(AssignExpression& node);
|
||||
void Validate(BinaryExpression& node);
|
||||
|
||||
@@ -108,7 +108,6 @@ namespace Nz::ShaderBuilder
|
||||
inline std::unique_ptr<ShaderAst::ExpressionStatement> operator()(ShaderAst::ExpressionPtr expression) const;
|
||||
};
|
||||
|
||||
template<bool Const>
|
||||
struct ForEach
|
||||
{
|
||||
inline std::unique_ptr<ShaderAst::ForEachStatement> operator()(std::string varName, ShaderAst::ExpressionPtr expression, ShaderAst::StatementPtr statement) const;
|
||||
@@ -173,7 +172,6 @@ namespace Nz::ShaderBuilder
|
||||
constexpr Impl::ConditionalStatement ConditionalStatement;
|
||||
constexpr Impl::Constant Constant;
|
||||
constexpr Impl::Branch<true> ConstBranch;
|
||||
constexpr Impl::ForEach<false> ConstForEach;
|
||||
constexpr Impl::DeclareConst DeclareConst;
|
||||
constexpr Impl::DeclareFunction DeclareFunction;
|
||||
constexpr Impl::DeclareOption DeclareOption;
|
||||
@@ -181,7 +179,7 @@ namespace Nz::ShaderBuilder
|
||||
constexpr Impl::DeclareVariable DeclareVariable;
|
||||
constexpr Impl::ExpressionStatement ExpressionStatement;
|
||||
constexpr Impl::NoParam<ShaderAst::DiscardStatement> Discard;
|
||||
constexpr Impl::ForEach<false> ForEach;
|
||||
constexpr Impl::ForEach ForEach;
|
||||
constexpr Impl::Identifier Identifier;
|
||||
constexpr Impl::Intrinsic Intrinsic;
|
||||
constexpr Impl::Multi MultiStatement;
|
||||
|
||||
@@ -269,11 +269,9 @@ namespace Nz::ShaderBuilder
|
||||
return expressionStatementNode;
|
||||
}
|
||||
|
||||
template<bool Const>
|
||||
std::unique_ptr<ShaderAst::ForEachStatement> Impl::ForEach<Const>::operator()(std::string varName, ShaderAst::ExpressionPtr expression, ShaderAst::StatementPtr statement) const
|
||||
std::unique_ptr<ShaderAst::ForEachStatement> Impl::ForEach::operator()(std::string varName, ShaderAst::ExpressionPtr expression, ShaderAst::StatementPtr statement) const
|
||||
{
|
||||
auto forEachNode = std::make_unique<ShaderAst::ForEachStatement>();
|
||||
forEachNode->isConst = Const;
|
||||
forEachNode->expression = std::move(expression);
|
||||
forEachNode->statement = std::move(statement);
|
||||
forEachNode->varName = std::move(varName);
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace Nz::ShaderLang
|
||||
ShaderAst::StatementPtr ParseConstStatement();
|
||||
ShaderAst::StatementPtr ParseDiscardStatement();
|
||||
ShaderAst::StatementPtr ParseExternalBlock(std::vector<ShaderAst::Attribute> attributes = {});
|
||||
ShaderAst::StatementPtr ParseForDeclaration();
|
||||
ShaderAst::StatementPtr ParseForDeclaration(std::vector<ShaderAst::Attribute> attributes = {});
|
||||
std::vector<ShaderAst::StatementPtr> ParseFunctionBody();
|
||||
ShaderAst::StatementPtr ParseFunctionDeclaration(std::vector<ShaderAst::Attribute> attributes = {});
|
||||
ShaderAst::DeclareFunctionStatement::Parameter ParseFunctionParameter();
|
||||
@@ -99,7 +99,7 @@ namespace Nz::ShaderLang
|
||||
std::vector<ShaderAst::StatementPtr> ParseStatementList();
|
||||
ShaderAst::StatementPtr ParseStructDeclaration(std::vector<ShaderAst::Attribute> attributes = {});
|
||||
ShaderAst::StatementPtr ParseVariableDeclaration();
|
||||
ShaderAst::StatementPtr ParseWhileStatement();
|
||||
ShaderAst::StatementPtr ParseWhileStatement(std::vector<ShaderAst::Attribute> attributes);
|
||||
|
||||
// Expressions
|
||||
ShaderAst::ExpressionPtr ParseBinOpRhs(int exprPrecedence, ShaderAst::ExpressionPtr lhs);
|
||||
|
||||
Reference in New Issue
Block a user