Nameless Engine
Loading...
Searching...
No Matches
ne::GlslShader Class Reference

#include <GlslShader.h>

Inheritance diagram for ne::GlslShader:
ne::Shader

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
 
GlslShaderoperator= (const GlslShader &)=delete
 
std::variant< std::pair< std::recursive_mutex, std::vector< char > > *, ErrorgetCompiledBytecode ()
 
std::pair< std::mutex, std::optional< DescriptorSetLayoutGenerator::Collected > > * getDescriptorSetLayoutInfo ()
 
virtual bool releaseShaderDataFromMemoryIfLoaded () override
 
- Public Member Functions inherited from ne::Shader
 Shader (const Shader &)=delete
 
Shaderoperator= (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, ErrorcompileShaderToBytecode (const ShaderDescription &shaderDescription)
 
static std::variant< std::shared_ptr< Shader >, std::string, ErrorcompileShader (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, ErrorcompileShader (Renderer *pRenderer, const std::filesystem::path &shaderCacheDirectory, const std::string &sConfiguration, const ShaderDescription &shaderDescription)
 
static std::variant< std::shared_ptr< Shader >, ErrorcreateFromCache (Renderer *pRenderer, const std::filesystem::path &pathToCompiledShaderBytecode, ShaderDescription &shaderDescription, const std::string &sShaderNameWithoutConfiguration, std::optional< ShaderCacheInvalidationReason > &cacheInvalidationReason)
 

Protected Member Functions

virtual std::optional< ErrorsaveAdditionalCompilationResultsInfo (ConfigManager &cacheMetadataConfigManager) override
 
virtual std::optional< ErrorcheckCachedAdditionalCompilationResultsInfo (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< ErrorsaveAdditionalCompilationResultsInfo (ConfigManager &cacheMetadataConfigManager)
 
virtual std::optional< ErrorcheckCachedAdditionalCompilationResultsInfo (ConfigManager &cacheMetadataConfigManager, std::optional< ShaderCacheInvalidationReason > &cacheInvalidationReason)
 
std::variant< std::filesystem::path, ErrorgetPathToCompiledShader ()
 
RenderergetRenderer () const
 

Private Member Functions

std::optional< ErrorloadShaderDataFromDiskIfNotLoaded ()
 

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 ()
 

Detailed Description

Represents a compiled GLSL shader.

Constructor & Destructor Documentation

◆ GlslShader()

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.

Parameters
pRendererUsed renderer.
pathToCompiledShaderPath to compiled shader bytecode on disk.
sShaderNameUnique name of this shader.
shaderTypeType of this shader.
vertexFormatVertex format that this shader uses (can be empty if not applicable, for example if this is a compute shader).

Member Function Documentation

◆ checkCachedAdditionalCompilationResultsInfo()

std::optional< Error > ne::GlslShader::checkCachedAdditionalCompilationResultsInfo ( ConfigManager cacheMetadataConfigManager,
std::optional< ShaderCacheInvalidationReason > &  cacheInvalidationReason 
)
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.

Parameters
cacheMetadataConfigManagerConfig manager to write the data to.
cacheInvalidationReasonWill be not empty if cache was invalidated (i.e. cache can't be used).
Returns
Error if some internal error occurred.

Reimplemented from ne::Shader.

◆ compileShader()

std::variant< std::shared_ptr< Shader >, std::string, Error > ne::GlslShader::compileShader ( Renderer pRenderer,
const std::filesystem::path &  cacheDirectory,
const std::string &  sConfiguration,
const ShaderDescription shaderDescription 
)
static

Compiles a shader.

Parameters
pRendererVulkan renderer.
cacheDirectoryDirectory to store this shader's cache, for example: ".../shader_cache/engine.default".
sConfigurationShader configuration text that will be added to the name.
shaderDescriptionDescription that describes the shader and how the shader should be compiled.
Returns
One of the three values: compiled shader, string containing shader compilation error/warning or an internal error.

◆ compileShaderToBytecode()

static std::variant< std::vector< uint32_t >, std::string, Error > ne::GlslShader::compileShaderToBytecode ( const ShaderDescription shaderDescription)
static

Compiles the specified shader file to bytecode.

Parameters
shaderDescriptionDescribes the shader and how the shader should be compiled.
Returns
One of the three values: compiled bytecode, string containing shader compilation error/warning or an internal error.

◆ convertShaderTypeToShadercShaderKind()

shaderc_shader_kind ne::GlslShader::convertShaderTypeToShadercShaderKind ( ShaderType  shaderType)
staticprivate

Converts shader type to a shader kind type used by shaderc library.

Parameters
shaderTypeShader type to convert.
Returns
Shader kind.

◆ getCompiledBytecode()

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).

Remarks
Returned pointer will only be valid while this object is alive.
Returns
Error if something went wrong, otherwise a mutex to use while accessing the bytecode and an array of bytes.

◆ getDescriptorSetLayoutInfo()

std::pair< std::mutex, std::optional< DescriptorSetLayoutGenerator::Collected > > * ne::GlslShader::getDescriptorSetLayoutInfo ( )

Returns information about descriptor layout that can be used for this shader.

Returns
Empty if descriptor layout information was not collected yet, use getCompiledBytecode to collect and load everything, otherwise descriptor layout info.

◆ loadShaderDataFromDiskIfNotLoaded()

std::optional< Error > ne::GlslShader::loadShaderDataFromDiskIfNotLoaded ( )
private

Loads shader data (bytecode, descriptor set layout info, etc.) from disk cache if it's not loaded yet.

Returns
Error if something went wrong.

◆ releaseShaderDataFromMemoryIfLoaded()

bool ne::GlslShader::releaseShaderDataFromMemoryIfLoaded ( )
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.

Returns
false if was released from memory, true if was not loaded in memory previously.

Implements ne::Shader.

◆ saveAdditionalCompilationResultsInfo()

std::optional< Error > ne::GlslShader::saveAdditionalCompilationResultsInfo ( ConfigManager cacheMetadataConfigManager)
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.

Parameters
cacheMetadataConfigManagerConfig manager to write the data to.
Returns
Error if something went wrong.

Reimplemented from ne::Shader.

Member Data Documentation

◆ mtxDescriptorSetLayoutInfo

std::pair<std::mutex, std::optional<DescriptorSetLayoutGenerator::Collected> > ne::GlslShader::mtxDescriptorSetLayoutInfo
private

Contains information used to create descriptor set layout.

Remarks
Might not be calculated yet, see loadShaderDataFromDiskIfNotLoaded for collecting this information.

◆ mtxSpirvBytecode

std::pair<std::recursive_mutex, std::vector<char> > ne::GlslShader::mtxSpirvBytecode
private

SPIR-V bytecode (array of bytes) of the compiled shader.

◆ sDescriptorSetLayoutSectionName

const auto ne::GlslShader::sDescriptorSetLayoutSectionName = "Descriptor Set Layout"
inlinestaticprivate

Name of the section used to store descriptor set layout info.


The documentation for this class was generated from the following files: