VTK  9.3.20240919
vtkWebGPUComputeBuffer.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef vtkWebGPUComputeBuffer_h
5#define vtkWebGPUComputeBuffer_h
6
7#include "vtkDataArray.h" // for vtkDataArray used in SetData
8#include "vtkLogger.h" // for the logger
9#include "vtkObject.h"
10#include "vtkRenderingWebGPUModule.h" // For export macro
11#include "vtkSetGet.h" // for get/set macro
12#include "vtk_wgpu.h" // for dawn classes
13
14#include <functional>
15#include <string>
16
17VTK_ABI_NAMESPACE_BEGIN
18
21
26class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUComputeBuffer : public vtkObject
27{
28public:
31 void PrintSelf(ostream& os, vtkIndent indent) override;
32
53 {
54 UNDEFINED = 0,
58 UNIFORM_BUFFER
59 };
60
70 {
71 VTK_DATA_ARRAY = 0,
72 STD_VECTOR
73 };
74
76
82
84
91 uint32_t GetGroup() const { return this->Group; }
92 vtkGetMacro(Group, vtkIdType);
93 vtkSetMacro(Group, vtkIdType);
95
97
104 uint32_t GetBinding() const { return this->Binding; }
105 vtkGetMacro(Binding, vtkIdType);
106 vtkSetMacro(Binding, vtkIdType);
108
110
114 vtkGetMacro(Label, std::string);
115 vtkSetMacro(Label, std::string);
117
127 template <typename T>
128 void SetData(const std::vector<T>& data)
129 {
130 this->DataPointer = data.data();
131 this->ByteSize = data.size() * sizeof(T);
132 }
133
144
146
149 vtkGetMacro(DataType, BufferDataType);
150 vtkSetMacro(DataType, BufferDataType);
152
159 const void* GetDataPointer() { return this->DataPointer; }
160
167 vtkDataArray* GetDataArray() { return this->DataArray; }
168
170
173 vtkGetMacro(ByteSize, vtkIdType);
174 vtkSetMacro(ByteSize, vtkIdType);
176
177protected:
180
181private:
183
185 void operator=(const vtkWebGPUComputeBuffer&) = delete;
186
187 // Bind group index
188 vtkIdType Group = -1;
189 // Binding withing the bind group
190 vtkIdType Binding = -1;
191 // The mode of the buffer can be read only, write only, read/write, ...
192 BufferMode Mode = BufferMode::UNDEFINED;
193 // The type of data that will be uploaded to the GPU
194 BufferDataType DataType = BufferDataType::STD_VECTOR;
195
196 // Pointer to the data that this buffer will contain. This variable DataPointer is only used when
197 // the user set the buffer data (with SetData()) using an std::vector.
198 const void* DataPointer = nullptr;
199 // Data array containing the data that will be uploaded to the buffer. Only relevant if the user
200 // called SetData(vtkDataArray).
201 vtkDataArray* DataArray = nullptr;
202 // How many bytes will be uploaded from the buffer to the GPU
203 vtkIdType ByteSize = 0;
204 // Label that can be used to identify this buffer and help with debugging
205 // in case something goes wrong
206 std::string Label;
207};
208
209VTK_ABI_NAMESPACE_END
210#endif
abstract superclass for arrays of numeric data
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
Represents the set of parameters that will be used to create a compute shader buffer on the device wh...
const void * GetDataPointer()
The pointer to the std::vector<> data passed with SetData(std::vector)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetData(const std::vector< T > &data)
Sets the data that will be used by the buffer.
BufferDataType
Because the compute buffer can accept multiple data types as input (std::vector, vtkDataArray) but wi...
uint32_t GetGroup() const
Get/set the group of the buffer in the compute shader.
~vtkWebGPUComputeBuffer() override
void SetData(vtkDataArray *data)
Sets the data that will be used by the buffer.
vtkSetEnumMacro(Mode, BufferMode)
Get/set the buffer mode.
vtkDataArray * GetDataArray()
The pointer to the vtkDataArray passed with SetData(vtkDataArray)
uint32_t GetBinding() const
Get/set the binding of the buffer in the compute shader.
static vtkWebGPUComputeBuffer * New()
vtkGetEnumMacro(Mode, BufferMode)
Get/set the buffer mode.
A compute pass is an abstraction for offloading computation from the CPU onto the GPU using WebGPU co...
int vtkIdType
Definition vtkType.h:315