VTK  9.7.20260913
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
8#include "vtkNew.h"
9#include "vtkRenderingWebGPUModule.h"
10#include "vtkSmartPointer.h"
11#include "vtkTimeStamp.h"
13
14#include "vtk_wgpu.h"
15#include <unordered_set>
16
17VTK_ABI_NAMESPACE_BEGIN
18
19class vtkPoints;
20class vtkMatrix4x4;
21class vtkViewport;
22class vtkActor2D;
27
31class VTKRENDERINGWEBGPU_NO_EXPORT vtkWebGPUPolyDataMapper2DInternals
32{
38 enum GraphicsPipeline2DType : int
39 {
40 // Pipeline that renders points
41 GFX_PIPELINE_2D_POINTS = 0,
42 GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
43 // Pipeline that renders lines
44 GFX_PIPELINE_2D_LINES,
45 GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
46 // Pipeline that renders triangles
47 GFX_PIPELINE_2D_TRIANGLES,
48 GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
49 NUM_GFX_PIPELINE_2D_NB_TYPES
50 };
51
52 struct Mapper2DState
53 {
54 vtkTypeFloat32 WCVCMatrix[4][4];
55 vtkTypeFloat32 Color[4];
56 vtkTypeFloat32 PointSize;
57 vtkTypeFloat32 LineWidth;
58 vtkTypeUInt32 Flags;
59 vtkTypeUInt32 Padding;
60 };
61 static constexpr int BIT_POSITION_USE_CELL_COLOR = 0;
62 static constexpr int BIT_POSITION_USE_POINT_COLOR = 1;
63
64 struct MeshAttributeArrayDescriptor
65 {
66 vtkTypeUInt32 Start = 0;
67 vtkTypeUInt32 NumTuples = 0;
68 vtkTypeUInt32 NumComponents = 0;
69 };
70
71 struct MeshDescriptor
72 {
73 MeshAttributeArrayDescriptor Positions;
74 MeshAttributeArrayDescriptor UVs;
75 MeshAttributeArrayDescriptor Colors;
76 };
77
78 struct ShaderSSBO
79 {
80 vtkWebGPU::Buffer Buffer;
81 std::size_t Size;
82 vtkTimeStamp BuildTimeStamp;
83 };
84
85 struct TopologyBindGroupInfo
86 {
87 // buffer for the connectivity
88 vtkWebGPU::Buffer ConnectivityBuffer;
89 // buffer for the cell id
90 vtkWebGPU::Buffer CellIdBuffer;
91 // uniform buffer for the cell id offset
92 vtkWebGPU::Buffer CellIdOffsetUniformBuffer;
93 // bind group for the primitive size uniform.
94 vtkWebGPU::BindGroup BindGroup;
95 // vertexCount for draw call.
96 vtkTypeUInt32 VertexCount = 0;
97 };
98
99 bool RebuildGraphicsPipelines = false;
100 bool UseCellScalarMapping = false;
101 bool UsePointScalarMapping = false;
102
103 std::map<GraphicsPipeline2DType, vtkWebGPUCellToPrimitiveConverter::TopologySourceType>
104 PipelineBindGroupCombos = {
106 { GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
109 { GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
112 { GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
114 };
115
116 const std::array<WGPUPrimitiveTopology, NUM_GFX_PIPELINE_2D_NB_TYPES>
117 GraphicsPipeline2DPrimitiveTypes = { WGPUPrimitiveTopology_TriangleStrip,
118 WGPUPrimitiveTopology_TriangleStrip, WGPUPrimitiveTopology_TriangleStrip,
119 WGPUPrimitiveTopology_TriangleStrip, WGPUPrimitiveTopology_TriangleList,
120 WGPUPrimitiveTopology_TriangleList };
121
122 std::string GraphicsPipeline2DKeys[NUM_GFX_PIPELINE_2D_NB_TYPES];
123
124 vtkSmartPointer<vtkPoints> TransformedPoints;
125
126 vtkNew<vtkMatrix4x4> WCVCMatrix;
127 Mapper2DState State;
128 MeshDescriptor MeshArraysDescriptor;
129
130 ShaderSSBO Mapper2DStateData;
131 ShaderSSBO AttributeDescriptorData;
132 ShaderSSBO MeshData;
133
134 TopologyBindGroupInfo
136
137 vtkWebGPU::BindGroup MeshAttributeBindGroup;
138 vtkTimeStamp TextureBindTime;
139 int ActorTextureUnit = -1;
140 vtkWebGPU::BindGroupLayout MeshAttributeBindGroupLayout;
141
143 std::unordered_set<vtkWebGPURenderer*> Renderers;
144
148 static vtkWebGPU::BindGroupLayout CreateMeshAttributeBindGroupLayout(const WGPUDevice& device,
149 const std::string& label, vtkWebGPURenderTextureDeviceResource* textureDevRc = nullptr);
150
154 static vtkWebGPU::BindGroupLayout CreateTopologyBindGroupLayout(
155 const WGPUDevice& device, const std::string& label, bool homogeneousCellSize);
156
160 static const char* GetGraphicsPipelineTypeAsString(GraphicsPipeline2DType graphicsPipelineType);
161
162 static bool IsPipelineForHomogeneousCellSize(GraphicsPipeline2DType graphicsPipelineType);
163
164 void ApplyShaderReplacements(GraphicsPipeline2DType pipelineType, std::string& vss,
165 std::string& fss, vtkWebGPURenderWindow* wgpuRenderWindow, vtkActor2D* actor);
166
167 void ReplaceShaderVertexOutputDef(std::string& vss, std::string& fss);
168 void ReplaceShaderMapperBindings(
169 std::string& vss, std::string& fss, vtkWebGPURenderWindow* wgpuRenderWindow, vtkActor2D* actor);
170
171 void ReplaceVertexShaderConstantsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
172 void ReplaceVertexShaderMapper2DStateDef(std::string& vss);
173 void ReplaceVertexShaderMeshArraysDescriptorDef(std::string& vss);
174 void ReplaceVertexShaderTopologyBindings(std::string& vss);
175 void ReplaceVertexShaderVertexInputDef(std::string& vss);
176 void ReplaceVertexShaderUtilityMethodsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
177 void ReplaceVertexShaderVertexMainStart(std::string& vss);
178 void ReplaceVertexShaderVertexIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
179 void ReplaceVertexShaderPrimitiveIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
180 void ReplaceVertexShaderCellIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
181 void ReplaceVertexShaderPositionImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
182 void ReplaceVertexShaderPickingImpl(std::string& vss);
183 void ReplaceVertexShaderColorsImpl(std::string& vss);
184 void ReplaceVertexShaderUVsImpl(std::string& vss);
185 void ReplaceVertexShaderVertexMainEnd(std::string& vss);
186
187 void ReplaceFragmentShaderFragmentOutputDef(std::string& fss);
188 void ReplaceFragmentShaderFragmentMainStart(std::string& fss);
189 void ReplaceFragmentShaderPickingImpl(std::string& fss);
190 void ReplaceFragmentShaderColorImpl(std::string& fss);
191 void ReplaceFragmentShaderFragmentMainEnd(std::string& fss);
192
193public:
196
203
209
214 void RecordDrawCommands(vtkViewport* viewport, const WGPURenderPassEncoder& encoder);
215 void RecordDrawCommands(vtkViewport* viewport, const WGPURenderBundleEncoder& encoder);
216};
217
218VTK_ABI_NAMESPACE_END
219
220#endif
221// 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 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 WGPURenderBundleEncoder &encoder)
void ReleaseGraphicsResources(vtkWindow *w)
Release any graphics resources that are being consumed by this mapper.
void RecordDrawCommands(vtkViewport *viewport, const WGPURenderPassEncoder &encoder)
Record draw calls in the render pass encoder.
2D PolyData support for WebGPU
WebGPU rendering window.
window superclass for vtkRenderWindow
Definition vtkWindow.h:62
Reference-counted ownership for WebGPU C API handles.