Nameless Engine
Loading...
Searching...
No Matches
ne::ComputeShaderInterface Class Referenceabstract

#include <ComputeShaderInterface.h>

Inheritance diagram for ne::ComputeShaderInterface:
ne::GlslComputeShaderInterface ne::HlslComputeShaderInterface

Public Member Functions

 ComputeShaderInterface (const ComputeShaderInterface &)=delete
 
ComputeShaderInterfaceoperator= (const ComputeShaderInterface &)=delete
 
virtual std::optional< ErrorbindResource (GpuResource *pResource, const std::string &sShaderResourceName, ComputeResourceUsage usage, bool bUpdateOnlyCurrentFrameResourceDescriptors=false)=0
 
void submitForExecution (unsigned int iThreadGroupCountX, unsigned int iThreadGroupCountY, unsigned int iThreadGroupCountZ)
 
ComputeExecutionGroup getExecutionGroup () const
 
ComputeExecutionStage getExecutionStage () const
 
std::string getComputeShaderName () const
 
PipelinegetUsedPipeline () const
 

Static Public Member Functions

static std::variant< std::unique_ptr< ComputeShaderInterface >, ErrorcreateUsingGraphicsQueue (Renderer *pRenderer, const std::string &sCompiledComputeShaderName, ComputeExecutionStage executionStage, ComputeExecutionGroup executionGroup=ComputeExecutionGroup::FIRST)
 

Protected Member Functions

 ComputeShaderInterface (Renderer *pRenderer, const std::string &sComputeShaderName, ComputeExecutionStage executionStage, ComputeExecutionGroup executionGroup)
 
RenderergetRenderer ()
 
PipelinegetPipeline () const
 
unsigned int getThreadGroupCountX () const
 
unsigned int getThreadGroupCountY () const
 
unsigned int getThreadGroupCountZ () const
 

Static Protected Member Functions

static std::variant< std::unique_ptr< ComputeShaderInterface >, ErrorcreateRenderSpecificInterface (Renderer *pRenderer, const std::string &sComputeShaderName, ComputeExecutionStage executionStage, ComputeExecutionGroup executionGroup)
 
static std::unique_ptr< ComputeShaderInterfacecreatePartiallyInitializedRenderSpecificInterface (Renderer *pRenderer, const std::string &sComputeShaderName, ComputeExecutionStage executionStage, ComputeExecutionGroup executionGroup)
 

Private Attributes

RendererpRenderer = nullptr
 
PipelineSharedPtr pPipeline
 
unsigned int iThreadGroupCountX = 0
 
unsigned int iThreadGroupCountY = 0
 
unsigned int iThreadGroupCountZ = 0
 
const ComputeExecutionStage executionStage = ComputeExecutionStage::AFTER_DEPTH_PREPASS
 
const ComputeExecutionGroup executionGroup = ComputeExecutionGroup::FIRST
 
const std::string sComputeShaderName
 

Detailed Description

Interface to configure and run a compute shader.

Constructor & Destructor Documentation

◆ ComputeShaderInterface()

ne::ComputeShaderInterface::ComputeShaderInterface ( Renderer pRenderer,
const std::string &  sComputeShaderName,
ComputeExecutionStage  executionStage,
ComputeExecutionGroup  executionGroup 
)
protected

Initializes everything except for pPipeline which is expected to be initialized right after object creation.

Parameters
pRendererUsed renderer.
sComputeShaderNameName of the compiled compute shader to use.
executionStageDetermines when the shader will be executed.
executionGroupExecution order.

Member Function Documentation

◆ bindResource()

virtual std::optional< Error > ne::ComputeShaderInterface::bindResource ( GpuResource pResource,
const std::string &  sShaderResourceName,
ComputeResourceUsage  usage,
bool  bUpdateOnlyCurrentFrameResourceDescriptors = false 
)
pure virtual

Binds the specified resource to be available in compute shaders.

