Helper function to compile shader and get SPIR-V disassembly.
| 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) |
nothing calls this directly
no test coverage detected