VTK  9.6.20260505
vtkWebGPUPolyDataMapper2DInternals.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 vtkWebGPUPolyDataMapper2DInternals_h
5#define vtkWebGPUPolyDataMapper2DInternals_h
6
7#include "vtkNew.h"
8#include "vtkRenderingWebGPUModule.h"
9#include "vtkSmartPointer.h"
10#include "vtkTimeStamp.h"
12
13#include "vtk_wgpu.h"
14#include <unordered_set>
15
16VTK_ABI_NAMESPACE_BEGIN
17
18class vtkPoints;
19class vtkMatrix4x4;
20class vtkViewport;
21class vtkActor2D;
26
30class VTKRENDERINGWEBGPU_NO_EXPORT vtkWebGPUPolyDataMapper2DInternals
31{
37 enum GraphicsPipeline2DType : int
38 {
39 // Pipeline that renders points
40 GFX_PIPELINE_2D_POINTS = 0,
41 GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
42 // Pipeline that renders lines
43 GFX_PIPELINE_2D_LINES,
44 GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
45 // Pipeline that renders triangles
46 GFX_PIPELINE_2D_TRIANGLES,
47 GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
48 NUM_GFX_PIPELINE_2D_NB_TYPES
49 };
50
51 struct Mapper2DState
52 {
53 vtkTypeFloat32 WCVCMatrix[4][4];
54 vtkTypeFloat32 Color[4];
55 vtkTypeFloat32 PointSize;
56 vtkTypeFloat32 LineWidth;
57 vtkTypeUInt32 Flags;
58 vtkTypeUInt32 Padding;
59 };
60 static constexpr int BIT_POSITION_USE_CELL_COLOR = 0;
61 static constexpr int BIT_POSITION_USE_POINT_COLOR = 1;
62
63 struct MeshAttributeArrayDescriptor
64 {
65 vtkTypeUInt32 Start = 0;
66 vtkTypeUInt32 NumTuples = 0;
67 vtkTypeUInt32 NumComponents = 0;
68 };
69
70 struct MeshDescriptor
71 {
72 MeshAttributeArrayDescriptor Positions;
73 MeshAttributeArrayDescriptor UVs;
74 MeshAttributeArrayDescriptor Colors;
75 };
76
77 struct ShaderSSBO
78 {
79 wgpu::Buffer Buffer;
80 std::size_t Size;
81 vtkTimeStamp BuildTimeStamp;
82 };
83
84 struct TopologyBindGroupInfo
85 {
86 // buffer for the connectivity
87 wgpu::Buffer ConnectivityBuffer;
88 // buffer for the cell id
89 wgpu::Buffer CellIdBuffer;
90 // uniform buffer for the cell id offset
91 wgpu::Buffer CellIdOffsetUniformBuffer;
92 // bind group for the primitive size uniform.
93 wgpu::BindGroup BindGroup;
94 // vertexCount for draw call.
95 vtkTypeUInt32 VertexCount = 0;
96 };
97
98 bool RebuildGraphicsPipelines = false;
99 bool UseCellScalarMapping = false;
100 bool UsePointScalarMapping = false;
101
102 std::map<GraphicsPipeline2DType, vtkWebGPUCellToPrimitiveConverter::TopologySourceType>
103 PipelineBindGroupCombos = {
105 { GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
108 { GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
111 { GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
113 };
114
115 const std::array<wgpu::PrimitiveTopology, NUM_GFX_PIPELINE_2D_NB_TYPES>
116 GraphicsPipeline2DPrimitiveTypes = { wgpu::PrimitiveTopology::TriangleStrip,
117 wgpu::PrimitiveTopology::TriangleStrip, wgpu::PrimitiveTopology::TriangleStrip,
118 wgpu::PrimitiveTopology::TriangleStrip, wgpu::PrimitiveTopology::TriangleList,
119 wgpu::PrimitiveTopology::TriangleList };
120
121 std::string GraphicsPipeline2DKeys[NUM_GFX_PIPELINE_2D_NB_TYPES];
122
123 vtkSmartPointer<vtkPoints> TransformedPoints;
124
125 vtkNew<vtkMatrix4x4> WCVCMatrix;
126 Mapper2DState State;
127 MeshDescriptor MeshArraysDescriptor;
128
129 ShaderSSBO Mapper2DStateData;
130 ShaderSSBO AttributeDescriptorData;
131 ShaderSSBO MeshData;
132
133 TopologyBindGroupInfo
135
136 wgpu::BindGroup MeshAttributeBindGroup;
137 vtkTimeStamp TextureBindTime;
138 int ActorTextureUnit = -1;
139 wgpu::BindGroupLayout MeshAttributeBindGroupLayout;
140
142 std::unordered_set<vtkWebGPURenderer*> Renderers;
143
147 static wgpu::BindGroupLayout CreateMeshAttributeBindGroupLayout(const wgpu::Device& device,
148 const std::string& label, vtkWebGPURenderTextureDeviceResource* textureDevRc = nullptr);
149
153 static wgpu::BindGroupLayout CreateTopologyBindGroupLayout(
154 const wgpu::Device& device, const std::string& label, bool homogeneousCellSize);
155
159 static const char* GetGraphicsPipelineTypeAsString(GraphicsPipeline2DType graphicsPipelineType);
160
161 static bool IsPipelineForHomogeneousCellSize(GraphicsPipeline2DType graphicsPipelineType);
162
163 void ApplyShaderReplacements(GraphicsPipeline2DType pipelineType, std::string& vss,
164 std::string& fss, vtkWebGPURenderWindow* wgpuRenderWindow, vtkActor2D* actor);
165
166 void ReplaceShaderVertexOutputDef(std::string& vss, std::string& fss);
167 void ReplaceShaderMapperBindings(
168 std::string& vss, std::string& fss, vtkWebGPURenderWindow* wgpuRenderWindow, vtkActor2D* actor);
169
170 void ReplaceVertexShaderConstantsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
171 void ReplaceVertexShaderMapper2DStateDef(std::string& vss);
172 void ReplaceVertexShaderMeshArraysDescriptorDef(std::string& vss);
173 void ReplaceVertexShaderTopologyBindings(std::string& vss);
174 void ReplaceVertexShaderVertexInputDef(std::string& vss);
175 void ReplaceVertexShaderUtilityMethodsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
176 void ReplaceVertexShaderVertexMainStart(std::string& vss);
177 void ReplaceVertexShaderVertexIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
178 void ReplaceVertexShaderPrimitiveIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
179 void ReplaceVertexShaderCellIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
180 void ReplaceVertexShaderPositionImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
181 void ReplaceVertexShaderPickingImpl(std::string& vss);
182 void ReplaceVertexShaderColorsImpl(std::string& vss);
183 void ReplaceVertexShaderUVsImpl(std::string& vss);
184 void ReplaceVertexShaderVertexMainEnd(std::string& vss);
185
186 void ReplaceFragmentShaderFragmentOutputDef(std::string& fss);
187 void ReplaceFragmentShaderFragmentMainStart(std::string& fss);
188 void ReplaceFragmentShaderPickingImpl(std::string& fss);
189 void ReplaceFragmentShaderColorImpl(std::string& fss);
190 void ReplaceFragmentShaderFragmentMainEnd(std::string& fss);
191
192public:
195
202
208
213 void RecordDrawCommands(vtkViewport* viewport, const wgpu::RenderPassEncoder& encoder);
214 void RecordDrawCommands(vtkViewport* viewport, const wgpu::RenderBundleEncoder& encoder);
215};
216
217VTK_ABI_NAMESPACE_END
218
219#endif
220// VTK-HeaderTest-Exclude: vtkWebGPUPolyDataMapper2DInternals.h
a actor that draws 2D data
Definition vtkActor2D.h:145
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:168
represent and manipulate 3D points
Definition vtkPoints.h:140
Hold a reference to a vtkObjectBase instance.
record modification and/or execution time
abstract specification for Viewports
Definition vtkViewport.h:66
void RecordDrawCommands(vtkViewport *viewport, const wgpu::RenderBundleEncoder &encoder)
void UpdateBuffers(vtkViewport *viewport, vtkActor2D *actor, vtkWebGPUPolyDataMapper2D *mapper)
Convert cells to primitives, update topology and mesh data in webgpu buffers used by shader program.
void RecordDrawCommands(vtkViewport *viewport, const wgpu::RenderPassEncoder &encoder)
Record draw calls in the render pass encoder.
void ReleaseGraphicsResources(vtkWindow *w)
Release any graphics resources that are being consumed by this mapper.
2D PolyData support for WebGPU
WebGPU rendering window.
window superclass for vtkRenderWindow
Definition vtkWindow.h:61