Vulkan-Samples
Vulkan-Samples copied to clipboard
Add support for loading HLSL shaders / offline SPIR-V loading
With HLSL being a first-class Vulkan shader front-end and an increasing no, of request for HLSL shader support we should rethink how we load shaders to add in HLSL support.
There are two fundamentally different approaches to doing this:
Approach A:
Allow loading offline compiled SPIR-V files. That way we could easily add HLSL shader counterparts to all GLSL shaders, then precompile them while creating the samples using glslang or dxc and deliver them as assets with the samples, or even have them compiled as part of a build step. Then we could add a runtime toggle to select what shader type you want to run with. This would require very little programming effort and works on all platforms. This is the approach I choose for my own samples.
Approach B:
Adding another front-end runtime compiler. That has two draw backs: We need to program an integration and we would need to make sure that all platforms support the front-end. DXC runs on multiple platforms, but basically still uses COM, so probably won't work on Android.
Related issues and PRs:
- #179
- #192
- #434
- #183
- #892
In v2.0 I was looking at offline compiling into SPIRV and saving in generated header files. This avoids the need for filesystem lookups and allows us to bake the SPIRV into the application.
We also have the added bonus of offline reflection and compile safe types.
My one concern is our usage of variants. I'm not certain how we would define variants of shaders upfront?
Are we actually using variants in our samples?
Yep. We use variants against content loaded from models and then I believe there are some samples which also use custom variants.
If we preprocessed meshes with an offline tool then we can remove the need for most of the variants. We can simply add the missing info into meshes.
This was also a vision for v2.0
Since we agreed on approach A and since we already did good progress on getting HLSL into our samples, I'm closing this.