SpiecsEngine
 
Loading...
Searching...
No Matches

◆ CompileToSPV()

void Spices::ShaderCompiler::CompileToSPV ( const std::string & data,
const ShaderStage & stage,
const std::string & name,
std::vector< uint8_t > & spirv )
static

Compile glsl to spv.

Parameters
[in]dataglsl data.
[in]stageShaderStage.
[in]nameShader Name.
[in,out]spirvspv data.

Instance Compiler.

Shader Header Search folder and processer.

Compile Settings.

Runtime Compile.

Get Compiled spirv code.

Instance Compiler.

Shader Header Search folder and processer.

Compile Settings.

Runtime Compile.

Get Compiled spirv code.

Definition at line 16 of file ShaderCompiler.cpp.

17 {
19
23 shaderc::Compiler compiler;
24 shaderc::CompileOptions options;
25
29 shaderc_util::FileFinder fileFinder;
30 fileFinder.search_path().push_back(SPICES_ENGINE_ASSETS_PATH + "Shaders/src");
31
32#ifdef SPICES_DEBUG
33
34 options.SetGenerateDebugInfo(); // -g
35
36#endif
37
41 options.SetOptimizationLevel(shaderc_optimization_level_performance); // -o
42 options.SetTargetSpirv(shaderc_spirv_version_1_6); // --target-env=spv1.6
43 options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_3); // --target-env=vulkan1.3
44 options.SetIncluder(std::make_unique<glslc::FileIncluder>(&fileFinder));
45
49 shaderc::SpvCompilationResult module = compiler.CompileGlslToSpv(data, ShaderHelper::ToShaderCKind(stage), name.c_str(), options);
50 if (module.GetCompilationStatus() != shaderc_compilation_status_success)
51 {
52 std::stringstream ss;
53 ss << "Error compiling module: " << module.GetErrorMessage();
54
55 SPICES_CORE_ERROR(ss.str())
56 }
57
61 std::vector<uint32_t> code32 = { module.cbegin(), module.cend() };
62 spirv.resize(code32.size() * 4);
63 memcpy(spirv.data(), code32.data(), spirv.size());
64 }
#define SPICES_PROFILE_ZONE