Nameless Engine
|
#include <GlslShader.h>
Public Member Functions | |
GlslShader (Renderer *pRenderer, std::filesystem::path pathToCompiledShader, const std::string &sShaderName, ShaderType shaderType, const std::optional< VertexFormat > &vertexFormat) | |
GlslShader (const GlslShader &)=delete | |
GlslShader & | operator= (const GlslShader &)=delete |
std::variant< std::pair< std::recursive_mutex, std::vector< char > > *, Error > | getCompiledBytecode () |
std::pair< std::mutex, std::optional< DescriptorSetLayoutGenerator::Collected > > * | getDescriptorSetLayoutInfo () |
virtual bool | releaseShaderDataFromMemoryIfLoaded () override |
Public Member Functions inherited from ne::Shader | |
Shader (const Shader &)=delete | |
Shader & | operator= (const Shader &)=delete |
std::string | getShaderName () const |
ShaderType | getShaderType () const |
std::optional< VertexFormat > | getVertexFormat () const |
virtual bool | releaseShaderDataFromMemoryIfLoaded ()=0 |
Static Public Member Functions | |
static std::variant< std::vector< uint32_t >, std::string, Error > | compileShaderToBytecode (const ShaderDescription &shaderDescription) |
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) |
Static Public Member Functions inherited from ne::Shader | |
static constexpr const char * | getFrameConstantsShaderResourceName () |
static size_t | getCurrentAmountOfShadersInMemory () |
static std::variant< std::shared_ptr< Shader >, std::string, Error > | compileShader (Renderer *pRenderer, const std::filesystem::path &shaderCacheDirectory, const std::string &sConfiguration, const ShaderDescription &shaderDescription) |
static std::variant< std::shared_ptr< Shader >, Error > | createFromCache (Renderer *pRenderer, const std::filesystem::path &pathToCompiledShaderBytecode, ShaderDescription &shaderDescription, const std::string &sShaderNameWithoutConfiguration, std::optional< ShaderCacheInvalidationReason > &cacheInvalidationReason) |
Protected Member Functions | |
virtual std::optional< Error > | saveAdditionalCompilationResultsInfo (ConfigManager &cacheMetadataConfigManager) override |
virtual std::optional< Error > | checkCachedAdditionalCompilationResultsInfo (ConfigManager &cacheMetadataConfigManager, std::optional< ShaderCacheInvalidationReason > &cacheInvalidationReason) override |
Protected Member Functions inherited from ne::Shader | |
Shader (Renderer *pRenderer, std::filesystem::path pathToCompiledShader, const std::string &sShaderName, ShaderType shaderType, std::optional< VertexFormat > vertexFormat) | |
virtual std::optional< Error > | saveAdditionalCompilationResultsInfo (ConfigManager &cacheMetadataConfigManager) |
virtual std::optional< Error > | checkCachedAdditionalCompilationResultsInfo (ConfigManager &cacheMetadataConfigManager, std::optional< ShaderCacheInvalidationReason > &cacheInvalidationReason) |
std::variant< std::filesystem::path, Error > | getPathToCompiledShader () |
Renderer * | getRenderer () const |
Private Member Functions | |
std::optional< Error > | loadShaderDataFromDiskIfNotLoaded () |
Static Private Member Functions | |
static shaderc_shader_kind | convertShaderTypeToShadercShaderKind (ShaderType shaderType) |
Private Attributes | |
std::pair< std::recursive_mutex, std::vector< char > > | mtxSpirvBytecode |
std::pair< std::mutex, std::optional< DescriptorSetLayoutGenerator::Collected > > | mtxDescriptorSetLayoutInfo |
Static Private Attributes | |
static const auto | sDescriptorSetLayoutSectionName = "Descriptor Set Layout" |
Additional Inherited Members | |
Static Protected Member Functions inherited from ne::Shader | |
static void | notifyShaderBytecodeLoadedIntoMemory () |
static void | notifyShaderBytecodeReleasedFromMemory () |
Represents a compiled GLSL shader.
ne::GlslShader::GlslShader | ( | Renderer * | pRenderer, |
std::filesystem::path | pathToCompiledShader, | ||
const std::string & | sShaderName, | ||
ShaderType | shaderType, | ||
const std::optional< VertexFormat > & | vertexFormat | ||
) |
Constructor. Used to create shader using cache.
pRenderer | Used renderer. |
pathToCompiledShader | Path to compiled shader bytecode on disk. |
sShaderName | Unique name of this shader. |
shaderType | Type of this shader. |
vertexFormat | Vertex format that this shader uses (can be empty if not applicable, for example if this is a compute shader). |
|
overrideprotectedvirtual |
Used to check cached data of shader language specific (additional) shader compilation results (such as reflection data, i.e. if there are some other compilation results besides compiled shader bytecode which is automatically hashed and checked) whether its valid or not.
cacheMetadataConfigManager | Config manager to write the data to. |
cacheInvalidationReason | Will be not empty if cache was invalidated (i.e. cache can't be used). |
Reimplemented from ne::Shader.
|
static |
Compiles a shader.
pRenderer | Vulkan renderer. |
cacheDirectory | Directory to store this shader's cache, for example: ".../shader_cache/engine.default". |
sConfiguration | Shader configuration text that will be added to the name. |
shaderDescription | Description that describes the shader and how the shader should be compiled. |
|
static |
Compiles the specified shader file to bytecode.
shaderDescription | Describes the shader and how the shader should be compiled. |
|
staticprivate |
std::variant< std::pair< std::recursive_mutex, std::vector< char > > *, Error > ne::GlslShader::getCompiledBytecode | ( | ) |
Loads compiled SPIR-V bytecode from disk and stores it in memory. Subsequent calls to this function will just return the bytecode pointer (no disk loading will happen).
std::pair< std::mutex, std::optional< DescriptorSetLayoutGenerator::Collected > > * ne::GlslShader::getDescriptorSetLayoutInfo | ( | ) |
Returns information about descriptor layout that can be used for this shader.
|
private |
Loads shader data (bytecode, descriptor set layout info, etc.) from disk cache if it's not loaded yet.
|
overridevirtual |
Releases underlying shader data (bytecode, root signature, etc.) from memory (this object will not be deleted) if the shader data was loaded into memory. Next time this shader will be needed the data will be loaded from disk.
false
if was released from memory, true
if was not loaded in memory previously. Implements ne::Shader.
|
overrideprotectedvirtual |
Used to save data of shader language specific (additional) shader compilation results (such as reflection data, i.e. if there are some other compilation results besides compiled shader bytecode which is automatically hashed and checked) to later check them in checkCachedAdditionalCompilationResultsInfo.
cacheMetadataConfigManager | Config manager to write the data to. |
Reimplemented from ne::Shader.
|
private |
Contains information used to create descriptor set layout.
|
private |
SPIR-V bytecode (array of bytes) of the compiled shader.
|
inlinestaticprivate |
Name of the section used to store descriptor set layout info.