Rename a few classes
This commit is contained in:
parent
7a5f91f740
commit
74fb01af28
|
|
@ -53,17 +53,20 @@
|
||||||
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
||||||
#include <Nazara/Renderer/RenderWindowParameters.hpp>
|
#include <Nazara/Renderer/RenderWindowParameters.hpp>
|
||||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderAstRecursiveVisitor.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderAstSerializer.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderAstValidator.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderAstVisitor.hpp>
|
||||||
#include <Nazara/Renderer/ShaderBinding.hpp>
|
#include <Nazara/Renderer/ShaderBinding.hpp>
|
||||||
#include <Nazara/Renderer/ShaderBuilder.hpp>
|
#include <Nazara/Renderer/ShaderBuilder.hpp>
|
||||||
#include <Nazara/Renderer/ShaderEnums.hpp>
|
#include <Nazara/Renderer/ShaderEnums.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderExpressionType.hpp>
|
||||||
#include <Nazara/Renderer/ShaderNodes.hpp>
|
#include <Nazara/Renderer/ShaderNodes.hpp>
|
||||||
#include <Nazara/Renderer/ShaderSerializer.hpp>
|
|
||||||
#include <Nazara/Renderer/ShaderStageImpl.hpp>
|
#include <Nazara/Renderer/ShaderStageImpl.hpp>
|
||||||
#include <Nazara/Renderer/ShaderValidator.hpp>
|
|
||||||
#include <Nazara/Renderer/ShaderVariables.hpp>
|
#include <Nazara/Renderer/ShaderVariables.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVisitor.hpp>
|
|
||||||
#include <Nazara/Renderer/ShaderWriter.hpp>
|
#include <Nazara/Renderer/ShaderWriter.hpp>
|
||||||
|
#include <Nazara/Renderer/SpirvWriter.hpp>
|
||||||
#include <Nazara/Renderer/Texture.hpp>
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
#include <Nazara/Renderer/UploadPool.hpp>
|
#include <Nazara/Renderer/UploadPool.hpp>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVisitor.hpp>
|
#include <Nazara/Renderer/ShaderAstVisitor.hpp>
|
||||||
#include <Nazara/Renderer/ShaderWriter.hpp>
|
#include <Nazara/Renderer/ShaderWriter.hpp>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class NAZARA_RENDERER_API GlslWriter : public ShaderWriter, public ShaderVarVisitor, public ShaderVisitor
|
class NAZARA_RENDERER_API GlslWriter : public ShaderWriter, public ShaderVarVisitor, public ShaderAstVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Environment;
|
struct Environment;
|
||||||
|
|
@ -60,7 +60,7 @@ namespace Nz
|
||||||
void LeaveScope();
|
void LeaveScope();
|
||||||
|
|
||||||
using ShaderVarVisitor::Visit;
|
using ShaderVarVisitor::Visit;
|
||||||
using ShaderVisitor::Visit;
|
using ShaderAstVisitor::Visit;
|
||||||
void Visit(const ShaderNodes::ExpressionPtr& expr, bool encloseIfRequired = false);
|
void Visit(const ShaderNodes::ExpressionPtr& expr, bool encloseIfRequired = false);
|
||||||
void Visit(const ShaderNodes::AccessMember& node) override;
|
void Visit(const ShaderNodes::AccessMember& node) override;
|
||||||
void Visit(const ShaderNodes::AssignOp& node) override;
|
void Visit(const ShaderNodes::AssignOp& node) override;
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,17 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVisitor.hpp>
|
#include <Nazara/Renderer/ShaderAstVisitor.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class NAZARA_RENDERER_API ShaderRecursiveVisitor : public ShaderVisitor
|
class NAZARA_RENDERER_API ShaderAstRecursiveVisitor : public ShaderAstVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShaderRecursiveVisitor() = default;
|
ShaderAstRecursiveVisitor() = default;
|
||||||
~ShaderRecursiveVisitor() = default;
|
~ShaderAstRecursiveVisitor() = default;
|
||||||
|
|
||||||
using ShaderVisitor::Visit;
|
using ShaderAstVisitor::Visit;
|
||||||
|
|
||||||
void Visit(const ShaderNodes::AccessMember& node) override;
|
void Visit(const ShaderNodes::AccessMember& node) override;
|
||||||
void Visit(const ShaderNodes::AssignOp& node) override;
|
void Visit(const ShaderNodes::AssignOp& node) override;
|
||||||
|
|
@ -37,6 +37,6 @@ namespace Nz
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderRecursiveVisitor.inl>
|
#include <Nazara/Renderer/ShaderAstRecursiveVisitor.inl>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderRecursiveVisitor.hpp>
|
#include <Nazara/Renderer/ShaderAstRecursiveVisitor.hpp>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
|
|
@ -17,13 +17,13 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class NAZARA_RENDERER_API ShaderSerializerBase
|
class NAZARA_RENDERER_API ShaderAstSerializerBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShaderSerializerBase() = default;
|
ShaderAstSerializerBase() = default;
|
||||||
ShaderSerializerBase(const ShaderSerializerBase&) = delete;
|
ShaderAstSerializerBase(const ShaderAstSerializerBase&) = delete;
|
||||||
ShaderSerializerBase(ShaderSerializerBase&&) = delete;
|
ShaderAstSerializerBase(ShaderAstSerializerBase&&) = delete;
|
||||||
~ShaderSerializerBase() = default;
|
~ShaderAstSerializerBase() = default;
|
||||||
|
|
||||||
void Serialize(ShaderNodes::AccessMember& node);
|
void Serialize(ShaderNodes::AccessMember& node);
|
||||||
void Serialize(ShaderNodes::AssignOp& node);
|
void Serialize(ShaderNodes::AssignOp& node);
|
||||||
|
|
@ -69,11 +69,11 @@ namespace Nz
|
||||||
template<typename T> void Variable(std::shared_ptr<T>& var);
|
template<typename T> void Variable(std::shared_ptr<T>& var);
|
||||||
};
|
};
|
||||||
|
|
||||||
class NAZARA_RENDERER_API ShaderSerializer final : public ShaderSerializerBase
|
class NAZARA_RENDERER_API ShaderAstSerializer final : public ShaderAstSerializerBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline ShaderSerializer(ByteStream& stream);
|
inline ShaderAstSerializer(ByteStream& stream);
|
||||||
~ShaderSerializer() = default;
|
~ShaderAstSerializer() = default;
|
||||||
|
|
||||||
void Serialize(const ShaderAst& shader);
|
void Serialize(const ShaderAst& shader);
|
||||||
|
|
||||||
|
|
@ -96,11 +96,11 @@ namespace Nz
|
||||||
ByteStream& m_stream;
|
ByteStream& m_stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NAZARA_RENDERER_API ShaderUnserializer final : public ShaderSerializerBase
|
class NAZARA_RENDERER_API ShaderAstUnserializer final : public ShaderAstSerializerBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShaderUnserializer(ByteStream& stream);
|
ShaderAstUnserializer(ByteStream& stream);
|
||||||
~ShaderUnserializer() = default;
|
~ShaderAstUnserializer() = default;
|
||||||
|
|
||||||
ShaderAst Unserialize();
|
ShaderAst Unserialize();
|
||||||
|
|
||||||
|
|
@ -126,6 +126,6 @@ namespace Nz
|
||||||
NAZARA_RENDERER_API ShaderAst UnserializeShader(ByteStream& stream);
|
NAZARA_RENDERER_API ShaderAst UnserializeShader(ByteStream& stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderSerializer.inl>
|
#include <Nazara/Renderer/ShaderAstSerializer.inl>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderSerializer.hpp>
|
#include <Nazara/Renderer/ShaderAstSerializer.hpp>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ShaderSerializerBase::Container(T& container)
|
void ShaderAstSerializerBase::Container(T& container)
|
||||||
{
|
{
|
||||||
bool isWriting = IsWriting();
|
bool isWriting = IsWriting();
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Nz
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ShaderSerializerBase::Enum(T& enumVal)
|
void ShaderAstSerializerBase::Enum(T& enumVal)
|
||||||
{
|
{
|
||||||
bool isWriting = IsWriting();
|
bool isWriting = IsWriting();
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ShaderSerializerBase::OptEnum(std::optional<T>& optVal)
|
void ShaderAstSerializerBase::OptEnum(std::optional<T>& optVal)
|
||||||
{
|
{
|
||||||
bool isWriting = IsWriting();
|
bool isWriting = IsWriting();
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ShaderSerializerBase::OptVal(std::optional<T>& optVal)
|
void ShaderAstSerializerBase::OptVal(std::optional<T>& optVal)
|
||||||
{
|
{
|
||||||
bool isWriting = IsWriting();
|
bool isWriting = IsWriting();
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ShaderSerializerBase::Node(std::shared_ptr<T>& node)
|
void ShaderAstSerializerBase::Node(std::shared_ptr<T>& node)
|
||||||
{
|
{
|
||||||
bool isWriting = IsWriting();
|
bool isWriting = IsWriting();
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ShaderSerializerBase::Variable(std::shared_ptr<T>& var)
|
void ShaderAstSerializerBase::Variable(std::shared_ptr<T>& var)
|
||||||
{
|
{
|
||||||
bool isWriting = IsWriting();
|
bool isWriting = IsWriting();
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ namespace Nz
|
||||||
var = std::static_pointer_cast<T>(value);
|
var = std::static_pointer_cast<T>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ShaderSerializerBase::Value(std::size_t& val)
|
inline void ShaderAstSerializerBase::Value(std::size_t& val)
|
||||||
{
|
{
|
||||||
bool isWriting = IsWriting();
|
bool isWriting = IsWriting();
|
||||||
|
|
||||||
|
|
@ -113,12 +113,12 @@ namespace Nz
|
||||||
val = static_cast<std::size_t>(value);
|
val = static_cast<std::size_t>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ShaderSerializer::ShaderSerializer(ByteStream& stream) :
|
inline ShaderAstSerializer::ShaderAstSerializer(ByteStream& stream) :
|
||||||
m_stream(stream)
|
m_stream(stream)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ShaderUnserializer::ShaderUnserializer(ByteStream& stream) :
|
inline ShaderAstUnserializer::ShaderAstUnserializer(ByteStream& stream) :
|
||||||
m_stream(stream)
|
m_stream(stream)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -12,18 +12,18 @@
|
||||||
#include <Nazara/Core/ByteStream.hpp>
|
#include <Nazara/Core/ByteStream.hpp>
|
||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||||
#include <Nazara/Renderer/ShaderRecursiveVisitor.hpp>
|
#include <Nazara/Renderer/ShaderAstRecursiveVisitor.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class NAZARA_RENDERER_API ShaderValidator : public ShaderRecursiveVisitor, public ShaderVarVisitor
|
class NAZARA_RENDERER_API ShaderAstValidator : public ShaderAstRecursiveVisitor, public ShaderVarVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline ShaderValidator(const ShaderAst& shader);
|
inline ShaderAstValidator(const ShaderAst& shader);
|
||||||
ShaderValidator(const ShaderValidator&) = delete;
|
ShaderAstValidator(const ShaderAstValidator&) = delete;
|
||||||
ShaderValidator(ShaderValidator&&) = delete;
|
ShaderAstValidator(ShaderAstValidator&&) = delete;
|
||||||
~ShaderValidator() = default;
|
~ShaderAstValidator() = default;
|
||||||
|
|
||||||
bool Validate(std::string* error = nullptr);
|
bool Validate(std::string* error = nullptr);
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace Nz
|
||||||
void TypeMustMatch(const ShaderNodes::ExpressionPtr& left, const ShaderNodes::ExpressionPtr& right);
|
void TypeMustMatch(const ShaderNodes::ExpressionPtr& left, const ShaderNodes::ExpressionPtr& right);
|
||||||
void TypeMustMatch(const ShaderExpressionType& left, const ShaderExpressionType& right);
|
void TypeMustMatch(const ShaderExpressionType& left, const ShaderExpressionType& right);
|
||||||
|
|
||||||
using ShaderRecursiveVisitor::Visit;
|
using ShaderAstRecursiveVisitor::Visit;
|
||||||
void Visit(const ShaderNodes::AccessMember& node) override;
|
void Visit(const ShaderNodes::AccessMember& node) override;
|
||||||
void Visit(const ShaderNodes::AssignOp& node) override;
|
void Visit(const ShaderNodes::AssignOp& node) override;
|
||||||
void Visit(const ShaderNodes::BinaryOp& node) override;
|
void Visit(const ShaderNodes::BinaryOp& node) override;
|
||||||
|
|
@ -65,6 +65,6 @@ namespace Nz
|
||||||
NAZARA_RENDERER_API bool ValidateShader(const ShaderAst& shader, std::string* error = nullptr);
|
NAZARA_RENDERER_API bool ValidateShader(const ShaderAst& shader, std::string* error = nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderValidator.inl>
|
#include <Nazara/Renderer/ShaderAstValidator.inl>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderValidator.hpp>
|
#include <Nazara/Renderer/ShaderAstValidator.hpp>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
ShaderValidator::ShaderValidator(const ShaderAst& shader) :
|
ShaderAstValidator::ShaderAstValidator(const ShaderAst& shader) :
|
||||||
m_shader(shader)
|
m_shader(shader)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -15,13 +15,13 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class NAZARA_RENDERER_API ShaderVisitor
|
class NAZARA_RENDERER_API ShaderAstVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShaderVisitor() = default;
|
ShaderAstVisitor() = default;
|
||||||
ShaderVisitor(const ShaderVisitor&) = delete;
|
ShaderAstVisitor(const ShaderAstVisitor&) = delete;
|
||||||
ShaderVisitor(ShaderVisitor&&) = delete;
|
ShaderAstVisitor(ShaderAstVisitor&&) = delete;
|
||||||
virtual ~ShaderVisitor();
|
virtual ~ShaderAstVisitor();
|
||||||
|
|
||||||
void EnableCondition(const std::string& name, bool cond);
|
void EnableCondition(const std::string& name, bool cond);
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class ShaderVisitor;
|
class ShaderAstVisitor;
|
||||||
|
|
||||||
namespace ShaderNodes
|
namespace ShaderNodes
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +37,7 @@ namespace Nz
|
||||||
inline NodeType GetType() const;
|
inline NodeType GetType() const;
|
||||||
inline bool IsStatement() const;
|
inline bool IsStatement() const;
|
||||||
|
|
||||||
virtual void Visit(ShaderVisitor& visitor) = 0;
|
virtual void Visit(ShaderAstVisitor& visitor) = 0;
|
||||||
|
|
||||||
static inline unsigned int GetComponentCount(BasicType type);
|
static inline unsigned int GetComponentCount(BasicType type);
|
||||||
static inline BasicType GetComponentType(BasicType type);
|
static inline BasicType GetComponentType(BasicType type);
|
||||||
|
|
@ -77,7 +77,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
inline ExpressionStatement();
|
inline ExpressionStatement();
|
||||||
|
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
ExpressionPtr expression;
|
ExpressionPtr expression;
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
inline ConditionalStatement();
|
inline ConditionalStatement();
|
||||||
|
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
std::string conditionName;
|
std::string conditionName;
|
||||||
StatementPtr statement;
|
StatementPtr statement;
|
||||||
|
|
@ -102,7 +102,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
inline StatementBlock();
|
inline StatementBlock();
|
||||||
|
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
std::vector<StatementPtr> statements;
|
std::vector<StatementPtr> statements;
|
||||||
|
|
||||||
|
|
@ -113,7 +113,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
inline DeclareVariable();
|
inline DeclareVariable();
|
||||||
|
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
LocalVariablePtr variable;
|
LocalVariablePtr variable;
|
||||||
ExpressionPtr expression;
|
ExpressionPtr expression;
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Nz
|
||||||
|
|
||||||
ExpressionCategory GetExpressionCategory() const override;
|
ExpressionCategory GetExpressionCategory() const override;
|
||||||
ShaderExpressionType GetExpressionType() const override;
|
ShaderExpressionType GetExpressionType() const override;
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
VariablePtr var;
|
VariablePtr var;
|
||||||
|
|
||||||
|
|
@ -140,7 +140,7 @@ namespace Nz
|
||||||
|
|
||||||
ExpressionCategory GetExpressionCategory() const override;
|
ExpressionCategory GetExpressionCategory() const override;
|
||||||
ShaderExpressionType GetExpressionType() const override;
|
ShaderExpressionType GetExpressionType() const override;
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
std::size_t memberIndex;
|
std::size_t memberIndex;
|
||||||
ExpressionPtr structExpr;
|
ExpressionPtr structExpr;
|
||||||
|
|
@ -156,7 +156,7 @@ namespace Nz
|
||||||
inline AssignOp();
|
inline AssignOp();
|
||||||
|
|
||||||
ShaderExpressionType GetExpressionType() const override;
|
ShaderExpressionType GetExpressionType() const override;
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
AssignType op;
|
AssignType op;
|
||||||
ExpressionPtr left;
|
ExpressionPtr left;
|
||||||
|
|
@ -170,7 +170,7 @@ namespace Nz
|
||||||
inline BinaryOp();
|
inline BinaryOp();
|
||||||
|
|
||||||
ShaderExpressionType GetExpressionType() const override;
|
ShaderExpressionType GetExpressionType() const override;
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
BinaryType op;
|
BinaryType op;
|
||||||
ExpressionPtr left;
|
ExpressionPtr left;
|
||||||
|
|
@ -185,7 +185,7 @@ namespace Nz
|
||||||
|
|
||||||
inline Branch();
|
inline Branch();
|
||||||
|
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
std::vector<ConditionalStatement> condStatements;
|
std::vector<ConditionalStatement> condStatements;
|
||||||
StatementPtr elseStatement;
|
StatementPtr elseStatement;
|
||||||
|
|
@ -204,7 +204,7 @@ namespace Nz
|
||||||
inline Cast();
|
inline Cast();
|
||||||
|
|
||||||
ShaderExpressionType GetExpressionType() const override;
|
ShaderExpressionType GetExpressionType() const override;
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
BasicType exprType;
|
BasicType exprType;
|
||||||
std::array<ExpressionPtr, 4> expressions;
|
std::array<ExpressionPtr, 4> expressions;
|
||||||
|
|
@ -218,7 +218,7 @@ namespace Nz
|
||||||
inline Constant();
|
inline Constant();
|
||||||
|
|
||||||
ShaderExpressionType GetExpressionType() const override;
|
ShaderExpressionType GetExpressionType() const override;
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
using Variant = std::variant<
|
using Variant = std::variant<
|
||||||
bool,
|
bool,
|
||||||
|
|
@ -239,7 +239,7 @@ namespace Nz
|
||||||
|
|
||||||
ExpressionCategory GetExpressionCategory() const override;
|
ExpressionCategory GetExpressionCategory() const override;
|
||||||
ShaderExpressionType GetExpressionType() const override;
|
ShaderExpressionType GetExpressionType() const override;
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
std::array<SwizzleComponent, 4> components;
|
std::array<SwizzleComponent, 4> components;
|
||||||
std::size_t componentCount;
|
std::size_t componentCount;
|
||||||
|
|
@ -255,7 +255,7 @@ namespace Nz
|
||||||
inline Sample2D();
|
inline Sample2D();
|
||||||
|
|
||||||
ShaderExpressionType GetExpressionType() const override;
|
ShaderExpressionType GetExpressionType() const override;
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
ExpressionPtr sampler;
|
ExpressionPtr sampler;
|
||||||
ExpressionPtr coordinates;
|
ExpressionPtr coordinates;
|
||||||
|
|
@ -270,7 +270,7 @@ namespace Nz
|
||||||
inline IntrinsicCall();
|
inline IntrinsicCall();
|
||||||
|
|
||||||
ShaderExpressionType GetExpressionType() const override;
|
ShaderExpressionType GetExpressionType() const override;
|
||||||
void Visit(ShaderVisitor& visitor) override;
|
void Visit(ShaderAstVisitor& visitor) override;
|
||||||
|
|
||||||
IntrinsicType intrinsic;
|
IntrinsicType intrinsic;
|
||||||
std::vector<ExpressionPtr> parameters;
|
std::vector<ExpressionPtr> parameters;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVisitor.hpp>
|
#include <Nazara/Renderer/ShaderAstVisitor.hpp>
|
||||||
#include <Nazara/Renderer/ShaderWriter.hpp>
|
#include <Nazara/Renderer/ShaderWriter.hpp>
|
||||||
#include <Nazara/Utility/FieldOffsets.hpp>
|
#include <Nazara/Utility/FieldOffsets.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class NAZARA_RENDERER_API SpirvWriter : public ShaderVisitor
|
class NAZARA_RENDERER_API SpirvWriter : public ShaderAstVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Environment;
|
struct Environment;
|
||||||
|
|
@ -84,7 +84,7 @@ namespace Nz
|
||||||
|
|
||||||
UInt32 RegisterType(ShaderExpressionType type);
|
UInt32 RegisterType(ShaderExpressionType type);
|
||||||
|
|
||||||
using ShaderVisitor::Visit;
|
using ShaderAstVisitor::Visit;
|
||||||
void Visit(const ShaderNodes::AccessMember& node) override;
|
void Visit(const ShaderNodes::AccessMember& node) override;
|
||||||
void Visit(const ShaderNodes::AssignOp& node) override;
|
void Visit(const ShaderNodes::AssignOp& node) override;
|
||||||
void Visit(const ShaderNodes::Branch& node) override;
|
void Visit(const ShaderNodes::Branch& node) override;
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@
|
||||||
#include <Nazara/Utility/Config.hpp>
|
#include <Nazara/Utility/Config.hpp>
|
||||||
#include <Nazara/Utility/CubemapParams.hpp>
|
#include <Nazara/Utility/CubemapParams.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
|
#include <Nazara/Utility/FieldOffsets.hpp>
|
||||||
#include <Nazara/Utility/Font.hpp>
|
#include <Nazara/Utility/Font.hpp>
|
||||||
#include <Nazara/Utility/FontData.hpp>
|
#include <Nazara/Utility/FontData.hpp>
|
||||||
#include <Nazara/Utility/FontGlyph.hpp>
|
#include <Nazara/Utility/FontGlyph.hpp>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include <Nazara/OpenGLRenderer/Utils.hpp>
|
#include <Nazara/OpenGLRenderer/Utils.hpp>
|
||||||
#include <Nazara/Renderer/GlslWriter.hpp>
|
#include <Nazara/Renderer/GlslWriter.hpp>
|
||||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||||
#include <Nazara/Renderer/ShaderSerializer.hpp>
|
#include <Nazara/Renderer/ShaderAstSerializer.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <Nazara/Renderer/GlslWriter.hpp>
|
#include <Nazara/Renderer/GlslWriter.hpp>
|
||||||
#include <Nazara/Core/Algorithm.hpp>
|
#include <Nazara/Core/Algorithm.hpp>
|
||||||
#include <Nazara/Core/CallOnExit.hpp>
|
#include <Nazara/Core/CallOnExit.hpp>
|
||||||
#include <Nazara/Renderer/ShaderValidator.hpp>
|
#include <Nazara/Renderer/ShaderAstValidator.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
|
|
@ -305,7 +305,7 @@ namespace Nz
|
||||||
if (enclose)
|
if (enclose)
|
||||||
Append("(");
|
Append("(");
|
||||||
|
|
||||||
ShaderVisitor::Visit(expr);
|
ShaderAstVisitor::Visit(expr);
|
||||||
|
|
||||||
if (enclose)
|
if (enclose)
|
||||||
Append(")");
|
Append(")");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
// Copyright (C) 2015 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
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/ShaderAstRecursiveVisitor.hpp>
|
||||||
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::AccessMember& node)
|
||||||
|
{
|
||||||
|
Visit(node.structExpr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::AssignOp& node)
|
||||||
|
{
|
||||||
|
Visit(node.left);
|
||||||
|
Visit(node.right);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::BinaryOp& node)
|
||||||
|
{
|
||||||
|
Visit(node.left);
|
||||||
|
Visit(node.right);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::Branch& node)
|
||||||
|
{
|
||||||
|
for (auto& cond : node.condStatements)
|
||||||
|
{
|
||||||
|
Visit(cond.condition);
|
||||||
|
Visit(cond.statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.elseStatement)
|
||||||
|
Visit(node.elseStatement);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::Cast& node)
|
||||||
|
{
|
||||||
|
for (auto& expr : node.expressions)
|
||||||
|
{
|
||||||
|
if (!expr)
|
||||||
|
break;
|
||||||
|
|
||||||
|
Visit(expr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::Constant& /*node*/)
|
||||||
|
{
|
||||||
|
/* Nothing to do */
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::DeclareVariable& node)
|
||||||
|
{
|
||||||
|
if (node.expression)
|
||||||
|
Visit(node.expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::ExpressionStatement& node)
|
||||||
|
{
|
||||||
|
Visit(node.expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::Identifier& /*node*/)
|
||||||
|
{
|
||||||
|
/* Nothing to do */
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::IntrinsicCall& node)
|
||||||
|
{
|
||||||
|
for (auto& param : node.parameters)
|
||||||
|
Visit(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::Sample2D& node)
|
||||||
|
{
|
||||||
|
Visit(node.sampler);
|
||||||
|
Visit(node.coordinates);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::StatementBlock& node)
|
||||||
|
{
|
||||||
|
for (auto& statement : node.statements)
|
||||||
|
Visit(statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstRecursiveVisitor::Visit(const ShaderNodes::SwizzleOp& node)
|
||||||
|
{
|
||||||
|
Visit(node.expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderSerializer.hpp>
|
#include <Nazara/Renderer/ShaderAstSerializer.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
#include <Nazara/Renderer/ShaderVarVisitor.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVisitor.hpp>
|
#include <Nazara/Renderer/ShaderAstVisitor.hpp>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
|
|
@ -14,10 +14,10 @@ namespace Nz
|
||||||
constexpr UInt32 s_magicNumber = 0x4E534852;
|
constexpr UInt32 s_magicNumber = 0x4E534852;
|
||||||
constexpr UInt32 s_currentVersion = 1;
|
constexpr UInt32 s_currentVersion = 1;
|
||||||
|
|
||||||
class ShaderSerializerVisitor : public ShaderVisitor, public ShaderVarVisitor
|
class ShaderSerializerVisitor : public ShaderAstVisitor, public ShaderVarVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShaderSerializerVisitor(ShaderSerializerBase& serializer) :
|
ShaderSerializerVisitor(ShaderAstSerializerBase& serializer) :
|
||||||
m_serializer(serializer)
|
m_serializer(serializer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -126,32 +126,32 @@ namespace Nz
|
||||||
m_serializer.Serialize(const_cast<T&>(node));
|
m_serializer.Serialize(const_cast<T&>(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderSerializerBase& m_serializer;
|
ShaderAstSerializerBase& m_serializer;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::AccessMember& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::AccessMember& node)
|
||||||
{
|
{
|
||||||
Value(node.memberIndex);
|
Value(node.memberIndex);
|
||||||
Node(node.structExpr);
|
Node(node.structExpr);
|
||||||
Type(node.exprType);
|
Type(node.exprType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::AssignOp& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::AssignOp& node)
|
||||||
{
|
{
|
||||||
Enum(node.op);
|
Enum(node.op);
|
||||||
Node(node.left);
|
Node(node.left);
|
||||||
Node(node.right);
|
Node(node.right);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::BinaryOp& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::BinaryOp& node)
|
||||||
{
|
{
|
||||||
Enum(node.op);
|
Enum(node.op);
|
||||||
Node(node.left);
|
Node(node.left);
|
||||||
Node(node.right);
|
Node(node.right);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::Branch& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::Branch& node)
|
||||||
{
|
{
|
||||||
Container(node.condStatements);
|
Container(node.condStatements);
|
||||||
for (auto& condStatement : node.condStatements)
|
for (auto& condStatement : node.condStatements)
|
||||||
|
|
@ -163,20 +163,20 @@ namespace Nz
|
||||||
Node(node.elseStatement);
|
Node(node.elseStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::BuiltinVariable& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::BuiltinVariable& node)
|
||||||
{
|
{
|
||||||
Enum(node.entry);
|
Enum(node.entry);
|
||||||
Type(node.type);
|
Type(node.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::Cast& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::Cast& node)
|
||||||
{
|
{
|
||||||
Enum(node.exprType);
|
Enum(node.exprType);
|
||||||
for (auto& expr : node.expressions)
|
for (auto& expr : node.expressions)
|
||||||
Node(expr);
|
Node(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::Constant& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::Constant& node)
|
||||||
{
|
{
|
||||||
UInt32 typeIndex;
|
UInt32 typeIndex;
|
||||||
if (IsWriting())
|
if (IsWriting())
|
||||||
|
|
@ -205,23 +205,23 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::DeclareVariable& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::DeclareVariable& node)
|
||||||
{
|
{
|
||||||
Variable(node.variable);
|
Variable(node.variable);
|
||||||
Node(node.expression);
|
Node(node.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::ExpressionStatement& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::ExpressionStatement& node)
|
||||||
{
|
{
|
||||||
Node(node.expression);
|
Node(node.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::Identifier& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::Identifier& node)
|
||||||
{
|
{
|
||||||
Variable(node.var);
|
Variable(node.var);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::IntrinsicCall& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::IntrinsicCall& node)
|
||||||
{
|
{
|
||||||
Enum(node.intrinsic);
|
Enum(node.intrinsic);
|
||||||
Container(node.parameters);
|
Container(node.parameters);
|
||||||
|
|
@ -229,26 +229,26 @@ namespace Nz
|
||||||
Node(param);
|
Node(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::NamedVariable& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::NamedVariable& node)
|
||||||
{
|
{
|
||||||
Value(node.name);
|
Value(node.name);
|
||||||
Type(node.type);
|
Type(node.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::Sample2D& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::Sample2D& node)
|
||||||
{
|
{
|
||||||
Node(node.sampler);
|
Node(node.sampler);
|
||||||
Node(node.coordinates);
|
Node(node.coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::StatementBlock& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::StatementBlock& node)
|
||||||
{
|
{
|
||||||
Container(node.statements);
|
Container(node.statements);
|
||||||
for (auto& statement : node.statements)
|
for (auto& statement : node.statements)
|
||||||
Node(statement);
|
Node(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializerBase::Serialize(ShaderNodes::SwizzleOp& node)
|
void ShaderAstSerializerBase::Serialize(ShaderNodes::SwizzleOp& node)
|
||||||
{
|
{
|
||||||
Value(node.componentCount);
|
Value(node.componentCount);
|
||||||
Node(node.expression);
|
Node(node.expression);
|
||||||
|
|
@ -258,7 +258,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ShaderSerializer::Serialize(const ShaderAst& shader)
|
void ShaderAstSerializer::Serialize(const ShaderAst& shader)
|
||||||
{
|
{
|
||||||
m_stream << s_magicNumber << s_currentVersion;
|
m_stream << s_magicNumber << s_currentVersion;
|
||||||
|
|
||||||
|
|
@ -346,12 +346,12 @@ namespace Nz
|
||||||
m_stream.FlushBits();
|
m_stream.FlushBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderSerializer::IsWriting() const
|
bool ShaderAstSerializer::IsWriting() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Node(ShaderNodes::NodePtr& node)
|
void ShaderAstSerializer::Node(ShaderNodes::NodePtr& node)
|
||||||
{
|
{
|
||||||
ShaderNodes::NodeType nodeType = (node) ? node->GetType() : ShaderNodes::NodeType::None;
|
ShaderNodes::NodeType nodeType = (node) ? node->GetType() : ShaderNodes::NodeType::None;
|
||||||
m_stream << static_cast<Int32>(nodeType);
|
m_stream << static_cast<Int32>(nodeType);
|
||||||
|
|
@ -363,7 +363,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Type(ShaderExpressionType& type)
|
void ShaderAstSerializer::Type(ShaderExpressionType& type)
|
||||||
{
|
{
|
||||||
std::visit([&](auto&& arg)
|
std::visit([&](auto&& arg)
|
||||||
{
|
{
|
||||||
|
|
@ -383,57 +383,57 @@ namespace Nz
|
||||||
}, type);
|
}, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Node(const ShaderNodes::NodePtr& node)
|
void ShaderAstSerializer::Node(const ShaderNodes::NodePtr& node)
|
||||||
{
|
{
|
||||||
Node(const_cast<ShaderNodes::NodePtr&>(node)); //< Yes const_cast is ugly but it won't be used for writing
|
Node(const_cast<ShaderNodes::NodePtr&>(node)); //< Yes const_cast is ugly but it won't be used for writing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Value(bool& val)
|
void ShaderAstSerializer::Value(bool& val)
|
||||||
{
|
{
|
||||||
m_stream << val;
|
m_stream << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Value(float& val)
|
void ShaderAstSerializer::Value(float& val)
|
||||||
{
|
{
|
||||||
m_stream << val;
|
m_stream << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Value(std::string& val)
|
void ShaderAstSerializer::Value(std::string& val)
|
||||||
{
|
{
|
||||||
m_stream << val;
|
m_stream << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Value(Vector2f& val)
|
void ShaderAstSerializer::Value(Vector2f& val)
|
||||||
{
|
{
|
||||||
m_stream << val;
|
m_stream << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Value(Vector3f& val)
|
void ShaderAstSerializer::Value(Vector3f& val)
|
||||||
{
|
{
|
||||||
m_stream << val;
|
m_stream << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Value(Vector4f& val)
|
void ShaderAstSerializer::Value(Vector4f& val)
|
||||||
{
|
{
|
||||||
m_stream << val;
|
m_stream << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Value(UInt8& val)
|
void ShaderAstSerializer::Value(UInt8& val)
|
||||||
{
|
{
|
||||||
m_stream << val;
|
m_stream << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Value(UInt16& val)
|
void ShaderAstSerializer::Value(UInt16& val)
|
||||||
{
|
{
|
||||||
m_stream << val;
|
m_stream << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Value(UInt32& val)
|
void ShaderAstSerializer::Value(UInt32& val)
|
||||||
{
|
{
|
||||||
m_stream << val;
|
m_stream << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSerializer::Variable(ShaderNodes::VariablePtr& var)
|
void ShaderAstSerializer::Variable(ShaderNodes::VariablePtr& var)
|
||||||
{
|
{
|
||||||
ShaderNodes::VariableType nodeType = (var) ? var->GetType() : ShaderNodes::VariableType::None;
|
ShaderNodes::VariableType nodeType = (var) ? var->GetType() : ShaderNodes::VariableType::None;
|
||||||
m_stream << static_cast<Int32>(nodeType);
|
m_stream << static_cast<Int32>(nodeType);
|
||||||
|
|
@ -445,7 +445,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderAst ShaderUnserializer::Unserialize()
|
ShaderAst ShaderAstUnserializer::Unserialize()
|
||||||
{
|
{
|
||||||
UInt32 magicNumber;
|
UInt32 magicNumber;
|
||||||
UInt32 version;
|
UInt32 version;
|
||||||
|
|
@ -558,12 +558,12 @@ namespace Nz
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderUnserializer::IsWriting() const
|
bool ShaderAstUnserializer::IsWriting() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Node(ShaderNodes::NodePtr& node)
|
void ShaderAstUnserializer::Node(ShaderNodes::NodePtr& node)
|
||||||
{
|
{
|
||||||
Int32 nodeTypeInt;
|
Int32 nodeTypeInt;
|
||||||
m_stream >> nodeTypeInt;
|
m_stream >> nodeTypeInt;
|
||||||
|
|
@ -599,7 +599,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Type(ShaderExpressionType& type)
|
void ShaderAstUnserializer::Type(ShaderExpressionType& type)
|
||||||
{
|
{
|
||||||
UInt8 typeIndex;
|
UInt8 typeIndex;
|
||||||
Value(typeIndex);
|
Value(typeIndex);
|
||||||
|
|
@ -629,52 +629,52 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Value(bool& val)
|
void ShaderAstUnserializer::Value(bool& val)
|
||||||
{
|
{
|
||||||
m_stream >> val;
|
m_stream >> val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Value(float& val)
|
void ShaderAstUnserializer::Value(float& val)
|
||||||
{
|
{
|
||||||
m_stream >> val;
|
m_stream >> val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Value(std::string& val)
|
void ShaderAstUnserializer::Value(std::string& val)
|
||||||
{
|
{
|
||||||
m_stream >> val;
|
m_stream >> val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Value(Vector2f& val)
|
void ShaderAstUnserializer::Value(Vector2f& val)
|
||||||
{
|
{
|
||||||
m_stream >> val;
|
m_stream >> val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Value(Vector3f& val)
|
void ShaderAstUnserializer::Value(Vector3f& val)
|
||||||
{
|
{
|
||||||
m_stream >> val;
|
m_stream >> val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Value(Vector4f& val)
|
void ShaderAstUnserializer::Value(Vector4f& val)
|
||||||
{
|
{
|
||||||
m_stream >> val;
|
m_stream >> val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Value(UInt8& val)
|
void ShaderAstUnserializer::Value(UInt8& val)
|
||||||
{
|
{
|
||||||
m_stream >> val;
|
m_stream >> val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Value(UInt16& val)
|
void ShaderAstUnserializer::Value(UInt16& val)
|
||||||
{
|
{
|
||||||
m_stream >> val;
|
m_stream >> val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Value(UInt32& val)
|
void ShaderAstUnserializer::Value(UInt32& val)
|
||||||
{
|
{
|
||||||
m_stream >> val;
|
m_stream >> val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderUnserializer::Variable(ShaderNodes::VariablePtr& var)
|
void ShaderAstUnserializer::Variable(ShaderNodes::VariablePtr& var)
|
||||||
{
|
{
|
||||||
Int32 nodeTypeInt;
|
Int32 nodeTypeInt;
|
||||||
m_stream >> nodeTypeInt;
|
m_stream >> nodeTypeInt;
|
||||||
|
|
@ -707,7 +707,7 @@ namespace Nz
|
||||||
ByteArray byteArray;
|
ByteArray byteArray;
|
||||||
ByteStream stream(&byteArray, OpenModeFlags(OpenMode_WriteOnly));
|
ByteStream stream(&byteArray, OpenModeFlags(OpenMode_WriteOnly));
|
||||||
|
|
||||||
ShaderSerializer serializer(stream);
|
ShaderAstSerializer serializer(stream);
|
||||||
serializer.Serialize(shader);
|
serializer.Serialize(shader);
|
||||||
|
|
||||||
return byteArray;
|
return byteArray;
|
||||||
|
|
@ -715,7 +715,7 @@ namespace Nz
|
||||||
|
|
||||||
ShaderAst UnserializeShader(ByteStream& stream)
|
ShaderAst UnserializeShader(ByteStream& stream)
|
||||||
{
|
{
|
||||||
ShaderUnserializer unserializer(stream);
|
ShaderAstUnserializer unserializer(stream);
|
||||||
return unserializer.Unserialize();
|
return unserializer.Unserialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderValidator.hpp>
|
#include <Nazara/Renderer/ShaderAstValidator.hpp>
|
||||||
#include <Nazara/Core/CallOnExit.hpp>
|
#include <Nazara/Core/CallOnExit.hpp>
|
||||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVariables.hpp>
|
#include <Nazara/Renderer/ShaderVariables.hpp>
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Nz
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ShaderValidator::Context
|
struct ShaderAstValidator::Context
|
||||||
{
|
{
|
||||||
struct Local
|
struct Local
|
||||||
{
|
{
|
||||||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
||||||
std::vector<std::size_t> blockLocalIndex;
|
std::vector<std::size_t> blockLocalIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ShaderValidator::Validate(std::string* error)
|
bool ShaderAstValidator::Validate(std::string* error)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -57,14 +57,14 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShaderNodes::ExpressionPtr& ShaderValidator::MandatoryExpr(const ShaderNodes::ExpressionPtr& node)
|
const ShaderNodes::ExpressionPtr& ShaderAstValidator::MandatoryExpr(const ShaderNodes::ExpressionPtr& node)
|
||||||
{
|
{
|
||||||
MandatoryNode(node);
|
MandatoryNode(node);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShaderNodes::NodePtr& ShaderValidator::MandatoryNode(const ShaderNodes::NodePtr& node)
|
const ShaderNodes::NodePtr& ShaderAstValidator::MandatoryNode(const ShaderNodes::NodePtr& node)
|
||||||
{
|
{
|
||||||
if (!node)
|
if (!node)
|
||||||
throw AstError{ "Invalid node" };
|
throw AstError{ "Invalid node" };
|
||||||
|
|
@ -72,18 +72,18 @@ namespace Nz
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::TypeMustMatch(const ShaderNodes::ExpressionPtr& left, const ShaderNodes::ExpressionPtr& right)
|
void ShaderAstValidator::TypeMustMatch(const ShaderNodes::ExpressionPtr& left, const ShaderNodes::ExpressionPtr& right)
|
||||||
{
|
{
|
||||||
return TypeMustMatch(left->GetExpressionType(), right->GetExpressionType());
|
return TypeMustMatch(left->GetExpressionType(), right->GetExpressionType());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::TypeMustMatch(const ShaderExpressionType& left, const ShaderExpressionType& right)
|
void ShaderAstValidator::TypeMustMatch(const ShaderExpressionType& left, const ShaderExpressionType& right)
|
||||||
{
|
{
|
||||||
if (left != right)
|
if (left != right)
|
||||||
throw AstError{ "Left expression type must match right expression type" };
|
throw AstError{ "Left expression type must match right expression type" };
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::AccessMember& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::AccessMember& node)
|
||||||
{
|
{
|
||||||
const ShaderExpressionType& exprType = MandatoryExpr(node.structExpr)->GetExpressionType();
|
const ShaderExpressionType& exprType = MandatoryExpr(node.structExpr)->GetExpressionType();
|
||||||
if (!std::holds_alternative<std::string>(exprType))
|
if (!std::holds_alternative<std::string>(exprType))
|
||||||
|
|
@ -105,7 +105,7 @@ namespace Nz
|
||||||
throw AstError{ "member type does not match node type" };
|
throw AstError{ "member type does not match node type" };
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::AssignOp& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::AssignOp& node)
|
||||||
{
|
{
|
||||||
MandatoryNode(node.left);
|
MandatoryNode(node.left);
|
||||||
MandatoryNode(node.right);
|
MandatoryNode(node.right);
|
||||||
|
|
@ -114,10 +114,10 @@ namespace Nz
|
||||||
if (node.left->GetExpressionCategory() != ShaderNodes::ExpressionCategory::LValue)
|
if (node.left->GetExpressionCategory() != ShaderNodes::ExpressionCategory::LValue)
|
||||||
throw AstError { "Assignation is only possible with a l-value" };
|
throw AstError { "Assignation is only possible with a l-value" };
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::BinaryOp& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::BinaryOp& node)
|
||||||
{
|
{
|
||||||
MandatoryNode(node.left);
|
MandatoryNode(node.left);
|
||||||
MandatoryNode(node.right);
|
MandatoryNode(node.right);
|
||||||
|
|
@ -186,10 +186,10 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::Branch& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::Branch& node)
|
||||||
{
|
{
|
||||||
for (const auto& condStatement : node.condStatements)
|
for (const auto& condStatement : node.condStatements)
|
||||||
{
|
{
|
||||||
|
|
@ -197,10 +197,10 @@ namespace Nz
|
||||||
MandatoryNode(condStatement.statement);
|
MandatoryNode(condStatement.statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::Cast& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::Cast& node)
|
||||||
{
|
{
|
||||||
unsigned int componentCount = 0;
|
unsigned int componentCount = 0;
|
||||||
unsigned int requiredComponents = node.GetComponentCount(node.exprType);
|
unsigned int requiredComponents = node.GetComponentCount(node.exprType);
|
||||||
|
|
@ -219,14 +219,14 @@ namespace Nz
|
||||||
if (componentCount != requiredComponents)
|
if (componentCount != requiredComponents)
|
||||||
throw AstError{ "Component count doesn't match required component count" };
|
throw AstError{ "Component count doesn't match required component count" };
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::Constant& /*node*/)
|
void ShaderAstValidator::Visit(const ShaderNodes::Constant& /*node*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::DeclareVariable& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::DeclareVariable& node)
|
||||||
{
|
{
|
||||||
assert(m_context);
|
assert(m_context);
|
||||||
|
|
||||||
|
|
@ -234,17 +234,17 @@ namespace Nz
|
||||||
local.name = node.variable->name;
|
local.name = node.variable->name;
|
||||||
local.type = node.variable->type;
|
local.type = node.variable->type;
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::ExpressionStatement& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::ExpressionStatement& node)
|
||||||
{
|
{
|
||||||
MandatoryNode(node.expression);
|
MandatoryNode(node.expression);
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::Identifier& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::Identifier& node)
|
||||||
{
|
{
|
||||||
assert(m_context);
|
assert(m_context);
|
||||||
|
|
||||||
|
|
@ -254,7 +254,7 @@ namespace Nz
|
||||||
Visit(node.var);
|
Visit(node.var);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::IntrinsicCall& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::IntrinsicCall& node)
|
||||||
{
|
{
|
||||||
switch (node.intrinsic)
|
switch (node.intrinsic)
|
||||||
{
|
{
|
||||||
|
|
@ -292,10 +292,10 @@ namespace Nz
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::Sample2D& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::Sample2D& node)
|
||||||
{
|
{
|
||||||
if (MandatoryExpr(node.sampler)->GetExpressionType() != ShaderExpressionType{ ShaderNodes::BasicType::Sampler2D })
|
if (MandatoryExpr(node.sampler)->GetExpressionType() != ShaderExpressionType{ ShaderNodes::BasicType::Sampler2D })
|
||||||
throw AstError{ "Sampler must be a Sampler2D" };
|
throw AstError{ "Sampler must be a Sampler2D" };
|
||||||
|
|
@ -303,10 +303,10 @@ namespace Nz
|
||||||
if (MandatoryExpr(node.coordinates)->GetExpressionType() != ShaderExpressionType{ ShaderNodes::BasicType::Float2 })
|
if (MandatoryExpr(node.coordinates)->GetExpressionType() != ShaderExpressionType{ ShaderNodes::BasicType::Float2 })
|
||||||
throw AstError{ "Coordinates must be a Float2" };
|
throw AstError{ "Coordinates must be a Float2" };
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::StatementBlock& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::StatementBlock& node)
|
||||||
{
|
{
|
||||||
assert(m_context);
|
assert(m_context);
|
||||||
|
|
||||||
|
|
@ -319,10 +319,10 @@ namespace Nz
|
||||||
m_context->declaredLocals.resize(m_context->blockLocalIndex.back());
|
m_context->declaredLocals.resize(m_context->blockLocalIndex.back());
|
||||||
m_context->blockLocalIndex.pop_back();
|
m_context->blockLocalIndex.pop_back();
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::SwizzleOp& node)
|
void ShaderAstValidator::Visit(const ShaderNodes::SwizzleOp& node)
|
||||||
{
|
{
|
||||||
if (node.componentCount > 4)
|
if (node.componentCount > 4)
|
||||||
throw AstError{ "Cannot swizzle more than four elements" };
|
throw AstError{ "Cannot swizzle more than four elements" };
|
||||||
|
|
@ -343,15 +343,15 @@ namespace Nz
|
||||||
throw AstError{ "Cannot swizzle this type" };
|
throw AstError{ "Cannot swizzle this type" };
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::BuiltinVariable& /*var*/)
|
void ShaderAstValidator::Visit(const ShaderNodes::BuiltinVariable& /*var*/)
|
||||||
{
|
{
|
||||||
/* Nothing to do */
|
/* Nothing to do */
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::InputVariable& var)
|
void ShaderAstValidator::Visit(const ShaderNodes::InputVariable& var)
|
||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < m_shader.GetInputCount(); ++i)
|
for (std::size_t i = 0; i < m_shader.GetInputCount(); ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -366,7 +366,7 @@ namespace Nz
|
||||||
throw AstError{ "Input not found" };
|
throw AstError{ "Input not found" };
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::LocalVariable& var)
|
void ShaderAstValidator::Visit(const ShaderNodes::LocalVariable& var)
|
||||||
{
|
{
|
||||||
const auto& vars = m_context->declaredLocals;
|
const auto& vars = m_context->declaredLocals;
|
||||||
|
|
||||||
|
|
@ -377,7 +377,7 @@ namespace Nz
|
||||||
TypeMustMatch(it->type, var.type);
|
TypeMustMatch(it->type, var.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::OutputVariable& var)
|
void ShaderAstValidator::Visit(const ShaderNodes::OutputVariable& var)
|
||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < m_shader.GetOutputCount(); ++i)
|
for (std::size_t i = 0; i < m_shader.GetOutputCount(); ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -392,7 +392,7 @@ namespace Nz
|
||||||
throw AstError{ "Output not found" };
|
throw AstError{ "Output not found" };
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::ParameterVariable& var)
|
void ShaderAstValidator::Visit(const ShaderNodes::ParameterVariable& var)
|
||||||
{
|
{
|
||||||
assert(m_context->currentFunction);
|
assert(m_context->currentFunction);
|
||||||
|
|
||||||
|
|
@ -405,7 +405,7 @@ namespace Nz
|
||||||
TypeMustMatch(it->type, var.type);
|
TypeMustMatch(it->type, var.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderValidator::Visit(const ShaderNodes::UniformVariable& var)
|
void ShaderAstValidator::Visit(const ShaderNodes::UniformVariable& var)
|
||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < m_shader.GetUniformCount(); ++i)
|
for (std::size_t i = 0; i < m_shader.GetUniformCount(); ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -422,7 +422,7 @@ namespace Nz
|
||||||
|
|
||||||
bool ValidateShader(const ShaderAst& shader, std::string* error)
|
bool ValidateShader(const ShaderAst& shader, std::string* error)
|
||||||
{
|
{
|
||||||
ShaderValidator validator(shader);
|
ShaderAstValidator validator(shader);
|
||||||
return validator.Validate(error);
|
return validator.Validate(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,14 +2,14 @@
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderVisitor.hpp>
|
#include <Nazara/Renderer/ShaderAstVisitor.hpp>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
ShaderVisitor::~ShaderVisitor() = default;
|
ShaderAstVisitor::~ShaderAstVisitor() = default;
|
||||||
|
|
||||||
void ShaderVisitor::EnableCondition(const std::string& name, bool cond)
|
void ShaderAstVisitor::EnableCondition(const std::string& name, bool cond)
|
||||||
{
|
{
|
||||||
if (cond)
|
if (cond)
|
||||||
m_conditions.insert(name);
|
m_conditions.insert(name);
|
||||||
|
|
@ -17,12 +17,12 @@ namespace Nz
|
||||||
m_conditions.erase(name);
|
m_conditions.erase(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderVisitor::IsConditionEnabled(const std::string& name) const
|
bool ShaderAstVisitor::IsConditionEnabled(const std::string& name) const
|
||||||
{
|
{
|
||||||
return m_conditions.count(name) != 0;
|
return m_conditions.count(name) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderVisitor::Visit(const ShaderNodes::NodePtr& node)
|
void ShaderAstVisitor::Visit(const ShaderNodes::NodePtr& node)
|
||||||
{
|
{
|
||||||
node->Visit(*this);
|
node->Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderNodes.hpp>
|
#include <Nazara/Renderer/ShaderNodes.hpp>
|
||||||
#include <Nazara/Core/Algorithm.hpp>
|
#include <Nazara/Core/Algorithm.hpp>
|
||||||
#include <Nazara/Renderer/ShaderSerializer.hpp>
|
#include <Nazara/Renderer/ShaderAstSerializer.hpp>
|
||||||
#include <Nazara/Renderer/ShaderVisitor.hpp>
|
#include <Nazara/Renderer/ShaderAstVisitor.hpp>
|
||||||
#include <Nazara/Renderer/ShaderWriter.hpp>
|
#include <Nazara/Renderer/ShaderWriter.hpp>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
|
|
@ -18,26 +18,26 @@ namespace Nz::ShaderNodes
|
||||||
return ExpressionCategory::RValue;
|
return ExpressionCategory::RValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionStatement::Visit(ShaderVisitor& visitor)
|
void ExpressionStatement::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConditionalStatement::Visit(ShaderVisitor& visitor)
|
void ConditionalStatement::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
if (visitor.IsConditionEnabled(conditionName))
|
if (visitor.IsConditionEnabled(conditionName))
|
||||||
statement->Visit(visitor);
|
statement->Visit(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void StatementBlock::Visit(ShaderVisitor& visitor)
|
void StatementBlock::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DeclareVariable::Visit(ShaderVisitor& visitor)
|
void DeclareVariable::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +54,7 @@ namespace Nz::ShaderNodes
|
||||||
return var->type;
|
return var->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Identifier::Visit(ShaderVisitor& visitor)
|
void Identifier::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +69,7 @@ namespace Nz::ShaderNodes
|
||||||
return exprType;
|
return exprType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccessMember::Visit(ShaderVisitor& visitor)
|
void AccessMember::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +79,7 @@ namespace Nz::ShaderNodes
|
||||||
return left->GetExpressionType();
|
return left->GetExpressionType();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignOp::Visit(ShaderVisitor& visitor)
|
void AssignOp::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -137,13 +137,13 @@ namespace Nz::ShaderNodes
|
||||||
return *exprType;
|
return *exprType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryOp::Visit(ShaderVisitor& visitor)
|
void BinaryOp::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Branch::Visit(ShaderVisitor& visitor)
|
void Branch::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -170,7 +170,7 @@ namespace Nz::ShaderNodes
|
||||||
}, value);
|
}, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Constant::Visit(ShaderVisitor& visitor)
|
void Constant::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +180,7 @@ namespace Nz::ShaderNodes
|
||||||
return exprType;
|
return exprType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cast::Visit(ShaderVisitor& visitor)
|
void Cast::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +199,7 @@ namespace Nz::ShaderNodes
|
||||||
return static_cast<BasicType>(UnderlyingCast(GetComponentType(std::get<BasicType>(exprType))) + componentCount - 1);
|
return static_cast<BasicType>(UnderlyingCast(GetComponentType(std::get<BasicType>(exprType))) + componentCount - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwizzleOp::Visit(ShaderVisitor& visitor)
|
void SwizzleOp::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -210,7 +210,7 @@ namespace Nz::ShaderNodes
|
||||||
return BasicType::Float4;
|
return BasicType::Float4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sample2D::Visit(ShaderVisitor& visitor)
|
void Sample2D::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -231,7 +231,7 @@ namespace Nz::ShaderNodes
|
||||||
return BasicType::Void;
|
return BasicType::Void;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntrinsicCall::Visit(ShaderVisitor& visitor)
|
void IntrinsicCall::Visit(ShaderAstVisitor& visitor)
|
||||||
{
|
{
|
||||||
visitor.Visit(*this);
|
visitor.Visit(*this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
// Copyright (C) 2015 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
|
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderRecursiveVisitor.hpp>
|
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::AccessMember& node)
|
|
||||||
{
|
|
||||||
Visit(node.structExpr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::AssignOp& node)
|
|
||||||
{
|
|
||||||
Visit(node.left);
|
|
||||||
Visit(node.right);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::BinaryOp& node)
|
|
||||||
{
|
|
||||||
Visit(node.left);
|
|
||||||
Visit(node.right);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::Branch& node)
|
|
||||||
{
|
|
||||||
for (auto& cond : node.condStatements)
|
|
||||||
{
|
|
||||||
Visit(cond.condition);
|
|
||||||
Visit(cond.statement);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.elseStatement)
|
|
||||||
Visit(node.elseStatement);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::Cast& node)
|
|
||||||
{
|
|
||||||
for (auto& expr : node.expressions)
|
|
||||||
{
|
|
||||||
if (!expr)
|
|
||||||
break;
|
|
||||||
|
|
||||||
Visit(expr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::Constant& /*node*/)
|
|
||||||
{
|
|
||||||
/* Nothing to do */
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::DeclareVariable& node)
|
|
||||||
{
|
|
||||||
if (node.expression)
|
|
||||||
Visit(node.expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::ExpressionStatement& node)
|
|
||||||
{
|
|
||||||
Visit(node.expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::Identifier& /*node*/)
|
|
||||||
{
|
|
||||||
/* Nothing to do */
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::IntrinsicCall& node)
|
|
||||||
{
|
|
||||||
for (auto& param : node.parameters)
|
|
||||||
Visit(param);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::Sample2D& node)
|
|
||||||
{
|
|
||||||
Visit(node.sampler);
|
|
||||||
Visit(node.coordinates);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::StatementBlock& node)
|
|
||||||
{
|
|
||||||
for (auto& statement : node.statements)
|
|
||||||
Visit(statement);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderRecursiveVisitor::Visit(const ShaderNodes::SwizzleOp& node)
|
|
||||||
{
|
|
||||||
Visit(node.expression);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <Nazara/Renderer/SpirvWriter.hpp>
|
#include <Nazara/Renderer/SpirvWriter.hpp>
|
||||||
#include <Nazara/Core/CallOnExit.hpp>
|
#include <Nazara/Core/CallOnExit.hpp>
|
||||||
#include <Nazara/Core/Endianness.hpp>
|
#include <Nazara/Core/Endianness.hpp>
|
||||||
#include <Nazara/Renderer/ShaderValidator.hpp>
|
#include <Nazara/Renderer/ShaderAstValidator.hpp>
|
||||||
#include <tsl/ordered_map.h>
|
#include <tsl/ordered_map.h>
|
||||||
#include <tsl/ordered_set.h>
|
#include <tsl/ordered_set.h>
|
||||||
#include <SpirV/spirv.h>
|
#include <SpirV/spirv.h>
|
||||||
|
|
@ -22,7 +22,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
using ConstantVariant = ShaderNodes::Constant::Variant;
|
using ConstantVariant = ShaderNodes::Constant::Variant;
|
||||||
|
|
||||||
class PreVisitor : public ShaderRecursiveVisitor, public ShaderVarVisitor
|
class PreVisitor : public ShaderAstRecursiveVisitor, public ShaderVarVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using BuiltinContainer = std::unordered_set<std::shared_ptr<const ShaderNodes::BuiltinVariable>>;
|
using BuiltinContainer = std::unordered_set<std::shared_ptr<const ShaderNodes::BuiltinVariable>>;
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Nz
|
||||||
using LocalContainer = std::unordered_set<std::shared_ptr<const ShaderNodes::LocalVariable>>;
|
using LocalContainer = std::unordered_set<std::shared_ptr<const ShaderNodes::LocalVariable>>;
|
||||||
using ParameterContainer = std::unordered_set< std::shared_ptr<const ShaderNodes::ParameterVariable>>;
|
using ParameterContainer = std::unordered_set< std::shared_ptr<const ShaderNodes::ParameterVariable>>;
|
||||||
|
|
||||||
using ShaderRecursiveVisitor::Visit;
|
using ShaderAstRecursiveVisitor::Visit;
|
||||||
using ShaderVarVisitor::Visit;
|
using ShaderVarVisitor::Visit;
|
||||||
|
|
||||||
void Visit(const ShaderNodes::Constant& node) override
|
void Visit(const ShaderNodes::Constant& node) override
|
||||||
|
|
@ -68,26 +68,26 @@ namespace Nz
|
||||||
},
|
},
|
||||||
node.value);
|
node.value);
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visit(const ShaderNodes::DeclareVariable& node) override
|
void Visit(const ShaderNodes::DeclareVariable& node) override
|
||||||
{
|
{
|
||||||
Visit(node.variable);
|
Visit(node.variable);
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visit(const ShaderNodes::Identifier& node) override
|
void Visit(const ShaderNodes::Identifier& node) override
|
||||||
{
|
{
|
||||||
Visit(node.var);
|
Visit(node.var);
|
||||||
|
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visit(const ShaderNodes::IntrinsicCall& node) override
|
void Visit(const ShaderNodes::IntrinsicCall& node) override
|
||||||
{
|
{
|
||||||
ShaderRecursiveVisitor::Visit(node);
|
ShaderAstRecursiveVisitor::Visit(node);
|
||||||
|
|
||||||
switch (node.intrinsic)
|
switch (node.intrinsic)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include <ShaderNode/Widgets/MainWindow.hpp>
|
#include <ShaderNode/Widgets/MainWindow.hpp>
|
||||||
#include <Nazara/Core/File.hpp>
|
#include <Nazara/Core/File.hpp>
|
||||||
#include <Nazara/Renderer/GlslWriter.hpp>
|
#include <Nazara/Renderer/GlslWriter.hpp>
|
||||||
#include <Nazara/Renderer/ShaderSerializer.hpp>
|
#include <Nazara/Renderer/ShaderAstSerializer.hpp>
|
||||||
#include <ShaderNode/ShaderGraph.hpp>
|
#include <ShaderNode/ShaderGraph.hpp>
|
||||||
#include <ShaderNode/Widgets/BufferEditor.hpp>
|
#include <ShaderNode/Widgets/BufferEditor.hpp>
|
||||||
#include <ShaderNode/Widgets/InputEditor.hpp>
|
#include <ShaderNode/Widgets/InputEditor.hpp>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue