Renderer: Rename enums

ExpressionType => BasicType
ShaderAst::Type => ShaderExpressionType
This commit is contained in:
Jérôme Leclercq
2020-07-16 18:34:58 +02:00
parent c7a8091e68
commit 1d2fb88198
26 changed files with 210 additions and 184 deletions

View File

@@ -44,9 +44,9 @@ namespace Nz
};
private:
void Append(ShaderAst::Type type);
void Append(ShaderExpressionType type);
void Append(ShaderNodes::BuiltinEntry builtin);
void Append(ShaderNodes::ExpressionType type);
void Append(ShaderNodes::BasicType type);
void Append(ShaderNodes::MemoryLayout layout);
template<typename T> void Append(const T& param);
void AppendCommentSection(const std::string& section);

View File

@@ -86,7 +86,7 @@ namespace Nz
std::visit([&](auto&& arg)
{
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, ShaderNodes::ExpressionType>)
if constexpr (std::is_same_v<T, ShaderNodes::BasicType>)
{
Append(arg);
Append(" ");

View File

@@ -8,11 +8,10 @@
#define NAZARA_SHADER_AST_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/ShaderExpressionType.hpp>
#include <Nazara/Renderer/ShaderNodes.hpp>
#include <optional>
#include <string>
#include <unordered_map>
#include <variant>
#include <vector>
namespace Nz
@@ -28,16 +27,14 @@ namespace Nz
struct Uniform;
struct VariableBase;
using Type = std::variant<ShaderNodes::ExpressionType, std::string>;
ShaderAst() = default;
~ShaderAst() = default;
void AddFunction(std::string name, ShaderNodes::StatementPtr statement, std::vector<FunctionParameter> parameters = {}, ShaderNodes::ExpressionType returnType = ShaderNodes::ExpressionType::Void);
void AddInput(std::string name, Type type, std::optional<std::size_t> locationIndex);
void AddOutput(std::string name, Type type, std::optional<std::size_t> locationIndex);
void AddFunction(std::string name, ShaderNodes::StatementPtr statement, std::vector<FunctionParameter> parameters = {}, ShaderNodes::BasicType returnType = ShaderNodes::BasicType::Void);
void AddInput(std::string name, ShaderExpressionType type, std::optional<std::size_t> locationIndex);
void AddOutput(std::string name, ShaderExpressionType type, std::optional<std::size_t> locationIndex);
void AddStruct(std::string name, std::vector<StructMember> members);
void AddUniform(std::string name, Type type, std::optional<std::size_t> bindingIndex, std::optional<ShaderNodes::MemoryLayout> memoryLayout);
void AddUniform(std::string name, ShaderExpressionType type, std::optional<std::size_t> bindingIndex, std::optional<ShaderNodes::MemoryLayout> memoryLayout);
inline const Function& GetFunction(std::size_t i) const;
inline std::size_t GetFunctionCount() const;
@@ -58,7 +55,7 @@ namespace Nz
struct VariableBase
{
std::string name;
Type type;
ShaderExpressionType type;
};
struct FunctionParameter : VariableBase
@@ -69,7 +66,7 @@ namespace Nz
{
std::string name;
std::vector<FunctionParameter> parameters;
ShaderNodes::ExpressionType returnType;
ShaderNodes::BasicType returnType;
ShaderNodes::StatementPtr statement;
};
@@ -93,7 +90,7 @@ namespace Nz
struct StructMember
{
std::string name;
Type type;
ShaderExpressionType type;
};
private:

View File

@@ -67,7 +67,7 @@ namespace Nz::ShaderBuilder
constexpr BinOpBuilder<ShaderNodes::BinaryType::Substract> Substract;
constexpr GenBuilder<ShaderNodes::UniformVariable> Uniform;
template<ShaderNodes::ExpressionType Type, typename... Args> std::shared_ptr<ShaderNodes::Cast> Cast(Args&&... args);
template<ShaderNodes::BasicType Type, typename... Args> std::shared_ptr<ShaderNodes::Cast> Cast(Args&&... args);
}
#include <Nazara/Renderer/ShaderBuilder.inl>

View File

@@ -28,21 +28,21 @@ namespace Nz::ShaderBuilder
inline std::shared_ptr<ShaderNodes::Variable> BuiltinBuilder::operator()(ShaderNodes::BuiltinEntry builtin) const
{
ShaderNodes::ExpressionType exprType = ShaderNodes::ExpressionType::Void;
ShaderNodes::BasicType exprType = ShaderNodes::BasicType::Void;
switch (builtin)
{
case ShaderNodes::BuiltinEntry::VertexPosition:
exprType = ShaderNodes::ExpressionType::Float4;
exprType = ShaderNodes::BasicType::Float4;
break;
}
NazaraAssert(exprType != ShaderNodes::ExpressionType::Void, "Unhandled builtin");
NazaraAssert(exprType != ShaderNodes::BasicType::Void, "Unhandled builtin");
return ShaderNodes::BuiltinVariable::Build(builtin, exprType);
}
template<ShaderNodes::ExpressionType Type, typename... Args>
template<ShaderNodes::BasicType Type, typename... Args>
std::shared_ptr<ShaderNodes::Cast> Cast(Args&&... args)
{
return ShaderNodes::Cast::Build(Type, std::forward<Args>(args)...);

View File

@@ -16,6 +16,19 @@ namespace Nz::ShaderNodes
Simple //< =
};
enum class BasicType
{
Boolean, // bool
Float1, // float
Float2, // vec2
Float3, // vec3
Float4, // vec4
Mat4x4, // mat4
Sampler2D, // sampler2D
Void // void
};
enum class BinaryType
{
Add, //< +
@@ -37,19 +50,6 @@ namespace Nz::ShaderNodes
RValue
};
enum class ExpressionType
{
Boolean, // bool
Float1, // float
Float2, // vec2
Float3, // vec3
Float4, // vec4
Mat4x4, // mat4
Sampler2D, // sampler2D
Void // void
};
enum class IntrinsicType
{
CrossProduct,

View File

@@ -0,0 +1,20 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADER_EXPRESSIONTYPE_HPP
#define NAZARA_SHADER_EXPRESSIONTYPE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/ShaderNodes.hpp>
#include <string>
#include <variant>
namespace Nz
{
using ShaderExpressionType = std::variant<ShaderNodes::BasicType, std::string>;
}
#endif // NAZARA_SHADER_EXPRESSIONTYPE_HPP

View File

@@ -38,8 +38,8 @@ namespace Nz
virtual void Visit(ShaderVisitor& visitor) = 0;
static inline unsigned int GetComponentCount(ExpressionType type);
static inline ExpressionType GetComponentType(ExpressionType type);
static inline unsigned int GetComponentCount(BasicType type);
static inline BasicType GetComponentType(BasicType type);
protected:
inline Node(NodeType type, bool isStatement);
@@ -59,7 +59,7 @@ namespace Nz
inline Expression(NodeType type);
virtual ExpressionCategory GetExpressionCategory() const;
virtual ExpressionType GetExpressionType() const = 0;
virtual BasicType GetExpressionType() const = 0;
};
class Statement;
@@ -125,7 +125,7 @@ namespace Nz
inline Identifier();
ExpressionCategory GetExpressionCategory() const override;
ExpressionType GetExpressionType() const override;
BasicType GetExpressionType() const override;
void Visit(ShaderVisitor& visitor) override;
VariablePtr var;
@@ -139,7 +139,7 @@ namespace Nz
{
inline AssignOp();
ExpressionType GetExpressionType() const override;
BasicType GetExpressionType() const override;
void Visit(ShaderVisitor& visitor) override;
AssignType op;
@@ -153,7 +153,7 @@ namespace Nz
{
inline BinaryOp();
ExpressionType GetExpressionType() const override;
BasicType GetExpressionType() const override;
void Visit(ShaderVisitor& visitor) override;
BinaryType op;
@@ -187,24 +187,24 @@ namespace Nz
{
inline Cast();
ExpressionType GetExpressionType() const override;
BasicType GetExpressionType() const override;
void Visit(ShaderVisitor& visitor) override;
ExpressionType exprType;
BasicType exprType;
std::array<ExpressionPtr, 4> expressions;
static inline std::shared_ptr<Cast> Build(ExpressionType castTo, ExpressionPtr first, ExpressionPtr second = nullptr, ExpressionPtr third = nullptr, ExpressionPtr fourth = nullptr);
static inline std::shared_ptr<Cast> Build(ExpressionType castTo, ExpressionPtr* expressions, std::size_t expressionCount);
static inline std::shared_ptr<Cast> Build(BasicType castTo, ExpressionPtr first, ExpressionPtr second = nullptr, ExpressionPtr third = nullptr, ExpressionPtr fourth = nullptr);
static inline std::shared_ptr<Cast> Build(BasicType castTo, ExpressionPtr* expressions, std::size_t expressionCount);
};
struct NAZARA_RENDERER_API Constant : public Expression
{
inline Constant();
ExpressionType GetExpressionType() const override;
BasicType GetExpressionType() const override;
void Visit(ShaderVisitor& visitor) override;
ExpressionType exprType;
BasicType exprType;
union
{
@@ -227,7 +227,7 @@ namespace Nz
inline SwizzleOp();
ExpressionCategory GetExpressionCategory() const override;
ExpressionType GetExpressionType() const override;
BasicType GetExpressionType() const override;
void Visit(ShaderVisitor& visitor) override;
std::array<SwizzleComponent, 4> components;
@@ -243,7 +243,7 @@ namespace Nz
{
inline Sample2D();
ExpressionType GetExpressionType() const override;
BasicType GetExpressionType() const override;
void Visit(ShaderVisitor& visitor) override;
ExpressionPtr sampler;
@@ -258,7 +258,7 @@ namespace Nz
{
inline IntrinsicCall();
ExpressionType GetExpressionType() const override;
BasicType GetExpressionType() const override;
void Visit(ShaderVisitor& visitor) override;
IntrinsicType intrinsic;

View File

@@ -23,20 +23,20 @@ namespace Nz::ShaderNodes
return m_isStatement;
}
inline unsigned int Node::GetComponentCount(ExpressionType type)
inline unsigned int Node::GetComponentCount(BasicType type)
{
switch (type)
{
case ExpressionType::Float2:
case BasicType::Float2:
return 2;
case ExpressionType::Float3:
case BasicType::Float3:
return 3;
case ExpressionType::Float4:
case BasicType::Float4:
return 4;
case ExpressionType::Mat4x4:
case BasicType::Mat4x4:
return 4;
default:
@@ -44,17 +44,17 @@ namespace Nz::ShaderNodes
}
}
inline ExpressionType Node::GetComponentType(ExpressionType type)
inline BasicType Node::GetComponentType(BasicType type)
{
switch (type)
{
case ExpressionType::Float2:
case ExpressionType::Float3:
case ExpressionType::Float4:
return ExpressionType::Float1;
case BasicType::Float2:
case BasicType::Float3:
case BasicType::Float4:
return BasicType::Float1;
case ExpressionType::Mat4x4:
return ExpressionType::Float4;
case BasicType::Mat4x4:
return BasicType::Float4;
default:
return type;
@@ -198,7 +198,7 @@ namespace Nz::ShaderNodes
{
}
inline std::shared_ptr<Cast> Cast::Build(ExpressionType castTo, ExpressionPtr first, ExpressionPtr second, ExpressionPtr third, ExpressionPtr fourth)
inline std::shared_ptr<Cast> Cast::Build(BasicType castTo, ExpressionPtr first, ExpressionPtr second, ExpressionPtr third, ExpressionPtr fourth)
{
auto node = std::make_shared<Cast>();
node->exprType = castTo;
@@ -207,7 +207,7 @@ namespace Nz::ShaderNodes
return node;
}
inline std::shared_ptr<Cast> Cast::Build(ExpressionType castTo, ExpressionPtr* Expressions, std::size_t expressionCount)
inline std::shared_ptr<Cast> Cast::Build(BasicType castTo, ExpressionPtr* Expressions, std::size_t expressionCount)
{
auto node = std::make_shared<Cast>();
node->exprType = castTo;
@@ -226,7 +226,7 @@ namespace Nz::ShaderNodes
inline std::shared_ptr<Constant> Constant::Build(bool value)
{
auto node = std::make_shared<Constant>();
node->exprType = ExpressionType::Boolean;
node->exprType = BasicType::Boolean;
node->values.bool1 = value;
return node;
@@ -235,7 +235,7 @@ namespace Nz::ShaderNodes
inline std::shared_ptr<Constant> Constant::Build(float value)
{
auto node = std::make_shared<Constant>();
node->exprType = ExpressionType::Float1;
node->exprType = BasicType::Float1;
node->values.vec1 = value;
return node;
@@ -244,7 +244,7 @@ namespace Nz::ShaderNodes
inline std::shared_ptr<Constant> Constant::Build(const Vector2f& value)
{
auto node = std::make_shared<Constant>();
node->exprType = ExpressionType::Float2;
node->exprType = BasicType::Float2;
node->values.vec2 = value;
return node;
@@ -253,7 +253,7 @@ namespace Nz::ShaderNodes
inline std::shared_ptr<Constant> Constant::Build(const Vector3f& value)
{
auto node = std::make_shared<Constant>();
node->exprType = ExpressionType::Float3;
node->exprType = BasicType::Float3;
node->values.vec3 = value;
return node;
@@ -262,7 +262,7 @@ namespace Nz::ShaderNodes
inline std::shared_ptr<Constant> Constant::Build(const Vector4f& value)
{
auto node = std::make_shared<Constant>();
node->exprType = ExpressionType::Float4;
node->exprType = BasicType::Float4;
node->values.vec4 = value;
return node;

View File

@@ -103,7 +103,7 @@ namespace Nz
private:
bool IsWriting() const override;
void Node(ShaderNodes::NodePtr& node) override;
void Type(ShaderAst::Type& type);
void Type(ShaderExpressionType& type);
void Value(bool& val) override;
void Value(float& val) override;
void Value(std::string& val) override;

View File

@@ -30,7 +30,7 @@ namespace Nz
const ShaderNodes::ExpressionPtr& MandatoryExpr(const ShaderNodes::ExpressionPtr& node);
const ShaderNodes::NodePtr& MandatoryNode(const ShaderNodes::NodePtr& node);
void TypeMustMatch(const ShaderNodes::ExpressionPtr& left, const ShaderNodes::ExpressionPtr& right);
void TypeMustMatch(const ShaderAst::Type& left, const ShaderAst::Type& right);
void TypeMustMatch(const ShaderExpressionType& left, const ShaderExpressionType& right);
using ShaderVisitor::Visit;
void Visit(const ShaderNodes::AssignOp& node) override;

View File

@@ -34,7 +34,7 @@ namespace Nz
virtual VariableType GetType() const = 0;
virtual void Visit(ShaderVarVisitor& visitor) = 0;
ExpressionType type;
BasicType type;
};
struct BuiltinVariable;
@@ -48,7 +48,7 @@ namespace Nz
VariableType GetType() const override;
void Visit(ShaderVarVisitor& visitor) override;
static inline std::shared_ptr<BuiltinVariable> Build(BuiltinEntry entry, ExpressionType varType);
static inline std::shared_ptr<BuiltinVariable> Build(BuiltinEntry entry, BasicType varType);
};
struct NamedVariable;
@@ -69,7 +69,7 @@ namespace Nz
VariableType GetType() const override;
void Visit(ShaderVarVisitor& visitor) override;
static inline std::shared_ptr<InputVariable> Build(std::string varName, ExpressionType varType);
static inline std::shared_ptr<InputVariable> Build(std::string varName, BasicType varType);
};
struct LocalVariable;
@@ -81,7 +81,7 @@ namespace Nz
VariableType GetType() const override;
void Visit(ShaderVarVisitor& visitor) override;
static inline std::shared_ptr<LocalVariable> Build(std::string varName, ExpressionType varType);
static inline std::shared_ptr<LocalVariable> Build(std::string varName, BasicType varType);
};
struct OutputVariable;
@@ -93,7 +93,7 @@ namespace Nz
VariableType GetType() const override;
void Visit(ShaderVarVisitor& visitor) override;
static inline std::shared_ptr<OutputVariable> Build(std::string varName, ExpressionType varType);
static inline std::shared_ptr<OutputVariable> Build(std::string varName, BasicType varType);
};
struct ParameterVariable;
@@ -105,7 +105,7 @@ namespace Nz
VariableType GetType() const override;
void Visit(ShaderVarVisitor& visitor) override;
static inline std::shared_ptr<ParameterVariable> Build(std::string varName, ExpressionType varType);
static inline std::shared_ptr<ParameterVariable> Build(std::string varName, BasicType varType);
};
struct UniformVariable;
@@ -117,7 +117,7 @@ namespace Nz
VariableType GetType() const override;
void Visit(ShaderVarVisitor& visitor) override;
static inline std::shared_ptr<UniformVariable> Build(std::string varName, ExpressionType varType);
static inline std::shared_ptr<UniformVariable> Build(std::string varName, BasicType varType);
};
}
}

View File

@@ -7,7 +7,7 @@
namespace Nz::ShaderNodes
{
inline std::shared_ptr<BuiltinVariable> BuiltinVariable::Build(BuiltinEntry variable, ExpressionType varType)
inline std::shared_ptr<BuiltinVariable> BuiltinVariable::Build(BuiltinEntry variable, BasicType varType)
{
auto node = std::make_shared<BuiltinVariable>();
node->entry = variable;
@@ -16,7 +16,7 @@ namespace Nz::ShaderNodes
return node;
}
inline std::shared_ptr<InputVariable> InputVariable::Build(std::string varName, ExpressionType varType)
inline std::shared_ptr<InputVariable> InputVariable::Build(std::string varName, BasicType varType)
{
auto node = std::make_shared<InputVariable>();
node->name = std::move(varName);
@@ -25,7 +25,7 @@ namespace Nz::ShaderNodes
return node;
}
inline std::shared_ptr<LocalVariable> LocalVariable::Build(std::string varName, ExpressionType varType)
inline std::shared_ptr<LocalVariable> LocalVariable::Build(std::string varName, BasicType varType)
{
auto node = std::make_shared<LocalVariable>();
node->name = std::move(varName);
@@ -34,7 +34,7 @@ namespace Nz::ShaderNodes
return node;
}
inline std::shared_ptr<OutputVariable> OutputVariable::Build(std::string varName, ExpressionType varType)
inline std::shared_ptr<OutputVariable> OutputVariable::Build(std::string varName, BasicType varType)
{
auto node = std::make_shared<OutputVariable>();
node->name = std::move(varName);
@@ -43,7 +43,7 @@ namespace Nz::ShaderNodes
return node;
}
inline std::shared_ptr<ParameterVariable> ParameterVariable::Build(std::string varName, ExpressionType varType)
inline std::shared_ptr<ParameterVariable> ParameterVariable::Build(std::string varName, BasicType varType)
{
auto node = std::make_shared<ParameterVariable>();
node->name = std::move(varName);
@@ -52,7 +52,7 @@ namespace Nz::ShaderNodes
return node;
}
inline std::shared_ptr<UniformVariable> UniformVariable::Build(std::string varName, ExpressionType varType)
inline std::shared_ptr<UniformVariable> UniformVariable::Build(std::string varName, BasicType varType)
{
auto node = std::make_shared<UniformVariable>();
node->name = std::move(varName);