NAP
computecomponent.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "renderservice.h"
9 #include "materialinstance.h"
10 #include "shadervariabledeclarations.h"
11 
12 // External Includes
13 #include <nap/resourceptr.h>
14 #include <component.h>
15 
16 namespace nap
17 {
18  // Forward Declares
19  class ComputeComponentInstance;
20 
36  class NAPAPI ComputeComponent : public Component
37  {
38  RTTI_ENABLE(Component)
39  DECLARE_COMPONENT(ComputeComponent, ComputeComponentInstance)
40  public:
42  uint mInvocations = 1;
43  };
44 
45 
62  {
63  RTTI_ENABLE(ComponentInstance)
64  public:
66 
72  virtual bool init(utility::ErrorState& errorState) override;
73 
78  void compute(VkCommandBuffer commandBuffer);
79 
85  void compute(VkCommandBuffer commandBuffer, uint numInvocations);
86 
90  ComputeMaterialInstance& getMaterialInstance() { return mComputeMaterialInstance; }
91 
95  glm::u32vec3 getWorkGroupSize() const { return mComputeMaterialInstance.getMaterial().getShader().getWorkGroupSize(); }
96 
101  void setInvocations(uint numInvocations) { mInvocations = numInvocations; }
102 
106  uint getInvocations() const { return mInvocations; }
107 
108  protected:
109 
115  virtual void onCompute(VkCommandBuffer commandBuffer, uint numInvocations);
116 
122  void insertBarriers(VkCommandBuffer commandBuffer);
123 
124  RenderService* mRenderService = nullptr;
126  uint mInvocations = 1;
127  };
128 }
nap::uint
unsigned int uint
Definition: numeric.h:23
nap::ComputeMaterialInstanceResource
Definition: materialinstance.h:54
nap::ComputeComponent
Definition: computecomponent.h:36
nap::ComputeComponentInstance::setInvocations
void setInvocations(uint numInvocations)
Definition: computecomponent.h:101
nap::utility::ErrorState
Definition: errorstate.h:19
nap::ComputeComponentInstance::getInvocations
uint getInvocations() const
Definition: computecomponent.h:106
nap::ComputeComponentInstance::getWorkGroupSize
glm::u32vec3 getWorkGroupSize() const
Definition: computecomponent.h:95
nap::ComputeComponentInstance
Definition: computecomponent.h:61
nap::RenderService
Definition: renderservice.h:268
nap::EntityInstance
Definition: entity.h:34
nap::ComponentInstance
Definition: component.h:43
nap::Component
Definition: component.h:151
nap::ComputeComponent::mComputeMaterialInstanceResource
ComputeMaterialInstanceResource mComputeMaterialInstanceResource
Property 'ComputeMaterialInstance' The compute material instance resource.
Definition: computecomponent.h:41
nap::ComputeComponentInstance::mComputeMaterialInstance
ComputeMaterialInstance mComputeMaterialInstance
Definition: computecomponent.h:125
nap::ComputeMaterialInstance
Definition: materialinstance.h:284
nap
Definition: assert.h:10
nap::ComputeComponentInstance::getMaterialInstance
ComputeMaterialInstance & getMaterialInstance()
Definition: computecomponent.h:90