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

Wraps shader code driver handle (VkShaderModule). See ShaderManager for compiling shaders dynamically. More...

#include <foray_shadermodule.hpp>

Inheritance diagram for foray::core::ShaderModule:
foray::core::VulkanResource< VkObjectType::VK_OBJECT_TYPE_SHADER_MODULE > foray::core::ManagedResource foray::NoMoveDefaults

Public Member Functions

 ShaderModule ()=default
 
 ~ShaderModule ()
 
uint64_t CompileFromSource (Context *context, const osi::Utf8Path &path, const ShaderCompilerConfig &config={})
 Loads by compiling from source using the ShaderManager.
 
void LoadFromFile (Context *context, const osi::Utf8Path &path)
 Loads from a spirv file.
 
void LoadFromBinary (Context *context, const std::vector< uint8_t > &binaryBuffer)
 Loads from a binary buffer.
 
void LoadFromBinary (Context *context, const std::vector< uint32_t > &binaryBuffer)
 Loads from a binary buffer.
 
template<size_t ARR_SIZE>
void LoadFromBinary (Context *context, const uint8_t binaryBuffer[ARR_SIZE])
 Loads from a binary buffer.
 
template<size_t ARR_SIZE>
void LoadFromBinary (Context *context, const uint32_t binaryBuffer[ARR_SIZE])
 Loads from a binary buffer.
 
void LoadFromBinary (Context *context, const uint8_t *binaryBuffer, size_t sizeInBytes)
 Loads from a binary buffer.
 
void LoadFromBinary (Context *context, const uint32_t *binaryBuffer, size_t sizeInBytes)
 Loads from a binary buffer.
 
virtual bool Exists () const override
 Return true, if the managed resource is allocated.
 
virtual void Destroy () override
 Destroy the resource.
 
VkPipelineShaderStageCreateInfo GetShaderStageCi (VkShaderStageFlagBits stage, const char *entry="main") const
 Fill a shader stage create info. .sType, .stage, .module, .pName fields are set, remainder default initialized.
 
 operator VkShaderModule () const
 
- Public Member Functions inherited from foray::core::VulkanResource< VkObjectType::VK_OBJECT_TYPE_SHADER_MODULE >
 VulkanResource ()
 
 VulkanResource (std::string_view name)
 
virtual std::string_view GetTypeName () const
 Returns <OBJECT_TYPE> stringified.
 
- Public Member Functions inherited from foray::core::ManagedResource
 ManagedResource ()
 Default constructor registers the resource.
 
 ManagedResource (std::string_view name)
 Registers the resource and sets its name.
 
virtual ~ManagedResource ()
 Unregisters the resource.
 
std::string_view GetName () const
 Return a custom name for the object.
 
virtual void SetName (std::string_view name)
 Set a custom name for the object.
 
std::string Print () const
 Print name and type in one string.
 
- Public Member Functions inherited from foray::NoMoveDefaults
 NoMoveDefaults ()=default
 
 NoMoveDefaults (const NoMoveDefaults &other)=delete
 
 NoMoveDefaults (NoMoveDefaults &&other)=default
 
NoMoveDefaultsoperator= (const NoMoveDefaults &other)=delete
 

Protected Attributes

ContextmContext = nullptr
 
VkShaderModule mShaderModule = nullptr
 
- Protected Attributes inherited from foray::core::ManagedResource
std::string mName
 This objects custom name.
 

Additional Inherited Members

- Static Public Member Functions inherited from foray::core::ManagedResource
static void sPrintAllocatedResources (bool printAsWarning)
 Print a list of all registered existing resources.
 
static const std::unordered_set< ManagedResource * > * GetTotalAllocatedResources ()
 
- Protected Member Functions inherited from foray::core::VulkanResource< VkObjectType::VK_OBJECT_TYPE_SHADER_MODULE >
virtual void SetObjectName (core::Context *context, const void *handle, std::string_view name, bool updateResourceName=true)
 Set the object name. Sets both ManagedResource::mName aswell as vulkan debug object name.
 

Detailed Description

Wraps shader code driver handle (VkShaderModule). See ShaderManager for compiling shaders dynamically.

