VTK WebGPU

A major challenge facing any cross-platform graphics and visualization system is supporting the rendering process across multiple computing platforms. From its earliest days, VTK has used an object-factory mechanism to run-time adapt to various rendering libraries such as GL, Starbase, XGL, OpenGL, and others, depending on the specific capabilities of the platform. However, this has placed a significant burden on the VTK community to implement and support many graphics implementations. And with the explosive growth of the web as a computing environment, supporting graphics in a web browser adds another fun twist to the challenge.

The primary reason for this preponderance of computer graphics libraries and APIs is a continually evolving technology environment, driven by the demand for more realistic visuals, higher performance, and broader platform compatibility. Vendors also desire to create solutions optimized to their computing environment—thus the development of new graphics standards and libraries that provide developers with powerful tools to harness the capabilities of modern hardware. This blog post provides a deep-dive exploration of some of these key emerging technologies and the overarching philosophies behind efforts to unify graphics across diverse platforms.

WebGPU dragon
Stanford Dragon dataset rendered with VTK

Some History: OpenGL

For years, since its initial release in 1992, OpenGL served as the industry standard for cross-platform 2D and 3D graphics API. Its widespread adoption made it a cornerstone for many applications and games throughout the 1990s and 2000s. However, as hardware became more sophisticated in the late 2000s and 2010s, OpenGL’s driver-centric approach and higher-level abstraction began to show limitations in performance and control on modern GPUs and multi-core CPUs.

The limitations of OpenGL have become increasingly evident over time. Its state machine architecture, while offering flexibility, can result in complex and error-prone code, especially when managing multiple states. The high-level abstraction, which was initially beneficial, means that developers have less direct control over the hardware, making it challenging to optimize for specific architectures.

Additionally, the driver-centric model introduces performance overhead because drivers must translate OpenGL commands into low-level GPU instructions. This abstraction also complicates the utilization of multi-core CPUs, as OpenGL is largely built around a single-threaded execution model. Furthermore, the lack of explicit memory management within the API restricts developers’ control over resource allocation, potentially leading to inefficiencies and unexpected behavior.

Lastly, the slow pace of adopting new features compared to the rapid evolution of hardware underscores OpenGL’s struggle to meet modern graphics demands. As graphics hardware and software have advanced, the inherent limitations of OpenGL have become more pronounced. A significant architectural challenge arises from its state machine paradigm. Although, as mentioned, it provides flexibility in managing rendering parameters, this design often results in complicated and error-prone codebases. Developers frequently find themselves overseeing numerous distinct states simultaneously, which can lead to subtle bugs that are difficult to diagnose and fix, consuming valuable development time.

Emerging Standards: Vulkan, Metal, and Direct3D

Enter Vulkan, a next-generation, low-overhead, cross-platform 3D graphics and compute API. Developed by the Khronos Group (the same consortium behind OpenGL), Vulkan offers developers much greater direct control over the GPU, leading to significantly improved performance by enabling parallel command buffer recording. Its explicit nature requires more code from developers, but rewards them with unparalleled optimization potential. Vulkan is designed to be highly scalable, working across a wide range of devices, from mobile phones to high-end workstations, giving it a leg up as compared to OpenGL’s more fragmented landscape.

However, Vulkan’s low-level control, while powerful, also presents a steeper learning curve and increased development complexity compared to higher-level APIs like OpenGL. Developers must manage memory, synchronization, and command buffer submission more explicitly, which can lead to more verbose code and a greater potential for subtle bugs if not handled carefully. The initial setup and boilerplate code required for a Vulkan application are also more extensive, making it less suitable for quick prototypes or simpler graphics tasks where the performance benefits might not outweigh the increased development effort. Additionally, debugging Vulkan applications can be more challenging due to their explicit nature and the direct interaction with hardware.

Metal, another emerging standard, is Apple’s proprietary low-overhead graphics and compute API, specifically designed for its ecosystem (iOS, macOS, iPadOS, and tvOS). Like Vulkan, Metal provides closer access to the GPU, allowing for highly optimized graphics rendering and computation. Its tight integration with Apple’s hardware and software stack enables developers to extract maximum performance from Apple devices, making it the go-to API for high-performance graphics applications within this ecosystem. Its primary limitation is its platform specificity, being exclusively available on Apple hardware. This restricts its use to a smaller range of devices compared to cross-platform APIs, requiring developers to use alternative solutions for non-Apple platforms.

Direct3D, a component of Microsoft’s DirectX API, is the dominant graphics API for Windows-based platforms, including PCs and Xbox consoles. Like Vulkan and Metal, it offers low-level access to the GPU, enabling developers to optimize performance for Microsoft’s hardware and software ecosystem. Direct3D has a long history of driving advancements in PC gaming and remains a crucial tool for developers targeting the Windows platform, offering a rich feature set and tight integration with Windows-specific technologies. However, its significant limitation is its lack of cross-platform compatibility, as it is exclusively available on Microsoft Windows and Xbox platforms. This means developers targeting other operating systems need to implement alternative graphics APIs for those environments.

The Web’s New Frontier: WebGPU

Beyond traditional desktop and mobile applications, the web is also seeing a significant leap forward in graphics capabilities with WebGPU. This emerging web standard, developed by the W3C GPU for the Web Community Group, aims to bring the power of modern 3D graphics and computation, similar to what Vulkan and Metal offer, directly to web browsers.

WebGPU is designed to provide a low-level, high-performance API for rendering and computation on the web, leveraging the capabilities of underlying system APIs like Vulkan, Metal, and DirectX 12. This means web developers will be able to create much more sophisticated and graphically intensive applications directly within the browser, without the need for plugins or specialized software. It represents a significant step towards blurring the lines between native and web-based graphics experiences.

