VTK  9.4.2
vtkWebGPUPolyDataMapper.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#ifndef vtkWebGPUPolyDataMapper_h
4#define vtkWebGPUPolyDataMapper_h
5
6#include "vtkPolyDataMapper.h"
7
8#include "vtkRenderingWebGPUModule.h" // for export macro
9#include "vtkType.h" // for types
10#include "vtk_wgpu.h" // for webgpu
11
12#include <unordered_set> // for the not set compute render buffers
13
14VTK_ABI_NAMESPACE_BEGIN
15class vtkCellArray;
16class vtkTypeFloat32Array;
20
21class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUPolyDataMapper : public vtkPolyDataMapper
22{
23public:
26 void PrintSelf(ostream& os, vtkIndent indent) override;
27
32 {
33 POINT_POSITIONS = 0,
39 POINT_UNDEFINED
40 };
41
46 {
47 CELL_COLORS = 0,
51 CELL_UNDEFINED
52 };
53
57 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
59 vtkRenderer* renderer, vtkActor* act, const wgpu::RenderPassEncoder& passEncoder);
61 vtkRenderer* renderer, vtkActor* act, const wgpu::RenderBundleEncoder& bundleEncoder);
62
69
76 bool GetSupportsSelection() override { return false; }
77
81 void ShallowCopy(vtkAbstractMapper* m) override;
82
94 void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
95 int fieldAssociation, int componentno = -1) override;
96
97 // This method will Map the specified data array for use as
98 // a texture coordinate for texture tname. The actual
99 // attribute will be named tname_coord so as to not
100 // conflict with the texture sampler definition which will
101 // be tname.
102 void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
103 int fieldAssociation, int componentno = -1) override;
104
108 void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
109
114
120 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
121
138 PointDataAttributes attribute, int bufferGroup, int bufferBinding, int uniformsGroup,
139 int uniformsBinding);
140
145 CellDataAttributes attribute, int bufferGroup, int bufferBinding, int uniformsGroup,
146 int uniformsBinding);
147
148protected:
151
157 void ComputeBounds() override;
158
162 void SetupPipelineLayout(const wgpu::Device& device, vtkRenderer* renderer, vtkActor* actor);
163
168 void SetupBindGroups(const wgpu::Device& device, vtkRenderer* renderer);
169
174
179
186
192
198
204
210 unsigned long GetExactPointBufferSize();
211 unsigned long GetExactCellBufferSize();
212 std::vector<unsigned long> GetExactConnecitivityBufferSizes();
214 vtkWebGPURenderWindow* wgpuRenWin, const wgpu::Device& device, vtkActor* actor);
215 bool UpdateMeshIndexBuffers(const wgpu::Device& device);
216 vtkTypeFloat32Array* ComputeEdgeArray(vtkCellArray* polys);
217
221 void SetupGraphicsPipeline(const wgpu::Device& device, vtkRenderer* renderer, vtkActor* actor);
222
223 wgpu::PipelineLayout PipelineLayout;
224 wgpu::ShaderModule Shader;
225
227 {
228 struct
229 {
230 // point attributes.
231 wgpu::Buffer Buffer;
232 } Point;
233
234 struct
235 {
236 // cell attributes.
237 wgpu::Buffer Buffer;
238 } Cell;
239 };
241
243 {
244 vtkTypeUInt32 Start = 0;
245 vtkTypeUInt32 NumTuples = 0;
246 vtkTypeUInt32 NumComponents = 0;
247 vtkTypeUInt32 Pad = 0; // for 16-byte alignment in MeshAttributeDescriptor
248 };
250 {
259 };
261
264
265 bool InitializedPipeline = false;
266 bool UpdatedPrimitiveSizes = false;
267 bool UpdatedGeometryBuffers = false;
268 bool UpdatedPrimitiveBuffers = false;
269 bool HasPointColors = false;
270 bool HasPointNormals = false;
271 bool HasPointTangents = false;
272 bool HasPointUVs = false;
273 bool HasCellColors = false;
274 bool HasCellNormals = false;
275 // used by RenderPiece and functions it calls to reduce
276 // calls to get the input and allow for rendering of
277 // other polydata (not the input)
278 vtkPolyData* CurrentInput = nullptr;
279 // vtkRenderer culls props to frustum. At that point, it requests
280 // mappers for bounds of the geometry. We cache the vtkAlgorithm output
281 // so that `UpdateMeshGeometryBuffers` can reuse it without climbing up
282 // vtkAlgorithm pipeline.
283 vtkPolyData* CachedInput = nullptr;
284
285 // 1 bind group for this polydata mesh
286 wgpu::BindGroup MeshAttributeBindGroup;
287 // 1 bind group layout for the above bindgroup
288 wgpu::BindGroupLayout MeshAttributeBindGroupLayout;
289
291 {
292 // 1 uniform buffer for the primitive size.
294 // 1 buffer for the primitive cell ids and point ids.
295 wgpu::Buffer Buffer;
296 // 1 bind group for the primitive size uniform.
297 wgpu::BindGroup BindGroup;
298 // each primitive-type gets a pipeline.
299 wgpu::RenderPipeline Pipeline;
300 // vertexCount for draw call.
301 vtkTypeUInt32 VertexCount = 0;
302 };
303 // 1 bind group layout for the above bindgroups.
304 wgpu::BindGroupLayout PrimitiveBindGroupLayout;
305
309 unsigned long EdgeArrayCount = 0;
310
311 // Cache these so that subsequent arrivals to UpdateMeshGeometry do not unnecessarily invoke
312 // MapScalars().
315 vtkDataArray* LastColors = nullptr;
316
317private:
319 friend class vtkWebGPURenderer;
320
324 wgpu::Buffer GetPointDataWGPUBuffer() { return this->MeshSSBO.Point.Buffer; }
325
329 wgpu::Buffer GetCellDataWGPUBuffer() { return this->MeshSSBO.Cell.Buffer; }
330
337 std::vector<vtkSmartPointer<vtkWebGPUComputeRenderBuffer>> SetupComputeRenderBuffers;
338
342 std::unordered_set<vtkSmartPointer<vtkWebGPUComputeRenderBuffer>> NotSetupComputeRenderBuffers;
343
347 const PointDataAttributes PointDataAttributesOrder[PointDataAttributes::POINT_NB_ATTRIBUTES] = {
348 PointDataAttributes::POINT_POSITIONS, PointDataAttributes::POINT_COLORS,
349 PointDataAttributes::POINT_NORMALS, PointDataAttributes::POINT_TANGENTS,
350 PointDataAttributes::POINT_UVS
351 };
352
356 const CellDataAttributes CellDataAttributesOrder[CellDataAttributes::CELL_NB_ATTRIBUTES] = {
357 CellDataAttributes::CELL_EDGES, CellDataAttributes::CELL_COLORS,
358 CellDataAttributes::CELL_NORMALS
359 };
360
362 void operator=(const vtkWebGPUPolyDataMapper&) = delete;
363};
364VTK_ABI_NAMESPACE_END
365#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
object to represent cell connectivity
abstract superclass for arrays of numeric data
a simple class to control print indentation
Definition vtkIndent.h:108
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:66
abstract specification for renderers
Hold a reference to a vtkObjectBase instance.
record modification and/or execution time
Render buffers are returned by calls to vtkWebGPUPolyDataMapper::AcquirePointAttributeComputeRenderBu...
PointDataAttributes
All the attributes supported by the point data buffer.
unsigned long GetPointAttributeByteSize(vtkWebGPUPolyDataMapper::PointDataAttributes attribute)
Returns the size of the 'sub-buffer' within the whole point data SSBO for the given attribute.
wgpu::BindGroupLayout MeshAttributeBindGroupLayout
void ProcessSelectorPixelBuffers(vtkHardwareSelector *sel, std::vector< unsigned int > &pixeloffsets, vtkProp *prop) override
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
void SetupBindGroups(const wgpu::Device &device, vtkRenderer *renderer)
Creates bind groups for all the buffers in the MeshGeometryBuffers struct.
PrimitiveBindGroupInfo PointPrimitiveBGInfo
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
PrimitiveBindGroupInfo TrianglePrimitiveBGInfo
vtkIdType GetPointAttributeByteOffset(PointDataAttributes attribute)
Returns the offset at which the 'sub-buffer' of 'attribute' starts within the mesh SSBO point data bu...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
unsigned long GetCellAttributeElementSize(vtkWebGPUPolyDataMapper::CellDataAttributes attribute)
Returns the size in bytes of one element of the given attribute.
void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
Select a data array from the point/cell data and map it to a generic vertex attribute.
void EncodeRenderCommands(vtkRenderer *renderer, vtkActor *act, const wgpu::RenderBundleEncoder &bundleEncoder)
void RemoveAllVertexAttributeMappings() override
Remove all vertex attributes.
PrimitiveBindGroupInfo LinePrimitiveBGInfo
vtkSmartPointer< vtkWebGPUComputeRenderBuffer > AcquirePointAttributeComputeRenderBuffer(PointDataAttributes attribute, int bufferGroup, int bufferBinding, int uniformsGroup, int uniformsBinding)
Returns an already configured (ready to be added to a vtkWebGPUComputePipeline) buffer bound to the g...
void SetupPipelineLayout(const wgpu::Device &device, vtkRenderer *renderer, vtkActor *actor)
Sets up bindgroup layouts and creates a pipeline layout.
vtkSmartPointer< vtkWebGPUComputeRenderBuffer > AcquireCellAttributeComputeRenderBuffer(CellDataAttributes attribute, int bufferGroup, int bufferBinding, int uniformsGroup, int uniformsBinding)
Same as AcquirePointAttributeComputeRenderBuffer but for cell data attributes.
wgpu::PipelineLayout PipelineLayout
unsigned long GetExactPointBufferSize()
Enqueues a write command on the device queue for all buffers whose data is outdated.
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
vtkIdType GetCellAttributeByteOffset(CellDataAttributes attribute)
Returns the offset at which the 'sub-buffer' of 'attribute' starts within the mesh SSBO cell data buf...
bool UpdateMeshIndexBuffers(const wgpu::Device &device)
void RemoveVertexAttributeMapping(const char *vertexAttributeName) override
Remove a vertex attribute mapping.
static vtkWebGPUPolyDataMapper * New()
vtkTypeFloat32Array * ComputeEdgeArray(vtkCellArray *polys)
~vtkWebGPUPolyDataMapper() override
bool UpdateMeshGeometryBuffers(vtkWebGPURenderWindow *wgpuRenWin, const wgpu::Device &device, vtkActor *actor)
void MapDataArrayToMultiTextureAttribute(const char *tname, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
void EncodeRenderCommands(vtkRenderer *renderer, vtkActor *act, const wgpu::RenderPassEncoder &passEncoder)
unsigned long GetCellAttributeByteSize(vtkWebGPUPolyDataMapper::CellDataAttributes attribute)
Returns the size of the 'sub-buffer' within the whole cell data SSBO for the given attribute.
std::vector< unsigned long > GetExactConnecitivityBufferSizes()
void SetupGraphicsPipeline(const wgpu::Device &device, vtkRenderer *renderer, vtkActor *actor)
Creates the graphics pipeline.
void RenderPiece(vtkRenderer *ren, vtkActor *act) override
Implemented by sub classes.
wgpu::BindGroupLayout PrimitiveBindGroupLayout
unsigned long GetExactCellBufferSize()
unsigned long GetPointAttributeElementSize(vtkWebGPUPolyDataMapper::PointDataAttributes attribute)
Returns the size in bytes of one element of the given attribute.
CellDataAttributes
All the attributes supported by the cell data buffer.
void ComputeBounds() override
Called in GetBounds().
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
struct vtkWebGPUPolyDataMapper::MeshAttributeBuffers::@202 Cell
struct vtkWebGPUPolyDataMapper::MeshAttributeBuffers::@201 Point
int vtkIdType
Definition vtkType.h:315