Constructor & Destructor Documentation

◆ ShaderModule()

foray::core::ShaderModule::ShaderModule ( )
default

◆ ~ShaderModule()

foray::core::ShaderModule::~ShaderModule ( )
inline

Member Function Documentation

◆ CompileFromSource()

uint64_t foray::core::ShaderModule::CompileFromSource ( Context context,
const osi::Utf8Path path,
const ShaderCompilerConfig config = {} 
)

Loads by compiling from source using the ShaderManager.

Parameters
contextRequires ShaderMan, DispatchTable
pathPath of the source file (glsl or hlsl shader source)
configOptional struct for configuring the shader compiler
Returns
The shader compilation key

◆ Destroy()

virtual void foray::core::ShaderModule::Destroy ( )
overridevirtual

Destroy the resource.

Remarks
This method must be callable even if the resource has not been initialized yet. This method must call any Destroy() overloads of child objects and of base classes

Implements foray::core::ManagedResource.

◆ Exists()

virtual bool foray::core::ShaderModule::Exists ( ) const
inlineoverridevirtual

Return true, if the managed resource is allocated.

Example: Vulkan object stored could be nullptr or instantiated

Implements foray::core::ManagedResource.

◆ GetShaderStageCi()

VkPipelineShaderStageCreateInfo foray::core::ShaderModule::GetShaderStageCi ( VkShaderStageFlagBits  stage,
const char *  entry = "main" 
) const

Fill a shader stage create info. .sType, .stage, .module, .pName fields are set, remainder default initialized.

◆ LoadFromBinary() [1/6]

void foray::core::ShaderModule::LoadFromBinary ( Context context,
const std::vector< uint32_t > &  binaryBuffer 
)
inline

Loads from a binary buffer.

Parameters
contextRequires DispatchTable
binaryBufferBinary data

◆ LoadFromBinary() [2/6]

void foray::core::ShaderModule::LoadFromBinary ( Context context,
const std::vector< uint8_t > &  binaryBuffer 
)
inline

Loads from a binary buffer.

Parameters
contextRequires DispatchTable
binaryBufferBinary data

◆ LoadFromBinary() [3/6]

void foray::core::ShaderModule::LoadFromBinary ( Context context,
const uint32_t *  binaryBuffer,
size_t  sizeInBytes 
)

Loads from a binary buffer.

Parameters
contextRequires DispatchTable
binaryBufferBinary data
sizeInBytesSize in bytes

◆ LoadFromBinary() [4/6]

template<size_t ARR_SIZE>
void foray::core::ShaderModule::LoadFromBinary ( Context context,
const uint32_t  binaryBuffer[ARR_SIZE] 
)
inline

Loads from a binary buffer.

Parameters
contextRequires DispatchTable
binaryBufferBinary data
Template Parameters
ARR_SIZEArray size

◆ LoadFromBinary() [5/6]

void foray::core::ShaderModule::LoadFromBinary ( Context context,
const uint8_t *  binaryBuffer,
size_t  sizeInBytes 
)

Loads from a binary buffer.

Parameters
contextRequires DispatchTable
binaryBufferBinary data
sizeInBytesSize in bytes

◆ LoadFromBinary() [6/6]

template<size_t ARR_SIZE>
void foray::core::ShaderModule::LoadFromBinary ( Context context,
const uint8_t  binaryBuffer[ARR_SIZE] 
)
inline

Loads from a binary buffer.

Parameters
contextRequires DispatchTable
binaryBufferBinary data
Template Parameters
ARR_SIZEArray size

◆ LoadFromFile()

void foray::core::ShaderModule::LoadFromFile ( Context context,
const osi::Utf8Path path 
)

Loads from a spirv file.

Parameters
contextRequires DispatchTable
pathSpirv file path (absolute or relative to current working directory)

◆ operator VkShaderModule()

foray::core::ShaderModule::operator VkShaderModule ( ) const

Member Data Documentation

◆ mContext

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

◆ mShaderModule

VkShaderModule foray::core::ShaderModule::mShaderModule = nullptr
protected

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