| 40 | using ExtInstGLSLstd450RoundTripTest = ::testing::TestWithParam<ExtInstContext>; |
| 41 | |
| 42 | TEST_P(ExtInstGLSLstd450RoundTripTest, ParameterizedExtInst) { |
| 43 | spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_0); |
| 44 | const std::string spirv = R"( |
| 45 | OpCapability Shader |
| 46 | %1 = OpExtInstImport "GLSL.std.450" |
| 47 | OpMemoryModel Logical Simple |
| 48 | OpEntryPoint Vertex %2 "main" |
| 49 | %3 = OpTypeVoid |
| 50 | %4 = OpTypeFunction %3 |
| 51 | %2 = OpFunction %3 None %5 |
| 52 | %6 = OpLabel |
| 53 | %8 = OpExtInst %7 %1 )" + std::string(GetParam().extInstOpName) + |
| 54 | " " + GetParam().extInstOperandVars + R"( |
| 55 | OpReturn |
| 56 | OpFunctionEnd |
| 57 | )"; |
| 58 | const std::string spirv_header = |
| 59 | R"(; SPIR-V |
| 60 | ; Version: 1.0 |
| 61 | ; Generator: Khronos SPIR-V Tools Assembler; 0 |
| 62 | ; Bound: 9 |
| 63 | ; Schema: 0)"; |
| 64 | spv_binary binary = nullptr; |
| 65 | spv_diagnostic diagnostic; |
| 66 | spv_result_t error = spvTextToBinary(context, spirv.c_str(), spirv.size(), |
| 67 | &binary, &diagnostic); |
| 68 | if (error) { |
| 69 | spvDiagnosticPrint(diagnostic); |
| 70 | spvDiagnosticDestroy(diagnostic); |
| 71 | ASSERT_EQ(SPV_SUCCESS, error) |
| 72 | << "Source was: " << std::endl |
| 73 | << spirv << std::endl |
| 74 | << "Test case for : " << GetParam().extInstOpName << std::endl; |
| 75 | } |
| 76 | |
| 77 | // Check we do have the extended instruction's corresponding binary code in |
| 78 | // the generated SPIR-V binary. |
| 79 | std::vector<uint32_t> expected_contains( |
| 80 | {12 /*OpExtInst*/ | GetParam().extInstLength << 16, 7 /*return type*/, |
| 81 | 8 /*result id*/, 1 /*glsl450 import*/, GetParam().extInstOpcode}); |
| 82 | for (uint32_t operand : GetParam().extInstOperandIds) { |
| 83 | expected_contains.push_back(operand); |
| 84 | } |
| 85 | EXPECT_NE(binary->code + binary->wordCount, |
| 86 | std::search(binary->code, binary->code + binary->wordCount, |
| 87 | expected_contains.begin(), expected_contains.end())) |
| 88 | << "Cannot find\n" |
| 89 | << spvtest::WordVector(expected_contains).str() << "in\n" |
| 90 | << spvtest::WordVector(*binary).str(); |
| 91 | |
| 92 | // Check round trip gives the same text. |
| 93 | spv_text output_text = nullptr; |
| 94 | error = spvBinaryToText(context, binary->code, binary->wordCount, |
| 95 | SPV_BINARY_TO_TEXT_OPTION_NONE, &output_text, |
| 96 | &diagnostic); |
| 97 | |
| 98 | if (error) { |
| 99 | spvDiagnosticPrint(diagnostic); |
nothing calls this directly
no test coverage detected