VTK  9.7.1
vtkWebGPUCellToPrimitiveConverter.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
23 #ifndef vtkWebGPUCellToPrimitiveConverter_h
24 #define vtkWebGPUCellToPrimitiveConverter_h
25 
26 #include "vtkObject.h"
27 
28 #include "vtkDeprecation.h" // for VTK_DEPRECATED_IN_9_7_0
29 #include "vtkProperty.h" // for VTK_SURFACE
30 #include "vtkRenderingWebGPUModule.h" // for export macro
31 #include "vtkSmartPointer.h" // for vtkSmartPointer
32 #include "vtkTimeStamp.h" // for vtkTimeStamp
33 
34 #include "vtk_wgpu.h" // for wgpu::Buffer
35 
36 #include <array> // for std::array
37 #include <utility> // for std::pair
38 
39 VTK_ABI_NAMESPACE_BEGIN
41 class vtkPolyData;
42 class vtkCellArray;
43 class vtkDataArray;
46 
47 class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUCellToPrimitiveConverter : public vtkObject
48 {
49 public:
52  void PrintSelf(ostream& os, vtkIndent indent) override;
53 
59  void ReleaseGraphicsResources(vtkWindow*);
60 
65  enum TopologySourceType : int
66  {
67  // Used to draw VTK_VERTEX and VTK_POLY_VERTEX cell types
68  TOPOLOGY_SOURCE_VERTS = 0,
69  // Used to draw VTK_LINE and VTK_POLY_LINE cell types.
71  // Used to draw only the points of each line segment.
72  // Activated when `vtkProperty::Representation` == `VTK_POINTS`
74  // Used to draw VTK_QUAD, VTK_TRIANGLE and VTK_POLYGON cell types.
76  // Used to draw only the corner points of each face.
77  // Activated when `vtkProperty::Representation` == `VTK_POINTS`
79  // Used to draw only the edges of each face.
80  // Activated when `vtkProperty::Representation` == `VTK_WIREFRAME`
82  NUM_TOPOLOGY_SOURCE_TYPES
83  };
84 
86 
96  VTK_DEPRECATED_IN_9_7_0("Use DispatchMeshToPrimitiveComputePipeline() that accepts const "
97  "std::array<T*, N> parameters instead.")
98  bool DispatchMeshToPrimitiveComputePipeline(vtkWebGPUConfiguration* wgpuConfiguration,
99  vtkPolyData* mesh, int representation, vtkTypeUInt32* vertexCounts[NUM_TOPOLOGY_SOURCE_TYPES],
100  wgpu::Buffer* connectivityBuffers[NUM_TOPOLOGY_SOURCE_TYPES],
101  wgpu::Buffer* cellIdBuffers[NUM_TOPOLOGY_SOURCE_TYPES],
102  wgpu::Buffer* edgeArrayBuffers[NUM_TOPOLOGY_SOURCE_TYPES],
103  wgpu::Buffer* cellIdOffsetUniformBuffers[NUM_TOPOLOGY_SOURCE_TYPES]);
104  bool DispatchMeshToPrimitiveComputePipeline(vtkWebGPUConfiguration* wgpuConfiguration,
105  vtkPolyData* mesh, int representation,
106  const std::array<vtkTypeUInt32*, NUM_TOPOLOGY_SOURCE_TYPES>& vertexCounts,
107  const std::array<wgpu::Buffer*, NUM_TOPOLOGY_SOURCE_TYPES>& connectivityBuffers,
108  const std::array<wgpu::Buffer*, NUM_TOPOLOGY_SOURCE_TYPES>& cellIdBuffers,
109  const std::array<wgpu::Buffer*, NUM_TOPOLOGY_SOURCE_TYPES>& edgeArrayBuffers,
110  const std::array<wgpu::Buffer*, NUM_TOPOLOGY_SOURCE_TYPES>& cellIdOffsetUniformBuffers);
112 
123  bool DispatchMeshesToPrimitiveComputePipeline(vtkWebGPUConfiguration* wgpuConfiguration,
124  std::vector<vtkPolyData*> meshes, int representation,
125  std::vector<std::pair<vtkTypeUInt32, vtkTypeUInt32>>*
126  vertexOffsetAndCounts[NUM_TOPOLOGY_SOURCE_TYPES],
127  std::array<wgpu::Buffer*, NUM_TOPOLOGY_SOURCE_TYPES>& connectivityBuffers,
128  std::array<wgpu::Buffer*, NUM_TOPOLOGY_SOURCE_TYPES>& cellIdBuffers,
129  std::array<wgpu::Buffer*, NUM_TOPOLOGY_SOURCE_TYPES>& edgeArrayBuffers);
130 
139  VTK_DEPRECATED_IN_9_7_0("Use DispatchCellArrayToPrimitiveComputePipeline() instead.")
140  bool DispatchCellToPrimitiveComputePipeline(vtkWebGPUConfiguration* wgpuConfiguration,
141  vtkCellArray* cells, int representation, int cellType, vtkTypeUInt32 cellIdOffset,
142  vtkTypeUInt32* vertexCount, wgpu::Buffer* connectivityBuffer, wgpu::Buffer* cellIdBuffer,
143  wgpu::Buffer* edgeArrayBuffer, wgpu::Buffer* cellIdOffsetUniformBuffer);
144 
153  bool DispatchCellArrayToPrimitiveComputePipeline(vtkWebGPUConfiguration* wgpuConfiguration,
154  vtkCellArray* cells, int representation, int cellType, vtkTypeUInt32 cellIdOffset,
155  vtkTypeUInt32* vertexCount, wgpu::Buffer* connectivityBuffer, wgpu::Buffer* cellIdBuffer,
156  wgpu::Buffer* edgeArrayBuffer, wgpu::Buffer* cellIdOffsetUniformBuffer,
157  vtkDataArray* pointCoordinates = nullptr);
158 
169  bool DispatchCellArraysToPrimitiveComputePipeline(vtkWebGPUConfiguration* wgpuConfiguration,
170  const std::vector<vtkCellArray*>& cellArrays, int representation, int cellType,
171  const std::vector<vtkIdType>& numberOfPoints,
172  std::vector<std::pair<vtkTypeUInt32, vtkTypeUInt32>>* vertexOffsetAndCounts,
173  wgpu::Buffer* connectivityBuffer, wgpu::Buffer* cellIdBuffer, wgpu::Buffer* edgeArrayBuffer,
174  const std::vector<vtkDataArray*>& pointCoordinates = {});
175 
181  bool GetNeedToRebuildCellToPrimitiveComputePipeline(
183 
187  void UpdateCellToPrimitiveComputePipelineTimestamp(
189 
197  static vtkIdType GetTessellatedPrimitiveSizeOffsetForCellType(int cellType);
198 
202  static const char* GetTopologySourceTypeAsString(TopologySourceType topologySourceType);
203 
207  static const char* GetCellTypeAsString(int cellType);
208 
213  static const char* GetTessellatedPrimitiveTypeAsString(TopologySourceType topologySourceType);
214 
218  static std::size_t GetTessellatedPrimitiveSize(TopologySourceType topologySourceType);
219 
223  static TopologySourceType GetTopologySourceTypeForCellType(
224  int cellType, int representation = VTK_SURFACE);
225 
226 protected:
229 
230 private:
232  void operator=(const vtkWebGPUCellToPrimitiveConverter&) = delete;
233 
239  std::pair<vtkSmartPointer<vtkWebGPUComputePass>, vtkSmartPointer<vtkWebGPUComputePipeline>>
240  CreateCellToPrimitiveComputePassForCellType(
241  vtkSmartPointer<vtkWebGPUConfiguration> wgpuConfiguration,
242  TopologySourceType topologySourceType);
243 
244  // Timestamps help reuse previous resources as much as possible.
246  // compute pass speeds up cell to primitive conversions.
249  // compute pipeline to execute the compute pass.
252 };
253 
254 VTK_ABI_NAMESPACE_END
255 
256 #endif
Converts VTK cell connectivity arrays into webgpu primitives using compute shaders.
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.
#define VTK_SURFACE
Definition: vtkProperty.h:45
record modification and/or execution time
Definition: vtkTimeStamp.h:24
int vtkIdType
Definition: vtkType.h:363
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
a simple class to control print indentation
Definition: vtkIndent.h:28
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
object to represent cell connectivity
Definition: vtkCellArray.h:177
Create a webgpu device for use in rendering and compute pipelines.
A compute pipeline is the orchestrator of a collection of compute passes.
TopologySourceType
All supported types of topology.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
#define VTK_DEPRECATED_IN_9_7_0(reason)
A compute pass is an abstraction for offloading computation from the CPU onto the GPU using WebGPU co...