Nameless Engine
|
#include <Shader.h>
Public Member Functions | |
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 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 | |
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 |
Static Protected Member Functions | |
static void | notifyShaderBytecodeLoadedIntoMemory () |
static void | notifyShaderBytecodeReleasedFromMemory () |
Static Private Member Functions | |
static std::variant< std::shared_ptr< Shader >, std::string, Error > | compileRenderDependentShader (Renderer *pRenderer, const std::filesystem::path &shaderCacheDirectory, const std::string &sConfiguration, const ShaderDescription &shaderDescription) |
static std::variant< std::shared_ptr< Shader >, Error > | createRenderDependentShaderFromCache (Renderer *pRenderer, const std::filesystem::path &pathToSourceShaderFile, const std::filesystem::path &pathToCompiledShaderBytecode, const std::string &sShaderName, ShaderType shaderType, std::optional< VertexFormat > vertexFormat) |
Private Attributes | |
Renderer *const | pRenderer = nullptr |
const std::optional< VertexFormat > | optionalVertexFormat |
const std::string | sShaderName |
const ShaderType | shaderType |
const std::filesystem::path | pathToCompiledShader |
Static Private Attributes | |
static const auto | sCompiledBytecodeHashKeyName = "compiled_bytecode_hash" |
static constexpr auto | pFrameConstantBufferName = "frameData" |
Base class for different types/formats of shaders to implement.
Represents a single compiled shader variant from the ShaderPack.
|
protected |
Constructor.
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). |
|
inlineprotectedvirtual |
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 in ne::GlslShader, and ne::HlslShader.
|
staticprivate |
Compiles a HLSL/GLSL shader depending on the used renderer.
pRenderer | Current renderer. |
shaderCacheDirectory | 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 a shader.
pRenderer | Current renderer. |
shaderCacheDirectory | 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 |
Creates a new shader using shader cache.
pRenderer | Used renderer. |
pathToCompiledShaderBytecode | Path to compiled shader bytecode on disk (with configuration), for example: ".../shader_cache/engine.default.vs/shader16604691462768904089". |
shaderDescription | Description that describes the shader and how the shader should be compiled. Used for cache invalidation. |
sShaderNameWithoutConfiguration | Initial shader name without configuration hash, this name is used for logging. |
cacheInvalidationReason | Will be not empty if cache was invalidated (i.e. cache can't be used). |
|
staticprivate |
Creates a new HLSL/GLSL shader depending on the used renderer, expects that all cached shader data is valid.
pRenderer | Used renderer. |
pathToSourceShaderFile | Path to shader source code file. |
pathToCompiledShaderBytecode | Path to compiled shader bytecode on disk. |
sShaderName | Unique name of this shader. |
shaderType | Type of this shader. |
vertexFormat | Can be empty if non applicable (for example if this shader is a compute shader). |
|
static |
Returns the current amount shaders (vertex, pixel, etc.) loaded into the memory (RAM/VRAM).
|
inlinestaticconstexpr |
Returns name of the shader resource that stores frame-global constants.
|
protected |
Returns path to compiled shader blob on disk.
|
protected |
Returns renderer.
std::string ne::Shader::getShaderName | ( | ) | const |
Returns unique name of this shader.
ShaderType ne::Shader::getShaderType | ( | ) | const |
Returns type of this shader.
std::optional< VertexFormat > ne::Shader::getVertexFormat | ( | ) | const |
Returns vertex format used by this shader.
|
staticprotected |
Derived shader classes should call this function once they load shader bytecode into the memory from the disk.
|
staticprotected |
Derived shader classes should call this function once they release shader bytecode from the memory.
|
pure virtual |
Releases underlying shader bytecode for each shader from memory (this object will not be deleted) if the shader bytecode was loaded into memory. Next time this shader will be needed it will be loaded from disk.
false
if was released from memory, true
if was not loaded in memory previously. Implemented in ne::GlslShader, and ne::HlslShader.
|
inlineprotectedvirtual |
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 in ne::GlslShader, and ne::HlslShader.
|
private |
Vertex format that this shader uses.
|
private |
Path to compiled shader.
|
staticconstexprprivate |
Name of the cbuffer
/uniform
resource used to store frame data in shaders.
|
private |
Do not delete. Used renderer.
|
inlinestaticprivate |
Name of the key used to store compiled bytecode hash in the metadata file.
|
private |
Type of this shader.
|
private |
Unique shader name received from ShaderManager.