Shader: Add module resolver + use modules for engine shaders
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADER_AST_INDEXREMAPPER_HPP
|
||||
#define NAZARA_SHADER_AST_INDEXREMAPPER_HPP
|
||||
#ifndef NAZARA_SHADER_AST_INDEXREMAPPERVISITOR_HPP
|
||||
#define NAZARA_SHADER_AST_INDEXREMAPPERVISITOR_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
@@ -60,4 +60,4 @@ namespace Nz::ShaderAst
|
||||
|
||||
#include <Nazara/Shader/Ast/IndexRemapperVisitor.inl>
|
||||
|
||||
#endif // NAZARA_SHADER_AST_INDEXREMAPPER_HPP
|
||||
#endif // NAZARA_SHADER_AST_INDEXREMAPPERVISITOR_HPP
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/ShaderModuleResolver.hpp>
|
||||
#include <Nazara/Shader/Ast/AstCloner.hpp>
|
||||
#include <Nazara/Shader/Ast/AstTypes.hpp>
|
||||
#include <Nazara/Shader/Ast/Module.hpp>
|
||||
@@ -42,7 +43,7 @@ namespace Nz::ShaderAst
|
||||
|
||||
struct Options
|
||||
{
|
||||
std::function<ModulePtr(const std::vector<std::string>& /*modulePath*/)> moduleCallback;
|
||||
std::shared_ptr<ShaderModuleResolver> moduleResolver;
|
||||
std::unordered_set<std::string> reservedIdentifiers;
|
||||
std::unordered_map<UInt32, ConstantValue> optionValues;
|
||||
bool makeVariableNameUnique = false;
|
||||
|
||||
45
include/Nazara/Shader/DirectoryModuleResolver.hpp
Normal file
45
include/Nazara/Shader/DirectoryModuleResolver.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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_DIRECTORYMODULERESOLVER_HPP
|
||||
#define NAZARA_SHADER_DIRECTORYMODULERESOLVER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/VirtualDirectory.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/ShaderModuleResolver.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_SHADER_API DirectoryModuleResolver : public ShaderModuleResolver
|
||||
{
|
||||
public:
|
||||
inline DirectoryModuleResolver();
|
||||
DirectoryModuleResolver(const DirectoryModuleResolver&) = delete;
|
||||
DirectoryModuleResolver(DirectoryModuleResolver&&) = delete;
|
||||
~DirectoryModuleResolver() = default;
|
||||
|
||||
inline void RegisterModuleDirectory(std::string_view path, std::filesystem::path realPath);
|
||||
inline void RegisterModuleFile(std::string_view path, std::filesystem::path realPath);
|
||||
inline void RegisterModuleFile(std::string_view path, std::vector<UInt8> fileContent);
|
||||
inline void RegisterModuleFile(std::string_view path, const void* staticData, std::size_t size);
|
||||
|
||||
ShaderAst::ModulePtr Resolve(const std::vector<std::string>& modulePath) override;
|
||||
|
||||
DirectoryModuleResolver& operator=(const DirectoryModuleResolver&) = delete;
|
||||
DirectoryModuleResolver& operator=(DirectoryModuleResolver&&) = delete;
|
||||
|
||||
private:
|
||||
std::shared_ptr<VirtualDirectory> m_searchDirectory;
|
||||
std::unordered_map<std::string, ShaderAst::ModulePtr> m_knownModules;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/DirectoryModuleResolver.inl>
|
||||
|
||||
#endif // NAZARA_SHADER_DIRECTORYMODULERESOLVER_HPP
|
||||
36
include/Nazara/Shader/DirectoryModuleResolver.inl
Normal file
36
include/Nazara/Shader/DirectoryModuleResolver.inl
Normal file
@@ -0,0 +1,36 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Shader/DirectoryModuleResolver.hpp>
|
||||
#include <Nazara/Shader/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline DirectoryModuleResolver::DirectoryModuleResolver() :
|
||||
m_searchDirectory(std::make_shared<VirtualDirectory>())
|
||||
{
|
||||
}
|
||||
|
||||
inline void DirectoryModuleResolver::RegisterModuleDirectory(std::string_view path, std::filesystem::path realPath)
|
||||
{
|
||||
m_searchDirectory->StoreDirectory(path, realPath);
|
||||
}
|
||||
|
||||
inline void DirectoryModuleResolver::RegisterModuleFile(std::string_view path, std::filesystem::path realPath)
|
||||
{
|
||||
m_searchDirectory->StoreFile(path, realPath);
|
||||
}
|
||||
|
||||
inline void DirectoryModuleResolver::RegisterModuleFile(std::string_view path, std::vector<UInt8> fileContent)
|
||||
{
|
||||
m_searchDirectory->StoreFile(path, std::move(fileContent));
|
||||
}
|
||||
|
||||
inline void DirectoryModuleResolver::RegisterModuleFile(std::string_view path, const void* staticData, std::size_t size)
|
||||
{
|
||||
m_searchDirectory->StoreFile(path, staticData, size);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/DebugOff.hpp>
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <Nazara/Shader/Ast/AstExpressionVisitorExcept.hpp>
|
||||
#include <Nazara/Shader/Ast/AstStatementVisitorExcept.hpp>
|
||||
#include <Nazara/Shader/Ast/Module.hpp>
|
||||
#include <Nazara/Shader/Ast/SanitizeVisitor.hpp>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -48,7 +49,7 @@ namespace Nz
|
||||
};
|
||||
|
||||
static const char* GetFlipYUniformName();
|
||||
static ShaderAst::ModulePtr Sanitize(const ShaderAst::Module& module, std::unordered_map<UInt32, ShaderAst::ConstantValue> optionValues, std::string* error = nullptr);
|
||||
static ShaderAst::SanitizeVisitor::Options GetSanitizeOptions();
|
||||
|
||||
private:
|
||||
void Append(const ShaderAst::AliasType& aliasType);
|
||||
|
||||
40
include/Nazara/Shader/ShaderModuleResolver.hpp
Normal file
40
include/Nazara/Shader/ShaderModuleResolver.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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_SHADERMODULERESOLVER_HPP
|
||||
#define NAZARA_SHADER_SHADERMODULERESOLVER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace ShaderAst
|
||||
{
|
||||
using ModulePtr = std::shared_ptr<class Module>;
|
||||
}
|
||||
|
||||
class NAZARA_SHADER_API ShaderModuleResolver
|
||||
{
|
||||
public:
|
||||
ShaderModuleResolver() = default;
|
||||
ShaderModuleResolver(const ShaderModuleResolver&) = default;
|
||||
ShaderModuleResolver(ShaderModuleResolver&&) = default;
|
||||
virtual ~ShaderModuleResolver();
|
||||
|
||||
virtual ShaderAst::ModulePtr Resolve(const std::vector<std::string>& /*modulePath*/) = 0;
|
||||
|
||||
ShaderModuleResolver& operator=(const ShaderModuleResolver&) = default;
|
||||
ShaderModuleResolver& operator=(ShaderModuleResolver&&) = default;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/ShaderModuleResolver.inl>
|
||||
|
||||
#endif // NAZARA_SHADER_SHADERMODULERESOLVER_HPP
|
||||
12
include/Nazara/Shader/ShaderModuleResolver.inl
Normal file
12
include/Nazara/Shader/ShaderModuleResolver.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Shader/ShaderModuleResolver.hpp>
|
||||
#include <Nazara/Shader/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Shader/DebugOff.hpp>
|
||||
@@ -10,11 +10,14 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/ConstantValue.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ShaderModuleResolver;
|
||||
|
||||
class NAZARA_SHADER_API ShaderWriter
|
||||
{
|
||||
public:
|
||||
@@ -27,6 +30,7 @@ namespace Nz
|
||||
|
||||
struct States
|
||||
{
|
||||
std::shared_ptr<ShaderModuleResolver> shaderModuleResolver;
|
||||
std::unordered_map<UInt32, ShaderAst::ConstantValue> optionValues;
|
||||
bool optimize = false;
|
||||
bool sanitized = false;
|
||||
|
||||
Reference in New Issue
Block a user