Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
foray::core::ShaderManager Class Reference

Shader manager maintains a structure of shader compilations. More...

#include <foray_shadermanager.hpp>

Classes

struct  IncludeFile
 Represents a file included (nested) in a shader compilation, but not compiled by itself. More...
 
struct  ShaderCompilation
 Represents a unique shader compilation (input source path + config => Spirv file) More...
 

Public Member Functions

 ShaderManager (core::Context *context=nullptr)
 
uint64_t CompileShader (osi::Utf8Path sourceFilePath, ShaderModule &shaderModule, const ShaderCompilerConfig &config={}, core::Context *context=nullptr)
 Accesses sourceFilePath, scans for dependencies, compiles if necessary, loads into shaderModule.
 
uint64_t CompileShader (osi::Utf8Path sourceFilePath, ShaderModule *shaderModule, const ShaderCompilerConfig &config={}, core::Context *context=nullptr)
 Accesses sourceFilePath, scans for dependencies, compiles if necessary, loads into shaderModule.
 
virtual bool CheckAndUpdateShaders (std::unordered_set< uint64_t > &out_recompiled)
 Checks and updates shader compilations for source code changes.
 
 ShaderManager ()=default
 
virtual bool CallGlslCompiler (std::string_view args)
 Calls glslc in path on linux, glslc.exe (derived from VULKAN_SDK environment variable) on windows.
 

Protected Types

enum class  ECompileCheckResult { UpToDate , MissingInput , NeedsRecompile }
 
using WriteTimeLookup = std::unordered_map< osi::Utf8Path, std::filesystem::file_time_type >
 maps files to last write times
 

Protected Member Functions

virtual uint64_t MakeHash (std::string_view absoluteUniqueSourceFilePath, const ShaderCompilerConfig &config)
 Calculates a unique hash based on source file path and config.
 
void DiscoverIncludes (ShaderCompilation *compilation)
 Discover and register all includes for a shader compilation.
 
IncludeFileRecursivelyProcessInclude (const osi::Utf8Path &path, const std::vector< osi::Utf8Path > &extraIncludeDirs)
 Create or return an include file. Recursively processes #include directives to resolve nested includes.
 

Static Protected Member Functions

static std::filesystem::file_time_type GetWriteTime (const osi::Utf8Path &path, WriteTimeLookup &writeTimeLookup)
 Get last write time.
 

Protected Attributes

core::ContextmContext = nullptr
 Context used for initialization of shader modules.
 
std::unordered_map< uint64_t, std::unique_ptr< ShaderCompilation > > mTrackedCompilations
 Map of shader compilation keys to tracked compilations.
 
std::unordered_map< osi::Utf8Path, std::unique_ptr< IncludeFile > > mTrackedIncludeFiles
 Map of include file paths to include file structs.
 

Detailed Description

Shader manager maintains a structure of shader compilations.

When registering a shader file compilation via CompileShader(..):

Member Typedef Documentation

◆ WriteTimeLookup

using foray::core::ShaderManager::WriteTimeLookup = std::unordered_map<osi::Utf8Path, std::filesystem::file_time_type>
protected

maps files to last write times

Member Enumeration Documentation

◆ ECompileCheckResult

Enumerator
UpToDate 
MissingInput 
NeedsRecompile 

Constructor & Destructor Documentation

◆ ShaderManager() [1/2]

foray::core::ShaderManager::ShaderManager ( core::Context context = nullptr)
inlineexplicit
Parameters
contextIf set, is used as fallback for CompileShader() context argument

◆ ShaderManager() [2/2]

foray::core::ShaderManager::ShaderManager ( )
default

Member Function Documentation

◆ CallGlslCompiler()

virtual bool foray::core::ShaderManager::CallGlslCompiler ( std::string_view  args)
virtual

Calls glslc in path on linux, glslc.exe (derived from VULKAN_SDK environment variable) on windows.

Parameters
argsArguments are passed as follows: GLSLC_EXECUTABLE –target-spv=spv1.5 OPTIMIZE ARGS (OPTIMIZE = -O0 for DEBUG, -O for RELEASE CMake targets)
Returns
True if glslc compiler exe returns 0 (indicating success), false otherwise

◆ CheckAndUpdateShaders()

virtual bool foray::core::ShaderManager::CheckAndUpdateShaders ( std::unordered_set< uint64_t > &  out_recompiled)
virtual

Checks and updates shader compilations for source code changes.

Will check all tracked shader files for modifications and recompile the shader compilations accordingly

Parameters
out_recompiledOutput set for shader compilation keys which have been recompiled
Returns
Returns true if any shader was updated

◆ CompileShader() [1/2]

uint64_t foray::core::ShaderManager::CompileShader ( osi::Utf8Path  sourceFilePath,
ShaderModule shaderModule,
const ShaderCompilerConfig config = {},
core::Context context = nullptr 
)

Accesses sourceFilePath, scans for dependencies, compiles if necessary, loads into shaderModule.

Parameters
sourceFilePathPath to the shader source file
shaderModuleOutput shadermodule to initialize
configConfigure compilation parameters
contextContext for initialization of ShaderModule. If set to nullptr, will use ShaderManager context
Returns
Returns the key to this unique shader compilation

◆ CompileShader() [2/2]

uint64_t foray::core::ShaderManager::CompileShader ( osi::Utf8Path  sourceFilePath,
ShaderModule shaderModule,
const ShaderCompilerConfig config = {},
core::Context context = nullptr 
)

Accesses sourceFilePath, scans for dependencies, compiles if necessary, loads into shaderModule.

Parameters
sourceFilePathPath to the shader source file
shaderModuleOutput shadermodule to initialize
configConfigure compilation parameters
contextContext for initialization of ShaderModule. If set to nullptr, will use ShaderManager context
Returns
Returns the key to this unique shader compilation

◆ DiscoverIncludes()

void foray::core::ShaderManager::DiscoverIncludes ( ShaderCompilation compilation)
protected

Discover and register all includes for a shader compilation.

◆ GetWriteTime()

static std::filesystem::file_time_type foray::core::ShaderManager::GetWriteTime ( const osi::Utf8Path path,
WriteTimeLookup writeTimeLookup 
)
staticprotected

Get last write time.

Parameters
pathFile path
writeTimeLookupLookup
Returns
Lookup table result / std::filesystem::file_time_type::min() if not found, last write time otherwise

◆ MakeHash()

virtual uint64_t foray::core::ShaderManager::MakeHash ( std::string_view  absoluteUniqueSourceFilePath,
const ShaderCompilerConfig config 
)
protectedvirtual

Calculates a unique hash based on source file path and config.

◆ RecursivelyProcessInclude()

IncludeFile * foray::core::ShaderManager::RecursivelyProcessInclude ( const osi::Utf8Path path,
const std::vector< osi::Utf8Path > &  extraIncludeDirs 
)
protected

Create or return an include file. Recursively processes #include directives to resolve nested includes.

Parameters
pathAbsolute file path
extraIncludeDirsAdditional include dirs
Returns
Include File

Member Data Documentation

◆ mContext

core::Context* foray::core::ShaderManager::mContext = nullptr
protected

Context used for initialization of shader modules.

◆ mTrackedCompilations

std::unordered_map<uint64_t, std::unique_ptr<ShaderCompilation> > foray::core::ShaderManager::mTrackedCompilations
protected

Map of shader compilation keys to tracked compilations.

◆ mTrackedIncludeFiles

std::unordered_map<osi::Utf8Path, std::unique_ptr<IncludeFile> > foray::core::ShaderManager::mTrackedIncludeFiles
protected

Map of include file paths to include file structs.


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