WIP
This commit is contained in:
@@ -17,6 +17,7 @@ namespace Nz::ShaderAst
|
||||
{
|
||||
inline bool Compare(const Expression& lhs, const Expression& rhs);
|
||||
inline bool Compare(const Module& lhs, const Module& rhs);
|
||||
inline bool Compare(const Module::ImportedModule& lhs, const Module::ImportedModule& rhs);
|
||||
inline bool Compare(const Module::Metadata& lhs, const Module::Metadata& rhs);
|
||||
inline bool Compare(const Statement& lhs, const Statement& rhs);
|
||||
|
||||
|
||||
@@ -31,12 +31,29 @@ namespace Nz::ShaderAst
|
||||
if (!Compare(*lhs.metadata, *rhs.metadata))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.importedModules, rhs.importedModules))
|
||||
return false;
|
||||
|
||||
if (!Compare(*lhs.rootNode, *rhs.rootNode))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Compare(const Module::ImportedModule& lhs, const Module::ImportedModule& rhs)
|
||||
{
|
||||
if (!Compare(lhs.identifier, rhs.identifier))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.dependencies, rhs.dependencies))
|
||||
return false;
|
||||
|
||||
if (!Compare(*lhs.module, *rhs.module))
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Compare(const Module::Metadata& lhs, const Module::Metadata& rhs)
|
||||
{
|
||||
if (!Compare(lhs.moduleId, rhs.moduleId))
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace Nz
|
||||
LangVersion, //< NZSL version - has argument version string
|
||||
Set, //< Binding set (external var only) - has argument index
|
||||
Unroll, //< Unroll (for/for each only) - has argument mode
|
||||
Uuid, //< Uuid (module only) - has argument string
|
||||
};
|
||||
|
||||
enum class BinaryType
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Nz::ShaderAst
|
||||
public:
|
||||
struct Metadata;
|
||||
|
||||
inline Module(UInt32 shaderLangVersion);
|
||||
inline Module(UInt32 shaderLangVersion, const Uuid& moduleId = Uuid::Generate());
|
||||
inline Module(std::shared_ptr<const Metadata> metadata);
|
||||
inline Module(std::shared_ptr<const Metadata> metadata, MultiStatementPtr rootNode);
|
||||
Module(const Module&) = default;
|
||||
@@ -34,14 +34,22 @@ namespace Nz::ShaderAst
|
||||
Module& operator=(const Module&) = default;
|
||||
Module& operator=(Module&&) noexcept = default;
|
||||
|
||||
std::shared_ptr<const Metadata> metadata;
|
||||
MultiStatementPtr rootNode;
|
||||
struct ImportedModule
|
||||
{
|
||||
std::string identifier;
|
||||
std::vector<Uuid> dependencies;
|
||||
ModulePtr module;
|
||||
};
|
||||
|
||||
struct Metadata
|
||||
{
|
||||
UInt32 shaderLangVersion;
|
||||
Uuid moduleId;
|
||||
};
|
||||
|
||||
std::shared_ptr<const Metadata> metadata;
|
||||
std::vector<ImportedModule> importedModules;
|
||||
MultiStatementPtr rootNode;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
inline Module::Module(UInt32 shaderLangVersion)
|
||||
inline Module::Module(UInt32 shaderLangVersion, const Uuid& uuid)
|
||||
{
|
||||
auto mutMetadata = std::make_shared<Metadata>();
|
||||
mutMetadata->moduleId = Uuid::Generate();
|
||||
mutMetadata->moduleId = uuid;
|
||||
mutMetadata->shaderLangVersion = shaderLangVersion;
|
||||
|
||||
metadata = std::move(mutMetadata);
|
||||
|
||||
@@ -250,7 +250,6 @@ namespace Nz::ShaderAst
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
std::optional<std::size_t> constIndex;
|
||||
std::optional<bool> hidden;
|
||||
std::string name;
|
||||
ExpressionPtr expression;
|
||||
ExpressionValue<ExpressionType> type;
|
||||
@@ -270,7 +269,6 @@ namespace Nz::ShaderAst
|
||||
ExpressionValue<ExpressionType> type;
|
||||
};
|
||||
|
||||
std::optional<bool> hidden;
|
||||
std::vector<ExternalVar> externalVars;
|
||||
ExpressionValue<UInt32> bindingSet;
|
||||
};
|
||||
@@ -288,7 +286,6 @@ namespace Nz::ShaderAst
|
||||
};
|
||||
|
||||
std::optional<std::size_t> funcIndex;
|
||||
std::optional<bool> hidden;
|
||||
std::string name;
|
||||
std::vector<Parameter> parameters;
|
||||
std::vector<StatementPtr> statements;
|
||||
@@ -304,7 +301,6 @@ namespace Nz::ShaderAst
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
std::optional<std::size_t> optIndex;
|
||||
std::optional<bool> hidden;
|
||||
std::string optName;
|
||||
ExpressionPtr defaultValue;
|
||||
ExpressionValue<ExpressionType> optType;
|
||||
@@ -316,7 +312,6 @@ namespace Nz::ShaderAst
|
||||
void Visit(AstStatementVisitor& visitor) override;
|
||||
|
||||
std::optional<std::size_t> structIndex;
|
||||
std::optional<bool> hidden;
|
||||
ExpressionValue<bool> isExported;
|
||||
StructDescription description;
|
||||
};
|
||||
|
||||
@@ -57,8 +57,12 @@ namespace Nz::ShaderAst
|
||||
};
|
||||
|
||||
private:
|
||||
struct CurrentFunctionData;
|
||||
struct Environment;
|
||||
struct FunctionData;
|
||||
struct Identifier;
|
||||
template<typename T> struct IdentifierData;
|
||||
struct Scope;
|
||||
|
||||
using AstCloner::CloneExpression;
|
||||
ExpressionValue<ExpressionType> CloneType(const ExpressionValue<ExpressionType>& exprType) override;
|
||||
@@ -97,6 +101,8 @@ namespace Nz::ShaderAst
|
||||
|
||||
const Identifier* FindIdentifier(const std::string_view& identifierName) const;
|
||||
template<typename F> const Identifier* FindIdentifier(const std::string_view& identifierName, F&& functor) const;
|
||||
const Identifier* FindIdentifier(const Environment& environment, const std::string_view& identifierName) const;
|
||||
template<typename F> const Identifier* FindIdentifier(const Environment& environment, const std::string_view& identifierName, F&& functor) const;
|
||||
TypeParameter FindTypeParameter(const std::string_view& identifierName) const;
|
||||
|
||||
Expression& MandatoryExpr(const ExpressionPtr& node) const;
|
||||
@@ -114,13 +120,14 @@ namespace Nz::ShaderAst
|
||||
void PropagateFunctionFlags(std::size_t funcIndex, FunctionFlags flags, Bitset<>& seen);
|
||||
|
||||
void RegisterBuiltin();
|
||||
std::size_t RegisterConstant(std::string name, ConstantValue value, bool hidden = false, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterFunction(std::string name, FunctionData funcData, bool hidden = false, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterIntrinsic(std::string name, IntrinsicType type, bool hidden = false, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterStruct(std::string name, StructDescription* description, bool hidden = false, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterType(std::string name, ExpressionType expressionType, bool hidden = false, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterType(std::string name, PartialType partialType, bool hidden = false, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterVariable(std::string name, ExpressionType type, bool hidden = false, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterConstant(std::string name, ConstantValue value, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterFunction(std::string name, FunctionData funcData, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterIntrinsic(std::string name, IntrinsicType type);
|
||||
std::size_t RegisterModule(std::string moduleIdentifier, std::size_t moduleIndex);
|
||||
std::size_t RegisterStruct(std::string name, StructDescription* description, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterType(std::string name, ExpressionType expressionType, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterType(std::string name, PartialType partialType, std::optional<std::size_t> index = {});
|
||||
std::size_t RegisterVariable(std::string name, ExpressionType type, std::optional<std::size_t> index = {});
|
||||
|
||||
void ResolveFunctions();
|
||||
const ExpressionPtr& ResolveCondExpression(ConditionalExpression& node);
|
||||
@@ -132,6 +139,7 @@ namespace Nz::ShaderAst
|
||||
ExpressionType ResolveType(const ExpressionValue<ExpressionType>& exprTypeValue);
|
||||
|
||||
void SanitizeIdentifier(std::string& identifier);
|
||||
MultiStatementPtr SanitizeInternal(MultiStatement& rootNode, std::string* error);
|
||||
|
||||
void TypeMustMatch(const ExpressionPtr& left, const ExpressionPtr& right) const;
|
||||
void TypeMustMatch(const ExpressionType& left, const ExpressionType& right) const;
|
||||
@@ -167,6 +175,7 @@ namespace Nz::ShaderAst
|
||||
Constant,
|
||||
Function,
|
||||
Intrinsic,
|
||||
Module,
|
||||
Struct,
|
||||
Type,
|
||||
Variable
|
||||
|
||||
Reference in New Issue
Block a user