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
- 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)
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)
BufferBindingInstancefindBinding (const std::string &name)
UniformStructInstancegetUniform (const std::string &name)
BufferBindingInstancegetBinding (const std::string &name)
const SamplerInstanceListgetSamplers () const
const BufferBindingInstanceListgetBufferBindings () const
const UniformStructInstanceListgetUniformStructs () const
SamplerInstancefindSampler (const std::string &name) 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 > >
- 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)
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 Texture2D &texture2D, VkSampler sampler)
BufferBindingInstancegetOrCreateBufferInternal (const std::string &name)
SamplerInstancegetOrCreateSamplerInternal (const std::string &name)
- 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)
- Protected Attributes inherited from BaseMaterialInstance
VkDevice mDevice = nullptr
RenderServicemRenderService = nullptr
BaseMaterialmMaterial = nullptr
BaseMaterialInstanceResourcemResource = nullptr
std::vector< UniformBufferObjectmUniformBufferObjects
std::vector< VkWriteDescriptorSet > mStorageWriteDescriptorSets
std::vector< VkDescriptorBufferInfo > mStorageDescriptors
std::vector< VkWriteDescriptorSet > mSamplerWriteDescriptorSets
std::vector< VkDescriptorImageInfo > mSamplerDescriptors
bool mUniformsCreated = false


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:
Collaboration diagram for ComputeMaterialInstance:

Member Function Documentation

◆ getMaterial() [1/2]

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

◆ getMaterial() [2/2]

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

◆ init()

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

Initializes all runtime structures for ComputeMaterialInstance.