Shader: Add module statement
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/ByteStream.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/Nodes.hpp>
|
||||
#include <Nazara/Shader/Ast/Module.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
@@ -94,9 +94,11 @@ namespace Nz::ShaderAst
|
||||
inline ShaderAstSerializer(ByteStream& stream);
|
||||
~ShaderAstSerializer() = default;
|
||||
|
||||
void Serialize(StatementPtr& shader);
|
||||
void Serialize(Module& shader);
|
||||
|
||||
private:
|
||||
using AstSerializerBase::Serialize;
|
||||
|
||||
bool IsWriting() const override;
|
||||
void Node(ExpressionPtr& node) override;
|
||||
void Node(StatementPtr& node) override;
|
||||
@@ -125,9 +127,11 @@ namespace Nz::ShaderAst
|
||||
ShaderAstUnserializer(ByteStream& stream);
|
||||
~ShaderAstUnserializer() = default;
|
||||
|
||||
StatementPtr Unserialize();
|
||||
ModulePtr Unserialize();
|
||||
|
||||
private:
|
||||
using AstSerializerBase::Serialize;
|
||||
|
||||
bool IsWriting() const override;
|
||||
void Node(ExpressionPtr& node) override;
|
||||
void Node(StatementPtr& node) override;
|
||||
@@ -150,9 +154,9 @@ namespace Nz::ShaderAst
|
||||
ByteStream& m_stream;
|
||||
};
|
||||
|
||||
NAZARA_SHADER_API ByteArray SerializeShader(StatementPtr& shader);
|
||||
inline StatementPtr UnserializeShader(const void* data, std::size_t size);
|
||||
NAZARA_SHADER_API StatementPtr UnserializeShader(ByteStream& stream);
|
||||
NAZARA_SHADER_API ByteArray SerializeShader(Module& shader);
|
||||
inline ModulePtr UnserializeShader(const void* data, std::size_t size);
|
||||
NAZARA_SHADER_API ModulePtr UnserializeShader(ByteStream& stream);
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/Ast/AstSerializer.inl>
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace Nz::ShaderAst
|
||||
{
|
||||
}
|
||||
|
||||
inline StatementPtr UnserializeShader(const void* data, std::size_t size)
|
||||
inline ModulePtr UnserializeShader(const void* data, std::size_t size)
|
||||
{
|
||||
ByteStream byteStream(data, size);
|
||||
return UnserializeShader(byteStream);
|
||||
|
||||
@@ -31,7 +31,8 @@ namespace Nz::ShaderAst
|
||||
Vector4f,
|
||||
Vector2i32,
|
||||
Vector3i32,
|
||||
Vector4i32
|
||||
Vector4i32,
|
||||
std::string
|
||||
>;
|
||||
|
||||
using ConstantValue = TypeListInstantiate<ConstantTypes, std::variant>;
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace Nz
|
||||
Entry, //< Entry point (function only) - has argument type
|
||||
Layout, //< Struct layout (struct only) - has argument style
|
||||
Location, //< Location (struct member only) - has argument index
|
||||
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
|
||||
};
|
||||
@@ -136,6 +137,7 @@ namespace Nz
|
||||
Float32, //< f32
|
||||
Int32, //< i32
|
||||
UInt32, //< ui32
|
||||
String //< str
|
||||
};
|
||||
|
||||
enum class UnaryType
|
||||
|
||||
28
include/Nazara/Shader/Ast/Module.hpp
Normal file
28
include/Nazara/Shader/Ast/Module.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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_AST_MODULE_HPP
|
||||
#define NAZARA_SHADER_AST_MODULE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/Nodes.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
struct Module;
|
||||
|
||||
using ModulePtr = std::shared_ptr<Module>;
|
||||
|
||||
struct Module
|
||||
{
|
||||
MultiStatementPtr rootNode;
|
||||
UInt32 shaderLangVersion;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_SHADER_AST_MODULE_HPP
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/AstCloner.hpp>
|
||||
#include <Nazara/Shader/Ast/AstTypes.hpp>
|
||||
#include <Nazara/Shader/Ast/Module.hpp>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
@@ -30,8 +31,8 @@ namespace Nz::ShaderAst
|
||||
SanitizeVisitor(SanitizeVisitor&&) = delete;
|
||||
~SanitizeVisitor() = default;
|
||||
|
||||
inline StatementPtr Sanitize(Statement& statement, std::string* error = nullptr);
|
||||
StatementPtr Sanitize(Statement& statement, const Options& options, std::string* error = nullptr);
|
||||
inline ModulePtr Sanitize(Module& module, std::string* error = nullptr);
|
||||
ModulePtr Sanitize(Module& module, const Options& options, std::string* error = nullptr);
|
||||
|
||||
SanitizeVisitor& operator=(const SanitizeVisitor&) = delete;
|
||||
SanitizeVisitor& operator=(SanitizeVisitor&&) = delete;
|
||||
@@ -177,8 +178,8 @@ namespace Nz::ShaderAst
|
||||
Context* m_context;
|
||||
};
|
||||
|
||||
inline StatementPtr Sanitize(Statement& ast, std::string* error = nullptr);
|
||||
inline StatementPtr Sanitize(Statement& ast, const SanitizeVisitor::Options& options, std::string* error = nullptr);
|
||||
inline ModulePtr Sanitize(Module& module, std::string* error = nullptr);
|
||||
inline ModulePtr Sanitize(Module& module, const SanitizeVisitor::Options& options, std::string* error = nullptr);
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/Ast/SanitizeVisitor.inl>
|
||||
|
||||
@@ -7,21 +7,21 @@
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
inline StatementPtr SanitizeVisitor::Sanitize(Statement& statement, std::string* error)
|
||||
inline ModulePtr SanitizeVisitor::Sanitize(Module& module, std::string* error)
|
||||
{
|
||||
return Sanitize(statement, {}, error);
|
||||
return Sanitize(module, {}, error);
|
||||
}
|
||||
|
||||
inline StatementPtr Sanitize(Statement& ast, std::string* error)
|
||||
inline ModulePtr Sanitize(Module& module, std::string* error)
|
||||
{
|
||||
SanitizeVisitor sanitizer;
|
||||
return sanitizer.Sanitize(ast, error);
|
||||
return sanitizer.Sanitize(module, error);
|
||||
}
|
||||
|
||||
inline StatementPtr Sanitize(Statement& ast, const SanitizeVisitor::Options& options, std::string* error)
|
||||
inline ModulePtr Sanitize(Module& module, const SanitizeVisitor::Options& options, std::string* error)
|
||||
{
|
||||
SanitizeVisitor sanitizer;
|
||||
return sanitizer.Sanitize(ast, options, error);
|
||||
return sanitizer.Sanitize(module, options, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user