VTK  9.7.20260805
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
17
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
31VTK_ABI_NAMESPACE_BEGIN
32
36
37class VTKRENDERINGWEBGPU_EXPORT VTK_MARSHALAUTO vtkWebGPUConfiguration : public vtkObject
38{
39public:
42 void PrintSelf(ostream& os, vtkIndent indent) override;
43
54
67
69
80
82
99
101
109 vtkSetMacro(Timeout, double);
110 vtkGetMacro(Timeout, double);
112
116 static void SetDefaultTimeout(double);
117
125
130
132
135 wgpu::Adapter GetAdapter();
136 wgpu::Device GetDevice();
137 wgpu::Instance GetInstance();
139
158
166
183 void Finalize();
184
194
201 static std::size_t Align(std::size_t value, std::size_t alignment);
202
203 enum
204 {
207 };
208
212 std::string ReportCapabilities();
213 static std::string DeviceNotReadyMessage();
214
221 std::uint32_t GetAdapterVendorID();
222 std::uint32_t GetAdapterDeviceID();
223
225
243
245
250 wgpu::Buffer CreateBuffer(std::uint64_t sizeBytes, wgpu::BufferUsage usage,
251 bool mappedAtCreation = false, const char* label = nullptr);
252 wgpu::Buffer CreateBuffer(const wgpu::BufferDescriptor& bufferDescriptor);
254
259 void WriteBuffer(const wgpu::Buffer& buffer, std::uint64_t offset, const void* data,
260 std::size_t sizeBytes, const char* description = nullptr);
261
263
266 wgpu::Texture CreateTexture(wgpu::Extent3D extents, wgpu::TextureDimension dimension,
267 wgpu::TextureFormat format, wgpu::TextureUsage usage, int mipLevelCount = 1,
268 const char* label = nullptr);
269 wgpu::Texture CreateTexture(const wgpu::TextureDescriptor& textureDescriptor);
271
275 wgpu::TextureView CreateView(wgpu::Texture texture, wgpu::TextureViewDimension dimension,
276 wgpu::TextureAspect aspect, wgpu::TextureFormat format, int baseMipLevel, int mipLevelCount,
277 const char* label = nullptr);
278 wgpu::TextureView CreateView(
279 wgpu::Texture texture, const wgpu::TextureViewDescriptor& viewDescriptor);
280
285 void WriteTexture(wgpu::Texture texture, uint32_t bytesPerRow, uint32_t byteSize,
286 const void* data, uint32_t srcOffset = 0, wgpu::Origin3D dstOffset = { 0, 0, 0 },
287 uint32_t dstMipLevel = 0, const char* description = nullptr);
288
290
304
312
313protected:
316
317private:
319 void operator=(const vtkWebGPUConfiguration&) = delete;
320
322 std::unique_ptr<vtkWebGPUConfigurationInternals> Internals;
323
325 // Initialized in constructor at runtime based on the operating system.
326 BackendType Backend;
327 // In milliseconds
328 double Timeout;
329
331 // Tracks whether AddInstanceRef() was called so Finalize() can release it
332 // even after FinalizeDevice() has already set DeviceReady=false.
333 bool InstanceRefHeld = false;
334};
335
336VTK_ABI_NAMESPACE_END
337
338#endif
a simple class to control print indentation
Definition vtkIndent.h:29
@ VERBOSITY_INVALID
Definition vtkLogger.h:195
A compute pipeline is the orchestrator of a collection of compute passes.
vtkGetEnumMacro(PowerPreference, PowerPreferenceType)
Set/Get the power preference of the graphics adapter.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool IsMicrosoftGPUInUse()
Checks whether a particular vendor's GPU is in use.
wgpu::TextureView CreateView(wgpu::Texture texture, const wgpu::TextureViewDescriptor &viewDescriptor)
wgpu::Device GetDevice()
Get handles of the WGPU adapter/device/instance.
vtkLogger::Verbosity GetGPUMemoryLogVerbosity()
Set/Get the log verbosity of messages that are emitted when data is uploaded to GPU memory.
bool IsBroadcomGPUInUse()
Checks whether a particular vendor's GPU is in use.
wgpu::Texture CreateTexture(wgpu::Extent3D extents, wgpu::TextureDimension dimension, wgpu::TextureFormat format, wgpu::TextureUsage usage, int mipLevelCount=1, const char *label=nullptr)
Creates a WebGPU texture with the given device and returns it.
PowerPreferenceType
These enums have a one-one correspondence with the webgpu enums.
BackendType GetBackendInUse()
Get the backend in use.
vtkGetEnumMacro(Backend, BackendType)
Set/Get the graphics backend to use from the graphics adapter.
std::uint32_t GetAdapterDeviceID()
static std::size_t Align(std::size_t value, std::size_t alignment)
Adjusts a given value to the nearest multiple of the specified alignment.
~vtkWebGPUConfiguration() override
wgpu::Buffer CreateBuffer(const wgpu::BufferDescriptor &bufferDescriptor)
Convenient methods used to create webgpu buffers.
wgpu::Buffer CreateBuffer(std::uint64_t sizeBytes, wgpu::BufferUsage usage, bool mappedAtCreation=false, const char *label=nullptr)
Convenient methods used to create webgpu buffers.
static vtkWebGPUConfiguration * New()
void SetGPUMemoryLogVerbosity(vtkLogger::Verbosity verbosity)
Set/Get the log verbosity of messages that are emitted when data is uploaded to GPU memory.
static void SetDefaultTimeout(double)
Use this method to customize the default value for Timeout.
bool IsAppleGPUInUse()
Checks whether a particular vendor's GPU is in use.
vtkSetEnumMacro(Backend, BackendType)
Set/Get the graphics backend to use from the graphics adapter.
VTK_MAYSUSPEND bool Initialize()
Initializes the class.
std::string ReportCapabilities()
Print information of webgpu adapter and device to the output string.
wgpu::TextureView CreateView(wgpu::Texture texture, wgpu::TextureViewDimension dimension, wgpu::TextureAspect aspect, wgpu::TextureFormat format, int baseMipLevel, int mipLevelCount, const char *label=nullptr)
Creates a texture view of a texture.
wgpu::Texture CreateTexture(const wgpu::TextureDescriptor &textureDescriptor)
Creates a WebGPU texture with the given device and returns it.
bool IsAMDGPUInUse()
Checks whether a particular vendor's GPU is in use.
void DumpMemoryStatistics()
This method prints the information corresponding to all active wgpu::Buffer and wgpu::Texture objects...
void Finalize()
Finalizes the class.
bool IsNVIDIAGPUInUse()
Checks whether a particular vendor's GPU is in use.
void FinalizeDevice()
Destroys the WebGPU device and adapter without releasing the shared instance.
VTK_MAYSUSPEND void ProcessEvents()
Process events on the WGPUInstance.
vtkSetEnumMacro(PowerPreference, PowerPreferenceType)
Set/Get the power preference of the graphics adapter.
bool IsIntelGPUInUse()
Checks whether a particular vendor's GPU is in use.
bool IsARMGPUInUse()
Checks whether a particular vendor's GPU is in use.
void WriteBuffer(const wgpu::Buffer &buffer, std::uint64_t offset, const void *data, std::size_t sizeBytes, const char *description=nullptr)
Convenient method used to write data into an existing buffer.
std::uint32_t GetAdapterVendorID()
Get the PCI vendor ID of the adapter and the system PCI ID of the device.
bool IsMesaGPUInUse()
Checks whether a particular vendor's GPU is in use.
bool IsSamsungGPUInUse()
Checks whether a particular vendor's GPU is in use.
static std::string DeviceNotReadyMessage()
std::string GetBackendInUseAsString()
Convenient function returns a string representation of the currently used backend.
wgpu::Instance GetInstance()
Get handles of the WGPU adapter/device/instance.
void WriteTexture(wgpu::Texture texture, uint32_t bytesPerRow, uint32_t byteSize, const void *data, uint32_t srcOffset=0, wgpu::Origin3D dstOffset={ 0, 0, 0 }, uint32_t dstMipLevel=0, const char *description=nullptr)
Upload byteSize of data from the data pointer to the given texture, assuming bytesPerRow bytes of dat...
wgpu::Adapter GetAdapter()
Get handles of the WGPU adapter/device/instance.
WebGPU rendering window.
#define VTK_MAYSUSPEND
#define VTK_MARSHALAUTO