Add support for shader hotreloading
This commit is contained in:
@@ -35,6 +35,8 @@ namespace Nz
|
||||
{
|
||||
public:
|
||||
MaterialPass(std::shared_ptr<const MaterialSettings> settings);
|
||||
MaterialPass(const MaterialPass&) = delete;
|
||||
MaterialPass(MaterialPass&&) = delete;
|
||||
inline ~MaterialPass();
|
||||
|
||||
inline void Configure(std::shared_ptr<MaterialPipeline> pipeline);
|
||||
@@ -105,6 +107,9 @@ namespace Nz
|
||||
|
||||
void Update(RenderFrame& renderFrame, CommandBufferBuilder& builder);
|
||||
|
||||
MaterialPass& operator=(const MaterialPass&) = delete;
|
||||
MaterialPass& operator=(MaterialPass&&) = delete;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnMaterialPassInvalidated, const MaterialPass* /*materialPass*/);
|
||||
NazaraSignal(OnMaterialPassPipelineInvalidated, const MaterialPass* /*materialPass*/);
|
||||
@@ -125,6 +130,11 @@ namespace Nz
|
||||
TextureSamplerInfo samplerInfo;
|
||||
};
|
||||
|
||||
struct ShaderEntry
|
||||
{
|
||||
NazaraSlot(UberShader, OnShaderUpdated, onShaderUpdated);
|
||||
};
|
||||
|
||||
struct UniformBuffer
|
||||
{
|
||||
std::shared_ptr<RenderBuffer> buffer;
|
||||
@@ -135,6 +145,7 @@ namespace Nz
|
||||
std::array<ShaderAst::ConstantValue, 64> m_optionValues;
|
||||
std::shared_ptr<const MaterialSettings> m_settings;
|
||||
std::vector<MaterialTexture> m_textures;
|
||||
std::vector<ShaderEntry> m_shaders;
|
||||
std::vector<UniformBuffer> m_uniformBuffers;
|
||||
mutable std::shared_ptr<MaterialPipeline> m_pipeline;
|
||||
mutable MaterialPipelineInfo m_pipelineInfo;
|
||||
|
||||
@@ -67,7 +67,13 @@ namespace Nz
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
struct UberShaderEntry
|
||||
{
|
||||
NazaraSlot(UberShader, OnShaderUpdated, onShaderUpdated);
|
||||
};
|
||||
|
||||
mutable std::vector<std::shared_ptr<RenderPipeline>> m_renderPipelines;
|
||||
std::vector<UberShaderEntry> m_uberShaderEntries;
|
||||
MaterialPipelineInfo m_pipelineInfo;
|
||||
|
||||
using PipelineCache = std::unordered_map<MaterialPipelineInfo, std::shared_ptr<MaterialPipeline>>;
|
||||
|
||||
@@ -12,6 +12,15 @@ namespace Nz
|
||||
inline MaterialPipeline::MaterialPipeline(const MaterialPipelineInfo& pipelineInfo, Token) :
|
||||
m_pipelineInfo(pipelineInfo)
|
||||
{
|
||||
m_uberShaderEntries.resize(m_pipelineInfo.shaders.size());
|
||||
for (std::size_t i = 0; i < m_uberShaderEntries.size(); ++i)
|
||||
{
|
||||
m_uberShaderEntries[i].onShaderUpdated.Connect(m_pipelineInfo.shaders[i].uberShader->OnShaderUpdated, [this](UberShader*)
|
||||
{
|
||||
// Clear cache
|
||||
m_renderPipelines.clear();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Renderer/RenderPipeline.hpp>
|
||||
#include <Nazara/Shader/ShaderModuleResolver.hpp>
|
||||
#include <Nazara/Shader/Ast/Module.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -26,6 +28,8 @@ namespace Nz
|
||||
struct Option;
|
||||
using ConfigCallback = std::function<void(Config& config, const std::vector<RenderPipelineInfo::VertexBufferData>& vertexBuffers)>;
|
||||
|
||||
UberShader(ShaderStageTypeFlags shaderStages, std::string moduleName);
|
||||
UberShader(ShaderStageTypeFlags shaderStages, ShaderModuleResolver& moduleResolver, std::string moduleName);
|
||||
UberShader(ShaderStageTypeFlags shaderStages, ShaderAst::ModulePtr shaderModule);
|
||||
~UberShader() = default;
|
||||
|
||||
@@ -58,7 +62,13 @@ namespace Nz
|
||||
UInt32 hash;
|
||||
};
|
||||
|
||||
NazaraSignal(OnShaderUpdated, UberShader* /*uberShader*/);
|
||||
|
||||
private:
|
||||
void Validate(ShaderAst::Module& module);
|
||||
|
||||
NazaraSlot(ShaderModuleResolver, OnModuleUpdated, m_onShaderModuleUpdated);
|
||||
|
||||
std::unordered_map<Config, std::shared_ptr<ShaderModule>, ConfigHasher, ConfigEqual> m_combinations;
|
||||
std::unordered_map<std::string, Option> m_optionIndexByName;
|
||||
ShaderAst::ModulePtr m_shaderModule;
|
||||
|
||||
Reference in New Issue
Block a user