VTK
9.4.20250208
|
A compute pass is an abstraction for offloading computation from the CPU onto the GPU using WebGPU compute shaders. More...
#include <vtkWebGPUComputePass.h>
Public Types | |
typedef vtkObject | Superclass |
using | BufferMapAsyncCallback = std::function< void(const void *, void *)> |
using | TextureMapAsyncCallback = std::function< void(const void *, int, void *)> |
Public Member Functions | |
virtual vtkTypeBool | IsA (const char *type) |
Return 1 if this class is the same type of (or a subclass of) the named class. | |
vtkWebGPUComputePass * | NewInstance () const |
void | PrintSelf (ostream &os, vtkIndent indent) override |
Methods invoked by print to print information about the object including superclasses. | |
void | SetShaderSourceFromPath (const char *shaderFilePath) |
int | AddBuffer (vtkSmartPointer< vtkWebGPUComputeBuffer > buffer) |
Adds a buffer to the pass and uploads its data to the device. | |
void | AddRenderBuffer (vtkSmartPointer< vtkWebGPUComputeRenderBuffer > renderBuffer) |
Adds a render buffer to the pass. | |
int | AddRenderTexture (vtkSmartPointer< vtkWebGPUComputeRenderTexture > renderTexture) |
Adds a render texture to the pass. | |
int | AddTexture (vtkSmartPointer< vtkWebGPUComputeTexture > texture) |
Adds a texture to the pass and upload its data to the device. | |
vtkSmartPointer< vtkWebGPUComputeTextureView > | CreateTextureView (int textureIndex) |
Returns a new texture view on the given texture (given by the index) that can be configured and then added to the compute pass by AddTextureView() | |
int | AddTextureView (vtkSmartPointer< vtkWebGPUComputeTextureView > textureView) |
Adds a texture view to the compute pass and returns its index. | |
void | RebindTextureView (int group, int binding, int textureViewIndex) |
This function allows the usage of multiple texture views on a single binding point (group / binding combination) in the shader (although not at the same time). | |
void | DeleteTextureViews (int textureIndex) |
Deletes all the texture views of a given texture (given by its index) | |
unsigned int | GetBufferByteSize (int bufferIndex) |
Returns the size in bytes of a buffer. | |
void | ResizeBuffer (int bufferIndex, vtkIdType newByteSize) |
Resizes a buffer of the pass. | |
vtkSmartPointer< vtkWebGPUComputeTexture > | GetComputeTexture (int textureIndex) |
Retrieves the compute texture associated with the given texture index. | |
vtkSmartPointer< vtkWebGPUComputeTextureView > | GetTextureView (int textureViewIndex) |
Retrieves the texture view associated with the given texture view index. | |
void | RecreateComputeTexture (int textureIndex) |
Recreates a compute texture. | |
void | RecreateTextureView (int textureViewIndex) |
Recreates a compute texture view. | |
void | ReadBufferFromGPU (int bufferIndex, BufferMapAsyncCallback callback, void *userdata) |
void | ReadTextureFromGPU (int textureIndex, int mipLevel, TextureMapAsyncCallback callback, void *userdata) |
This function maps the texture into a linear memory block, making it accessible to the CPU. | |
template<typename T , std::enable_if_t< std::is_arithmetic< T >::value, bool > = true> | |
void | UpdateBufferData (int bufferIndex, const std::vector< T > &newData) |
Updates the data of a buffer. | |
template<typename T , std::enable_if_t< std::is_arithmetic< T >::value, bool > = true> | |
void | UpdateBufferData (int bufferIndex, vtkIdType byteOffset, const std::vector< T > &data) |
Similar to the overload without offset of this function. | |
void | UpdateBufferData (int bufferIndex, vtkDataArray *newData) |
Updates the data of a buffer with a vtkDataArray. | |
void | UpdateBufferData (int bufferIndex, vtkIdType byteOffset, vtkDataArray *newData) |
Similar to the overload without offset of this function. | |
template<typename T , std::enable_if_t< std::is_arithmetic< T >::value, bool > = true> | |
void | UpdateTextureData (int textureIndex, const std::vector< T > &data) |
Uploads the given data to the texture starting at pixel (0, 0) | |
void | Dispatch () |
Dispatch the compute pass with (X, Y, Z) = (groupX, groupsY, groupZ) groups. | |
void | ReleaseResources () |
Releases the resources used by this compute pass. | |
virtual std::string | GetShaderSource () |
Set/get the WGSL source of the shader. | |
virtual void | SetShaderSource (std::string) |
Set/get the WGSL source of the shader. | |
virtual std::string | GetShaderEntryPoint () |
Set/get the entry (name of the function) of the WGSL compute shader. | |
virtual void | SetShaderEntryPoint (std::string) |
Set/get the entry (name of the function) of the WGSL compute shader. | |
virtual std::string & | GetLabel () |
Set/get the label of the compute pass. | |
void | SetLabel (const std::string &label) |
Set/get the label of the compute pass. | |
void | SetWorkgroups (int groupsX, int groupsY, int groupsZ) |
![]() | |
vtkBaseTypeMacro (vtkObject, vtkObjectBase) | |
virtual void | DebugOn () |
Turn debugging output on. | |
virtual void | DebugOff () |
Turn debugging output off. | |
bool | GetDebug () |
Get the value of the debug flag. | |
void | SetDebug (bool debugFlag) |
Set the value of the debug flag. | |
virtual void | Modified () |
Update the modification time for this object. | |
virtual vtkMTimeType | GetMTime () |
Return this object's modified time. | |
void | PrintSelf (ostream &os, vtkIndent indent) override |
Methods invoked by print to print information about the object including superclasses. | |
void | RemoveObserver (unsigned long tag) |
void | RemoveObservers (unsigned long event) |
void | RemoveObservers (const char *event) |
void | RemoveAllObservers () |
vtkTypeBool | HasObserver (unsigned long event) |
vtkTypeBool | HasObserver (const char *event) |
vtkTypeBool | InvokeEvent (unsigned long event) |
vtkTypeBool | InvokeEvent (const char *event) |
std::string | GetObjectDescription () const override |
The object description printed in messages and PrintSelf output. | |
unsigned long | AddObserver (unsigned long event, vtkCommand *, float priority=0.0f) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
unsigned long | AddObserver (const char *event, vtkCommand *, float priority=0.0f) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
vtkCommand * | GetCommand (unsigned long tag) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
void | RemoveObserver (vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
void | RemoveObservers (unsigned long event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
void | RemoveObservers (const char *event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
vtkTypeBool | HasObserver (unsigned long event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
vtkTypeBool | HasObserver (const char *event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
template<class U , class T > | |
unsigned long | AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f) |
Overloads to AddObserver that allow developers to add class member functions as callbacks for events. | |
template<class U , class T > | |
unsigned long | AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f) |
Overloads to AddObserver that allow developers to add class member functions as callbacks for events. | |
template<class U , class T > | |
unsigned long | AddObserver (unsigned long event, U observer, bool(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f) |
Allow user to set the AbortFlagOn() with the return value of the callback method. | |
vtkTypeBool | InvokeEvent (unsigned long event, void *callData) |
This method invokes an event and return whether the event was aborted or not. | |
vtkTypeBool | InvokeEvent (const char *event, void *callData) |
This method invokes an event and return whether the event was aborted or not. | |
virtual void | SetObjectName (const std::string &objectName) |
Set/get the name of this object for reporting purposes. | |
virtual std::string | GetObjectName () const |
Set/get the name of this object for reporting purposes. | |
![]() | |
const char * | GetClassName () const |
Return the class name as a string. | |
virtual std::string | GetObjectDescription () const |
The object description printed in messages and PrintSelf output. | |
virtual vtkTypeBool | IsA (const char *name) |
Return 1 if this class is the same type of (or a subclass of) the named class. | |
virtual vtkIdType | GetNumberOfGenerationsFromBase (const char *name) |
Given the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class). | |
virtual void | Delete () |
Delete a VTK object. | |
virtual void | FastDelete () |
Delete a reference to this object. | |
void | InitializeObjectBase () |
void | Print (ostream &os) |
Print an object to an ostream. | |
void | Register (vtkObjectBase *o) |
Increase the reference count (mark as used by another object). | |
virtual void | UnRegister (vtkObjectBase *o) |
Decrease the reference count (release by another object). | |
int | GetReferenceCount () |
Return the current reference count of this object. | |
void | SetReferenceCount (int) |
Sets the reference count. | |
bool | GetIsInMemkind () const |
A local state flag that remembers whether this object lives in the normal or extended memory space. | |
virtual void | PrintHeader (ostream &os, vtkIndent indent) |
Methods invoked by print to print information about the object including superclasses. | |
virtual void | PrintTrailer (ostream &os, vtkIndent indent) |
Methods invoked by print to print information about the object including superclasses. | |
virtual bool | UsesGarbageCollector () const |
Indicate whether the class uses vtkGarbageCollector or not. | |
Static Public Member Functions | |
static vtkWebGPUComputePass * | New () |
Note to the VTK user: A compute pass should always be acquired through vtkWebGPUComputePipeline::CreateComputePass(). | |
static vtkTypeBool | IsTypeOf (const char *type) |
static vtkWebGPUComputePass * | SafeDownCast (vtkObjectBase *o) |
![]() | |
static vtkObject * | New () |
Create an object with Debug turned off, modified time initialized to zero, and reference counting on. | |
static void | BreakOnError () |
This method is called when vtkErrorMacro executes. | |
static void | SetGlobalWarningDisplay (vtkTypeBool val) |
This is a global flag that controls whether any debug, warning or error messages are displayed. | |
static void | GlobalWarningDisplayOn () |
This is a global flag that controls whether any debug, warning or error messages are displayed. | |
static void | GlobalWarningDisplayOff () |
This is a global flag that controls whether any debug, warning or error messages are displayed. | |
static vtkTypeBool | GetGlobalWarningDisplay () |
This is a global flag that controls whether any debug, warning or error messages are displayed. | |
![]() | |
static vtkTypeBool | IsTypeOf (const char *name) |
Return 1 if this class type is the same type of (or a subclass of) the named class. | |
static vtkIdType | GetNumberOfGenerationsFromBaseType (const char *name) |
Given a the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class). | |
static vtkObjectBase * | New () |
Create an object with Debug turned off, modified time initialized to zero, and reference counting on. | |
static void | SetMemkindDirectory (const char *directoryname) |
The name of a directory, ideally mounted -o dax, to memory map an extended memory space within. | |
static bool | GetUsingMemkind () |
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) or within the extended memory space. | |
Protected Member Functions | |
virtual vtkObjectBase * | NewInstanceInternal () const |
vtkWebGPUComputePass () | |
~vtkWebGPUComputePass () override | |
![]() | |
vtkObject () | |
~vtkObject () override | |
void | RegisterInternal (vtkObjectBase *, vtkTypeBool check) override |
void | UnRegisterInternal (vtkObjectBase *, vtkTypeBool check) override |
void | InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr) |
These methods allow a command to exclusively grab all events. | |
void | InternalReleaseFocus () |
These methods allow a command to exclusively grab all events. | |
![]() | |
vtkObjectBase () | |
virtual | ~vtkObjectBase () |
virtual void | RegisterInternal (vtkObjectBase *, vtkTypeBool check) |
virtual void | UnRegisterInternal (vtkObjectBase *, vtkTypeBool check) |
virtual void | ReportReferences (vtkGarbageCollector *) |
virtual void | ObjectFinalize () |
vtkObjectBase (const vtkObjectBase &) | |
void | operator= (const vtkObjectBase &) |
Friends | |
class | vtkWebGPUComputePassInternals |
class | vtkWebGPUComputePassTextureStorageInternals |
class | vtkWebGPUComputePassBufferStorageInternals |
class | vtkWebGPUComputePipeline |
class | vtkWebGPUHelpers |
class | vtkWebGPUPointCloudMapperInternals |
class | vtkWebGPURenderWindow |
class | vtkWebGPURenderer |
Additional Inherited Members | |
![]() | |
static vtkMallocingFunction | GetCurrentMallocFunction () |
static vtkReallocingFunction | GetCurrentReallocFunction () |
static vtkFreeingFunction | GetCurrentFreeFunction () |
static vtkFreeingFunction | GetAlternateFreeFunction () |
![]() | |
bool | Debug |
vtkTimeStamp | MTime |
vtkSubjectHelper * | SubjectHelper |
std::string | ObjectName |
![]() | |
std::atomic< int32_t > | ReferenceCount |
vtkWeakPointerBase ** | WeakPointers |
A compute pass is an abstraction for offloading computation from the CPU onto the GPU using WebGPU compute shaders.
The basic usage of a compute pass outside a rendering pipeline is:
Integrated into a rendering pipeline, the only difference in the usage of the class is going to be the creation of the buffers. You will not create the vtkWebGPUComputeBuffer yourself but rather acquire one (or many) by calling AcquirePointAttributeComputeRenderBuffer() on a vtkWebGPURenderer. The returned buffers can then be added to the compute pass with AddRenderBuffer(). Other steps are identical. This remark also applies to render textures.
Definition at line 50 of file vtkWebGPUComputePass.h.
Definition at line 59 of file vtkWebGPUComputePass.h.
using vtkWebGPUComputePass::BufferMapAsyncCallback = std::function<void(const void*, void*)> |
Definition at line 202 of file vtkWebGPUComputePass.h.
using vtkWebGPUComputePass::TextureMapAsyncCallback = std::function<void(const void*, int, void*)> |
Definition at line 233 of file vtkWebGPUComputePass.h.
|
protected |
|
overrideprotected |
|
static |
Note to the VTK user: A compute pass should always be acquired through vtkWebGPUComputePipeline::CreateComputePass().
You should not create compute pass through vtkNew<> or vtkSmartPointer<> directly.
|
static |
|
virtual |
Return 1 if this class is the same type of (or a subclass of) the named class.
Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.
Reimplemented from vtkObjectBase.
|
static |
|
protectedvirtual |
vtkWebGPUComputePass * vtkWebGPUComputePass::NewInstance | ( | ) | const |
|
overridevirtual |
|
virtual |
Set/get the WGSL source of the shader.
|
virtual |
Set/get the WGSL source of the shader.
void vtkWebGPUComputePass::SetShaderSourceFromPath | ( | const char * | shaderFilePath | ) |
|
virtual |
Set/get the entry (name of the function) of the WGSL compute shader.
|
virtual |
Set/get the entry (name of the function) of the WGSL compute shader.
|
virtual |
Set/get the label of the compute pass.
This label will be printed along with error/warning logs to help with debugging
void vtkWebGPUComputePass::SetLabel | ( | const std::string & | label | ) |
Set/get the label of the compute pass.
This label will be printed along with error/warning logs to help with debugging
int vtkWebGPUComputePass::AddBuffer | ( | vtkSmartPointer< vtkWebGPUComputeBuffer > | buffer | ) |
Adds a buffer to the pass and uploads its data to the device.
Returns the index of the buffer that can for example be used as input to the ReadBufferFromGPU() function
void vtkWebGPUComputePass::AddRenderBuffer | ( | vtkSmartPointer< vtkWebGPUComputeRenderBuffer > | renderBuffer | ) |
Adds a render buffer to the pass.
A render buffer can be obtained from vtkWebGPURenderWindow::AcquireDepthBufferRenderTexture()
int vtkWebGPUComputePass::AddRenderTexture | ( | vtkSmartPointer< vtkWebGPUComputeRenderTexture > | renderTexture | ) |
Adds a render texture to the pass.
A render texture can be obtained from vtkWebGPURenderWindow::AcquireDepthBufferRenderTexture() and analogous methods.
int vtkWebGPUComputePass::AddTexture | ( | vtkSmartPointer< vtkWebGPUComputeTexture > | texture | ) |
Adds a texture to the pass and upload its data to the device.
Returns the index of the texture that can for example be used as input to the ReadTextureFromGPU() function
vtkSmartPointer< vtkWebGPUComputeTextureView > vtkWebGPUComputePass::CreateTextureView | ( | int | textureIndex | ) |
Returns a new texture view on the given texture (given by the index) that can be configured and then added to the compute pass by AddTextureView()
int vtkWebGPUComputePass::AddTextureView | ( | vtkSmartPointer< vtkWebGPUComputeTextureView > | textureView | ) |
Adds a texture view to the compute pass and returns its index.
void vtkWebGPUComputePass::RebindTextureView | ( | int | group, |
int | binding, | ||
int | textureViewIndex | ||
) |
This function allows the usage of multiple texture views on a single binding point (group / binding combination) in the shader (although not at the same time).
It acts as AddTextureView() if no texture view was bound to the group/binding in the first place.
For example, consider that your shader has the following binding: @group(0) @binding(0) var inputTexture: texture_2d<f32>;
Depending on your needs, you may want to execute this compute pass twice but with a different texture as input to the shader each time. To achieve that, you would create 2 TextureViews on the 2 Textures that you want your shader to manipulate and call RebindTextureView() on your second texture view index before Dispatching the second compute pass so that it the texture view sampled in the shader samples the second texture.
void vtkWebGPUComputePass::DeleteTextureViews | ( | int | textureIndex | ) |
Deletes all the texture views of a given texture (given by its index)
unsigned int vtkWebGPUComputePass::GetBufferByteSize | ( | int | bufferIndex | ) |
Returns the size in bytes of a buffer.
void vtkWebGPUComputePass::ResizeBuffer | ( | int | bufferIndex, |
vtkIdType | newByteSize | ||
) |
Resizes a buffer of the pass.
vtkSmartPointer< vtkWebGPUComputeTexture > vtkWebGPUComputePass::GetComputeTexture | ( | int | textureIndex | ) |
Retrieves the compute texture associated with the given texture index.
vtkSmartPointer< vtkWebGPUComputeTextureView > vtkWebGPUComputePass::GetTextureView | ( | int | textureViewIndex | ) |
Retrieves the texture view associated with the given texture view index.
void vtkWebGPUComputePass::RecreateComputeTexture | ( | int | textureIndex | ) |
Recreates a compute texture.
Must be called if the compute texture has been modified (after a call to GetComputeTexure() + modifications of the parameters for example) for the changes to take effect.
void vtkWebGPUComputePass::RecreateTextureView | ( | int | textureViewIndex | ) |
Recreates a compute texture view.
Must be called if the texture view has been modified (after a call to GetComputeTextureView for example) for the changes to take effect.
void vtkWebGPUComputePass::ReadBufferFromGPU | ( | int | bufferIndex, |
BufferMapAsyncCallback | callback, | ||
void * | userdata | ||
) |
void vtkWebGPUComputePass::ReadTextureFromGPU | ( | int | textureIndex, |
int | mipLevel, | ||
TextureMapAsyncCallback | callback, | ||
void * | userdata | ||
) |
This function maps the texture into a linear memory block, making it accessible to the CPU.
This is an asynchronous operation, meaning that the given callback will be called when the mapping is done.
The texture data can then be read from the callback and stored in a buffer (std::vector<>, vtkDataArray, ...) passed in via the userdata pointer for example
|
inline |
Updates the data of a buffer.
The given data is expected to be at most the size of the buffer. If N bytes are given to update but the buffer size is > N, only the first N bytes will be updated, the rest will remain unchanged. The data is immediately available to the GPU (no call to vtkWebGPUComputePass::Update() is necessary for this call to take effect)
Definition at line 260 of file vtkWebGPUComputePass.h.
|
inline |
Similar to the overload without offset of this function.
The offset is used to determine where in the buffer to reupload data. Useful when only a portion of the buffer needs to be reuploaded.
Definition at line 271 of file vtkWebGPUComputePass.h.
void vtkWebGPUComputePass::UpdateBufferData | ( | int | bufferIndex, |
vtkDataArray * | newData | ||
) |
Updates the data of a buffer with a vtkDataArray.
The given data is expected to be at most the size of the buffer. If N bytes are given to update but the buffer size is > N, only the first N bytes will be updated, the rest will remain unchanged. The data is immediately available to the GPU (no call to vtkWebGPUComputePass::Update() is necessary for this call to take effect
void vtkWebGPUComputePass::UpdateBufferData | ( | int | bufferIndex, |
vtkIdType | byteOffset, | ||
vtkDataArray * | newData | ||
) |
Similar to the overload without offset of this function.
The offset is used to determine where in the buffer to reupload data. Useful when only a portion of the buffer needs to be reuploaded.
|
inline |
Uploads the given data to the texture starting at pixel (0, 0)
Definition at line 300 of file vtkWebGPUComputePass.h.
void vtkWebGPUComputePass::SetWorkgroups | ( | int | groupsX, |
int | groupsY, | ||
int | groupsZ | ||
) |
void vtkWebGPUComputePass::Dispatch | ( | ) |
Dispatch the compute pass with (X, Y, Z) = (groupX, groupsY, groupZ) groups.
void vtkWebGPUComputePass::ReleaseResources | ( | ) |
Releases the resources used by this compute pass.
After this call, the compute pass will be in an unusable state and it should be removed from the compute pipeline it belongs to. A new compute pass should then be created from the compute pipeline.
|
friend |
Definition at line 337 of file vtkWebGPUComputePass.h.
|
friend |
Definition at line 338 of file vtkWebGPUComputePass.h.
|
friend |
Definition at line 339 of file vtkWebGPUComputePass.h.
|
friend |
Definition at line 340 of file vtkWebGPUComputePass.h.
|
friend |
Definition at line 341 of file vtkWebGPUComputePass.h.
|
friend |
Definition at line 344 of file vtkWebGPUComputePass.h.
|
friend |
Definition at line 345 of file vtkWebGPUComputePass.h.
|
friend |
Definition at line 346 of file vtkWebGPUComputePass.h.