VTK  9.7.20260918
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 webgpu C API
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
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
80
82
99
101
109 vtkSetMacro(Timeout, double);
110 vtkGetMacro(Timeout, double);
112
116 static void SetDefaultTimeout(double);
117
125
130
132
135 WGPUAdapter GetAdapter();
136 WGPUDevice GetDevice();
137 WGPUInstance GetInstance();
139
158
166
183 void Finalize();
184
194
196
203 void IncrementActiveBufferMapCount() { ++this->ActiveBufferMapCount; }
204 void DecrementActiveBufferMapCount() { --this->ActiveBufferMapCount; }
205 int GetActiveBufferMapCount() const { return this->ActiveBufferMapCount; }
207
214 static std::size_t Align(std::size_t value, std::size_t alignment);
215
216 enum
217 {
220 };
221
225 std::string ReportCapabilities();
226 static std::string DeviceNotReadyMessage();
227
234 std::uint32_t GetAdapterVendorID();
235 std::uint32_t GetAdapterDeviceID();
236
238
256
267 void DeferBufferRelease(WGPUBuffer buffer);
268
270
275 WGPUBuffer CreateBuffer(std::uint64_t sizeBytes, WGPUBufferUsage usage,
276 bool mappedAtCreation = false, const char* label = nullptr);
277 WGPUBuffer CreateBuffer(const WGPUBufferDescriptor& bufferDescriptor);
279
284 void WriteBuffer(WGPUBuffer buffer, std::uint64_t offset, const void* data, std::size_t sizeBytes,
285 const char* description = nullptr);
286
288
291 WGPUTexture CreateTexture(WGPUExtent3D extents, WGPUTextureDimension dimension,
292 WGPUTextureFormat format, WGPUTextureUsage usage, int mipLevelCount = 1,
293 const char* label = nullptr);
294 WGPUTexture CreateTexture(const WGPUTextureDescriptor& textureDescriptor);
296
300 WGPUTextureView CreateView(WGPUTexture texture, WGPUTextureViewDimension dimension,
301 WGPUTextureAspect aspect, WGPUTextureFormat format, int baseMipLevel, int mipLevelCount,
302 const char* label = nullptr);
303 WGPUTextureView CreateView(WGPUTexture texture, const WGPUTextureViewDescriptor& viewDescriptor);
304
309 void WriteTexture(WGPUTexture texture, uint32_t bytesPerRow, uint32_t byteSize, const void* data,
310 uint32_t srcOffset = 0, WGPUOrigin3D dstOffset = { 0, 0, 0 }, uint32_t dstMipLevel = 0,
311 const char* description = nullptr);
312
314
328
336
337protected:
340
341private:
343 void operator=(const vtkWebGPUConfiguration&) = delete;
344
346 std::unique_ptr<vtkWebGPUConfigurationInternals> Internals;
347
348 // Number of in-flight asynchronous buffer map (readback) operations. See
349 // IncrementActiveBufferMapCount().
350 int ActiveBufferMapCount = 0;
351
353 // Initialized in constructor at runtime based on the operating system.
354 BackendType Backend;
355 // In milliseconds
356 double Timeout;
357
359 // Tracks whether AddInstanceRef() was called so Finalize() can release it
360 // even after FinalizeDevice() has already set DeviceReady=false.
361 bool InstanceRefHeld = false;
362};
363
364VTK_ABI_NAMESPACE_END
365
366#endif
a simple class to control print indentation
Definition vtkIndent.h:108
@ VERBOSITY_INVALID
Definition vtkLogger.h:214
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.
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.
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.
WGPUInstance GetInstance()
Get handles of the WGPU adapter/device/instance.
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
WGPUTexture CreateTexture(WGPUExtent3D extents, WGPUTextureDimension dimension, WGPUTextureFormat format, WGPUTextureUsage usage, int mipLevelCount=1, const char *label=nullptr)
Creates a WebGPU texture with the given device and returns it.
void IncrementActiveBufferMapCount()
Tracks the number of in-flight asynchronous buffer map (readback) operations.
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.
int GetActiveBufferMapCount() const
Tracks the number of in-flight asynchronous buffer map (readback) operations.
WGPUBuffer CreateBuffer(const WGPUBufferDescriptor &bufferDescriptor)
Convenient methods used to create webgpu buffers.
vtkSetEnumMacro(Backend, BackendType)
Set/Get the graphics backend to use from the graphics adapter.
void WriteTexture(WGPUTexture texture, uint32_t bytesPerRow, uint32_t byteSize, const void *data, uint32_t srcOffset=0, WGPUOrigin3D 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...
VTK_MAYSUSPEND bool Initialize()
Initializes the class.
std::string ReportCapabilities()
Print information of webgpu adapter and device to the output string.
void DeferBufferRelease(WGPUBuffer buffer)
Take over buffer's reference and release it once control has returned from the WebGPU implementation,...
WGPUTexture CreateTexture(const WGPUTextureDescriptor &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 WGPUBuffer and WGPUTexture objects to ...
void WriteBuffer(WGPUBuffer 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.
WGPUTextureView CreateView(WGPUTexture texture, const WGPUTextureViewDescriptor &viewDescriptor)
void Finalize()
Finalizes the class.
bool IsNVIDIAGPUInUse()
Checks whether a particular vendor's GPU is in use.
void DecrementActiveBufferMapCount()
Tracks the number of in-flight asynchronous buffer map (readback) operations.
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.
WGPUDevice GetDevice()
Get handles of the WGPU adapter/device/instance.
bool IsIntelGPUInUse()
Checks whether a particular vendor's GPU is in use.
bool IsARMGPUInUse()
Checks whether a particular vendor's GPU is in use.
WGPUBuffer CreateBuffer(std::uint64_t sizeBytes, WGPUBufferUsage usage, bool mappedAtCreation=false, const char *label=nullptr)
Convenient methods used to create webgpu buffers.
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.
WGPUTextureView CreateView(WGPUTexture texture, WGPUTextureViewDimension dimension, WGPUTextureAspect aspect, WGPUTextureFormat format, int baseMipLevel, int mipLevelCount, const char *label=nullptr)
Creates a texture view of a texture.
WGPUAdapter GetAdapter()
Get handles of the WGPU adapter/device/instance.
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.
WebGPU rendering window.
#define VTK_MAYSUSPEND
#define VTK_MARSHALAUTO