LiteFX 0.4.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
LiteFX::Rendering::IShaderProgram Class Referenceabstract

The interface for a shader program. More...

#include <rendering_api.hpp>

Inherits LiteFX::SharedObject.

Inherited by LiteFX::Rendering::ShaderProgram< DirectX12ShaderModule >, LiteFX::Rendering::ShaderProgram< VulkanShaderModule >, and LiteFX::Rendering::ShaderProgram< TShaderModule >.

Public Member Functions

 ~IShaderProgram () noexcept override=default
 
 IShaderProgram (const IShaderProgram &)=delete
 
 IShaderProgram (IShaderProgram &&) noexcept=delete
 
auto operator= (const IShaderProgram &)=delete
 
auto operator= (IShaderProgram &&) noexcept=delete
 
const IShaderModuleoperator[] (StringView name) const
 Returns a pointer to shader module based on its (case-sensitive) name.
 
bool contains (StringView name) const
 Returns true, if the program contains a shader module with the provided name or file name and false otherwise.
 
bool contains (const IShaderModule &module) const
 Returns true, if the program contains the provided shader module and false otherwise.
 
Enumerable< const IShaderModule & > modules () const
 Returns the modules, the shader program is build from.
 
SharedPtr< IPipelineLayoutreflectPipelineLayout () const
 Uses shader reflection to extract the pipeline layout of a shader. May not be available in all backends.
 
ShaderRecordCollection buildShaderRecordCollection () const noexcept
 Builds a shader record collection based on the current shader program.
 
- Public Member Functions inherited from LiteFX::SharedObject
virtual ~SharedObject () noexcept=default
 Destroys the shared object.
 
template<typename TSelf >
auto shared_from_this (this TSelf &&self) noexcept
 Returns a shared pointer to the current object instance.
 
template<typename TSelf >
auto weak_from_this (this TSelf &&self) noexcept -> WeakPtr< std::remove_reference_t< TSelf > >
 Returns a weak pointer to the current object instance.
 

Protected Member Functions

 IShaderProgram () noexcept=default
 
- Protected Member Functions inherited from LiteFX::SharedObject
 SharedObject () noexcept=default
 Initializes a new shared object.
 
 SharedObject (SharedObject &&) noexcept=default
 
 SharedObject (const SharedObject &)=default
 
SharedObjectoperator= (SharedObject &&) noexcept=default
 
SharedObjectoperator= (const SharedObject &)=default
 

Additional Inherited Members

- Static Protected Member Functions inherited from LiteFX::SharedObject
template<typename T , typename... TArgs>
static auto create (TArgs &&... args) -> SharedPtr< T >
 Generic factory method used to create instances of the shared object.
 

Detailed Description

The interface for a shader program.

A shader program differs in it's functionality as well as the contained shader modules, depending on the pipeline type it gets assigned to. A shader program can be of any of the following types:

  • Rasterization: A rasterization pipeline is a traditional pipeline, that can contain at maximum one module of the following stages: Vertex, Tessellation Control, Tessellation Evaluation, Geometry, Fragment. A vertex and fragment shader are required for rasterization programs.
  • Mesh shading: If mesh shader support is enabled (through the device feature GraphicsDeviceFeatures::MeshShaders), a mesh shading program can contain at maximum one module of the following stages: Task, Mesh, Fragment. A mesh and fragment shader are required for a mesh shading program.
  • Compute: A compute shader program must only contain a single module for the Compute stage.
  • Ray-tracing: If ray tracing support is enabled (through the device feature GraphicsDeviceFeatures::RayTracing), a ray tracing program can contain modules of the following stages: Ray Generation, Any Hit, Closest Hit, Intersection, Miss, Callable. There must be exactly one Ray Generation module. All other modules can occur multiple times. To build a ray tracing pipeline, all shaders should be added to a single shader program, which is then passed to the pipeline during creation.

Shaders from different program types must not be mixed. For example, it is not valid to add a compute module to a rasterization program. The only exception to this is the ShaderStage::Fragment module, which can be added to a mesh pipeline, as well as a rasterization pipeline.

Constructor & Destructor Documentation

◆ IShaderProgram() [1/3]

LiteFX::Rendering::IShaderProgram::IShaderProgram ( )
protecteddefaultnoexcept

◆ ~IShaderProgram()

LiteFX::Rendering::IShaderProgram::~IShaderProgram ( )
overridedefaultnoexcept

◆ IShaderProgram() [2/3]

LiteFX::Rendering::IShaderProgram::IShaderProgram ( const IShaderProgram & )
delete

◆ IShaderProgram() [3/3]

LiteFX::Rendering::IShaderProgram::IShaderProgram ( IShaderProgram && )
deletenoexcept

Member Function Documentation

◆ buildShaderRecordCollection()

ShaderRecordCollection LiteFX::Rendering::IShaderProgram::buildShaderRecordCollection ( ) const
inlinenodiscardnoexcept

Builds a shader record collection based on the current shader program.

Returns
The shader record collection instance.

◆ contains() [1/2]

bool LiteFX::Rendering::IShaderProgram::contains ( const IShaderModule & module) const
inline

Returns true, if the program contains the provided shader module and false otherwise.

Parameters
moduleThe module to look up in the shader program.
Returns
true, if the program contains the provided shader module and false otherwise.

◆ contains() [2/2]

bool LiteFX::Rendering::IShaderProgram::contains ( StringView name) const
inline

Returns true, if the program contains a shader module with the provided name or file name and false otherwise.

Parameters
nameThe case-sensitive name or file name of the shader module to look up.
Returns
true, if the program contains a shader module with the provided name or file name and false otherwise.

◆ modules()

Enumerable< const IShaderModule & > LiteFX::Rendering::IShaderProgram::modules ( ) const
inline

Returns the modules, the shader program is build from.

Returns
The modules, the shader program is build from.

◆ operator=() [1/2]

auto LiteFX::Rendering::IShaderProgram::operator= ( const IShaderProgram & )
delete

◆ operator=() [2/2]

auto LiteFX::Rendering::IShaderProgram::operator= ( IShaderProgram && )
deletenoexcept

◆ operator[]()

const IShaderModule * LiteFX::Rendering::IShaderProgram::operator[] ( StringView name) const
inline

Returns a pointer to shader module based on its (case-sensitive) name.

Parameters
nameThe name or file name of the shader module.
Returns
A pointer to the shader module, or nullptr, if it was not found.

◆ reflectPipelineLayout()

SharedPtr< IPipelineLayout > LiteFX::Rendering::IShaderProgram::reflectPipelineLayout ( ) const
inline

Uses shader reflection to extract the pipeline layout of a shader. May not be available in all backends.

Note that shader reflection may not yield different results than you would expect, especially when using DirectX 12. For more information on how to use shader reflection and how to write portable shaders, refer to the shader development guide in the wiki.

In particular, shader reflection is not able to restore:

  • Input attachments in DirectX. Instead, input attachments are treated as DescriptorType::Texture. This is usually not a problem, since DirectX does not have a concept of render pass outputs/inputs anyway. However, keep this in mind, if you want to filter descriptors based on their type, for example. Immutable sampler states in Vulkan. Those are only restored in DirectX, if an explicit root signature has been provided. For this reason, it is best not to use them, if you want to use shader reflection.
Returns
The pipeline layout extracted from shader reflection.