Shader: Cleanup and rename AST files
This commit is contained in:
83
include/Nazara/Shader/Ast/AstCloner.hpp
Normal file
83
include/Nazara/Shader/Ast/AstCloner.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADERASTCLONER_HPP
|
||||
#define NAZARA_SHADERASTCLONER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/AstExpressionVisitor.hpp>
|
||||
#include <Nazara/Shader/Ast/AstStatementVisitor.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class NAZARA_SHADER_API AstCloner : public AstExpressionVisitor, public AstStatementVisitor
|
||||
{
|
||||
public:
|
||||
AstCloner() = default;
|
||||
AstCloner(const AstCloner&) = delete;
|
||||
AstCloner(AstCloner&&) = delete;
|
||||
~AstCloner() = default;
|
||||
|
||||
ExpressionPtr Clone(ExpressionPtr& statement);
|
||||
StatementPtr Clone(StatementPtr& statement);
|
||||
|
||||
AstCloner& operator=(const AstCloner&) = delete;
|
||||
AstCloner& operator=(AstCloner&&) = delete;
|
||||
|
||||
protected:
|
||||
inline ExpressionPtr CloneExpression(ExpressionPtr& expr);
|
||||
inline StatementPtr CloneStatement(StatementPtr& statement);
|
||||
|
||||
virtual ExpressionPtr CloneExpression(Expression& expr);
|
||||
virtual StatementPtr CloneStatement(Statement& statement);
|
||||
|
||||
virtual ExpressionPtr Clone(AccessMemberIdentifierExpression& node);
|
||||
virtual ExpressionPtr Clone(AccessMemberIndexExpression& node);
|
||||
virtual ExpressionPtr Clone(AssignExpression& node);
|
||||
virtual ExpressionPtr Clone(BinaryExpression& node);
|
||||
virtual ExpressionPtr Clone(CastExpression& node);
|
||||
virtual ExpressionPtr Clone(ConditionalExpression& node);
|
||||
virtual ExpressionPtr Clone(ConstantExpression& node);
|
||||
virtual ExpressionPtr Clone(IdentifierExpression& node);
|
||||
virtual ExpressionPtr Clone(IntrinsicExpression& node);
|
||||
virtual ExpressionPtr Clone(SwizzleExpression& node);
|
||||
virtual ExpressionPtr Clone(VariableExpression& node);
|
||||
|
||||
virtual StatementPtr Clone(BranchStatement& node);
|
||||
virtual StatementPtr Clone(ConditionalStatement& node);
|
||||
virtual StatementPtr Clone(DeclareExternalStatement& node);
|
||||
virtual StatementPtr Clone(DeclareFunctionStatement& node);
|
||||
virtual StatementPtr Clone(DeclareStructStatement& node);
|
||||
virtual StatementPtr Clone(DeclareVariableStatement& node);
|
||||
virtual StatementPtr Clone(DiscardStatement& node);
|
||||
virtual StatementPtr Clone(ExpressionStatement& node);
|
||||
virtual StatementPtr Clone(MultiStatement& node);
|
||||
virtual StatementPtr Clone(NoOpStatement& node);
|
||||
virtual StatementPtr Clone(ReturnStatement& node);
|
||||
|
||||
#define NAZARA_SHADERAST_NODE(NodeType) void Visit(NodeType& node) override;
|
||||
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
||||
|
||||
void PushExpression(ExpressionPtr expression);
|
||||
void PushStatement(StatementPtr statement);
|
||||
|
||||
ExpressionPtr PopExpression();
|
||||
StatementPtr PopStatement();
|
||||
|
||||
private:
|
||||
std::vector<ExpressionPtr> m_expressionStack;
|
||||
std::vector<StatementPtr> m_statementStack;
|
||||
};
|
||||
|
||||
inline ExpressionPtr Clone(ExpressionPtr& node);
|
||||
inline StatementPtr Clone(StatementPtr& node);
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/Ast/AstCloner.inl>
|
||||
|
||||
#endif
|
||||
39
include/Nazara/Shader/Ast/AstCloner.inl
Normal file
39
include/Nazara/Shader/Ast/AstCloner.inl
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Shader/Ast/AstCloner.hpp>
|
||||
#include <Nazara/Shader/Debug.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
ExpressionPtr AstCloner::CloneExpression(ExpressionPtr& expr)
|
||||
{
|
||||
if (!expr)
|
||||
return nullptr;
|
||||
|
||||
return CloneExpression(*expr);
|
||||
}
|
||||
|
||||
StatementPtr AstCloner::CloneStatement(StatementPtr& statement)
|
||||
{
|
||||
if (!statement)
|
||||
return nullptr;
|
||||
|
||||
return CloneStatement(*statement);
|
||||
}
|
||||
|
||||
inline ExpressionPtr Clone(ExpressionPtr& node)
|
||||
{
|
||||
AstCloner cloner;
|
||||
return cloner.Clone(node);
|
||||
}
|
||||
|
||||
inline StatementPtr Clone(StatementPtr& node)
|
||||
{
|
||||
AstCloner cloner;
|
||||
return cloner.Clone(node);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/DebugOff.hpp>
|
||||
32
include/Nazara/Shader/Ast/AstExpressionVisitor.hpp
Normal file
32
include/Nazara/Shader/Ast/AstExpressionVisitor.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADER_AST_EXPRESSIONVISITOR_HPP
|
||||
#define NAZARA_SHADER_AST_EXPRESSIONVISITOR_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/Nodes.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class NAZARA_SHADER_API AstExpressionVisitor
|
||||
{
|
||||
public:
|
||||
AstExpressionVisitor() = default;
|
||||
AstExpressionVisitor(const AstExpressionVisitor&) = delete;
|
||||
AstExpressionVisitor(AstExpressionVisitor&&) = delete;
|
||||
virtual ~AstExpressionVisitor();
|
||||
|
||||
#define NAZARA_SHADERAST_EXPRESSION(Node) virtual void Visit(Node& node) = 0;
|
||||
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
||||
|
||||
AstExpressionVisitor& operator=(const AstExpressionVisitor&) = delete;
|
||||
AstExpressionVisitor& operator=(AstExpressionVisitor&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
26
include/Nazara/Shader/Ast/AstExpressionVisitorExcept.hpp
Normal file
26
include/Nazara/Shader/Ast/AstExpressionVisitorExcept.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADERASTEXPRESSIONVISITOREXCEPT_HPP
|
||||
#define NAZARA_SHADERASTEXPRESSIONVISITOREXCEPT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/AstExpressionVisitor.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class NAZARA_SHADER_API ExpressionVisitorExcept : public AstExpressionVisitor
|
||||
{
|
||||
public:
|
||||
using AstExpressionVisitor::Visit;
|
||||
|
||||
#define NAZARA_SHADERAST_EXPRESSION(Node) void Visit(ShaderAst::Node& node) override;
|
||||
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
56
include/Nazara/Shader/Ast/AstNodeList.hpp
Normal file
56
include/Nazara/Shader/Ast/AstNodeList.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#if !defined(NAZARA_SHADERAST_NODE) && !defined(NAZARA_SHADERAST_EXPRESSION) && !defined(NAZARA_SHADERAST_STATEMENT)
|
||||
#error You must define NAZARA_SHADERAST_NODE or NAZARA_SHADERAST_EXPRESSION or NAZARA_SHADERAST_STATEMENT before including this file
|
||||
#endif
|
||||
|
||||
#ifndef NAZARA_SHADERAST_NODE
|
||||
#define NAZARA_SHADERAST_NODE(X)
|
||||
#endif
|
||||
|
||||
#ifndef NAZARA_SHADERAST_NODE_LAST
|
||||
#define NAZARA_SHADERAST_NODE_LAST(X)
|
||||
#endif
|
||||
|
||||
#ifndef NAZARA_SHADERAST_EXPRESSION
|
||||
#define NAZARA_SHADERAST_EXPRESSION(X) NAZARA_SHADERAST_NODE(X)
|
||||
#endif
|
||||
|
||||
#ifndef NAZARA_SHADERAST_STATEMENT
|
||||
#define NAZARA_SHADERAST_STATEMENT(X) NAZARA_SHADERAST_NODE(X)
|
||||
#endif
|
||||
|
||||
#ifndef NAZARA_SHADERAST_STATEMENT_LAST
|
||||
#define NAZARA_SHADERAST_STATEMENT_LAST(X) NAZARA_SHADERAST_STATEMENT(X)
|
||||
#endif
|
||||
|
||||
NAZARA_SHADERAST_EXPRESSION(AccessMemberIdentifierExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(AccessMemberIndexExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(AssignExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(BinaryExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(CastExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(ConditionalExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(ConstantExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(IdentifierExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(IntrinsicExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(SwizzleExpression)
|
||||
NAZARA_SHADERAST_EXPRESSION(VariableExpression)
|
||||
NAZARA_SHADERAST_STATEMENT(BranchStatement)
|
||||
NAZARA_SHADERAST_STATEMENT(ConditionalStatement)
|
||||
NAZARA_SHADERAST_STATEMENT(DeclareExternalStatement)
|
||||
NAZARA_SHADERAST_STATEMENT(DeclareFunctionStatement)
|
||||
NAZARA_SHADERAST_STATEMENT(DeclareStructStatement)
|
||||
NAZARA_SHADERAST_STATEMENT(DeclareVariableStatement)
|
||||
NAZARA_SHADERAST_STATEMENT(DiscardStatement)
|
||||
NAZARA_SHADERAST_STATEMENT(ExpressionStatement)
|
||||
NAZARA_SHADERAST_STATEMENT(MultiStatement)
|
||||
NAZARA_SHADERAST_STATEMENT(NoOpStatement)
|
||||
NAZARA_SHADERAST_STATEMENT_LAST(ReturnStatement)
|
||||
|
||||
#undef NAZARA_SHADERAST_EXPRESSION
|
||||
#undef NAZARA_SHADERAST_NODE
|
||||
#undef NAZARA_SHADERAST_NODE_LAST
|
||||
#undef NAZARA_SHADERAST_STATEMENT
|
||||
#undef NAZARA_SHADERAST_STATEMENT_LAST
|
||||
47
include/Nazara/Shader/Ast/AstOptimizer.hpp
Normal file
47
include/Nazara/Shader/Ast/AstOptimizer.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADERASTOPTIMISER_HPP
|
||||
#define NAZARA_SHADERASTOPTIMISER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/AstCloner.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class NAZARA_SHADER_API AstOptimizer : public AstCloner
|
||||
{
|
||||
public:
|
||||
AstOptimizer() = default;
|
||||
AstOptimizer(const AstOptimizer&) = delete;
|
||||
AstOptimizer(AstOptimizer&&) = delete;
|
||||
~AstOptimizer() = default;
|
||||
|
||||
StatementPtr Optimise(StatementPtr& statement);
|
||||
StatementPtr Optimise(StatementPtr& statement, UInt64 enabledConditions);
|
||||
|
||||
AstOptimizer& operator=(const AstOptimizer&) = delete;
|
||||
AstOptimizer& operator=(AstOptimizer&&) = delete;
|
||||
|
||||
protected:
|
||||
using AstCloner::Visit;
|
||||
void Visit(BinaryExpression& node) override;
|
||||
void Visit(ConditionalExpression& node) override;
|
||||
void Visit(BranchStatement& node) override;
|
||||
void Visit(ConditionalStatement& node) override;
|
||||
|
||||
template<BinaryType Type> void PropagateConstant(std::unique_ptr<ConstantExpression>&& lhs, std::unique_ptr<ConstantExpression>&& rhs);
|
||||
|
||||
private:
|
||||
UInt64 m_enabledConditions;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/Ast/AstOptimizer.inl>
|
||||
|
||||
#endif
|
||||
12
include/Nazara/Shader/Ast/AstOptimizer.inl
Normal file
12
include/Nazara/Shader/Ast/AstOptimizer.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Shader/Ast/AstOptimizer.hpp>
|
||||
#include <Nazara/Shader/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/DebugOff.hpp>
|
||||
51
include/Nazara/Shader/Ast/AstRecursiveVisitor.hpp
Normal file
51
include/Nazara/Shader/Ast/AstRecursiveVisitor.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADER_RECURSIVE_VISITOR_HPP
|
||||
#define NAZARA_SHADER_RECURSIVE_VISITOR_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/AstExpressionVisitor.hpp>
|
||||
#include <Nazara/Shader/Ast/AstStatementVisitor.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class NAZARA_SHADER_API AstRecursiveVisitor : public AstExpressionVisitor, public AstStatementVisitor
|
||||
{
|
||||
public:
|
||||
AstRecursiveVisitor() = default;
|
||||
~AstRecursiveVisitor() = default;
|
||||
|
||||
void Visit(AccessMemberIdentifierExpression& node) override;
|
||||
void Visit(AccessMemberIndexExpression& node) override;
|
||||
void Visit(AssignExpression& node) override;
|
||||
void Visit(BinaryExpression& node) override;
|
||||
void Visit(CastExpression& node) override;
|
||||
void Visit(ConditionalExpression& node) override;
|
||||
void Visit(ConstantExpression& node) override;
|
||||
void Visit(IdentifierExpression& node) override;
|
||||
void Visit(IntrinsicExpression& node) override;
|
||||
void Visit(SwizzleExpression& node) override;
|
||||
void Visit(VariableExpression& node) override;
|
||||
|
||||
void Visit(BranchStatement& node) override;
|
||||
void Visit(ConditionalStatement& node) override;
|
||||
void Visit(DeclareExternalStatement& node) override;
|
||||
void Visit(DeclareFunctionStatement& node) override;
|
||||
void Visit(DeclareStructStatement& node) override;
|
||||
void Visit(DeclareVariableStatement& node) override;
|
||||
void Visit(DiscardStatement& node) override;
|
||||
void Visit(ExpressionStatement& node) override;
|
||||
void Visit(MultiStatement& node) override;
|
||||
void Visit(NoOpStatement& node) override;
|
||||
void Visit(ReturnStatement& node) override;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/Ast/AstRecursiveVisitor.inl>
|
||||
|
||||
#endif
|
||||
12
include/Nazara/Shader/Ast/AstRecursiveVisitor.inl
Normal file
12
include/Nazara/Shader/Ast/AstRecursiveVisitor.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Shader/Ast/AstRecursiveVisitor.hpp>
|
||||
#include <Nazara/Shader/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/DebugOff.hpp>
|
||||
149
include/Nazara/Shader/Ast/AstSerializer.hpp
Normal file
149
include/Nazara/Shader/Ast/AstSerializer.hpp
Normal file
@@ -0,0 +1,149 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADERSERIALIZER_HPP
|
||||
#define NAZARA_SHADERSERIALIZER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/ByteStream.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/Nodes.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class NAZARA_SHADER_API AstSerializerBase
|
||||
{
|
||||
public:
|
||||
AstSerializerBase() = default;
|
||||
AstSerializerBase(const AstSerializerBase&) = delete;
|
||||
AstSerializerBase(AstSerializerBase&&) = delete;
|
||||
~AstSerializerBase() = default;
|
||||
|
||||
void Serialize(AccessMemberIdentifierExpression& node);
|
||||
void Serialize(AccessMemberIndexExpression& node);
|
||||
void Serialize(AssignExpression& node);
|
||||
void Serialize(BinaryExpression& node);
|
||||
void Serialize(CastExpression& node);
|
||||
void Serialize(ConditionalExpression& node);
|
||||
void Serialize(ConstantExpression& node);
|
||||
void Serialize(IdentifierExpression& node);
|
||||
void Serialize(IntrinsicExpression& node);
|
||||
void Serialize(SwizzleExpression& node);
|
||||
void Serialize(VariableExpression& node);
|
||||
|
||||
void Serialize(BranchStatement& node);
|
||||
void Serialize(ConditionalStatement& node);
|
||||
void Serialize(DeclareExternalStatement& node);
|
||||
void Serialize(DeclareFunctionStatement& node);
|
||||
void Serialize(DeclareStructStatement& node);
|
||||
void Serialize(DeclareVariableStatement& node);
|
||||
void Serialize(DiscardStatement& node);
|
||||
void Serialize(ExpressionStatement& node);
|
||||
void Serialize(MultiStatement& node);
|
||||
void Serialize(NoOpStatement& node);
|
||||
void Serialize(ReturnStatement& node);
|
||||
|
||||
protected:
|
||||
template<typename T> void Container(T& container);
|
||||
template<typename T> void Enum(T& enumVal);
|
||||
template<typename T> void OptEnum(std::optional<T>& optVal);
|
||||
template<typename T> void OptVal(std::optional<T>& optVal);
|
||||
|
||||
virtual bool IsWriting() const = 0;
|
||||
|
||||
virtual void Node(ExpressionPtr& node) = 0;
|
||||
virtual void Node(StatementPtr& node) = 0;
|
||||
|
||||
virtual void Type(ExpressionType& type) = 0;
|
||||
|
||||
virtual void Value(bool& val) = 0;
|
||||
virtual void Value(float& val) = 0;
|
||||
virtual void Value(std::string& val) = 0;
|
||||
virtual void Value(Int32& val) = 0;
|
||||
virtual void Value(Vector2f& val) = 0;
|
||||
virtual void Value(Vector3f& val) = 0;
|
||||
virtual void Value(Vector4f& val) = 0;
|
||||
virtual void Value(Vector2i32& val) = 0;
|
||||
virtual void Value(Vector3i32& val) = 0;
|
||||
virtual void Value(Vector4i32& val) = 0;
|
||||
virtual void Value(UInt8& val) = 0;
|
||||
virtual void Value(UInt16& val) = 0;
|
||||
virtual void Value(UInt32& val) = 0;
|
||||
virtual void Value(UInt64& val) = 0;
|
||||
inline void SizeT(std::size_t& val);
|
||||
};
|
||||
|
||||
class NAZARA_SHADER_API ShaderAstSerializer final : public AstSerializerBase
|
||||
{
|
||||
public:
|
||||
inline ShaderAstSerializer(ByteStream& stream);
|
||||
~ShaderAstSerializer() = default;
|
||||
|
||||
void Serialize(StatementPtr& shader);
|
||||
|
||||
private:
|
||||
bool IsWriting() const override;
|
||||
void Node(ExpressionPtr& node) override;
|
||||
void Node(StatementPtr& node) override;
|
||||
void Type(ExpressionType& type) override;
|
||||
void Value(bool& val) override;
|
||||
void Value(float& val) override;
|
||||
void Value(std::string& val) override;
|
||||
void Value(Int32& val) override;
|
||||
void Value(Vector2f& val) override;
|
||||
void Value(Vector3f& val) override;
|
||||
void Value(Vector4f& val) override;
|
||||
void Value(Vector2i32& val) override;
|
||||
void Value(Vector3i32& val) override;
|
||||
void Value(Vector4i32& val) override;
|
||||
void Value(UInt8& val) override;
|
||||
void Value(UInt16& val) override;
|
||||
void Value(UInt32& val) override;
|
||||
void Value(UInt64& val) override;
|
||||
|
||||
ByteStream& m_stream;
|
||||
};
|
||||
|
||||
class NAZARA_SHADER_API ShaderAstUnserializer final : public AstSerializerBase
|
||||
{
|
||||
public:
|
||||
ShaderAstUnserializer(ByteStream& stream);
|
||||
~ShaderAstUnserializer() = default;
|
||||
|
||||
StatementPtr Unserialize();
|
||||
|
||||
private:
|
||||
bool IsWriting() const override;
|
||||
void Node(ExpressionPtr& node) override;
|
||||
void Node(StatementPtr& node) override;
|
||||
void Type(ExpressionType& type) override;
|
||||
void Value(bool& val) override;
|
||||
void Value(float& val) override;
|
||||
void Value(std::string& val) override;
|
||||
void Value(Int32& val) override;
|
||||
void Value(Vector2f& val) override;
|
||||
void Value(Vector3f& val) override;
|
||||
void Value(Vector4f& val) override;
|
||||
void Value(Vector2i32& val) override;
|
||||
void Value(Vector3i32& val) override;
|
||||
void Value(Vector4i32& val) override;
|
||||
void Value(UInt8& val) override;
|
||||
void Value(UInt16& val) override;
|
||||
void Value(UInt32& val) override;
|
||||
void Value(UInt64& val) override;
|
||||
|
||||
ByteStream& m_stream;
|
||||
};
|
||||
|
||||
NAZARA_SHADER_API ByteArray SerializeShader(StatementPtr& shader);
|
||||
inline StatementPtr UnserializeShader(const void* data, std::size_t size);
|
||||
NAZARA_SHADER_API StatementPtr UnserializeShader(ByteStream& stream);
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/Ast/AstSerializer.inl>
|
||||
|
||||
#endif
|
||||
111
include/Nazara/Shader/Ast/AstSerializer.inl
Normal file
111
include/Nazara/Shader/Ast/AstSerializer.inl
Normal file
@@ -0,0 +1,111 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Shader/Ast/AstSerializer.hpp>
|
||||
#include <Nazara/Shader/Debug.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
template<typename T>
|
||||
void AstSerializerBase::Container(T& container)
|
||||
{
|
||||
bool isWriting = IsWriting();
|
||||
|
||||
UInt32 size;
|
||||
if (isWriting)
|
||||
size = UInt32(container.size());
|
||||
|
||||
Value(size);
|
||||
if (!isWriting)
|
||||
container.resize(size);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void AstSerializerBase::Enum(T& enumVal)
|
||||
{
|
||||
bool isWriting = IsWriting();
|
||||
|
||||
UInt32 value;
|
||||
if (isWriting)
|
||||
value = static_cast<UInt32>(enumVal);
|
||||
|
||||
Value(value);
|
||||
if (!isWriting)
|
||||
enumVal = static_cast<T>(value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AstSerializerBase::OptEnum(std::optional<T>& optVal)
|
||||
{
|
||||
bool isWriting = IsWriting();
|
||||
|
||||
bool hasValue;
|
||||
if (isWriting)
|
||||
hasValue = optVal.has_value();
|
||||
|
||||
Value(hasValue);
|
||||
|
||||
if (!isWriting && hasValue)
|
||||
optVal.emplace();
|
||||
|
||||
if (optVal.has_value())
|
||||
Enum(optVal.value());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AstSerializerBase::OptVal(std::optional<T>& optVal)
|
||||
{
|
||||
bool isWriting = IsWriting();
|
||||
|
||||
bool hasValue;
|
||||
if (isWriting)
|
||||
hasValue = optVal.has_value();
|
||||
|
||||
Value(hasValue);
|
||||
|
||||
if (!isWriting && hasValue)
|
||||
optVal.emplace();
|
||||
|
||||
if (optVal.has_value())
|
||||
{
|
||||
if constexpr (std::is_same_v<T, std::size_t>)
|
||||
SizeT(optVal.value());
|
||||
else
|
||||
Value(optVal.value());
|
||||
}
|
||||
}
|
||||
|
||||
inline void AstSerializerBase::SizeT(std::size_t& val)
|
||||
{
|
||||
bool isWriting = IsWriting();
|
||||
|
||||
UInt32 fixedVal;
|
||||
if (isWriting)
|
||||
fixedVal = static_cast<UInt32>(val);
|
||||
|
||||
Value(fixedVal);
|
||||
|
||||
if (!isWriting)
|
||||
val = static_cast<std::size_t>(fixedVal);
|
||||
}
|
||||
|
||||
inline ShaderAstSerializer::ShaderAstSerializer(ByteStream& stream) :
|
||||
m_stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
inline ShaderAstUnserializer::ShaderAstUnserializer(ByteStream& stream) :
|
||||
m_stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
inline StatementPtr UnserializeShader(const void* data, std::size_t size)
|
||||
{
|
||||
ByteStream byteStream(data, size);
|
||||
return UnserializeShader(byteStream);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/DebugOff.hpp>
|
||||
32
include/Nazara/Shader/Ast/AstStatementVisitor.hpp
Normal file
32
include/Nazara/Shader/Ast/AstStatementVisitor.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADERASTSTATEMENTVISITOR_HPP
|
||||
#define NAZARA_SHADERASTSTATEMENTVISITOR_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/Nodes.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class NAZARA_SHADER_API AstStatementVisitor
|
||||
{
|
||||
public:
|
||||
AstStatementVisitor() = default;
|
||||
AstStatementVisitor(const AstStatementVisitor&) = delete;
|
||||
AstStatementVisitor(AstStatementVisitor&&) = delete;
|
||||
virtual ~AstStatementVisitor();
|
||||
|
||||
#define NAZARA_SHADERAST_STATEMENT(NodeType) virtual void Visit(ShaderAst::NodeType& node) = 0;
|
||||
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
||||
|
||||
AstStatementVisitor& operator=(const AstStatementVisitor&) = delete;
|
||||
AstStatementVisitor& operator=(AstStatementVisitor&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
26
include/Nazara/Shader/Ast/AstStatementVisitorExcept.hpp
Normal file
26
include/Nazara/Shader/Ast/AstStatementVisitorExcept.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADERASTSTATEMENTVISITOREXCEPT_HPP
|
||||
#define NAZARA_SHADERASTSTATEMENTVISITOREXCEPT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/AstStatementVisitor.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class NAZARA_SHADER_API StatementVisitorExcept : public AstStatementVisitor
|
||||
{
|
||||
public:
|
||||
using AstStatementVisitor::Visit;
|
||||
|
||||
#define NAZARA_SHADERAST_STATEMENT(Node) void Visit(ShaderAst::Node& node) override;
|
||||
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
54
include/Nazara/Shader/Ast/AstUtils.hpp
Normal file
54
include/Nazara/Shader/Ast/AstUtils.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADER_AST_UTILS_HPP
|
||||
#define NAZARA_SHADER_AST_UTILS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
#include <Nazara/Shader/Ast/AstExpressionVisitor.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class NAZARA_SHADER_API ShaderAstValueCategory final : public AstExpressionVisitor
|
||||
{
|
||||
public:
|
||||
ShaderAstValueCategory() = default;
|
||||
ShaderAstValueCategory(const ShaderAstValueCategory&) = delete;
|
||||
ShaderAstValueCategory(ShaderAstValueCategory&&) = delete;
|
||||
~ShaderAstValueCategory() = default;
|
||||
|
||||
ExpressionCategory GetExpressionCategory(Expression& expression);
|
||||
|
||||
ShaderAstValueCategory& operator=(const ShaderAstValueCategory&) = delete;
|
||||
ShaderAstValueCategory& operator=(ShaderAstValueCategory&&) = delete;
|
||||
|
||||
private:
|
||||
using AstExpressionVisitor::Visit;
|
||||
|
||||
void Visit(AccessMemberIdentifierExpression& node) override;
|
||||
void Visit(AccessMemberIndexExpression& node) override;
|
||||
void Visit(AssignExpression& node) override;
|
||||
void Visit(BinaryExpression& node) override;
|
||||
void Visit(CastExpression& node) override;
|
||||
void Visit(ConditionalExpression& node) override;
|
||||
void Visit(ConstantExpression& node) override;
|
||||
void Visit(IdentifierExpression& node) override;
|
||||
void Visit(IntrinsicExpression& node) override;
|
||||
void Visit(SwizzleExpression& node) override;
|
||||
void Visit(VariableExpression& node) override;
|
||||
|
||||
ExpressionCategory m_expressionCategory;
|
||||
};
|
||||
|
||||
inline ExpressionCategory GetExpressionCategory(Expression& expression);
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/Ast/AstUtils.inl>
|
||||
|
||||
#endif
|
||||
17
include/Nazara/Shader/Ast/AstUtils.inl
Normal file
17
include/Nazara/Shader/Ast/AstUtils.inl
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Shader/Ast/AstUtils.hpp>
|
||||
#include <Nazara/Shader/Debug.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
ExpressionCategory GetExpressionCategory(Expression& expression)
|
||||
{
|
||||
ShaderAstValueCategory visitor;
|
||||
return visitor.GetExpressionCategory(expression);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/DebugOff.hpp>
|
||||
@@ -8,7 +8,7 @@
|
||||
#define NAZARA_SHADERAST_ATTRIBUTES_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/ShaderEnums.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
|
||||
92
include/Nazara/Shader/Ast/Enums.hpp
Normal file
92
include/Nazara/Shader/Ast/Enums.hpp
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADER_AST_ENUMS_HPP
|
||||
#define NAZARA_SHADER_AST_ENUMS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
enum class AssignType
|
||||
{
|
||||
Simple //< =
|
||||
};
|
||||
|
||||
enum class AttributeType
|
||||
{
|
||||
Binding, //< Binding (external var only) - has argument index
|
||||
Builtin, //< Builtin (struct member only) - has argument type
|
||||
Entry, //< Entry point (function only) - has argument type
|
||||
Layout, //< Struct layout (struct only) - has argument style
|
||||
Location //< Location (struct member only) - has argument index
|
||||
};
|
||||
|
||||
enum class BinaryType
|
||||
{
|
||||
Add, //< +
|
||||
Subtract, //< -
|
||||
Multiply, //< *
|
||||
Divide, //< /
|
||||
|
||||
CompEq, //< ==
|
||||
CompGe, //< >=
|
||||
CompGt, //< >
|
||||
CompLe, //< <=
|
||||
CompLt, //< <
|
||||
CompNe //< <=
|
||||
};
|
||||
|
||||
enum class BuiltinEntry
|
||||
{
|
||||
VertexPosition, // gl_Position
|
||||
};
|
||||
|
||||
enum class ExpressionCategory
|
||||
{
|
||||
LValue,
|
||||
RValue
|
||||
};
|
||||
|
||||
enum class IntrinsicType
|
||||
{
|
||||
CrossProduct,
|
||||
DotProduct,
|
||||
SampleTexture
|
||||
};
|
||||
|
||||
enum class MemoryLayout
|
||||
{
|
||||
Std140
|
||||
};
|
||||
|
||||
enum class NodeType
|
||||
{
|
||||
None = -1,
|
||||
|
||||
#define NAZARA_SHADERAST_NODE(Node) Node,
|
||||
#define NAZARA_SHADERAST_STATEMENT_LAST(Node) Node, Max = Node
|
||||
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
||||
};
|
||||
|
||||
enum class PrimitiveType
|
||||
{
|
||||
Boolean, //< bool
|
||||
Float32, //< f32
|
||||
Int32, //< i32
|
||||
UInt32, //< ui32
|
||||
};
|
||||
|
||||
enum class SwizzleComponent
|
||||
{
|
||||
First,
|
||||
Second,
|
||||
Third,
|
||||
Fourth
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_SHADER_ENUMS_HPP
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Shader/ShaderEnums.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
#include <Nazara/Shader/Ast/Attribute.hpp>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
309
include/Nazara/Shader/Ast/Nodes.hpp
Normal file
309
include/Nazara/Shader/Ast/Nodes.hpp
Normal file
@@ -0,0 +1,309 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADER_AST_NODES_HPP
|
||||
#define NAZARA_SHADER_AST_NODES_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/ConstantValue.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
#include <Nazara/Shader/Ast/Attribute.hpp>
|
||||
#include <Nazara/Shader/Ast/ExpressionType.hpp>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
class AstExpressionVisitor;
|
||||
class AstStatementVisitor;
|
||||
|
||||
struct Node;
|
||||
|
||||
using NodePtr = std::unique_ptr<Node>;
|
||||
|
||||
struct NAZARA_SHADER_API Node
|
||||
{
|
||||
Node() = default;
|
||||
Node(const Node&) = delete;
|
||||
Node(Node&&) noexcept = default;
|
||||
virtual ~Node();
|
||||
|
||||
virtual NodeType GetType() const = 0;
|
||||
|
||||
Node& operator=(const Node&) = delete;
|
||||
Node& operator=(Node&&) noexcept = default;
|
||||
};
|
||||
|
||||
// Expressions
|
||||
|
||||
struct Expression;
|
||||
|
||||
using ExpressionPtr = std::unique_ptr<Expression>;
|
||||
|
||||
struct NAZARA_SHADER_API Expression : Node
|
||||
{
|
||||
Expression() = default;
|
||||
Expression(const Expression&) = delete;
|
||||
Expression(Expression&&) noexcept = default;
|
||||
~Expression() = default;
|
||||
|
||||
virtual void Visit(AstExpressionVisitor& visitor) = 0;
|
||||
|
||||
Expression& operator=(const Expression&) = delete;
|
||||
Expression& operator=(Expression&&) noexcept = default;
|
||||
|
||||
std::optional<ExpressionType> cachedExpressionType;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API AccessMemberIdentifierExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
ExpressionPtr structExpr;
|
||||
std::vector<std::string> memberIdentifiers;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API AccessMemberIndexExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
ExpressionPtr structExpr;
|
||||
std::vector<std::size_t> memberIndices;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API AssignExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
AssignType op;
|
||||
ExpressionPtr left;
|
||||
ExpressionPtr right;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API BinaryExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
BinaryType op;
|
||||
ExpressionPtr left;
|
||||
ExpressionPtr right;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API CastExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
ExpressionType targetType;
|
||||
std::array<ExpressionPtr, 4> expressions;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API ConditionalExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
std::string conditionName;
|
||||
ExpressionPtr falsePath;
|
||||
ExpressionPtr truePath;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API ConstantExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
ShaderAst::ConstantValue value;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API IdentifierExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
std::string identifier;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API IntrinsicExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
IntrinsicType intrinsic;
|
||||
std::vector<ExpressionPtr> parameters;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API SwizzleExpression : public Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
std::array<SwizzleComponent, 4> components;
|
||||
std::size_t componentCount;
|
||||
ExpressionPtr expression;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API VariableExpression : Expression
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
std::size_t variableId;
|
||||
};
|
||||
|
||||
// Statements
|
||||
|
||||
struct Statement;
|
||||
|
||||
using StatementPtr = std::unique_ptr<Statement>;
|
||||
|
||||
struct NAZARA_SHADER_API Statement : Node
|
||||
{
|
||||
Statement() = default;
|
||||
Statement(const Statement&) = delete;
|
||||
Statement(Statement&&) noexcept = default;
|
||||
~Statement() = default;
|
||||
|
||||
virtual void Visit(AstStatementVisitor& visitor) = 0;
|
||||
|
||||
Statement& operator=(const Statement&) = delete;
|
||||
Statement& operator=(Statement&&) noexcept = default;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API BranchStatement : public Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
struct ConditionalStatement
|
||||
{
|
||||
ExpressionPtr condition;
|
||||
StatementPtr statement;
|
||||
};
|
||||
|
||||
std::vector<ConditionalStatement> condStatements;
|
||||
StatementPtr elseStatement;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API ConditionalStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
std::string conditionName;
|
||||
StatementPtr statement;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API DeclareExternalStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
struct ExternalVar
|
||||
{
|
||||
std::optional<unsigned int> bindingIndex;
|
||||
std::string name;
|
||||
ExpressionType type;
|
||||
};
|
||||
|
||||
std::optional<std::size_t> varIndex;
|
||||
std::vector<ExternalVar> externalVars;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API DeclareFunctionStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
struct Parameter
|
||||
{
|
||||
std::string name;
|
||||
ExpressionType type;
|
||||
};
|
||||
|
||||
std::optional<ShaderStageType> entryStage;
|
||||
std::optional<std::size_t> funcIndex;
|
||||
std::optional<std::size_t> varIndex;
|
||||
std::string name;
|
||||
std::vector<Parameter> parameters;
|
||||
std::vector<StatementPtr> statements;
|
||||
ExpressionType returnType;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API DeclareStructStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
std::optional<std::size_t> structIndex;
|
||||
StructDescription description;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API DeclareVariableStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
std::optional<std::size_t> varIndex;
|
||||
std::string varName;
|
||||
ExpressionPtr initialExpression;
|
||||
ExpressionType varType;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API DiscardStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API ExpressionStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
ExpressionPtr expression;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API MultiStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
std::vector<StatementPtr> statements;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API NoOpStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API ReturnStatement : Statement
|
||||
{
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
ExpressionPtr returnExpr;
|
||||
};
|
||||
|
||||
inline const ShaderAst::ExpressionType& GetExpressionType(ShaderAst::Expression& expr);
|
||||
inline bool IsExpression(NodeType nodeType);
|
||||
inline bool IsStatement(NodeType nodeType);
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/Ast/Nodes.inl>
|
||||
|
||||
#endif
|
||||
41
include/Nazara/Shader/Ast/Nodes.inl
Normal file
41
include/Nazara/Shader/Ast/Nodes.inl
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Shader generator"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Shader/Ast/Nodes.hpp>
|
||||
#include <Nazara/Shader/Debug.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
const ShaderAst::ExpressionType& GetExpressionType(ShaderAst::Expression& expr)
|
||||
{
|
||||
assert(expr.cachedExpressionType);
|
||||
return expr.cachedExpressionType.value();
|
||||
}
|
||||
|
||||
inline bool IsExpression(NodeType nodeType)
|
||||
{
|
||||
switch (nodeType)
|
||||
{
|
||||
#define NAZARA_SHADERAST_EXPRESSION(Node) case NodeType::Node: return true;
|
||||
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool IsStatement(NodeType nodeType)
|
||||
{
|
||||
switch (nodeType)
|
||||
{
|
||||
#define NAZARA_SHADERAST_STATEMENT(Node) case NodeType::Node: return true;
|
||||
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/DebugOff.hpp>
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/ShaderAstCloner.hpp>
|
||||
#include <Nazara/Shader/Ast/AstCloner.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
|
||||
Reference in New Issue
Block a user