VTK  9.7.1
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 
17 VTK_ABI_NAMESPACE_BEGIN
18 
20 class vtkWebGPURenderer;
21 
26 class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUComputeBuffer : public vtkObject
27 {
28 public:
30  static vtkWebGPUComputeBuffer* New();
31  void PrintSelf(ostream& os, vtkIndent indent) override;
32 
53  {
54  UNDEFINED = 0,
58  UNIFORM_BUFFER
59  };
60 
70  {
72  STD_VECTOR
73  };
74 
76 
79  vtkGetEnumMacro(Mode, BufferMode);
80  vtkSetEnumMacro(Mode, BufferMode);
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 
143  void SetData(vtkDataArray* data);
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 
177 protected:
179  ~vtkWebGPUComputeBuffer() override;
180 
181 private:
182  friend class vtkWebGPUComputePass;
183 
185  void operator=(const vtkWebGPUComputeBuffer&) = delete;
186 
187  // Bind group index
188  vtkIdType Group = -1;
189  // Binding within 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 
209 VTK_ABI_NAMESPACE_END
210 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
const void * GetDataPointer()
The pointer to the std::vector<> data passed with SetData(std::vector)
BufferDataType
Because the compute buffer can accept multiple data types as input (std::vector, vtkDataArray) but wi...
int vtkIdType
Definition: vtkType.h:363
Represents the set of parameters that will be used to create a compute shader buffer on the device wh...
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.
a simple class to control print indentation
Definition: vtkIndent.h:28
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
uint32_t GetGroup() const
Get/set the group of the buffer in the compute shader.
void SetData(const std::vector< T > &data)
Sets the data that will be used by the buffer.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
A compute pass is an abstraction for offloading computation from the CPU onto the GPU using WebGPU co...