fuzzer_replayer_test.cpp 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  1. // Copyright (c) 2019 Google LLC
  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. #include "gtest/gtest.h"
  15. #include "source/fuzz/fuzzer.h"
  16. #include "source/fuzz/fuzzer_util.h"
  17. #include "source/fuzz/pseudo_random_generator.h"
  18. #include "source/fuzz/replayer.h"
  19. #include "source/fuzz/uniform_buffer_element_descriptor.h"
  20. #include "test/fuzz/fuzz_test_util.h"
  21. namespace spvtools {
  22. namespace fuzz {
  23. namespace {
  24. const uint32_t kNumFuzzerRuns = 20;
  25. // The SPIR-V came from this GLSL:
  26. //
  27. // #version 310 es
  28. //
  29. // void foo() {
  30. // int x;
  31. // x = 2;
  32. // for (int i = 0; i < 100; i++) {
  33. // x += i;
  34. // x = x * 2;
  35. // }
  36. // return;
  37. // }
  38. //
  39. // void main() {
  40. // foo();
  41. // for (int i = 0; i < 10; i++) {
  42. // int j = 20;
  43. // while(j > 0) {
  44. // foo();
  45. // j--;
  46. // }
  47. // do {
  48. // i++;
  49. // } while(i < 4);
  50. // }
  51. // }
  52. const std::string kTestShader1 = R"(
  53. OpCapability Shader
  54. %1 = OpExtInstImport "GLSL.std.450"
  55. OpMemoryModel Logical GLSL450
  56. OpEntryPoint Fragment %4 "main"
  57. OpExecutionMode %4 OriginUpperLeft
  58. OpSource ESSL 310
  59. OpName %4 "main"
  60. OpName %6 "foo("
  61. OpName %10 "x"
  62. OpName %12 "i"
  63. OpName %33 "i"
  64. OpName %42 "j"
  65. OpDecorate %10 RelaxedPrecision
  66. OpDecorate %12 RelaxedPrecision
  67. OpDecorate %19 RelaxedPrecision
  68. OpDecorate %23 RelaxedPrecision
  69. OpDecorate %24 RelaxedPrecision
  70. OpDecorate %25 RelaxedPrecision
  71. OpDecorate %26 RelaxedPrecision
  72. OpDecorate %27 RelaxedPrecision
  73. OpDecorate %28 RelaxedPrecision
  74. OpDecorate %30 RelaxedPrecision
  75. OpDecorate %33 RelaxedPrecision
  76. OpDecorate %39 RelaxedPrecision
  77. OpDecorate %42 RelaxedPrecision
  78. OpDecorate %49 RelaxedPrecision
  79. OpDecorate %52 RelaxedPrecision
  80. OpDecorate %53 RelaxedPrecision
  81. OpDecorate %58 RelaxedPrecision
  82. OpDecorate %59 RelaxedPrecision
  83. OpDecorate %60 RelaxedPrecision
  84. OpDecorate %63 RelaxedPrecision
  85. OpDecorate %64 RelaxedPrecision
  86. %2 = OpTypeVoid
  87. %3 = OpTypeFunction %2
  88. %8 = OpTypeInt 32 1
  89. %9 = OpTypePointer Function %8
  90. %11 = OpConstant %8 2
  91. %13 = OpConstant %8 0
  92. %20 = OpConstant %8 100
  93. %21 = OpTypeBool
  94. %29 = OpConstant %8 1
  95. %40 = OpConstant %8 10
  96. %43 = OpConstant %8 20
  97. %61 = OpConstant %8 4
  98. %4 = OpFunction %2 None %3
  99. %5 = OpLabel
  100. %33 = OpVariable %9 Function
  101. %42 = OpVariable %9 Function
  102. %32 = OpFunctionCall %2 %6
  103. OpStore %33 %13
  104. OpBranch %34
  105. %34 = OpLabel
  106. OpLoopMerge %36 %37 None
  107. OpBranch %38
  108. %38 = OpLabel
  109. %39 = OpLoad %8 %33
  110. %41 = OpSLessThan %21 %39 %40
  111. OpBranchConditional %41 %35 %36
  112. %35 = OpLabel
  113. OpStore %42 %43
  114. OpBranch %44
  115. %44 = OpLabel
  116. OpLoopMerge %46 %47 None
  117. OpBranch %48
  118. %48 = OpLabel
  119. %49 = OpLoad %8 %42
  120. %50 = OpSGreaterThan %21 %49 %13
  121. OpBranchConditional %50 %45 %46
  122. %45 = OpLabel
  123. %51 = OpFunctionCall %2 %6
  124. %52 = OpLoad %8 %42
  125. %53 = OpISub %8 %52 %29
  126. OpStore %42 %53
  127. OpBranch %47
  128. %47 = OpLabel
  129. OpBranch %44
  130. %46 = OpLabel
  131. OpBranch %54
  132. %54 = OpLabel
  133. OpLoopMerge %56 %57 None
  134. OpBranch %55
  135. %55 = OpLabel
  136. %58 = OpLoad %8 %33
  137. %59 = OpIAdd %8 %58 %29
  138. OpStore %33 %59
  139. OpBranch %57
  140. %57 = OpLabel
  141. %60 = OpLoad %8 %33
  142. %62 = OpSLessThan %21 %60 %61
  143. OpBranchConditional %62 %54 %56
  144. %56 = OpLabel
  145. OpBranch %37
  146. %37 = OpLabel
  147. %63 = OpLoad %8 %33
  148. %64 = OpIAdd %8 %63 %29
  149. OpStore %33 %64
  150. OpBranch %34
  151. %36 = OpLabel
  152. OpReturn
  153. OpFunctionEnd
  154. %6 = OpFunction %2 None %3
  155. %7 = OpLabel
  156. %10 = OpVariable %9 Function
  157. %12 = OpVariable %9 Function
  158. OpStore %10 %11
  159. OpStore %12 %13
  160. OpBranch %14
  161. %14 = OpLabel
  162. OpLoopMerge %16 %17 None
  163. OpBranch %18
  164. %18 = OpLabel
  165. %19 = OpLoad %8 %12
  166. %22 = OpSLessThan %21 %19 %20
  167. OpBranchConditional %22 %15 %16
  168. %15 = OpLabel
  169. %23 = OpLoad %8 %12
  170. %24 = OpLoad %8 %10
  171. %25 = OpIAdd %8 %24 %23
  172. OpStore %10 %25
  173. %26 = OpLoad %8 %10
  174. %27 = OpIMul %8 %26 %11
  175. OpStore %10 %27
  176. OpBranch %17
  177. %17 = OpLabel
  178. %28 = OpLoad %8 %12
  179. %30 = OpIAdd %8 %28 %29
  180. OpStore %12 %30
  181. OpBranch %14
  182. %16 = OpLabel
  183. OpReturn
  184. OpFunctionEnd
  185. )";
  186. // The SPIR-V came from this GLSL, which was then optimized using spirv-opt
  187. // with the -O argument:
  188. //
  189. // #version 310 es
  190. //
  191. // precision highp float;
  192. //
  193. // layout(location = 0) out vec4 _GLF_color;
  194. //
  195. // layout(set = 0, binding = 0) uniform buf0 {
  196. // vec2 injectionSwitch;
  197. // };
  198. // layout(set = 0, binding = 1) uniform buf1 {
  199. // vec2 resolution;
  200. // };
  201. // bool checkSwap(float a, float b)
  202. // {
  203. // return gl_FragCoord.y < resolution.y / 2.0 ? a > b : a < b;
  204. // }
  205. // void main()
  206. // {
  207. // float data[10];
  208. // for(int i = 0; i < 10; i++)
  209. // {
  210. // data[i] = float(10 - i) * injectionSwitch.y;
  211. // }
  212. // for(int i = 0; i < 9; i++)
  213. // {
  214. // for(int j = 0; j < 10; j++)
  215. // {
  216. // if(j < i + 1)
  217. // {
  218. // continue;
  219. // }
  220. // bool doSwap = checkSwap(data[i], data[j]);
  221. // if(doSwap)
  222. // {
  223. // float temp = data[i];
  224. // data[i] = data[j];
  225. // data[j] = temp;
  226. // }
  227. // }
  228. // }
  229. // if(gl_FragCoord.x < resolution.x / 2.0)
  230. // {
  231. // _GLF_color = vec4(data[0] / 10.0, data[5] / 10.0, data[9] / 10.0, 1.0);
  232. // }
  233. // else
  234. // {
  235. // _GLF_color = vec4(data[5] / 10.0, data[9] / 10.0, data[0] / 10.0, 1.0);
  236. // }
  237. // }
  238. const std::string kTestShader2 = R"(
  239. OpCapability Shader
  240. %1 = OpExtInstImport "GLSL.std.450"
  241. OpMemoryModel Logical GLSL450
  242. OpEntryPoint Fragment %4 "main" %16 %139 %25 %68
  243. OpExecutionMode %4 OriginUpperLeft
  244. OpSource ESSL 310
  245. OpName %4 "main"
  246. OpName %16 "gl_FragCoord"
  247. OpName %23 "buf1"
  248. OpMemberName %23 0 "resolution"
  249. OpName %25 ""
  250. OpName %61 "data"
  251. OpName %66 "buf0"
  252. OpMemberName %66 0 "injectionSwitch"
  253. OpName %68 ""
  254. OpName %139 "_GLF_color"
  255. OpDecorate %16 BuiltIn FragCoord
  256. OpMemberDecorate %23 0 Offset 0
  257. OpDecorate %23 Block
  258. OpDecorate %25 DescriptorSet 0
  259. OpDecorate %25 Binding 1
  260. OpDecorate %64 RelaxedPrecision
  261. OpMemberDecorate %66 0 Offset 0
  262. OpDecorate %66 Block
  263. OpDecorate %68 DescriptorSet 0
  264. OpDecorate %68 Binding 0
  265. OpDecorate %75 RelaxedPrecision
  266. OpDecorate %95 RelaxedPrecision
  267. OpDecorate %126 RelaxedPrecision
  268. OpDecorate %128 RelaxedPrecision
  269. OpDecorate %139 Location 0
  270. OpDecorate %182 RelaxedPrecision
  271. OpDecorate %183 RelaxedPrecision
  272. OpDecorate %184 RelaxedPrecision
  273. %2 = OpTypeVoid
  274. %3 = OpTypeFunction %2
  275. %6 = OpTypeFloat 32
  276. %7 = OpTypePointer Function %6
  277. %8 = OpTypeBool
  278. %14 = OpTypeVector %6 4
  279. %15 = OpTypePointer Input %14
  280. %16 = OpVariable %15 Input
  281. %17 = OpTypeInt 32 0
  282. %18 = OpConstant %17 1
  283. %19 = OpTypePointer Input %6
  284. %22 = OpTypeVector %6 2
  285. %23 = OpTypeStruct %22
  286. %24 = OpTypePointer Uniform %23
  287. %25 = OpVariable %24 Uniform
  288. %26 = OpTypeInt 32 1
  289. %27 = OpConstant %26 0
  290. %28 = OpTypePointer Uniform %6
  291. %56 = OpConstant %26 10
  292. %58 = OpConstant %17 10
  293. %59 = OpTypeArray %6 %58
  294. %60 = OpTypePointer Function %59
  295. %66 = OpTypeStruct %22
  296. %67 = OpTypePointer Uniform %66
  297. %68 = OpVariable %67 Uniform
  298. %74 = OpConstant %26 1
  299. %83 = OpConstant %26 9
  300. %129 = OpConstant %17 0
  301. %138 = OpTypePointer Output %14
  302. %139 = OpVariable %138 Output
  303. %144 = OpConstant %26 5
  304. %151 = OpConstant %6 1
  305. %194 = OpConstant %6 0.5
  306. %195 = OpConstant %6 0.100000001
  307. %4 = OpFunction %2 None %3
  308. %5 = OpLabel
  309. %61 = OpVariable %60 Function
  310. OpBranch %50
  311. %50 = OpLabel
  312. %182 = OpPhi %26 %27 %5 %75 %51
  313. %57 = OpSLessThan %8 %182 %56
  314. OpLoopMerge %52 %51 None
  315. OpBranchConditional %57 %51 %52
  316. %51 = OpLabel
  317. %64 = OpISub %26 %56 %182
  318. %65 = OpConvertSToF %6 %64
  319. %69 = OpAccessChain %28 %68 %27 %18
  320. %70 = OpLoad %6 %69
  321. %71 = OpFMul %6 %65 %70
  322. %72 = OpAccessChain %7 %61 %182
  323. OpStore %72 %71
  324. %75 = OpIAdd %26 %182 %74
  325. OpBranch %50
  326. %52 = OpLabel
  327. OpBranch %77
  328. %77 = OpLabel
  329. %183 = OpPhi %26 %27 %52 %128 %88
  330. %84 = OpSLessThan %8 %183 %83
  331. OpLoopMerge %79 %88 None
  332. OpBranchConditional %84 %78 %79
  333. %78 = OpLabel
  334. OpBranch %86
  335. %86 = OpLabel
  336. %184 = OpPhi %26 %27 %78 %126 %89
  337. %92 = OpSLessThan %8 %184 %56
  338. OpLoopMerge %1000 %89 None
  339. OpBranchConditional %92 %87 %1000
  340. %87 = OpLabel
  341. %95 = OpIAdd %26 %183 %74
  342. %96 = OpSLessThan %8 %184 %95
  343. OpSelectionMerge %98 None
  344. OpBranchConditional %96 %97 %98
  345. %97 = OpLabel
  346. OpBranch %89
  347. %98 = OpLabel
  348. %104 = OpAccessChain %7 %61 %183
  349. %105 = OpLoad %6 %104
  350. %107 = OpAccessChain %7 %61 %184
  351. %108 = OpLoad %6 %107
  352. %166 = OpAccessChain %19 %16 %18
  353. %167 = OpLoad %6 %166
  354. %168 = OpAccessChain %28 %25 %27 %18
  355. %169 = OpLoad %6 %168
  356. %170 = OpFMul %6 %169 %194
  357. %171 = OpFOrdLessThan %8 %167 %170
  358. OpSelectionMerge %172 None
  359. OpBranchConditional %171 %173 %174
  360. %173 = OpLabel
  361. %177 = OpFOrdGreaterThan %8 %105 %108
  362. OpBranch %172
  363. %174 = OpLabel
  364. %180 = OpFOrdLessThan %8 %105 %108
  365. OpBranch %172
  366. %172 = OpLabel
  367. %186 = OpPhi %8 %177 %173 %180 %174
  368. OpSelectionMerge %112 None
  369. OpBranchConditional %186 %111 %112
  370. %111 = OpLabel
  371. %116 = OpLoad %6 %104
  372. %120 = OpLoad %6 %107
  373. OpStore %104 %120
  374. OpStore %107 %116
  375. OpBranch %112
  376. %112 = OpLabel
  377. OpBranch %89
  378. %89 = OpLabel
  379. %126 = OpIAdd %26 %184 %74
  380. OpBranch %86
  381. %1000 = OpLabel
  382. OpBranch %88
  383. %88 = OpLabel
  384. %128 = OpIAdd %26 %183 %74
  385. OpBranch %77
  386. %79 = OpLabel
  387. %130 = OpAccessChain %19 %16 %129
  388. %131 = OpLoad %6 %130
  389. %132 = OpAccessChain %28 %25 %27 %129
  390. %133 = OpLoad %6 %132
  391. %134 = OpFMul %6 %133 %194
  392. %135 = OpFOrdLessThan %8 %131 %134
  393. OpSelectionMerge %137 None
  394. OpBranchConditional %135 %136 %153
  395. %136 = OpLabel
  396. %140 = OpAccessChain %7 %61 %27
  397. %141 = OpLoad %6 %140
  398. %143 = OpFMul %6 %141 %195
  399. %145 = OpAccessChain %7 %61 %144
  400. %146 = OpLoad %6 %145
  401. %147 = OpFMul %6 %146 %195
  402. %148 = OpAccessChain %7 %61 %83
  403. %149 = OpLoad %6 %148
  404. %150 = OpFMul %6 %149 %195
  405. %152 = OpCompositeConstruct %14 %143 %147 %150 %151
  406. OpStore %139 %152
  407. OpBranch %137
  408. %153 = OpLabel
  409. %154 = OpAccessChain %7 %61 %144
  410. %155 = OpLoad %6 %154
  411. %156 = OpFMul %6 %155 %195
  412. %157 = OpAccessChain %7 %61 %83
  413. %158 = OpLoad %6 %157
  414. %159 = OpFMul %6 %158 %195
  415. %160 = OpAccessChain %7 %61 %27
  416. %161 = OpLoad %6 %160
  417. %162 = OpFMul %6 %161 %195
  418. %163 = OpCompositeConstruct %14 %156 %159 %162 %151
  419. OpStore %139 %163
  420. OpBranch %137
  421. %137 = OpLabel
  422. OpReturn
  423. OpFunctionEnd
  424. )";
  425. // The SPIR-V came from this GLSL, which was then optimized using spirv-opt
  426. // with the -O argument:
  427. //
  428. // #version 310 es
  429. //
  430. // precision highp float;
  431. //
  432. // layout(location = 0) out vec4 _GLF_color;
  433. //
  434. // layout(set = 0, binding = 0) uniform buf0 {
  435. // vec2 resolution;
  436. // };
  437. // void main(void)
  438. // {
  439. // float A[50];
  440. // for(
  441. // int i = 0;
  442. // i < 200;
  443. // i ++
  444. // )
  445. // {
  446. // if(i >= int(resolution.x))
  447. // {
  448. // break;
  449. // }
  450. // if((4 * (i / 4)) == i)
  451. // {
  452. // A[i / 4] = float(i);
  453. // }
  454. // }
  455. // for(
  456. // int i = 0;
  457. // i < 50;
  458. // i ++
  459. // )
  460. // {
  461. // if(i < int(gl_FragCoord.x))
  462. // {
  463. // break;
  464. // }
  465. // if(i > 0)
  466. // {
  467. // A[i] += A[i - 1];
  468. // }
  469. // }
  470. // if(int(gl_FragCoord.x) < 20)
  471. // {
  472. // _GLF_color = vec4(A[0] / resolution.x, A[4] / resolution.y, 1.0, 1.0);
  473. // }
  474. // else
  475. // if(int(gl_FragCoord.x) < 40)
  476. // {
  477. // _GLF_color = vec4(A[5] / resolution.x, A[9] / resolution.y, 1.0, 1.0);
  478. // }
  479. // else
  480. // if(int(gl_FragCoord.x) < 60)
  481. // {
  482. // _GLF_color = vec4(A[10] / resolution.x, A[14] / resolution.y,
  483. // 1.0, 1.0);
  484. // }
  485. // else
  486. // if(int(gl_FragCoord.x) < 80)
  487. // {
  488. // _GLF_color = vec4(A[15] / resolution.x, A[19] / resolution.y,
  489. // 1.0, 1.0);
  490. // }
  491. // else
  492. // if(int(gl_FragCoord.x) < 100)
  493. // {
  494. // _GLF_color = vec4(A[20] / resolution.x, A[24] / resolution.y,
  495. // 1.0, 1.0);
  496. // }
  497. // else
  498. // if(int(gl_FragCoord.x) < 120)
  499. // {
  500. // _GLF_color = vec4(A[25] / resolution.x, A[29] / resolution.y,
  501. // 1.0, 1.0);
  502. // }
  503. // else
  504. // if(int(gl_FragCoord.x) < 140)
  505. // {
  506. // _GLF_color = vec4(A[30] / resolution.x, A[34] / resolution.y,
  507. // 1.0, 1.0);
  508. // }
  509. // else
  510. // if(int(gl_FragCoord.x) < 160)
  511. // {
  512. // _GLF_color = vec4(A[35] / resolution.x, A[39] /
  513. // resolution.y, 1.0, 1.0);
  514. // }
  515. // else
  516. // if(int(gl_FragCoord.x) < 180)
  517. // {
  518. // _GLF_color = vec4(A[40] / resolution.x, A[44] /
  519. // resolution.y, 1.0, 1.0);
  520. // }
  521. // else
  522. // if(int(gl_FragCoord.x) < 180)
  523. // {
  524. // _GLF_color = vec4(A[45] / resolution.x, A[49] /
  525. // resolution.y, 1.0, 1.0);
  526. // }
  527. // else
  528. // {
  529. // discard;
  530. // }
  531. // }
  532. const std::string kTestShader3 = R"(
  533. OpCapability Shader
  534. %1 = OpExtInstImport "GLSL.std.450"
  535. OpMemoryModel Logical GLSL450
  536. OpEntryPoint Fragment %4 "main" %68 %100 %24
  537. OpExecutionMode %4 OriginUpperLeft
  538. OpSource ESSL 310
  539. OpName %4 "main"
  540. OpName %22 "buf0"
  541. OpMemberName %22 0 "resolution"
  542. OpName %24 ""
  543. OpName %46 "A"
  544. OpName %68 "gl_FragCoord"
  545. OpName %100 "_GLF_color"
  546. OpMemberDecorate %22 0 Offset 0
  547. OpDecorate %22 Block
  548. OpDecorate %24 DescriptorSet 0
  549. OpDecorate %24 Binding 0
  550. OpDecorate %37 RelaxedPrecision
  551. OpDecorate %38 RelaxedPrecision
  552. OpDecorate %55 RelaxedPrecision
  553. OpDecorate %68 BuiltIn FragCoord
  554. OpDecorate %83 RelaxedPrecision
  555. OpDecorate %91 RelaxedPrecision
  556. OpDecorate %100 Location 0
  557. OpDecorate %302 RelaxedPrecision
  558. OpDecorate %304 RelaxedPrecision
  559. %2 = OpTypeVoid
  560. %3 = OpTypeFunction %2
  561. %6 = OpTypeInt 32 1
  562. %9 = OpConstant %6 0
  563. %16 = OpConstant %6 200
  564. %17 = OpTypeBool
  565. %20 = OpTypeFloat 32
  566. %21 = OpTypeVector %20 2
  567. %22 = OpTypeStruct %21
  568. %23 = OpTypePointer Uniform %22
  569. %24 = OpVariable %23 Uniform
  570. %25 = OpTypeInt 32 0
  571. %26 = OpConstant %25 0
  572. %27 = OpTypePointer Uniform %20
  573. %35 = OpConstant %6 4
  574. %43 = OpConstant %25 50
  575. %44 = OpTypeArray %20 %43
  576. %45 = OpTypePointer Function %44
  577. %51 = OpTypePointer Function %20
  578. %54 = OpConstant %6 1
  579. %63 = OpConstant %6 50
  580. %66 = OpTypeVector %20 4
  581. %67 = OpTypePointer Input %66
  582. %68 = OpVariable %67 Input
  583. %69 = OpTypePointer Input %20
  584. %95 = OpConstant %6 20
  585. %99 = OpTypePointer Output %66
  586. %100 = OpVariable %99 Output
  587. %108 = OpConstant %25 1
  588. %112 = OpConstant %20 1
  589. %118 = OpConstant %6 40
  590. %122 = OpConstant %6 5
  591. %128 = OpConstant %6 9
  592. %139 = OpConstant %6 60
  593. %143 = OpConstant %6 10
  594. %149 = OpConstant %6 14
  595. %160 = OpConstant %6 80
  596. %164 = OpConstant %6 15
  597. %170 = OpConstant %6 19
  598. %181 = OpConstant %6 100
  599. %190 = OpConstant %6 24
  600. %201 = OpConstant %6 120
  601. %205 = OpConstant %6 25
  602. %211 = OpConstant %6 29
  603. %222 = OpConstant %6 140
  604. %226 = OpConstant %6 30
  605. %232 = OpConstant %6 34
  606. %243 = OpConstant %6 160
  607. %247 = OpConstant %6 35
  608. %253 = OpConstant %6 39
  609. %264 = OpConstant %6 180
  610. %273 = OpConstant %6 44
  611. %287 = OpConstant %6 45
  612. %293 = OpConstant %6 49
  613. %4 = OpFunction %2 None %3
  614. %5 = OpLabel
  615. %46 = OpVariable %45 Function
  616. OpBranch %10
  617. %10 = OpLabel
  618. %302 = OpPhi %6 %9 %5 %55 %42
  619. %18 = OpSLessThan %17 %302 %16
  620. OpLoopMerge %12 %42 None
  621. OpBranchConditional %18 %11 %12
  622. %11 = OpLabel
  623. %28 = OpAccessChain %27 %24 %9 %26
  624. %29 = OpLoad %20 %28
  625. %30 = OpConvertFToS %6 %29
  626. %31 = OpSGreaterThanEqual %17 %302 %30
  627. OpSelectionMerge %33 None
  628. OpBranchConditional %31 %32 %33
  629. %32 = OpLabel
  630. OpBranch %12
  631. %33 = OpLabel
  632. %37 = OpSDiv %6 %302 %35
  633. %38 = OpIMul %6 %35 %37
  634. %40 = OpIEqual %17 %38 %302
  635. OpBranchConditional %40 %41 %42
  636. %41 = OpLabel
  637. %50 = OpConvertSToF %20 %302
  638. %52 = OpAccessChain %51 %46 %37
  639. OpStore %52 %50
  640. OpBranch %42
  641. %42 = OpLabel
  642. %55 = OpIAdd %6 %302 %54
  643. OpBranch %10
  644. %12 = OpLabel
  645. OpBranch %57
  646. %57 = OpLabel
  647. %304 = OpPhi %6 %9 %12 %91 %80
  648. %64 = OpSLessThan %17 %304 %63
  649. OpLoopMerge %59 %80 None
  650. OpBranchConditional %64 %58 %59
  651. %58 = OpLabel
  652. %70 = OpAccessChain %69 %68 %26
  653. %71 = OpLoad %20 %70
  654. %72 = OpConvertFToS %6 %71
  655. %73 = OpSLessThan %17 %304 %72
  656. OpSelectionMerge %75 None
  657. OpBranchConditional %73 %74 %75
  658. %74 = OpLabel
  659. OpBranch %59
  660. %75 = OpLabel
  661. %78 = OpSGreaterThan %17 %304 %9
  662. OpBranchConditional %78 %79 %80
  663. %79 = OpLabel
  664. %83 = OpISub %6 %304 %54
  665. %84 = OpAccessChain %51 %46 %83
  666. %85 = OpLoad %20 %84
  667. %86 = OpAccessChain %51 %46 %304
  668. %87 = OpLoad %20 %86
  669. %88 = OpFAdd %20 %87 %85
  670. OpStore %86 %88
  671. OpBranch %80
  672. %80 = OpLabel
  673. %91 = OpIAdd %6 %304 %54
  674. OpBranch %57
  675. %59 = OpLabel
  676. %92 = OpAccessChain %69 %68 %26
  677. %93 = OpLoad %20 %92
  678. %94 = OpConvertFToS %6 %93
  679. %96 = OpSLessThan %17 %94 %95
  680. OpSelectionMerge %98 None
  681. OpBranchConditional %96 %97 %114
  682. %97 = OpLabel
  683. %101 = OpAccessChain %51 %46 %9
  684. %102 = OpLoad %20 %101
  685. %103 = OpAccessChain %27 %24 %9 %26
  686. %104 = OpLoad %20 %103
  687. %105 = OpFDiv %20 %102 %104
  688. %106 = OpAccessChain %51 %46 %35
  689. %107 = OpLoad %20 %106
  690. %109 = OpAccessChain %27 %24 %9 %108
  691. %110 = OpLoad %20 %109
  692. %111 = OpFDiv %20 %107 %110
  693. %113 = OpCompositeConstruct %66 %105 %111 %112 %112
  694. OpStore %100 %113
  695. OpBranch %98
  696. %114 = OpLabel
  697. %119 = OpSLessThan %17 %94 %118
  698. OpSelectionMerge %121 None
  699. OpBranchConditional %119 %120 %135
  700. %120 = OpLabel
  701. %123 = OpAccessChain %51 %46 %122
  702. %124 = OpLoad %20 %123
  703. %125 = OpAccessChain %27 %24 %9 %26
  704. %126 = OpLoad %20 %125
  705. %127 = OpFDiv %20 %124 %126
  706. %129 = OpAccessChain %51 %46 %128
  707. %130 = OpLoad %20 %129
  708. %131 = OpAccessChain %27 %24 %9 %108
  709. %132 = OpLoad %20 %131
  710. %133 = OpFDiv %20 %130 %132
  711. %134 = OpCompositeConstruct %66 %127 %133 %112 %112
  712. OpStore %100 %134
  713. OpBranch %121
  714. %135 = OpLabel
  715. %140 = OpSLessThan %17 %94 %139
  716. OpSelectionMerge %142 None
  717. OpBranchConditional %140 %141 %156
  718. %141 = OpLabel
  719. %144 = OpAccessChain %51 %46 %143
  720. %145 = OpLoad %20 %144
  721. %146 = OpAccessChain %27 %24 %9 %26
  722. %147 = OpLoad %20 %146
  723. %148 = OpFDiv %20 %145 %147
  724. %150 = OpAccessChain %51 %46 %149
  725. %151 = OpLoad %20 %150
  726. %152 = OpAccessChain %27 %24 %9 %108
  727. %153 = OpLoad %20 %152
  728. %154 = OpFDiv %20 %151 %153
  729. %155 = OpCompositeConstruct %66 %148 %154 %112 %112
  730. OpStore %100 %155
  731. OpBranch %142
  732. %156 = OpLabel
  733. %161 = OpSLessThan %17 %94 %160
  734. OpSelectionMerge %163 None
  735. OpBranchConditional %161 %162 %177
  736. %162 = OpLabel
  737. %165 = OpAccessChain %51 %46 %164
  738. %166 = OpLoad %20 %165
  739. %167 = OpAccessChain %27 %24 %9 %26
  740. %168 = OpLoad %20 %167
  741. %169 = OpFDiv %20 %166 %168
  742. %171 = OpAccessChain %51 %46 %170
  743. %172 = OpLoad %20 %171
  744. %173 = OpAccessChain %27 %24 %9 %108
  745. %174 = OpLoad %20 %173
  746. %175 = OpFDiv %20 %172 %174
  747. %176 = OpCompositeConstruct %66 %169 %175 %112 %112
  748. OpStore %100 %176
  749. OpBranch %163
  750. %177 = OpLabel
  751. %182 = OpSLessThan %17 %94 %181
  752. OpSelectionMerge %184 None
  753. OpBranchConditional %182 %183 %197
  754. %183 = OpLabel
  755. %185 = OpAccessChain %51 %46 %95
  756. %186 = OpLoad %20 %185
  757. %187 = OpAccessChain %27 %24 %9 %26
  758. %188 = OpLoad %20 %187
  759. %189 = OpFDiv %20 %186 %188
  760. %191 = OpAccessChain %51 %46 %190
  761. %192 = OpLoad %20 %191
  762. %193 = OpAccessChain %27 %24 %9 %108
  763. %194 = OpLoad %20 %193
  764. %195 = OpFDiv %20 %192 %194
  765. %196 = OpCompositeConstruct %66 %189 %195 %112 %112
  766. OpStore %100 %196
  767. OpBranch %184
  768. %197 = OpLabel
  769. %202 = OpSLessThan %17 %94 %201
  770. OpSelectionMerge %204 None
  771. OpBranchConditional %202 %203 %218
  772. %203 = OpLabel
  773. %206 = OpAccessChain %51 %46 %205
  774. %207 = OpLoad %20 %206
  775. %208 = OpAccessChain %27 %24 %9 %26
  776. %209 = OpLoad %20 %208
  777. %210 = OpFDiv %20 %207 %209
  778. %212 = OpAccessChain %51 %46 %211
  779. %213 = OpLoad %20 %212
  780. %214 = OpAccessChain %27 %24 %9 %108
  781. %215 = OpLoad %20 %214
  782. %216 = OpFDiv %20 %213 %215
  783. %217 = OpCompositeConstruct %66 %210 %216 %112 %112
  784. OpStore %100 %217
  785. OpBranch %204
  786. %218 = OpLabel
  787. %223 = OpSLessThan %17 %94 %222
  788. OpSelectionMerge %225 None
  789. OpBranchConditional %223 %224 %239
  790. %224 = OpLabel
  791. %227 = OpAccessChain %51 %46 %226
  792. %228 = OpLoad %20 %227
  793. %229 = OpAccessChain %27 %24 %9 %26
  794. %230 = OpLoad %20 %229
  795. %231 = OpFDiv %20 %228 %230
  796. %233 = OpAccessChain %51 %46 %232
  797. %234 = OpLoad %20 %233
  798. %235 = OpAccessChain %27 %24 %9 %108
  799. %236 = OpLoad %20 %235
  800. %237 = OpFDiv %20 %234 %236
  801. %238 = OpCompositeConstruct %66 %231 %237 %112 %112
  802. OpStore %100 %238
  803. OpBranch %225
  804. %239 = OpLabel
  805. %244 = OpSLessThan %17 %94 %243
  806. OpSelectionMerge %246 None
  807. OpBranchConditional %244 %245 %260
  808. %245 = OpLabel
  809. %248 = OpAccessChain %51 %46 %247
  810. %249 = OpLoad %20 %248
  811. %250 = OpAccessChain %27 %24 %9 %26
  812. %251 = OpLoad %20 %250
  813. %252 = OpFDiv %20 %249 %251
  814. %254 = OpAccessChain %51 %46 %253
  815. %255 = OpLoad %20 %254
  816. %256 = OpAccessChain %27 %24 %9 %108
  817. %257 = OpLoad %20 %256
  818. %258 = OpFDiv %20 %255 %257
  819. %259 = OpCompositeConstruct %66 %252 %258 %112 %112
  820. OpStore %100 %259
  821. OpBranch %246
  822. %260 = OpLabel
  823. %265 = OpSLessThan %17 %94 %264
  824. OpSelectionMerge %267 None
  825. OpBranchConditional %265 %266 %280
  826. %266 = OpLabel
  827. %268 = OpAccessChain %51 %46 %118
  828. %269 = OpLoad %20 %268
  829. %270 = OpAccessChain %27 %24 %9 %26
  830. %271 = OpLoad %20 %270
  831. %272 = OpFDiv %20 %269 %271
  832. %274 = OpAccessChain %51 %46 %273
  833. %275 = OpLoad %20 %274
  834. %276 = OpAccessChain %27 %24 %9 %108
  835. %277 = OpLoad %20 %276
  836. %278 = OpFDiv %20 %275 %277
  837. %279 = OpCompositeConstruct %66 %272 %278 %112 %112
  838. OpStore %100 %279
  839. OpBranch %267
  840. %280 = OpLabel
  841. OpSelectionMerge %285 None
  842. OpBranchConditional %265 %285 %300
  843. %285 = OpLabel
  844. %288 = OpAccessChain %51 %46 %287
  845. %289 = OpLoad %20 %288
  846. %290 = OpAccessChain %27 %24 %9 %26
  847. %291 = OpLoad %20 %290
  848. %292 = OpFDiv %20 %289 %291
  849. %294 = OpAccessChain %51 %46 %293
  850. %295 = OpLoad %20 %294
  851. %296 = OpAccessChain %27 %24 %9 %108
  852. %297 = OpLoad %20 %296
  853. %298 = OpFDiv %20 %295 %297
  854. %299 = OpCompositeConstruct %66 %292 %298 %112 %112
  855. OpStore %100 %299
  856. OpBranch %267
  857. %300 = OpLabel
  858. OpKill
  859. %267 = OpLabel
  860. OpBranch %246
  861. %246 = OpLabel
  862. OpBranch %225
  863. %225 = OpLabel
  864. OpBranch %204
  865. %204 = OpLabel
  866. OpBranch %184
  867. %184 = OpLabel
  868. OpBranch %163
  869. %163 = OpLabel
  870. OpBranch %142
  871. %142 = OpLabel
  872. OpBranch %121
  873. %121 = OpLabel
  874. OpBranch %98
  875. %98 = OpLabel
  876. OpReturn
  877. OpFunctionEnd
  878. )";
  879. // The SPIR-V comes from the 'matrices_smart_loops' GLSL shader that ships
  880. // with GraphicsFuzz.
  881. const std::string kTestShader4 = R"(
  882. OpCapability Shader
  883. %1 = OpExtInstImport "GLSL.std.450"
  884. OpMemoryModel Logical GLSL450
  885. OpEntryPoint Fragment %4 "main" %327 %363 %65 %70 %80 %90 %99 %108 %117 %126 %135 %144 %333
  886. OpExecutionMode %4 OriginUpperLeft
  887. OpSource ESSL 310
  888. OpName %4 "main"
  889. OpName %8 "matrix_number"
  890. OpName %12 "cols"
  891. OpName %23 "rows"
  892. OpName %31 "c"
  893. OpName %41 "r"
  894. OpName %65 "m22"
  895. OpName %68 "buf0"
  896. OpMemberName %68 0 "one"
  897. OpName %70 ""
  898. OpName %80 "m23"
  899. OpName %90 "m24"
  900. OpName %99 "m32"
  901. OpName %108 "m33"
  902. OpName %117 "m34"
  903. OpName %126 "m42"
  904. OpName %135 "m43"
  905. OpName %144 "m44"
  906. OpName %164 "sum_index"
  907. OpName %165 "cols"
  908. OpName %173 "rows"
  909. OpName %184 "sums"
  910. OpName %189 "c"
  911. OpName %198 "r"
  912. OpName %325 "region_x"
  913. OpName %327 "gl_FragCoord"
  914. OpName %331 "buf1"
  915. OpMemberName %331 0 "resolution"
  916. OpName %333 ""
  917. OpName %340 "region_y"
  918. OpName %348 "overall_region"
  919. OpName %363 "_GLF_color"
  920. OpDecorate %8 RelaxedPrecision
  921. OpDecorate %12 RelaxedPrecision
  922. OpDecorate %19 RelaxedPrecision
  923. OpDecorate %23 RelaxedPrecision
  924. OpDecorate %29 RelaxedPrecision
  925. OpDecorate %31 RelaxedPrecision
  926. OpDecorate %38 RelaxedPrecision
  927. OpDecorate %39 RelaxedPrecision
  928. OpDecorate %41 RelaxedPrecision
  929. OpDecorate %47 RelaxedPrecision
  930. OpDecorate %48 RelaxedPrecision
  931. OpDecorate %50 RelaxedPrecision
  932. OpDecorate %66 RelaxedPrecision
  933. OpDecorate %67 RelaxedPrecision
  934. OpMemberDecorate %68 0 Offset 0
  935. OpDecorate %68 Block
  936. OpDecorate %70 DescriptorSet 0
  937. OpDecorate %70 Binding 0
  938. OpDecorate %81 RelaxedPrecision
  939. OpDecorate %82 RelaxedPrecision
  940. OpDecorate %91 RelaxedPrecision
  941. OpDecorate %92 RelaxedPrecision
  942. OpDecorate %100 RelaxedPrecision
  943. OpDecorate %101 RelaxedPrecision
  944. OpDecorate %109 RelaxedPrecision
  945. OpDecorate %110 RelaxedPrecision
  946. OpDecorate %118 RelaxedPrecision
  947. OpDecorate %119 RelaxedPrecision
  948. OpDecorate %127 RelaxedPrecision
  949. OpDecorate %128 RelaxedPrecision
  950. OpDecorate %136 RelaxedPrecision
  951. OpDecorate %137 RelaxedPrecision
  952. OpDecorate %145 RelaxedPrecision
  953. OpDecorate %146 RelaxedPrecision
  954. OpDecorate %152 RelaxedPrecision
  955. OpDecorate %154 RelaxedPrecision
  956. OpDecorate %155 RelaxedPrecision
  957. OpDecorate %156 RelaxedPrecision
  958. OpDecorate %157 RelaxedPrecision
  959. OpDecorate %159 RelaxedPrecision
  960. OpDecorate %160 RelaxedPrecision
  961. OpDecorate %161 RelaxedPrecision
  962. OpDecorate %162 RelaxedPrecision
  963. OpDecorate %163 RelaxedPrecision
  964. OpDecorate %164 RelaxedPrecision
  965. OpDecorate %165 RelaxedPrecision
  966. OpDecorate %171 RelaxedPrecision
  967. OpDecorate %173 RelaxedPrecision
  968. OpDecorate %179 RelaxedPrecision
  969. OpDecorate %185 RelaxedPrecision
  970. OpDecorate %189 RelaxedPrecision
  971. OpDecorate %195 RelaxedPrecision
  972. OpDecorate %196 RelaxedPrecision
  973. OpDecorate %198 RelaxedPrecision
  974. OpDecorate %204 RelaxedPrecision
  975. OpDecorate %205 RelaxedPrecision
  976. OpDecorate %207 RelaxedPrecision
  977. OpDecorate %218 RelaxedPrecision
  978. OpDecorate %219 RelaxedPrecision
  979. OpDecorate %220 RelaxedPrecision
  980. OpDecorate %228 RelaxedPrecision
  981. OpDecorate %229 RelaxedPrecision
  982. OpDecorate %230 RelaxedPrecision
  983. OpDecorate %238 RelaxedPrecision
  984. OpDecorate %239 RelaxedPrecision
  985. OpDecorate %240 RelaxedPrecision
  986. OpDecorate %248 RelaxedPrecision
  987. OpDecorate %249 RelaxedPrecision
  988. OpDecorate %250 RelaxedPrecision
  989. OpDecorate %258 RelaxedPrecision
  990. OpDecorate %259 RelaxedPrecision
  991. OpDecorate %260 RelaxedPrecision
  992. OpDecorate %268 RelaxedPrecision
  993. OpDecorate %269 RelaxedPrecision
  994. OpDecorate %270 RelaxedPrecision
  995. OpDecorate %278 RelaxedPrecision
  996. OpDecorate %279 RelaxedPrecision
  997. OpDecorate %280 RelaxedPrecision
  998. OpDecorate %288 RelaxedPrecision
  999. OpDecorate %289 RelaxedPrecision
  1000. OpDecorate %290 RelaxedPrecision
  1001. OpDecorate %298 RelaxedPrecision
  1002. OpDecorate %299 RelaxedPrecision
  1003. OpDecorate %300 RelaxedPrecision
  1004. OpDecorate %309 RelaxedPrecision
  1005. OpDecorate %310 RelaxedPrecision
  1006. OpDecorate %311 RelaxedPrecision
  1007. OpDecorate %312 RelaxedPrecision
  1008. OpDecorate %313 RelaxedPrecision
  1009. OpDecorate %319 RelaxedPrecision
  1010. OpDecorate %320 RelaxedPrecision
  1011. OpDecorate %321 RelaxedPrecision
  1012. OpDecorate %322 RelaxedPrecision
  1013. OpDecorate %323 RelaxedPrecision
  1014. OpDecorate %324 RelaxedPrecision
  1015. OpDecorate %325 RelaxedPrecision
  1016. OpDecorate %327 BuiltIn FragCoord
  1017. OpMemberDecorate %331 0 Offset 0
  1018. OpDecorate %331 Block
  1019. OpDecorate %333 DescriptorSet 0
  1020. OpDecorate %333 Binding 1
  1021. OpDecorate %339 RelaxedPrecision
  1022. OpDecorate %340 RelaxedPrecision
  1023. OpDecorate %347 RelaxedPrecision
  1024. OpDecorate %348 RelaxedPrecision
  1025. OpDecorate %349 RelaxedPrecision
  1026. OpDecorate %351 RelaxedPrecision
  1027. OpDecorate %352 RelaxedPrecision
  1028. OpDecorate %353 RelaxedPrecision
  1029. OpDecorate %354 RelaxedPrecision
  1030. OpDecorate %356 RelaxedPrecision
  1031. OpDecorate %363 Location 0
  1032. OpDecorate %364 RelaxedPrecision
  1033. %2 = OpTypeVoid
  1034. %3 = OpTypeFunction %2
  1035. %6 = OpTypeInt 32 0
  1036. %7 = OpTypePointer Function %6
  1037. %9 = OpConstant %6 0
  1038. %10 = OpTypeInt 32 1
  1039. %11 = OpTypePointer Function %10
  1040. %13 = OpConstant %10 2
  1041. %20 = OpConstant %10 4
  1042. %21 = OpTypeBool
  1043. %32 = OpConstant %10 0
  1044. %61 = OpTypeFloat 32
  1045. %62 = OpTypeVector %61 2
  1046. %63 = OpTypeMatrix %62 2
  1047. %64 = OpTypePointer Private %63
  1048. %65 = OpVariable %64 Private
  1049. %68 = OpTypeStruct %61
  1050. %69 = OpTypePointer Uniform %68
  1051. %70 = OpVariable %69 Uniform
  1052. %71 = OpTypePointer Uniform %61
  1053. %74 = OpTypePointer Private %61
  1054. %77 = OpTypeVector %61 3
  1055. %78 = OpTypeMatrix %77 2
  1056. %79 = OpTypePointer Private %78
  1057. %80 = OpVariable %79 Private
  1058. %87 = OpTypeVector %61 4
  1059. %88 = OpTypeMatrix %87 2
  1060. %89 = OpTypePointer Private %88
  1061. %90 = OpVariable %89 Private
  1062. %97 = OpTypeMatrix %62 3
  1063. %98 = OpTypePointer Private %97
  1064. %99 = OpVariable %98 Private
  1065. %106 = OpTypeMatrix %77 3
  1066. %107 = OpTypePointer Private %106
  1067. %108 = OpVariable %107 Private
  1068. %115 = OpTypeMatrix %87 3
  1069. %116 = OpTypePointer Private %115
  1070. %117 = OpVariable %116 Private
  1071. %124 = OpTypeMatrix %62 4
  1072. %125 = OpTypePointer Private %124
  1073. %126 = OpVariable %125 Private
  1074. %133 = OpTypeMatrix %77 4
  1075. %134 = OpTypePointer Private %133
  1076. %135 = OpVariable %134 Private
  1077. %142 = OpTypeMatrix %87 4
  1078. %143 = OpTypePointer Private %142
  1079. %144 = OpVariable %143 Private
  1080. %153 = OpConstant %10 1
  1081. %158 = OpConstant %6 1
  1082. %181 = OpConstant %6 9
  1083. %182 = OpTypeArray %61 %181
  1084. %183 = OpTypePointer Function %182
  1085. %186 = OpConstant %61 0
  1086. %187 = OpTypePointer Function %61
  1087. %314 = OpConstant %61 16
  1088. %326 = OpTypePointer Input %87
  1089. %327 = OpVariable %326 Input
  1090. %328 = OpTypePointer Input %61
  1091. %331 = OpTypeStruct %62
  1092. %332 = OpTypePointer Uniform %331
  1093. %333 = OpVariable %332 Uniform
  1094. %336 = OpConstant %61 3
  1095. %350 = OpConstant %10 3
  1096. %357 = OpConstant %10 9
  1097. %362 = OpTypePointer Output %87
  1098. %363 = OpVariable %362 Output
  1099. %368 = OpConstant %61 1
  1100. %374 = OpConstantComposite %87 %186 %186 %186 %368
  1101. %4 = OpFunction %2 None %3
  1102. %5 = OpLabel
  1103. %8 = OpVariable %7 Function
  1104. %12 = OpVariable %11 Function
  1105. %23 = OpVariable %11 Function
  1106. %31 = OpVariable %11 Function
  1107. %41 = OpVariable %11 Function
  1108. %164 = OpVariable %11 Function
  1109. %165 = OpVariable %11 Function
  1110. %173 = OpVariable %11 Function
  1111. %184 = OpVariable %183 Function
  1112. %189 = OpVariable %11 Function
  1113. %198 = OpVariable %11 Function
  1114. %325 = OpVariable %11 Function
  1115. %340 = OpVariable %11 Function
  1116. %348 = OpVariable %11 Function
  1117. OpStore %8 %9
  1118. OpStore %12 %13
  1119. OpBranch %14
  1120. %14 = OpLabel
  1121. OpLoopMerge %16 %17 None
  1122. OpBranch %18
  1123. %18 = OpLabel
  1124. %19 = OpLoad %10 %12
  1125. %22 = OpSLessThanEqual %21 %19 %20
  1126. OpBranchConditional %22 %15 %16
  1127. %15 = OpLabel
  1128. OpStore %23 %13
  1129. OpBranch %24
  1130. %24 = OpLabel
  1131. OpLoopMerge %26 %27 None
  1132. OpBranch %28
  1133. %28 = OpLabel
  1134. %29 = OpLoad %10 %23
  1135. %30 = OpSLessThanEqual %21 %29 %20
  1136. OpBranchConditional %30 %25 %26
  1137. %25 = OpLabel
  1138. OpStore %31 %32
  1139. OpBranch %33
  1140. %33 = OpLabel
  1141. OpLoopMerge %35 %36 None
  1142. OpBranch %37
  1143. %37 = OpLabel
  1144. %38 = OpLoad %10 %31
  1145. %39 = OpLoad %10 %12
  1146. %40 = OpSLessThan %21 %38 %39
  1147. OpBranchConditional %40 %34 %35
  1148. %34 = OpLabel
  1149. OpStore %41 %32
  1150. OpBranch %42
  1151. %42 = OpLabel
  1152. OpLoopMerge %44 %45 None
  1153. OpBranch %46
  1154. %46 = OpLabel
  1155. %47 = OpLoad %10 %41
  1156. %48 = OpLoad %10 %23
  1157. %49 = OpSLessThan %21 %47 %48
  1158. OpBranchConditional %49 %43 %44
  1159. %43 = OpLabel
  1160. %50 = OpLoad %6 %8
  1161. OpSelectionMerge %60 None
  1162. OpSwitch %50 %60 0 %51 1 %52 2 %53 3 %54 4 %55 5 %56 6 %57 7 %58 8 %59
  1163. %51 = OpLabel
  1164. %66 = OpLoad %10 %31
  1165. %67 = OpLoad %10 %41
  1166. %72 = OpAccessChain %71 %70 %32
  1167. %73 = OpLoad %61 %72
  1168. %75 = OpAccessChain %74 %65 %66 %67
  1169. OpStore %75 %73
  1170. OpBranch %60
  1171. %52 = OpLabel
  1172. %81 = OpLoad %10 %31
  1173. %82 = OpLoad %10 %41
  1174. %83 = OpAccessChain %71 %70 %32
  1175. %84 = OpLoad %61 %83
  1176. %85 = OpAccessChain %74 %80 %81 %82
  1177. OpStore %85 %84
  1178. OpBranch %60
  1179. %53 = OpLabel
  1180. %91 = OpLoad %10 %31
  1181. %92 = OpLoad %10 %41
  1182. %93 = OpAccessChain %71 %70 %32
  1183. %94 = OpLoad %61 %93
  1184. %95 = OpAccessChain %74 %90 %91 %92
  1185. OpStore %95 %94
  1186. OpBranch %60
  1187. %54 = OpLabel
  1188. %100 = OpLoad %10 %31
  1189. %101 = OpLoad %10 %41
  1190. %102 = OpAccessChain %71 %70 %32
  1191. %103 = OpLoad %61 %102
  1192. %104 = OpAccessChain %74 %99 %100 %101
  1193. OpStore %104 %103
  1194. OpBranch %60
  1195. %55 = OpLabel
  1196. %109 = OpLoad %10 %31
  1197. %110 = OpLoad %10 %41
  1198. %111 = OpAccessChain %71 %70 %32
  1199. %112 = OpLoad %61 %111
  1200. %113 = OpAccessChain %74 %108 %109 %110
  1201. OpStore %113 %112
  1202. OpBranch %60
  1203. %56 = OpLabel
  1204. %118 = OpLoad %10 %31
  1205. %119 = OpLoad %10 %41
  1206. %120 = OpAccessChain %71 %70 %32
  1207. %121 = OpLoad %61 %120
  1208. %122 = OpAccessChain %74 %117 %118 %119
  1209. OpStore %122 %121
  1210. OpBranch %60
  1211. %57 = OpLabel
  1212. %127 = OpLoad %10 %31
  1213. %128 = OpLoad %10 %41
  1214. %129 = OpAccessChain %71 %70 %32
  1215. %130 = OpLoad %61 %129
  1216. %131 = OpAccessChain %74 %126 %127 %128
  1217. OpStore %131 %130
  1218. OpBranch %60
  1219. %58 = OpLabel
  1220. %136 = OpLoad %10 %31
  1221. %137 = OpLoad %10 %41
  1222. %138 = OpAccessChain %71 %70 %32
  1223. %139 = OpLoad %61 %138
  1224. %140 = OpAccessChain %74 %135 %136 %137
  1225. OpStore %140 %139
  1226. OpBranch %60
  1227. %59 = OpLabel
  1228. %145 = OpLoad %10 %31
  1229. %146 = OpLoad %10 %41
  1230. %147 = OpAccessChain %71 %70 %32
  1231. %148 = OpLoad %61 %147
  1232. %149 = OpAccessChain %74 %144 %145 %146
  1233. OpStore %149 %148
  1234. OpBranch %60
  1235. %60 = OpLabel
  1236. OpBranch %45
  1237. %45 = OpLabel
  1238. %152 = OpLoad %10 %41
  1239. %154 = OpIAdd %10 %152 %153
  1240. OpStore %41 %154
  1241. OpBranch %42
  1242. %44 = OpLabel
  1243. OpBranch %36
  1244. %36 = OpLabel
  1245. %155 = OpLoad %10 %31
  1246. %156 = OpIAdd %10 %155 %153
  1247. OpStore %31 %156
  1248. OpBranch %33
  1249. %35 = OpLabel
  1250. %157 = OpLoad %6 %8
  1251. %159 = OpIAdd %6 %157 %158
  1252. OpStore %8 %159
  1253. OpBranch %27
  1254. %27 = OpLabel
  1255. %160 = OpLoad %10 %23
  1256. %161 = OpIAdd %10 %160 %153
  1257. OpStore %23 %161
  1258. OpBranch %24
  1259. %26 = OpLabel
  1260. OpBranch %17
  1261. %17 = OpLabel
  1262. %162 = OpLoad %10 %12
  1263. %163 = OpIAdd %10 %162 %153
  1264. OpStore %12 %163
  1265. OpBranch %14
  1266. %16 = OpLabel
  1267. OpStore %164 %32
  1268. OpStore %165 %13
  1269. OpBranch %166
  1270. %166 = OpLabel
  1271. OpLoopMerge %168 %169 None
  1272. OpBranch %170
  1273. %170 = OpLabel
  1274. %171 = OpLoad %10 %165
  1275. %172 = OpSLessThanEqual %21 %171 %20
  1276. OpBranchConditional %172 %167 %168
  1277. %167 = OpLabel
  1278. OpStore %173 %13
  1279. OpBranch %174
  1280. %174 = OpLabel
  1281. OpLoopMerge %176 %177 None
  1282. OpBranch %178
  1283. %178 = OpLabel
  1284. %179 = OpLoad %10 %173
  1285. %180 = OpSLessThanEqual %21 %179 %20
  1286. OpBranchConditional %180 %175 %176
  1287. %175 = OpLabel
  1288. %185 = OpLoad %10 %164
  1289. %188 = OpAccessChain %187 %184 %185
  1290. OpStore %188 %186
  1291. OpStore %189 %32
  1292. OpBranch %190
  1293. %190 = OpLabel
  1294. OpLoopMerge %192 %193 None
  1295. OpBranch %194
  1296. %194 = OpLabel
  1297. %195 = OpLoad %10 %189
  1298. %196 = OpLoad %10 %165
  1299. %197 = OpSLessThan %21 %195 %196
  1300. OpBranchConditional %197 %191 %192
  1301. %191 = OpLabel
  1302. OpStore %198 %32
  1303. OpBranch %199
  1304. %199 = OpLabel
  1305. OpLoopMerge %201 %202 None
  1306. OpBranch %203
  1307. %203 = OpLabel
  1308. %204 = OpLoad %10 %198
  1309. %205 = OpLoad %10 %173
  1310. %206 = OpSLessThan %21 %204 %205
  1311. OpBranchConditional %206 %200 %201
  1312. %200 = OpLabel
  1313. %207 = OpLoad %10 %164
  1314. OpSelectionMerge %217 None
  1315. OpSwitch %207 %217 0 %208 1 %209 2 %210 3 %211 4 %212 5 %213 6 %214 7 %215 8 %216
  1316. %208 = OpLabel
  1317. %218 = OpLoad %10 %164
  1318. %219 = OpLoad %10 %189
  1319. %220 = OpLoad %10 %198
  1320. %221 = OpAccessChain %74 %65 %219 %220
  1321. %222 = OpLoad %61 %221
  1322. %223 = OpAccessChain %187 %184 %218
  1323. %224 = OpLoad %61 %223
  1324. %225 = OpFAdd %61 %224 %222
  1325. %226 = OpAccessChain %187 %184 %218
  1326. OpStore %226 %225
  1327. OpBranch %217
  1328. %209 = OpLabel
  1329. %228 = OpLoad %10 %164
  1330. %229 = OpLoad %10 %189
  1331. %230 = OpLoad %10 %198
  1332. %231 = OpAccessChain %74 %80 %229 %230
  1333. %232 = OpLoad %61 %231
  1334. %233 = OpAccessChain %187 %184 %228
  1335. %234 = OpLoad %61 %233
  1336. %235 = OpFAdd %61 %234 %232
  1337. %236 = OpAccessChain %187 %184 %228
  1338. OpStore %236 %235
  1339. OpBranch %217
  1340. %210 = OpLabel
  1341. %238 = OpLoad %10 %164
  1342. %239 = OpLoad %10 %189
  1343. %240 = OpLoad %10 %198
  1344. %241 = OpAccessChain %74 %90 %239 %240
  1345. %242 = OpLoad %61 %241
  1346. %243 = OpAccessChain %187 %184 %238
  1347. %244 = OpLoad %61 %243
  1348. %245 = OpFAdd %61 %244 %242
  1349. %246 = OpAccessChain %187 %184 %238
  1350. OpStore %246 %245
  1351. OpBranch %217
  1352. %211 = OpLabel
  1353. %248 = OpLoad %10 %164
  1354. %249 = OpLoad %10 %189
  1355. %250 = OpLoad %10 %198
  1356. %251 = OpAccessChain %74 %99 %249 %250
  1357. %252 = OpLoad %61 %251
  1358. %253 = OpAccessChain %187 %184 %248
  1359. %254 = OpLoad %61 %253
  1360. %255 = OpFAdd %61 %254 %252
  1361. %256 = OpAccessChain %187 %184 %248
  1362. OpStore %256 %255
  1363. OpBranch %217
  1364. %212 = OpLabel
  1365. %258 = OpLoad %10 %164
  1366. %259 = OpLoad %10 %189
  1367. %260 = OpLoad %10 %198
  1368. %261 = OpAccessChain %74 %108 %259 %260
  1369. %262 = OpLoad %61 %261
  1370. %263 = OpAccessChain %187 %184 %258
  1371. %264 = OpLoad %61 %263
  1372. %265 = OpFAdd %61 %264 %262
  1373. %266 = OpAccessChain %187 %184 %258
  1374. OpStore %266 %265
  1375. OpBranch %217
  1376. %213 = OpLabel
  1377. %268 = OpLoad %10 %164
  1378. %269 = OpLoad %10 %189
  1379. %270 = OpLoad %10 %198
  1380. %271 = OpAccessChain %74 %117 %269 %270
  1381. %272 = OpLoad %61 %271
  1382. %273 = OpAccessChain %187 %184 %268
  1383. %274 = OpLoad %61 %273
  1384. %275 = OpFAdd %61 %274 %272
  1385. %276 = OpAccessChain %187 %184 %268
  1386. OpStore %276 %275
  1387. OpBranch %217
  1388. %214 = OpLabel
  1389. %278 = OpLoad %10 %164
  1390. %279 = OpLoad %10 %189
  1391. %280 = OpLoad %10 %198
  1392. %281 = OpAccessChain %74 %126 %279 %280
  1393. %282 = OpLoad %61 %281
  1394. %283 = OpAccessChain %187 %184 %278
  1395. %284 = OpLoad %61 %283
  1396. %285 = OpFAdd %61 %284 %282
  1397. %286 = OpAccessChain %187 %184 %278
  1398. OpStore %286 %285
  1399. OpBranch %217
  1400. %215 = OpLabel
  1401. %288 = OpLoad %10 %164
  1402. %289 = OpLoad %10 %189
  1403. %290 = OpLoad %10 %198
  1404. %291 = OpAccessChain %74 %135 %289 %290
  1405. %292 = OpLoad %61 %291
  1406. %293 = OpAccessChain %187 %184 %288
  1407. %294 = OpLoad %61 %293
  1408. %295 = OpFAdd %61 %294 %292
  1409. %296 = OpAccessChain %187 %184 %288
  1410. OpStore %296 %295
  1411. OpBranch %217
  1412. %216 = OpLabel
  1413. %298 = OpLoad %10 %164
  1414. %299 = OpLoad %10 %189
  1415. %300 = OpLoad %10 %198
  1416. %301 = OpAccessChain %74 %144 %299 %300
  1417. %302 = OpLoad %61 %301
  1418. %303 = OpAccessChain %187 %184 %298
  1419. %304 = OpLoad %61 %303
  1420. %305 = OpFAdd %61 %304 %302
  1421. %306 = OpAccessChain %187 %184 %298
  1422. OpStore %306 %305
  1423. OpBranch %217
  1424. %217 = OpLabel
  1425. OpBranch %202
  1426. %202 = OpLabel
  1427. %309 = OpLoad %10 %198
  1428. %310 = OpIAdd %10 %309 %153
  1429. OpStore %198 %310
  1430. OpBranch %199
  1431. %201 = OpLabel
  1432. OpBranch %193
  1433. %193 = OpLabel
  1434. %311 = OpLoad %10 %189
  1435. %312 = OpIAdd %10 %311 %153
  1436. OpStore %189 %312
  1437. OpBranch %190
  1438. %192 = OpLabel
  1439. %313 = OpLoad %10 %164
  1440. %315 = OpAccessChain %187 %184 %313
  1441. %316 = OpLoad %61 %315
  1442. %317 = OpFDiv %61 %316 %314
  1443. %318 = OpAccessChain %187 %184 %313
  1444. OpStore %318 %317
  1445. %319 = OpLoad %10 %164
  1446. %320 = OpIAdd %10 %319 %153
  1447. OpStore %164 %320
  1448. OpBranch %177
  1449. %177 = OpLabel
  1450. %321 = OpLoad %10 %173
  1451. %322 = OpIAdd %10 %321 %153
  1452. OpStore %173 %322
  1453. OpBranch %174
  1454. %176 = OpLabel
  1455. OpBranch %169
  1456. %169 = OpLabel
  1457. %323 = OpLoad %10 %165
  1458. %324 = OpIAdd %10 %323 %153
  1459. OpStore %165 %324
  1460. OpBranch %166
  1461. %168 = OpLabel
  1462. %329 = OpAccessChain %328 %327 %9
  1463. %330 = OpLoad %61 %329
  1464. %334 = OpAccessChain %71 %333 %32 %9
  1465. %335 = OpLoad %61 %334
  1466. %337 = OpFDiv %61 %335 %336
  1467. %338 = OpFDiv %61 %330 %337
  1468. %339 = OpConvertFToS %10 %338
  1469. OpStore %325 %339
  1470. %341 = OpAccessChain %328 %327 %158
  1471. %342 = OpLoad %61 %341
  1472. %343 = OpAccessChain %71 %333 %32 %9
  1473. %344 = OpLoad %61 %343
  1474. %345 = OpFDiv %61 %344 %336
  1475. %346 = OpFDiv %61 %342 %345
  1476. %347 = OpConvertFToS %10 %346
  1477. OpStore %340 %347
  1478. %349 = OpLoad %10 %340
  1479. %351 = OpIMul %10 %349 %350
  1480. %352 = OpLoad %10 %325
  1481. %353 = OpIAdd %10 %351 %352
  1482. OpStore %348 %353
  1483. %354 = OpLoad %10 %348
  1484. %355 = OpSGreaterThan %21 %354 %32
  1485. %356 = OpLoad %10 %348
  1486. %358 = OpSLessThan %21 %356 %357
  1487. %359 = OpLogicalAnd %21 %355 %358
  1488. OpSelectionMerge %361 None
  1489. OpBranchConditional %359 %360 %373
  1490. %360 = OpLabel
  1491. %364 = OpLoad %10 %348
  1492. %365 = OpAccessChain %187 %184 %364
  1493. %366 = OpLoad %61 %365
  1494. %367 = OpCompositeConstruct %77 %366 %366 %366
  1495. %369 = OpCompositeExtract %61 %367 0
  1496. %370 = OpCompositeExtract %61 %367 1
  1497. %371 = OpCompositeExtract %61 %367 2
  1498. %372 = OpCompositeConstruct %87 %369 %370 %371 %368
  1499. OpStore %363 %372
  1500. OpBranch %361
  1501. %373 = OpLabel
  1502. OpStore %363 %374
  1503. OpBranch %361
  1504. %361 = OpLabel
  1505. OpReturn
  1506. OpFunctionEnd
  1507. )";
  1508. // The SPIR-V comes from the following GLSL:
  1509. //
  1510. // #version 310 es
  1511. // precision highp float;
  1512. //
  1513. // layout(location = 0) out vec4 color;
  1514. //
  1515. // void main()
  1516. // {
  1517. // color = vec4(1.0, 0.0, 0.0, 1.0);
  1518. // }
  1519. const std::string kTestShader5 = R"(
  1520. OpCapability Shader
  1521. %1 = OpExtInstImport "GLSL.std.450"
  1522. OpMemoryModel Logical GLSL450
  1523. OpEntryPoint Fragment %4 "main" %9
  1524. OpExecutionMode %4 OriginUpperLeft
  1525. OpSource ESSL 310
  1526. OpName %4 "main"
  1527. OpName %9 "color"
  1528. OpDecorate %9 Location 0
  1529. %2 = OpTypeVoid
  1530. %3 = OpTypeFunction %2
  1531. %6 = OpTypeFloat 32
  1532. %7 = OpTypeVector %6 4
  1533. %8 = OpTypePointer Output %7
  1534. %9 = OpVariable %8 Output
  1535. %10 = OpConstant %6 1
  1536. %11 = OpConstant %6 0
  1537. %12 = OpConstantComposite %7 %10 %11 %11 %10
  1538. %4 = OpFunction %2 None %3
  1539. %5 = OpLabel
  1540. OpStore %9 %12
  1541. OpReturn
  1542. OpFunctionEnd
  1543. )";
  1544. // Some miscellaneous SPIR-V.
  1545. const std::string kTestShader6 = R"(
  1546. OpCapability Shader
  1547. OpCapability SampledBuffer
  1548. OpCapability ImageBuffer
  1549. %1 = OpExtInstImport "GLSL.std.450"
  1550. OpMemoryModel Logical GLSL450
  1551. OpEntryPoint Fragment %2 "main" %40 %41
  1552. OpExecutionMode %2 OriginUpperLeft
  1553. OpSource GLSL 450
  1554. OpDecorate %40 DescriptorSet 0
  1555. OpDecorate %40 Binding 69
  1556. OpDecorate %41 DescriptorSet 0
  1557. OpDecorate %41 Binding 1
  1558. %54 = OpTypeFloat 32
  1559. %76 = OpTypeVector %54 4
  1560. %55 = OpConstant %54 0
  1561. %56 = OpTypeVector %54 3
  1562. %94 = OpTypeVector %54 2
  1563. %112 = OpConstantComposite %94 %55 %55
  1564. %57 = OpConstantComposite %56 %55 %55 %55
  1565. %15 = OpTypeImage %54 2D 2 0 0 1 Unknown
  1566. %114 = OpTypePointer UniformConstant %15
  1567. %38 = OpTypeSampler
  1568. %125 = OpTypePointer UniformConstant %38
  1569. %132 = OpTypeVoid
  1570. %133 = OpTypeFunction %132
  1571. %45 = OpTypeSampledImage %15
  1572. %40 = OpVariable %114 UniformConstant
  1573. %41 = OpVariable %125 UniformConstant
  1574. %2 = OpFunction %132 None %133
  1575. %164 = OpLabel
  1576. %184 = OpLoad %15 %40
  1577. %213 = OpLoad %38 %41
  1578. %216 = OpSampledImage %45 %184 %213
  1579. %217 = OpImageSampleImplicitLod %76 %216 %112 Bias %55
  1580. OpReturn
  1581. OpFunctionEnd
  1582. )";
  1583. // A virtually empty piece of SPIR-V.
  1584. const std::string kTestShader7 = R"(
  1585. OpCapability Shader
  1586. %1 = OpExtInstImport "GLSL.std.450"
  1587. OpMemoryModel Logical GLSL450
  1588. OpEntryPoint Fragment %4 "main"
  1589. OpExecutionMode %4 OriginUpperLeft
  1590. OpSource ESSL 320
  1591. %2 = OpTypeVoid
  1592. %3 = OpTypeFunction %2
  1593. %4 = OpFunction %2 None %3
  1594. %5 = OpLabel
  1595. OpReturn
  1596. OpFunctionEnd
  1597. )";
  1598. void AddConstantUniformFact(protobufs::FactSequence* facts,
  1599. uint32_t descriptor_set, uint32_t binding,
  1600. std::vector<uint32_t>&& indices, uint32_t value) {
  1601. protobufs::FactConstantUniform fact;
  1602. *fact.mutable_uniform_buffer_element_descriptor() =
  1603. MakeUniformBufferElementDescriptor(descriptor_set, binding,
  1604. std::move(indices));
  1605. *fact.mutable_constant_word()->Add() = value;
  1606. protobufs::Fact temp;
  1607. *temp.mutable_constant_uniform_fact() = fact;
  1608. *facts->mutable_fact()->Add() = temp;
  1609. }
  1610. // Reinterpret the bits of |value| as a 32-bit unsigned int
  1611. uint32_t FloatBitsAsUint(float value) {
  1612. uint32_t result;
  1613. memcpy(&result, &value, sizeof(float));
  1614. return result;
  1615. }
  1616. // Assembles the given |shader| text, and then runs the fuzzer |num_runs|
  1617. // times, using successive seeds starting from |initial_seed|. Checks that
  1618. // the binary produced after each fuzzer run is valid, and that replaying
  1619. // the transformations that were applied during fuzzing leads to an
  1620. // identical binary.
  1621. void RunFuzzerAndReplayer(const std::string& shader,
  1622. const protobufs::FactSequence& initial_facts,
  1623. uint32_t initial_seed, uint32_t num_runs) {
  1624. const auto env = SPV_ENV_UNIVERSAL_1_5;
  1625. std::vector<uint32_t> binary_in;
  1626. SpirvTools t(env);
  1627. t.SetMessageConsumer(kConsoleMessageConsumer);
  1628. ASSERT_TRUE(t.Assemble(shader, &binary_in, kFuzzAssembleOption));
  1629. ASSERT_TRUE(t.Validate(binary_in));
  1630. std::vector<fuzzerutil::ModuleSupplier> donor_suppliers;
  1631. for (auto donor : {&kTestShader1, &kTestShader2, &kTestShader3, &kTestShader4,
  1632. &kTestShader5, &kTestShader6}) {
  1633. donor_suppliers.emplace_back([donor]() {
  1634. return BuildModule(env, kConsoleMessageConsumer, *donor,
  1635. kFuzzAssembleOption);
  1636. });
  1637. }
  1638. std::vector<RepeatedPassStrategy> strategies{
  1639. RepeatedPassStrategy::kSimple,
  1640. RepeatedPassStrategy::kLoopedWithRecommendations,
  1641. RepeatedPassStrategy::kRandomWithRecommendations};
  1642. uint32_t strategy_index = 0;
  1643. for (uint32_t seed = initial_seed; seed < initial_seed + num_runs; seed++) {
  1644. spvtools::ValidatorOptions validator_options;
  1645. std::unique_ptr<opt::IRContext> ir_context;
  1646. ASSERT_TRUE(fuzzerutil::BuildIRContext(env, kConsoleMessageConsumer,
  1647. binary_in, validator_options,
  1648. &ir_context));
  1649. auto fuzzer_context = MakeUnique<FuzzerContext>(
  1650. MakeUnique<PseudoRandomGenerator>(seed),
  1651. FuzzerContext::GetMinFreshId(ir_context.get()), false);
  1652. auto transformation_context = MakeUnique<TransformationContext>(
  1653. MakeUnique<FactManager>(ir_context.get()), validator_options);
  1654. transformation_context->GetFactManager()->AddInitialFacts(
  1655. kConsoleMessageConsumer, initial_facts);
  1656. // Every 4th time we run the fuzzer, enable all fuzzer passes.
  1657. bool enable_all_passes = (seed % 4) == 0;
  1658. Fuzzer fuzzer(std::move(ir_context), std::move(transformation_context),
  1659. std::move(fuzzer_context), kConsoleMessageConsumer,
  1660. donor_suppliers, enable_all_passes,
  1661. strategies[strategy_index], true, validator_options, false);
  1662. auto fuzzer_result = fuzzer.Run(0);
  1663. // Cycle the repeated pass strategy so that we try a different one next time
  1664. // we run the fuzzer.
  1665. strategy_index =
  1666. (strategy_index + 1) % static_cast<uint32_t>(strategies.size());
  1667. ASSERT_NE(Fuzzer::Status::kFuzzerPassLedToInvalidModule,
  1668. fuzzer_result.status);
  1669. std::vector<uint32_t> transformed_binary;
  1670. fuzzer.GetIRContext()->module()->ToBinary(&transformed_binary, true);
  1671. ASSERT_TRUE(t.Validate(transformed_binary));
  1672. auto replayer_result =
  1673. Replayer(env, kConsoleMessageConsumer, binary_in, initial_facts,
  1674. fuzzer.GetTransformationSequence(),
  1675. static_cast<uint32_t>(
  1676. fuzzer.GetTransformationSequence().transformation_size()),
  1677. false, validator_options)
  1678. .Run();
  1679. ASSERT_EQ(Replayer::ReplayerResultStatus::kComplete,
  1680. replayer_result.status);
  1681. // After replaying the transformations applied by the fuzzer, exactly those
  1682. // transformations should have been applied, and the binary resulting from
  1683. // replay should be identical to that which resulted from fuzzing.
  1684. std::string fuzzer_transformations_string;
  1685. std::string replayer_transformations_string;
  1686. fuzzer.GetTransformationSequence().SerializeToString(
  1687. &fuzzer_transformations_string);
  1688. replayer_result.applied_transformations.SerializeToString(
  1689. &replayer_transformations_string);
  1690. ASSERT_EQ(fuzzer_transformations_string, replayer_transformations_string);
  1691. ASSERT_TRUE(IsEqual(env, transformed_binary,
  1692. replayer_result.transformed_module.get()));
  1693. }
  1694. }
  1695. TEST(FuzzerReplayerTest, Miscellaneous1) {
  1696. // Do some fuzzer runs, starting from an initial seed of 0 (seed value chosen
  1697. // arbitrarily).
  1698. RunFuzzerAndReplayer(kTestShader1, protobufs::FactSequence(), 0,
  1699. kNumFuzzerRuns);
  1700. }
  1701. TEST(FuzzerReplayerTest, Miscellaneous2) {
  1702. // Do some fuzzer runs, starting from an initial seed of 10 (seed value chosen
  1703. // arbitrarily).
  1704. RunFuzzerAndReplayer(kTestShader2, protobufs::FactSequence(), 10,
  1705. kNumFuzzerRuns);
  1706. }
  1707. TEST(FuzzerReplayerTest, Miscellaneous3) {
  1708. // Add the facts "resolution.x == 250" and "resolution.y == 100".
  1709. protobufs::FactSequence facts;
  1710. AddConstantUniformFact(&facts, 0, 0, {0, 0}, 250);
  1711. AddConstantUniformFact(&facts, 0, 0, {0, 1}, 100);
  1712. // Do some fuzzer runs, starting from an initial seed of 94 (seed value chosen
  1713. // arbitrarily).
  1714. RunFuzzerAndReplayer(kTestShader3, facts, 94, kNumFuzzerRuns);
  1715. }
  1716. TEST(FuzzerReplayerTest, Miscellaneous4) {
  1717. // Add the facts:
  1718. // - "one == 1.0"
  1719. // - "resolution.y == 256.0",
  1720. protobufs::FactSequence facts;
  1721. AddConstantUniformFact(&facts, 0, 0, {0}, FloatBitsAsUint(1.0));
  1722. AddConstantUniformFact(&facts, 0, 1, {0, 0}, FloatBitsAsUint(256.0));
  1723. AddConstantUniformFact(&facts, 0, 1, {0, 1}, FloatBitsAsUint(256.0));
  1724. // Do some fuzzer runs, starting from an initial seed of 14 (seed value chosen
  1725. // arbitrarily).
  1726. RunFuzzerAndReplayer(kTestShader4, facts, 14, kNumFuzzerRuns);
  1727. }
  1728. TEST(FuzzerReplayerTest, Miscellaneous5) {
  1729. // Do some fuzzer runs, starting from an initial seed of 29 (seed value chosen
  1730. // arbitrarily).
  1731. RunFuzzerAndReplayer(kTestShader5, protobufs::FactSequence(), 29,
  1732. kNumFuzzerRuns);
  1733. }
  1734. TEST(FuzzerReplayerTest, Miscellaneous6) {
  1735. // Do some fuzzer runs, starting from an initial seed of 57 (seed value chosen
  1736. // arbitrarily).
  1737. RunFuzzerAndReplayer(kTestShader6, protobufs::FactSequence(), 57,
  1738. kNumFuzzerRuns);
  1739. }
  1740. TEST(FuzzerReplayerTest, Miscellaneous7) {
  1741. // Do some fuzzer runs, starting from an initial seed of 1 (seed value chosen
  1742. // arbitrarily).
  1743. RunFuzzerAndReplayer(kTestShader7, protobufs::FactSequence(), 1,
  1744. kNumFuzzerRuns);
  1745. }
  1746. } // namespace
  1747. } // namespace fuzz
  1748. } // namespace spvtools