NAP
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ComputeComponentInstance Class Reference

#include <computecomponent.h>

Public Member Functions

 ComputeComponentInstance (EntityInstance &entity, Component &resource)
 
virtual bool init (utility::ErrorState &errorState) override
 
void compute (VkCommandBuffer commandBuffer)
 
void compute (VkCommandBuffer commandBuffer, uint numInvocations)
 
void enable (bool enable)
 
bool isEnabled () const
 
ComputeMaterialInstancegetMaterialInstance ()
 
glm::uvec3 getWorkGroupSize () const
 
void setInvocations (uint numInvocations)
 
uint getInvocations () const
 
- Public Member Functions inherited from ComponentInstance
 ComponentInstance (EntityInstance &entity, Component &resource)
 
virtual void update (double deltaTime)
 
nap::EntityInstancegetEntityInstance () const
 
nap::ComponentgetComponent () const
 
template<typename T >
T * getComponent () const
 
virtual bool init (utility::ErrorState &errorState)
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Protected Member Functions

virtual void onCompute (VkCommandBuffer commandBuffer, uint numInvocations)
 
void insertBarriers (VkCommandBuffer commandBuffer)
 

Protected Attributes

RenderServicemRenderService = nullptr
 
ComputeMaterialInstance mComputeMaterialInstance
 
uint mInvocations = 1
 
bool mEnabled = true
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Description

Instance part of Compute Component

The compute component represents a general-purpose computation that mutates one or more storage buffers. Internally, a ComputeComponentInstance manages a ComputeMaterialInstance and can caches the desired invocation count for repeated use.

ComputeComponentInstance::compute() dispatches the compute shader with the given compute command buffer. Multiple compute calls may be stacked and are implicitly synchronized by the resource usage and access types bound to the compute material's descriptor sets.

This component can only be used when 'Compute' is available and enabled in the RenderService, otherwise initialization fails. To enable Compute, make sure 'Compute' is marked under the 'RequiredQueues' in the RenderServiceConfiguration.

Inheritance diagram for ComputeComponentInstance:
[legend]
Collaboration diagram for ComputeComponentInstance:
[legend]

Constructor & Destructor Documentation

◆ ComputeComponentInstance()

ComputeComponentInstance ( EntityInstance entity,
Component resource 
)

Member Function Documentation

◆ compute() [1/2]

void compute ( VkCommandBuffer  commandBuffer)

Called by the renderservice, calls onCompute() with the number of invocations set in this instance

Parameters
commandBufferactive command buffer

◆ compute() [2/2]

void compute ( VkCommandBuffer  commandBuffer,
uint  numInvocations 
)

Called by the renderservice, calls onCompute() with the given number of invocations

Parameters
commandBufferactive command buffer
numInvocationsthe number of compute shader invocations

◆ enable()

void enable ( bool  enable)

Toggles whether this component is enabled.

Parameters
enableif this object should be enabled or not

◆ getInvocations()

uint getInvocations ( ) const

Returns the number of compute shader invocations for this instance

◆ getMaterialInstance()

ComputeMaterialInstance& getMaterialInstance ( )
Returns
compute program.

◆ getWorkGroupSize()

glm::uvec3 getWorkGroupSize ( ) const
Returns
the local workgroup size

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initializes the compute instance.

Parameters
errorStatecontains the error if initialization fails
Returns
if initialization succeeded.

Reimplemented from ComponentInstance.

◆ insertBarriers()

void insertBarriers ( VkCommandBuffer  commandBuffer)
protected

Inserts memory barriers based on usage properties of the bufferdata. Only does so for storage buffers which are, outside color and depth attachments in render passes, the only resources that can currently be written to. Makes the assumption that the data will be read in a subsequent render pass in the current frame.

◆ isEnabled()

bool isEnabled ( ) const
Returns
if the object is enabled for computation

◆ onCompute()

virtual void onCompute ( VkCommandBuffer  commandBuffer,
uint  numInvocations 
)
protectedvirtual

Dispatches the compute shader using the given command buffer, number of invocations and the bound computematerialinstance

Parameters
commandBufferactive command buffer
numInvocationsthe number of compute shader invocations

◆ setInvocations()

void setInvocations ( uint  numInvocations)

Sets the number of compute shader invocations for this instance

Parameters
numInvocationsthe number of compute shader invocations

Member Data Documentation

◆ mComputeMaterialInstance

ComputeMaterialInstance mComputeMaterialInstance
protected

◆ mEnabled

bool mEnabled = true
protected

◆ mInvocations

uint mInvocations = 1
protected

◆ mRenderService

RenderService* mRenderService = nullptr
protected