VTK  9.7.20260828
vtkWebGPURenderer.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 vtkWebGPURenderer_h
4#define vtkWebGPURenderer_h
5
6#include "vtkRenderer.h"
7
8#include "vtkRenderingWebGPUModule.h" // for export macro
9#include "vtkSmartPointer.h" // for ivar
10#include "vtkWeakPtr.h" // For vtkWeakPtr
11#include "vtkWebGPUComputePipeline.h" // for the compute pipelines used by this renderer
12#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
13#include "vtk_wgpu.h" // for webgpu
14
15#include <unordered_set> // for the set of actors rendered last frame
16#include <vector> // for the list of visible props
17
19class vtkCuller;
20class vtkRenderState;
23VTK_ABI_NAMESPACE_BEGIN
24
26
27class VTKRENDERINGWEBGPU_EXPORT VTK_MARSHALAUTO vtkWebGPURenderer : public vtkRenderer
28{
29public:
34 void PrintSelf(ostream& os, vtkIndent indent) override;
35
36 // get the complexity of the current lights as a int
37 // 0 = no lighting
38 // 1 = headlight
39 // 2 = directional lights
40 // 3 = positional lights
48 vtkGetMacro(LightingComplexity, int);
49
58
62 void Clear() override;
63
67 void DeviceRender() override;
68
75
81 int UpdateGeometry(vtkFrameBufferObjectBase* fbo = nullptr) override;
82
91
97
99
103 const std::vector<vtkSmartPointer<vtkWebGPUComputePipeline>>& GetSetupPreRenderComputePipelines();
104 const std::vector<vtkSmartPointer<vtkWebGPUComputePipeline>>&
107
108 int UpdateLights() override;
109
110 void SetEnvironmentTexture(vtkTexture* texture, bool isSRGB = false) override;
111
113
114 wgpu::RenderPassEncoder GetRenderPassEncoder() { return this->WGPURenderEncoder; }
115 wgpu::RenderBundleEncoder GetRenderBundleEncoder() { return this->WGPUBundleEncoder; }
116 wgpu::BindGroup GetSceneBindGroup() { return this->SceneBindGroup; }
117
118 void PopulateBindgroupLayouts(std::vector<wgpu::BindGroupLayout>& layouts)
119 {
120 layouts.emplace_back(this->SceneBindGroupLayout);
121 }
122
124
131
135 std::unordered_set<vtkProp*> GetPropsRendered() { return this->PropsRendered; }
136
138
145
147
163 vtkSetMacro(UseRenderBundles, bool);
164 vtkBooleanMacro(UseRenderBundles, bool);
165 vtkGetMacro(UseRenderBundles, bool);
167
178
203 {
204 this->RebuildRenderBundle = true;
205 this->Bundle = nullptr;
206 }
207
211 vtkGetMacro(RebuildRenderBundle, bool);
212
213protected:
216
225
226private:
228 // For the mapper to access 'AddPostRasterizationActor'
230 // For render window accessing PostRenderComputePipelines()
232
233 vtkWebGPURenderer(const vtkWebGPURenderer&) = delete;
234 void operator=(const vtkWebGPURenderer&) = delete;
235
236 // Setup scene and actor bindgroups. Actor has dynamic offsets.
237 void SetupBindGroupLayouts();
238 // Create buffers for the bind groups.
239 void CreateBuffers();
240 // Create scene bind group.
241 void SetupSceneBindGroup();
242
243 // Start, finish recording commands.
244 void BeginRecording();
245 void EndRecording();
246
247 std::size_t WriteLightsBuffer(std::size_t offset = 0);
248 std::size_t WriteSceneTransformsBuffer(std::size_t offset = 0);
249
253 void InitComputePipeline(vtkSmartPointer<vtkWebGPUComputePipeline> pipeline);
254
256
263 void PreRenderComputePipelines();
264 void PostRenderComputePipelines();
266
277 void PostRasterizationRender();
278
282 void AddPostRasterizationActor(vtkActor* actor);
283
288 std::vector<vtkSmartPointer<vtkWebGPUComputePipeline>> SetupPreRenderComputePipelines;
289 std::vector<vtkSmartPointer<vtkWebGPUComputePipeline>> SetupPostRenderComputePipelines;
290
294 std::vector<vtkSmartPointer<vtkWebGPUComputePipeline>> NotSetupPreRenderComputePipelines;
295 std::vector<vtkSmartPointer<vtkWebGPUComputePipeline>> NotSetupPostRenderComputePipelines;
296
304 std::vector<vtkActor*> PostRasterizationActors;
305
309 wgpu::CommandBuffer EncodePropListRenderCommand(vtkProp** propList, int listLength);
310
316 void RecordRenderCommands();
317
318 wgpu::RenderPassEncoder WGPURenderEncoder;
319 wgpu::RenderBundleEncoder WGPUBundleEncoder;
320 wgpu::Buffer SceneTransformBuffer;
321 wgpu::Buffer SceneLightsBuffer;
322
323 wgpu::BindGroup SceneBindGroup;
324 wgpu::BindGroupLayout SceneBindGroupLayout;
325
326 // Render bundles enable faster rendering.
327 bool UseRenderBundles = true;
328 bool RebuildRenderBundle = false;
329 // the commands in bundle get reused every frame.
330 wgpu::RenderBundle Bundle;
331
332 int LightingComplexity = 0;
333 std::size_t NumberOfLightsUsed = 0;
334 std::vector<std::size_t> LightIDs;
335 std::size_t AllocatedLightsBufferSize = 0;
336 std::size_t PreviousLightCount = 0;
337
338 vtkMTimeType LightingUpdateTime;
339 vtkTimeStamp LightingUploadTimestamp;
340
344 vtkSmartPointer<vtkTransform> UserLightTransform;
345
350 bool ComputeBuffersInitialized = false;
351
357
361 bool DrawBackgroundInClearPass = true;
362
369 std::unordered_set<vtkProp*> PropsRendered;
370
381 std::vector<vtkProp*> LastVisibleProps;
382
388 std::vector<vtkProp*> VisibleProps;
389
394 bool VisiblePropSetChanged();
395
401 bool CanReuseRenderBundle() const
402 {
403 return this->UseRenderBundles && !this->RebuildRenderBundle && this->Bundle != nullptr;
404 }
405
411 bool PropSupportsReusingRenderBundle(vtkProp*) const;
412
418 void WarnIfCullingWithRenderBundles();
419
421 vtkWeakPtr<vtkCuller> DefaultCuller;
422 bool WarnedAboutCullingWithRenderBundles = false;
423};
424
425#define vtkWebGPURenderer_OVERRIDE_ATTRIBUTES vtkWebGPURenderer::CreateOverrideAttributes()
426VTK_ABI_NAMESPACE_END
427#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
a superclass for prop cullers
Definition vtkCuller.h:31
abstract interface to OpenGL FBOs
a simple class to control print indentation
Definition vtkIndent.h:108
Attribute for vtkObjectFactory overrides.
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:68
Context in which a vtkRenderPass will render.
Hold a reference to a vtkObjectBase instance.
handles properties associated with a texture map
Definition vtkTexture.h:168
record modification and/or execution time
describes linear transformations via a 4x4 matrix
a weak reference to a vtkObjectBase.
Definition vtkWeakPtr.h:52
This culler does both frustum culling and occlusion culling.
void ConfigureComputeRenderBuffers(vtkSmartPointer< vtkWebGPUComputePipeline > computePipeline)
Set up the buffers of a given vtkWebGPUComputePass.
friend class vtkWebGPUComputePointCloudMapper
void ReleaseGraphicsResources(vtkWindow *w) override
static vtkWebGPURenderer * New()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void ConfigureComputePipelines()
Sets the adapter and the device of the render window of this renderer to the compute pipelines of thi...
void AddPostRenderComputePipeline(vtkSmartPointer< vtkWebGPUComputePipeline > pipeline)
Adds a compute pipeline to the renderer that will be executed each frame before/after the rendering p...
wgpu::BindGroup GetSceneBindGroup()
int UpdateOpaquePolygonalGeometry() override
Request mappers to run the vtkAlgorithm pipeline (if needed) and consequently update device buffers c...
int UpdateTranslucentPolygonalGeometry() override
Ask all props to update and draw any translucent polygonal geometry.
int UpdateGeometry(vtkFrameBufferObjectBase *fbo=nullptr) override
Ask all props to update and draw any opaque and translucent geometry.
friend class vtkWebGPUComputeOcclusionCuller
int UpdateLights() override
Ask all lights to load themselves into rendering pipeline.
void SetUserLightTransform(vtkTransform *transform)
Set the user light transform applied after the camera transform.
void PopulateBindgroupLayouts(std::vector< wgpu::BindGroupLayout > &layouts)
std::unordered_set< vtkProp * > GetPropsRendered()
Returns the list of the actors that were rendered last frame.
void Clear() override
Clear the image to the background color.
vtkTransform * GetUserLightTransform()
Set the user light transform applied after the camera transform.
static vtkOverrideAttribute * CreateOverrideAttributes()
void DeviceRender() override
Create an image.
void InvalidateBundle()
Forces the renderer to re-record draw commands into a render bundle.
void AddPreRenderComputePipeline(vtkSmartPointer< vtkWebGPUComputePipeline > pipeline)
Adds a compute pipeline to the renderer that will be executed each frame before/after the rendering p...
wgpu::RenderBundleEncoder GetRenderBundleEncoder()
~vtkWebGPURenderer() override
wgpu::RenderPassEncoder GetRenderPassEncoder()
void UpdateBuffers()
Updates / creates the various buffer necessary for the rendering of the props.
const std::vector< vtkSmartPointer< vtkWebGPUComputePipeline > > & GetSetupPostRenderComputePipelines()
Returns the list of compute pipelines of this renderer that have been setup for execution before/afte...
friend class vtkWebGPURenderWindow
vtkGetEnumMacro(RenderStage, RenderStageEnum)
Query the stage in the rendering process.
const std::vector< vtkSmartPointer< vtkWebGPUComputePipeline > > & GetSetupPreRenderComputePipelines()
Returns the list of compute pipelines of this renderer that have been setup for execution before/afte...
void SetEnvironmentTexture(vtkTexture *texture, bool isSRGB=false) override
Set/Get the environment texture used for image based lighting.
window superclass for vtkRenderWindow
Definition vtkWindow.h:62
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:318
#define VTK_MARSHALAUTO
#define VTK_NEWINSTANCE