Unifying Graphics Across Platforms: Approaches and Philosophies

The proliferation of different graphics APIs across various platforms presents a challenge for developers aiming to deliver consistent experiences. Several approaches and philosophies are emerging to address this. Cross-API Abstraction Layers involve the development of libraries and frameworks that provide a unified API, which then translates calls to the underlying platform-specific graphics APIs (Vulkan, Metal, DirectX). This allows developers to write code once and deploy it across multiple platforms with minimal changes, abstracting away the complexities of each individual API. Another approach is Engine-Level Abstraction, where game engines and rendering frameworks (e.g., Unity, Unreal Engine, Godot) inherently provide their own abstraction layers. Developers work within the engine’s API, and the engine handles the translation to the appropriate graphics API for the target platform. This is a common and highly effective approach for multi-platform development. Shader Language Unification is also being pursued; while graphics APIs differ, the underlying principles of how GPUs process data through shaders remain somewhat consistent. Efforts are underway to create universal shader languages or transpilers that can convert shaders written in one language (e.g., GLSL, HLSL, WGSL) into another, facilitating cross-platform shader development. Finally, Portable API Design Philosophies are at play; when designing new APIs like WebGPU, the philosophy is to draw inspiration from the best practices of modern low-level APIs while ensuring portability and web-specific security considerations. This aims to create a “least common denominator” that is both powerful and widely implementable.

The trend is clear: greater control over hardware, increased performance, and a strong drive towards unifying graphics development across the ever-expanding array of devices and platforms. As these standards and libraries mature, we can expect to see even more immersive and graphically stunning experiences in applications, games, and on the web.

How WebGPU is used to unify graphics

WebGPU’s design inherently positions it as a potential unifying force for graphics across various platforms. By building upon the foundational concepts of modern native APIs like Vulkan, Metal, and DirectX 12, WebGPU aims to provide a consistent and powerful rendering and computation layer not just for web browsers, but also for desktop and mobile environments. This is largely achieved through initiatives like WebGPU’s native implementations (e.g., through libraries that allow WebGPU code to run directly on the underlying system’s graphics API) and its adoption within frameworks that target multiple platforms. Developers can write WebGPU code once, and through these mechanisms, potentially deploy it to the web, desktop applications, and even mobile applications, abstracting away the complexities of each platform’s specific graphics backend. This approach promises a future where a single graphics codebase can reach a vast array of devices, significantly streamlining development for multi-platform experiences.

VTK and WebGPU / Dawn

For decades, the Visualization Toolkit (VTK) has been an indispensable tool for scientific data visualization, providing robust capabilities for researchers and engineers across various disciplines. At the heart of VTK’s rendering engine has traditionally been OpenGL, the venerable cross-platform graphics API. While OpenGL has served VTK exceptionally well, its limitations in the face of modern hardware and the evolving web landscape have become increasingly apparent, prompting a significant architectural shift towards WebGPU.

The reliance on OpenGL has meant that VTK, particularly in web-based applications, has often faced hurdles related to performance, driver compatibility, and the inherent complexity of OpenGL’s state-machine architecture. As outlined in the “Emerging Graphics Standards and Libraries” section, OpenGL’s driver-centric model and higher-level abstraction can hinder optimization for contemporary GPUs and multi-core CPUs. This has pushed the scientific visualization community, and specifically the VTK development team, to seek more performant and future-proof solutions.

Our team is actively working on a major modernization effort to replace OpenGL with WebGPU as the primary graphics backend for VTK. This transition is not merely an upgrade; it’s a fundamental re-architecture aimed at unlocking new levels of performance, better utilizing modern GPU capabilities, and significantly enhancing VTK’s presence on the web. WebGPU, as an emerging web standard, promises low-level, high-performance rendering and computation directly within web browsers, bridging the gap between native and web-based graphics experiences.

The initial implementation of WebGPU in VTK leverages Dawn, Google’s C++ implementation of the WebGPU standard. Dawn provides a robust and efficient way to interact with the underlying system graphics APIs (Vulkan, Metal, DirectX 12) through a unified WebGPU interface. By starting with Dawn’s C++ API, we can quickly integrate WebGPU’s powerful features into VTK while benefiting from a mature and well-supported codebase. This approach allows us to rapidly prototype and develop the new rendering pipeline, ensuring that VTK can harness the full potential of modern GPUs.

Looking ahead

As the WebGPU specification matures and the C API becomes stable and widely adopted, we plan to transition VTK to utilize the official WebGPU C API. This move will further solidify VTK’s integration with the WebGPU ecosystem, ensuring long-term compatibility and providing direct access to the standard as it evolves. This strategic shift will not only enhance VTK’s performance and capabilities but also streamline its deployment across diverse platforms, from high-end workstations to web browsers, truly unifying the experience of scientific visualization.

In terms of a roadmap, our high-level plans are the following:

  • 2026 / Q2: Native desktop support; polydata mapper fixes and speed improvements; 2D image mapper
  • 2026 / Q3: Image slice mapping; support of rendering passes; volume rendering
  • 2026 / Q4: VTK v10.0.0 release with WebGPU
  • 2027: Additional mappers (sphere, surface LIC, etc); advanced volume rendering

Acknowledgements

VTK is an open source toolkit developed by an extended community. Refer to VTK’s GitLab repository for a detailed capture of contributions and enhancements. Research reported in this publication was supported by the National Institute of Biomedical Imaging and Bioengineering of the National Institutes of Health under Award Number R01EB014955. The content is solely the responsibility of the authors and does not necessarily represent the official views of the National Institutes of Health.

Leave a Reply