Warning
This overload is used in cases where you cannot transfer resource ownership to the compute shader interface. In this case you must guarantee that the resource will not be deleted while this compute shader interface exists and while the GPU is processing this compute shader.
Parameters
pResourceResource to bind to compute shader.
sShaderResourceNameResource name from shader.
usageResource usage.
bUpdateOnlyCurrentFrameResourceDescriptorsSpecify true if you guarantee that you will bind a different GPU resource on the next frame, specify false if you are not sure if you will rebind the resource on the next frame or not. When true is specified only descriptors of the current frame resource will be updated (because descriptors of other frame resources might be in use and it's invalid to update them), when false descriptors of all frame resources will be updated.
Returns
Error if something went wrong.

Implemented in ne::GlslComputeShaderInterface, and ne::HlslComputeShaderInterface.

◆ createPartiallyInitializedRenderSpecificInterface()

std::unique_ptr< ComputeShaderInterface > ne::ComputeShaderInterface::createPartiallyInitializedRenderSpecificInterface ( Renderer pRenderer,
const std::string &  sComputeShaderName,
ComputeExecutionStage  executionStage,
ComputeExecutionGroup  executionGroup 
)
staticprotected

Creates a new interface and initializes everything except for pPipeline which is expected to be initialized right after object creation.

Parameters
pRendererUsed renderer.
sComputeShaderNameName of the compiled compute shader to use.
executionStageDetermines when the shader will be executed.
executionGroupDetermines execution group of this shader where shaders of the first group will be executed before shaders from the second group and so on.
Returns
Created interface.

◆ createRenderSpecificInterface()

std::variant< std::unique_ptr< ComputeShaderInterface >, Error > ne::ComputeShaderInterface::createRenderSpecificInterface ( Renderer pRenderer,
const std::string &  sComputeShaderName,
ComputeExecutionStage  executionStage,
ComputeExecutionGroup  executionGroup 
)
staticprotected

Creates a new fully initialized render-specific compute shader interface.

Parameters
pRendererUsed renderer.
sComputeShaderNameName of the compiled compute shader to use.
executionStageDetermines when the shader will be executed.
executionGroupDetermines execution group of this shader where shaders of the first group will be executed before shaders from the second group and so on.
Returns
Error if something went wrong, otherwise created interface.

◆ createUsingGraphicsQueue()

std::variant< std::unique_ptr< ComputeShaderInterface >, Error > ne::ComputeShaderInterface::createUsingGraphicsQueue ( Renderer pRenderer,
const std::string &  sCompiledComputeShaderName,
ComputeExecutionStage  executionStage,
ComputeExecutionGroup  executionGroup = ComputeExecutionGroup::FIRST 
)
static

Creates a new render-specific interface to a compute shader that will be run in the graphics queue (the same queue that the rendering uses), this compute shader will run synchronously to the rendering operations (on the GPU).

Remarks
You might want to run your compute shader in the graphics queue if you need to make sure that some rendering operation(s) are run strictly before or after the compute shader (for example if you need to calculate some data that the rendering will use then use the graphics queue).
Parameters
pRendererUsed renderer.
sCompiledComputeShaderNameName of the compiled compute shader to later run.
executionStageDetermines when the shader will be executed.
executionGroupDetermines execution group of this shader where shaders of the first group will be executed before shaders from the second group and so on.
Returns
Error if something went wrong, otherwise created interface.

◆ getComputeShaderName()

std::string ne::ComputeShaderInterface::getComputeShaderName ( ) const

Returns name of the compiled compute shader that this interface uses.

Returns
Compute shader name.

◆ getExecutionGroup()

ComputeExecutionGroup ne::ComputeShaderInterface::getExecutionGroup ( ) const

Returns execution group of this shader where shaders of the first group will be executed before shaders from the second group and so on.

Returns
Execution group.

◆ getExecutionStage()

ComputeExecutionStage ne::ComputeShaderInterface::getExecutionStage ( ) const

Returns execution stage of this shader.

Returns
Execution stage.

◆ getPipeline()

Pipeline * ne::ComputeShaderInterface::getPipeline ( ) const
protected

Returns used compute pipeline.

Returns
Pipeline.

◆ getRenderer()

Renderer * ne::ComputeShaderInterface::getRenderer ( )
protected

Returns used renderer.

Warning
Do not delete (free) returned pointer.
Returns
Non-owning pointer to the renderer.

◆ getThreadGroupCountX()

unsigned int ne::ComputeShaderInterface::getThreadGroupCountX ( ) const
inlineprotected

Returns the number of thread groups dispatched in the X direction.

Returns
Group count.

◆ getThreadGroupCountY()

unsigned int ne::ComputeShaderInterface::getThreadGroupCountY ( ) const
inlineprotected

Returns the number of thread groups dispatched in the Y direction.

Returns
Group count.

◆ getThreadGroupCountZ()

unsigned int ne::ComputeShaderInterface::getThreadGroupCountZ ( ) const
inlineprotected

Returns the number of thread groups dispatched in the Z direction.

Returns
Group count.

◆ getUsedPipeline()

Pipeline * ne::ComputeShaderInterface::getUsedPipeline ( ) const

Returns compute pipeline that this shader is referencing.

Returns
Compute pipeline (always valid pointer unless this object is being destroyed).

◆ submitForExecution()

void ne::ComputeShaderInterface::submitForExecution ( unsigned int  iThreadGroupCountX,
unsigned int  iThreadGroupCountY,
unsigned int  iThreadGroupCountZ 
)

Adds this compute shader to the GPU queue to be executed.

Remarks
This function queues the shader to be executed only once, if you want to queue this shader again you need to call this function later (if using graphics queue - after a new frame is drawn, otherwise later when you need it). Calling this function again right after calling it the first time will do nothing if graphics queue is used but override the specified thread group counts, if compute queue is used it will queue it again (so it will be executed twice).
Parameters
iThreadGroupCountXThe number of thread groups dispatched in the X direction.
iThreadGroupCountYThe number of thread groups dispatched in the Y direction.
iThreadGroupCountZThe number of thread groups dispatched in the Z direction.

Member Data Documentation

◆ executionGroup

const ComputeExecutionGroup ne::ComputeShaderInterface::executionGroup = ComputeExecutionGroup::FIRST
private

Describes order of execution.

◆ executionStage

const ComputeExecutionStage ne::ComputeShaderInterface::executionStage = ComputeExecutionStage::AFTER_DEPTH_PREPASS
private

Describes when shader should be executed.

◆ iThreadGroupCountX

unsigned int ne::ComputeShaderInterface::iThreadGroupCountX = 0
private

The number of thread groups dispatched in the X direction.

◆ iThreadGroupCountY

unsigned int ne::ComputeShaderInterface::iThreadGroupCountY = 0
private

The number of thread groups dispatched in the Y direction.

◆ iThreadGroupCountZ

unsigned int ne::ComputeShaderInterface::iThreadGroupCountZ = 0
private

The number of thread groups dispatched in the Z direction.

◆ pPipeline

PipelineSharedPtr ne::ComputeShaderInterface::pPipeline
private

Compute pipeline that this interface is using.

◆ pRenderer

Renderer* ne::ComputeShaderInterface::pRenderer = nullptr
private

Do not delete (free) this pointer. A non-owning pointer to the renderer.

◆ sComputeShaderName

const std::string ne::ComputeShaderInterface::sComputeShaderName
private

Name of the compiled compute shader to run.


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