Vulkan’ize Graphic and Compute API’s

Vulkan is a low-level cross-platform graphic API broadly supported. There are several projects to implement all other the existing graphic and compute API’s like OpenGL, OpenGL ES, OpenCL, WebGL, DirectX and even Glide on top of Vulkan. Some projects translate Vulkan to other API’s in case there is no support yet available due to restrictions of the operating system or not yet available drivers.

2019-05-02 14_49_23-

The implementation of all the other graphic and compute API’s on top of Vulkan greatly improves compatibility and reduces development efforts of hardware drivers that got more and more complex with the legacy API’s. This unification on one hardware driver reduces development efforts and bugs. Take the independent developed RADV driver for AMD GPU’s as an example, basically just 2 developers implemented a new driver in one year. Vulkan is the right approach to unify the other API’s for the first time successfully. One improvement in the Vulkan stack will benefit all the implementations on top of it.

Vulkan target

  • DirectX -> Vulkan
    • DirectInput
      • DI1..DI7 -> DI8
        • see DXWrapper, it is wrapping DirectInput 1 until DirectDInput 7 calls into DirectInput 8 (using DInputTo8)
      • DI8
        • no translation to Vulkan required as input handling is separate in Wine
    • DirectDraw
      • DD1..DD6 -> DD7
        • see DXWrapper, it is wrapping DirectDraw 1 until DirectDraw 6 calls into DirectDraw 7
      • DD7 -> DX9
        • see DXWrapper, it is wrapping DirectDraw 7 calls into Direct3D 9 (using Dd7to9)
      • DD8
        • no translation to Vulkan
    • Direct3D
      • D3D1..D3D6 -> D3D7
        • DXWrapper (license BSD, https://github.com/elishacloud/dxwrapper) is wrapping Direct3D 1 until Direct3D 6 calls into Direct3D 7. Plus it integrates D3D8to9 to convert Direct3D 8 to Direct3D 9 as well.
        • dgVoodoo2 see D3D8.
      • D3D7
        • dgVoodoo2 see D3D8. Besides dgVoodoo2 there is no other project to translate D3D7 e.g. to D3D8, D3D9 or D3D10.
        • no Open Source Vulkan translation
      • D3D8
        • DXWrapper includes D3D8to9 (license BSD, https://github.com/crosire/d3d8to9) which is converting Direct3D 8 to Direct3D 9. It seems like this was the project to be used in combination with D9VK. Might be used as well with DXWrapper.
        • dgVoodoo2 (license proprietary but free of charge, http://www.dege.freeweb.hu) translates Direct3D 1-7 plus Direct3D 8.1 to DirextX 10.1. This allows the  combination with DXVK. Would be nice if GOG would support to release this as open source!
        • See GalliumNine, it has a D3D8 to D3D9 codepath
      • D3D9
        • D9VK (license zlib, https://github.com/Joshua-Ashton/d9vk) translates DX9 (and potentially DX8 in the future) to Vulkan. D9VK avoids expensive state lookups and uses CSMT. D9VK runs in this stage most D3D9 games already without graphical glitches and with a good performance. D9VK is based on DXVK and can be combined. D9VK is part of Proton 4.11.
        • GalliumNine+Zink (refer to OpenGL below). As soon as Zink will be merged in Mesa mainline it could be used together with GalliumNine to provide D3D9 support via Gallium3D on Vulkan. GalliumNine added NIR support and this would allow the combination with Zink, read https://github.com/iXit/Mesa-3D/issues/339, NIR was enabled in Mesa 19.1 https://lists.freedesktop.org/archives/mesa-dev/2019-February/215515.html. GalliumNine is based on Gallium3D and provides for Direct3D 9 native API’s for Wine directly out of Mesa, read Wine-Staging.
      • D3D10+D3D11
        • DXVK (license zlib, https://github.com/doitsujin/dxvk) translates DX11 and DX10 (since 0.70) into Vulkan and it works impressively well on Wine and Proton (Steam Play) in Linux with a broad support for games. Follow this guide to get DXVK up and running in Wine or just use Steam Play (Proton).
      • D3D12
        • VKD3D 1.1 (license LGPL, https://source.winehq.org/git/vkd3d.git) is a Wine project and aims to map Direct3D 12 (DX12) directly to Vulkan. For now there very few real D3D 12 exclusive titles, so this project is just nice to have. As Direct3D 12 borrowed a lot of concepts from Vulkan and its predecessor Mantle, it’s much less complex compared to Direct3D 11, though it’s ataption is slow. Even though VKD3D is developed by the Wine community, it is kept separately so that other developers can use it as well and the DXVK main developer provided some patches too. Most of the DX12 demos run since VKD3D version 1.0. On proprietary Apple platforms VKD3D supports the use of MoltenVK to translate from Vulkan further to proprietary Metal.
  • OpenGL -> Vulkan
  • OpenGL ES/WebGL -> Vulkan
    • ZINK (refer to OpenGL above)
    • ANGLE (license BSD, https://github.com/google/angle) is a cross platform project developed by Google, see http://www.phoronix.com/scan.php?page=news_item&px=Chromium-ANGLE-Vulkan. The project describes itself as “ANGLE currently provides translation from OpenGL ES 2.0/3.0 to desktop OpenGL, OpenGL ES, Direct3D 9, Direct3D 11 and Vulkan. Support to translate OpenGL ES 2.0 to Vulkan is available in Android Q, OpenGL ES 3.0 is still in development. This project is interesting as it allows at least Android, Linux and Windows to translate OpenGL ES (not yet finalized is ES 3.0) to Vulkan. With this the GPU hardware vendor for Android would only need to supply a Vulkan driver and not as well the more complex OpenGL ES driver. Another user of ANGLE is hardware acceleration in Chromium and Firefox (with the Webrender engine written in Rust to translate OpenGL ES if not available directly to D3D11) on Windows, so even here Vulkan could be great to unify all drivers.
  • OpenCL -> Vulkan
  • Glide -> Vulkan

Vulkan base

  • Vulkan -> CPU fallback (without GPU)
    • Kazan (formerly Vulkan-CPU, license LGPLv2.1, https://salsa.debian.org/Kazan-team/kazan) is a Vulkan driver for Linux that runs on top of a regular CPU in case a GPU Vulkan driver is missing like for Nvidia where no open source driver is available or in a virtual machine. Instead of C++ the new Kazan is rewritten in Rust. Use cases
      • Computing tasks
      • Provide software rendering for desktops based on Vulkan (not yet available, basic Vulkan support landed in Qt 5.10 and GTK 4 toolkits) or simple games (required e.g. in case of Nvidia or some ARM devices where no open source Vulkan driver is available)
      • Testing a vendor neutral Vulkan implementation
      • Virtual machines/clouds without a real GPU
    • SwiftShader (license Apache 2.0, https://github.com/google/swiftshader) offers a cross platform Vulkan 1.1 on CPU backend (similiar to LLVM for OpenGL, it previously was based on OpenGL ES and Direct3D 9). Combined with ANGLE it could allow other API’s like OpenGL ES to run as well on the CPU. SwiftShader can be seen as well like a fallback driver in case the GPU driver doesn’t work as it should or is not available e.g. on Andoid or in Chromium.
  • Vulkan -> Vulkan/DX12/Metal/OpenGL ES
    • gfx-rs (license Apache 2.0, https://github.com/gfx-rs/gfx) is a Mozilla effort to develop a graphics/hardware abstraction library written in Rust. The gfx-hal is a hardware abstraction layer based on the Vulkan-ic to translate to native backends on Vulkan and additionally to DX12, Metal and OpenGL ES (OpenGL, WebGL). Mozilla is using this for the WebGPU-servo project to use Vulkan for the Web (https://github.com/gfx-rs/wgpu). So besides Firefox becoming a user of gfx-rs they collaborate as well with Dolphin and RPCS3 to improve MacOS support https://gfx-rs.github.io/2018/09/03/rpcs3-dolphin.html.
  • Vulkan -> Metal
  • Vulkan -> DX12
    • See gfx-rs
  • Vulkan -> WebVK/WebGPU -> Vulkan, DX12, Metal

Harmonization

SPIR-V

SPIR-V is a platform independent intermediate language layer for OpenCL and GLSL that is supported by Vulkan. It will be extended to NIR by the nouveau developers.

NIR

The intermediate representation NIR is becoming the common foundation of the Mesa drivers and it allows the Vulkan developments to share more code (paths) with OpenGL and OpenCL. Originally NIR was developed by Intel for their OpenGL mesa driver, later support for the Intel ANV Vulkan driver was added.

NIR provided as well the groundwork for the community Vulkan driver RADV for AMD GPU’s. Now the OpenGL RadeonSI driver lately sees as well a lot of work to use NIR, which is required to add SPIR-V ingestion’s from OpenGL 4.6, finally it should replace AMD’s TGSI. To test the NIR IR with Mesa 19.1 you need to set the AMD_DEBUG=nir (previously R600_DEBUG=nir) environment variable. For a steam game you would add the launch option AMD_DEBUG=nir %command% (previously R600_DEBUG=nir) and mostly all games should run just fine with NIR (if not, write a bug report).

Another effort is to add NIR support to Nouveau for SPIR-V ingestions required for OpenGL 4.6 (https://www.phoronix.com/scan.php?page=news_item&px=Nouveau-NIR-IR-V6) and compute support (OpenCL 2.1), read https://www.phoronix.com/scan.php?page=news_item&px=Nouveau-NIR-V2. Mesa 19.1+ requires the environment variable NV50_PROG_USE_NIR=1 to support NIR. Additionally this could open the door for a own open source community Nouveau Vulkan driver.

The Freedreno driver will add NIR support for OpenCL and SPIR-V in OpenGL 4.6 as well (https://www.phoronix.com/scan.php?page=news_item&px=Freedreno-OpenCL-SPIR-V-Too).

Etnaviv added for Vivante NIR support in Mesa 19.2 (https://www.phoronix.com/scan.php?page=news_item&px=Etnaviv-NIR-Compiler-Mesa-19.2). It requires the parameter ETNA_MESA_DEBUG=nir.

For ARM Mali the NIR support is developed as well (https://www.phoronix.com/scan.php?page=news_item&px=Chai-ARM-Midgard-To-NIR).

The OpenCL Gallium3D “Clover”state tracker (actually only at OpenCL 1.2) received support for SPIR-V binaries https://www.phoronix.com/scan.php?page=news_item&px=SPIR-V-Clover-OpenCL-2018 with Mesa 19.0. SPIR-V is based on Vulkan and OpenCL 2.1+. Additionally this allows the conversion from the SPIR-V intermediate representation (IR) back to NIR, which is required for drivers without SPIR-V support, like at the moment Nouveau, V3D (VC5/VC6) and Etnaviv or to LLVM IR for the other Gallium 3D drivers.

NIR Status

  • OpenGL
    • Intel: standard and as well in the new Iris driver (Mesa 19.1)
    • AMD: RadeonSI testing (requires parameter AMD_DEBUG=nir), required for OpenGL 4.6. Since Mesa 18.0 OpenGL 4.5 is fully supported by RadeonSI’s NIR backend.
    • Nouveau: testing since Mesa 19.1 (requires parameter NV50_PROG_USE_NIR=1), required for OpenGL 4.6.
    • Vivante: testing in Etnaviv since Mesa 19.2 (requires parameter ETNA_MESA_DEBUG=nir )
    • VC4/Freedreno: Gallium3D, required for OpenGL 4.6
    • VC5/VC6: In development via V3D
    • Mali: In development, but not as a Gallium3D driver
  • Vulkan
  • OpenCL
    • Intel: Beignet offers an alternative OpenCL approach
    • RadeonSI: In development via Clover, but ROCm is used now for OpenCL instead with its own implementation
    • Nouveau: In development, almost finished, patches for Mesa 19.2
    • VC5/VC6: –
  • DX9
    • GalliumNine added NIR support with Mesa 19.1 so that it can be used together with the new Intel Iris Gallium3D driver and with Zink.

Gallium3D

Gallium3D drivers are used by AMD, Intel (only Iris) and several other GPU vendors. As a side effect of all the NIR developments.

HLSL

Glslang could convert HLSL as well to SPIR-V, but not at the same time with the output to DXIL and SPIR-V. Microsoft open sourced in 2017 the Direct X shader compiler DXC for HLSL (high level shading compiler) based on LLVM/Clang. Orginally it did output only DXIL for Windows 10, but Google added in June 2018 a SPIR-V output, which in turn can be used by Vulkan, OpenGL 4.6 and OpenCL (https://github.com/google/DirectXShaderCompiler/tree/linux).

Shader Conductor

Shader Conductor (license MIT, https://github.com/Microsoft/ShaderConductor) is a new project from Microsoft. Besides the DXIL output the Direct X shader compiler can provide as well SPIR-V. SPIR-V could then output to Vulkan or to OpenGL via SPIRV-Cross. Besides this SPIRV-Cross allows as well to go again OpenGL (via GLSL), OpenGL ES (via ESSL), D3d 9/10/11 (via MSL) or to Metal (via MSL), for more details read https://www.phoronix.com/scan.php?page=news_item&px=Microsoft-Shader-Conductor.

Legacy Projects

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: