VTK  9.4.20250130
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 "vtk_wgpu.h" // for wgpu
27
28#include <memory> // for unique_ptr
29
30VTK_ABI_NAMESPACE_BEGIN
31
35
36class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUConfiguration : public vtkObject
37{
38public:
41 void PrintSelf(ostream& os, vtkIndent indent) override;
42
48 {
49 Undefined,
50 LowPower,
51 HighPerformance
52 };
53
54 enum class BackendType
55 {
56 Undefined,
57 Null,
58 WebGPU,
59 D3D11,
60 D3D12,
61 Metal,
62 Vulkan,
63 OpenGL,
64 OpenGLES
65 };
66
68
79
81
98
100
108 vtkSetMacro(Timeout, double);
109 vtkGetMacro(Timeout, double);
111
115 static void SetDefaultTimeout(double);
116
124
129
131
134 wgpu::Adapter GetAdapter();
135 wgpu::Device GetDevice();
136 wgpu::Instance GetInstance();
138
156
162 void Finalize();
163
172
179 static std::size_t Align(std::size_t value, std::size_t alignment);
180
181 enum
182 {
183 AdapterRequestCompletedEvent = vtkCommand::UserEvent,
185 };
186
190 std::string ReportCapabilities();
191 static std::string DeviceNotReadyMessage();
192
199 std::uint32_t GetAdapterVendorID();
200 std::uint32_t GetAdapterDeviceID();
201
203
221
223
228 wgpu::Buffer CreateBuffer(unsigned long sizeBytes, wgpu::BufferUsage usage,
229 bool mappedAtCreation = false, const char* label = nullptr);
230 wgpu::Buffer CreateBuffer(const wgpu::BufferDescriptor& bufferDescriptor);
232
237 void WriteBuffer(const wgpu::Buffer& buffer, unsigned long offset, const void* data,
238 unsigned long sizeBytes, const char* description = nullptr);
239
241
244 wgpu::Texture CreateTexture(wgpu::Extent3D extents, wgpu::TextureDimension dimension,
245 wgpu::TextureFormat format, wgpu::TextureUsage usage, int mipLevelCount = 1,
246 const char* label = nullptr);
247 wgpu::Texture CreateTexture(const wgpu::TextureDescriptor& textureDescriptor);
249
253 wgpu::TextureView CreateView(wgpu::Texture texture, wgpu::TextureViewDimension dimension,
254 wgpu::TextureAspect aspect, wgpu::TextureFormat format, int baseMipLevel, int mipLevelCount,
255 const char* label = nullptr);
256 wgpu::TextureView CreateView(
257 wgpu::Texture texture, const wgpu::TextureViewDescriptor& viewDescriptor);
258
263 void WriteTexture(wgpu::Texture texture, uint32_t bytesPerRow, uint32_t byteSize,
264 const void* data, const char* description = nullptr);
265
267
281
289
290protected:
293
294 PowerPreferenceType PowerPreference = PowerPreferenceType::HighPerformance;
295 // Initialized in constructor at runtime based on the operating system.
297 // In milliseconds
298 double Timeout;
299
301
302 void AcquireAdapter(vtkObject* caller, unsigned long event, void* calldata);
303
304 void AcquireDevice(vtkObject* caller, unsigned long event, void* calldata);
305
306private:
308 void operator=(const vtkWebGPUConfiguration&) = delete;
309
311 std::unique_ptr<vtkWebGPUConfigurationInternals> Internals;
312};
313
314VTK_ABI_NAMESPACE_END
315
316#endif
a simple class to control print indentation
Definition vtkIndent.h:108
@ VERBOSITY_INVALID
Definition vtkLogger.h:214
abstract base class for most VTK objects
Definition vtkObject.h:162
A compute pipeline is the orchestrator of a collection of compute passes.
Create a webgpu device for use in rendering and compute pipelines.
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.
void AcquireAdapter(vtkObject *caller, unsigned long event, void *calldata)
~vtkWebGPUConfiguration() override
wgpu::Buffer CreateBuffer(const wgpu::BufferDescriptor &bufferDescriptor)
Convenient methods used to create webgpu buffers.
wgpu::Buffer CreateBuffer(unsigned long sizeBytes, wgpu::BufferUsage usage, bool mappedAtCreation=false, const char *label=nullptr)
Convenient methods used to create webgpu buffers.
static vtkWebGPUConfiguration * New()
void WriteBuffer(const wgpu::Buffer &buffer, unsigned long offset, const void *data, unsigned long sizeBytes, const char *description=nullptr)
Convenient method used to write data into an existing buffer.
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.
void WriteTexture(wgpu::Texture texture, uint32_t bytesPerRow, uint32_t byteSize, const void *data, const char *description=nullptr)
Upload byteSize of data from the data pointer to the given texture, assuming bytesPerRow bytes of dat...
void AcquireDevice(vtkObject *caller, unsigned long event, void *calldata)
vtkSetEnumMacro(Backend, BackendType)
Set/Get the graphics backend to use from the graphics adapter.
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.
vtkSetEnumMacro(PowerPreference, PowerPreferenceType)
Set/Get the power preference of the graphics adapter.
void ProcessEvents()
Process events on the WGPUInstance.
bool IsIntelGPUInUse()
Checks whether a particular vendor's GPU is in use.
bool IsARMGPUInUse()
Checks whether a particular vendor's GPU is in use.
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.
bool Initialize()
Initializes the class.
wgpu::Adapter GetAdapter()
Get handles of the WGPU adapter/device/instance.
WebGPU rendering window.