MCPcopy Create free account
hub / github.com/KhronosGroup/glslang / compileShaderToSpirv

Method compileShaderToSpirv

gtests/SpvPatternTest.cpp:43–70  ·  view source on GitHub ↗

Helper function to compile shader and get SPIR-V disassembly.

Source from the content-addressed store, hash-verified

41
42 // Helper function to compile shader and get SPIR-V disassembly.
43 std::string compileShaderToSpirv(const std::string& shaderSource, EShLanguage stage)
44 {
45 glslang::TShader shader(stage);
46 glslang::TProgram program;
47
48 // Compile the shader
49 const char* shaderStrings = shaderSource.c_str();
50 shader.setStrings(&shaderStrings, 1);
51
52 if (!shader.parse(GetDefaultResources(), 450, false, EShMsgDefault)) {
53 return "COMPILATION_FAILED: " + std::string(shader.getInfoLog());
54 }
55
56 program.addShader(&shader);
57 if (!program.link(EShMsgDefault)) {
58 return "LINKING_FAILED: " + std::string(program.getInfoLog());
59 }
60
61 // Generate SPIR-V.
62 std::vector<uint32_t> spirv;
63 glslang::GlslangToSpv(*program.getIntermediate(stage), spirv);
64
65 // Disassemble SPIR-V to text.
66 std::ostringstream disassembly_stream;
67 spv::Disassemble(disassembly_stream, spirv);
68
69 return disassembly_stream.str();
70 }
71
72 // Helper function to check if the given SPIR-V string contains a specific pattern.
73 bool containsPattern(const std::string& spirvText, const std::string& pattern)

Callers

nothing calls this directly

Calls 8

GetDefaultResourcesFunction · 0.85
GlslangToSpvFunction · 0.85
DisassembleFunction · 0.85
c_strMethod · 0.80
setStringsMethod · 0.80
getInfoLogMethod · 0.80
parseMethod · 0.45
linkMethod · 0.45

Tested by

no test coverage detected