Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

[EU] The shader compiler

Stanislav Vasilev edited this page Apr 29, 2022 · 7 revisions

Because the engine uses the Vulkan API, we are required to precompile the shader files to a bytecode intermediate format. This format is called SPIR-V, and shaders are compiled by the UVKShaderCompiler.

The UVKShaderCompiler can either be invoked by the game engine at runtime when changes to the shaders are found, or by using the UVKShaderCompiler executable.

How it works

The UVKShaderCompiler scans the Config folder of your project for shader files, next it generates the MD5 hash of the file and scans the Generated directory for any file with that exact hash as a filename. If no file is found, the shaders get recompiled, otherwise it continues on to the next shader in the Content directory.

In production because those hashes are not needed for validating the shaders, the shaders get compiled into the Content directory with the original name of the source code file, then get packaged by the archive and shipped and if any tampering happened in the archive, the developer can check using the entire archive's hash

Using the CLI

Since the UVKShaderCompiler provides a CLI interface, you can use it for manual compilation. There are 3 options

  1. --help <directory to project> - for help
  2. --complete-regen <directory to project> - for completely regenerating the cache
  3. --compile <directory to project> - for compiling the cache

Shader formats

The shader compiler can get the following shader formats as input:

  1. .frag - fragment shader
  2. .vert - vertex shader
  3. .comp - compute shader
  4. .geom - geometry shader
  5. .tesc - tesselation control shader
  6. .tese - tesselation evaluation shader

All you need to do is create a file with the given file extension in the Content/ directory and it will automatically be compiled!

Debugging

CLI

Additionally to any of the flags to the CLI you can also provide a debug boolean. This boolean can be used to show reflection information needed to debug shaders. This flag can be provided by appending to your call to the CLI --debug

Code

In the engine itself you can define the field shaderDebug EngineInitInfo struct to true

Clone this wiki locally