Raven Engine v0.1
A modern 3D Game Engine
Loading...
Searching...
No Matches
Raven::VulkanShader Class Reference

Represents a Vulkan shader, managing modules, reflection data, and descriptor sets. More...

#include <VulkanShader.h>

Inherits Raven::Shader.

Classes

struct  ReflectionData
 Reflection data extracted from the shader code. More...

Public Member Functions

ILLUMINE_API VulkanShader (const std::string &filepath, bool forceCompile)
 Loads and creates a VulkanShader from a file.
ILLUMINE_API void Release () override
 Cleans up Vulkan resources on destruction.
const std::unordered_map< ShaderStage, Ref< ShaderModuleHandle > > & GetShaderModules () const override
 Returns the Vulkan shader modules mapped by shader stage.
ILLUMINE_API const std::string & GetName () const override
 Gets the shader's human-readable name.
const std::string & GetFilePath () const override
 Gets the file path from which the shader was loaded.
const NodeStrMap< ShaderBuffer > & GetShaderBuffers () const
 Retrieves constant buffers declared in the shader.
const NodeStrMap< ShaderResourceDeclaration > & GetResources () const
 Retrieves shader resource declarations.
const std::vector< ShaderResource::PushConstantRange > & GetPushConstantRanges () const
 Gets the push constant ranges defined in the shader.
const std::vector< ShaderResource::ShaderDescriptorSet > & GetShaderDescriptorSets () const
 Retrieves all descriptor sets used by the shader.
VkWriteDescriptorSet & GetWriteDescriptor (u32 set, const std::string &name)
 Accesses a VkWriteDescriptorSet for a given descriptor set index and resource name.
VkDescriptorSetLayout GetDescriptorSetLayout (u32 set)
 Gets the Vulkan descriptor set layout for a given set index.
std::vector< VkDescriptorSet > GetDescriptorSets () const
 Retrieves all allocated Vulkan descriptor sets.
VkDescriptorSet GetDescriptorSet (u32 set) const
 Gets the Vulkan descriptor set for a given index.
const std::vector< VkDescriptorSetLayout > & GetAllDescriptorLayouts ()
 Returns all descriptor set layouts.
ILLUMINE_API ShaderResource::UniformBufferGetUniformBuffer (const u32 binding=0, const u32 set=0)
 Gets a reference to a uniform buffer by binding and set indices.
u32 GetUniformBufferCount (u32 set=0)
 Returns the number of uniform buffers in a descriptor set.
ILLUMINE_API Expected< std::pair< u32, u32 > > FindUniformBinding (const std::string &name) const
 Finds the descriptor set and binding index of a uniform buffer by name.
ILLUMINE_API Expected< std::pair< u32, u32 > > FindImageBinding (const std::string &name) const
 Finds the descriptor set and binding index of an image resource by name.
ILLUMINE_API Expected< std::pair< u32, u32 > > FindSamplerBinding (const std::string &name) const
 Finds the descriptor set and binding index of a sampler resource by name.
ILLUMINE_API Expected< std::pair< u32, u32 > > FindStorageBinding (const std::string &name) const
 Finds the descriptor set and binding index of a storage buffer by name.
ILLUMINE_API bool HasBinding (u32 setIndex, const std::string &name) const
 Checks if a binding with the specified name exists in a set.
Public Member Functions inherited from Raven::Shader
virtual ~Shader ()=default
Public Member Functions inherited from Raven::RefCounted
 RefCounted ()
virtual ~RefCounted ()
void IncRefCount ()
void DecRefCount ()
u32 GetRefCount () const

Friends

class VulkanShaderCompiler

Additional Inherited Members

Static Public Member Functions inherited from Raven::Shader
static Ref< ShaderCreate (const std::string &filepath, bool forceCompile=false)
 Factory method to create a shader from a file.

Detailed Description

Represents a Vulkan shader, managing modules, reflection data, and descriptor sets.

Loads and compiles Vulkan shaders from file, holds SPIR-V binaries, reflection data (uniforms, resources), descriptor set layouts, and Vulkan descriptor sets.

Constructor & Destructor Documentation

◆ VulkanShader()

Raven::VulkanShader::VulkanShader ( const std::string & filepath,
bool forceCompile )

Loads and creates a VulkanShader from a file.

Parameters
filepathPath to the shader source or SPIR-V file.
forceCompileForces shader recompilation (if supported).

Member Function Documentation

◆ FindImageBinding()

Expected< std::pair< u32, u32 > > Raven::VulkanShader::FindImageBinding ( const std::string & name) const

Finds the descriptor set and binding index of an image resource by name.

Parameters
nameThe image resource name.
Returns
Expected pair of <set, binding> or error if not found.

◆ FindSamplerBinding()

Expected< std::pair< u32, u32 > > Raven::VulkanShader::FindSamplerBinding ( const std::string & name) const

Finds the descriptor set and binding index of a sampler resource by name.

Parameters
nameThe sampler resource name.
Returns
Expected pair of <set, binding> or error if not found.

◆ FindStorageBinding()

