VTK  9.7.20261031
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
147 bool HasFeature(WGPUFeatureName feature);
148
167
175
192 void Finalize();
193
203
205
212 void IncrementActiveBufferMapCount() { ++this->ActiveBufferMapCount; }
213 void DecrementActiveBufferMapCount() { --this->ActiveBufferMapCount; }
214 int GetActiveBufferMapCount() const { return this->ActiveBufferMapCount; }
216
223 static std::size_t Align(std::size_t value, std::size_t alignment);
224
225 enum
226 {
229 };
230
234 std::string ReportCapabilities();
235 static std::string DeviceNotReadyMessage();
236
243 std::uint32_t GetAdapterVendorID();
244 std::uint32_t GetAdapterDeviceID();
245
247
265
276 void DeferBufferRelease(WGPUBuffer buffer);
277
279
284 WGPUBuffer CreateBuffer(std::uint64_t sizeBytes, WGPUBufferUsage usage,
285 bool mappedAtCreation = false, const char* label = nullptr);
286 WGPUBuffer CreateBuffer(const WGPUBufferDescriptor& bufferDescriptor);
288
293 void WriteBuffer(WGPUBuffer buffer, std::uint64_t offset, const void* data, std::size_t sizeBytes,
294 const char* description = nullptr);
295
297
300 WGPUTexture CreateTexture(WGPUExtent3D extents, WGPUTextureDimension dimension,
301 WGPUTextureFormat format, WGPUTextureUsage usage, int mipLevelCount = 1,
302 const char* label = nullptr);
303 WGPUTexture CreateTexture(const WGPUTextureDescriptor& textureDescriptor);
305
309 WGPUTextureView CreateView(WGPUTexture texture, WGPUTextureViewDimension dimension,
310 WGPUTextureAspect aspect, WGPUTextureFormat format, int baseMipLevel, int mipLevelCount,
311 const char* label = nullptr);
312 WGPUTextureView CreateView(WGPUTexture texture, const WGPUTextureViewDescriptor& viewDescriptor);
313
318 void WriteTexture(WGPUTexture texture, uint32_t bytesPerRow, uint32_t byteSize, const void* data,
319 uint32_t srcOffset = 0, WGPUOrigin3D dstOffset = { 0, 0, 0 }, uint32_t dstMipLevel = 0,
320 const char* description = nullptr);
321
323
337
345
346protected:
349
350private:
352 void operator=(const vtkWebGPUConfiguration&) = delete;
353
355 std::unique_ptr<vtkWebGPUConfigurationInternals> Internals;
356
357 // Number of in-flight asynchronous buffer map (readback) operations. See
358 // IncrementActiveBufferMapCount().
359 int ActiveBufferMapCount = 0;
360
362 // Initialized in constructor at runtime based on the operating system.
363 BackendType Backend;
364 // In milliseconds
365 double Timeout;
366
368 // Tracks whether AddInstanceRef() was called so Finalize() can release it
369 // even after FinalizeDevice() has already set DeviceReady=false.
370 bool InstanceRefHeld = false;
371};
372
373VTK_ABI_NAMESPACE_END
374
375#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.
bool HasFeature(WGPUFeatureName feature)
Returns whether the device in use supports feature.
WebGPU rendering window.
#define VTK_MAYSUSPEND
#define VTK_MARSHALAUTO