Nameless Engine
Loading...
Searching...
No Matches
GlslShader.h
1#pragma once
2
3// Standard.
4#include <mutex>
5#include <optional>
6#include <unordered_map>
7
8// Custom.
9#include "shader/general/Shader.h"
10#include "shader/glsl/DescriptorSetLayoutGenerator.h"
11
12// External.
13#include "shaderc/shaderc.hpp"
14#include "vulkan/vulkan.h"
15
16namespace ne {
17 class Renderer;
18
20 class GlslShader : public Shader {
21 public:
34 std::filesystem::path pathToCompiledShader,
35 const std::string& sShaderName,
36 ShaderType shaderType,
37 const std::optional<VertexFormat>& vertexFormat);
38
39 GlslShader() = delete;
40 GlslShader(const GlslShader&) = delete;
41 GlslShader& operator=(const GlslShader&) = delete;
42
43 virtual ~GlslShader() override = default;
44
54 static std::variant<std::vector<uint32_t>, std::string, Error>
55 compileShaderToBytecode(const ShaderDescription& shaderDescription);
56
70 static std::variant<std::shared_ptr<Shader>, std::string, Error> compileShader(
72 const std::filesystem::path& cacheDirectory,
73 const std::string& sConfiguration,
74 const ShaderDescription& shaderDescription);
75
86 std::variant<std::pair<std::recursive_mutex, std::vector<char>>*, Error> getCompiledBytecode();
87
94 std::pair<std::mutex, std::optional<DescriptorSetLayoutGenerator::Collected>>*
96
104 virtual bool releaseShaderDataFromMemoryIfLoaded() override;
105
106 protected:
117 [[nodiscard]] virtual std::optional<Error>
118 saveAdditionalCompilationResultsInfo(ConfigManager& cacheMetadataConfigManager) override;
119
131 [[nodiscard]] virtual std::optional<Error> checkCachedAdditionalCompilationResultsInfo(
132 ConfigManager& cacheMetadataConfigManager,
133 std::optional<ShaderCacheInvalidationReason>& cacheInvalidationReason) override;
134
135 private:
143 static shaderc_shader_kind convertShaderTypeToShadercShaderKind(ShaderType shaderType);
144
151 [[nodiscard]] std::optional<Error> loadShaderDataFromDiskIfNotLoaded();
152
154 std::pair<std::recursive_mutex, std::vector<char>> mtxSpirvBytecode;
155
162 std::pair<std::mutex, std::optional<DescriptorSetLayoutGenerator::Collected>>
164
166 static inline const auto sDescriptorSetLayoutSectionName = "Descriptor Set Layout";
167 };
168} // namespace ne
Definition: ConfigManager.h:27
Definition: Error.h:27
Definition: GlslShader.h:20
std::variant< std::pair< std::recursive_mutex, std::vector< char > > *, Error > getCompiledBytecode()
Definition: GlslShader.cpp:217
std::pair< std::mutex, std::optional< DescriptorSetLayoutGenerator::Collected > > * getDescriptorSetLayoutInfo()
Definition: GlslShader.cpp:230
static std::variant< std::shared_ptr< Shader >, std::string, Error > compileShader(Renderer *pRenderer, const std::filesystem::path &cacheDirectory, const std::string &sConfiguration, const ShaderDescription &shaderDescription)
Definition: GlslShader.cpp:58
static shaderc_shader_kind convertShaderTypeToShadercShaderKind(ShaderType shaderType)
Definition: GlslShader.cpp:234
std::pair< std::mutex, std::optional< DescriptorSetLayoutGenerator::Collected > > mtxDescriptorSetLayoutInfo
Definition: GlslShader.h:163
std::pair< std::recursive_mutex, std::vector< char > > mtxSpirvBytecode
Definition: GlslShader.h:154
virtual std::optional< Error > saveAdditionalCompilationResultsInfo(ConfigManager &cacheMetadataConfigManager) override
Definition: GlslShader.cpp:206
virtual std::optional< Error > checkCachedAdditionalCompilationResultsInfo(ConfigManager &cacheMetadataConfigManager, std::optional< ShaderCacheInvalidationReason > &cacheInvalidationReason) override
Definition: GlslShader.cpp:210
virtual bool releaseShaderDataFromMemoryIfLoaded() override
Definition: GlslShader.cpp:184
std::optional< Error > loadShaderDataFromDiskIfNotLoaded()
Definition: GlslShader.cpp:255
static std::variant< std::vector< uint32_t >, std::string, Error > compileShaderToBytecode(const ShaderDescription &shaderDescription)
static const auto sDescriptorSetLayoutSectionName
Definition: GlslShader.h:166
Definition: Renderer.h:43
Definition: Shader.h:23
const ShaderType shaderType
Definition: Shader.h:254
const std::filesystem::path pathToCompiledShader
Definition: Shader.h:257
const std::string sShaderName
Definition: Shader.h:251
Renderer *const pRenderer
Definition: Shader.h:241
Definition: ShaderDescription.h:74