ShaderLang: Proof of concept (add support for a lot of things)

This commit is contained in:
Jérôme Leclercq
2021-03-31 10:21:35 +02:00
parent 2a73005295
commit c1d1838336
37 changed files with 2259 additions and 908 deletions

View File

@@ -0,0 +1,24 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Shader generator"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADERAST_ATTRIBUTES_HPP
#define NAZARA_SHADERAST_ATTRIBUTES_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Shader/ShaderEnums.hpp>
namespace Nz::ShaderAst
{
struct Attribute
{
using Param = std::variant<std::monostate, long long, std::string>;
AttributeType type;
Param args;
};
}
#endif

View File

@@ -0,0 +1,96 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Shader generator"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADER_AST_EXPRESSIONTYPE_HPP
#define NAZARA_SHADER_AST_EXPRESSIONTYPE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Shader/ShaderEnums.hpp>
#include <Nazara/Shader/Ast/Attribute.hpp>
#include <string>
#include <variant>
#include <vector>
namespace Nz::ShaderAst
{
struct IdentifierType //< Alias or struct
{
std::string name;
inline bool operator==(const IdentifierType& rhs) const;
inline bool operator!=(const IdentifierType& rhs) const;
};
struct MatrixType
{
std::size_t columnCount;
std::size_t rowCount;
PrimitiveType type;
inline bool operator==(const MatrixType& rhs) const;
inline bool operator!=(const MatrixType& rhs) const;
};
struct NoType
{
inline bool operator==(const NoType& rhs) const;
inline bool operator!=(const NoType& rhs) const;
};
struct SamplerType
{
ImageType dim;
PrimitiveType sampledType;
inline bool operator==(const SamplerType& rhs) const;
inline bool operator!=(const SamplerType& rhs) const;
};
struct UniformType
{
IdentifierType containedType;
inline bool operator==(const UniformType& rhs) const;
inline bool operator!=(const UniformType& rhs) const;
};
struct VectorType
{
std::size_t componentCount;
PrimitiveType type;
inline bool operator==(const VectorType& rhs) const;
inline bool operator!=(const VectorType& rhs) const;
};
using ExpressionType = std::variant<NoType, IdentifierType, PrimitiveType, MatrixType, SamplerType, UniformType, VectorType>;
struct StructDescription
{
struct StructMember
{
std::string name;
std::vector<Attribute> attributes;
ExpressionType type;
};
std::string name;
std::vector<StructMember> members;
};
inline bool IsIdentifierType(const ExpressionType& type);
inline bool IsMatrixType(const ExpressionType& type);
inline bool IsNoType(const ExpressionType& type);
inline bool IsPrimitiveType(const ExpressionType& type);
inline bool IsSamplerType(const ExpressionType& type);
inline bool IsUniformType(const ExpressionType& type);
inline bool IsVectorType(const ExpressionType& type);
}
#include <Nazara/Shader/Ast/ExpressionType.inl>
#endif

View File

@@ -0,0 +1,111 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Shader generator"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/ExpressionType.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
inline bool IdentifierType::operator==(const IdentifierType& rhs) const
{
return name == rhs.name;
}
inline bool IdentifierType::operator!=(const IdentifierType& rhs) const
{
return !operator==(rhs);
}
inline bool MatrixType::operator==(const MatrixType& rhs) const
{
return columnCount == rhs.columnCount && rowCount == rhs.rowCount && type == rhs.type;
}
inline bool MatrixType::operator!=(const MatrixType& rhs) const
{
return !operator==(rhs);
}
inline bool NoType::operator==(const NoType& /*rhs*/) const
{
return true;
}
inline bool NoType::operator!=(const NoType& /*rhs*/) const
{
return false;
}
inline bool SamplerType::operator==(const SamplerType& rhs) const
{
return dim == rhs.dim && sampledType == rhs.sampledType;
}
inline bool SamplerType::operator!=(const SamplerType& rhs) const
{
return !operator==(rhs);
}
inline bool UniformType::operator==(const UniformType& rhs) const
{
return containedType == rhs.containedType;
}
inline bool UniformType::operator!=(const UniformType& rhs) const
{
return !operator==(rhs);
}
inline bool VectorType::operator==(const VectorType& rhs) const
{
return componentCount == rhs.componentCount && type == rhs.type;
}
inline bool VectorType::operator!=(const VectorType& rhs) const
{
return !operator==(rhs);
}
inline bool IsIdentifierType(const ExpressionType& type)
{
return std::holds_alternative<IdentifierType>(type);
}
inline bool IsMatrixType(const ExpressionType& type)
{
return std::holds_alternative<MatrixType>(type);
}
inline bool IsNoType(const ExpressionType& type)
{
return std::holds_alternative<NoType>(type);
}
inline bool IsPrimitiveType(const ExpressionType& type)
{
return std::holds_alternative<PrimitiveType>(type);
}
inline bool IsSamplerType(const ExpressionType& type)
{
return std::holds_alternative<SamplerType>(type);
}
bool IsUniformType(const ExpressionType& type)
{
return std::holds_alternative<UniformType>(type);
}
bool IsVectorType(const ExpressionType& type)
{
return std::holds_alternative<VectorType>(type);
}
}
#include <Nazara/Shader/DebugOff.hpp>