NAP
Public Member Functions | List of all members
ComputeMaterialInstance Class Reference

#include <materialinstance.h>

Public Member Functions

bool init (RenderService &renderService, ComputeMaterialInstanceResource &resource, utility::ErrorState &errorState)
 
ComputeMaterialgetMaterial ()
 
const ComputeMaterialgetMaterial () const
 
glm::uvec3 getWorkGroupSize () const
 
- Public Member Functions inherited from BaseMaterialInstance
virtual UniformStructInstancegetOrCreateUniform (const std::string &name)
 
template<class T >
T * getOrCreateBuffer (const std::string &name)
 
BufferBindingInstancegetOrCreateBuffer (const std::string &name)
 
template<class T >
T * getOrCreateSampler (const std::string &name)
 
SamplerInstancegetOrCreateSampler (const std::string &name)
 
template<class T >
T * getOrCreateSampler (const Sampler &resource)
 
SamplerInstancegetOrCreateSampler (const Sampler &resource)
 
BaseMaterialgetMaterial ()
 
const BaseMaterialgetMaterial () const
 
virtual const DescriptorSetupdate ()
 
- Public Member Functions inherited from UniformContainer
 UniformContainer ()=default
 
virtual ~UniformContainer ()=default
 
 UniformContainer (const UniformContainer &)=delete
 
UniformContaineroperator= (const UniformContainer &)=delete
 
UniformStructInstancefindUniform (const std::string &name) const
 
SamplerInstancefindSampler (const std::string &name) const
 
BufferBindingInstancefindBinding (const std::string &name) const
 
ShaderConstantInstancefindConstant (const std::string &name) const
 
const SamplerInstanceListgetSamplers () const
 
const BufferBindingInstanceListgetBufferBindings () const
 
const ShaderConstantInstanceListgetConstants () const
 
const UniformStructInstanceListgetUniformStructs () const
 

Additional Inherited Members

- Public Types inherited from UniformContainer
using UniformStructInstanceList = std::vector< std::unique_ptr< UniformStructInstance > >
 
using BufferBindingInstanceList = std::vector< std::unique_ptr< BufferBindingInstance > >
 
using SamplerInstanceList = std::vector< std::unique_ptr< SamplerInstance > >
 
using ShaderConstantInstanceList = std::vector< std::unique_ptr< ShaderConstantInstance > >
 
- Protected Member Functions inherited from BaseMaterialInstance
bool initInternal (RenderService &renderService, BaseMaterial &material, BaseMaterialInstanceResource &instanceResource, utility::ErrorState &errorState)
 
void rebuildUBO (UniformBufferObject &ubo, UniformStructInstance *overrideStruct)
 
void onUniformCreated ()
 
void onSamplerChanged (int imageStartIndex, SamplerInstance &samplerInstance, int imageArrayIndex)
 
void onBufferChanged (int storageBufferIndex, BufferBindingInstance &bindingInstance)
 
void updateBuffers (const DescriptorSet &descriptorSet)
 
bool initBuffers (BaseMaterialInstanceResource &resource, utility::ErrorState &errorState)
 
void updateSamplers (const DescriptorSet &descriptorSet)
 
bool initSamplers (BaseMaterialInstanceResource &resource, utility::ErrorState &errorState)
 
void addImageInfo (const Texture &texture, VkSampler sampler)
 
bool initConstants (BaseMaterialInstanceResource &resource, utility::ErrorState &errorState)
 
BufferBindingInstancegetOrCreateBufferInternal (const std::string &name)
 
SamplerInstancegetOrCreateSamplerInternal (const std::string &name, const Sampler *sampler)
 
const ShaderStageConstantMapgetShaderStageConstantMap () const
 
ShaderConstantHash getConstantHash () const
 
- Protected Member Functions inherited from UniformContainer
UniformStructInstancecreateUniformRootStruct (const ShaderVariableStructDeclaration &declaration, const UniformCreatedCallback &uniformCreatedCallback)
 
BufferBindingInstanceaddBindingInstance (std::unique_ptr< BufferBindingInstance > instance)
 
SamplerInstanceaddSamplerInstance (std::unique_ptr< SamplerInstance > instance)
 
ShaderConstantInstanceaddConstantInstance (std::unique_ptr< ShaderConstantInstance > instance)
 
- Protected Attributes inherited from BaseMaterialInstance
VkDevice mDevice = nullptr
 
RenderServicemRenderService = nullptr
 
BaseMaterialmMaterial = nullptr
 
BaseMaterialInstanceResourcemResource = nullptr
 
DescriptorSetCachemDescriptorSetCache
 
std::vector< UniformBufferObjectmUniformBufferObjects
 
std::vector< VkWriteDescriptorSet > mStorageWriteDescriptorSets
 
std::vector< VkDescriptorBufferInfo > mStorageDescriptors
 
std::vector< VkWriteDescriptorSet > mSamplerWriteDescriptorSets
 
std::vector< VkDescriptorImageInfo > mSamplerDescriptors
 
ShaderStageConstantMap mShaderStageConstantMap
 
ShaderConstantHash mConstantHash
 
bool mUniformsCreated = false
 

Description

To run a compute shader, you must use a ComputeMaterialInstance. This material contains the runtime resources that are bound to shader variable inputs in your compute shader. ComputeMaterialInstance is intended to be used as a property in ComputeComponents. It must be initialized based on a ComputeMaterialInstanceResource object to fill its runtime data. init() must be called from the ComponentInstance's init() function. Before drawing, make sure to call update() to update the uniforms and samplers. A descriptorset will be returned that can be used to issue the Vulkan draw call.

Multiple ComputeMaterialInstances can share a single ComputeMaterial and a single ComputeMaterialInstance can override ComputeMaterial properties on a per-instance basis. This means that you can set uniform, buffer or texture data on ComputeMaterial level, which means that, as long as the property isn't overridden, you will set it for all ComputeMaterialInstances in one go. If you set a property on ComputeMaterialInstance level, you will set it only for that ComputeMaterialInstance.

It is also possible to set uniform, buffer or texture state on a single MaterialInstance multiple times per frame. When multiple draws are performed with the frame, the state at the point of draw will be used.

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

Member Function Documentation

◆ getMaterial() [1/2]

ComputeMaterial& getMaterial ( )
Returns
material that this instance is overriding.

◆ getMaterial() [2/2]

const ComputeMaterial& getMaterial ( ) const
Returns
material that this instance is overriding

◆ getWorkGroupSize()

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

◆ init()

bool init ( RenderService renderService,
ComputeMaterialInstanceResource resource,
utility::ErrorState errorState 
)

Initializes all runtime structures for ComputeMaterialInstance.