VTK  9.7.1
vtkWebGPUConfiguration.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
18 #ifndef vtkWebGPUConfiguration_h
19 #define vtkWebGPUConfiguration_h
20 
21 #include "vtkObject.h"
22 
23 #include "vtkCommand.h" // for vtkCommand
24 #include "vtkLogger.h" // for vtkLogger::Verbosity enum
25 #include "vtkRenderingWebGPUModule.h" // for export macro
26 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
27 #include "vtk_wgpu.h" // for wgpu
28 
29 #include <memory> // for unique_ptr
30 
31 VTK_ABI_NAMESPACE_BEGIN
32 
36 
37 class VTKRENDERINGWEBGPU_EXPORT VTK_MARSHALAUTO vtkWebGPUConfiguration : public vtkObject
38 {
39 public:
40  static vtkWebGPUConfiguration* New();
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
49  {
50  Undefined,
51  LowPower,
52  HighPerformance
53  };
54 
55  enum class BackendType
56  {
57  Undefined,
58  Null,
59  WebGPU,
60  D3D11,
61  D3D12,
62  Metal,
63  Vulkan,
64  OpenGL,
65  OpenGLES
66  };
67 
69 
77  vtkSetEnumMacro(PowerPreference, PowerPreferenceType);
78  vtkGetEnumMacro(PowerPreference, PowerPreferenceType);
80 
82 
96  vtkSetEnumMacro(Backend, BackendType);
97  vtkGetEnumMacro(Backend, BackendType);
99 
101 
109  vtkSetMacro(Timeout, double);
110  vtkGetMacro(Timeout, double);
112 
116  static void SetDefaultTimeout(double);
117 
124  BackendType GetBackendInUse();
125 
129  std::string GetBackendInUseAsString();
130 
132 
135  wgpu::Adapter GetAdapter();
136  wgpu::Device GetDevice();
137  wgpu::Instance GetInstance();
139 
156  bool Initialize();
157 
164  void FinalizeDevice();
165 
182  void Finalize();
183 
191  void ProcessEvents();
192 
199  static std::size_t Align(std::size_t value, std::size_t alignment);
200 
201  enum
202  {
203  AdapterRequestCompletedEvent = vtkCommand::UserEvent,
205  };
206 
210  std::string ReportCapabilities();
211  static std::string DeviceNotReadyMessage();
212 
219  std::uint32_t GetAdapterVendorID();
220  std::uint32_t GetAdapterDeviceID();
221 
223 
231  bool IsAMDGPUInUse();
232  bool IsAppleGPUInUse();
233  bool IsARMGPUInUse();
234  bool IsBroadcomGPUInUse();
235  bool IsIntelGPUInUse();
236  bool IsMesaGPUInUse();
237  bool IsMicrosoftGPUInUse();
238  bool IsNVIDIAGPUInUse();
239  bool IsSamsungGPUInUse();
241 
243 
248  wgpu::Buffer CreateBuffer(std::uint64_t sizeBytes, wgpu::BufferUsage usage,
249  bool mappedAtCreation = false, const char* label = nullptr);
250  wgpu::Buffer CreateBuffer(const wgpu::BufferDescriptor& bufferDescriptor);
252 
257  void WriteBuffer(const wgpu::Buffer& buffer, std::uint64_t offset, const void* data,
258  std::size_t sizeBytes, const char* description = nullptr);
259 
261 
264  wgpu::Texture CreateTexture(wgpu::Extent3D extents, wgpu::TextureDimension dimension,
265  wgpu::TextureFormat format, wgpu::TextureUsage usage, int mipLevelCount = 1,
266  const char* label = nullptr);
267  wgpu::Texture CreateTexture(const wgpu::TextureDescriptor& textureDescriptor);
269 
273  wgpu::TextureView CreateView(wgpu::Texture texture, wgpu::TextureViewDimension dimension,
274  wgpu::TextureAspect aspect, wgpu::TextureFormat format, int baseMipLevel, int mipLevelCount,
275  const char* label = nullptr);
276  wgpu::TextureView CreateView(
277  wgpu::Texture texture, const wgpu::TextureViewDescriptor& viewDescriptor);
278 
283  void WriteTexture(wgpu::Texture texture, uint32_t bytesPerRow, uint32_t byteSize,
284  const void* data, uint32_t srcOffset = 0, wgpu::Origin3D dstOffset = { 0, 0, 0 },
285  uint32_t dstMipLevel = 0, const char* description = nullptr);
286 
288 
299  void SetGPUMemoryLogVerbosity(vtkLogger::Verbosity verbosity);
300  vtkLogger::Verbosity GetGPUMemoryLogVerbosity();
302 
309  void DumpMemoryStatistics();
310 
311 protected:
313  ~vtkWebGPUConfiguration() override;
314 
315 private:
317  void operator=(const vtkWebGPUConfiguration&) = delete;
318 
320  std::unique_ptr<vtkWebGPUConfigurationInternals> Internals;
321 
322  PowerPreferenceType PowerPreference = PowerPreferenceType::HighPerformance;
323  // Initialized in constructor at runtime based on the operating system.
324  BackendType Backend;
325  // In milliseconds
326  double Timeout;
327 
328  vtkLogger::Verbosity GPUMemoryLogVerbosity = vtkLogger::VERBOSITY_INVALID;
329  // Tracks whether AddInstanceRef() was called so Finalize() can release it
330  // even after FinalizeDevice() has already set DeviceReady=false.
331  bool InstanceRefHeld = false;
332 };
333 
334 VTK_ABI_NAMESPACE_END
335 
336 #endif
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.
PowerPreferenceType
These enums have a one-one correspondence with the webgpu enums.
a simple class to control print indentation
Definition: vtkIndent.h:28
Create a webgpu device for use in rendering and compute pipelines.
A compute pipeline is the orchestrator of a collection of compute passes.
#define VTK_MARSHALAUTO
WebGPU rendering window.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...