Are Vulkan shaders written in the same way as in OpenGL or GLSL?

They can be. For Vulkan, you can write in GLSL (with Vulkan extensions) and use an offline toolchain headed by glslangValidator to translate that to SPIR-V (standard Vulkan only accepts SPIR-V). This offline toolchain is included in the LunarG Vulkan SDK. See the SPIR-V toolchain document in the SDK for more information.

There are other ways to write shaders for Vulkan-based applications using different high-level languages and supporting toolchains. Some high-level shaders can be linked directly into an application, so you don’t have to rely solely on offline support. We call this off-driver support, and you can do it online by using a side tool in real-time. Note that it isn’t part of the core Vulkan drivers stack. SPIR-V can also be written directly in SPIR-V assembly language and assembled using the spirv-as tool included in the LunarG SDK.

Many applications porting to Vulkan also need a way to port their HLSL shaders to SPIR-V. glslangValidator also provides a method to translate HLSL shaders to SPIR-V. Currently, glslangValidator supports HLSL through SM 5 complete enough to run complex, real-world workloads such as Dota 2 and Ashes of the Singularity. It accepts shaders for any shader stage, and handles common language constructs for functions, control flow, variable and type declarations, registers and pack offsets, most DX10 and later texture methods, most intrinsic functions, most preprocessor functionality, most built-in semantics, and attributes that affect stage functionality. To learn more about HLSL support in glslangValidator, visit the FAQ in the Wiki at the glslang GitHub.

HLSL can also be translated to SPIR-V using DXC. DXC supports HLSL starting with SM5. DXC is currently not included in the LunarG SDK. See this link for more information.

Return to FAQs