upgrade_memory_model_test.cpp 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  1. // Copyright (c) 2018 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 "assembly_builder.h"
  15. #include "gmock/gmock.h"
  16. #include "pass_fixture.h"
  17. #include "pass_utils.h"
  18. namespace {
  19. using namespace spvtools;
  20. using UpgradeMemoryModelTest = opt::PassTest<::testing::Test>;
  21. TEST_F(UpgradeMemoryModelTest, InvalidMemoryModelOpenCL) {
  22. const std::string text = R"(
  23. ; CHECK: OpMemoryModel Logical OpenCL
  24. OpCapability Kernel
  25. OpCapability Linkage
  26. OpMemoryModel Logical OpenCL
  27. )";
  28. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  29. }
  30. TEST_F(UpgradeMemoryModelTest, InvalidMemoryModelVulkanKHR) {
  31. const std::string text = R"(
  32. ; CHECK: OpMemoryModel Logical VulkanKHR
  33. OpCapability Shader
  34. OpCapability Linkage
  35. OpCapability VulkanMemoryModelKHR
  36. OpExtension "SPV_KHR_vulkan_memory_model"
  37. OpMemoryModel Logical VulkanKHR
  38. )";
  39. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  40. }
  41. TEST_F(UpgradeMemoryModelTest, JustMemoryModel) {
  42. const std::string text = R"(
  43. ; CHECK: OpCapability VulkanMemoryModelKHR
  44. ; CHECK: OpExtension "SPV_KHR_vulkan_memory_model"
  45. ; CHECK: OpMemoryModel Logical VulkanKHR
  46. OpCapability Shader
  47. OpCapability Linkage
  48. OpMemoryModel Logical GLSL450
  49. )";
  50. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  51. }
  52. TEST_F(UpgradeMemoryModelTest, RemoveDecorations) {
  53. const std::string text = R"(
  54. ; CHECK-NOT: OpDecorate
  55. OpCapability Shader
  56. OpCapability Linkage
  57. OpMemoryModel Logical GLSL450
  58. OpDecorate %var Volatile
  59. OpDecorate %var Coherent
  60. %int = OpTypeInt 32 0
  61. %ptr_int_Uniform = OpTypePointer Uniform %int
  62. %var = OpVariable %ptr_int_Uniform Uniform
  63. )";
  64. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  65. }
  66. TEST_F(UpgradeMemoryModelTest, WorkgroupVariable) {
  67. const std::string text = R"(
  68. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 2
  69. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  70. ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  71. OpCapability Shader
  72. OpCapability Linkage
  73. OpMemoryModel Logical GLSL450
  74. %void = OpTypeVoid
  75. %int = OpTypeInt 32 0
  76. %ptr_int_Workgroup = OpTypePointer Workgroup %int
  77. %var = OpVariable %ptr_int_Workgroup Workgroup
  78. %func_ty = OpTypeFunction %void
  79. %func = OpFunction %void None %func_ty
  80. %1 = OpLabel
  81. %ld = OpLoad %int %var
  82. %st = OpStore %var %ld
  83. OpReturn
  84. OpFunctionEnd
  85. )";
  86. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  87. }
  88. TEST_F(UpgradeMemoryModelTest, WorkgroupFunctionParameter) {
  89. const std::string text = R"(
  90. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 2
  91. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  92. ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  93. OpCapability Shader
  94. OpCapability Linkage
  95. OpMemoryModel Logical GLSL450
  96. %void = OpTypeVoid
  97. %int = OpTypeInt 32 0
  98. %ptr_int_Workgroup = OpTypePointer Workgroup %int
  99. %func_ty = OpTypeFunction %void %ptr_int_Workgroup
  100. %func = OpFunction %void None %func_ty
  101. %param = OpFunctionParameter %ptr_int_Workgroup
  102. %1 = OpLabel
  103. %ld = OpLoad %int %param
  104. %st = OpStore %param %ld
  105. OpReturn
  106. OpFunctionEnd
  107. )";
  108. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  109. }
  110. TEST_F(UpgradeMemoryModelTest, SimpleUniformVariable) {
  111. const std::string text = R"(
  112. ; CHECK-NOT: OpDecorate
  113. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  114. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  115. ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  116. OpCapability Shader
  117. OpCapability Linkage
  118. OpMemoryModel Logical GLSL450
  119. OpDecorate %var Coherent
  120. OpDecorate %var Volatile
  121. %void = OpTypeVoid
  122. %int = OpTypeInt 32 0
  123. %ptr_int_Uniform = OpTypePointer Uniform %int
  124. %var = OpVariable %ptr_int_Uniform Uniform
  125. %func_ty = OpTypeFunction %void
  126. %func = OpFunction %void None %func_ty
  127. %1 = OpLabel
  128. %ld = OpLoad %int %var
  129. OpStore %var %ld
  130. OpReturn
  131. OpFunctionEnd
  132. )";
  133. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  134. }
  135. TEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameter) {
  136. const std::string text = R"(
  137. ; CHECK-NOT: OpDecorate
  138. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  139. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  140. ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  141. OpCapability Shader
  142. OpCapability Linkage
  143. OpMemoryModel Logical GLSL450
  144. OpDecorate %param Coherent
  145. OpDecorate %param Volatile
  146. %void = OpTypeVoid
  147. %int = OpTypeInt 32 0
  148. %ptr_int_Uniform = OpTypePointer Uniform %int
  149. %func_ty = OpTypeFunction %void %ptr_int_Uniform
  150. %func = OpFunction %void None %func_ty
  151. %param = OpFunctionParameter %ptr_int_Uniform
  152. %1 = OpLabel
  153. %ld = OpLoad %int %param
  154. OpStore %param %ld
  155. OpReturn
  156. OpFunctionEnd
  157. )";
  158. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  159. }
  160. TEST_F(UpgradeMemoryModelTest, SimpleUniformVariableOnlyVolatile) {
  161. const std::string text = R"(
  162. ; CHECK-NOT: OpDecorate
  163. ; CHECK-NOT: OpConstant
  164. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
  165. ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile
  166. OpCapability Shader
  167. OpCapability Linkage
  168. OpMemoryModel Logical GLSL450
  169. OpDecorate %var Volatile
  170. %void = OpTypeVoid
  171. %int = OpTypeInt 32 0
  172. %ptr_int_Uniform = OpTypePointer Uniform %int
  173. %var = OpVariable %ptr_int_Uniform Uniform
  174. %func_ty = OpTypeFunction %void
  175. %func = OpFunction %void None %func_ty
  176. %1 = OpLabel
  177. %ld = OpLoad %int %var
  178. OpStore %var %ld
  179. OpReturn
  180. OpFunctionEnd
  181. )";
  182. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  183. }
  184. TEST_F(UpgradeMemoryModelTest, SimpleUniformVariableCopied) {
  185. const std::string text = R"(
  186. ; CHECK-NOT: OpDecorate
  187. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  188. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  189. ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  190. OpCapability Shader
  191. OpCapability Linkage
  192. OpMemoryModel Logical GLSL450
  193. OpDecorate %var Coherent
  194. OpDecorate %var Volatile
  195. %void = OpTypeVoid
  196. %int = OpTypeInt 32 0
  197. %ptr_int_Uniform = OpTypePointer Uniform %int
  198. %var = OpVariable %ptr_int_Uniform Uniform
  199. %func_ty = OpTypeFunction %void
  200. %func = OpFunction %void None %func_ty
  201. %1 = OpLabel
  202. %copy = OpCopyObject %ptr_int_Uniform %var
  203. %ld = OpLoad %int %copy
  204. OpStore %copy %ld
  205. OpReturn
  206. OpFunctionEnd
  207. )";
  208. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  209. }
  210. TEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameterCopied) {
  211. const std::string text = R"(
  212. ; CHECK-NOT: OpDecorate
  213. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  214. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  215. ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  216. OpCapability Shader
  217. OpCapability Linkage
  218. OpMemoryModel Logical GLSL450
  219. OpDecorate %param Coherent
  220. OpDecorate %param Volatile
  221. %void = OpTypeVoid
  222. %int = OpTypeInt 32 0
  223. %ptr_int_Uniform = OpTypePointer Uniform %int
  224. %func_ty = OpTypeFunction %void %ptr_int_Uniform
  225. %func = OpFunction %void None %func_ty
  226. %param = OpFunctionParameter %ptr_int_Uniform
  227. %1 = OpLabel
  228. %copy = OpCopyObject %ptr_int_Uniform %param
  229. %ld = OpLoad %int %copy
  230. %copy2 = OpCopyObject %ptr_int_Uniform %param
  231. OpStore %copy2 %ld
  232. OpReturn
  233. OpFunctionEnd
  234. )";
  235. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  236. }
  237. TEST_F(UpgradeMemoryModelTest, SimpleUniformVariableAccessChain) {
  238. const std::string text = R"(
  239. ; CHECK-NOT: OpDecorate
  240. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  241. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  242. ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  243. OpCapability Shader
  244. OpCapability Linkage
  245. OpMemoryModel Logical GLSL450
  246. OpDecorate %var Coherent
  247. OpDecorate %var Volatile
  248. %void = OpTypeVoid
  249. %int = OpTypeInt 32 0
  250. %int0 = OpConstant %int 0
  251. %int3 = OpConstant %int 3
  252. %int_array_3 = OpTypeArray %int %int3
  253. %ptr_intarray_Uniform = OpTypePointer Uniform %int_array_3
  254. %ptr_int_Uniform = OpTypePointer Uniform %int
  255. %var = OpVariable %ptr_intarray_Uniform Uniform
  256. %func_ty = OpTypeFunction %void
  257. %func = OpFunction %void None %func_ty
  258. %1 = OpLabel
  259. %gep = OpAccessChain %ptr_int_Uniform %var %int0
  260. %ld = OpLoad %int %gep
  261. OpStore %gep %ld
  262. OpReturn
  263. OpFunctionEnd
  264. )";
  265. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  266. }
  267. TEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameterAccessChain) {
  268. const std::string text = R"(
  269. ; CHECK-NOT: OpDecorate
  270. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  271. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  272. ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  273. OpCapability Shader
  274. OpCapability Linkage
  275. OpMemoryModel Logical GLSL450
  276. OpDecorate %param Coherent
  277. OpDecorate %param Volatile
  278. %void = OpTypeVoid
  279. %int = OpTypeInt 32 0
  280. %int0 = OpConstant %int 0
  281. %int3 = OpConstant %int 3
  282. %int_array_3 = OpTypeArray %int %int3
  283. %ptr_intarray_Uniform = OpTypePointer Uniform %int_array_3
  284. %ptr_int_Uniform = OpTypePointer Uniform %int
  285. %func_ty = OpTypeFunction %void %ptr_intarray_Uniform
  286. %func = OpFunction %void None %func_ty
  287. %param = OpFunctionParameter %ptr_intarray_Uniform
  288. %1 = OpLabel
  289. %ld_gep = OpAccessChain %ptr_int_Uniform %param %int0
  290. %ld = OpLoad %int %ld_gep
  291. %st_gep = OpAccessChain %ptr_int_Uniform %param %int0
  292. OpStore %st_gep %ld
  293. OpReturn
  294. OpFunctionEnd
  295. )";
  296. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  297. }
  298. TEST_F(UpgradeMemoryModelTest, VariablePointerSelect) {
  299. const std::string text = R"(
  300. ; CHECK-NOT: OpDecorate
  301. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  302. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  303. ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  304. OpCapability Shader
  305. OpCapability Linkage
  306. OpCapability VariablePointers
  307. OpExtension "SPV_KHR_variable_pointers"
  308. OpMemoryModel Logical GLSL450
  309. OpDecorate %var Coherent
  310. OpDecorate %var Volatile
  311. %void = OpTypeVoid
  312. %int = OpTypeInt 32 0
  313. %bool = OpTypeBool
  314. %true = OpConstantTrue %bool
  315. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  316. %null = OpConstantNull %ptr_int_StorageBuffer
  317. %var = OpVariable %ptr_int_StorageBuffer StorageBuffer
  318. %func_ty = OpTypeFunction %void
  319. %func = OpFunction %void None %func_ty
  320. %1 = OpLabel
  321. %select = OpSelect %ptr_int_StorageBuffer %true %var %null
  322. %ld = OpLoad %int %select
  323. OpStore %var %ld
  324. OpReturn
  325. OpFunctionEnd
  326. )";
  327. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  328. }
  329. TEST_F(UpgradeMemoryModelTest, VariablePointerSelectConservative) {
  330. const std::string text = R"(
  331. ; CHECK-NOT: OpDecorate
  332. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  333. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  334. ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  335. OpCapability Shader
  336. OpCapability Linkage
  337. OpCapability VariablePointers
  338. OpExtension "SPV_KHR_variable_pointers"
  339. OpMemoryModel Logical GLSL450
  340. OpDecorate %var1 Coherent
  341. OpDecorate %var2 Volatile
  342. %void = OpTypeVoid
  343. %int = OpTypeInt 32 0
  344. %bool = OpTypeBool
  345. %true = OpConstantTrue %bool
  346. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  347. %var1 = OpVariable %ptr_int_StorageBuffer StorageBuffer
  348. %var2 = OpVariable %ptr_int_StorageBuffer StorageBuffer
  349. %func_ty = OpTypeFunction %void
  350. %func = OpFunction %void None %func_ty
  351. %1 = OpLabel
  352. %select = OpSelect %ptr_int_StorageBuffer %true %var1 %var2
  353. %ld = OpLoad %int %select
  354. OpStore %select %ld
  355. OpReturn
  356. OpFunctionEnd
  357. )";
  358. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  359. }
  360. TEST_F(UpgradeMemoryModelTest, VariablePointerIncrement) {
  361. const std::string text = R"(
  362. ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
  363. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  364. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  365. ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  366. OpCapability Shader
  367. OpCapability Linkage
  368. OpCapability VariablePointers
  369. OpExtension "SPV_KHR_variable_pointers"
  370. OpMemoryModel Logical GLSL450
  371. OpDecorate %param Coherent
  372. OpDecorate %param ArrayStride 4
  373. %void = OpTypeVoid
  374. %bool = OpTypeBool
  375. %int = OpTypeInt 32 0
  376. %int0 = OpConstant %int 0
  377. %int1 = OpConstant %int 1
  378. %int10 = OpConstant %int 10
  379. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  380. %func_ty = OpTypeFunction %void %ptr_int_StorageBuffer
  381. %func = OpFunction %void None %func_ty
  382. %param = OpFunctionParameter %ptr_int_StorageBuffer
  383. %1 = OpLabel
  384. OpBranch %2
  385. %2 = OpLabel
  386. %phi = OpPhi %ptr_int_StorageBuffer %param %1 %ptr_next %2
  387. %iv = OpPhi %int %int0 %1 %inc %2
  388. %inc = OpIAdd %int %iv %int1
  389. %ptr_next = OpPtrAccessChain %ptr_int_StorageBuffer %phi %int1
  390. %cmp = OpIEqual %bool %iv %int10
  391. OpLoopMerge %3 %2 None
  392. OpBranchConditional %cmp %3 %2
  393. %3 = OpLabel
  394. %ld = OpLoad %int %phi
  395. OpStore %phi %ld
  396. OpReturn
  397. OpFunctionEnd
  398. )";
  399. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  400. }
  401. TEST_F(UpgradeMemoryModelTest, CoherentStructElement) {
  402. const std::string text = R"(
  403. ; CHECK-NOT: OpMemberDecorate
  404. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  405. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  406. ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  407. OpCapability Shader
  408. OpCapability Linkage
  409. OpExtension "SPV_KHR_storage_buffer_storage_class"
  410. OpMemoryModel Logical GLSL450
  411. OpMemberDecorate %struct 0 Coherent
  412. %void = OpTypeVoid
  413. %int = OpTypeInt 32 0
  414. %int0 = OpConstant %int 0
  415. %struct = OpTypeStruct %int
  416. %ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct
  417. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  418. %func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer
  419. %func = OpFunction %void None %func_ty
  420. %param = OpFunctionParameter %ptr_struct_StorageBuffer
  421. %1 = OpLabel
  422. %gep = OpAccessChain %ptr_int_StorageBuffer %param %int0
  423. %ld = OpLoad %int %gep
  424. OpStore %gep %ld
  425. OpReturn
  426. OpFunctionEnd
  427. )";
  428. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  429. }
  430. TEST_F(UpgradeMemoryModelTest, CoherentElementFullStructAccess) {
  431. const std::string text = R"(
  432. ; CHECK-NOT: OpMemberDecorate
  433. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  434. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  435. ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  436. OpCapability Shader
  437. OpCapability Linkage
  438. OpExtension "SPV_KHR_storage_buffer_storage_class"
  439. OpMemoryModel Logical GLSL450
  440. OpMemberDecorate %struct 0 Coherent
  441. %void = OpTypeVoid
  442. %int = OpTypeInt 32 0
  443. %struct = OpTypeStruct %int
  444. %ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct
  445. %func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer
  446. %func = OpFunction %void None %func_ty
  447. %param = OpFunctionParameter %ptr_struct_StorageBuffer
  448. %1 = OpLabel
  449. %ld = OpLoad %struct %param
  450. OpStore %param %ld
  451. OpReturn
  452. OpFunctionEnd
  453. )";
  454. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  455. }
  456. TEST_F(UpgradeMemoryModelTest, CoherentElementNotAccessed) {
  457. const std::string text = R"(
  458. ; CHECK-NOT: OpMemberDecorate
  459. ; CHECK-NOT: MakePointerAvailableKHR
  460. ; CHECK-NOT: NonPrivatePointerKHR
  461. ; CHECK-NOT: MakePointerVisibleKHR
  462. OpCapability Shader
  463. OpCapability Linkage
  464. OpExtension "SPV_KHR_storage_buffer_storage_class"
  465. OpMemoryModel Logical GLSL450
  466. OpMemberDecorate %struct 1 Coherent
  467. %void = OpTypeVoid
  468. %int = OpTypeInt 32 0
  469. %int0 = OpConstant %int 0
  470. %struct = OpTypeStruct %int %int
  471. %ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct
  472. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  473. %func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer
  474. %func = OpFunction %void None %func_ty
  475. %param = OpFunctionParameter %ptr_struct_StorageBuffer
  476. %1 = OpLabel
  477. %gep = OpAccessChain %ptr_int_StorageBuffer %param %int0
  478. %ld = OpLoad %int %gep
  479. OpStore %gep %ld
  480. OpReturn
  481. OpFunctionEnd
  482. )";
  483. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  484. }
  485. TEST_F(UpgradeMemoryModelTest, MultiIndexAccessCoherent) {
  486. const std::string text = R"(
  487. ; CHECK-NOT: OpMemberDecorate
  488. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  489. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  490. ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  491. OpCapability Shader
  492. OpCapability Linkage
  493. OpExtension "SPV_KHR_storage_buffer_storage_class"
  494. OpMemoryModel Logical GLSL450
  495. OpMemberDecorate %inner 1 Coherent
  496. %void = OpTypeVoid
  497. %int = OpTypeInt 32 0
  498. %int0 = OpConstant %int 0
  499. %int1 = OpConstant %int 1
  500. %inner = OpTypeStruct %int %int
  501. %middle = OpTypeStruct %inner
  502. %outer = OpTypeStruct %middle %middle
  503. %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
  504. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  505. %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
  506. %func = OpFunction %void None %func_ty
  507. %param = OpFunctionParameter %ptr_outer_StorageBuffer
  508. %1 = OpLabel
  509. %ld_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int0 %int0 %int1
  510. %ld = OpLoad %int %ld_gep
  511. %st_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int1 %int0 %int1
  512. OpStore %st_gep %ld
  513. OpReturn
  514. OpFunctionEnd
  515. )";
  516. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  517. }
  518. TEST_F(UpgradeMemoryModelTest, MultiIndexAccessNonCoherent) {
  519. const std::string text = R"(
  520. ; CHECK-NOT: OpMemberDecorate
  521. ; CHECK-NOT: MakePointerAvailableKHR
  522. ; CHECK-NOT: NonPrivatePointerKHR
  523. ; CHECK-NOT: MakePointerVisibleKHR
  524. OpCapability Shader
  525. OpCapability Linkage
  526. OpExtension "SPV_KHR_storage_buffer_storage_class"
  527. OpMemoryModel Logical GLSL450
  528. OpMemberDecorate %inner 1 Coherent
  529. %void = OpTypeVoid
  530. %int = OpTypeInt 32 0
  531. %int0 = OpConstant %int 0
  532. %int1 = OpConstant %int 1
  533. %inner = OpTypeStruct %int %int
  534. %middle = OpTypeStruct %inner
  535. %outer = OpTypeStruct %middle %middle
  536. %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
  537. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  538. %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
  539. %func = OpFunction %void None %func_ty
  540. %param = OpFunctionParameter %ptr_outer_StorageBuffer
  541. %1 = OpLabel
  542. %ld_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int0 %int0 %int0
  543. %ld = OpLoad %int %ld_gep
  544. %st_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int1 %int0 %int0
  545. OpStore %st_gep %ld
  546. OpReturn
  547. OpFunctionEnd
  548. )";
  549. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  550. }
  551. TEST_F(UpgradeMemoryModelTest, ConsecutiveAccessChainCoherent) {
  552. const std::string text = R"(
  553. ; CHECK-NOT: OpMemberDecorate
  554. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  555. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  556. ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  557. OpCapability Shader
  558. OpCapability Linkage
  559. OpExtension "SPV_KHR_storage_buffer_storage_class"
  560. OpMemoryModel Logical GLSL450
  561. OpMemberDecorate %inner 1 Coherent
  562. %void = OpTypeVoid
  563. %int = OpTypeInt 32 0
  564. %int0 = OpConstant %int 0
  565. %int1 = OpConstant %int 1
  566. %inner = OpTypeStruct %int %int
  567. %middle = OpTypeStruct %inner
  568. %outer = OpTypeStruct %middle %middle
  569. %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
  570. %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
  571. %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
  572. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  573. %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
  574. %func = OpFunction %void None %func_ty
  575. %param = OpFunctionParameter %ptr_outer_StorageBuffer
  576. %1 = OpLabel
  577. %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
  578. %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
  579. %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1
  580. %ld = OpLoad %int %ld_gep3
  581. %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
  582. %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
  583. %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1
  584. OpStore %st_gep3 %ld
  585. OpReturn
  586. OpFunctionEnd
  587. )";
  588. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  589. }
  590. TEST_F(UpgradeMemoryModelTest, ConsecutiveAccessChainNonCoherent) {
  591. const std::string text = R"(
  592. ; CHECK-NOT: OpMemberDecorate
  593. ; CHECK-NOT: MakePointerAvailableKHR
  594. ; CHECK-NOT: NonPrivatePointerKHR
  595. ; CHECK-NOT: MakePointerVisibleKHR
  596. OpCapability Shader
  597. OpCapability Linkage
  598. OpExtension "SPV_KHR_storage_buffer_storage_class"
  599. OpMemoryModel Logical GLSL450
  600. OpMemberDecorate %inner 1 Coherent
  601. %void = OpTypeVoid
  602. %int = OpTypeInt 32 0
  603. %int0 = OpConstant %int 0
  604. %int1 = OpConstant %int 1
  605. %inner = OpTypeStruct %int %int
  606. %middle = OpTypeStruct %inner
  607. %outer = OpTypeStruct %middle %middle
  608. %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
  609. %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
  610. %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
  611. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  612. %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
  613. %func = OpFunction %void None %func_ty
  614. %param = OpFunctionParameter %ptr_outer_StorageBuffer
  615. %1 = OpLabel
  616. %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
  617. %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
  618. %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int0
  619. %ld = OpLoad %int %ld_gep3
  620. %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
  621. %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
  622. %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int0
  623. OpStore %st_gep3 %ld
  624. OpReturn
  625. OpFunctionEnd
  626. )";
  627. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  628. }
  629. TEST_F(UpgradeMemoryModelTest, CoherentStructElementAccess) {
  630. const std::string text = R"(
  631. ; CHECK-NOT: OpMemberDecorate
  632. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  633. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  634. ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  635. OpCapability Shader
  636. OpCapability Linkage
  637. OpExtension "SPV_KHR_storage_buffer_storage_class"
  638. OpMemoryModel Logical GLSL450
  639. OpMemberDecorate %middle 0 Coherent
  640. %void = OpTypeVoid
  641. %int = OpTypeInt 32 0
  642. %int0 = OpConstant %int 0
  643. %int1 = OpConstant %int 1
  644. %inner = OpTypeStruct %int %int
  645. %middle = OpTypeStruct %inner
  646. %outer = OpTypeStruct %middle %middle
  647. %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
  648. %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
  649. %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
  650. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  651. %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
  652. %func = OpFunction %void None %func_ty
  653. %param = OpFunctionParameter %ptr_outer_StorageBuffer
  654. %1 = OpLabel
  655. %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
  656. %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
  657. %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1
  658. %ld = OpLoad %int %ld_gep3
  659. %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
  660. %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
  661. %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1
  662. OpStore %st_gep3 %ld
  663. OpReturn
  664. OpFunctionEnd
  665. )";
  666. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  667. }
  668. TEST_F(UpgradeMemoryModelTest, NonCoherentLoadCoherentStore) {
  669. const std::string text = R"(
  670. ; CHECK-NOT: OpMemberDecorate
  671. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  672. ; CHECK-NOT: MakePointerVisibleKHR
  673. ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailableKHR|NonPrivatePointerKHR [[scope]]
  674. OpCapability Shader
  675. OpCapability Linkage
  676. OpExtension "SPV_KHR_storage_buffer_storage_class"
  677. OpMemoryModel Logical GLSL450
  678. OpMemberDecorate %outer 1 Coherent
  679. %void = OpTypeVoid
  680. %int = OpTypeInt 32 0
  681. %int0 = OpConstant %int 0
  682. %int1 = OpConstant %int 1
  683. %inner = OpTypeStruct %int %int
  684. %middle = OpTypeStruct %inner
  685. %outer = OpTypeStruct %middle %middle
  686. %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
  687. %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
  688. %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
  689. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  690. %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
  691. %func = OpFunction %void None %func_ty
  692. %param = OpFunctionParameter %ptr_outer_StorageBuffer
  693. %1 = OpLabel
  694. %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
  695. %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
  696. %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1
  697. %ld = OpLoad %int %ld_gep3
  698. %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
  699. %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
  700. %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1
  701. OpStore %st_gep3 %ld
  702. OpReturn
  703. OpFunctionEnd
  704. )";
  705. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  706. }
  707. TEST_F(UpgradeMemoryModelTest, CopyMemory) {
  708. const std::string text = R"(
  709. ; CHECK-NOT: OpDecorate
  710. ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
  711. ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Volatile|MakePointerVisibleKHR|NonPrivatePointerKHR [[queuefamily]]
  712. ; CHECK-NOT: [[queuefamily]]
  713. OpCapability Shader
  714. OpCapability Linkage
  715. OpExtension "SPV_KHR_storage_buffer_storage_class"
  716. OpMemoryModel Logical GLSL450
  717. OpDecorate %in_var Coherent
  718. OpDecorate %out_var Volatile
  719. %void = OpTypeVoid
  720. %int = OpTypeInt 32 0
  721. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  722. %in_var = OpVariable %ptr_int_StorageBuffer StorageBuffer
  723. %out_var = OpVariable %ptr_int_StorageBuffer StorageBuffer
  724. %func_ty = OpTypeFunction %void
  725. %func = OpFunction %void None %func_ty
  726. %1 = OpLabel
  727. OpCopyMemory %out_var %in_var
  728. OpReturn
  729. OpFunctionEnd
  730. )";
  731. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  732. }
  733. TEST_F(UpgradeMemoryModelTest, CopyMemorySized) {
  734. const std::string text = R"(
  735. ; CHECK-NOT: OpDecorate
  736. ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
  737. ; CHECK: OpCopyMemorySized {{%\w+}} {{%\w+}} {{%\w+}} Volatile|MakePointerAvailableKHR|NonPrivatePointerKHR [[queuefamily]]
  738. ; CHECK-NOT: [[queuefamily]]
  739. OpCapability Shader
  740. OpCapability Linkage
  741. OpCapability Addresses
  742. OpExtension "SPV_KHR_storage_buffer_storage_class"
  743. OpMemoryModel Logical GLSL450
  744. OpDecorate %out_param Coherent
  745. OpDecorate %in_param Volatile
  746. %void = OpTypeVoid
  747. %int = OpTypeInt 32 0
  748. %int4 = OpConstant %int 4
  749. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  750. %func_ty = OpTypeFunction %void %ptr_int_StorageBuffer %ptr_int_StorageBuffer
  751. %func = OpFunction %void None %func_ty
  752. %in_param = OpFunctionParameter %ptr_int_StorageBuffer
  753. %out_param = OpFunctionParameter %ptr_int_StorageBuffer
  754. %1 = OpLabel
  755. OpCopyMemorySized %out_param %in_param %int4
  756. OpReturn
  757. OpFunctionEnd
  758. )";
  759. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  760. }
  761. TEST_F(UpgradeMemoryModelTest, CopyMemoryTwoScopes) {
  762. const std::string text = R"(
  763. ; CHECK-NOT: OpDecorate
  764. ; CHECK-DAG: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
  765. ; CHECK-DAG: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
  766. ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailableKHR|MakePointerVisibleKHR|NonPrivatePointerKHR [[workgroup]] [[queuefamily]]
  767. OpCapability Shader
  768. OpCapability Linkage
  769. OpExtension "SPV_KHR_storage_buffer_storage_class"
  770. OpMemoryModel Logical GLSL450
  771. OpDecorate %in_var Coherent
  772. OpDecorate %out_var Coherent
  773. %void = OpTypeVoid
  774. %int = OpTypeInt 32 0
  775. %ptr_int_Workgroup = OpTypePointer Workgroup %int
  776. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  777. %in_var = OpVariable %ptr_int_StorageBuffer StorageBuffer
  778. %out_var = OpVariable %ptr_int_Workgroup Workgroup
  779. %func_ty = OpTypeFunction %void
  780. %func = OpFunction %void None %func_ty
  781. %1 = OpLabel
  782. OpCopyMemory %out_var %in_var
  783. OpReturn
  784. OpFunctionEnd
  785. )";
  786. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  787. }
  788. TEST_F(UpgradeMemoryModelTest, VolatileImageRead) {
  789. const std::string text = R"(
  790. ; CHECK-NOT: OpDecorate
  791. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
  792. ; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexelKHR
  793. OpCapability Shader
  794. OpCapability Linkage
  795. OpCapability StorageImageReadWithoutFormat
  796. OpExtension "SPV_KHR_storage_buffer_storage_class"
  797. OpMemoryModel Logical GLSL450
  798. OpDecorate %var Volatile
  799. %void = OpTypeVoid
  800. %int = OpTypeInt 32 0
  801. %v2int = OpTypeVector %int 2
  802. %float = OpTypeFloat 32
  803. %int0 = OpConstant %int 0
  804. %v2int_0 = OpConstantComposite %v2int %int0 %int0
  805. %image = OpTypeImage %float 2D 0 0 0 2 Unknown
  806. %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
  807. %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
  808. %func_ty = OpTypeFunction %void
  809. %func = OpFunction %void None %func_ty
  810. %1 = OpLabel
  811. %ld = OpLoad %image %var
  812. %rd = OpImageRead %float %ld %v2int_0
  813. OpReturn
  814. OpFunctionEnd
  815. )";
  816. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  817. }
  818. TEST_F(UpgradeMemoryModelTest, CoherentImageRead) {
  819. const std::string text = R"(
  820. ; CHECK-NOT: OpDecorate
  821. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  822. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  823. ; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisibleKHR|NonPrivateTexelKHR [[scope]]
  824. OpCapability Shader
  825. OpCapability Linkage
  826. OpCapability StorageImageReadWithoutFormat
  827. OpExtension "SPV_KHR_storage_buffer_storage_class"
  828. OpMemoryModel Logical GLSL450
  829. OpDecorate %var Coherent
  830. %void = OpTypeVoid
  831. %int = OpTypeInt 32 0
  832. %v2int = OpTypeVector %int 2
  833. %float = OpTypeFloat 32
  834. %int0 = OpConstant %int 0
  835. %v2int_0 = OpConstantComposite %v2int %int0 %int0
  836. %image = OpTypeImage %float 2D 0 0 0 2 Unknown
  837. %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
  838. %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
  839. %func_ty = OpTypeFunction %void
  840. %func = OpFunction %void None %func_ty
  841. %1 = OpLabel
  842. %ld = OpLoad %image %var
  843. %rd = OpImageRead %float %ld %v2int_0
  844. OpReturn
  845. OpFunctionEnd
  846. )";
  847. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  848. }
  849. TEST_F(UpgradeMemoryModelTest, CoherentImageReadExtractedFromSampledImage) {
  850. const std::string text = R"(
  851. ; CHECK-NOT: OpDecorate
  852. ; CHECK: [[image:%\w+]] = OpTypeImage
  853. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  854. ; CHECK: OpLoad [[image]] {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  855. ; CHECK-NOT: NonPrivatePointerKHR
  856. ; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisibleKHR|NonPrivateTexelKHR [[scope]]
  857. OpCapability Shader
  858. OpCapability Linkage
  859. OpCapability StorageImageReadWithoutFormat
  860. OpExtension "SPV_KHR_storage_buffer_storage_class"
  861. OpMemoryModel Logical GLSL450
  862. OpDecorate %var Coherent
  863. %void = OpTypeVoid
  864. %int = OpTypeInt 32 0
  865. %v2int = OpTypeVector %int 2
  866. %float = OpTypeFloat 32
  867. %int0 = OpConstant %int 0
  868. %v2int_0 = OpConstantComposite %v2int %int0 %int0
  869. %image = OpTypeImage %float 2D 0 0 0 0 Unknown
  870. %sampled_image = OpTypeSampledImage %image
  871. %sampler = OpTypeSampler
  872. %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
  873. %ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler
  874. %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
  875. %sampler_var = OpVariable %ptr_sampler_StorageBuffer StorageBuffer
  876. %func_ty = OpTypeFunction %void
  877. %func = OpFunction %void None %func_ty
  878. %1 = OpLabel
  879. %ld = OpLoad %image %var
  880. %ld_sampler = OpLoad %sampler %sampler_var
  881. %sample = OpSampledImage %sampled_image %ld %ld_sampler
  882. %extract = OpImage %image %sample
  883. %rd = OpImageRead %float %extract %v2int_0
  884. OpReturn
  885. OpFunctionEnd
  886. )";
  887. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  888. }
  889. TEST_F(UpgradeMemoryModelTest, VolatileImageWrite) {
  890. const std::string text = R"(
  891. ; CHECK-NOT: OpDecorate
  892. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
  893. ; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexelKHR
  894. OpCapability Shader
  895. OpCapability Linkage
  896. OpCapability StorageImageWriteWithoutFormat
  897. OpExtension "SPV_KHR_storage_buffer_storage_class"
  898. OpMemoryModel Logical GLSL450
  899. OpDecorate %param Volatile
  900. %void = OpTypeVoid
  901. %int = OpTypeInt 32 0
  902. %v2int = OpTypeVector %int 2
  903. %float = OpTypeFloat 32
  904. %float0 = OpConstant %float 0
  905. %v2int_null = OpConstantNull %v2int
  906. %image = OpTypeImage %float 2D 0 0 0 0 Unknown
  907. %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
  908. %func_ty = OpTypeFunction %void %ptr_image_StorageBuffer
  909. %func = OpFunction %void None %func_ty
  910. %param = OpFunctionParameter %ptr_image_StorageBuffer
  911. %1 = OpLabel
  912. %ld = OpLoad %image %param
  913. OpImageWrite %ld %v2int_null %float0
  914. OpReturn
  915. OpFunctionEnd
  916. )";
  917. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  918. }
  919. TEST_F(UpgradeMemoryModelTest, CoherentImageWrite) {
  920. const std::string text = R"(
  921. ; CHECK-NOT: OpDecorate
  922. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  923. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR
  924. ; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelAvailableKHR|NonPrivateTexelKHR [[scope]]
  925. OpCapability Shader
  926. OpCapability Linkage
  927. OpCapability StorageImageWriteWithoutFormat
  928. OpExtension "SPV_KHR_storage_buffer_storage_class"
  929. OpMemoryModel Logical GLSL450
  930. OpDecorate %param Coherent
  931. %void = OpTypeVoid
  932. %int = OpTypeInt 32 0
  933. %v2int = OpTypeVector %int 2
  934. %float = OpTypeFloat 32
  935. %float0 = OpConstant %float 0
  936. %v2int_null = OpConstantNull %v2int
  937. %image = OpTypeImage %float 2D 0 0 0 0 Unknown
  938. %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
  939. %func_ty = OpTypeFunction %void %ptr_image_StorageBuffer
  940. %func = OpFunction %void None %func_ty
  941. %param = OpFunctionParameter %ptr_image_StorageBuffer
  942. %1 = OpLabel
  943. %ld = OpLoad %image %param
  944. OpImageWrite %ld %v2int_null %float0
  945. OpReturn
  946. OpFunctionEnd
  947. )";
  948. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  949. }
  950. TEST_F(UpgradeMemoryModelTest, CoherentImageWriteExtractFromSampledImage) {
  951. const std::string text = R"(
  952. ; CHECK-NOT: OpDecorate
  953. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  954. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR
  955. ; CHECK-NOT: NonPrivatePointerKHR
  956. ; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelAvailableKHR|NonPrivateTexelKHR [[scope]]
  957. OpCapability Shader
  958. OpCapability Linkage
  959. OpCapability StorageImageWriteWithoutFormat
  960. OpExtension "SPV_KHR_storage_buffer_storage_class"
  961. OpMemoryModel Logical GLSL450
  962. OpDecorate %param Coherent
  963. %void = OpTypeVoid
  964. %int = OpTypeInt 32 0
  965. %v2int = OpTypeVector %int 2
  966. %float = OpTypeFloat 32
  967. %float0 = OpConstant %float 0
  968. %v2int_null = OpConstantNull %v2int
  969. %image = OpTypeImage %float 2D 0 0 0 0 Unknown
  970. %sampled_image = OpTypeSampledImage %image
  971. %sampler = OpTypeSampler
  972. %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
  973. %ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler
  974. %func_ty = OpTypeFunction %void %ptr_image_StorageBuffer %ptr_sampler_StorageBuffer
  975. %func = OpFunction %void None %func_ty
  976. %param = OpFunctionParameter %ptr_image_StorageBuffer
  977. %sampler_param = OpFunctionParameter %ptr_sampler_StorageBuffer
  978. %1 = OpLabel
  979. %ld = OpLoad %image %param
  980. %ld_sampler = OpLoad %sampler %sampler_param
  981. %sample = OpSampledImage %sampled_image %ld %ld_sampler
  982. %extract = OpImage %image %sample
  983. OpImageWrite %extract %v2int_null %float0
  984. OpReturn
  985. OpFunctionEnd
  986. )";
  987. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  988. }
  989. TEST_F(UpgradeMemoryModelTest, VolatileImageSparseRead) {
  990. const std::string text = R"(
  991. ; CHECK-NOT: OpDecorate
  992. ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
  993. ; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexelKHR
  994. OpCapability Shader
  995. OpCapability Linkage
  996. OpCapability StorageImageReadWithoutFormat
  997. OpCapability SparseResidency
  998. OpExtension "SPV_KHR_storage_buffer_storage_class"
  999. OpMemoryModel Logical GLSL450
  1000. OpDecorate %var Volatile
  1001. %void = OpTypeVoid
  1002. %int = OpTypeInt 32 0
  1003. %v2int = OpTypeVector %int 2
  1004. %float = OpTypeFloat 32
  1005. %int0 = OpConstant %int 0
  1006. %v2int_0 = OpConstantComposite %v2int %int0 %int0
  1007. %image = OpTypeImage %float 2D 0 0 0 2 Unknown
  1008. %struct = OpTypeStruct %int %float
  1009. %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
  1010. %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
  1011. %func_ty = OpTypeFunction %void
  1012. %func = OpFunction %void None %func_ty
  1013. %1 = OpLabel
  1014. %ld = OpLoad %image %var
  1015. %rd = OpImageSparseRead %struct %ld %v2int_0
  1016. OpReturn
  1017. OpFunctionEnd
  1018. )";
  1019. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1020. }
  1021. TEST_F(UpgradeMemoryModelTest, CoherentImageSparseRead) {
  1022. const std::string text = R"(
  1023. ; CHECK-NOT: OpDecorate
  1024. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  1025. ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  1026. ; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisibleKHR|NonPrivateTexelKHR [[scope]]
  1027. OpCapability Shader
  1028. OpCapability Linkage
  1029. OpCapability StorageImageReadWithoutFormat
  1030. OpCapability SparseResidency
  1031. OpExtension "SPV_KHR_storage_buffer_storage_class"
  1032. OpMemoryModel Logical GLSL450
  1033. OpDecorate %var Coherent
  1034. %void = OpTypeVoid
  1035. %int = OpTypeInt 32 0
  1036. %v2int = OpTypeVector %int 2
  1037. %float = OpTypeFloat 32
  1038. %int0 = OpConstant %int 0
  1039. %v2int_0 = OpConstantComposite %v2int %int0 %int0
  1040. %image = OpTypeImage %float 2D 0 0 0 2 Unknown
  1041. %struct = OpTypeStruct %int %float
  1042. %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
  1043. %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
  1044. %func_ty = OpTypeFunction %void
  1045. %func = OpFunction %void None %func_ty
  1046. %1 = OpLabel
  1047. %ld = OpLoad %image %var
  1048. %rd = OpImageSparseRead %struct %ld %v2int_0
  1049. OpReturn
  1050. OpFunctionEnd
  1051. )";
  1052. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1053. }
  1054. TEST_F(UpgradeMemoryModelTest,
  1055. CoherentImageSparseReadExtractedFromSampledImage) {
  1056. const std::string text = R"(
  1057. ; CHECK-NOT: OpDecorate
  1058. ; CHECK: [[image:%\w+]] = OpTypeImage
  1059. ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
  1060. ; CHECK: OpLoad [[image]] {{%\w+}} MakePointerVisibleKHR|NonPrivatePointerKHR [[scope]]
  1061. ; CHECK-NOT: NonPrivatePointerKHR
  1062. ; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisibleKHR|NonPrivateTexelKHR [[scope]]
  1063. OpCapability Shader
  1064. OpCapability Linkage
  1065. OpCapability StorageImageReadWithoutFormat
  1066. OpCapability SparseResidency
  1067. OpExtension "SPV_KHR_storage_buffer_storage_class"
  1068. OpMemoryModel Logical GLSL450
  1069. OpDecorate %var Coherent
  1070. %void = OpTypeVoid
  1071. %int = OpTypeInt 32 0
  1072. %v2int = OpTypeVector %int 2
  1073. %float = OpTypeFloat 32
  1074. %int0 = OpConstant %int 0
  1075. %v2int_0 = OpConstantComposite %v2int %int0 %int0
  1076. %image = OpTypeImage %float 2D 0 0 0 0 Unknown
  1077. %struct = OpTypeStruct %int %float
  1078. %sampled_image = OpTypeSampledImage %image
  1079. %sampler = OpTypeSampler
  1080. %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
  1081. %ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler
  1082. %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
  1083. %sampler_var = OpVariable %ptr_sampler_StorageBuffer StorageBuffer
  1084. %func_ty = OpTypeFunction %void
  1085. %func = OpFunction %void None %func_ty
  1086. %1 = OpLabel
  1087. %ld = OpLoad %image %var
  1088. %ld_sampler = OpLoad %sampler %sampler_var
  1089. %sample = OpSampledImage %sampled_image %ld %ld_sampler
  1090. %extract = OpImage %image %sample
  1091. %rd = OpImageSparseRead %struct %extract %v2int_0
  1092. OpReturn
  1093. OpFunctionEnd
  1094. )";
  1095. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1096. }
  1097. TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierNoChange) {
  1098. const std::string text = R"(
  1099. ; CHECK: [[none:%\w+]] = OpConstant {{%\w+}} 0
  1100. ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
  1101. ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[none]]
  1102. OpCapability Tessellation
  1103. OpMemoryModel Logical GLSL450
  1104. OpEntryPoint TessellationControl %func "func"
  1105. %void = OpTypeVoid
  1106. %int = OpTypeInt 32 0
  1107. %none = OpConstant %int 0
  1108. %workgroup = OpConstant %int 2
  1109. %func_ty = OpTypeFunction %void
  1110. %func = OpFunction %void None %func_ty
  1111. %1 = OpLabel
  1112. OpControlBarrier %workgroup %workgroup %none
  1113. OpReturn
  1114. OpFunctionEnd
  1115. )";
  1116. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1117. }
  1118. TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierAddOutput) {
  1119. const std::string text = R"(
  1120. ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
  1121. ; CHECK: [[output:%\w+]] = OpConstant {{%\w+}} 4096
  1122. ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[output]]
  1123. OpCapability Tessellation
  1124. OpMemoryModel Logical GLSL450
  1125. OpEntryPoint TessellationControl %func "func" %var
  1126. %void = OpTypeVoid
  1127. %int = OpTypeInt 32 0
  1128. %none = OpConstant %int 0
  1129. %workgroup = OpConstant %int 2
  1130. %ptr_int_Output = OpTypePointer Output %int
  1131. %var = OpVariable %ptr_int_Output Output
  1132. %func_ty = OpTypeFunction %void
  1133. %func = OpFunction %void None %func_ty
  1134. %1 = OpLabel
  1135. %ld = OpLoad %int %var
  1136. OpControlBarrier %workgroup %workgroup %none
  1137. OpStore %var %ld
  1138. OpReturn
  1139. OpFunctionEnd
  1140. )";
  1141. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1142. }
  1143. TEST_F(UpgradeMemoryModelTest, TessellationMemoryBarrierNoChange) {
  1144. const std::string text = R"(
  1145. ; CHECK: [[none:%\w+]] = OpConstant {{%\w+}} 0
  1146. ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
  1147. ; CHECK: OpMemoryBarrier [[workgroup]] [[none]]
  1148. OpCapability Tessellation
  1149. OpMemoryModel Logical GLSL450
  1150. OpEntryPoint TessellationControl %func "func" %var
  1151. %void = OpTypeVoid
  1152. %int = OpTypeInt 32 0
  1153. %none = OpConstant %int 0
  1154. %workgroup = OpConstant %int 2
  1155. %ptr_int_Output = OpTypePointer Output %int
  1156. %var = OpVariable %ptr_int_Output Output
  1157. %func_ty = OpTypeFunction %void
  1158. %func = OpFunction %void None %func_ty
  1159. %1 = OpLabel
  1160. %ld = OpLoad %int %var
  1161. OpMemoryBarrier %workgroup %none
  1162. OpStore %var %ld
  1163. OpReturn
  1164. OpFunctionEnd
  1165. )";
  1166. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1167. }
  1168. TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierAddOutputSubFunction) {
  1169. const std::string text = R"(
  1170. ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
  1171. ; CHECK: [[output:%\w+]] = OpConstant {{%\w+}} 4096
  1172. ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[output]]
  1173. OpCapability Tessellation
  1174. OpMemoryModel Logical GLSL450
  1175. OpEntryPoint TessellationControl %func "func" %var
  1176. %void = OpTypeVoid
  1177. %int = OpTypeInt 32 0
  1178. %none = OpConstant %int 0
  1179. %workgroup = OpConstant %int 2
  1180. %ptr_int_Output = OpTypePointer Output %int
  1181. %var = OpVariable %ptr_int_Output Output
  1182. %func_ty = OpTypeFunction %void
  1183. %func = OpFunction %void None %func_ty
  1184. %1 = OpLabel
  1185. %call = OpFunctionCall %void %sub_func
  1186. OpReturn
  1187. OpFunctionEnd
  1188. %sub_func = OpFunction %void None %func_ty
  1189. %2 = OpLabel
  1190. %ld = OpLoad %int %var
  1191. OpControlBarrier %workgroup %workgroup %none
  1192. OpStore %var %ld
  1193. OpReturn
  1194. OpFunctionEnd
  1195. )";
  1196. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1197. }
  1198. TEST_F(UpgradeMemoryModelTest,
  1199. TessellationControlBarrierAddOutputDifferentFunctions) {
  1200. const std::string text = R"(
  1201. ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
  1202. ; CHECK: [[output:%\w+]] = OpConstant {{%\w+}} 4096
  1203. ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[output]]
  1204. OpCapability Tessellation
  1205. OpMemoryModel Logical GLSL450
  1206. OpEntryPoint TessellationControl %func "func" %var
  1207. %void = OpTypeVoid
  1208. %int = OpTypeInt 32 0
  1209. %none = OpConstant %int 0
  1210. %workgroup = OpConstant %int 2
  1211. %ptr_int_Output = OpTypePointer Output %int
  1212. %var = OpVariable %ptr_int_Output Output
  1213. %func_ty = OpTypeFunction %void
  1214. %ld_func_ty = OpTypeFunction %int
  1215. %st_func_ty = OpTypeFunction %void %int
  1216. %func = OpFunction %void None %func_ty
  1217. %1 = OpLabel
  1218. %call_ld = OpFunctionCall %int %ld_func
  1219. %call_barrier = OpFunctionCall %void %barrier_func
  1220. %call_st = OpFunctionCall %void %st_func %call_ld
  1221. OpReturn
  1222. OpFunctionEnd
  1223. %ld_func = OpFunction %int None %ld_func_ty
  1224. %2 = OpLabel
  1225. %ld = OpLoad %int %var
  1226. OpReturnValue %ld
  1227. OpFunctionEnd
  1228. %barrier_func = OpFunction %void None %func_ty
  1229. %3 = OpLabel
  1230. OpControlBarrier %workgroup %workgroup %none
  1231. OpReturn
  1232. OpFunctionEnd
  1233. %st_func = OpFunction %void None %st_func_ty
  1234. %param = OpFunctionParameter %int
  1235. %4 = OpLabel
  1236. OpStore %var %param
  1237. OpReturn
  1238. OpFunctionEnd
  1239. )";
  1240. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1241. }
  1242. TEST_F(UpgradeMemoryModelTest, ChangeControlBarrierMemoryScope) {
  1243. std::string text = R"(
  1244. ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
  1245. ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
  1246. ; CHECK: OpControlBarrier [[workgroup]] [[queuefamily]]
  1247. OpCapability Shader
  1248. OpMemoryModel Logical GLSL450
  1249. OpEntryPoint GLCompute %func "func"
  1250. %void = OpTypeVoid
  1251. %int = OpTypeInt 32 0
  1252. %none = OpConstant %int 0
  1253. %device = OpConstant %int 1
  1254. %workgroup = OpConstant %int 2
  1255. %func_ty = OpTypeFunction %void
  1256. %func = OpFunction %void None %func_ty
  1257. %1 = OpLabel
  1258. OpControlBarrier %workgroup %device %none
  1259. OpReturn
  1260. OpFunctionEnd
  1261. )";
  1262. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1263. }
  1264. TEST_F(UpgradeMemoryModelTest, ChangeMemoryBarrierMemoryScope) {
  1265. std::string text = R"(
  1266. ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
  1267. ; CHECK: OpMemoryBarrier [[queuefamily]]
  1268. OpCapability Shader
  1269. OpMemoryModel Logical GLSL450
  1270. OpEntryPoint GLCompute %func "func"
  1271. %void = OpTypeVoid
  1272. %int = OpTypeInt 32 0
  1273. %none = OpConstant %int 0
  1274. %device = OpConstant %int 1
  1275. %func_ty = OpTypeFunction %void
  1276. %func = OpFunction %void None %func_ty
  1277. %1 = OpLabel
  1278. OpMemoryBarrier %device %none
  1279. OpReturn
  1280. OpFunctionEnd
  1281. )";
  1282. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1283. }
  1284. TEST_F(UpgradeMemoryModelTest, ChangeAtomicMemoryScope) {
  1285. std::string text = R"(
  1286. ; CHECK: [[int:%\w+]] = OpTypeInt
  1287. ; CHECK: [[var:%\w+]] = OpVariable
  1288. ; CHECK: [[qf:%\w+]] = OpConstant [[int]] 5
  1289. ; CHECK: OpAtomicLoad [[int]] [[var]] [[qf]]
  1290. ; CHECK: OpAtomicStore [[var]] [[qf]]
  1291. ; CHECK: OpAtomicExchange [[int]] [[var]] [[qf]]
  1292. ; CHECK: OpAtomicCompareExchange [[int]] [[var]] [[qf]]
  1293. ; CHECK: OpAtomicIIncrement [[int]] [[var]] [[qf]]
  1294. ; CHECK: OpAtomicIDecrement [[int]] [[var]] [[qf]]
  1295. ; CHECK: OpAtomicIAdd [[int]] [[var]] [[qf]]
  1296. ; CHECK: OpAtomicISub [[int]] [[var]] [[qf]]
  1297. ; CHECK: OpAtomicSMin [[int]] [[var]] [[qf]]
  1298. ; CHECK: OpAtomicSMax [[int]] [[var]] [[qf]]
  1299. ; CHECK: OpAtomicUMin [[int]] [[var]] [[qf]]
  1300. ; CHECK: OpAtomicUMax [[int]] [[var]] [[qf]]
  1301. ; CHECK: OpAtomicAnd [[int]] [[var]] [[qf]]
  1302. ; CHECK: OpAtomicOr [[int]] [[var]] [[qf]]
  1303. ; CHECK: OpAtomicXor [[int]] [[var]] [[qf]]
  1304. OpCapability Shader
  1305. OpExtension "SPV_KHR_storage_buffer_storage_class"
  1306. OpMemoryModel Logical GLSL450
  1307. OpEntryPoint GLCompute %func "func"
  1308. %void = OpTypeVoid
  1309. %int = OpTypeInt 32 0
  1310. %none = OpConstant %int 0
  1311. %device = OpConstant %int 1
  1312. %func_ty = OpTypeFunction %void
  1313. %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
  1314. %var = OpVariable %ptr_int_StorageBuffer StorageBuffer
  1315. %func = OpFunction %void None %func_ty
  1316. %1 = OpLabel
  1317. %ld = OpAtomicLoad %int %var %device %none
  1318. OpAtomicStore %var %device %none %ld
  1319. %ex = OpAtomicExchange %int %var %device %none %ld
  1320. %cmp_ex = OpAtomicCompareExchange %int %var %device %none %none %ld %ld
  1321. %inc = OpAtomicIIncrement %int %var %device %none
  1322. %dec = OpAtomicIDecrement %int %var %device %none
  1323. %add = OpAtomicIAdd %int %var %device %none %ld
  1324. %sub = OpAtomicISub %int %var %device %none %ld
  1325. %smin = OpAtomicSMin %int %var %device %none %ld
  1326. %smax = OpAtomicSMax %int %var %device %none %ld
  1327. %umin = OpAtomicUMin %int %var %device %none %ld
  1328. %umax = OpAtomicUMax %int %var %device %none %ld
  1329. %and = OpAtomicAnd %int %var %device %none %ld
  1330. %or = OpAtomicOr %int %var %device %none %ld
  1331. %xor = OpAtomicXor %int %var %device %none %ld
  1332. OpReturn
  1333. OpFunctionEnd
  1334. )";
  1335. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1336. }
  1337. TEST_F(UpgradeMemoryModelTest, UpgradeModfNoFlags) {
  1338. const std::string text = R"(
  1339. ; CHECK: [[float:%\w+]] = OpTypeFloat 32
  1340. ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
  1341. ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]]
  1342. ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
  1343. ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
  1344. ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
  1345. ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
  1346. ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
  1347. ; CHECK: OpStore [[var]] [[ex1]]
  1348. ; CHECK-NOT: NonPrivatePointerKHR
  1349. ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
  1350. OpCapability Shader
  1351. OpMemoryModel Logical GLSL450
  1352. %import = OpExtInstImport "GLSL.std.450"
  1353. OpEntryPoint GLCompute %func "func"
  1354. %void = OpTypeVoid
  1355. %float = OpTypeFloat 32
  1356. %float_0 = OpConstant %float 0
  1357. %ptr_ssbo_float = OpTypePointer StorageBuffer %float
  1358. %ssbo_var = OpVariable %ptr_ssbo_float StorageBuffer
  1359. %func_ty = OpTypeFunction %void
  1360. %func = OpFunction %void None %func_ty
  1361. %1 = OpLabel
  1362. %2 = OpExtInst %float %import Modf %float_0 %ssbo_var
  1363. %3 = OpFAdd %float %float_0 %2
  1364. OpReturn
  1365. OpFunctionEnd
  1366. )";
  1367. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1368. }
  1369. TEST_F(UpgradeMemoryModelTest, UpgradeModfWorkgroupCoherent) {
  1370. const std::string text = R"(
  1371. ; CHECK: [[float:%\w+]] = OpTypeFloat 32
  1372. ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
  1373. ; CHECK: [[ptr:%\w+]] = OpTypePointer Workgroup [[float]]
  1374. ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] Workgroup
  1375. ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
  1376. ; CHECK: [[wg_scope:%\w+]] = OpConstant {{%\w+}} 2
  1377. ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
  1378. ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
  1379. ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
  1380. ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailableKHR|NonPrivatePointerKHR [[wg_scope]]
  1381. ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
  1382. OpCapability Shader
  1383. OpMemoryModel Logical GLSL450
  1384. %import = OpExtInstImport "GLSL.std.450"
  1385. OpEntryPoint GLCompute %func "func"
  1386. OpDecorate %wg_var Coherent
  1387. %void = OpTypeVoid
  1388. %float = OpTypeFloat 32
  1389. %float_0 = OpConstant %float 0
  1390. %ptr_wg_float = OpTypePointer Workgroup %float
  1391. %wg_var = OpVariable %ptr_wg_float Workgroup
  1392. %func_ty = OpTypeFunction %void
  1393. %func = OpFunction %void None %func_ty
  1394. %1 = OpLabel
  1395. %2 = OpExtInst %float %import Modf %float_0 %wg_var
  1396. %3 = OpFAdd %float %float_0 %2
  1397. OpReturn
  1398. OpFunctionEnd
  1399. )";
  1400. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1401. }
  1402. TEST_F(UpgradeMemoryModelTest, UpgradeModfSSBOCoherent) {
  1403. const std::string text = R"(
  1404. ; CHECK: [[float:%\w+]] = OpTypeFloat 32
  1405. ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
  1406. ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]]
  1407. ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
  1408. ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
  1409. ; CHECK: [[qf_scope:%\w+]] = OpConstant {{%\w+}} 5
  1410. ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
  1411. ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
  1412. ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
  1413. ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailableKHR|NonPrivatePointerKHR [[qf_scope]]
  1414. ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
  1415. OpCapability Shader
  1416. OpMemoryModel Logical GLSL450
  1417. %import = OpExtInstImport "GLSL.std.450"
  1418. OpEntryPoint GLCompute %func "func"
  1419. OpDecorate %ssbo_var Coherent
  1420. %void = OpTypeVoid
  1421. %float = OpTypeFloat 32
  1422. %float_0 = OpConstant %float 0
  1423. %ptr_ssbo_float = OpTypePointer StorageBuffer %float
  1424. %ssbo_var = OpVariable %ptr_ssbo_float StorageBuffer
  1425. %func_ty = OpTypeFunction %void
  1426. %func = OpFunction %void None %func_ty
  1427. %1 = OpLabel
  1428. %2 = OpExtInst %float %import Modf %float_0 %ssbo_var
  1429. %3 = OpFAdd %float %float_0 %2
  1430. OpReturn
  1431. OpFunctionEnd
  1432. )";
  1433. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1434. }
  1435. TEST_F(UpgradeMemoryModelTest, UpgradeModfSSBOVolatile) {
  1436. const std::string text = R"(
  1437. ; CHECK: [[float:%\w+]] = OpTypeFloat 32
  1438. ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
  1439. ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]]
  1440. ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
  1441. ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
  1442. ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
  1443. ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
  1444. ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
  1445. ; CHECK: OpStore [[var]] [[ex1]] Volatile
  1446. ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
  1447. OpCapability Shader
  1448. OpMemoryModel Logical GLSL450
  1449. %import = OpExtInstImport "GLSL.std.450"
  1450. OpEntryPoint GLCompute %func "func"
  1451. OpDecorate %wg_var Volatile
  1452. %void = OpTypeVoid
  1453. %float = OpTypeFloat 32
  1454. %float_0 = OpConstant %float 0
  1455. %ptr_ssbo_float = OpTypePointer StorageBuffer %float
  1456. %wg_var = OpVariable %ptr_ssbo_float StorageBuffer
  1457. %func_ty = OpTypeFunction %void
  1458. %func = OpFunction %void None %func_ty
  1459. %1 = OpLabel
  1460. %2 = OpExtInst %float %import Modf %float_0 %wg_var
  1461. %3 = OpFAdd %float %float_0 %2
  1462. OpReturn
  1463. OpFunctionEnd
  1464. )";
  1465. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1466. }
  1467. TEST_F(UpgradeMemoryModelTest, UpgradeFrexpNoFlags) {
  1468. const std::string text = R"(
  1469. ; CHECK: [[float:%\w+]] = OpTypeFloat 32
  1470. ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
  1471. ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
  1472. ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]]
  1473. ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
  1474. ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
  1475. ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
  1476. ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
  1477. ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
  1478. ; CHECK: OpStore [[var]] [[ex1]]
  1479. ; CHECK-NOT: NonPrivatePointerKHR
  1480. ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
  1481. OpCapability Shader
  1482. OpMemoryModel Logical GLSL450
  1483. %import = OpExtInstImport "GLSL.std.450"
  1484. OpEntryPoint GLCompute %func "func"
  1485. %void = OpTypeVoid
  1486. %float = OpTypeFloat 32
  1487. %float_0 = OpConstant %float 0
  1488. %int = OpTypeInt 32 0
  1489. %ptr_ssbo_int = OpTypePointer StorageBuffer %int
  1490. %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
  1491. %func_ty = OpTypeFunction %void
  1492. %func = OpFunction %void None %func_ty
  1493. %1 = OpLabel
  1494. %2 = OpExtInst %float %import Frexp %float_0 %ssbo_var
  1495. %3 = OpFAdd %float %float_0 %2
  1496. OpReturn
  1497. OpFunctionEnd
  1498. )";
  1499. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1500. }
  1501. TEST_F(UpgradeMemoryModelTest, UpgradeFrexpWorkgroupCoherent) {
  1502. const std::string text = R"(
  1503. ; CHECK: [[float:%\w+]] = OpTypeFloat 32
  1504. ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
  1505. ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
  1506. ; CHECK: [[ptr:%\w+]] = OpTypePointer Workgroup [[int]]
  1507. ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] Workgroup
  1508. ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
  1509. ; CHECK: [[wg_scope:%\w+]] = OpConstant {{%\w+}} 2
  1510. ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
  1511. ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
  1512. ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
  1513. ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailableKHR|NonPrivatePointerKHR [[wg_scope]]
  1514. ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
  1515. OpCapability Shader
  1516. OpMemoryModel Logical GLSL450
  1517. %import = OpExtInstImport "GLSL.std.450"
  1518. OpEntryPoint GLCompute %func "func"
  1519. OpDecorate %wg_var Coherent
  1520. %void = OpTypeVoid
  1521. %float = OpTypeFloat 32
  1522. %float_0 = OpConstant %float 0
  1523. %int = OpTypeInt 32 0
  1524. %ptr_wg_int = OpTypePointer Workgroup %int
  1525. %wg_var = OpVariable %ptr_wg_int Workgroup
  1526. %func_ty = OpTypeFunction %void
  1527. %func = OpFunction %void None %func_ty
  1528. %1 = OpLabel
  1529. %2 = OpExtInst %float %import Frexp %float_0 %wg_var
  1530. %3 = OpFAdd %float %float_0 %2
  1531. OpReturn
  1532. OpFunctionEnd
  1533. )";
  1534. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1535. }
  1536. TEST_F(UpgradeMemoryModelTest, UpgradeFrexpSSBOCoherent) {
  1537. const std::string text = R"(
  1538. ; CHECK: [[float:%\w+]] = OpTypeFloat 32
  1539. ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
  1540. ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
  1541. ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]]
  1542. ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
  1543. ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
  1544. ; CHECK: [[qf_scope:%\w+]] = OpConstant {{%\w+}} 5
  1545. ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
  1546. ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
  1547. ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
  1548. ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailableKHR|NonPrivatePointerKHR [[qf_scope]]
  1549. ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
  1550. OpCapability Shader
  1551. OpMemoryModel Logical GLSL450
  1552. %import = OpExtInstImport "GLSL.std.450"
  1553. OpEntryPoint GLCompute %func "func"
  1554. OpDecorate %ssbo_var Coherent
  1555. %void = OpTypeVoid
  1556. %float = OpTypeFloat 32
  1557. %float_0 = OpConstant %float 0
  1558. %int = OpTypeInt 32 0
  1559. %ptr_ssbo_int = OpTypePointer StorageBuffer %int
  1560. %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
  1561. %func_ty = OpTypeFunction %void
  1562. %func = OpFunction %void None %func_ty
  1563. %1 = OpLabel
  1564. %2 = OpExtInst %float %import Frexp %float_0 %ssbo_var
  1565. %3 = OpFAdd %float %float_0 %2
  1566. OpReturn
  1567. OpFunctionEnd
  1568. )";
  1569. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1570. }
  1571. TEST_F(UpgradeMemoryModelTest, UpgradeFrexpSSBOVolatile) {
  1572. const std::string text = R"(
  1573. ; CHECK: [[float:%\w+]] = OpTypeFloat 32
  1574. ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
  1575. ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
  1576. ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]]
  1577. ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
  1578. ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
  1579. ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
  1580. ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
  1581. ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
  1582. ; CHECK: OpStore [[var]] [[ex1]] Volatile
  1583. ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
  1584. OpCapability Shader
  1585. OpMemoryModel Logical GLSL450
  1586. %import = OpExtInstImport "GLSL.std.450"
  1587. OpEntryPoint GLCompute %func "func"
  1588. OpDecorate %wg_var Volatile
  1589. %void = OpTypeVoid
  1590. %float = OpTypeFloat 32
  1591. %float_0 = OpConstant %float 0
  1592. %int = OpTypeInt 32 0
  1593. %ptr_ssbo_int = OpTypePointer StorageBuffer %int
  1594. %wg_var = OpVariable %ptr_ssbo_int StorageBuffer
  1595. %func_ty = OpTypeFunction %void
  1596. %func = OpFunction %void None %func_ty
  1597. %1 = OpLabel
  1598. %2 = OpExtInst %float %import Frexp %float_0 %wg_var
  1599. %3 = OpFAdd %float %float_0 %2
  1600. OpReturn
  1601. OpFunctionEnd
  1602. )";
  1603. SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
  1604. }
  1605. } // namespace