Expected< std::pair< u32, u32 > > Raven::VulkanShader::FindStorageBinding ( const std::string & name) const

Finds the descriptor set and binding index of a storage buffer by name.

Parameters
nameThe storage buffer name.
Returns
Expected pair of <set, binding> or error if not found.

◆ FindUniformBinding()

Expected< std::pair< u32, u32 > > Raven::VulkanShader::FindUniformBinding ( const std::string & name) const

Finds the descriptor set and binding index of a uniform buffer by name.

Parameters
nameThe uniform buffer name.
Returns
Expected pair of <set, binding> or error if not found.

◆ GetAllDescriptorLayouts()

const std::vector< VkDescriptorSetLayout > & Raven::VulkanShader::GetAllDescriptorLayouts ( )
inline

Returns all descriptor set layouts.

Returns
Vector of VkDescriptorSetLayout handles.

◆ GetDescriptorSet()

VkDescriptorSet Raven::VulkanShader::GetDescriptorSet ( u32 set) const
inline

Gets the Vulkan descriptor set for a given index.

Parameters
setThe descriptor set index.
Returns
VkDescriptorSet handle.

◆ GetDescriptorSetLayout()

VkDescriptorSetLayout Raven::VulkanShader::GetDescriptorSetLayout ( u32 set)
inline

Gets the Vulkan descriptor set layout for a given set index.

Parameters
setThe descriptor set index.
Returns
VkDescriptorSetLayout handle.

◆ GetDescriptorSets()

std::vector< VkDescriptorSet > Raven::VulkanShader::GetDescriptorSets ( ) const
inline

Retrieves all allocated Vulkan descriptor sets.

Returns
Vector of VkDescriptorSet handles.

◆ GetFilePath()

const std::string & Raven::VulkanShader::GetFilePath ( ) const
inlineoverridevirtual

Gets the file path from which the shader was loaded.

Returns
File path string.

Implements Raven::Shader.

◆ GetName()

const std::string & Raven::VulkanShader::GetName ( ) const
overridevirtual

Gets the shader's human-readable name.

Returns
Shader name string.

Implements Raven::Shader.

◆ GetPushConstantRanges()

const std::vector< ShaderResource::PushConstantRange > & Raven::VulkanShader::GetPushConstantRanges ( ) const
inline

Gets the push constant ranges defined in the shader.

Returns
Vector of push constant ranges.

◆ GetResources()

const NodeStrMap< ShaderResourceDeclaration > & Raven::VulkanShader::GetResources ( ) const
inline

Retrieves shader resource declarations.

Returns
Map of resource names to ShaderResourceDeclaration.

◆ GetShaderBuffers()

const NodeStrMap< ShaderBuffer > & Raven::VulkanShader::GetShaderBuffers ( ) const
inline

Retrieves constant buffers declared in the shader.

Returns
Map of constant buffer names to ShaderBuffer data.

◆ GetShaderDescriptorSets()

const std::vector< ShaderResource::ShaderDescriptorSet > & Raven::VulkanShader::GetShaderDescriptorSets ( ) const
inline

Retrieves all descriptor sets used by the shader.

Returns
Vector of shader descriptor sets.

◆ GetShaderModules()

const std::unordered_map< ShaderStage, Ref< ShaderModuleHandle > > & Raven::VulkanShader::GetShaderModules ( ) const
inlineoverridevirtual

Returns the Vulkan shader modules mapped by shader stage.

Returns
Map of ShaderStage to ShaderModuleHandle reference.

Implements Raven::Shader.

◆ GetUniformBuffer()

ShaderResource::UniformBuffer & Raven::VulkanShader::GetUniformBuffer ( const u32 binding = 0,
const u32 set = 0 )

Gets a reference to a uniform buffer by binding and set indices.

Parameters
bindingThe binding index within the descriptor set.
setThe descriptor set index.
Returns
Reference to the uniform buffer resource.

◆ GetUniformBufferCount()

u32 Raven::VulkanShader::GetUniformBufferCount ( u32 set = 0)
inline

Returns the number of uniform buffers in a descriptor set.

Parameters
setThe descriptor set index.
Returns
Number of uniform buffers.

◆ GetWriteDescriptor()

VkWriteDescriptorSet & Raven::VulkanShader::GetWriteDescriptor ( u32 set,
const std::string & name )
inline

Accesses a VkWriteDescriptorSet for a given descriptor set index and resource name.

Parameters
setThe descriptor set index.
nameThe resource name within the descriptor set.
Returns
Reference to the Vulkan write descriptor set.

◆ HasBinding()

bool Raven::VulkanShader::HasBinding ( u32 setIndex,
const std::string & name ) const

Checks if a binding with the specified name exists in a set.

Parameters
setIndexset to look at
nameThe name of the Uniform in the set
Returns
true if the uniform exists, false if not

◆ Release()

void Raven::VulkanShader::Release ( )
overridevirtual

Cleans up Vulkan resources on destruction.

Implements Raven::Shader.

◆ VulkanShaderCompiler

friend class VulkanShaderCompiler
friend

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