Shader: First working version on both Vulkan & OpenGL (ES)

This commit is contained in:
Jérôme Leclercq
2021-04-12 15:38:20 +02:00
parent f93a5bbdc1
commit ea99c6a19e
42 changed files with 1803 additions and 1053 deletions

View File

@@ -8,8 +8,8 @@
#define NAZARA_SPIRVCONSTANTCACHE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Shader/ShaderConstantValue.hpp>
#include <Nazara/Shader/ShaderEnums.hpp>
#include <Nazara/Shader/Ast/ConstantValue.hpp>
#include <Nazara/Shader/Ast/ExpressionType.hpp>
#include <Nazara/Shader/SpirvData.hpp>
#include <memory>
@@ -25,6 +25,8 @@ namespace Nz
class NAZARA_SHADER_API SpirvConstantCache
{
public:
using StructCallback = std::function<const ShaderAst::StructDescription&(std::size_t structIndex)>;
SpirvConstantCache(UInt32& resultId);
SpirvConstantCache(const SpirvConstantCache& cache) = delete;
SpirvConstantCache(SpirvConstantCache&& cache) noexcept;
@@ -37,8 +39,6 @@ namespace Nz
using ConstantPtr = std::shared_ptr<Constant>;
using TypePtr = std::shared_ptr<Type>;
using IdentifierCallback = std::function<TypePtr(const std::string& identifier)>;
struct Bool {};
struct Float
@@ -66,11 +66,6 @@ namespace Nz
UInt32 columnCount;
};
struct Identifier
{
std::string name;
};
struct Image
{
std::optional<SpirvAccessQualifier> qualifier;
@@ -112,7 +107,7 @@ namespace Nz
std::vector<Member> members;
};
using AnyType = std::variant<Bool, Float, Function, Identifier, Image, Integer, Matrix, Pointer, SampledImage, Structure, Vector, Void>;
using AnyType = std::variant<Bool, Float, Function, Image, Integer, Matrix, Pointer, SampledImage, Structure, Vector, Void>;
struct ConstantBool
{
@@ -134,10 +129,11 @@ namespace Nz
struct Variable
{
std::optional<std::size_t> funcId; //< For inputs/outputs
std::optional<ConstantPtr> initializer;
std::string debugName;
TypePtr type;
SpirvStorageClass storageClass;
std::optional<ConstantPtr> initializer;
};
using BaseType = std::variant<Bool, Float, Integer, Vector, Matrix, Image>;
@@ -166,6 +162,21 @@ namespace Nz
AnyType type;
};
ConstantPtr BuildConstant(const ShaderAst::ConstantValue& value) const;
TypePtr BuildFunctionType(const ShaderAst::ExpressionType& retType, const std::vector<ShaderAst::ExpressionType>& parameters) const;
TypePtr BuildPointerType(const ShaderAst::PrimitiveType& type, SpirvStorageClass storageClass) const;
TypePtr BuildPointerType(const ShaderAst::ExpressionType& type, SpirvStorageClass storageClass) const;
TypePtr BuildType(const ShaderAst::ExpressionType& type) const;
TypePtr BuildType(const ShaderAst::IdentifierType& type) const;
TypePtr BuildType(const ShaderAst::MatrixType& type) const;
TypePtr BuildType(const ShaderAst::NoType& type) const;
TypePtr BuildType(const ShaderAst::PrimitiveType& type) const;
TypePtr BuildType(const ShaderAst::SamplerType& type) const;
TypePtr BuildType(const ShaderAst::StructType& type) const;
TypePtr BuildType(const ShaderAst::StructDescription& structDesc) const;
TypePtr BuildType(const ShaderAst::VectorType& type) const;
TypePtr BuildType(const ShaderAst::UniformType& type) const;
UInt32 GetId(const Constant& c);
UInt32 GetId(const Type& t);
UInt32 GetId(const Variable& v);
@@ -174,26 +185,13 @@ namespace Nz
UInt32 Register(Type t);
UInt32 Register(Variable v);
void SetIdentifierCallback(IdentifierCallback callback);
void SetStructCallback(StructCallback callback);
void Write(SpirvSection& annotations, SpirvSection& constants, SpirvSection& debugInfos);
SpirvConstantCache& operator=(const SpirvConstantCache& cache) = delete;
SpirvConstantCache& operator=(SpirvConstantCache&& cache) noexcept;
static ConstantPtr BuildConstant(const ShaderConstantValue& value);
static TypePtr BuildFunctionType(const ShaderAst::ExpressionType& retType, const std::vector<ShaderAst::ExpressionType>& parameters);
static TypePtr BuildPointerType(const ShaderAst::PrimitiveType& type, SpirvStorageClass storageClass);
static TypePtr BuildPointerType(const ShaderAst::ExpressionType& type, SpirvStorageClass storageClass);
static TypePtr BuildType(const ShaderAst::ExpressionType& type);
static TypePtr BuildType(const ShaderAst::IdentifierType& type);
static TypePtr BuildType(const ShaderAst::MatrixType& type);
static TypePtr BuildType(const ShaderAst::NoType& type);
static TypePtr BuildType(const ShaderAst::PrimitiveType& type);
static TypePtr BuildType(const ShaderAst::SamplerType& type);
static TypePtr BuildType(const ShaderAst::StructDescription& structDesc);
static TypePtr BuildType(const ShaderAst::VectorType& type);
private:
struct DepRegisterer;
struct Eq;
@@ -204,7 +202,6 @@ namespace Nz
void WriteStruct(const Structure& structData, UInt32 resultId, SpirvSection& annotations, SpirvSection& constants, SpirvSection& debugInfos);
IdentifierCallback m_identifierCallback;
std::unique_ptr<Internal> m_internal;
};
}