Nameless Engine
|
#include <HlslShader.h>
Public Member Functions | |
HlslShader (Renderer *pRenderer, std::filesystem::path pathToCompiledShader, const std::string &sShaderName, ShaderType shaderType, const std::optional< VertexFormat > &vertexFormat, const std::string &sSourceFileHash) | |
HlslShader (const HlslShader &)=delete | |
HlslShader & | operator= (const HlslShader &)=delete |
std::variant< ComPtr< IDxcBlob >, Error > | getCompiledBlob () |
std::pair< std::mutex, std::optional< RootSignatureGenerator::CollectedInfo > > * | getRootSignatureInfo () |
std::string | getShaderSourceFileHash () const |
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 constexpr std::string_view | getVertexShaderModel () |
static constexpr std::string_view | getPixelShaderModel () |
static constexpr std::string_view | getComputeShaderModel () |
static std::variant< std::string, Error > | getShaderCompilerVersion () |
static CD3DX12_STATIC_SAMPLER_DESC | getStaticSamplerDescription (TextureFilteringQuality textureFilteringQuality) |
static CD3DX12_STATIC_SAMPLER_DESC | getStaticComparisonSamplerDescription () |
static UINT | getStaticSamplerShaderRegisterSpace () |
static std::variant< ComPtr< IDxcResult >, std::string, Error > | compileShaderToBytecode (const ShaderDescription &shaderDescription, const std::optional< std::filesystem::path > &pathToPdb) |
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::variant< std::string, Error > | calculateReflectionFileHash () |
std::optional< Error > | loadShaderDataFromDiskIfNotLoaded () |
Static Private Member Functions | |
static std::variant< ComPtr< IDxcBlob >, Error > | readBlobFromDisk (const std::filesystem::path &pathToFile) |
Private Attributes | |
std::pair< std::recursive_mutex, ComPtr< IDxcBlob > > | mtxCompiledBytecode |
std::pair< std::mutex, std::optional< RootSignatureGenerator::CollectedInfo > > | mtxRootSignatureInfo |
std::string | sSourceFileHash |
Static Private Attributes | |
static UINT | iShaderFileCodepage = DXC_CP_ACP |
static auto | sShaderReflectionFileExtension = ".reflection" |
static const auto | sReflectionFileHashKeyName = "reflection_file_hash" |
static const auto | sHlslSectionName = "HLSL" |
static const UINT | iStaticSamplerShaderRegisterSpace = 5 |
static constexpr std::string_view | sVertexShaderModel = "vs_6_0" |
static constexpr std::string_view | sPixelShaderModel = "ps_6_0" |
static constexpr std::string_view | sComputeShaderModel = "cs_6_0" |
Additional Inherited Members | |
Static Protected Member Functions inherited from ne::Shader | |
static void | notifyShaderBytecodeLoadedIntoMemory () |
static void | notifyShaderBytecodeReleasedFromMemory () |
Represents a compiled HLSL shader.
ne::HlslShader::HlslShader | ( | Renderer * | pRenderer, |
std::filesystem::path | pathToCompiledShader, | ||
const std::string & | sShaderName, | ||
ShaderType | shaderType, | ||
const std::optional< VertexFormat > & | vertexFormat, | ||
const std::string & | sSourceFileHash | ||
) |
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). |
sSourceFileHash | Shader source file hash, used to tell what shaders were compiled from the same file. |
|
private |
Looks for reflection file next to the compiled shader bytecode file and calculates its hash.
|
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 | DirectX 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. |
pathToPdb | Path where the PDB will be saved after compilation (outside of this function) in debug builds. |
std::variant< ComPtr< IDxcBlob >, Error > ne::HlslShader::getCompiledBlob | ( | ) |
Loads compiled bytecode from disk and stores it in memory. Subsequent calls to this function will just copy the bytecode pointer (no disk loading will happen).
|
inlinestaticconstexpr |
Returns used compute shader model version.
|
inlinestaticconstexpr |
Returns used pixel shader model version.
std::pair< std::mutex, std::optional< RootSignatureGenerator::CollectedInfo > > * ne::HlslShader::getRootSignatureInfo | ( | ) |
Returns information about root signature that can be used for this shader.
|
static |
Returns current version of the HLSL shader compiler.
std::string ne::HlslShader::getShaderSourceFileHash | ( | ) | const |
Returns hash of the shader source file that was used to compile the shader.
|
static |
Returns description of a static comparison sampler.
|
static |
Returns a static sampler description depending on the specified texture filtering mode.
textureFilteringQuality | Returned sampler description will use the specified texture filtering. |
|
static |
Returns shader register space (in HLSL) that should be used by different sampler types.
|
inlinestaticconstexpr |
Returns used vertex shader model version.
|
private |
Loads shader data (bytecode, root signature, etc.) from disk cache if it's not loaded yet.
|
staticprivate |
Reads file and creates a new DXC blob using file's content.
pathToFile | Path to the file to create blob from. |
|
overridevirtual |
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. 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.
|
inlinestaticprivate |
Shader file encoding.
|
inlinestaticprivate |
Determines which shader register space (in HLSL) should be used by different sampler types.
|
private |
Mutex for read/write operations on compiled bytecode (may be empty if not stored in memory right now).
|
private |
Contains information used to create root signature.
|
staticconstexprprivate |
Used compute shader model.
|
inlinestaticprivate |
Name of the section used to store HLSL specific metadata.
|
staticconstexprprivate |
Used pixel shader model.
|
inlinestaticprivate |
Name of the key used to store reflection file hash in the metadata file.
|
inlinestaticprivate |
File extension for saving shader reflection data.
|
private |
Shader source file hash, used to tell what shaders were compiled from the same file.
|
staticconstexprprivate |
Used vertex shader model.