Shader: Add SourceLocation members
TODO: Fill from Parser and use them for error throwing in SanitizeVisitor
This commit is contained in:
parent
b8bf19f8cd
commit
960ab64d98
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Shader/Config.hpp>
|
#include <Nazara/Shader/Config.hpp>
|
||||||
|
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||||
#include <Nazara/Shader/Ast/Attribute.hpp>
|
#include <Nazara/Shader/Ast/Attribute.hpp>
|
||||||
#include <Nazara/Shader/Ast/Module.hpp>
|
#include <Nazara/Shader/Ast/Module.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -23,12 +24,15 @@ namespace Nz::ShaderAst
|
||||||
|
|
||||||
template<typename T> bool Compare(const T& lhs, const T& rhs);
|
template<typename T> bool Compare(const T& lhs, const T& rhs);
|
||||||
template<typename T, std::size_t S> bool Compare(const std::array<T, S>& lhs, const std::array<T, S>& rhs);
|
template<typename T, std::size_t S> bool Compare(const std::array<T, S>& lhs, const std::array<T, S>& rhs);
|
||||||
|
template<typename T> bool Compare(const std::shared_ptr<T>& lhs, const std::shared_ptr<T>& rhs);
|
||||||
template<typename T> bool Compare(const std::vector<T>& lhs, const std::vector<T>& rhs);
|
template<typename T> bool Compare(const std::vector<T>& lhs, const std::vector<T>& rhs);
|
||||||
template<typename T> bool Compare(const std::unique_ptr<T>& lhs, const std::unique_ptr<T>& rhs);
|
template<typename T> bool Compare(const std::unique_ptr<T>& lhs, const std::unique_ptr<T>& rhs);
|
||||||
template<typename T> bool Compare(const ExpressionValue<T>& lhs, const ExpressionValue<T>& rhs);
|
template<typename T> bool Compare(const ExpressionValue<T>& lhs, const ExpressionValue<T>& rhs);
|
||||||
|
inline bool Compare(const AccessIdentifierExpression::Identifier& lhs, const AccessIdentifierExpression::Identifier& rhs);
|
||||||
inline bool Compare(const BranchStatement::ConditionalStatement& lhs, const BranchStatement::ConditionalStatement& rhs);
|
inline bool Compare(const BranchStatement::ConditionalStatement& lhs, const BranchStatement::ConditionalStatement& rhs);
|
||||||
inline bool Compare(const DeclareExternalStatement::ExternalVar& lhs, const DeclareExternalStatement::ExternalVar& rhs);
|
inline bool Compare(const DeclareExternalStatement::ExternalVar& lhs, const DeclareExternalStatement::ExternalVar& rhs);
|
||||||
inline bool Compare(const DeclareFunctionStatement::Parameter& lhs, const DeclareFunctionStatement::Parameter& rhs);
|
inline bool Compare(const DeclareFunctionStatement::Parameter& lhs, const DeclareFunctionStatement::Parameter& rhs);
|
||||||
|
inline bool Compare(const ShaderLang::SourceLocation& lhs, const ShaderLang::SourceLocation& rhs);
|
||||||
inline bool Compare(const StructDescription& lhs, const StructDescription& rhs);
|
inline bool Compare(const StructDescription& lhs, const StructDescription& rhs);
|
||||||
inline bool Compare(const StructDescription::StructMember& lhs, const StructDescription::StructMember& rhs);
|
inline bool Compare(const StructDescription::StructMember& lhs, const StructDescription::StructMember& rhs);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ namespace Nz::ShaderAst
|
||||||
if (lhs.GetType() != rhs.GetType())
|
if (lhs.GetType() != rhs.GetType())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||||
|
return false;
|
||||||
|
|
||||||
switch (lhs.GetType())
|
switch (lhs.GetType())
|
||||||
{
|
{
|
||||||
case NodeType::None: break;
|
case NodeType::None: break;
|
||||||
|
|
@ -70,6 +73,9 @@ namespace Nz::ShaderAst
|
||||||
if (lhs.GetType() != rhs.GetType())
|
if (lhs.GetType() != rhs.GetType())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||||
|
return false;
|
||||||
|
|
||||||
switch (lhs.GetType())
|
switch (lhs.GetType())
|
||||||
{
|
{
|
||||||
case NodeType::None: break;
|
case NodeType::None: break;
|
||||||
|
|
@ -101,6 +107,17 @@ namespace Nz::ShaderAst
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool Compare(const std::shared_ptr<T>& lhs, const std::shared_ptr<T>& rhs)
|
||||||
|
{
|
||||||
|
if (lhs == nullptr)
|
||||||
|
return rhs == nullptr;
|
||||||
|
else if (rhs == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Compare(*lhs, *rhs);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Compare(const std::vector<T>& lhs, const std::vector<T>& rhs)
|
bool Compare(const std::vector<T>& lhs, const std::vector<T>& rhs)
|
||||||
{
|
{
|
||||||
|
|
@ -153,6 +170,17 @@ namespace Nz::ShaderAst
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Compare(const AccessIdentifierExpression::Identifier& lhs, const AccessIdentifierExpression::Identifier& rhs)
|
||||||
|
{
|
||||||
|
if (!Compare(lhs.identifier, rhs.identifier))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool Compare(const BranchStatement::ConditionalStatement& lhs, const BranchStatement::ConditionalStatement& rhs)
|
inline bool Compare(const BranchStatement::ConditionalStatement& lhs, const BranchStatement::ConditionalStatement& rhs)
|
||||||
{
|
{
|
||||||
if (!Compare(lhs.condition, rhs.condition))
|
if (!Compare(lhs.condition, rhs.condition))
|
||||||
|
|
@ -178,6 +206,9 @@ namespace Nz::ShaderAst
|
||||||
if (!Compare(lhs.type, rhs.type))
|
if (!Compare(lhs.type, rhs.type))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,6 +220,29 @@ namespace Nz::ShaderAst
|
||||||
if (!Compare(lhs.type, rhs.type))
|
if (!Compare(lhs.type, rhs.type))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Compare(const ShaderLang::SourceLocation& lhs, const ShaderLang::SourceLocation& rhs)
|
||||||
|
{
|
||||||
|
if (!Compare(lhs.endColumn, rhs.endColumn))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.endLine, rhs.endLine))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.startColumn, rhs.startColumn))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.startLine, rhs.startLine))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.file, rhs.file))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,6 +277,9 @@ namespace Nz::ShaderAst
|
||||||
if (!Compare(lhs.type, rhs.type))
|
if (!Compare(lhs.type, rhs.type))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <Nazara/Core/ByteArray.hpp>
|
#include <Nazara/Core/ByteArray.hpp>
|
||||||
#include <Nazara/Core/ByteStream.hpp>
|
#include <Nazara/Core/ByteStream.hpp>
|
||||||
#include <Nazara/Shader/Config.hpp>
|
#include <Nazara/Shader/Config.hpp>
|
||||||
|
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||||
#include <Nazara/Shader/Ast/Module.hpp>
|
#include <Nazara/Shader/Ast/Module.hpp>
|
||||||
|
|
||||||
namespace Nz::ShaderAst
|
namespace Nz::ShaderAst
|
||||||
|
|
@ -43,7 +44,6 @@ namespace Nz::ShaderAst
|
||||||
void Serialize(TypeExpression& node);
|
void Serialize(TypeExpression& node);
|
||||||
void Serialize(VariableValueExpression& node);
|
void Serialize(VariableValueExpression& node);
|
||||||
void Serialize(UnaryExpression& node);
|
void Serialize(UnaryExpression& node);
|
||||||
void SerializeExpressionCommon(Expression& expr);
|
|
||||||
|
|
||||||
void Serialize(BranchStatement& node);
|
void Serialize(BranchStatement& node);
|
||||||
void Serialize(ConditionalStatement& node);
|
void Serialize(ConditionalStatement& node);
|
||||||
|
|
@ -65,6 +65,9 @@ namespace Nz::ShaderAst
|
||||||
void Serialize(ScopedStatement& node);
|
void Serialize(ScopedStatement& node);
|
||||||
void Serialize(WhileStatement& node);
|
void Serialize(WhileStatement& node);
|
||||||
|
|
||||||
|
void SerializeExpressionCommon(Expression& expr);
|
||||||
|
void SerializeNodeCommon(ShaderAst::Node& node);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<typename T> void Container(T& container);
|
template<typename T> void Container(T& container);
|
||||||
template<typename T> void Enum(T& enumVal);
|
template<typename T> void Enum(T& enumVal);
|
||||||
|
|
@ -75,11 +78,14 @@ namespace Nz::ShaderAst
|
||||||
|
|
||||||
virtual bool IsWriting() const = 0;
|
virtual bool IsWriting() const = 0;
|
||||||
|
|
||||||
virtual void SerializeModule(ModulePtr& module) = 0;
|
|
||||||
|
|
||||||
virtual void Node(ExpressionPtr& node) = 0;
|
virtual void Node(ExpressionPtr& node) = 0;
|
||||||
virtual void Node(StatementPtr& node) = 0;
|
virtual void Node(StatementPtr& node) = 0;
|
||||||
|
|
||||||
|
virtual void SerializeModule(ModulePtr& module) = 0;
|
||||||
|
virtual void SharedString(std::shared_ptr<const std::string>& val) = 0;
|
||||||
|
|
||||||
|
inline void SourceLoc(ShaderLang::SourceLocation& sourceLoc);
|
||||||
|
|
||||||
virtual void Type(ExpressionType& type) = 0;
|
virtual void Type(ExpressionType& type) = 0;
|
||||||
|
|
||||||
virtual void Value(bool& val) = 0;
|
virtual void Value(bool& val) = 0;
|
||||||
|
|
@ -110,11 +116,11 @@ namespace Nz::ShaderAst
|
||||||
private:
|
private:
|
||||||
using AstSerializerBase::Serialize;
|
using AstSerializerBase::Serialize;
|
||||||
|
|
||||||
void SerializeModule(ModulePtr& module) override;
|
|
||||||
|
|
||||||
bool IsWriting() const override;
|
bool IsWriting() const override;
|
||||||
void Node(ExpressionPtr& node) override;
|
void Node(ExpressionPtr& node) override;
|
||||||
void Node(StatementPtr& node) override;
|
void Node(StatementPtr& node) override;
|
||||||
|
void SerializeModule(ModulePtr& module) override;
|
||||||
|
void SharedString(std::shared_ptr<const std::string>& val) override;
|
||||||
void Type(ExpressionType& type) override;
|
void Type(ExpressionType& type) override;
|
||||||
void Value(bool& val) override;
|
void Value(bool& val) override;
|
||||||
void Value(float& val) override;
|
void Value(float& val) override;
|
||||||
|
|
@ -131,6 +137,7 @@ namespace Nz::ShaderAst
|
||||||
void Value(UInt32& val) override;
|
void Value(UInt32& val) override;
|
||||||
void Value(UInt64& val) override;
|
void Value(UInt64& val) override;
|
||||||
|
|
||||||
|
std::unordered_map<std::string, UInt32> m_stringIndices;
|
||||||
ByteStream& m_stream;
|
ByteStream& m_stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -145,11 +152,11 @@ namespace Nz::ShaderAst
|
||||||
private:
|
private:
|
||||||
using AstSerializerBase::Serialize;
|
using AstSerializerBase::Serialize;
|
||||||
|
|
||||||
void SerializeModule(ModulePtr& module) override;
|
|
||||||
|
|
||||||
bool IsWriting() const override;
|
bool IsWriting() const override;
|
||||||
void Node(ExpressionPtr& node) override;
|
void Node(ExpressionPtr& node) override;
|
||||||
void Node(StatementPtr& node) override;
|
void Node(StatementPtr& node) override;
|
||||||
|
void SerializeModule(ModulePtr& module) override;
|
||||||
|
void SharedString(std::shared_ptr<const std::string>& val) override;
|
||||||
void Type(ExpressionType& type) override;
|
void Type(ExpressionType& type) override;
|
||||||
void Value(bool& val) override;
|
void Value(bool& val) override;
|
||||||
void Value(float& val) override;
|
void Value(float& val) override;
|
||||||
|
|
@ -166,6 +173,7 @@ namespace Nz::ShaderAst
|
||||||
void Value(UInt32& val) override;
|
void Value(UInt32& val) override;
|
||||||
void Value(UInt64& val) override;
|
void Value(UInt64& val) override;
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<const std::string>> m_strings;
|
||||||
ByteStream& m_stream;
|
ByteStream& m_stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,15 @@ namespace Nz::ShaderAst
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void AstSerializerBase::SourceLoc(ShaderLang::SourceLocation& sourceLoc)
|
||||||
|
{
|
||||||
|
SharedString(sourceLoc.file);
|
||||||
|
Value(sourceLoc.endColumn);
|
||||||
|
Value(sourceLoc.endLine);
|
||||||
|
Value(sourceLoc.startColumn);
|
||||||
|
Value(sourceLoc.startLine);
|
||||||
|
}
|
||||||
|
|
||||||
inline void AstSerializerBase::SizeT(std::size_t& val)
|
inline void AstSerializerBase::SizeT(std::size_t& val)
|
||||||
{
|
{
|
||||||
bool isWriting = IsWriting();
|
bool isWriting = IsWriting();
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#define NAZARA_SHADER_AST_EXPRESSIONTYPE_HPP
|
#define NAZARA_SHADER_AST_EXPRESSIONTYPE_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
|
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||||
#include <Nazara/Shader/Ast/Attribute.hpp>
|
#include <Nazara/Shader/Ast/Attribute.hpp>
|
||||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
|
|
@ -166,6 +167,7 @@ namespace Nz::ShaderAst
|
||||||
ExpressionValue<UInt32> locationIndex;
|
ExpressionValue<UInt32> locationIndex;
|
||||||
ExpressionValue<ExpressionType> type;
|
ExpressionValue<ExpressionType> type;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
ShaderLang::SourceLocation sourceLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
ExpressionValue<StructLayout> layout;
|
ExpressionValue<StructLayout> layout;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include <Nazara/Math/Vector3.hpp>
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
#include <Nazara/Math/Vector4.hpp>
|
#include <Nazara/Math/Vector4.hpp>
|
||||||
#include <Nazara/Shader/Config.hpp>
|
#include <Nazara/Shader/Config.hpp>
|
||||||
|
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||||
#include <Nazara/Shader/Ast/Attribute.hpp>
|
#include <Nazara/Shader/Ast/Attribute.hpp>
|
||||||
#include <Nazara/Shader/Ast/ConstantValue.hpp>
|
#include <Nazara/Shader/Ast/ConstantValue.hpp>
|
||||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||||
|
|
@ -41,6 +42,8 @@ namespace Nz::ShaderAst
|
||||||
|
|
||||||
Node& operator=(const Node&) = delete;
|
Node& operator=(const Node&) = delete;
|
||||||
Node& operator=(Node&&) noexcept = default;
|
Node& operator=(Node&&) noexcept = default;
|
||||||
|
|
||||||
|
ShaderLang::SourceLocation sourceLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
|
|
@ -69,7 +72,13 @@ namespace Nz::ShaderAst
|
||||||
NodeType GetType() const override;
|
NodeType GetType() const override;
|
||||||
void Visit(AstExpressionVisitor& visitor) override;
|
void Visit(AstExpressionVisitor& visitor) override;
|
||||||
|
|
||||||
std::vector<std::string> identifiers;
|
struct Identifier
|
||||||
|
{
|
||||||
|
std::string identifier;
|
||||||
|
ShaderLang::SourceLocation sourceLocation;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<Identifier> identifiers;
|
||||||
ExpressionPtr expr;
|
ExpressionPtr expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -317,6 +326,7 @@ namespace Nz::ShaderAst
|
||||||
ExpressionValue<UInt32> bindingIndex;
|
ExpressionValue<UInt32> bindingIndex;
|
||||||
ExpressionValue<UInt32> bindingSet;
|
ExpressionValue<UInt32> bindingSet;
|
||||||
ExpressionValue<ExpressionType> type;
|
ExpressionValue<ExpressionType> type;
|
||||||
|
ShaderLang::SourceLocation sourceLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<ExternalVar> externalVars;
|
std::vector<ExternalVar> externalVars;
|
||||||
|
|
@ -330,9 +340,10 @@ namespace Nz::ShaderAst
|
||||||
|
|
||||||
struct Parameter
|
struct Parameter
|
||||||
{
|
{
|
||||||
ExpressionValue<ExpressionType> type;
|
|
||||||
std::optional<std::size_t> varIndex;
|
std::optional<std::size_t> varIndex;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
ExpressionValue<ExpressionType> type;
|
||||||
|
ShaderLang::SourceLocation sourceLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::optional<std::size_t> funcIndex;
|
std::optional<std::size_t> funcIndex;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,12 @@ namespace Nz::ShaderBuilder
|
||||||
{
|
{
|
||||||
auto accessMemberNode = std::make_unique<ShaderAst::AccessIdentifierExpression>();
|
auto accessMemberNode = std::make_unique<ShaderAst::AccessIdentifierExpression>();
|
||||||
accessMemberNode->expr = std::move(expr);
|
accessMemberNode->expr = std::move(expr);
|
||||||
accessMemberNode->identifiers = std::move(memberIdentifiers);
|
accessMemberNode->identifiers.reserve(memberIdentifiers.size());
|
||||||
|
for (std::string& identifier : memberIdentifiers)
|
||||||
|
{
|
||||||
|
auto& identifierEntry = accessMemberNode->identifiers.emplace_back();
|
||||||
|
identifierEntry.identifier = std::move(identifier);
|
||||||
|
}
|
||||||
|
|
||||||
return accessMemberNode;
|
return accessMemberNode;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Shader/Config.hpp>
|
#include <Nazara/Shader/Config.hpp>
|
||||||
#include <Nazara/Shader/ShaderLangParser.hpp>
|
#include <Nazara/Shader/ShaderLangParser.hpp>
|
||||||
|
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -18,22 +19,6 @@
|
||||||
|
|
||||||
namespace Nz::ShaderLang
|
namespace Nz::ShaderLang
|
||||||
{
|
{
|
||||||
struct SourceLocation
|
|
||||||
{
|
|
||||||
inline SourceLocation();
|
|
||||||
inline SourceLocation(unsigned int line, unsigned int column, std::shared_ptr<const std::string> file);
|
|
||||||
inline SourceLocation(unsigned int line, unsigned int startColumn, unsigned int endColumn, std::shared_ptr<const std::string> file);
|
|
||||||
inline SourceLocation(unsigned int startLine, unsigned int endLine, unsigned int startColumn, unsigned int endColumn, std::shared_ptr<const std::string> file);
|
|
||||||
|
|
||||||
inline bool IsValid() const;
|
|
||||||
|
|
||||||
std::shared_ptr<const std::string> file; //< Since the same file will be used for every node, prevent holding X time the same path
|
|
||||||
unsigned int endColumn;
|
|
||||||
unsigned int endLine;
|
|
||||||
unsigned int startColumn;
|
|
||||||
unsigned int startLine;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ErrorCategory
|
enum class ErrorCategory
|
||||||
{
|
{
|
||||||
Ast,
|
Ast,
|
||||||
|
|
|
||||||
|
|
@ -7,46 +7,6 @@
|
||||||
|
|
||||||
namespace Nz::ShaderLang
|
namespace Nz::ShaderLang
|
||||||
{
|
{
|
||||||
inline SourceLocation::SourceLocation() :
|
|
||||||
endColumn(0),
|
|
||||||
endLine(0),
|
|
||||||
startColumn(0),
|
|
||||||
startLine(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SourceLocation::SourceLocation(unsigned int Line, unsigned int Column, std::shared_ptr<const std::string> File) :
|
|
||||||
file(std::move(File)),
|
|
||||||
endColumn(Column),
|
|
||||||
endLine(Line),
|
|
||||||
startColumn(Column),
|
|
||||||
startLine(Line)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SourceLocation::SourceLocation(unsigned int Line, unsigned int StartColumn, unsigned int EndColumn, std::shared_ptr<const std::string> File) :
|
|
||||||
file(std::move(File)),
|
|
||||||
endColumn(EndColumn),
|
|
||||||
endLine(Line),
|
|
||||||
startColumn(StartColumn),
|
|
||||||
startLine(Line)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SourceLocation::SourceLocation(unsigned int StartLine, unsigned int EndLine, unsigned int StartColumn, unsigned int EndColumn, std::shared_ptr<const std::string> File) :
|
|
||||||
file(std::move(File)),
|
|
||||||
endColumn(EndColumn),
|
|
||||||
endLine(EndLine),
|
|
||||||
startColumn(StartColumn),
|
|
||||||
startLine(StartLine)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool SourceLocation::IsValid() const
|
|
||||||
{
|
|
||||||
return startLine != 0 && endLine != 0 && endColumn != 0 && startColumn != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Error::Error(SourceLocation sourceLocation, ErrorCategory errorCategory, unsigned int errorType) noexcept :
|
inline Error::Error(SourceLocation sourceLocation, ErrorCategory errorCategory, unsigned int errorType) noexcept :
|
||||||
m_errorCategory(errorCategory),
|
m_errorCategory(errorCategory),
|
||||||
m_sourceLocation(std::move(sourceLocation)),
|
m_sourceLocation(std::move(sourceLocation)),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||||
|
// This file is part of the "Nazara Engine - Shader module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_SHADER_SHADERLANGSOURCELOCATION_HPP
|
||||||
|
#define NAZARA_SHADER_SHADERLANGSOURCELOCATION_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequisites.hpp>
|
||||||
|
#include <Nazara/Shader/Config.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Nz::ShaderLang
|
||||||
|
{
|
||||||
|
struct SourceLocation
|
||||||
|
{
|
||||||
|
inline SourceLocation();
|
||||||
|
inline SourceLocation(unsigned int line, unsigned int column, std::shared_ptr<const std::string> file);
|
||||||
|
inline SourceLocation(unsigned int line, unsigned int startColumn, unsigned int endColumn, std::shared_ptr<const std::string> file);
|
||||||
|
inline SourceLocation(unsigned int startLine, unsigned int endLine, unsigned int startColumn, unsigned int endColumn, std::shared_ptr<const std::string> file);
|
||||||
|
|
||||||
|
inline bool IsValid() const;
|
||||||
|
|
||||||
|
std::shared_ptr<const std::string> file; //< Since the same file will be used for every node, prevent holding X time the same path
|
||||||
|
UInt32 endColumn;
|
||||||
|
UInt32 endLine;
|
||||||
|
UInt32 startColumn;
|
||||||
|
UInt32 startLine;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Shader/ShaderLangSourceLocation.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_SHADER_SHADERLANGSOURCELOCATION_HPP
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||||
|
// This file is part of the "Nazara Engine - Shader module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||||
|
#include <Nazara/Shader/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz::ShaderLang
|
||||||
|
{
|
||||||
|
inline SourceLocation::SourceLocation() :
|
||||||
|
endColumn(0),
|
||||||
|
endLine(0),
|
||||||
|
startColumn(0),
|
||||||
|
startLine(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline SourceLocation::SourceLocation(unsigned int Line, unsigned int Column, std::shared_ptr<const std::string> File) :
|
||||||
|
file(std::move(File)),
|
||||||
|
endColumn(Column),
|
||||||
|
endLine(Line),
|
||||||
|
startColumn(Column),
|
||||||
|
startLine(Line)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline SourceLocation::SourceLocation(unsigned int Line, unsigned int StartColumn, unsigned int EndColumn, std::shared_ptr<const std::string> File) :
|
||||||
|
file(std::move(File)),
|
||||||
|
endColumn(EndColumn),
|
||||||
|
endLine(Line),
|
||||||
|
startColumn(StartColumn),
|
||||||
|
startLine(Line)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline SourceLocation::SourceLocation(unsigned int StartLine, unsigned int EndLine, unsigned int StartColumn, unsigned int EndColumn, std::shared_ptr<const std::string> File) :
|
||||||
|
file(std::move(File)),
|
||||||
|
endColumn(EndColumn),
|
||||||
|
endLine(EndLine),
|
||||||
|
startColumn(StartColumn),
|
||||||
|
startLine(StartLine)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool SourceLocation::IsValid() const
|
||||||
|
{
|
||||||
|
return startLine != 0 && endLine != 0 && endColumn != 0 && startColumn != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Shader/DebugOff.hpp>
|
||||||
|
|
@ -26,12 +26,14 @@ namespace Nz::ShaderAst
|
||||||
#define NAZARA_SHADERAST_EXPRESSION(Node) void Visit(Node& node) override \
|
#define NAZARA_SHADERAST_EXPRESSION(Node) void Visit(Node& node) override \
|
||||||
{ \
|
{ \
|
||||||
m_serializer.Serialize(node); \
|
m_serializer.Serialize(node); \
|
||||||
|
m_serializer.SerializeNodeCommon(node); \
|
||||||
m_serializer.SerializeExpressionCommon(node); \
|
m_serializer.SerializeExpressionCommon(node); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NAZARA_SHADERAST_STATEMENT(Node) void Visit(Node& node) override \
|
#define NAZARA_SHADERAST_STATEMENT(Node) void Visit(Node& node) override \
|
||||||
{ \
|
{ \
|
||||||
m_serializer.Serialize(node); \
|
m_serializer.Serialize(node); \
|
||||||
|
m_serializer.SerializeNodeCommon(node); \
|
||||||
}
|
}
|
||||||
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
#include <Nazara/Shader/Ast/AstNodeList.hpp>
|
||||||
|
|
||||||
|
|
@ -45,8 +47,11 @@ namespace Nz::ShaderAst
|
||||||
Node(node.expr);
|
Node(node.expr);
|
||||||
|
|
||||||
Container(node.identifiers);
|
Container(node.identifiers);
|
||||||
for (std::string& identifier : node.identifiers)
|
for (auto& identifier : node.identifiers)
|
||||||
Value(identifier);
|
{
|
||||||
|
Value(identifier.identifier);
|
||||||
|
SourceLoc(identifier.sourceLocation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AstSerializerBase::Serialize(AccessIndexExpression& node)
|
void AstSerializerBase::Serialize(AccessIndexExpression& node)
|
||||||
|
|
@ -204,11 +209,6 @@ namespace Nz::ShaderAst
|
||||||
Node(node.expression);
|
Node(node.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AstSerializerBase::SerializeExpressionCommon(Expression& expr)
|
|
||||||
{
|
|
||||||
OptType(expr.cachedExpressionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AstSerializerBase::Serialize(BranchStatement& node)
|
void AstSerializerBase::Serialize(BranchStatement& node)
|
||||||
{
|
{
|
||||||
Container(node.condStatements);
|
Container(node.condStatements);
|
||||||
|
|
@ -235,6 +235,14 @@ namespace Nz::ShaderAst
|
||||||
Node(node.expression);
|
Node(node.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AstSerializerBase::Serialize(DeclareConstStatement& node)
|
||||||
|
{
|
||||||
|
OptVal(node.constIndex);
|
||||||
|
Value(node.name);
|
||||||
|
ExprValue(node.type);
|
||||||
|
Node(node.expression);
|
||||||
|
}
|
||||||
|
|
||||||
void AstSerializerBase::Serialize(DeclareExternalStatement& node)
|
void AstSerializerBase::Serialize(DeclareExternalStatement& node)
|
||||||
{
|
{
|
||||||
ExprValue(node.bindingSet);
|
ExprValue(node.bindingSet);
|
||||||
|
|
@ -247,17 +255,10 @@ namespace Nz::ShaderAst
|
||||||
ExprValue(extVar.type);
|
ExprValue(extVar.type);
|
||||||
ExprValue(extVar.bindingIndex);
|
ExprValue(extVar.bindingIndex);
|
||||||
ExprValue(extVar.bindingSet);
|
ExprValue(extVar.bindingSet);
|
||||||
|
SourceLoc(extVar.sourceLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AstSerializerBase::Serialize(DeclareConstStatement& node)
|
|
||||||
{
|
|
||||||
OptVal(node.constIndex);
|
|
||||||
Value(node.name);
|
|
||||||
ExprValue(node.type);
|
|
||||||
Node(node.expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AstSerializerBase::Serialize(DeclareFunctionStatement& node)
|
void AstSerializerBase::Serialize(DeclareFunctionStatement& node)
|
||||||
{
|
{
|
||||||
Value(node.name);
|
Value(node.name);
|
||||||
|
|
@ -274,6 +275,7 @@ namespace Nz::ShaderAst
|
||||||
Value(parameter.name);
|
Value(parameter.name);
|
||||||
ExprValue(parameter.type);
|
ExprValue(parameter.type);
|
||||||
OptVal(parameter.varIndex);
|
OptVal(parameter.varIndex);
|
||||||
|
SourceLoc(parameter.sourceLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
Container(node.statements);
|
Container(node.statements);
|
||||||
|
|
@ -305,6 +307,7 @@ namespace Nz::ShaderAst
|
||||||
ExprValue(member.builtin);
|
ExprValue(member.builtin);
|
||||||
ExprValue(member.cond);
|
ExprValue(member.cond);
|
||||||
ExprValue(member.locationIndex);
|
ExprValue(member.locationIndex);
|
||||||
|
SourceLoc(member.sourceLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -378,6 +381,16 @@ namespace Nz::ShaderAst
|
||||||
Node(node.body);
|
Node(node.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AstSerializerBase::SerializeExpressionCommon(Expression& expr)
|
||||||
|
{
|
||||||
|
OptType(expr.cachedExpressionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AstSerializerBase::SerializeNodeCommon(ShaderAst::Node& node)
|
||||||
|
{
|
||||||
|
SourceLoc(node.sourceLocation);
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderAstSerializer::Serialize(ModulePtr& module)
|
void ShaderAstSerializer::Serialize(ModulePtr& module)
|
||||||
{
|
{
|
||||||
m_stream << s_shaderAstMagicNumber << s_shaderAstCurrentVersion;
|
m_stream << s_shaderAstMagicNumber << s_shaderAstCurrentVersion;
|
||||||
|
|
@ -387,23 +400,6 @@ namespace Nz::ShaderAst
|
||||||
m_stream.FlushBits();
|
m_stream.FlushBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderAstSerializer::SerializeModule(ModulePtr& module)
|
|
||||||
{
|
|
||||||
m_stream << module->metadata->moduleName;
|
|
||||||
m_stream << module->metadata->moduleId;
|
|
||||||
m_stream << module->metadata->shaderLangVersion;
|
|
||||||
|
|
||||||
Container(module->importedModules);
|
|
||||||
for (auto& importedModule : module->importedModules)
|
|
||||||
{
|
|
||||||
Value(importedModule.identifier);
|
|
||||||
SerializeModule(importedModule.module);
|
|
||||||
}
|
|
||||||
|
|
||||||
ShaderSerializerVisitor visitor(*this);
|
|
||||||
module->rootNode->Visit(visitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShaderAstSerializer::IsWriting() const
|
bool ShaderAstSerializer::IsWriting() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -432,6 +428,44 @@ namespace Nz::ShaderAst
|
||||||
node->Visit(visitor);
|
node->Visit(visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShaderAstSerializer::SerializeModule(ModulePtr& module)
|
||||||
|
{
|
||||||
|
m_stream << module->metadata->moduleName;
|
||||||
|
m_stream << module->metadata->moduleId;
|
||||||
|
m_stream << module->metadata->shaderLangVersion;
|
||||||
|
|
||||||
|
Container(module->importedModules);
|
||||||
|
for (auto& importedModule : module->importedModules)
|
||||||
|
{
|
||||||
|
Value(importedModule.identifier);
|
||||||
|
SerializeModule(importedModule.module);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderSerializerVisitor visitor(*this);
|
||||||
|
module->rootNode->Visit(visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstSerializer::SharedString(std::shared_ptr<const std::string>& val)
|
||||||
|
{
|
||||||
|
bool hasValue = (val != nullptr);
|
||||||
|
Value(hasValue);
|
||||||
|
|
||||||
|
if (hasValue)
|
||||||
|
{
|
||||||
|
auto it = m_stringIndices.find(*val);
|
||||||
|
bool newString = (it == m_stringIndices.end());
|
||||||
|
Value(newString);
|
||||||
|
|
||||||
|
if (newString)
|
||||||
|
{
|
||||||
|
Value(const_cast<std::string&>(*val)); //< won't be used for writing
|
||||||
|
m_stringIndices.emplace(*val, m_stringIndices.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Value(it->second); //< string index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderAstSerializer::Type(ExpressionType& type)
|
void ShaderAstSerializer::Type(ExpressionType& type)
|
||||||
{
|
{
|
||||||
|
|
@ -606,29 +640,6 @@ namespace Nz::ShaderAst
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderAstUnserializer::SerializeModule(ModulePtr& module)
|
|
||||||
{
|
|
||||||
std::shared_ptr<Module::Metadata> metadata = std::make_shared<Module::Metadata>();
|
|
||||||
m_stream >> metadata->moduleName;
|
|
||||||
m_stream >> metadata->moduleId;
|
|
||||||
m_stream >> metadata->shaderLangVersion;
|
|
||||||
|
|
||||||
std::vector<Module::ImportedModule> importedModules;
|
|
||||||
Container(importedModules);
|
|
||||||
for (auto& importedModule : importedModules)
|
|
||||||
{
|
|
||||||
Value(const_cast<std::string&>(importedModule.identifier)); //< not used for writing
|
|
||||||
SerializeModule(importedModule.module);
|
|
||||||
}
|
|
||||||
|
|
||||||
MultiStatementPtr rootNode = std::make_unique<MultiStatement>();
|
|
||||||
|
|
||||||
ShaderSerializerVisitor visitor(*this);
|
|
||||||
rootNode->Visit(visitor);
|
|
||||||
|
|
||||||
module = std::make_shared<Module>(std::move(metadata), std::move(rootNode), std::move(importedModules));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShaderAstUnserializer::IsWriting() const
|
bool ShaderAstUnserializer::IsWriting() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -686,6 +697,58 @@ namespace Nz::ShaderAst
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShaderAstUnserializer::SerializeModule(ModulePtr& module)
|
||||||
|
{
|
||||||
|
std::shared_ptr<Module::Metadata> metadata = std::make_shared<Module::Metadata>();
|
||||||
|
m_stream >> metadata->moduleName;
|
||||||
|
m_stream >> metadata->moduleId;
|
||||||
|
m_stream >> metadata->shaderLangVersion;
|
||||||
|
|
||||||
|
std::vector<Module::ImportedModule> importedModules;
|
||||||
|
Container(importedModules);
|
||||||
|
for (auto& importedModule : importedModules)
|
||||||
|
{
|
||||||
|
Value(const_cast<std::string&>(importedModule.identifier)); //< not used for writing
|
||||||
|
SerializeModule(importedModule.module);
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiStatementPtr rootNode = std::make_unique<MultiStatement>();
|
||||||
|
|
||||||
|
ShaderSerializerVisitor visitor(*this);
|
||||||
|
rootNode->Visit(visitor);
|
||||||
|
|
||||||
|
module = std::make_shared<Module>(std::move(metadata), std::move(rootNode), std::move(importedModules));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderAstUnserializer::SharedString(std::shared_ptr<const std::string>& val)
|
||||||
|
{
|
||||||
|
bool hasValue;
|
||||||
|
Value(hasValue);
|
||||||
|
|
||||||
|
if (hasValue)
|
||||||
|
{
|
||||||
|
bool newString;
|
||||||
|
Value(newString);
|
||||||
|
|
||||||
|
if (newString)
|
||||||
|
{
|
||||||
|
std::string newStr;
|
||||||
|
Value(newStr);
|
||||||
|
|
||||||
|
val = std::make_shared<const std::string>(std::move(newStr));
|
||||||
|
m_strings.emplace_back(val);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UInt32 strIndex;
|
||||||
|
Value(strIndex);
|
||||||
|
|
||||||
|
assert(strIndex < m_strings.size());
|
||||||
|
val = m_strings[strIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderAstUnserializer::Type(ExpressionType& type)
|
void ShaderAstUnserializer::Type(ExpressionType& type)
|
||||||
{
|
{
|
||||||
UInt8 typeIndex;
|
UInt8 typeIndex;
|
||||||
|
|
|
||||||
|
|
@ -306,16 +306,16 @@ namespace Nz::ShaderAst
|
||||||
std::size_t moduleIndex = m_context->moduleIndices.Retrieve(identifierData->index);
|
std::size_t moduleIndex = m_context->moduleIndices.Retrieve(identifierData->index);
|
||||||
|
|
||||||
const auto& env = *m_context->modules[moduleIndex].environment;
|
const auto& env = *m_context->modules[moduleIndex].environment;
|
||||||
identifierData = FindIdentifier(env, node.identifiers.front());
|
identifierData = FindIdentifier(env, node.identifiers.front().identifier);
|
||||||
if (identifierData)
|
if (identifierData)
|
||||||
return HandleIdentifier(identifierData);
|
return HandleIdentifier(identifierData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionPtr indexedExpr = CloneExpression(node.expr);
|
ExpressionPtr indexedExpr = CloneExpression(node.expr);
|
||||||
for (const std::string& identifier : node.identifiers)
|
for (const auto& identifierEntry : node.identifiers)
|
||||||
{
|
{
|
||||||
if (identifier.empty())
|
if (identifierEntry.identifier.empty())
|
||||||
throw AstError{ "empty identifier" };
|
throw AstError{ "empty identifier" };
|
||||||
|
|
||||||
const ExpressionType* exprType = GetExpressionType(*indexedExpr);
|
const ExpressionType* exprType = GetExpressionType(*indexedExpr);
|
||||||
|
|
@ -326,12 +326,12 @@ namespace Nz::ShaderAst
|
||||||
// TODO: Add proper support for methods
|
// TODO: Add proper support for methods
|
||||||
if (IsSamplerType(resolvedType))
|
if (IsSamplerType(resolvedType))
|
||||||
{
|
{
|
||||||
if (identifier == "Sample")
|
if (identifierEntry.identifier == "Sample")
|
||||||
{
|
{
|
||||||
// TODO: Add a MethodExpression?
|
// TODO: Add a MethodExpression?
|
||||||
auto identifierExpr = std::make_unique<AccessIdentifierExpression>();
|
auto identifierExpr = std::make_unique<AccessIdentifierExpression>();
|
||||||
identifierExpr->expr = std::move(indexedExpr);
|
identifierExpr->expr = std::move(indexedExpr);
|
||||||
identifierExpr->identifiers.push_back(identifier);
|
identifierExpr->identifiers.emplace_back().identifier = identifierEntry.identifier;
|
||||||
|
|
||||||
MethodType methodType;
|
MethodType methodType;
|
||||||
methodType.methodIndex = 0; //< FIXME
|
methodType.methodIndex = 0; //< FIXME
|
||||||
|
|
@ -342,7 +342,7 @@ namespace Nz::ShaderAst
|
||||||
indexedExpr = std::move(identifierExpr);
|
indexedExpr = std::move(identifierExpr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw AstError{ "type has no method " + identifier };
|
throw AstError{ "type has no method " + identifierEntry.identifier };
|
||||||
}
|
}
|
||||||
else if (IsStructType(resolvedType))
|
else if (IsStructType(resolvedType))
|
||||||
{
|
{
|
||||||
|
|
@ -367,7 +367,7 @@ namespace Nz::ShaderAst
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.name == identifier)
|
if (field.name == identifierEntry.identifier)
|
||||||
{
|
{
|
||||||
fieldPtr = &field;
|
fieldPtr = &field;
|
||||||
break;
|
break;
|
||||||
|
|
@ -377,7 +377,7 @@ namespace Nz::ShaderAst
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fieldPtr)
|
if (!fieldPtr)
|
||||||
throw AstError{ "unknown field " + identifier };
|
throw AstError{ "unknown field " + identifierEntry.identifier };
|
||||||
|
|
||||||
if (m_context->options.useIdentifierAccessesForStructs)
|
if (m_context->options.useIdentifierAccessesForStructs)
|
||||||
{
|
{
|
||||||
|
|
@ -394,8 +394,9 @@ namespace Nz::ShaderAst
|
||||||
else
|
else
|
||||||
accessIdentifierPtr = static_cast<AccessIdentifierExpression*>(indexedExpr.get());
|
accessIdentifierPtr = static_cast<AccessIdentifierExpression*>(indexedExpr.get());
|
||||||
|
|
||||||
accessIdentifierPtr->identifiers.push_back(fieldPtr->name);
|
|
||||||
accessIdentifierPtr->cachedExpressionType = ResolveTypeExpr(fieldPtr->type);
|
accessIdentifierPtr->cachedExpressionType = ResolveTypeExpr(fieldPtr->type);
|
||||||
|
|
||||||
|
accessIdentifierPtr->identifiers.emplace_back().identifier = fieldPtr->name;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -411,7 +412,7 @@ namespace Nz::ShaderAst
|
||||||
else if (IsPrimitiveType(resolvedType) || IsVectorType(resolvedType))
|
else if (IsPrimitiveType(resolvedType) || IsVectorType(resolvedType))
|
||||||
{
|
{
|
||||||
// Swizzle expression
|
// Swizzle expression
|
||||||
std::size_t swizzleComponentCount = identifier.size();
|
std::size_t swizzleComponentCount = identifierEntry.identifier.size();
|
||||||
if (swizzleComponentCount > 4)
|
if (swizzleComponentCount > 4)
|
||||||
throw AstError{ "cannot swizzle more than four elements" };
|
throw AstError{ "cannot swizzle more than four elements" };
|
||||||
|
|
||||||
|
|
@ -419,7 +420,7 @@ namespace Nz::ShaderAst
|
||||||
{
|
{
|
||||||
for (std::size_t j = 0; j < swizzleComponentCount; ++j)
|
for (std::size_t j = 0; j < swizzleComponentCount; ++j)
|
||||||
{
|
{
|
||||||
if (ToSwizzleIndex(identifier[j]) != 0)
|
if (ToSwizzleIndex(identifierEntry.identifier[j]) != 0)
|
||||||
throw AstError{ "invalid swizzle" };
|
throw AstError{ "invalid swizzle" };
|
||||||
//throw ShaderLang::CompilerInvalidSwizzleError{};
|
//throw ShaderLang::CompilerInvalidSwizzleError{};
|
||||||
}
|
}
|
||||||
|
|
@ -452,7 +453,7 @@ namespace Nz::ShaderAst
|
||||||
|
|
||||||
swizzle->componentCount = swizzleComponentCount;
|
swizzle->componentCount = swizzleComponentCount;
|
||||||
for (std::size_t j = 0; j < swizzleComponentCount; ++j)
|
for (std::size_t j = 0; j < swizzleComponentCount; ++j)
|
||||||
swizzle->components[j] = ToSwizzleIndex(identifier[j]);
|
swizzle->components[j] = ToSwizzleIndex(identifierEntry.identifier[j]);
|
||||||
|
|
||||||
Validate(*swizzle);
|
Validate(*swizzle);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -833,8 +833,8 @@ namespace Nz
|
||||||
assert(exprType);
|
assert(exprType);
|
||||||
assert(IsStructType(*exprType));
|
assert(IsStructType(*exprType));
|
||||||
|
|
||||||
for (const std::string& identifier : node.identifiers)
|
for (const auto& identifierEntry : node.identifiers)
|
||||||
Append(".", identifier);
|
Append(".", identifierEntry.identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlslWriter::Visit(ShaderAst::AccessIndexExpression& node)
|
void GlslWriter::Visit(ShaderAst::AccessIndexExpression& node)
|
||||||
|
|
|
||||||
|
|
@ -736,8 +736,8 @@ namespace Nz
|
||||||
{
|
{
|
||||||
Visit(node.expr, true);
|
Visit(node.expr, true);
|
||||||
|
|
||||||
for (const std::string& identifier : node.identifiers)
|
for (const auto& identifierEntry : node.identifiers)
|
||||||
Append(".", identifier);
|
Append(".", identifierEntry.identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LangWriter::Visit(ShaderAst::AccessIndexExpression& node)
|
void LangWriter::Visit(ShaderAst::AccessIndexExpression& node)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue