bool compile_glsl_to_spv(std::string& shader, glsl::program_domain domain, std::vector<u32>& spv) { EShLanguage lang = (domain == glsl::glsl_fragment_program) ? EShLangFragment : EShLangVertex; glslang::InitializeProcess(); glslang::TProgram program; glslang::TShader shader_object(lang); bool success = false; const char *shader_text = shader.data(); TBuiltInResource rsc; init_default_resources(rsc); shader_object.setStrings(&shader_text, 1); EShMessages msg = (EShMessages)(EShMsgVulkanRules | EShMsgSpvRules); if (shader_object.parse(&rsc, 400, EProfile::ECoreProfile, false, true, msg)) { program.addShader(&shader_object); success = program.link(EShMsgVulkanRules); if (success) { glslang::TIntermediate* bytes = program.getIntermediate(lang); glslang::GlslangToSpv(*bytes, spv); } } else { LOG_ERROR(RSX, "%s", shader_object.getInfoLog()); LOG_ERROR(RSX, "%s", shader_object.getInfoDebugLog()); } glslang::FinalizeProcess(); return success; }
void initialize_compiler_context() { glslang::InitializeProcess(); init_default_resources(g_default_config); }