MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-ValidationLayers / GLSLtoSPV

Function GLSLtoSPV

tests/framework/shader_helper.cpp:264–299  ·  view source on GitHub ↗

Compile a given string containing GLSL into SPV for use by VK Return value of false means an error was encountered.

Source from the content-addressed store, hash-verified

262// Return value of false means an error was encountered.
263//
264bool GLSLtoSPV(const VkPhysicalDeviceLimits& device_limits, const VkShaderStageFlagBits shader_type, const char* p_shader,
265 std::vector<uint32_t>& spirv, const spv_target_env spv_env) {
266 TBuiltInResource resources;
267 ProcessConfigFile(device_limits, resources);
268
269 EShMessages messages = static_cast<EShMessages>(EShMsgDefault | EShMsgSpvRules | EShMsgVulkanRules);
270 EShLanguage stage = FindLanguage(shader_type);
271 glslang::TShader shader(stage);
272 GlslangTargetEnv glslang_env(spv_env);
273 shader.setEnvTarget(glslang::EshTargetSpv, glslang_env);
274 shader.setEnvClient(glslang::EShClientVulkan, glslang_env);
275
276 const char* shader_strings[1];
277 shader_strings[0] = p_shader;
278 shader.setStrings(shader_strings, 1);
279
280 if (!shader.parse(&resources, 100, false, messages)) {
281 puts(shader.getInfoLog());
282 puts(shader.getInfoDebugLog());
283 return false; // something didn't work
284 }
285
286 glslang::TProgram program;
287 program.addShader(&shader);
288
289 if (!program.link(messages)) {
290 puts(shader.getInfoLog());
291 puts(shader.getInfoDebugLog());
292 return false;
293 }
294
295 glslang::SpvOptions spv_options;
296 glslang::GlslangToSpv(*program.getIntermediate(stage), spirv, &spv_options);
297
298 return true;
299}
300
301//
302// Compile a given string containing SPIR-V assembly into SPV for use by VK

Callers 5

ShaderMethod · 0.85
GLSLToSPVMethod · 0.85
InitFromGLSLMethod · 0.85
InitFromGLSLTryMethod · 0.85
TEST_FFunction · 0.85

Calls 3

ProcessConfigFileFunction · 0.85
FindLanguageFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected