GlistEngine
Loading...
Searching...
No Matches
gVKShaderCompiler.h
Go to the documentation of this file.
1/*
2 * gVKShaderCompiler.h
3 *
4 * Compiles Vulkan GLSL to SPIR-V at runtime. In a development build with
5 * shaderc, this also lets an engine shader be edited without rebuilding; only
6 * that configuration bakes graphics/shaders into GVK_VK_SHADER_SOURCE_DIR.
7 *
8 * Desktop Release builds use glslang for application-provided source such as
9 * post-process effects, while engine pipelines still use the SPIR-V committed
10 * in gVKShaders.h. Without either compiler, file-backed user shaders can fall
11 * back to adjacent .spv files; a source-only shader reports a clear failure.
12 */
13
14#pragma once
15
16#ifndef CORE_GVKSHADERCOMPILER_H
17#define CORE_GVKSHADERCOMPILER_H
18
19#include "gVKContext.h"
20
21#ifdef GVK_VULKAN
22
23#include <cstdint>
24#include <string>
25#include <vector>
26
27// True when engine shader files can be hot reloaded in this build. Source-only
28// application shaders may still be compiled by the Release glslang path when
29// this reports false.
30bool gvkRuntimeShadersAvailable();
31
32// Directory the .vert / .frag sources are read from; empty when unavailable.
33std::string gvkShaderSourceDir();
34
35// Last modification time of one shader source, as a plain integer to compare
36// against a previous reading. 0 when the file cannot be stated, which includes
37// every build where runtime shaders are off.
38long long gvkShaderFileTimestamp(const std::string& fileName);
39
40// Compiles one shader source to SPIR-V. Returns false, with the compiler's
41// diagnostics logged, when the file cannot be read or does not compile - the
42// caller is expected to keep using whatever it had.
43// define names one macro to set while compiling, or is empty for none. It exists
44// because the shader sources are shared with the OpenGL backend and one of them -
45// the coloured-geometry shader, which OpenGL draws both its 2D primitives and its
46// 3D meshes with - is compiled twice under different markers. Kept identical to
47// what gen_vk_shaders.cmake passes glslc, so a hot reloaded shader is the shader
48// the release build would have used.
49bool gvkCompileShaderFile(const std::string& fileName, VkShaderStageFlagBits stage,
50 const std::string& define,
51 std::vector<uint32_t>& spirv);
52
53// Compiles GLSL held in memory rather than read from the shader directory, for
54// shaders an application loads through gShader. debugName only names the module
55// in diagnostics.
56//
57// Unlike the engine's own shaders these keep their debug names: a user shader is
58// addressed by name - setFloat("intensity", v) - and the names have to survive
59// into the SPIR-V for reflection to find them. Optimisation is unaffected; the
60// two are separate switches.
61bool gvkCompileShaderSource(const std::string& source, VkShaderStageFlagBits stage,
62 const std::string& debugName, std::vector<uint32_t>& spirv);
63
64#endif /* GVK_VULKAN */
65
66#endif /* CORE_GVKSHADERCOMPILER_H */