text_to_binary.constant_test.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. // Copyright (c) 2015-2016 The Khronos Group Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Assembler tests for instructions in the "Group Instrucions" section of the
  15. // SPIR-V spec.
  16. #include <cstdint>
  17. #include <limits>
  18. #include <string>
  19. #include <vector>
  20. #include "gmock/gmock.h"
  21. #include "test/test_fixture.h"
  22. #include "test/unit_spirv.h"
  23. namespace spvtools {
  24. namespace {
  25. using spvtest::Concatenate;
  26. using spvtest::EnumCase;
  27. using spvtest::MakeInstruction;
  28. using ::testing::Eq;
  29. // Test Sampler Addressing Mode enum values
  30. using SamplerAddressingModeTest = spvtest::TextToBinaryTestBase<
  31. ::testing::TestWithParam<EnumCase<SpvSamplerAddressingMode>>>;
  32. TEST_P(SamplerAddressingModeTest, AnySamplerAddressingMode) {
  33. const std::string input =
  34. "%result = OpConstantSampler %type " + GetParam().name() + " 0 Nearest";
  35. EXPECT_THAT(CompiledInstructions(input),
  36. Eq(MakeInstruction(SpvOpConstantSampler,
  37. {1, 2, GetParam().value(), 0, 0})));
  38. }
  39. // clang-format off
  40. #define CASE(NAME) { SpvSamplerAddressingMode##NAME, #NAME }
  41. INSTANTIATE_TEST_SUITE_P(
  42. TextToBinarySamplerAddressingMode, SamplerAddressingModeTest,
  43. ::testing::ValuesIn(std::vector<EnumCase<SpvSamplerAddressingMode>>{
  44. CASE(None),
  45. CASE(ClampToEdge),
  46. CASE(Clamp),
  47. CASE(Repeat),
  48. CASE(RepeatMirrored),
  49. }));
  50. #undef CASE
  51. // clang-format on
  52. TEST_F(SamplerAddressingModeTest, WrongMode) {
  53. EXPECT_THAT(CompileFailure("%r = OpConstantSampler %t xxyyzz 0 Nearest"),
  54. Eq("Invalid sampler addressing mode 'xxyyzz'."));
  55. }
  56. // Test Sampler Filter Mode enum values
  57. using SamplerFilterModeTest = spvtest::TextToBinaryTestBase<
  58. ::testing::TestWithParam<EnumCase<SpvSamplerFilterMode>>>;
  59. TEST_P(SamplerFilterModeTest, AnySamplerFilterMode) {
  60. const std::string input =
  61. "%result = OpConstantSampler %type Clamp 0 " + GetParam().name();
  62. EXPECT_THAT(CompiledInstructions(input),
  63. Eq(MakeInstruction(SpvOpConstantSampler,
  64. {1, 2, 2, 0, GetParam().value()})));
  65. }
  66. // clang-format off
  67. #define CASE(NAME) { SpvSamplerFilterMode##NAME, #NAME}
  68. INSTANTIATE_TEST_SUITE_P(
  69. TextToBinarySamplerFilterMode, SamplerFilterModeTest,
  70. ::testing::ValuesIn(std::vector<EnumCase<SpvSamplerFilterMode>>{
  71. CASE(Nearest),
  72. CASE(Linear),
  73. }));
  74. #undef CASE
  75. // clang-format on
  76. TEST_F(SamplerFilterModeTest, WrongMode) {
  77. EXPECT_THAT(CompileFailure("%r = OpConstantSampler %t Clamp 0 xxyyzz"),
  78. Eq("Invalid sampler filter mode 'xxyyzz'."));
  79. }
  80. struct ConstantTestCase {
  81. std::string constant_type;
  82. std::string constant_value;
  83. std::vector<uint32_t> expected_instructions;
  84. };
  85. using OpConstantValidTest =
  86. spvtest::TextToBinaryTestBase<::testing::TestWithParam<ConstantTestCase>>;
  87. TEST_P(OpConstantValidTest, ValidTypes) {
  88. const std::string input = "%1 = " + GetParam().constant_type +
  89. "\n"
  90. "%2 = OpConstant %1 " +
  91. GetParam().constant_value + "\n";
  92. std::vector<uint32_t> instructions;
  93. EXPECT_THAT(CompiledInstructions(input), Eq(GetParam().expected_instructions))
  94. << " type: " << GetParam().constant_type
  95. << " literal: " << GetParam().constant_value;
  96. }
  97. // clang-format off
  98. INSTANTIATE_TEST_SUITE_P(
  99. TextToBinaryOpConstantValid, OpConstantValidTest,
  100. ::testing::ValuesIn(std::vector<ConstantTestCase>{
  101. // Check 16 bits
  102. {"OpTypeInt 16 0", "0x1234",
  103. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 0}),
  104. MakeInstruction(SpvOpConstant, {1, 2, 0x1234})})},
  105. {"OpTypeInt 16 0", "0x8000",
  106. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 0}),
  107. MakeInstruction(SpvOpConstant, {1, 2, 0x8000})})},
  108. {"OpTypeInt 16 0", "0",
  109. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 0}),
  110. MakeInstruction(SpvOpConstant, {1, 2, 0})})},
  111. {"OpTypeInt 16 0", "65535",
  112. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 0}),
  113. MakeInstruction(SpvOpConstant, {1, 2, 65535})})},
  114. {"OpTypeInt 16 0", "0xffff",
  115. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 0}),
  116. MakeInstruction(SpvOpConstant, {1, 2, 65535})})},
  117. {"OpTypeInt 16 1", "0x8000", // Test sign extension.
  118. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 1}),
  119. MakeInstruction(SpvOpConstant, {1, 2, 0xffff8000})})},
  120. {"OpTypeInt 16 1", "-32",
  121. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 1}),
  122. MakeInstruction(SpvOpConstant, {1, 2, uint32_t(-32)})})},
  123. {"OpTypeInt 16 1", "0",
  124. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 1}),
  125. MakeInstruction(SpvOpConstant, {1, 2, 0})})},
  126. {"OpTypeInt 16 1", "-0",
  127. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 1}),
  128. MakeInstruction(SpvOpConstant, {1, 2, 0})})},
  129. {"OpTypeInt 16 1", "-0x0",
  130. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 1}),
  131. MakeInstruction(SpvOpConstant, {1, 2, 0})})},
  132. {"OpTypeInt 16 1", "-32768",
  133. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 1}),
  134. MakeInstruction(SpvOpConstant, {1, 2, uint32_t(-32768)})})},
  135. // Check 32 bits
  136. {"OpTypeInt 32 0", "42",
  137. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 0}),
  138. MakeInstruction(SpvOpConstant, {1, 2, 42})})},
  139. {"OpTypeInt 32 1", "-32",
  140. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 1}),
  141. MakeInstruction(SpvOpConstant, {1, 2, uint32_t(-32)})})},
  142. {"OpTypeInt 32 1", "0",
  143. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 1}),
  144. MakeInstruction(SpvOpConstant, {1, 2, 0})})},
  145. {"OpTypeInt 32 1", "-0",
  146. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 1}),
  147. MakeInstruction(SpvOpConstant, {1, 2, 0})})},
  148. {"OpTypeInt 32 1", "-0x0",
  149. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 1}),
  150. MakeInstruction(SpvOpConstant, {1, 2, 0})})},
  151. {"OpTypeInt 32 1", "-0x001",
  152. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 1}),
  153. MakeInstruction(SpvOpConstant, {1, 2, uint32_t(-1)})})},
  154. {"OpTypeInt 32 1", "2147483647",
  155. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 1}),
  156. MakeInstruction(SpvOpConstant, {1, 2, 0x7fffffffu})})},
  157. {"OpTypeInt 32 1", "-2147483648",
  158. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 1}),
  159. MakeInstruction(SpvOpConstant, {1, 2, 0x80000000u})})},
  160. {"OpTypeFloat 32", "1.0",
  161. Concatenate({MakeInstruction(SpvOpTypeFloat, {1, 32}),
  162. MakeInstruction(SpvOpConstant, {1, 2, 0x3f800000})})},
  163. {"OpTypeFloat 32", "10.0",
  164. Concatenate({MakeInstruction(SpvOpTypeFloat, {1, 32}),
  165. MakeInstruction(SpvOpConstant, {1, 2, 0x41200000})})},
  166. {"OpTypeFloat 32", "-0x1p+128", // -infinity
  167. Concatenate({MakeInstruction(SpvOpTypeFloat, {1, 32}),
  168. MakeInstruction(SpvOpConstant, {1, 2, 0xFF800000})})},
  169. {"OpTypeFloat 32", "0x1p+128", // +infinity
  170. Concatenate({MakeInstruction(SpvOpTypeFloat, {1, 32}),
  171. MakeInstruction(SpvOpConstant, {1, 2, 0x7F800000})})},
  172. {"OpTypeFloat 32", "-0x1.8p+128", // A -NaN
  173. Concatenate({MakeInstruction(SpvOpTypeFloat, {1, 32}),
  174. MakeInstruction(SpvOpConstant, {1, 2, 0xFFC00000})})},
  175. {"OpTypeFloat 32", "-0x1.0002p+128", // A +NaN
  176. Concatenate({MakeInstruction(SpvOpTypeFloat, {1, 32}),
  177. MakeInstruction(SpvOpConstant, {1, 2, 0xFF800100})})},
  178. // Check 48 bits
  179. {"OpTypeInt 48 0", "0x1234",
  180. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 48, 0}),
  181. MakeInstruction(SpvOpConstant, {1, 2, 0x1234, 0})})},
  182. {"OpTypeInt 48 0", "0x800000000001",
  183. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 48, 0}),
  184. MakeInstruction(SpvOpConstant, {1, 2, 1, 0x00008000})})},
  185. {"OpTypeInt 48 1", "0x800000000000", // Test sign extension.
  186. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 48, 1}),
  187. MakeInstruction(SpvOpConstant, {1, 2, 0, 0xffff8000})})},
  188. {"OpTypeInt 48 1", "-32",
  189. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 48, 1}),
  190. MakeInstruction(SpvOpConstant, {1, 2, uint32_t(-32), uint32_t(-1)})})},
  191. // Check 64 bits
  192. {"OpTypeInt 64 0", "0x1234",
  193. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 0}),
  194. MakeInstruction(SpvOpConstant, {1, 2, 0x1234, 0})})},
  195. {"OpTypeInt 64 0", "18446744073709551615",
  196. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 0}),
  197. MakeInstruction(SpvOpConstant, {1, 2, 0xffffffffu, 0xffffffffu})})},
  198. {"OpTypeInt 64 0", "0xffffffffffffffff",
  199. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 0}),
  200. MakeInstruction(SpvOpConstant, {1, 2, 0xffffffffu, 0xffffffffu})})},
  201. {"OpTypeInt 64 1", "0x1234",
  202. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 1}),
  203. MakeInstruction(SpvOpConstant, {1, 2, 0x1234, 0})})},
  204. {"OpTypeInt 64 1", "-42",
  205. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 1}),
  206. MakeInstruction(SpvOpConstant, {1, 2, uint32_t(-42), uint32_t(-1)})})},
  207. {"OpTypeInt 64 1", "-0x01",
  208. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 1}),
  209. MakeInstruction(SpvOpConstant, {1, 2, 0xffffffffu, 0xffffffffu})})},
  210. {"OpTypeInt 64 1", "9223372036854775807",
  211. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 1}),
  212. MakeInstruction(SpvOpConstant, {1, 2, 0xffffffffu, 0x7fffffffu})})},
  213. {"OpTypeInt 64 1", "0x7fffffff",
  214. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 1}),
  215. MakeInstruction(SpvOpConstant, {1, 2, 0x7fffffffu, 0})})},
  216. }));
  217. // clang-format on
  218. // A test case for checking OpConstant with invalid literals with a leading
  219. // minus.
  220. struct InvalidLeadingMinusCase {
  221. std::string type;
  222. std::string literal;
  223. };
  224. using OpConstantInvalidLeadingMinusTest = spvtest::TextToBinaryTestBase<
  225. ::testing::TestWithParam<InvalidLeadingMinusCase>>;
  226. TEST_P(OpConstantInvalidLeadingMinusTest, InvalidCase) {
  227. const std::string input = "%1 = " + GetParam().type +
  228. "\n"
  229. "%2 = OpConstant %1 " +
  230. GetParam().literal;
  231. EXPECT_THAT(CompileFailure(input),
  232. Eq("Cannot put a negative number in an unsigned literal"));
  233. }
  234. // clang-format off
  235. INSTANTIATE_TEST_SUITE_P(
  236. TextToBinaryOpConstantInvalidLeadingMinus, OpConstantInvalidLeadingMinusTest,
  237. ::testing::ValuesIn(std::vector<InvalidLeadingMinusCase>{
  238. {"OpTypeInt 16 0", "-0"},
  239. {"OpTypeInt 16 0", "-0x0"},
  240. {"OpTypeInt 16 0", "-1"},
  241. {"OpTypeInt 32 0", "-0"},
  242. {"OpTypeInt 32 0", "-0x0"},
  243. {"OpTypeInt 32 0", "-1"},
  244. {"OpTypeInt 64 0", "-0"},
  245. {"OpTypeInt 64 0", "-0x0"},
  246. {"OpTypeInt 64 0", "-1"},
  247. }));
  248. // clang-format on
  249. // A test case for invalid floating point literals.
  250. struct InvalidFloatConstantCase {
  251. uint32_t width;
  252. std::string literal;
  253. };
  254. using OpConstantInvalidFloatConstant = spvtest::TextToBinaryTestBase<
  255. ::testing::TestWithParam<InvalidFloatConstantCase>>;
  256. TEST_P(OpConstantInvalidFloatConstant, Samples) {
  257. // Check both kinds of instructions that take literal floats.
  258. for (const auto& instruction : {"OpConstant", "OpSpecConstant"}) {
  259. std::stringstream input;
  260. input << "%1 = OpTypeFloat " << GetParam().width << "\n"
  261. << "%2 = " << instruction << " %1 " << GetParam().literal;
  262. std::stringstream expected_error;
  263. expected_error << "Invalid " << GetParam().width
  264. << "-bit float literal: " << GetParam().literal;
  265. EXPECT_THAT(CompileFailure(input.str()), Eq(expected_error.str()));
  266. }
  267. }
  268. // clang-format off
  269. INSTANTIATE_TEST_SUITE_P(
  270. TextToBinaryInvalidFloatConstant, OpConstantInvalidFloatConstant,
  271. ::testing::ValuesIn(std::vector<InvalidFloatConstantCase>{
  272. {16, "abc"},
  273. {16, "--1"},
  274. {16, "-+1"},
  275. {16, "+-1"},
  276. {16, "++1"},
  277. {16, "1e30"}, // Overflow is an error for 16-bit floats.
  278. {16, "-1e30"},
  279. {16, "1e40"},
  280. {16, "-1e40"},
  281. {16, "1e400"},
  282. {16, "-1e400"},
  283. {32, "abc"},
  284. {32, "--1"},
  285. {32, "-+1"},
  286. {32, "+-1"},
  287. {32, "++1"},
  288. {32, "1e40"}, // Overflow is an error for 32-bit floats.
  289. {32, "-1e40"},
  290. {32, "1e400"},
  291. {32, "-1e400"},
  292. {64, "abc"},
  293. {64, "--1"},
  294. {64, "-+1"},
  295. {64, "+-1"},
  296. {64, "++1"},
  297. {32, "1e400"}, // Overflow is an error for 64-bit floats.
  298. {32, "-1e400"},
  299. }));
  300. // clang-format on
  301. using OpConstantInvalidTypeTest =
  302. spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>;
  303. TEST_P(OpConstantInvalidTypeTest, InvalidTypes) {
  304. const std::string input = "%1 = " + GetParam() +
  305. "\n"
  306. "%2 = OpConstant %1 0\n";
  307. EXPECT_THAT(
  308. CompileFailure(input),
  309. Eq("Type for Constant must be a scalar floating point or integer type"));
  310. }
  311. // clang-format off
  312. INSTANTIATE_TEST_SUITE_P(
  313. TextToBinaryOpConstantInvalidValidType, OpConstantInvalidTypeTest,
  314. ::testing::ValuesIn(std::vector<std::string>{
  315. {"OpTypeVoid",
  316. "OpTypeBool",
  317. "OpTypeVector %a 32",
  318. "OpTypeMatrix %a 32",
  319. "OpTypeImage %a 1D 0 0 0 0 Unknown",
  320. "OpTypeSampler",
  321. "OpTypeSampledImage %a",
  322. "OpTypeArray %a %b",
  323. "OpTypeRuntimeArray %a",
  324. "OpTypeStruct %a",
  325. "OpTypeOpaque \"Foo\"",
  326. "OpTypePointer UniformConstant %a",
  327. "OpTypeFunction %a %b",
  328. "OpTypeEvent",
  329. "OpTypeDeviceEvent",
  330. "OpTypeReserveId",
  331. "OpTypeQueue",
  332. "OpTypePipe ReadOnly",
  333. "OpTypeForwardPointer %a UniformConstant",
  334. // At least one thing that isn't a type at all
  335. "OpNot %a %b"
  336. },
  337. }));
  338. // clang-format on
  339. using OpSpecConstantValidTest =
  340. spvtest::TextToBinaryTestBase<::testing::TestWithParam<ConstantTestCase>>;
  341. TEST_P(OpSpecConstantValidTest, ValidTypes) {
  342. const std::string input = "%1 = " + GetParam().constant_type +
  343. "\n"
  344. "%2 = OpSpecConstant %1 " +
  345. GetParam().constant_value + "\n";
  346. std::vector<uint32_t> instructions;
  347. EXPECT_THAT(CompiledInstructions(input),
  348. Eq(GetParam().expected_instructions));
  349. }
  350. // clang-format off
  351. INSTANTIATE_TEST_SUITE_P(
  352. TextToBinaryOpSpecConstantValid, OpSpecConstantValidTest,
  353. ::testing::ValuesIn(std::vector<ConstantTestCase>{
  354. // Check 16 bits
  355. {"OpTypeInt 16 0", "0x1234",
  356. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 0}),
  357. MakeInstruction(SpvOpSpecConstant, {1, 2, 0x1234})})},
  358. {"OpTypeInt 16 0", "0x8000",
  359. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 0}),
  360. MakeInstruction(SpvOpSpecConstant, {1, 2, 0x8000})})},
  361. {"OpTypeInt 16 1", "0x8000", // Test sign extension.
  362. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 1}),
  363. MakeInstruction(SpvOpSpecConstant, {1, 2, 0xffff8000})})},
  364. {"OpTypeInt 16 1", "-32",
  365. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 16, 1}),
  366. MakeInstruction(SpvOpSpecConstant, {1, 2, uint32_t(-32)})})},
  367. // Check 32 bits
  368. {"OpTypeInt 32 0", "42",
  369. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 0}),
  370. MakeInstruction(SpvOpSpecConstant, {1, 2, 42})})},
  371. {"OpTypeInt 32 1", "-32",
  372. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 1}),
  373. MakeInstruction(SpvOpSpecConstant, {1, 2, uint32_t(-32)})})},
  374. {"OpTypeFloat 32", "1.0",
  375. Concatenate({MakeInstruction(SpvOpTypeFloat, {1, 32}),
  376. MakeInstruction(SpvOpSpecConstant, {1, 2, 0x3f800000})})},
  377. {"OpTypeFloat 32", "10.0",
  378. Concatenate({MakeInstruction(SpvOpTypeFloat, {1, 32}),
  379. MakeInstruction(SpvOpSpecConstant, {1, 2, 0x41200000})})},
  380. // Check 48 bits
  381. {"OpTypeInt 48 0", "0x1234",
  382. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 48, 0}),
  383. MakeInstruction(SpvOpSpecConstant, {1, 2, 0x1234, 0})})},
  384. {"OpTypeInt 48 0", "0x800000000001",
  385. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 48, 0}),
  386. MakeInstruction(SpvOpSpecConstant, {1, 2, 1, 0x00008000})})},
  387. {"OpTypeInt 48 1", "0x800000000000", // Test sign extension.
  388. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 48, 1}),
  389. MakeInstruction(SpvOpSpecConstant, {1, 2, 0, 0xffff8000})})},
  390. {"OpTypeInt 48 1", "-32",
  391. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 48, 1}),
  392. MakeInstruction(SpvOpSpecConstant, {1, 2, uint32_t(-32), uint32_t(-1)})})},
  393. // Check 64 bits
  394. {"OpTypeInt 64 0", "0x1234",
  395. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 0}),
  396. MakeInstruction(SpvOpSpecConstant, {1, 2, 0x1234, 0})})},
  397. {"OpTypeInt 64 1", "0x1234",
  398. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 1}),
  399. MakeInstruction(SpvOpSpecConstant, {1, 2, 0x1234, 0})})},
  400. {"OpTypeInt 64 1", "-42",
  401. Concatenate({MakeInstruction(SpvOpTypeInt, {1, 64, 1}),
  402. MakeInstruction(SpvOpSpecConstant, {1, 2, uint32_t(-42), uint32_t(-1)})})},
  403. }));
  404. // clang-format on
  405. using OpSpecConstantInvalidTypeTest =
  406. spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>;
  407. TEST_P(OpSpecConstantInvalidTypeTest, InvalidTypes) {
  408. const std::string input = "%1 = " + GetParam() +
  409. "\n"
  410. "%2 = OpSpecConstant %1 0\n";
  411. EXPECT_THAT(CompileFailure(input),
  412. Eq("Type for SpecConstant must be a scalar floating point or "
  413. "integer type"));
  414. }
  415. // clang-format off
  416. INSTANTIATE_TEST_SUITE_P(
  417. TextToBinaryOpSpecConstantInvalidValidType, OpSpecConstantInvalidTypeTest,
  418. ::testing::ValuesIn(std::vector<std::string>{
  419. {"OpTypeVoid",
  420. "OpTypeBool",
  421. "OpTypeVector %a 32",
  422. "OpTypeMatrix %a 32",
  423. "OpTypeImage %a 1D 0 0 0 0 Unknown",
  424. "OpTypeSampler",
  425. "OpTypeSampledImage %a",
  426. "OpTypeArray %a %b",
  427. "OpTypeRuntimeArray %a",
  428. "OpTypeStruct %a",
  429. "OpTypeOpaque \"Foo\"",
  430. "OpTypePointer UniformConstant %a",
  431. "OpTypeFunction %a %b",
  432. "OpTypeEvent",
  433. "OpTypeDeviceEvent",
  434. "OpTypeReserveId",
  435. "OpTypeQueue",
  436. "OpTypePipe ReadOnly",
  437. "OpTypeForwardPointer %a UniformConstant",
  438. // At least one thing that isn't a type at all
  439. "OpNot %a %b"
  440. },
  441. }));
  442. // clang-format on
  443. const int64_t kMaxUnsigned48Bit = (int64_t(1) << 48) - 1;
  444. const int64_t kMaxSigned48Bit = (int64_t(1) << 47) - 1;
  445. const int64_t kMinSigned48Bit = -kMaxSigned48Bit - 1;
  446. INSTANTIATE_TEST_SUITE_P(
  447. OpConstantRoundTrip, RoundTripTest,
  448. ::testing::ValuesIn(std::vector<std::string>{
  449. // 16 bit
  450. "%1 = OpTypeInt 16 0\n%2 = OpConstant %1 0\n",
  451. "%1 = OpTypeInt 16 0\n%2 = OpConstant %1 65535\n",
  452. "%1 = OpTypeInt 16 1\n%2 = OpConstant %1 -32768\n",
  453. "%1 = OpTypeInt 16 1\n%2 = OpConstant %1 32767\n",
  454. "%1 = OpTypeInt 32 0\n%2 = OpConstant %1 0\n",
  455. // 32 bit
  456. std::string("%1 = OpTypeInt 32 0\n%2 = OpConstant %1 0\n"),
  457. std::string("%1 = OpTypeInt 32 0\n%2 = OpConstant %1 ") +
  458. std::to_string(std::numeric_limits<uint32_t>::max()) + "\n",
  459. std::string("%1 = OpTypeInt 32 1\n%2 = OpConstant %1 ") +
  460. std::to_string(std::numeric_limits<int32_t>::max()) + "\n",
  461. std::string("%1 = OpTypeInt 32 1\n%2 = OpConstant %1 ") +
  462. std::to_string(std::numeric_limits<int32_t>::min()) + "\n",
  463. // 48 bit
  464. std::string("%1 = OpTypeInt 48 0\n%2 = OpConstant %1 0\n"),
  465. std::string("%1 = OpTypeInt 48 0\n%2 = OpConstant %1 ") +
  466. std::to_string(kMaxUnsigned48Bit) + "\n",
  467. std::string("%1 = OpTypeInt 48 1\n%2 = OpConstant %1 ") +
  468. std::to_string(kMaxSigned48Bit) + "\n",
  469. std::string("%1 = OpTypeInt 48 1\n%2 = OpConstant %1 ") +
  470. std::to_string(kMinSigned48Bit) + "\n",
  471. // 64 bit
  472. std::string("%1 = OpTypeInt 64 0\n%2 = OpConstant %1 0\n"),
  473. std::string("%1 = OpTypeInt 64 0\n%2 = OpConstant %1 ") +
  474. std::to_string(std::numeric_limits<uint64_t>::max()) + "\n",
  475. std::string("%1 = OpTypeInt 64 1\n%2 = OpConstant %1 ") +
  476. std::to_string(std::numeric_limits<int64_t>::max()) + "\n",
  477. std::string("%1 = OpTypeInt 64 1\n%2 = OpConstant %1 ") +
  478. std::to_string(std::numeric_limits<int64_t>::min()) + "\n",
  479. // 32-bit float
  480. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 0\n",
  481. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 13.5\n",
  482. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 -12.5\n",
  483. // 64-bit float
  484. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 0\n",
  485. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 1.79767e+308\n",
  486. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 -1.79767e+308\n",
  487. }));
  488. INSTANTIATE_TEST_SUITE_P(
  489. OpConstantHalfRoundTrip, RoundTripTest,
  490. ::testing::ValuesIn(std::vector<std::string>{
  491. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x0p+0\n",
  492. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x0p+0\n",
  493. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1p+0\n",
  494. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.1p+0\n",
  495. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.01p-1\n",
  496. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.8p+1\n",
  497. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.ffcp+1\n",
  498. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1p+0\n",
  499. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.1p+0\n",
  500. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.01p-1\n",
  501. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.8p+1\n",
  502. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.ffcp+1\n",
  503. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1p-16\n", // some denorms
  504. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1p-24\n",
  505. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1p-24\n",
  506. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1p+16\n", // +inf
  507. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1p+16\n", // -inf
  508. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.01p+16\n", // -inf
  509. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.01p+16\n", // nan
  510. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.11p+16\n", // nan
  511. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.ffp+16\n", // nan
  512. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.ffcp+16\n", // nan
  513. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.004p+16\n", // nan
  514. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.01p+16\n", // -nan
  515. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.11p+16\n", // -nan
  516. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.ffp+16\n", // -nan
  517. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.ffcp+16\n", // -nan
  518. "%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.004p+16\n", // -nan
  519. }));
  520. // clang-format off
  521. // (Clang-format really wants to break up these strings across lines.
  522. INSTANTIATE_TEST_SUITE_P(
  523. OpConstantRoundTripNonFinite, RoundTripTest,
  524. ::testing::ValuesIn(std::vector<std::string>{
  525. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0x1p+128\n", // -inf
  526. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 0x1p+128\n", // inf
  527. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0x1.8p+128\n", // -nan
  528. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0x1.0002p+128\n", // -nan
  529. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0x1.0018p+128\n", // -nan
  530. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0x1.01ep+128\n", // -nan
  531. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0x1.fffffep+128\n", // -nan
  532. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 0x1.8p+128\n", // +nan
  533. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 0x1.0002p+128\n", // +nan
  534. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 0x1.0018p+128\n", // +nan
  535. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 0x1.01ep+128\n", // +nan
  536. "%1 = OpTypeFloat 32\n%2 = OpConstant %1 0x1.fffffep+128\n", // +nan
  537. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 -0x1p+1024\n", // -inf
  538. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 0x1p+1024\n", // +inf
  539. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 -0x1.8p+1024\n", // -nan
  540. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 -0x1.0fp+1024\n", // -nan
  541. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 -0x1.0000000000001p+1024\n", // -nan
  542. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 -0x1.00003p+1024\n", // -nan
  543. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 -0x1.fffffffffffffp+1024\n", // -nan
  544. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 0x1.8p+1024\n", // +nan
  545. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 0x1.0fp+1024\n", // +nan
  546. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 0x1.0000000000001p+1024\n", // -nan
  547. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 0x1.00003p+1024\n", // -nan
  548. "%1 = OpTypeFloat 64\n%2 = OpConstant %1 0x1.fffffffffffffp+1024\n", // -nan
  549. }));
  550. // clang-format on
  551. INSTANTIATE_TEST_SUITE_P(
  552. OpSpecConstantRoundTrip, RoundTripTest,
  553. ::testing::ValuesIn(std::vector<std::string>{
  554. // 16 bit
  555. "%1 = OpTypeInt 16 0\n%2 = OpSpecConstant %1 0\n",
  556. "%1 = OpTypeInt 16 0\n%2 = OpSpecConstant %1 65535\n",
  557. "%1 = OpTypeInt 16 1\n%2 = OpSpecConstant %1 -32768\n",
  558. "%1 = OpTypeInt 16 1\n%2 = OpSpecConstant %1 32767\n",
  559. "%1 = OpTypeInt 32 0\n%2 = OpSpecConstant %1 0\n",
  560. // 32 bit
  561. std::string("%1 = OpTypeInt 32 0\n%2 = OpSpecConstant %1 0\n"),
  562. std::string("%1 = OpTypeInt 32 0\n%2 = OpSpecConstant %1 ") +
  563. std::to_string(std::numeric_limits<uint32_t>::max()) + "\n",
  564. std::string("%1 = OpTypeInt 32 1\n%2 = OpSpecConstant %1 ") +
  565. std::to_string(std::numeric_limits<int32_t>::max()) + "\n",
  566. std::string("%1 = OpTypeInt 32 1\n%2 = OpSpecConstant %1 ") +
  567. std::to_string(std::numeric_limits<int32_t>::min()) + "\n",
  568. // 48 bit
  569. std::string("%1 = OpTypeInt 48 0\n%2 = OpSpecConstant %1 0\n"),
  570. std::string("%1 = OpTypeInt 48 0\n%2 = OpSpecConstant %1 ") +
  571. std::to_string(kMaxUnsigned48Bit) + "\n",
  572. std::string("%1 = OpTypeInt 48 1\n%2 = OpSpecConstant %1 ") +
  573. std::to_string(kMaxSigned48Bit) + "\n",
  574. std::string("%1 = OpTypeInt 48 1\n%2 = OpSpecConstant %1 ") +
  575. std::to_string(kMinSigned48Bit) + "\n",
  576. // 64 bit
  577. std::string("%1 = OpTypeInt 64 0\n%2 = OpSpecConstant %1 0\n"),
  578. std::string("%1 = OpTypeInt 64 0\n%2 = OpSpecConstant %1 ") +
  579. std::to_string(std::numeric_limits<uint64_t>::max()) + "\n",
  580. std::string("%1 = OpTypeInt 64 1\n%2 = OpSpecConstant %1 ") +
  581. std::to_string(std::numeric_limits<int64_t>::max()) + "\n",
  582. std::string("%1 = OpTypeInt 64 1\n%2 = OpSpecConstant %1 ") +
  583. std::to_string(std::numeric_limits<int64_t>::min()) + "\n",
  584. // 32-bit float
  585. "%1 = OpTypeFloat 32\n%2 = OpSpecConstant %1 0\n",
  586. "%1 = OpTypeFloat 32\n%2 = OpSpecConstant %1 13.5\n",
  587. "%1 = OpTypeFloat 32\n%2 = OpSpecConstant %1 -12.5\n",
  588. // 64-bit float
  589. "%1 = OpTypeFloat 64\n%2 = OpSpecConstant %1 0\n",
  590. "%1 = OpTypeFloat 64\n%2 = OpSpecConstant %1 1.79767e+308\n",
  591. "%1 = OpTypeFloat 64\n%2 = OpSpecConstant %1 -1.79767e+308\n",
  592. }));
  593. // Test OpSpecConstantOp
  594. using OpSpecConstantOpTestWithIds =
  595. spvtest::TextToBinaryTestBase<::testing::TestWithParam<EnumCase<SpvOp>>>;
  596. // The operands to the OpSpecConstantOp opcode are all Ids.
  597. TEST_P(OpSpecConstantOpTestWithIds, Assembly) {
  598. std::stringstream input;
  599. input << "%2 = OpSpecConstantOp %1 " << GetParam().name();
  600. for (auto id : GetParam().operands()) input << " %" << id;
  601. input << "\n";
  602. EXPECT_THAT(CompiledInstructions(input.str()),
  603. Eq(MakeInstruction(SpvOpSpecConstantOp,
  604. {1, 2, uint32_t(GetParam().value())},
  605. GetParam().operands())));
  606. // Check the disassembler as well.
  607. EXPECT_THAT(EncodeAndDecodeSuccessfully(input.str()), input.str());
  608. }
  609. // clang-format off
  610. #define CASE1(NAME) { SpvOp##NAME, #NAME, {3} }
  611. #define CASE2(NAME) { SpvOp##NAME, #NAME, {3, 4} }
  612. #define CASE3(NAME) { SpvOp##NAME, #NAME, {3, 4, 5} }
  613. #define CASE4(NAME) { SpvOp##NAME, #NAME, {3, 4, 5, 6} }
  614. #define CASE5(NAME) { SpvOp##NAME, #NAME, {3, 4, 5, 6, 7} }
  615. #define CASE6(NAME) { SpvOp##NAME, #NAME, {3, 4, 5, 6, 7, 8} }
  616. INSTANTIATE_TEST_SUITE_P(
  617. TextToBinaryOpSpecConstantOp, OpSpecConstantOpTestWithIds,
  618. ::testing::ValuesIn(std::vector<EnumCase<SpvOp>>{
  619. // Conversion
  620. CASE1(SConvert),
  621. CASE1(FConvert),
  622. CASE1(ConvertFToS),
  623. CASE1(ConvertSToF),
  624. CASE1(ConvertFToU),
  625. CASE1(ConvertUToF),
  626. CASE1(UConvert),
  627. CASE1(ConvertPtrToU),
  628. CASE1(ConvertUToPtr),
  629. CASE1(GenericCastToPtr),
  630. CASE1(PtrCastToGeneric),
  631. CASE1(Bitcast),
  632. CASE1(QuantizeToF16),
  633. // Arithmetic
  634. CASE1(SNegate),
  635. CASE1(Not),
  636. CASE2(IAdd),
  637. CASE2(ISub),
  638. CASE2(IMul),
  639. CASE2(UDiv),
  640. CASE2(SDiv),
  641. CASE2(UMod),
  642. CASE2(SRem),
  643. CASE2(SMod),
  644. CASE2(ShiftRightLogical),
  645. CASE2(ShiftRightArithmetic),
  646. CASE2(ShiftLeftLogical),
  647. CASE2(BitwiseOr),
  648. CASE2(BitwiseAnd),
  649. CASE2(BitwiseXor),
  650. CASE1(FNegate),
  651. CASE2(FAdd),
  652. CASE2(FSub),
  653. CASE2(FMul),
  654. CASE2(FDiv),
  655. CASE2(FRem),
  656. CASE2(FMod),
  657. // Composite operations use literal numbers. So they're in another test.
  658. // Logical
  659. CASE2(LogicalOr),
  660. CASE2(LogicalAnd),
  661. CASE1(LogicalNot),
  662. CASE2(LogicalEqual),
  663. CASE2(LogicalNotEqual),
  664. CASE3(Select),
  665. // Comparison
  666. CASE2(IEqual),
  667. CASE2(INotEqual), // Allowed in 1.0 Rev 7
  668. CASE2(ULessThan),
  669. CASE2(SLessThan),
  670. CASE2(UGreaterThan),
  671. CASE2(SGreaterThan),
  672. CASE2(ULessThanEqual),
  673. CASE2(SLessThanEqual),
  674. CASE2(UGreaterThanEqual),
  675. CASE2(SGreaterThanEqual),
  676. // Memory
  677. // For AccessChain, there is a base Id, then a sequence of index Ids.
  678. // Having no index Ids is a corner case.
  679. CASE1(AccessChain),
  680. CASE2(AccessChain),
  681. CASE6(AccessChain),
  682. CASE1(InBoundsAccessChain),
  683. CASE2(InBoundsAccessChain),
  684. CASE6(InBoundsAccessChain),
  685. // PtrAccessChain also has an element Id.
  686. CASE2(PtrAccessChain),
  687. CASE3(PtrAccessChain),
  688. CASE6(PtrAccessChain),
  689. CASE2(InBoundsPtrAccessChain),
  690. CASE3(InBoundsPtrAccessChain),
  691. CASE6(InBoundsPtrAccessChain),
  692. }));
  693. #undef CASE1
  694. #undef CASE2
  695. #undef CASE3
  696. #undef CASE4
  697. #undef CASE5
  698. #undef CASE6
  699. // clang-format on
  700. using OpSpecConstantOpTestWithTwoIdsThenLiteralNumbers =
  701. spvtest::TextToBinaryTestBase<::testing::TestWithParam<EnumCase<SpvOp>>>;
  702. // The operands to the OpSpecConstantOp opcode are two Ids followed by a
  703. // sequence of literal numbers.
  704. TEST_P(OpSpecConstantOpTestWithTwoIdsThenLiteralNumbers, Assembly) {
  705. std::stringstream input;
  706. input << "%2 = OpSpecConstantOp %1 " << GetParam().name() << " %3 %4";
  707. for (auto number : GetParam().operands()) input << " " << number;
  708. input << "\n";
  709. EXPECT_THAT(CompiledInstructions(input.str()),
  710. Eq(MakeInstruction(SpvOpSpecConstantOp,
  711. {1, 2, uint32_t(GetParam().value()), 3, 4},
  712. GetParam().operands())));
  713. // Check the disassembler as well.
  714. EXPECT_THAT(EncodeAndDecodeSuccessfully(input.str()), input.str());
  715. }
  716. #define CASE(NAME) SpvOp##NAME, #NAME
  717. INSTANTIATE_TEST_SUITE_P(
  718. TextToBinaryOpSpecConstantOp,
  719. OpSpecConstantOpTestWithTwoIdsThenLiteralNumbers,
  720. ::testing::ValuesIn(std::vector<EnumCase<SpvOp>>{
  721. // For VectorShuffle, there are two vector operands, and at least
  722. // two selector Ids. OpenCL can have up to 16-element vectors.
  723. {CASE(VectorShuffle), {0, 0}},
  724. {CASE(VectorShuffle), {4, 3, 2, 1}},
  725. {CASE(VectorShuffle), {0, 2, 4, 6, 1, 3, 5, 7}},
  726. {CASE(VectorShuffle),
  727. {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}},
  728. // For CompositeInsert, there is an object to insert, the target
  729. // composite, and then literal indices.
  730. {CASE(CompositeInsert), {0}},
  731. {CASE(CompositeInsert), {4, 3, 99, 1}},
  732. }));
  733. using OpSpecConstantOpTestWithOneIdThenLiteralNumbers =
  734. spvtest::TextToBinaryTestBase<::testing::TestWithParam<EnumCase<SpvOp>>>;
  735. // The operands to the OpSpecConstantOp opcode are one Id followed by a
  736. // sequence of literal numbers.
  737. TEST_P(OpSpecConstantOpTestWithOneIdThenLiteralNumbers, Assembly) {
  738. std::stringstream input;
  739. input << "%2 = OpSpecConstantOp %1 " << GetParam().name() << " %3";
  740. for (auto number : GetParam().operands()) input << " " << number;
  741. input << "\n";
  742. EXPECT_THAT(CompiledInstructions(input.str()),
  743. Eq(MakeInstruction(SpvOpSpecConstantOp,
  744. {1, 2, uint32_t(GetParam().value()), 3},
  745. GetParam().operands())));
  746. // Check the disassembler as well.
  747. EXPECT_THAT(EncodeAndDecodeSuccessfully(input.str()), input.str());
  748. }
  749. #define CASE(NAME) SpvOp##NAME, #NAME
  750. INSTANTIATE_TEST_SUITE_P(
  751. TextToBinaryOpSpecConstantOp,
  752. OpSpecConstantOpTestWithOneIdThenLiteralNumbers,
  753. ::testing::ValuesIn(std::vector<EnumCase<SpvOp>>{
  754. // For CompositeExtract, the universal limit permits up to 255 literal
  755. // indices. Let's only test a few.
  756. {CASE(CompositeExtract), {0}},
  757. {CASE(CompositeExtract), {0, 99, 42, 16, 17, 12, 19}},
  758. }));
  759. // TODO(dneto): OpConstantTrue
  760. // TODO(dneto): OpConstantFalse
  761. // TODO(dneto): OpConstantComposite
  762. // TODO(dneto): OpConstantSampler: other variations Param is 0 or 1
  763. // TODO(dneto): OpConstantNull
  764. // TODO(dneto): OpSpecConstantTrue
  765. // TODO(dneto): OpSpecConstantFalse
  766. // TODO(dneto): OpSpecConstantComposite
  767. // TODO(dneto): Negative tests for OpSpecConstantOp
  768. } // namespace
  769. } // namespace spvtools