Skip to main content

Khronos Blog

HLSL as a First Class Vulkan Shading Language

Vulkan 1.2 Deepens HLSL Support

HLSL support in Vulkan has come a long way since its introduction a couple of years ago and now it has hit a critical maturation point to earn the coveted label of ‘production ready’. HLSL in Vulkan has been achieved through integrating a SPIR-V backend into DXC, Microsoft’s open source HLSL compiler (the encircled section in Figure 1 below), and also adding HLSL support in Khronos’ glslang compiler. HLSL is Microsoft’s DirectX's official shading language and is widely used by games and 3D applications. For many AAA game developers, HLSL is the language of choice and Khronos has received many developer requests to support HLSL in Vulkan. Now, thanks to Microsoft open sourcing their HLSL compiler, the Vulkan community has been able to work cooperatively with Microsoft to make HLSL support in Vulkan a proven choice alongside Khronos’ own GLSL shading language.

Fig.1 The Microsoft open source DXC compiler now supports
Vulkan and DX12 backend code generation

For those that used early iterations of the SPIR-V backend, dangling resource references and variable passing problems now feel like a distant memory. With feedback from the Vulkan community, Google, LunarG, NVIDIA, and Valve have steered an effort to resolve these and other issues by adding SPIR-V legalization to Vulkan’s HLSL shader compilers. HLSL is a fairly permissive language and the direct translation of HLSL to SPIR-V can sometimes generate illegal SPIR-V. The legalization process using the SPIR-V Tools step in Figure 1 applies corrective transformations to make the SPIR-V valid for Vulkan. While the image below depicts the flow for DXC, the legalization tools can also be used for HLSL compilation using the glslang compiler. Looking back, SPIR-V legalization was the keystone that enabled reliable compilation of HLSL to SPIR-V for Vulkan. Of course, this doesn’t mean things have slowed down; efforts to improve HLSL on Vulkan continue throughout the ecosystem. Vulkan 1.2 brings a notable number of new exciting features for HLSL on Vulkan - more on this later.

Even with ongoing improvements, HLSL on Vulkan has been ready for developers to use over the past year or so. Developers have been hard at work incorporating Vulkan HLSL compilers and tools into their production pipelines, and there’s no greater testament to HLSL-on-Vulkan’s production readiness than its adoption in AAA Vulkan games. Adding to an existing number of AAA titles, Google’s Stadia launched with a host of AAA titles that use HLSL on Vulkan: Destiny 2, Red Dead Redemption II, Assassin’s Creed Odyssey, and the Tomb Raider series to name a few. It’s quite amazing to see some of the biggest AAA titles using HLSL on Vulkan to render their content.

Vulkan 1.2 marks yet another significant step in Vulkan’s evolution and comes with new features for enhanced support of HLSL, including support for SPIR-V 1.4/1.5, more flexible buffer layouts, the Vulkan memory model, and subgroup operation support for narrower data types. The addition of these new features helps ensure that HLSL is a first-class Vulkan shading language.

Moving towards the future, the Vulkan working group is working on ray tracing technology. While a cross-vendor solution for ray tracing is still in discussion, NVIDIA has laid the groundwork for this in DXC, adding functionality to target their VKRay Vulkan ray tracing extension with shaders written in HLSL. This work will ultimately be leveraged to enable HLSL to be used to access cross-vendor ray tracing in Vulkan on multiple platforms.

Looking ahead, Khronos warmly welcomes continuing to work with Microsoft to enable Vulkan developers with the choice of using HLSL - making HLSL one of the most widely available shading languages in the industry.

Comments