2
3
4
5
11#include <glslc/src/file_includer.h>
12#include <libshaderc_util/include/libshaderc_util/file_finder.h>
16 void ShaderCompiler::CompileToSPV(
const std::string& data,
const ShaderStage& stage,
const std::string& name, std::vector<uint8_t>& spirv)
21
22
23 shaderc::Compiler compiler;
24 shaderc::CompileOptions options;
27
28
29 shaderc_util::FileFinder fileFinder;
30 fileFinder.search_path().push_back(SPICES_ENGINE_ASSETS_PATH +
"Shaders/src");
34 options.SetGenerateDebugInfo();
39
40
41 options.SetOptimizationLevel(shaderc_optimization_level_performance);
42 options.SetTargetSpirv(shaderc_spirv_version_1_6);
43 options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_3);
44 options.SetIncluder(std::make_unique<glslc::FileIncluder>(&fileFinder));
47
48
49 shaderc::SpvCompilationResult module = compiler.CompileGlslToSpv(data, ShaderHelper::ToShaderCKind(stage), name.c_str(), options);
50 if (module.GetCompilationStatus() != shaderc_compilation_status_success)
53 ss <<
"Error compiling module: " << module.GetErrorMessage();
55 SPICES_CORE_ERROR(ss.str())
59
60
61 std::vector<uint32_t> code32 = { module.cbegin(), module.cend() };
62 spirv.resize(code32.size() * 4);
63 memcpy(spirv.data(), code32.data(), spirv.size());
#define SPICES_PROFILE_ZONE
Wrapper of shaderc compiler.
ShaderStage
enum of shader stage.