trim_capabilities_pass_test.cpp 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558
  1. // Copyright (c) 2023 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <gtest/gtest-param-test.h>
  15. #include <gtest/gtest.h>
  16. #include <tuple>
  17. #include "spirv-tools/optimizer.hpp"
  18. #include "test/opt/pass_fixture.h"
  19. #include "test/opt/pass_utils.h"
  20. namespace spvtools {
  21. namespace opt {
  22. namespace {
  23. using TrimCapabilitiesPassTest = PassTest<::testing::Test>;
  24. TEST_F(TrimCapabilitiesPassTest, CheckKnownAliasTransformations) {
  25. // Those are expected changes caused by the test process:
  26. // - SPV is assembled. -> capability goes from text to number.
  27. // - SPV is optimized.
  28. // - SPV is disassembled -> capability goes from number to text.
  29. // - CHECK rule compares both text versions.
  30. // Because some capabilities share the same number (aliases), the text
  31. // compared with the CHECK rules depends on which alias is the first on the
  32. // SPIRV-Headers enum. This could change, and we want to easily distinguish
  33. // real failure from alias order change. This test is only here to list known
  34. // alias transformations. If this test breaks, it's not a bug in the
  35. // optimization pass, but just the SPIRV-Headers enum order that has changed.
  36. // If that happens, tests needs to be updated to the correct alias is used in
  37. // the CHECK rule.
  38. const std::string kTest = R"(
  39. OpCapability Linkage
  40. OpCapability StorageUniform16
  41. OpCapability StorageUniformBufferBlock16
  42. OpCapability ShaderViewportIndexLayerNV
  43. OpCapability FragmentBarycentricNV
  44. OpCapability ShadingRateNV
  45. OpCapability ShaderNonUniformEXT
  46. OpCapability RuntimeDescriptorArrayEXT
  47. OpCapability InputAttachmentArrayDynamicIndexingEXT
  48. OpCapability UniformTexelBufferArrayDynamicIndexingEXT
  49. OpCapability StorageTexelBufferArrayDynamicIndexingEXT
  50. OpCapability UniformBufferArrayNonUniformIndexingEXT
  51. OpCapability SampledImageArrayNonUniformIndexingEXT
  52. OpCapability StorageBufferArrayNonUniformIndexingEXT
  53. OpCapability StorageImageArrayNonUniformIndexingEXT
  54. OpCapability InputAttachmentArrayNonUniformIndexingEXT
  55. OpCapability UniformTexelBufferArrayNonUniformIndexingEXT
  56. OpCapability StorageTexelBufferArrayNonUniformIndexingEXT
  57. OpCapability VulkanMemoryModelKHR
  58. OpCapability VulkanMemoryModelDeviceScopeKHR
  59. OpCapability PhysicalStorageBufferAddressesEXT
  60. OpCapability DemoteToHelperInvocationEXT
  61. OpCapability DotProductInputAllKHR
  62. OpCapability DotProductInput4x8BitKHR
  63. OpCapability DotProductInput4x8BitPackedKHR
  64. OpCapability DotProductKHR
  65. OpCapability ComputeDerivativeGroupQuadsKHR
  66. OpCapability ComputeDerivativeGroupLinearKHR
  67. ; CHECK: OpCapability Linkage
  68. ; CHECK-NOT: OpCapability StorageUniform16
  69. ; CHECK-NOT: OpCapability StorageUniformBufferBlock16
  70. ; CHECK-NOT: OpCapability ShaderViewportIndexLayerNV
  71. ; CHECK-NOT: OpCapability FragmentBarycentricNV
  72. ; CHECK-NOT: OpCapability ShadingRateNV
  73. ; CHECK-NOT: OpCapability ShaderNonUniformEXT
  74. ; CHECK-NOT: OpCapability RuntimeDescriptorArrayEXT
  75. ; CHECK-NOT: OpCapability InputAttachmentArrayDynamicIndexingEXT
  76. ; CHECK-NOT: OpCapability UniformTexelBufferArrayDynamicIndexingEXT
  77. ; CHECK-NOT: OpCapability StorageTexelBufferArrayDynamicIndexingEXT
  78. ; CHECK-NOT: OpCapability UniformBufferArrayNonUniformIndexingEXT
  79. ; CHECK-NOT: OpCapability SampledImageArrayNonUniformIndexingEXT
  80. ; CHECK-NOT: OpCapability StorageBufferArrayNonUniformIndexingEXT
  81. ; CHECK-NOT: OpCapability StorageImageArrayNonUniformIndexingEXT
  82. ; CHECK-NOT: OpCapability InputAttachmentArrayNonUniformIndexingEXT
  83. ; CHECK-NOT: OpCapability UniformTexelBufferArrayNonUniformIndexingEXT
  84. ; CHECK-NOT: OpCapability StorageTexelBufferArrayNonUniformIndexingEXT
  85. ; CHECK-NOT: OpCapability VulkanMemoryModelKHR
  86. ; CHECK-NOT: OpCapability VulkanMemoryModelDeviceScopeKHR
  87. ; CHECK-NOT: OpCapability PhysicalStorageBufferAddressesEXT
  88. ; CHECK-NOT: OpCapability DemoteToHelperInvocationEXT
  89. ; CHECK-NOT: OpCapability DotProductInputAllKHR
  90. ; CHECK-NOT: OpCapability DotProductInput4x8BitKHR
  91. ; CHECK-NOT: OpCapability DotProductInput4x8BitPackedKHR
  92. ; CHECK-NOT: OpCapability DotProductKHR
  93. ; CHECK-NOT: OpCapability ComputeDerivativeGroupQuadsKHR
  94. ; CHECK-NOT: OpCapability ComputeDerivativeGroupLinearKHR
  95. ; CHECK: OpCapability UniformAndStorageBuffer16BitAccess
  96. ; CHECK: OpCapability StorageBuffer16BitAccess
  97. ; CHECK: OpCapability ShaderViewportIndexLayerEXT
  98. ; CHECK: OpCapability FragmentBarycentricKHR
  99. ; CHECK: OpCapability FragmentDensityEXT
  100. ; CHECK: OpCapability ShaderNonUniform
  101. ; CHECK: OpCapability RuntimeDescriptorArray
  102. ; CHECK: OpCapability InputAttachmentArrayDynamicIndexing
  103. ; CHECK: OpCapability UniformTexelBufferArrayDynamicIndexing
  104. ; CHECK: OpCapability StorageTexelBufferArrayDynamicIndexing
  105. ; CHECK: OpCapability UniformBufferArrayNonUniformIndexing
  106. ; CHECK: OpCapability SampledImageArrayNonUniformIndexing
  107. ; CHECK: OpCapability StorageBufferArrayNonUniformIndexing
  108. ; CHECK: OpCapability StorageImageArrayNonUniformIndexing
  109. ; CHECK: OpCapability InputAttachmentArrayNonUniformIndexing
  110. ; CHECK: OpCapability UniformTexelBufferArrayNonUniformIndexing
  111. ; CHECK: OpCapability StorageTexelBufferArrayNonUniformIndexing
  112. ; CHECK: OpCapability VulkanMemoryModel
  113. ; CHECK: OpCapability VulkanMemoryModelDeviceScope
  114. ; CHECK: OpCapability PhysicalStorageBufferAddresses
  115. ; CHECK: OpCapability DemoteToHelperInvocation
  116. ; CHECK: OpCapability DotProductInputAll
  117. ; CHECK: OpCapability DotProductInput4x8Bit
  118. ; CHECK: OpCapability DotProductInput4x8BitPacked
  119. ; CHECK: OpCapability DotProduct
  120. OpMemoryModel Logical Vulkan
  121. OpEntryPoint GLCompute %1 "main"
  122. %void = OpTypeVoid
  123. %3 = OpTypeFunction %void
  124. %1 = OpFunction %void None %3
  125. %6 = OpLabel
  126. OpReturn
  127. OpFunctionEnd;
  128. )";
  129. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  130. const auto result =
  131. SinglePassRunAndMatch<EmptyPass>(kTest, /* skip_nop= */ false);
  132. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  133. }
  134. TEST_F(TrimCapabilitiesPassTest, LinkagePreventsChanges) {
  135. const std::string kTest = R"(
  136. OpCapability Linkage
  137. OpCapability ClipDistance
  138. OpCapability CullDistance
  139. OpCapability DemoteToHelperInvocation
  140. OpCapability DeviceGroup
  141. OpCapability DrawParameters
  142. OpCapability Float16
  143. OpCapability Float64
  144. OpCapability FragmentBarycentricKHR
  145. OpCapability FragmentFullyCoveredEXT
  146. OpCapability FragmentShadingRateKHR
  147. OpCapability GroupNonUniform
  148. OpCapability GroupNonUniformArithmetic
  149. OpCapability GroupNonUniformBallot
  150. OpCapability GroupNonUniformQuad
  151. OpCapability GroupNonUniformShuffle
  152. OpCapability Image1D
  153. OpCapability ImageBuffer
  154. OpCapability ImageGatherExtended
  155. OpCapability ImageMSArray
  156. OpCapability ImageQuery
  157. OpCapability InputAttachment
  158. OpCapability InputAttachmentArrayNonUniformIndexing
  159. OpCapability Int16
  160. OpCapability Int64
  161. OpCapability Int64Atomics
  162. OpCapability Int64ImageEXT
  163. OpCapability MeshShadingNV
  164. OpCapability MinLod
  165. OpCapability MultiView
  166. OpCapability MultiViewport
  167. OpCapability PhysicalStorageBufferAddresses
  168. OpCapability RayQueryKHR
  169. OpCapability RayTracingKHR
  170. OpCapability RayTracingNV
  171. OpCapability RayTraversalPrimitiveCullingKHR
  172. OpCapability RuntimeDescriptorArray
  173. OpCapability SampleMaskPostDepthCoverage
  174. OpCapability SampleRateShading
  175. OpCapability Sampled1D
  176. OpCapability SampledBuffer
  177. OpCapability SampledImageArrayNonUniformIndexing
  178. OpCapability Shader
  179. OpCapability ShaderClockKHR
  180. OpCapability ShaderLayer
  181. OpCapability ShaderNonUniform
  182. OpCapability ShaderViewportIndex
  183. OpCapability ShaderViewportIndexLayerEXT
  184. OpCapability SparseResidency
  185. OpCapability StencilExportEXT
  186. OpCapability StorageImageArrayNonUniformIndexingEXT
  187. OpCapability StorageImageExtendedFormats
  188. OpCapability StorageImageReadWithoutFormat
  189. OpCapability StorageImageWriteWithoutFormat
  190. OpCapability StorageInputOutput16
  191. OpCapability StoragePushConstant16
  192. OpCapability StorageTexelBufferArrayNonUniformIndexing
  193. OpCapability StorageUniform16
  194. OpCapability StorageUniformBufferBlock16
  195. OpCapability Tessellation
  196. OpCapability UniformTexelBufferArrayNonUniformIndexing
  197. OpCapability VulkanMemoryModel
  198. OpExtension "SPV_EXT_fragment_fully_covered"
  199. OpExtension "SPV_EXT_shader_image_int64"
  200. OpExtension "SPV_EXT_shader_stencil_export"
  201. OpExtension "SPV_EXT_shader_viewport_index_layer"
  202. OpExtension "SPV_KHR_fragment_shader_barycentric"
  203. OpExtension "SPV_KHR_fragment_shading_rate"
  204. OpExtension "SPV_KHR_post_depth_coverage"
  205. OpExtension "SPV_KHR_ray_query"
  206. OpExtension "SPV_KHR_ray_tracing"
  207. OpExtension "SPV_KHR_shader_clock"
  208. OpExtension "SPV_NV_mesh_shader"
  209. OpExtension "SPV_NV_ray_tracing"
  210. OpExtension "SPV_NV_viewport_array2"
  211. ; CHECK: OpCapability Linkage
  212. ; CHECK: OpCapability ClipDistance
  213. ; CHECK: OpCapability CullDistance
  214. ; CHECK: OpCapability DemoteToHelperInvocation
  215. ; CHECK: OpCapability DeviceGroup
  216. ; CHECK: OpCapability DrawParameters
  217. ; CHECK: OpCapability Float16
  218. ; CHECK: OpCapability Float64
  219. ; CHECK: OpCapability FragmentBarycentricKHR
  220. ; CHECK: OpCapability FragmentFullyCoveredEXT
  221. ; CHECK: OpCapability FragmentShadingRateKHR
  222. ; CHECK: OpCapability GroupNonUniform
  223. ; CHECK: OpCapability GroupNonUniformArithmetic
  224. ; CHECK: OpCapability GroupNonUniformBallot
  225. ; CHECK: OpCapability GroupNonUniformQuad
  226. ; CHECK: OpCapability GroupNonUniformShuffle
  227. ; CHECK: OpCapability Image1D
  228. ; CHECK: OpCapability ImageBuffer
  229. ; CHECK: OpCapability ImageGatherExtended
  230. ; CHECK: OpCapability ImageMSArray
  231. ; CHECK: OpCapability ImageQuery
  232. ; CHECK: OpCapability InputAttachment
  233. ; CHECK: OpCapability InputAttachmentArrayNonUniformIndexing
  234. ; CHECK: OpCapability Int16
  235. ; CHECK: OpCapability Int64
  236. ; CHECK: OpCapability Int64Atomics
  237. ; CHECK: OpCapability Int64ImageEXT
  238. ; CHECK: OpCapability MeshShadingNV
  239. ; CHECK: OpCapability MinLod
  240. ; CHECK: OpCapability MultiView
  241. ; CHECK: OpCapability MultiViewport
  242. ; CHECK: OpCapability PhysicalStorageBufferAddresses
  243. ; CHECK: OpCapability RayQueryKHR
  244. ; CHECK: OpCapability RayTracingKHR
  245. ; CHECK: OpCapability RayTracingNV
  246. ; CHECK: OpCapability RayTraversalPrimitiveCullingKHR
  247. ; CHECK: OpCapability RuntimeDescriptorArray
  248. ; CHECK: OpCapability SampleMaskPostDepthCoverage
  249. ; CHECK: OpCapability SampleRateShading
  250. ; CHECK: OpCapability Sampled1D
  251. ; CHECK: OpCapability SampledBuffer
  252. ; CHECK: OpCapability SampledImageArrayNonUniformIndexing
  253. ; CHECK: OpCapability Shader
  254. ; CHECK: OpCapability ShaderClockKHR
  255. ; CHECK: OpCapability ShaderLayer
  256. ; CHECK: OpCapability ShaderNonUniform
  257. ; CHECK: OpCapability ShaderViewportIndex
  258. ; CHECK: OpCapability ShaderViewportIndexLayerEXT
  259. ; CHECK: OpCapability SparseResidency
  260. ; CHECK: OpCapability StencilExportEXT
  261. ; CHECK: OpCapability StorageImageArrayNonUniformIndexing
  262. ; CHECK: OpCapability StorageImageExtendedFormats
  263. ; CHECK: OpCapability StorageImageReadWithoutFormat
  264. ; CHECK: OpCapability StorageImageWriteWithoutFormat
  265. ; CHECK: OpCapability StorageInputOutput16
  266. ; CHECK: OpCapability StoragePushConstant16
  267. ; CHECK: OpCapability StorageTexelBufferArrayNonUniformIndexing
  268. ; CHECK: OpCapability Tessellation
  269. ; CHECK: OpCapability UniformTexelBufferArrayNonUniformIndex
  270. ; CHECK: OpCapability VulkanMemoryModel
  271. ; CHECK: OpExtension "SPV_EXT_fragment_fully_covered"
  272. ; CHECK: OpExtension "SPV_EXT_shader_image_int64"
  273. ; CHECK: OpExtension "SPV_EXT_shader_stencil_export"
  274. ; CHECK: OpExtension "SPV_EXT_shader_viewport_index_layer"
  275. ; CHECK: OpExtension "SPV_KHR_fragment_shader_barycentric"
  276. ; CHECK: OpExtension "SPV_KHR_fragment_shading_rate"
  277. ; CHECK: OpExtension "SPV_KHR_post_depth_coverage"
  278. ; CHECK: OpExtension "SPV_KHR_ray_query"
  279. ; CHECK: OpExtension "SPV_KHR_ray_tracing"
  280. ; CHECK: OpExtension "SPV_KHR_shader_clock"
  281. ; CHECK: OpExtension "SPV_NV_mesh_shader"
  282. ; CHECK: OpExtension "SPV_NV_ray_tracing"
  283. ; CHECK: OpExtension "SPV_NV_viewport_array2"
  284. OpMemoryModel Logical Vulkan
  285. %void = OpTypeVoid
  286. %3 = OpTypeFunction %void
  287. %1 = OpFunction %void None %3
  288. %6 = OpLabel
  289. OpReturn
  290. OpFunctionEnd;
  291. )";
  292. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  293. const auto result =
  294. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  295. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  296. }
  297. TEST_F(TrimCapabilitiesPassTest, KeepShader) {
  298. const std::string kTest = R"(
  299. OpCapability Shader
  300. ; CHECK: OpCapability Shader
  301. OpMemoryModel Logical GLSL450
  302. OpEntryPoint GLCompute %1 "main"
  303. %void = OpTypeVoid
  304. %3 = OpTypeFunction %void
  305. %1 = OpFunction %void None %3
  306. %6 = OpLabel
  307. OpReturn
  308. OpFunctionEnd;
  309. )";
  310. const auto result =
  311. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  312. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  313. }
  314. TEST_F(TrimCapabilitiesPassTest, KeepShaderClockWhenInUse) {
  315. const std::string kTest = R"(
  316. OpCapability Shader
  317. OpCapability Int64
  318. OpCapability ShaderClockKHR
  319. OpExtension "SPV_KHR_shader_clock"
  320. ; CHECK: OpCapability ShaderClockKHR
  321. ; CHECK: OpExtension "SPV_KHR_shader_clock"
  322. OpMemoryModel Logical GLSL450
  323. OpEntryPoint GLCompute %1 "main"
  324. %void = OpTypeVoid
  325. %uint = OpTypeInt 32 0
  326. %ulong = OpTypeInt 64 0
  327. %scope = OpConstant %uint 1
  328. %3 = OpTypeFunction %void
  329. %1 = OpFunction %void None %3
  330. %6 = OpLabel
  331. %7 = OpReadClockKHR %ulong %scope
  332. OpReturn
  333. OpFunctionEnd;
  334. )";
  335. const auto result =
  336. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  337. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  338. }
  339. TEST_F(TrimCapabilitiesPassTest, TrimShaderClockWhenUnused) {
  340. const std::string kTest = R"(
  341. OpCapability Shader
  342. OpCapability Int64
  343. OpCapability ShaderClockKHR
  344. OpExtension "SPV_KHR_shader_clock"
  345. ; CHECK-NOT: OpCapability ShaderClockKHR
  346. ; CHECK-NOT: OpExtension "SPV_KHR_shader_clock"
  347. OpMemoryModel Logical GLSL450
  348. OpEntryPoint GLCompute %1 "main"
  349. %void = OpTypeVoid
  350. %3 = OpTypeFunction %void
  351. %1 = OpFunction %void None %3
  352. %6 = OpLabel
  353. OpReturn
  354. OpFunctionEnd;
  355. )";
  356. const auto result =
  357. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  358. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  359. }
  360. TEST_F(TrimCapabilitiesPassTest, AMDShaderBallotExtensionRemains) {
  361. const std::string kTest = R"(
  362. OpCapability Shader
  363. OpCapability Groups
  364. OpExtension "SPV_AMD_shader_ballot"
  365. ; CHECK: OpCapability Groups
  366. ; CHECK: OpExtension "SPV_AMD_shader_ballot"
  367. OpMemoryModel Logical GLSL450
  368. OpEntryPoint GLCompute %1 "main"
  369. %void = OpTypeVoid
  370. %uint = OpTypeInt 32 0
  371. %1 = OpTypeFunction %void
  372. %uint_0 = OpConstant %uint 0
  373. %2 = OpFunction %void None %1
  374. %3 = OpLabel
  375. %4 = OpGroupIAddNonUniformAMD %uint %uint_0 ExclusiveScan %uint_0
  376. OpReturn
  377. OpFunctionEnd;
  378. )";
  379. const auto result =
  380. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  381. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  382. }
  383. TEST_F(TrimCapabilitiesPassTest, AMDShaderBallotExtensionRemoved) {
  384. const std::string kTest = R"(
  385. OpCapability Shader
  386. OpCapability Groups
  387. OpExtension "SPV_AMD_shader_ballot"
  388. ; CHECK-NOT: OpCapability Groups
  389. ; CHECK-NOT: OpExtension "SPV_AMD_shader_ballot"
  390. OpMemoryModel Logical GLSL450
  391. OpEntryPoint GLCompute %1 "main"
  392. %void = OpTypeVoid
  393. %1 = OpTypeFunction %void
  394. %2 = OpFunction %void None %1
  395. %3 = OpLabel
  396. OpReturn
  397. OpFunctionEnd;
  398. )";
  399. const auto result =
  400. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  401. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  402. }
  403. TEST_F(TrimCapabilitiesPassTest, MinLod_RemovedIfNotUsed) {
  404. const std::string kTest = R"(
  405. OpCapability Shader
  406. OpCapability Sampled1D
  407. OpCapability MinLod
  408. ; CHECK-NOT: OpCapability MinLod
  409. OpMemoryModel Logical GLSL450
  410. OpEntryPoint GLCompute %1 "main"
  411. %void = OpTypeVoid
  412. %float = OpTypeFloat 32
  413. %v3float = OpTypeVector %float 3
  414. %v4float = OpTypeVector %float 4
  415. %type_image = OpTypeImage %float Cube 2 0 0 1 Rgba32f
  416. %ptr_type_image = OpTypePointer UniformConstant %type_image
  417. %type_sampler = OpTypeSampler
  418. %ptr_type_sampler = OpTypePointer UniformConstant %type_sampler
  419. %float_0 = OpConstant %float 0
  420. %float_000 = OpConstantComposite %v3float %float_0 %float_0 %float_0
  421. %image = OpVariable %ptr_type_image UniformConstant
  422. %sampler = OpVariable %ptr_type_sampler UniformConstant
  423. %1 = OpTypeFunction %void
  424. %2 = OpFunction %void None %1
  425. %3 = OpLabel
  426. %21 = OpLoad %type_image %image
  427. %22 = OpLoad %type_sampler %sampler
  428. %24 = OpSampledImage %type_sampled_image %21 %22
  429. %25 = OpImageSampleImplicitLod %v4float %24 %float_000
  430. OpReturn
  431. OpFunctionEnd;
  432. )";
  433. const auto result =
  434. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  435. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  436. }
  437. TEST_F(TrimCapabilitiesPassTest, MinLod_RemainsWithOpImageSampleImplicitLod) {
  438. const std::string kTest = R"(
  439. OpCapability Shader
  440. OpCapability Sampled1D
  441. OpCapability MinLod
  442. ; CHECK: OpCapability MinLod
  443. OpMemoryModel Logical GLSL450
  444. OpEntryPoint GLCompute %1 "main"
  445. %void = OpTypeVoid
  446. %float = OpTypeFloat 32
  447. %v3float = OpTypeVector %float 3
  448. %v4float = OpTypeVector %float 4
  449. %type_image = OpTypeImage %float Cube 2 0 0 1 Rgba32f
  450. %ptr_type_image = OpTypePointer UniformConstant %type_image
  451. %type_sampler = OpTypeSampler
  452. %ptr_type_sampler = OpTypePointer UniformConstant %type_sampler
  453. %float_0 = OpConstant %float 0
  454. %float_000 = OpConstantComposite %v3float %float_0 %float_0 %float_0
  455. %image = OpVariable %ptr_type_image UniformConstant
  456. %sampler = OpVariable %ptr_type_sampler UniformConstant
  457. %1 = OpTypeFunction %void
  458. %2 = OpFunction %void None %1
  459. %3 = OpLabel
  460. %21 = OpLoad %type_image %image
  461. %22 = OpLoad %type_sampler %sampler
  462. %24 = OpSampledImage %type_sampled_image %21 %22
  463. %25 = OpImageSampleImplicitLod %v4float %24 %float_000 MinLod %float_0
  464. OpReturn
  465. OpFunctionEnd;
  466. )";
  467. const auto result =
  468. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  469. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  470. }
  471. TEST_F(TrimCapabilitiesPassTest,
  472. MinLod_RemainsWithOpImageSparseSampleImplicitLod) {
  473. const std::string kTest = R"(
  474. OpCapability Shader
  475. OpCapability SparseResidency
  476. OpCapability ImageGatherExtended
  477. OpCapability MinLod
  478. ; CHECK: OpCapability MinLod
  479. OpMemoryModel Logical GLSL450
  480. OpEntryPoint Fragment %2 "main"
  481. OpExecutionMode %2 OriginUpperLeft
  482. %void = OpTypeVoid
  483. %uint = OpTypeInt 32 0
  484. %float = OpTypeFloat 32
  485. %v2float = OpTypeVector %float 2
  486. %v3float = OpTypeVector %float 3
  487. %v4float = OpTypeVector %float 4
  488. %type_image = OpTypeImage %float 2D 2 0 0 1 Unknown
  489. %ptr_type_image = OpTypePointer UniformConstant %type_image
  490. %type_sampler = OpTypeSampler
  491. %ptr_type_sampler = OpTypePointer UniformConstant %type_sampler
  492. %type_sampled_image = OpTypeSampledImage %type_image
  493. %sparse_struct = OpTypeStruct %uint %v4float
  494. %float_0 = OpConstant %float 0
  495. %float_00 = OpConstantComposite %v2float %float_0 %float_0
  496. %float_000 = OpConstantComposite %v3float %float_0 %float_0 %float_0
  497. %image = OpVariable %ptr_type_image UniformConstant
  498. %sampler = OpVariable %ptr_type_sampler UniformConstant
  499. %1 = OpTypeFunction %void
  500. %2 = OpFunction %void None %1
  501. %3 = OpLabel
  502. %21 = OpLoad %type_image %image
  503. %22 = OpLoad %type_sampler %sampler
  504. %24 = OpSampledImage %type_sampled_image %21 %22
  505. %25 = OpImageSparseSampleImplicitLod %sparse_struct %24 %float_00 MinLod %float_0
  506. OpReturn
  507. OpFunctionEnd;
  508. )";
  509. const auto result =
  510. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  511. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  512. }
  513. TEST_F(TrimCapabilitiesPassTest, MinLod_DetectsMinLodWithBitmaskImageOperand) {
  514. const std::string kTest = R"(
  515. OpCapability MinLod
  516. ; CHECK: OpCapability MinLod
  517. OpCapability Shader
  518. OpCapability SparseResidency
  519. OpCapability ImageGatherExtended
  520. OpMemoryModel Logical GLSL450
  521. OpEntryPoint Fragment %1 "main"
  522. OpExecutionMode %1 OriginUpperLeft
  523. %type_sampler = OpTypeSampler
  524. %int = OpTypeInt 32 1
  525. %float = OpTypeFloat 32
  526. %v2int = OpTypeVector %int 2
  527. %v2float = OpTypeVector %float 2
  528. %v4float = OpTypeVector %float 4
  529. %ptr_sampler = OpTypePointer UniformConstant %type_sampler
  530. %type_image = OpTypeImage %float 2D 2 0 0 1 Unknown
  531. %ptr_image = OpTypePointer UniformConstant %type_image
  532. %void = OpTypeVoid
  533. %uint = OpTypeInt 32 0
  534. %type_sampled_image = OpTypeSampledImage %type_image
  535. %type_struct = OpTypeStruct %uint %v4float
  536. %int_1 = OpConstant %int 1
  537. %float_0 = OpConstant %float 0
  538. %float_1 = OpConstant %float 1
  539. %8 = OpConstantComposite %v2float %float_0 %float_0
  540. %12 = OpConstantComposite %v2int %int_1 %int_1
  541. %2 = OpVariable %ptr_sampler UniformConstant
  542. %3 = OpVariable %ptr_image UniformConstant
  543. %27 = OpTypeFunction %void
  544. %1 = OpFunction %void None %27
  545. %28 = OpLabel
  546. %29 = OpLoad %type_image %3
  547. %30 = OpLoad %type_sampler %2
  548. %31 = OpSampledImage %type_sampled_image %29 %30
  549. %32 = OpImageSparseSampleImplicitLod %type_struct %31 %8 ConstOffset|MinLod %12 %float_0
  550. OpReturn
  551. OpFunctionEnd
  552. )";
  553. const auto result =
  554. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  555. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  556. }
  557. TEST_F(TrimCapabilitiesPassTest,
  558. StorageInputOutput16_RemainsWithInputPointer_Vulkan1_0) {
  559. const std::string kTest = R"(
  560. OpCapability Shader
  561. OpCapability Float16
  562. OpCapability StorageInputOutput16
  563. OpExtension "SPV_KHR_16bit_storage"
  564. ; CHECK: OpCapability StorageInputOutput16
  565. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  566. OpMemoryModel Logical GLSL450
  567. OpEntryPoint GLCompute %2 "main"
  568. %void = OpTypeVoid
  569. %half = OpTypeFloat 16
  570. %ptr = OpTypePointer Input %half
  571. %1 = OpTypeFunction %void
  572. %2 = OpFunction %void None %1
  573. %3 = OpLabel
  574. OpReturn
  575. OpFunctionEnd
  576. )";
  577. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  578. const auto result =
  579. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  580. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  581. }
  582. TEST_F(TrimCapabilitiesPassTest,
  583. StorageInputOutput16_RemainsWithInputPointer_Vulkan1_1) {
  584. const std::string kTest = R"(
  585. OpCapability Shader
  586. OpCapability Float16
  587. OpCapability StorageInputOutput16
  588. OpExtension "SPV_KHR_16bit_storage"
  589. ; CHECK: OpCapability StorageInputOutput16
  590. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  591. OpMemoryModel Logical GLSL450
  592. OpEntryPoint GLCompute %2 "main"
  593. %void = OpTypeVoid
  594. %half = OpTypeFloat 16
  595. %ptr = OpTypePointer Input %half
  596. %1 = OpTypeFunction %void
  597. %2 = OpFunction %void None %1
  598. %3 = OpLabel
  599. OpReturn
  600. OpFunctionEnd
  601. )";
  602. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  603. const auto result =
  604. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  605. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  606. }
  607. TEST_F(TrimCapabilitiesPassTest,
  608. StorageInputOutput16_RemainsWithInputPointerArray_Vulkan1_0) {
  609. const std::string kTest = R"(
  610. OpCapability Shader
  611. OpCapability Float16
  612. OpCapability StorageInputOutput16
  613. OpExtension "SPV_KHR_16bit_storage"
  614. ; CHECK: OpCapability StorageInputOutput16
  615. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  616. OpMemoryModel Logical GLSL450
  617. OpEntryPoint GLCompute %2 "main"
  618. %void = OpTypeVoid
  619. %half = OpTypeFloat 16
  620. %uint = OpTypeInt 32 0
  621. %uint_1 = OpConstant %uint 1
  622. %array = OpTypeArray %half %uint_1
  623. %ptr = OpTypePointer Input %array
  624. %1 = OpTypeFunction %void
  625. %2 = OpFunction %void None %1
  626. %3 = OpLabel
  627. OpReturn
  628. OpFunctionEnd
  629. )";
  630. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  631. const auto result =
  632. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  633. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  634. }
  635. TEST_F(TrimCapabilitiesPassTest,
  636. StorageInputOutput16_RemainsWithInputPointerArray_Vulkan1_1) {
  637. const std::string kTest = R"(
  638. OpCapability Shader
  639. OpCapability Float16
  640. OpCapability StorageInputOutput16
  641. OpExtension "SPV_KHR_16bit_storage"
  642. ; CHECK: OpCapability StorageInputOutput16
  643. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  644. OpMemoryModel Logical GLSL450
  645. OpEntryPoint GLCompute %2 "main"
  646. %void = OpTypeVoid
  647. %half = OpTypeFloat 16
  648. %uint = OpTypeInt 32 0
  649. %uint_1 = OpConstant %uint 1
  650. %array = OpTypeArray %half %uint_1
  651. %ptr = OpTypePointer Input %array
  652. %1 = OpTypeFunction %void
  653. %2 = OpFunction %void None %1
  654. %3 = OpLabel
  655. OpReturn
  656. OpFunctionEnd
  657. )";
  658. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  659. const auto result =
  660. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  661. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  662. }
  663. TEST_F(TrimCapabilitiesPassTest,
  664. StorageInputOutput16_RemainsWithInputPointerStruct_Vulkan1_0) {
  665. const std::string kTest = R"(
  666. OpCapability Shader
  667. OpCapability Float16
  668. OpCapability StorageInputOutput16
  669. OpExtension "SPV_KHR_16bit_storage"
  670. ; CHECK: OpCapability StorageInputOutput16
  671. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  672. OpMemoryModel Logical GLSL450
  673. OpEntryPoint GLCompute %2 "main"
  674. %void = OpTypeVoid
  675. %half = OpTypeFloat 16
  676. %struct = OpTypeStruct %half
  677. %ptr = OpTypePointer Input %struct
  678. %1 = OpTypeFunction %void
  679. %2 = OpFunction %void None %1
  680. %3 = OpLabel
  681. OpReturn
  682. OpFunctionEnd
  683. )";
  684. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  685. const auto result =
  686. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  687. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  688. }
  689. TEST_F(TrimCapabilitiesPassTest,
  690. StorageInputOutput16_RemainsWithInputPointerStruct_Vulkan1_1) {
  691. const std::string kTest = R"(
  692. OpCapability Shader
  693. OpCapability Float16
  694. OpCapability StorageInputOutput16
  695. OpExtension "SPV_KHR_16bit_storage"
  696. ; CHECK: OpCapability StorageInputOutput16
  697. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  698. OpMemoryModel Logical GLSL450
  699. OpEntryPoint GLCompute %2 "main"
  700. %void = OpTypeVoid
  701. %half = OpTypeFloat 16
  702. %struct = OpTypeStruct %half
  703. %ptr = OpTypePointer Input %struct
  704. %1 = OpTypeFunction %void
  705. %2 = OpFunction %void None %1
  706. %3 = OpLabel
  707. OpReturn
  708. OpFunctionEnd
  709. )";
  710. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  711. const auto result =
  712. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  713. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  714. }
  715. TEST_F(TrimCapabilitiesPassTest,
  716. StorageInputOutput16_RemainsWithInputPointerStructOfStruct_Vulkan1_0) {
  717. const std::string kTest = R"(
  718. OpCapability Shader
  719. OpCapability Float16
  720. OpCapability StorageInputOutput16
  721. OpExtension "SPV_KHR_16bit_storage"
  722. ; CHECK: OpCapability StorageInputOutput16
  723. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  724. OpMemoryModel Logical GLSL450
  725. OpEntryPoint GLCompute %2 "main"
  726. %void = OpTypeVoid
  727. %half = OpTypeFloat 16
  728. %float = OpTypeFloat 32
  729. %struct = OpTypeStruct %float %half
  730. %parent = OpTypeStruct %float %struct
  731. %ptr = OpTypePointer Input %parent
  732. %1 = OpTypeFunction %void
  733. %2 = OpFunction %void None %1
  734. %3 = OpLabel
  735. OpReturn
  736. OpFunctionEnd
  737. )";
  738. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  739. const auto result =
  740. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  741. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  742. }
  743. TEST_F(TrimCapabilitiesPassTest,
  744. StorageInputOutput16_RemainsWithInputPointerStructOfStruct_Vulkan1_1) {
  745. const std::string kTest = R"(
  746. OpCapability Shader
  747. OpCapability Float16
  748. OpCapability StorageInputOutput16
  749. OpExtension "SPV_KHR_16bit_storage"
  750. ; CHECK: OpCapability StorageInputOutput16
  751. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  752. OpMemoryModel Logical GLSL450
  753. OpEntryPoint GLCompute %2 "main"
  754. %void = OpTypeVoid
  755. %half = OpTypeFloat 16
  756. %float = OpTypeFloat 32
  757. %struct = OpTypeStruct %float %half
  758. %parent = OpTypeStruct %float %struct
  759. %ptr = OpTypePointer Input %parent
  760. %1 = OpTypeFunction %void
  761. %2 = OpFunction %void None %1
  762. %3 = OpLabel
  763. OpReturn
  764. OpFunctionEnd
  765. )";
  766. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  767. const auto result =
  768. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  769. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  770. }
  771. TEST_F(TrimCapabilitiesPassTest,
  772. StorageInputOutput16_RemainsWithInputPointerArrayOfStruct_Vulkan1_0) {
  773. const std::string kTest = R"(
  774. OpCapability Shader
  775. OpCapability Float16
  776. OpCapability StorageInputOutput16
  777. OpExtension "SPV_KHR_16bit_storage"
  778. ; CHECK: OpCapability StorageInputOutput16
  779. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  780. OpMemoryModel Logical GLSL450
  781. OpEntryPoint GLCompute %2 "main"
  782. %void = OpTypeVoid
  783. %half = OpTypeFloat 16
  784. %struct = OpTypeStruct %half
  785. %uint = OpTypeInt 32 0
  786. %uint_1 = OpConstant %uint 1
  787. %array = OpTypeArray %struct %uint_1
  788. %ptr = OpTypePointer Input %array
  789. %1 = OpTypeFunction %void
  790. %2 = OpFunction %void None %1
  791. %3 = OpLabel
  792. OpReturn
  793. OpFunctionEnd
  794. )";
  795. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  796. const auto result =
  797. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  798. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  799. }
  800. TEST_F(TrimCapabilitiesPassTest,
  801. StorageInputOutput16_RemainsWithInputPointerArrayOfStruct_Vulkan1_1) {
  802. const std::string kTest = R"(
  803. OpCapability Shader
  804. OpCapability Float16
  805. OpCapability StorageInputOutput16
  806. OpExtension "SPV_KHR_16bit_storage"
  807. ; CHECK: OpCapability StorageInputOutput16
  808. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  809. OpMemoryModel Logical GLSL450
  810. OpEntryPoint GLCompute %2 "main"
  811. %void = OpTypeVoid
  812. %half = OpTypeFloat 16
  813. %struct = OpTypeStruct %half
  814. %uint = OpTypeInt 32 0
  815. %uint_1 = OpConstant %uint 1
  816. %array = OpTypeArray %struct %uint_1
  817. %ptr = OpTypePointer Input %array
  818. %1 = OpTypeFunction %void
  819. %2 = OpFunction %void None %1
  820. %3 = OpLabel
  821. OpReturn
  822. OpFunctionEnd
  823. )";
  824. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  825. const auto result =
  826. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  827. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  828. }
  829. TEST_F(TrimCapabilitiesPassTest,
  830. StorageInputOutput16_RemainsWithInputPointerVector_Vulkan1_0) {
  831. const std::string kTest = R"(
  832. OpCapability Shader
  833. OpCapability Float16
  834. OpCapability StorageInputOutput16
  835. OpExtension "SPV_KHR_16bit_storage"
  836. ; CHECK: OpCapability StorageInputOutput16
  837. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  838. OpMemoryModel Logical GLSL450
  839. OpEntryPoint GLCompute %2 "main"
  840. %void = OpTypeVoid
  841. %half = OpTypeFloat 16
  842. %vector = OpTypeVector %half 4
  843. %ptr = OpTypePointer Input %vector
  844. %1 = OpTypeFunction %void
  845. %2 = OpFunction %void None %1
  846. %3 = OpLabel
  847. OpReturn
  848. OpFunctionEnd
  849. )";
  850. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  851. const auto result =
  852. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  853. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  854. }
  855. TEST_F(TrimCapabilitiesPassTest,
  856. StorageInputOutput16_RemainsWithInputPointerVector_Vulkan1_1) {
  857. const std::string kTest = R"(
  858. OpCapability Shader
  859. OpCapability Float16
  860. OpCapability StorageInputOutput16
  861. OpExtension "SPV_KHR_16bit_storage"
  862. ; CHECK: OpCapability StorageInputOutput16
  863. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  864. OpMemoryModel Logical GLSL450
  865. OpEntryPoint GLCompute %2 "main"
  866. %void = OpTypeVoid
  867. %half = OpTypeFloat 16
  868. %vector = OpTypeVector %half 4
  869. %ptr = OpTypePointer Input %vector
  870. %1 = OpTypeFunction %void
  871. %2 = OpFunction %void None %1
  872. %3 = OpLabel
  873. OpReturn
  874. OpFunctionEnd
  875. )";
  876. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  877. const auto result =
  878. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  879. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  880. }
  881. TEST_F(TrimCapabilitiesPassTest,
  882. StorageInputOutput16_RemainsWithInputPointerMatrix_Vulkan1_0) {
  883. const std::string kTest = R"(
  884. OpCapability Shader
  885. OpCapability Float16
  886. OpCapability StorageInputOutput16
  887. OpExtension "SPV_KHR_16bit_storage"
  888. ; CHECK: OpCapability StorageInputOutput16
  889. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  890. OpMemoryModel Logical GLSL450
  891. OpEntryPoint GLCompute %2 "main"
  892. %void = OpTypeVoid
  893. %half = OpTypeFloat 16
  894. %vector = OpTypeVector %half 4
  895. %matrix = OpTypeMatrix %vector 4
  896. %ptr = OpTypePointer Input %matrix
  897. %1 = OpTypeFunction %void
  898. %2 = OpFunction %void None %1
  899. %3 = OpLabel
  900. OpReturn
  901. OpFunctionEnd
  902. )";
  903. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  904. const auto result =
  905. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  906. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  907. }
  908. TEST_F(TrimCapabilitiesPassTest,
  909. StorageInputOutput16_RemainsWithInputPointerMatrix_Vulkan1_1) {
  910. const std::string kTest = R"(
  911. OpCapability Shader
  912. OpCapability Float16
  913. OpCapability StorageInputOutput16
  914. OpExtension "SPV_KHR_16bit_storage"
  915. ; CHECK: OpCapability StorageInputOutput16
  916. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  917. OpMemoryModel Logical GLSL450
  918. OpEntryPoint GLCompute %2 "main"
  919. %void = OpTypeVoid
  920. %half = OpTypeFloat 16
  921. %vector = OpTypeVector %half 4
  922. %matrix = OpTypeMatrix %vector 4
  923. %ptr = OpTypePointer Input %matrix
  924. %1 = OpTypeFunction %void
  925. %2 = OpFunction %void None %1
  926. %3 = OpLabel
  927. OpReturn
  928. OpFunctionEnd
  929. )";
  930. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  931. const auto result =
  932. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  933. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  934. }
  935. TEST_F(TrimCapabilitiesPassTest,
  936. StorageInputOutput16_IsRemovedWithoutInputPointer) {
  937. const std::string kTest = R"(
  938. OpCapability Shader
  939. OpCapability Float16
  940. OpCapability StorageInputOutput16
  941. OpExtension "SPV_KHR_16bit_storage"
  942. ; CHECK-NOT: OpCapability StorageInputOutput16
  943. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  944. OpMemoryModel Logical GLSL450
  945. OpEntryPoint GLCompute %2 "main"
  946. %void = OpTypeVoid
  947. %1 = OpTypeFunction %void
  948. %2 = OpFunction %void None %1
  949. %3 = OpLabel
  950. OpReturn
  951. OpFunctionEnd
  952. )";
  953. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  954. const auto result =
  955. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  956. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  957. }
  958. TEST_F(TrimCapabilitiesPassTest,
  959. StorageInputOutput16_RemainsWithOutputPointer_Vulkan1_0) {
  960. const std::string kTest = R"(
  961. OpCapability Shader
  962. OpCapability Float16
  963. OpCapability StorageInputOutput16
  964. OpExtension "SPV_KHR_16bit_storage"
  965. ; CHECK: OpCapability StorageInputOutput16
  966. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  967. OpMemoryModel Logical GLSL450
  968. OpEntryPoint GLCompute %2 "main"
  969. %void = OpTypeVoid
  970. %half = OpTypeFloat 16
  971. %ptr = OpTypePointer Output %half
  972. %1 = OpTypeFunction %void
  973. %2 = OpFunction %void None %1
  974. %3 = OpLabel
  975. OpReturn
  976. OpFunctionEnd
  977. )";
  978. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  979. const auto result =
  980. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  981. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  982. }
  983. TEST_F(TrimCapabilitiesPassTest,
  984. StorageInputOutput16_RemainsWithOutputPointer_Vulkan1_1) {
  985. const std::string kTest = R"(
  986. OpCapability Shader
  987. OpCapability Float16
  988. OpCapability StorageInputOutput16
  989. OpExtension "SPV_KHR_16bit_storage"
  990. ; CHECK: OpCapability StorageInputOutput16
  991. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  992. OpMemoryModel Logical GLSL450
  993. OpEntryPoint GLCompute %2 "main"
  994. %void = OpTypeVoid
  995. %half = OpTypeFloat 16
  996. %ptr = OpTypePointer Output %half
  997. %1 = OpTypeFunction %void
  998. %2 = OpFunction %void None %1
  999. %3 = OpLabel
  1000. OpReturn
  1001. OpFunctionEnd
  1002. )";
  1003. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1004. const auto result =
  1005. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1006. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1007. }
  1008. TEST_F(TrimCapabilitiesPassTest,
  1009. StorageInputOutput16_RemovedWithoutOutputPointer) {
  1010. const std::string kTest = R"(
  1011. OpCapability Shader
  1012. OpCapability Float16
  1013. OpCapability StorageInputOutput16
  1014. OpExtension "SPV_KHR_16bit_storage"
  1015. ; CHECK-NOT: OpCapability StorageInputOutput16
  1016. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1017. OpMemoryModel Logical GLSL450
  1018. OpEntryPoint GLCompute %2 "main"
  1019. %void = OpTypeVoid
  1020. %1 = OpTypeFunction %void
  1021. %2 = OpFunction %void None %1
  1022. %3 = OpLabel
  1023. OpReturn
  1024. OpFunctionEnd
  1025. )";
  1026. const auto result =
  1027. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1028. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1029. }
  1030. TEST_F(TrimCapabilitiesPassTest,
  1031. StoragePushConstant16_RemainsSimplePointer_Vulkan1_0) {
  1032. const std::string kTest = R"(
  1033. OpCapability Shader
  1034. OpCapability Float16
  1035. OpCapability StoragePushConstant16
  1036. OpExtension "SPV_KHR_16bit_storage"
  1037. ; CHECK: OpCapability StoragePushConstant16
  1038. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  1039. OpMemoryModel Logical GLSL450
  1040. OpEntryPoint GLCompute %2 "main"
  1041. %void = OpTypeVoid
  1042. %half = OpTypeFloat 16
  1043. %ptr = OpTypePointer PushConstant %half
  1044. %1 = OpTypeFunction %void
  1045. %2 = OpFunction %void None %1
  1046. %3 = OpLabel
  1047. OpReturn
  1048. OpFunctionEnd
  1049. )";
  1050. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  1051. const auto result =
  1052. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1053. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1054. }
  1055. TEST_F(TrimCapabilitiesPassTest,
  1056. StoragePushConstant16_RemainsSimplePointer_Vulkan1_1) {
  1057. const std::string kTest = R"(
  1058. OpCapability Shader
  1059. OpCapability Float16
  1060. OpCapability StoragePushConstant16
  1061. OpExtension "SPV_KHR_16bit_storage"
  1062. ; CHECK: OpCapability StoragePushConstant16
  1063. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1064. OpMemoryModel Logical GLSL450
  1065. OpEntryPoint GLCompute %2 "main"
  1066. %void = OpTypeVoid
  1067. %half = OpTypeFloat 16
  1068. %ptr = OpTypePointer PushConstant %half
  1069. %1 = OpTypeFunction %void
  1070. %2 = OpFunction %void None %1
  1071. %3 = OpLabel
  1072. OpReturn
  1073. OpFunctionEnd
  1074. )";
  1075. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1076. const auto result =
  1077. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1078. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1079. }
  1080. TEST_F(TrimCapabilitiesPassTest, StoragePushConstant16_RemovedSimplePointer) {
  1081. const std::string kTest = R"(
  1082. OpCapability Shader
  1083. OpCapability Float16
  1084. OpCapability StoragePushConstant16
  1085. OpExtension "SPV_KHR_16bit_storage"
  1086. ; CHECK-NOT: OpCapability StoragePushConstant16
  1087. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1088. OpMemoryModel Logical GLSL450
  1089. OpEntryPoint GLCompute %2 "main"
  1090. %void = OpTypeVoid
  1091. %half = OpTypeFloat 16
  1092. %ptr = OpTypePointer Function %half
  1093. %1 = OpTypeFunction %void
  1094. %2 = OpFunction %void None %1
  1095. %3 = OpLabel
  1096. OpReturn
  1097. OpFunctionEnd
  1098. )";
  1099. const auto result =
  1100. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1101. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1102. }
  1103. TEST_F(TrimCapabilitiesPassTest,
  1104. StorageUniformBufferBlock16_RemainsSimplePointer_Vulkan1_0) {
  1105. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1106. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1107. spv::Capability::StorageBuffer16BitAccess);
  1108. const std::string kTest = R"(
  1109. OpCapability Shader
  1110. OpCapability Float16
  1111. OpCapability StorageBuffer16BitAccess
  1112. OpExtension "SPV_KHR_16bit_storage"
  1113. ; CHECK: OpCapability StorageBuffer16BitAccess
  1114. ; `-> StorageUniformBufferBlock16
  1115. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  1116. OpMemoryModel Logical GLSL450
  1117. OpEntryPoint GLCompute %2 "main"
  1118. OpDecorate %struct BufferBlock
  1119. %void = OpTypeVoid
  1120. %half = OpTypeFloat 16
  1121. %struct = OpTypeStruct %half
  1122. %ptr = OpTypePointer Uniform %struct
  1123. %1 = OpTypeFunction %void
  1124. %2 = OpFunction %void None %1
  1125. %3 = OpLabel
  1126. OpReturn
  1127. OpFunctionEnd
  1128. )";
  1129. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  1130. const auto result =
  1131. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1132. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1133. }
  1134. TEST_F(TrimCapabilitiesPassTest,
  1135. StorageUniformBufferBlock16_RemainsSimplePointer_Vulkan1_1) {
  1136. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1137. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1138. spv::Capability::StorageBuffer16BitAccess);
  1139. const std::string kTest = R"(
  1140. OpCapability Shader
  1141. OpCapability Float16
  1142. OpCapability StorageBuffer16BitAccess
  1143. OpExtension "SPV_KHR_16bit_storage"
  1144. ; CHECK: OpCapability StorageBuffer16BitAccess
  1145. ; `-> StorageUniformBufferBlock16
  1146. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1147. OpMemoryModel Logical GLSL450
  1148. OpEntryPoint GLCompute %2 "main"
  1149. OpDecorate %struct BufferBlock
  1150. %void = OpTypeVoid
  1151. %half = OpTypeFloat 16
  1152. %struct = OpTypeStruct %half
  1153. %ptr = OpTypePointer Uniform %struct
  1154. %1 = OpTypeFunction %void
  1155. %2 = OpFunction %void None %1
  1156. %3 = OpLabel
  1157. OpReturn
  1158. OpFunctionEnd
  1159. )";
  1160. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1161. const auto result =
  1162. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1163. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1164. }
  1165. TEST_F(TrimCapabilitiesPassTest,
  1166. StorageUniformBufferBlock16_RemovedSimplePointer) {
  1167. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1168. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1169. spv::Capability::StorageBuffer16BitAccess);
  1170. const std::string kTest = R"(
  1171. OpCapability Shader
  1172. OpCapability Float16
  1173. OpCapability StorageBuffer16BitAccess
  1174. OpExtension "SPV_KHR_16bit_storage"
  1175. ; CHECK-NOT: OpCapability StorageBuffer16BitAccess
  1176. ; `-> StorageUniformBufferBlock16
  1177. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1178. OpMemoryModel Logical GLSL450
  1179. OpEntryPoint GLCompute %2 "main"
  1180. %void = OpTypeVoid
  1181. %half = OpTypeFloat 16
  1182. %struct = OpTypeStruct %half
  1183. %ptr = OpTypePointer Function %struct
  1184. %1 = OpTypeFunction %void
  1185. %2 = OpFunction %void None %1
  1186. %3 = OpLabel
  1187. OpReturn
  1188. OpFunctionEnd
  1189. )";
  1190. const auto result =
  1191. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1192. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1193. }
  1194. TEST_F(TrimCapabilitiesPassTest,
  1195. StorageUniform16_RemovedWithBufferBlockPointer_Vulkan1_0) {
  1196. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1197. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1198. spv::Capability::StorageBuffer16BitAccess);
  1199. static_assert(spv::Capability::StorageUniform16 ==
  1200. spv::Capability::UniformAndStorageBuffer16BitAccess);
  1201. const std::string kTest = R"(
  1202. OpCapability Shader
  1203. OpCapability Float16
  1204. OpCapability StorageBuffer16BitAccess
  1205. OpCapability UniformAndStorageBuffer16BitAccess
  1206. OpExtension "SPV_KHR_16bit_storage"
  1207. ; CHECK: OpCapability StorageBuffer16BitAccess
  1208. ; `-> StorageUniformBufferBlock16
  1209. ; CHECK-NOT: OpCapability UniformAndStorageBuffer16BitAccess
  1210. ; `-> StorageUniform16
  1211. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  1212. OpMemoryModel Logical GLSL450
  1213. OpEntryPoint GLCompute %2 "main"
  1214. OpDecorate %struct BufferBlock
  1215. %void = OpTypeVoid
  1216. %half = OpTypeFloat 16
  1217. %struct = OpTypeStruct %half
  1218. %ptr = OpTypePointer Uniform %struct
  1219. %1 = OpTypeFunction %void
  1220. %2 = OpFunction %void None %1
  1221. %3 = OpLabel
  1222. OpReturn
  1223. OpFunctionEnd
  1224. )";
  1225. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  1226. const auto result =
  1227. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1228. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1229. }
  1230. TEST_F(TrimCapabilitiesPassTest,
  1231. StorageUniform16_RemovedWithBufferBlockPointer_Vulkan1_1) {
  1232. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1233. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1234. spv::Capability::StorageBuffer16BitAccess);
  1235. static_assert(spv::Capability::StorageUniform16 ==
  1236. spv::Capability::UniformAndStorageBuffer16BitAccess);
  1237. const std::string kTest = R"(
  1238. OpCapability Shader
  1239. OpCapability Float16
  1240. OpCapability StorageBuffer16BitAccess
  1241. OpCapability UniformAndStorageBuffer16BitAccess
  1242. OpExtension "SPV_KHR_16bit_storage"
  1243. ; CHECK: OpCapability StorageBuffer16BitAccess
  1244. ; `-> StorageUniformBufferBlock16
  1245. ; CHECK-NOT: OpCapability UniformAndStorageBuffer16BitAccess
  1246. ; `-> StorageUniform16
  1247. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1248. OpMemoryModel Logical GLSL450
  1249. OpEntryPoint GLCompute %2 "main"
  1250. OpDecorate %struct BufferBlock
  1251. %void = OpTypeVoid
  1252. %half = OpTypeFloat 16
  1253. %struct = OpTypeStruct %half
  1254. %ptr = OpTypePointer Uniform %struct
  1255. %1 = OpTypeFunction %void
  1256. %2 = OpFunction %void None %1
  1257. %3 = OpLabel
  1258. OpReturn
  1259. OpFunctionEnd
  1260. )";
  1261. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1262. const auto result =
  1263. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1264. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1265. }
  1266. TEST_F(TrimCapabilitiesPassTest,
  1267. StorageUniform16_RemovedWithNonBlockUniformPointer_Vulkan1_0) {
  1268. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1269. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1270. spv::Capability::StorageBuffer16BitAccess);
  1271. static_assert(spv::Capability::StorageUniform16 ==
  1272. spv::Capability::UniformAndStorageBuffer16BitAccess);
  1273. const std::string kTest = R"(
  1274. OpCapability Shader
  1275. OpCapability Float16
  1276. OpCapability StorageBuffer16BitAccess
  1277. OpCapability UniformAndStorageBuffer16BitAccess
  1278. OpExtension "SPV_KHR_16bit_storage"
  1279. ; CHECK-NOT: OpCapability StorageBuffer16BitAccess
  1280. ; `-> StorageUniformBufferBlock16
  1281. ; CHECK: OpCapability UniformAndStorageBuffer16BitAccess
  1282. ; `-> StorageUniform16
  1283. ; CHECK: OpExtension "SPV_KHR_16bit_storage"
  1284. OpMemoryModel Logical GLSL450
  1285. OpEntryPoint GLCompute %2 "main"
  1286. %void = OpTypeVoid
  1287. %half = OpTypeFloat 16
  1288. %struct = OpTypeStruct %half
  1289. %ptr = OpTypePointer Uniform %struct
  1290. %1 = OpTypeFunction %void
  1291. %2 = OpFunction %void None %1
  1292. %3 = OpLabel
  1293. OpReturn
  1294. OpFunctionEnd
  1295. )";
  1296. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  1297. const auto result =
  1298. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1299. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1300. }
  1301. TEST_F(TrimCapabilitiesPassTest,
  1302. StorageUniform16_RemovedWithNonBlockUniformPointer_Vulkan1_1) {
  1303. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1304. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1305. spv::Capability::StorageBuffer16BitAccess);
  1306. static_assert(spv::Capability::StorageUniform16 ==
  1307. spv::Capability::UniformAndStorageBuffer16BitAccess);
  1308. const std::string kTest = R"(
  1309. OpCapability Shader
  1310. OpCapability Float16
  1311. OpCapability StorageBuffer16BitAccess
  1312. OpCapability UniformAndStorageBuffer16BitAccess
  1313. OpExtension "SPV_KHR_16bit_storage"
  1314. ; CHECK-NOT: OpCapability StorageBuffer16BitAccess
  1315. ; `-> StorageUniformBufferBlock16
  1316. ; CHECK: OpCapability UniformAndStorageBuffer16BitAccess
  1317. ; `-> StorageUniform16
  1318. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1319. OpMemoryModel Logical GLSL450
  1320. OpEntryPoint GLCompute %2 "main"
  1321. %void = OpTypeVoid
  1322. %half = OpTypeFloat 16
  1323. %struct = OpTypeStruct %half
  1324. %ptr = OpTypePointer Uniform %struct
  1325. %1 = OpTypeFunction %void
  1326. %2 = OpFunction %void None %1
  1327. %3 = OpLabel
  1328. OpReturn
  1329. OpFunctionEnd
  1330. )";
  1331. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1332. const auto result =
  1333. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1334. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1335. }
  1336. TEST_F(TrimCapabilitiesPassTest,
  1337. StorageBuffer16BitAccess_RemainsSimplePointer_Vulkan1_0) {
  1338. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1339. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1340. spv::Capability::StorageBuffer16BitAccess);
  1341. const std::string kTest = R"(
  1342. OpCapability Shader
  1343. OpCapability Float16
  1344. OpCapability StorageBuffer16BitAccess
  1345. ; CHECK: OpCapability StorageBuffer16BitAccess
  1346. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1347. OpMemoryModel Logical GLSL450
  1348. OpEntryPoint GLCompute %2 "main"
  1349. OpDecorate %struct Block
  1350. %void = OpTypeVoid
  1351. %half = OpTypeFloat 16
  1352. %struct = OpTypeStruct %half
  1353. %ptr = OpTypePointer StorageBuffer %struct
  1354. %1 = OpTypeFunction %void
  1355. %2 = OpFunction %void None %1
  1356. %3 = OpLabel
  1357. OpReturn
  1358. OpFunctionEnd
  1359. )";
  1360. SetTargetEnv(SPV_ENV_VULKAN_1_0);
  1361. const auto result =
  1362. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1363. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1364. }
  1365. TEST_F(TrimCapabilitiesPassTest,
  1366. StorageBuffer16BitAccess_RemainsSimplePointer_Vulkan1_1) {
  1367. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1368. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1369. spv::Capability::StorageBuffer16BitAccess);
  1370. const std::string kTest = R"(
  1371. OpCapability Shader
  1372. OpCapability Float16
  1373. OpCapability StorageBuffer16BitAccess
  1374. ; CHECK: OpCapability StorageBuffer16BitAccess
  1375. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1376. OpMemoryModel Logical GLSL450
  1377. OpEntryPoint GLCompute %2 "main"
  1378. OpDecorate %struct Block
  1379. %void = OpTypeVoid
  1380. %half = OpTypeFloat 16
  1381. %struct = OpTypeStruct %half
  1382. %ptr = OpTypePointer StorageBuffer %struct
  1383. %1 = OpTypeFunction %void
  1384. %2 = OpFunction %void None %1
  1385. %3 = OpLabel
  1386. OpReturn
  1387. OpFunctionEnd
  1388. )";
  1389. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1390. const auto result =
  1391. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1392. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1393. }
  1394. TEST_F(
  1395. TrimCapabilitiesPassTest,
  1396. StorageBuffer16BitAccess_RemainsSimplePointerUshortPhysicalStorage_Vulkan1_1) {
  1397. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1398. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1399. spv::Capability::StorageBuffer16BitAccess);
  1400. const std::string kTest = R"(
  1401. OpCapability Shader
  1402. OpCapability StorageBuffer16BitAccess
  1403. OpCapability PhysicalStorageBufferAddresses
  1404. ; CHECK: OpCapability StorageBuffer16BitAccess
  1405. ; CHECK: OpCapability PhysicalStorageBufferAddresses
  1406. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1407. ; CHECK-NOT: OpCapability Int16
  1408. OpMemoryModel Logical GLSL450
  1409. OpEntryPoint GLCompute %2 "main"
  1410. OpDecorate %struct Block
  1411. %void = OpTypeVoid
  1412. %ushort = OpTypeInt 16 0
  1413. %struct = OpTypeStruct %ushort
  1414. %ptr = OpTypePointer PhysicalStorageBuffer %struct
  1415. %1 = OpTypeFunction %void
  1416. %2 = OpFunction %void None %1
  1417. %3 = OpLabel
  1418. OpReturn
  1419. OpFunctionEnd
  1420. )";
  1421. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1422. const auto result =
  1423. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1424. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1425. }
  1426. TEST_F(
  1427. TrimCapabilitiesPassTest,
  1428. StorageBuffer16BitAccess_RemainsSimplePointerUshortStorageBuffer_Vulkan1_1) {
  1429. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1430. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1431. spv::Capability::StorageBuffer16BitAccess);
  1432. const std::string kTest = R"(
  1433. OpCapability Shader
  1434. OpCapability StorageBuffer16BitAccess
  1435. ; CHECK: OpCapability StorageBuffer16BitAccess
  1436. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1437. ; CHECK-NOT: OpCapability Int16
  1438. OpMemoryModel Logical GLSL450
  1439. OpEntryPoint GLCompute %2 "main"
  1440. OpDecorate %struct Block
  1441. %void = OpTypeVoid
  1442. %ushort = OpTypeInt 16 0
  1443. %struct = OpTypeStruct %ushort
  1444. %ptr = OpTypePointer StorageBuffer %struct
  1445. %1 = OpTypeFunction %void
  1446. %2 = OpFunction %void None %1
  1447. %3 = OpLabel
  1448. OpReturn
  1449. OpFunctionEnd
  1450. )";
  1451. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1452. const auto result =
  1453. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1454. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1455. }
  1456. TEST_F(
  1457. TrimCapabilitiesPassTest,
  1458. StorageBuffer16BitAccess_RemainsSimplePointerUshortRecordBuffer_Vulkan1_1) {
  1459. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1460. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1461. spv::Capability::StorageBuffer16BitAccess);
  1462. const std::string kTest = R"(
  1463. OpCapability Shader
  1464. OpCapability RayTracingKHR
  1465. OpCapability StorageBuffer16BitAccess
  1466. OpExtension "SPV_KHR_ray_tracing"
  1467. ; CHECK-NOT: OpCapability Int16
  1468. ; CHECK: OpCapability RayTracingKHR
  1469. ; CHECK: OpCapability StorageBuffer16BitAccess
  1470. ; CHECK: OpExtension "SPV_KHR_ray_tracing"
  1471. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1472. OpMemoryModel Logical GLSL450
  1473. OpEntryPoint GLCompute %2 "main"
  1474. OpDecorate %struct Block
  1475. %void = OpTypeVoid
  1476. %ushort = OpTypeInt 16 0
  1477. %struct = OpTypeStruct %ushort
  1478. %ptr = OpTypePointer ShaderRecordBufferKHR %struct
  1479. %1 = OpTypeFunction %void
  1480. %2 = OpFunction %void None %1
  1481. %3 = OpLabel
  1482. OpReturn
  1483. OpFunctionEnd
  1484. )";
  1485. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1486. const auto result =
  1487. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1488. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1489. }
  1490. TEST_F(TrimCapabilitiesPassTest,
  1491. StorageBuffer16BitAccess_TrimRecordBuffer_Vulkan1_1) {
  1492. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1493. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1494. spv::Capability::StorageBuffer16BitAccess);
  1495. const std::string kTest = R"(
  1496. OpCapability Shader
  1497. OpCapability RayTracingKHR
  1498. OpCapability StorageBuffer16BitAccess
  1499. OpExtension "SPV_KHR_ray_tracing"
  1500. ; CHECK-NOT: OpCapability RayTracingKHR
  1501. ; CHECK-NOT: OpCapability StorageBuffer16BitAccess
  1502. ; CHECK-NOT: OpExtension "SPV_KHR_ray_tracing"
  1503. OpMemoryModel Logical GLSL450
  1504. OpEntryPoint GLCompute %2 "main"
  1505. OpDecorate %struct Block
  1506. %void = OpTypeVoid
  1507. %1 = OpTypeFunction %void
  1508. %2 = OpFunction %void None %1
  1509. %3 = OpLabel
  1510. OpReturn
  1511. OpFunctionEnd
  1512. )";
  1513. SetTargetEnv(SPV_ENV_VULKAN_1_1);
  1514. const auto result =
  1515. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1516. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1517. }
  1518. TEST_F(TrimCapabilitiesPassTest,
  1519. StorageBuffer16BitAccess_RemovedSimplePointer) {
  1520. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
  1521. static_assert(spv::Capability::StorageUniformBufferBlock16 ==
  1522. spv::Capability::StorageBuffer16BitAccess);
  1523. const std::string kTest = R"(
  1524. OpCapability Shader
  1525. OpCapability Float16
  1526. OpCapability StorageBuffer16BitAccess
  1527. OpExtension "SPV_KHR_16bit_storage"
  1528. ; CHECK-NOT: OpCapability StorageBuffer16BitAccess
  1529. ; CHECK-NOT: OpExtension "SPV_KHR_16bit_storage"
  1530. OpMemoryModel Logical GLSL450
  1531. OpEntryPoint GLCompute %2 "main"
  1532. %void = OpTypeVoid
  1533. %half = OpTypeFloat 16
  1534. %struct = OpTypeStruct %half
  1535. %ptr = OpTypePointer Function %struct
  1536. %1 = OpTypeFunction %void
  1537. %2 = OpFunction %void None %1
  1538. %3 = OpLabel
  1539. OpReturn
  1540. OpFunctionEnd
  1541. )";
  1542. const auto result =
  1543. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1544. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1545. }
  1546. TEST_F(TrimCapabilitiesPassTest, FragmentShaderInterlock_RemovedIfNotUsed) {
  1547. const std::string kTest = R"(
  1548. OpCapability Shader
  1549. OpCapability FragmentShaderPixelInterlockEXT
  1550. OpCapability FragmentShaderSampleInterlockEXT
  1551. OpCapability FragmentShaderShadingRateInterlockEXT
  1552. OpExtension "SPV_EXT_fragment_shader_interlock"
  1553. ; CHECK-NOT: OpCapability FragmentShaderPixelInterlockEXT
  1554. ; CHECK-NOT: OpCapability FragmentShaderSampleInterlockEXT
  1555. ; CHECK-NOT: OpCapability FragmentShaderShadingRateInterlockEXT
  1556. ; CHECK-NOT: OpExtension "SPV_EXT_fragment_shader_interlock"
  1557. OpMemoryModel Logical GLSL450
  1558. OpEntryPoint GLCompute %1 "main"
  1559. %void = OpTypeVoid
  1560. %1 = OpTypeFunction %void
  1561. %2 = OpFunction %void None %1
  1562. %3 = OpLabel
  1563. OpReturn
  1564. OpFunctionEnd;
  1565. )";
  1566. const auto result =
  1567. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1568. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1569. }
  1570. TEST_F(TrimCapabilitiesPassTest,
  1571. FragmentShaderPixelInterlock_RemainsWhenOrderedIsUsed) {
  1572. const std::string kTest = R"(
  1573. OpCapability Shader
  1574. OpCapability FragmentShaderPixelInterlockEXT
  1575. OpCapability FragmentShaderSampleInterlockEXT
  1576. OpCapability FragmentShaderShadingRateInterlockEXT
  1577. OpExtension "SPV_EXT_fragment_shader_interlock"
  1578. ; CHECK: OpCapability FragmentShaderPixelInterlockEXT
  1579. ; CHECK-NOT: OpCapability FragmentShaderSampleInterlockEXT
  1580. ; CHECK-NOT: OpCapability FragmentShaderShadingRateInterlockEXT
  1581. ; CHECK: OpExtension "SPV_EXT_fragment_shader_interlock"
  1582. OpMemoryModel Logical GLSL450
  1583. OpEntryPoint GLCompute %1 "main"
  1584. OpExecutionMode %main PixelInterlockOrderedEXT
  1585. %void = OpTypeVoid
  1586. %1 = OpTypeFunction %void
  1587. %2 = OpFunction %void None %1
  1588. %3 = OpLabel
  1589. OpBeginInvocationInterlockEXT
  1590. OpEndInvocationInterlockEXT
  1591. OpReturn
  1592. OpFunctionEnd;
  1593. )";
  1594. const auto result =
  1595. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1596. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1597. }
  1598. TEST_F(TrimCapabilitiesPassTest,
  1599. FragmentShaderPixelInterlock_RemainsWhenUnorderedIsUsed) {
  1600. const std::string kTest = R"(
  1601. OpCapability Shader
  1602. OpCapability FragmentShaderPixelInterlockEXT
  1603. OpCapability FragmentShaderSampleInterlockEXT
  1604. OpCapability FragmentShaderShadingRateInterlockEXT
  1605. OpExtension "SPV_EXT_fragment_shader_interlock"
  1606. ; CHECK: OpCapability FragmentShaderPixelInterlockEXT
  1607. ; CHECK-NOT: OpCapability FragmentShaderSampleInterlockEXT
  1608. ; CHECK-NOT: OpCapability FragmentShaderShadingRateInterlockEXT
  1609. ; CHECK: OpExtension "SPV_EXT_fragment_shader_interlock"
  1610. OpMemoryModel Logical GLSL450
  1611. OpEntryPoint GLCompute %1 "main"
  1612. OpExecutionMode %main PixelInterlockUnorderedEXT
  1613. %void = OpTypeVoid
  1614. %1 = OpTypeFunction %void
  1615. %2 = OpFunction %void None %1
  1616. %3 = OpLabel
  1617. OpBeginInvocationInterlockEXT
  1618. OpEndInvocationInterlockEXT
  1619. OpReturn
  1620. OpFunctionEnd;
  1621. )";
  1622. const auto result =
  1623. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1624. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1625. }
  1626. TEST_F(TrimCapabilitiesPassTest,
  1627. FragmentShaderSampleInterlock_RemainsWhenOrderedIsUsed) {
  1628. const std::string kTest = R"(
  1629. OpCapability Shader
  1630. OpCapability FragmentShaderPixelInterlockEXT
  1631. OpCapability FragmentShaderSampleInterlockEXT
  1632. OpCapability FragmentShaderShadingRateInterlockEXT
  1633. OpExtension "SPV_EXT_fragment_shader_interlock"
  1634. ; CHECK-NOT: OpCapability FragmentShaderPixelInterlockEXT
  1635. ; CHECK: OpCapability FragmentShaderSampleInterlockEXT
  1636. ; CHECK-NOT: OpCapability FragmentShaderShadingRateInterlockEXT
  1637. ; CHECK: OpExtension "SPV_EXT_fragment_shader_interlock"
  1638. OpMemoryModel Logical GLSL450
  1639. OpEntryPoint GLCompute %1 "main"
  1640. OpExecutionMode %main SampleInterlockOrderedEXT
  1641. %void = OpTypeVoid
  1642. %1 = OpTypeFunction %void
  1643. %2 = OpFunction %void None %1
  1644. %3 = OpLabel
  1645. OpBeginInvocationInterlockEXT
  1646. OpEndInvocationInterlockEXT
  1647. OpReturn
  1648. OpFunctionEnd;
  1649. )";
  1650. const auto result =
  1651. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1652. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1653. }
  1654. TEST_F(TrimCapabilitiesPassTest,
  1655. FragmentShaderSampleInterlock_RemainsWhenUnorderedIsUsed) {
  1656. const std::string kTest = R"(
  1657. OpCapability Shader
  1658. OpCapability FragmentShaderPixelInterlockEXT
  1659. OpCapability FragmentShaderSampleInterlockEXT
  1660. OpCapability FragmentShaderShadingRateInterlockEXT
  1661. OpExtension "SPV_EXT_fragment_shader_interlock"
  1662. ; CHECK-NOT: OpCapability FragmentShaderPixelInterlockEXT
  1663. ; CHECK: OpCapability FragmentShaderSampleInterlockEXT
  1664. ; CHECK-NOT: OpCapability FragmentShaderShadingRateInterlockEXT
  1665. ; CHECK: OpExtension "SPV_EXT_fragment_shader_interlock"
  1666. OpMemoryModel Logical GLSL450
  1667. OpEntryPoint GLCompute %1 "main"
  1668. OpExecutionMode %main SampleInterlockUnorderedEXT
  1669. %void = OpTypeVoid
  1670. %1 = OpTypeFunction %void
  1671. %2 = OpFunction %void None %1
  1672. %3 = OpLabel
  1673. OpBeginInvocationInterlockEXT
  1674. OpEndInvocationInterlockEXT
  1675. OpReturn
  1676. OpFunctionEnd;
  1677. )";
  1678. const auto result =
  1679. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1680. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1681. }
  1682. TEST_F(TrimCapabilitiesPassTest,
  1683. FragmentShaderShadingRateInterlock_RemainsWhenOrderedIsUsed) {
  1684. const std::string kTest = R"(
  1685. OpCapability Shader
  1686. OpCapability FragmentShaderPixelInterlockEXT
  1687. OpCapability FragmentShaderSampleInterlockEXT
  1688. OpCapability FragmentShaderShadingRateInterlockEXT
  1689. OpExtension "SPV_EXT_fragment_shader_interlock"
  1690. ; CHECK-NOT: OpCapability FragmentShaderPixelInterlockEXT
  1691. ; CHECK-NOT: OpCapability FragmentShaderSampleInterlockEXT
  1692. ; CHECK: OpCapability FragmentShaderShadingRateInterlockEXT
  1693. ; CHECK: OpExtension "SPV_EXT_fragment_shader_interlock"
  1694. OpMemoryModel Logical GLSL450
  1695. OpEntryPoint GLCompute %1 "main"
  1696. OpExecutionMode %main ShadingRateInterlockOrderedEXT
  1697. %void = OpTypeVoid
  1698. %1 = OpTypeFunction %void
  1699. %2 = OpFunction %void None %1
  1700. %3 = OpLabel
  1701. OpBeginInvocationInterlockEXT
  1702. OpEndInvocationInterlockEXT
  1703. OpReturn
  1704. OpFunctionEnd;
  1705. )";
  1706. const auto result =
  1707. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1708. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1709. }
  1710. TEST_F(TrimCapabilitiesPassTest,
  1711. FragmentShaderShadingRateInterlock_RemainsWhenUnorderedIsUsed) {
  1712. const std::string kTest = R"(
  1713. OpCapability Shader
  1714. OpCapability FragmentShaderPixelInterlockEXT
  1715. OpCapability FragmentShaderSampleInterlockEXT
  1716. OpCapability FragmentShaderShadingRateInterlockEXT
  1717. OpExtension "SPV_EXT_fragment_shader_interlock"
  1718. ; CHECK-NOT: OpCapability FragmentShaderPixelInterlockEXT
  1719. ; CHECK-NOT: OpCapability FragmentShaderSampleInterlockEXT
  1720. ; CHECK: OpCapability FragmentShaderShadingRateInterlockEXT
  1721. ; CHECK: OpExtension "SPV_EXT_fragment_shader_interlock"
  1722. OpMemoryModel Logical GLSL450
  1723. OpEntryPoint GLCompute %1 "main"
  1724. OpExecutionMode %main ShadingRateInterlockUnorderedEXT
  1725. %void = OpTypeVoid
  1726. %1 = OpTypeFunction %void
  1727. %2 = OpFunction %void None %1
  1728. %3 = OpLabel
  1729. OpBeginInvocationInterlockEXT
  1730. OpEndInvocationInterlockEXT
  1731. OpReturn
  1732. OpFunctionEnd;
  1733. )";
  1734. const auto result =
  1735. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1736. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1737. }
  1738. TEST_F(TrimCapabilitiesPassTest, Int64_RemovedWhenUnused) {
  1739. const std::string kTest = R"(
  1740. OpCapability Int64
  1741. ; CHECK-NOT: OpCapability Int64
  1742. OpCapability Shader
  1743. OpMemoryModel Logical GLSL450
  1744. OpEntryPoint GLCompute %1 "main"
  1745. %void = OpTypeVoid
  1746. %3 = OpTypeFunction %void
  1747. %1 = OpFunction %void None %3
  1748. %6 = OpLabel
  1749. OpReturn
  1750. OpFunctionEnd;
  1751. )";
  1752. const auto result =
  1753. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1754. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1755. }
  1756. TEST_F(TrimCapabilitiesPassTest, Int64_RemainsWhenUsed) {
  1757. const std::string kTest = R"(
  1758. OpCapability Int64
  1759. ; CHECK: OpCapability Int64
  1760. OpCapability Shader
  1761. OpMemoryModel Logical GLSL450
  1762. OpEntryPoint GLCompute %1 "main"
  1763. %void = OpTypeVoid
  1764. %int = OpTypeInt 64 0
  1765. %3 = OpTypeFunction %void
  1766. %1 = OpFunction %void None %3
  1767. %6 = OpLabel
  1768. OpReturn
  1769. OpFunctionEnd;
  1770. )";
  1771. const auto result =
  1772. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1773. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1774. }
  1775. TEST_F(TrimCapabilitiesPassTest, RayQueryKHR_RemovedWhenUnused) {
  1776. const std::string kTest = R"(
  1777. OpCapability Shader
  1778. OpCapability RayQueryKHR
  1779. OpExtension "SPV_KHR_ray_query"
  1780. ; CHECK-NOT: OpCapability RayQueryKHR
  1781. ; CHECK-NOT: OpExtension "SPV_KHR_ray_query"
  1782. OpMemoryModel Logical GLSL450
  1783. OpEntryPoint Vertex %main "main" %out_var_TEXCOORD1
  1784. OpSource HLSL 660
  1785. OpName %out_var_TEXCOORD1 "out.var.TEXCOORD1"
  1786. OpName %main "main"
  1787. OpDecorate %out_var_TEXCOORD1 Flat
  1788. OpDecorate %out_var_TEXCOORD1 Location 0
  1789. %uint = OpTypeInt 32 0
  1790. %uint_1234 = OpConstant %uint 1234
  1791. %_ptr_Output_uint = OpTypePointer Output %uint
  1792. %void = OpTypeVoid
  1793. %7 = OpTypeFunction %void
  1794. %out_var_TEXCOORD1 = OpVariable %_ptr_Output_uint Output
  1795. %main = OpFunction %void None %7
  1796. %8 = OpLabel
  1797. OpStore %out_var_TEXCOORD1 %uint_1234
  1798. OpReturn
  1799. OpFunctionEnd
  1800. )";
  1801. const auto result =
  1802. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1803. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  1804. }
  1805. TEST_F(TrimCapabilitiesPassTest,
  1806. RayQueryKHR_RemainsWhenAccelerationStructureIsPresent) {
  1807. const std::string kTest = R"(
  1808. OpCapability Shader
  1809. OpCapability RayQueryKHR
  1810. OpExtension "SPV_KHR_ray_query"
  1811. ; CHECK: OpCapability RayQueryKHR
  1812. ; CHECK: OpExtension "SPV_KHR_ray_query"
  1813. OpMemoryModel Logical GLSL450
  1814. OpEntryPoint GLCompute %main "main"
  1815. OpExecutionMode %main LocalSize 1 2 4
  1816. OpDecorate %var_bvh DescriptorSet 0
  1817. OpDecorate %var_bvh Binding 0
  1818. %bvh = OpTypeAccelerationStructureKHR
  1819. %ptr_bvh = OpTypePointer UniformConstant %bvh
  1820. %void = OpTypeVoid
  1821. %20 = OpTypeFunction %void
  1822. %var_bvh = OpVariable %ptr_bvh UniformConstant
  1823. %main = OpFunction %void None %20
  1824. %30 = OpLabel
  1825. OpReturn
  1826. OpFunctionEnd
  1827. )";
  1828. const auto result =
  1829. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1830. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1831. }
  1832. TEST_F(TrimCapabilitiesPassTest, RayQueryKHR_RemainsWhenRayQueryTypeIsPresent) {
  1833. const std::string kTest = R"(
  1834. OpCapability Shader
  1835. OpCapability RayQueryKHR
  1836. OpExtension "SPV_KHR_ray_query"
  1837. ; CHECK: OpCapability RayQueryKHR
  1838. ; CHECK: OpExtension "SPV_KHR_ray_query"
  1839. OpMemoryModel Logical GLSL450
  1840. OpEntryPoint GLCompute %main "main"
  1841. OpExecutionMode %main LocalSize 1 2 4
  1842. %query = OpTypeRayQueryKHR
  1843. %void = OpTypeVoid
  1844. %20 = OpTypeFunction %void
  1845. %ptr_query = OpTypePointer Function %query
  1846. %main = OpFunction %void None %20
  1847. %30 = OpLabel
  1848. %var_query = OpVariable %ptr_query Function
  1849. OpReturn
  1850. OpFunctionEnd
  1851. )";
  1852. const auto result =
  1853. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1854. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1855. }
  1856. TEST_F(TrimCapabilitiesPassTest, RayQueryKHR_RemainsWhenUsed) {
  1857. const std::string kTest = R"(
  1858. OpCapability Shader
  1859. OpCapability RayQueryKHR
  1860. OpExtension "SPV_KHR_ray_query"
  1861. ; CHECK: OpCapability RayQueryKHR
  1862. ; CHECK: OpExtension "SPV_KHR_ray_query"
  1863. OpMemoryModel Logical GLSL450
  1864. OpEntryPoint GLCompute %main "main"
  1865. OpExecutionMode %main LocalSize 1 2 4
  1866. OpDecorate %bvh DescriptorSet 0
  1867. OpDecorate %bvh Binding 0
  1868. OpDecorate %output DescriptorSet 0
  1869. OpDecorate %output Binding 1
  1870. OpDecorate %_runtimearr_float ArrayStride 4
  1871. OpMemberDecorate %type_RWStructuredBuffer_float 0 Offset 0
  1872. OpDecorate %type_RWStructuredBuffer_float BufferBlock
  1873. %float = OpTypeFloat 32
  1874. %float_0 = OpConstant %float 0
  1875. %int = OpTypeInt 32 1
  1876. %v3float = OpTypeVector %float 3
  1877. %12 = OpConstantComposite %v3float %float_0 %float_0 %float_0
  1878. %int_0 = OpConstant %int 0
  1879. %uint = OpTypeInt 32 0
  1880. %uint_0 = OpConstant %uint 0
  1881. %uint_1 = OpConstant %uint 1
  1882. %accelerationStructureKHR = OpTypeAccelerationStructureKHR
  1883. %_ptr_UniformConstant_accelerationStructureKHR = OpTypePointer UniformConstant %accelerationStructureKHR
  1884. %_runtimearr_float = OpTypeRuntimeArray %float
  1885. %type_RWStructuredBuffer_float = OpTypeStruct %_runtimearr_float
  1886. %_ptr_Uniform_type_RWStructuredBuffer_float = OpTypePointer Uniform %type_RWStructuredBuffer_float
  1887. %void = OpTypeVoid
  1888. %20 = OpTypeFunction %void
  1889. %rayQueryKHR = OpTypeRayQueryKHR
  1890. %_ptr_Function_rayQueryKHR = OpTypePointer Function %rayQueryKHR
  1891. %bool = OpTypeBool
  1892. %_ptr_Uniform_float = OpTypePointer Uniform %float
  1893. %bvh = OpVariable %_ptr_UniformConstant_accelerationStructureKHR UniformConstant
  1894. %output = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_float Uniform
  1895. %main = OpFunction %void None %20
  1896. %24 = OpLabel
  1897. %25 = OpVariable %_ptr_Function_rayQueryKHR Function
  1898. %26 = OpLoad %accelerationStructureKHR %bvh
  1899. OpRayQueryInitializeKHR %25 %26 %uint_0 %uint_0 %12 %float_0 %12 %float_0
  1900. %27 = OpRayQueryProceedKHR %bool %25
  1901. %28 = OpRayQueryGetIntersectionTypeKHR %uint %25 %uint_1
  1902. %29 = OpIEqual %bool %28 %uint_1
  1903. OpSelectionMerge %30 None
  1904. OpBranchConditional %29 %31 %30
  1905. %31 = OpLabel
  1906. %32 = OpAccessChain %_ptr_Uniform_float %output %int_0 %uint_0
  1907. OpStore %32 %float_0
  1908. OpBranch %30
  1909. %30 = OpLabel
  1910. OpReturn
  1911. OpFunctionEnd
  1912. )";
  1913. const auto result =
  1914. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1915. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1916. }
  1917. TEST_F(TrimCapabilitiesPassTest,
  1918. RayTracingKHR_RemainsWithIntersectionExecutionMode) {
  1919. const std::string kTest = R"(
  1920. OpCapability RayTracingKHR
  1921. OpExtension "SPV_KHR_ray_tracing"
  1922. ; CHECK: OpCapability RayTracingKHR
  1923. ; CHECK: OpExtension "SPV_KHR_ray_tracing"
  1924. OpMemoryModel Logical GLSL450
  1925. OpEntryPoint IntersectionKHR %main "main"
  1926. OpSource HLSL 660
  1927. OpName %main "main"
  1928. %void = OpTypeVoid
  1929. %3 = OpTypeFunction %void
  1930. %main = OpFunction %void None %3
  1931. %4 = OpLabel
  1932. OpReturn
  1933. OpFunctionEnd
  1934. )";
  1935. const auto result =
  1936. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1937. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1938. }
  1939. TEST_F(TrimCapabilitiesPassTest,
  1940. RayTracingKHR_RemainsWithClosestHitExecutionMode) {
  1941. const std::string kTest = R"(
  1942. OpCapability RayTracingKHR
  1943. OpExtension "SPV_KHR_ray_tracing"
  1944. ; CHECK: OpCapability RayTracingKHR
  1945. ; CHECK: OpExtension "SPV_KHR_ray_tracing"
  1946. OpMemoryModel Logical GLSL450
  1947. OpEntryPoint ClosestHitKHR %main "main" %a
  1948. OpSource HLSL 630
  1949. OpName %Payload "Payload"
  1950. OpMemberName %Payload 0 "color"
  1951. OpName %a "a"
  1952. OpName %main "main"
  1953. %float = OpTypeFloat 32
  1954. %v4float = OpTypeVector %float 4
  1955. %Payload = OpTypeStruct %v4float
  1956. %ptr_payload = OpTypePointer IncomingRayPayloadKHR %Payload
  1957. %void = OpTypeVoid
  1958. %8 = OpTypeFunction %void
  1959. %a = OpVariable %ptr_payload IncomingRayPayloadKHR
  1960. %main = OpFunction %void None %8
  1961. %9 = OpLabel
  1962. %10 = OpLoad %Payload %a
  1963. OpStore %a %10
  1964. OpReturn
  1965. OpFunctionEnd
  1966. )";
  1967. const auto result =
  1968. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  1969. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  1970. }
  1971. TEST_F(TrimCapabilitiesPassTest, RayTracingKHR_RemainsWithAnyHitExecutionMode) {
  1972. const std::string kTest = R"(
  1973. OpCapability RayTracingKHR
  1974. OpExtension "SPV_KHR_ray_tracing"
  1975. ; CHECK: OpCapability RayTracingKHR
  1976. ; CHECK: OpExtension "SPV_KHR_ray_tracing"
  1977. OpMemoryModel Logical GLSL450
  1978. OpEntryPoint AnyHitKHR %main "main" %a
  1979. OpSource HLSL 630
  1980. OpName %Payload "Payload"
  1981. OpMemberName %Payload 0 "color"
  1982. OpName %a "a"
  1983. OpName %main "main"
  1984. %float = OpTypeFloat 32
  1985. %v4float = OpTypeVector %float 4
  1986. %Payload = OpTypeStruct %v4float
  1987. %ptr_payload = OpTypePointer IncomingRayPayloadKHR %Payload
  1988. %void = OpTypeVoid
  1989. %8 = OpTypeFunction %void
  1990. %a = OpVariable %ptr_payload IncomingRayPayloadKHR
  1991. %main = OpFunction %void None %8
  1992. %9 = OpLabel
  1993. %10 = OpLoad %Payload %a
  1994. OpStore %a %10
  1995. OpReturn
  1996. OpFunctionEnd
  1997. )";
  1998. const auto result =
  1999. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2000. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2001. }
  2002. TEST_F(TrimCapabilitiesPassTest, RayTracingKHR_RemainsWithMissExecutionMode) {
  2003. const std::string kTest = R"(
  2004. OpCapability RayTracingKHR
  2005. OpExtension "SPV_KHR_ray_tracing"
  2006. ; CHECK: OpCapability RayTracingKHR
  2007. ; CHECK: OpExtension "SPV_KHR_ray_tracing"
  2008. OpMemoryModel Logical GLSL450
  2009. OpEntryPoint MissKHR %main "main" %a
  2010. OpSource HLSL 630
  2011. OpName %Payload "Payload"
  2012. OpMemberName %Payload 0 "color"
  2013. OpName %a "a"
  2014. OpName %main "main"
  2015. %float = OpTypeFloat 32
  2016. %v4float = OpTypeVector %float 4
  2017. %Payload = OpTypeStruct %v4float
  2018. %ptr_payload = OpTypePointer IncomingRayPayloadKHR %Payload
  2019. %void = OpTypeVoid
  2020. %8 = OpTypeFunction %void
  2021. %a = OpVariable %ptr_payload IncomingRayPayloadKHR
  2022. %main = OpFunction %void None %8
  2023. %9 = OpLabel
  2024. %10 = OpLoad %Payload %a
  2025. OpStore %a %10
  2026. OpReturn
  2027. OpFunctionEnd
  2028. )";
  2029. const auto result =
  2030. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2031. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2032. }
  2033. TEST_F(TrimCapabilitiesPassTest,
  2034. RayTracingKHR_RemainsWithRayGenerationExecutionMode) {
  2035. const std::string kTest = R"(
  2036. OpCapability RayTracingKHR
  2037. OpExtension "SPV_KHR_ray_tracing"
  2038. ; CHECK: OpCapability RayTracingKHR
  2039. ; CHECK: OpExtension "SPV_KHR_ray_tracing"
  2040. OpMemoryModel Logical GLSL450
  2041. OpEntryPoint RayGenerationKHR %main "main"
  2042. OpSource HLSL 630
  2043. OpName %main "main"
  2044. %void = OpTypeVoid
  2045. %3 = OpTypeFunction %void
  2046. %main = OpFunction %void None %3
  2047. %4 = OpLabel
  2048. OpReturn
  2049. OpFunctionEnd
  2050. )";
  2051. const auto result =
  2052. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2053. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2054. }
  2055. TEST_F(TrimCapabilitiesPassTest,
  2056. RayTracingKHR_RemainsWithCallableExecutionMode) {
  2057. const std::string kTest = R"(
  2058. ; CHECK: OpCapability RayTracingKHR
  2059. ; CHECK: OpExtension "SPV_KHR_ray_tracing"
  2060. OpCapability RayTracingKHR
  2061. OpExtension "SPV_KHR_ray_tracing"
  2062. OpMemoryModel Logical GLSL450
  2063. OpEntryPoint CallableKHR %main "main" %a
  2064. OpSource HLSL 660
  2065. OpName %Payload "Payload"
  2066. OpMemberName %Payload 0 "data"
  2067. OpName %a "a"
  2068. OpName %main "main"
  2069. %float = OpTypeFloat 32
  2070. %v4float = OpTypeVector %float 4
  2071. %Payload = OpTypeStruct %v4float
  2072. %ptr_payload = OpTypePointer IncomingCallableDataKHR %Payload
  2073. %void = OpTypeVoid
  2074. %8 = OpTypeFunction %void
  2075. %a = OpVariable %ptr_payload IncomingCallableDataKHR
  2076. %main = OpFunction %void None %8
  2077. %9 = OpLabel
  2078. %10 = OpLoad %Payload %a
  2079. OpStore %a %10
  2080. OpReturn
  2081. OpFunctionEnd
  2082. )";
  2083. const auto result =
  2084. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2085. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2086. }
  2087. TEST_F(TrimCapabilitiesPassTest,
  2088. ImageMSArray_RemainsIfSampledIs2AndArrayedIs1) {
  2089. const std::string kTest = R"(
  2090. OpCapability ImageMSArray
  2091. ; CHECK: OpCapability ImageMSArray
  2092. OpCapability Shader
  2093. OpCapability StorageImageMultisample
  2094. OpCapability StorageImageReadWithoutFormat
  2095. OpMemoryModel Logical GLSL450
  2096. OpEntryPoint Fragment %main "main"
  2097. OpExecutionMode %main OriginUpperLeft
  2098. OpDecorate %var_image DescriptorSet 0
  2099. OpDecorate %var_image Binding 1
  2100. %void = OpTypeVoid
  2101. %func = OpTypeFunction %void
  2102. %f32 = OpTypeFloat 32
  2103. %u32 = OpTypeInt 32 0
  2104. %uint_2 = OpConstant %u32 2
  2105. %uint_1 = OpConstant %u32 1
  2106. %v2uint = OpTypeVector %u32 2
  2107. %v4float = OpTypeVector %f32 4
  2108. %image = OpTypeImage %f32 2D 2 1 1 2 Unknown
  2109. %ptr_image = OpTypePointer UniformConstant %image
  2110. %10 = OpConstantComposite %v2uint %uint_1 %uint_2
  2111. %var_image = OpVariable %ptr_image UniformConstant
  2112. %main = OpFunction %void None %func
  2113. %main_lab = OpLabel
  2114. %18 = OpLoad %image %var_image
  2115. %19 = OpImageRead %v4float %18 %10 Sample %uint_2
  2116. OpReturn
  2117. OpFunctionEnd
  2118. )";
  2119. const auto result =
  2120. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2121. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2122. }
  2123. TEST_F(TrimCapabilitiesPassTest, ImageMSArray_RemovedIfNotUsed) {
  2124. const std::string kTest = R"(
  2125. OpCapability Shader
  2126. OpCapability ImageMSArray
  2127. ; CHECK-NOT: OpCapability ImageMSArray
  2128. OpMemoryModel Logical GLSL450
  2129. OpEntryPoint Fragment %main "main" %out_var_SV_Target
  2130. OpExecutionMode %main OriginUpperLeft
  2131. OpSource HLSL 660
  2132. OpName %out_var_SV_Target "out.var.SV_Target"
  2133. OpName %main "main"
  2134. OpDecorate %out_var_SV_Target Location 0
  2135. %float = OpTypeFloat 32
  2136. %v4float = OpTypeVector %float 4
  2137. %_ptr_Output_v4float = OpTypePointer Output %v4float
  2138. %void = OpTypeVoid
  2139. %7 = OpTypeFunction %void
  2140. %out_var_SV_Target = OpVariable %_ptr_Output_v4float Output
  2141. %main = OpFunction %void None %7
  2142. %8 = OpLabel
  2143. OpReturn
  2144. OpFunctionEnd
  2145. )";
  2146. const auto result =
  2147. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2148. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2149. }
  2150. TEST_F(TrimCapabilitiesPassTest, ImageMSArray_RemovedIfArrayedIsNot1) {
  2151. const std::string kTest = R"(
  2152. OpCapability ImageMSArray
  2153. ; CHECK-NOT: OpCapability ImageMSArray
  2154. OpCapability Shader
  2155. OpCapability StorageImageMultisample
  2156. OpCapability StorageImageReadWithoutFormat
  2157. OpMemoryModel Logical GLSL450
  2158. OpEntryPoint Fragment %main "main"
  2159. OpExecutionMode %main OriginUpperLeft
  2160. OpDecorate %var_image DescriptorSet 0
  2161. OpDecorate %var_image Binding 1
  2162. %void = OpTypeVoid
  2163. %func = OpTypeFunction %void
  2164. %f32 = OpTypeFloat 32
  2165. %u32 = OpTypeInt 32 0
  2166. %uint_2 = OpConstant %u32 2
  2167. %uint_1 = OpConstant %u32 1
  2168. %v2uint = OpTypeVector %u32 2
  2169. %v4float = OpTypeVector %f32 4
  2170. %image = OpTypeImage %f32 2D 2 0 1 2 Unknown
  2171. %ptr_image = OpTypePointer UniformConstant %image
  2172. %10 = OpConstantComposite %v2uint %uint_1 %uint_2
  2173. %var_image = OpVariable %ptr_image UniformConstant
  2174. %main = OpFunction %void None %func
  2175. %main_lab = OpLabel
  2176. %18 = OpLoad %image %var_image
  2177. %19 = OpImageRead %v4float %18 %10 Sample %uint_2
  2178. OpReturn
  2179. OpFunctionEnd
  2180. )";
  2181. const auto result =
  2182. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2183. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2184. }
  2185. TEST_F(TrimCapabilitiesPassTest, ImageMSArray_RemovedIfSampledNot2) {
  2186. const std::string kTest = R"(
  2187. OpCapability ImageMSArray
  2188. ; CHECK-NOT: OpCapability ImageMSArray
  2189. OpCapability Shader
  2190. OpCapability StorageImageReadWithoutFormat
  2191. OpMemoryModel Logical GLSL450
  2192. OpEntryPoint Fragment %main "main"
  2193. OpExecutionMode %main OriginUpperLeft
  2194. OpDecorate %var_image DescriptorSet 0
  2195. OpDecorate %var_image Binding 1
  2196. %void = OpTypeVoid
  2197. %func = OpTypeFunction %void
  2198. %f32 = OpTypeFloat 32
  2199. %u32 = OpTypeInt 32 0
  2200. %uint_3 = OpConstant %u32 3
  2201. %uint_2 = OpConstant %u32 2
  2202. %uint_1 = OpConstant %u32 1
  2203. %v3uint = OpTypeVector %u32 3
  2204. %v4float = OpTypeVector %f32 4
  2205. %image = OpTypeImage %f32 2D 2 1 0 2 Unknown
  2206. %ptr_image = OpTypePointer UniformConstant %image
  2207. %10 = OpConstantComposite %v3uint %uint_1 %uint_2 %uint_3
  2208. %var_image = OpVariable %ptr_image UniformConstant
  2209. %main = OpFunction %void None %func
  2210. %main_lab = OpLabel
  2211. %18 = OpLoad %image %var_image
  2212. %19 = OpImageRead %v4float %18 %10
  2213. OpReturn
  2214. OpFunctionEnd
  2215. )";
  2216. const auto result =
  2217. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2218. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2219. }
  2220. TEST_F(TrimCapabilitiesPassTest, Float64_RemovedWhenUnused) {
  2221. const std::string kTest = R"(
  2222. OpCapability Float64
  2223. ; CHECK-NOT: OpCapability Float64
  2224. OpCapability Shader
  2225. OpMemoryModel Logical GLSL450
  2226. OpEntryPoint GLCompute %1 "main"
  2227. %void = OpTypeVoid
  2228. %3 = OpTypeFunction %void
  2229. %1 = OpFunction %void None %3
  2230. %6 = OpLabel
  2231. OpReturn
  2232. OpFunctionEnd;
  2233. )";
  2234. const auto result =
  2235. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2236. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2237. }
  2238. TEST_F(TrimCapabilitiesPassTest, Float64_RemainsWhenUsed) {
  2239. const std::string kTest = R"(
  2240. OpCapability Float64
  2241. ; CHECK: OpCapability Float64
  2242. OpCapability Shader
  2243. OpMemoryModel Logical GLSL450
  2244. OpEntryPoint GLCompute %1 "main"
  2245. %void = OpTypeVoid
  2246. %float = OpTypeFloat 64
  2247. %3 = OpTypeFunction %void
  2248. %1 = OpFunction %void None %3
  2249. %6 = OpLabel
  2250. OpReturn
  2251. OpFunctionEnd;
  2252. )";
  2253. const auto result =
  2254. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2255. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2256. }
  2257. TEST_F(TrimCapabilitiesPassTest,
  2258. ComputeDerivativeGroupQuads_ReamainsWithExecMode) {
  2259. const std::string kTest = R"(
  2260. OpCapability ComputeDerivativeGroupQuadsKHR
  2261. OpCapability ComputeDerivativeGroupLinearKHR
  2262. ; CHECK-NOT: OpCapability ComputeDerivativeGroupLinearKHR
  2263. ; CHECK: OpCapability ComputeDerivativeGroupQuadsKHR
  2264. ; CHECK-NOT: OpCapability ComputeDerivativeGroupLinearKHR
  2265. OpCapability Shader
  2266. ; CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
  2267. OpExtension "SPV_NV_compute_shader_derivatives"
  2268. OpMemoryModel Logical GLSL450
  2269. OpEntryPoint GLCompute %1 "main"
  2270. OpExecutionMode %1 DerivativeGroupQuadsNV
  2271. %void = OpTypeVoid
  2272. %3 = OpTypeFunction %void
  2273. %1 = OpFunction %void None %3
  2274. %6 = OpLabel
  2275. OpReturn
  2276. OpFunctionEnd
  2277. )";
  2278. const auto result =
  2279. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2280. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2281. }
  2282. TEST_F(TrimCapabilitiesPassTest,
  2283. ComputeDerivativeGroupLinear_ReamainsWithExecMode) {
  2284. const std::string kTest = R"(
  2285. OpCapability ComputeDerivativeGroupLinearKHR
  2286. OpCapability ComputeDerivativeGroupQuadsKHR
  2287. ; CHECK-NOT: OpCapability ComputeDerivativeGroupQuadsKHR
  2288. ; CHECK: OpCapability ComputeDerivativeGroupLinearKHR
  2289. ; CHECK-NOT: OpCapability ComputeDerivativeGroupQuadsKHR
  2290. OpCapability Shader
  2291. ; CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
  2292. OpExtension "SPV_NV_compute_shader_derivatives"
  2293. OpMemoryModel Logical GLSL450
  2294. OpEntryPoint GLCompute %1 "main"
  2295. OpExecutionMode %1 DerivativeGroupLinearNV
  2296. %void = OpTypeVoid
  2297. %float = OpTypeFloat 64
  2298. %3 = OpTypeFunction %void
  2299. %1 = OpFunction %void None %3
  2300. %6 = OpLabel
  2301. OpReturn
  2302. OpFunctionEnd
  2303. )";
  2304. const auto result =
  2305. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2306. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2307. }
  2308. TEST_F(TrimCapabilitiesPassTest,
  2309. StorageImageReadWithoutFormat_RemovedIfUnused) {
  2310. const std::string kTest = R"(
  2311. OpCapability StorageImageReadWithoutFormat
  2312. ; CHECK-NOT: OpCapability StorageImageReadWithoutFormat
  2313. OpCapability Shader
  2314. OpMemoryModel Logical GLSL450
  2315. OpEntryPoint Fragment %PSMain "PSMain" %out_var
  2316. OpExecutionMode %PSMain OriginUpperLeft
  2317. OpDecorate %out_var Location 0
  2318. %float = OpTypeFloat 32
  2319. %float4 = OpTypeVector %float 4
  2320. %float_0 = OpConstant %float 0
  2321. %float4_0000 = OpConstantComposite %float4 %float_0 %float_0 %float_0 %float_0
  2322. %ptr_float4 = OpTypePointer Output %float4
  2323. %void = OpTypeVoid
  2324. %9 = OpTypeFunction %void
  2325. %out_var = OpVariable %ptr_float4 Output
  2326. %PSMain = OpFunction %void None %9
  2327. %10 = OpLabel
  2328. OpStore %out_var %float4_0000
  2329. OpReturn
  2330. OpFunctionEnd
  2331. )";
  2332. const auto result =
  2333. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2334. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2335. }
  2336. TEST_F(TrimCapabilitiesPassTest,
  2337. StorageImageReadWithoutFormat_RemovedIfUnusedOpImageFetch) {
  2338. const std::string kTest = R"(
  2339. OpCapability StorageImageReadWithoutFormat
  2340. ; CHECK-NOT: OpCapability StorageImageReadWithoutFormat
  2341. OpCapability Shader
  2342. OpMemoryModel Logical GLSL450
  2343. OpEntryPoint Fragment %PSMain "PSMain" %out_var
  2344. OpExecutionMode %PSMain OriginUpperLeft
  2345. OpDecorate %out_var Location 0
  2346. OpDecorate %texture DescriptorSet 0
  2347. OpDecorate %texture Binding 1
  2348. %float = OpTypeFloat 32
  2349. %float4 = OpTypeVector %float 4
  2350. %int = OpTypeInt 32 1
  2351. %int2 = OpTypeVector %int 2
  2352. %type_image = OpTypeImage %float 2D 2 0 0 1 Unknown
  2353. %ptr_image = OpTypePointer UniformConstant %type_image
  2354. %int_0 = OpConstant %int 0
  2355. %int2_00 = OpConstantComposite %int2 %int_0 %int_0
  2356. %ptr_float4 = OpTypePointer Output %float4
  2357. %void = OpTypeVoid
  2358. %9 = OpTypeFunction %void
  2359. %texture = OpVariable %ptr_image UniformConstant
  2360. %out_var = OpVariable %ptr_float4 Output
  2361. %PSMain = OpFunction %void None %9
  2362. %10 = OpLabel
  2363. %11 = OpLoad %type_image %texture
  2364. %12 = OpImageFetch %float4 %11 %int2_00 Lod %int_0
  2365. OpStore %out_var %12
  2366. OpReturn
  2367. OpFunctionEnd
  2368. )";
  2369. const auto result =
  2370. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2371. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2372. }
  2373. TEST_F(TrimCapabilitiesPassTest,
  2374. StorageImageReadWithoutFormat_RemainsWhenRequiredWithRead) {
  2375. const std::string kTest = R"(
  2376. OpCapability StorageImageReadWithoutFormat
  2377. ; CHECK: OpCapability StorageImageReadWithoutFormat
  2378. OpCapability Shader
  2379. OpMemoryModel Logical GLSL450
  2380. OpEntryPoint Fragment %PSMain "PSMain" %out_var
  2381. OpExecutionMode %PSMain OriginUpperLeft
  2382. OpDecorate %out_var Location 0
  2383. OpDecorate %texture DescriptorSet 0
  2384. OpDecorate %texture Binding 1
  2385. %float = OpTypeFloat 32
  2386. %float4 = OpTypeVector %float 4
  2387. %int = OpTypeInt 32 1
  2388. %int2 = OpTypeVector %int 2
  2389. %type_image = OpTypeImage %float 2D 2 0 0 1 Unknown
  2390. %ptr_image = OpTypePointer UniformConstant %type_image
  2391. %int_0 = OpConstant %int 0
  2392. %int2_00 = OpConstantComposite %int2 %int_0 %int_0
  2393. %ptr_float4 = OpTypePointer Output %float4
  2394. %void = OpTypeVoid
  2395. %9 = OpTypeFunction %void
  2396. %texture = OpVariable %ptr_image UniformConstant
  2397. %out_var = OpVariable %ptr_float4 Output
  2398. %PSMain = OpFunction %void None %9
  2399. %10 = OpLabel
  2400. %11 = OpLoad %type_image %texture
  2401. %12 = OpImageRead %float4 %11 %int2_00 Lod %int_0
  2402. OpStore %out_var %12
  2403. OpReturn
  2404. OpFunctionEnd
  2405. )";
  2406. const auto result =
  2407. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2408. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2409. }
  2410. TEST_F(TrimCapabilitiesPassTest,
  2411. StorageImageReadWithoutFormat_RemainsWhenRequiredWithSparseRead) {
  2412. const std::string kTest = R"(
  2413. OpCapability StorageImageReadWithoutFormat
  2414. ; CHECK: OpCapability StorageImageReadWithoutFormat
  2415. OpCapability SparseResidency
  2416. OpCapability Shader
  2417. OpMemoryModel Logical GLSL450
  2418. OpEntryPoint Fragment %PSMain "PSMain"
  2419. OpExecutionMode %PSMain OriginUpperLeft
  2420. OpDecorate %texture DescriptorSet 0
  2421. OpDecorate %texture Binding 1
  2422. %float = OpTypeFloat 32
  2423. %float4 = OpTypeVector %float 4
  2424. %int = OpTypeInt 32 1
  2425. %int2 = OpTypeVector %int 2
  2426. %type_image = OpTypeImage %float 2D 2 0 0 2 Unknown
  2427. %struct = OpTypeStruct %int %float4
  2428. %ptr_image = OpTypePointer UniformConstant %type_image
  2429. %int_0 = OpConstant %int 0
  2430. %int2_00 = OpConstantComposite %int2 %int_0 %int_0
  2431. %void = OpTypeVoid
  2432. %9 = OpTypeFunction %void
  2433. %texture = OpVariable %ptr_image UniformConstant
  2434. %PSMain = OpFunction %void None %9
  2435. %10 = OpLabel
  2436. %11 = OpLoad %type_image %texture
  2437. %12 = OpImageSparseRead %struct %11 %int2_00
  2438. OpReturn
  2439. OpFunctionEnd
  2440. )";
  2441. const auto result =
  2442. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2443. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2444. }
  2445. TEST_F(TrimCapabilitiesPassTest,
  2446. StorageImageReadWithoutFormat_RemovedWithReadOnSubpassData) {
  2447. const std::string kTest = R"(
  2448. OpCapability StorageImageReadWithoutFormat
  2449. ; CHECK-NOT: OpCapability StorageImageReadWithoutFormat
  2450. OpCapability InputAttachment
  2451. OpCapability Shader
  2452. OpMemoryModel Logical GLSL450
  2453. OpEntryPoint Fragment %PSMain "PSMain" %out_var
  2454. OpExecutionMode %PSMain OriginUpperLeft
  2455. OpDecorate %out_var Location 0
  2456. OpDecorate %texture DescriptorSet 0
  2457. OpDecorate %texture Binding 1
  2458. %float = OpTypeFloat 32
  2459. %float4 = OpTypeVector %float 4
  2460. %int = OpTypeInt 32 1
  2461. %int2 = OpTypeVector %int 2
  2462. %type_image = OpTypeImage %float SubpassData 2 0 0 2 Unknown
  2463. %ptr_image = OpTypePointer UniformConstant %type_image
  2464. %int_0 = OpConstant %int 0
  2465. %int2_00 = OpConstantComposite %int2 %int_0 %int_0
  2466. %ptr_float4 = OpTypePointer Output %float4
  2467. %void = OpTypeVoid
  2468. %9 = OpTypeFunction %void
  2469. %texture = OpVariable %ptr_image UniformConstant
  2470. %out_var = OpVariable %ptr_float4 Output
  2471. %PSMain = OpFunction %void None %9
  2472. %10 = OpLabel
  2473. %11 = OpLoad %type_image %texture
  2474. %12 = OpImageRead %float4 %11 %int2_00
  2475. OpStore %out_var %12
  2476. OpReturn
  2477. OpFunctionEnd
  2478. )";
  2479. const auto result =
  2480. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2481. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2482. }
  2483. TEST_F(TrimCapabilitiesPassTest,
  2484. StorageImageWriteWithoutFormat_RemainsWhenRequiredWithWrite) {
  2485. const std::string kTest = R"(
  2486. OpCapability StorageImageWriteWithoutFormat
  2487. ; CHECK: OpCapability StorageImageWriteWithoutFormat
  2488. OpCapability Shader
  2489. OpCapability StorageImageExtendedFormats
  2490. OpMemoryModel Logical GLSL450
  2491. OpEntryPoint GLCompute %main "main" %id %img
  2492. OpExecutionMode %main LocalSize 8 8 8
  2493. OpSource HLSL 670
  2494. OpName %type_image "type.3d.image"
  2495. OpName %img "img"
  2496. OpName %main "main"
  2497. OpDecorate %id BuiltIn GlobalInvocationId
  2498. OpDecorate %img DescriptorSet 0
  2499. OpDecorate %img Binding 0
  2500. %float = OpTypeFloat 32
  2501. %float_4 = OpConstant %float 4
  2502. %float_5 = OpConstant %float 5
  2503. %v2float = OpTypeVector %float 2
  2504. %9 = OpConstantComposite %v2float %float_4 %float_5
  2505. %type_image = OpTypeImage %float 3D 2 0 0 2 Unknown
  2506. %ptr_img = OpTypePointer UniformConstant %type_image
  2507. %uint = OpTypeInt 32 0
  2508. %v3uint = OpTypeVector %uint 3
  2509. %ptr_input = OpTypePointer Input %v3uint
  2510. %void = OpTypeVoid
  2511. %15 = OpTypeFunction %void
  2512. %img = OpVariable %ptr_img UniformConstant
  2513. %id = OpVariable %ptr_input Input
  2514. %main = OpFunction %void None %15
  2515. %16 = OpLabel
  2516. %17 = OpLoad %v3uint %id
  2517. %18 = OpLoad %type_image %img
  2518. OpImageWrite %18 %17 %9 None
  2519. OpReturn
  2520. OpFunctionEnd
  2521. )";
  2522. const auto result =
  2523. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2524. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2525. }
  2526. TEST_F(TrimCapabilitiesPassTest,
  2527. StorageImageWriteWithoutFormat_RemovedWithWriteOnKnownFormat) {
  2528. const std::string kTest = R"(
  2529. OpCapability StorageImageWriteWithoutFormat
  2530. ; CHECK-NOT: OpCapability StorageImageWriteWithoutFormat
  2531. OpCapability Shader
  2532. OpCapability StorageImageExtendedFormats
  2533. OpMemoryModel Logical GLSL450
  2534. OpEntryPoint GLCompute %main "main" %id %img
  2535. OpExecutionMode %main LocalSize 8 8 8
  2536. OpSource HLSL 670
  2537. OpName %type_image "type.3d.image"
  2538. OpName %img "img"
  2539. OpName %main "main"
  2540. OpDecorate %id BuiltIn GlobalInvocationId
  2541. OpDecorate %img DescriptorSet 0
  2542. OpDecorate %img Binding 0
  2543. %float = OpTypeFloat 32
  2544. %float_4 = OpConstant %float 4
  2545. %float_5 = OpConstant %float 5
  2546. %v2float = OpTypeVector %float 2
  2547. %9 = OpConstantComposite %v2float %float_4 %float_5
  2548. %type_image = OpTypeImage %float 3D 2 0 0 2 Rg32f
  2549. %ptr_img = OpTypePointer UniformConstant %type_image
  2550. %uint = OpTypeInt 32 0
  2551. %v3uint = OpTypeVector %uint 3
  2552. %ptr_input = OpTypePointer Input %v3uint
  2553. %void = OpTypeVoid
  2554. %15 = OpTypeFunction %void
  2555. %img = OpVariable %ptr_img UniformConstant
  2556. %id = OpVariable %ptr_input Input
  2557. %main = OpFunction %void None %15
  2558. %16 = OpLabel
  2559. %17 = OpLoad %v3uint %id
  2560. %18 = OpLoad %type_image %img
  2561. OpImageWrite %18 %17 %9 None
  2562. OpReturn
  2563. OpFunctionEnd
  2564. )";
  2565. const auto result =
  2566. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2567. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2568. }
  2569. TEST_F(TrimCapabilitiesPassTest, PhysicalStorageBuffer_RemovedWhenUnused) {
  2570. const std::string kTest = R"(
  2571. OpCapability PhysicalStorageBufferAddresses
  2572. ; CHECK-NOT: OpCapability PhysicalStorageBufferAddresses
  2573. OpCapability Shader
  2574. OpMemoryModel Logical GLSL450
  2575. OpEntryPoint GLCompute %1 "main"
  2576. %void = OpTypeVoid
  2577. %3 = OpTypeFunction %void
  2578. %1 = OpFunction %void None %3
  2579. %6 = OpLabel
  2580. OpReturn
  2581. OpFunctionEnd;
  2582. )";
  2583. const auto result =
  2584. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2585. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2586. }
  2587. TEST_F(TrimCapabilitiesPassTest,
  2588. PhysicalStorageBuffer_RemainsWithOpTypeForwardPointer) {
  2589. const std::string kTest = R"(
  2590. OpCapability PhysicalStorageBufferAddresses
  2591. ; CHECK: OpCapability PhysicalStorageBufferAddresses
  2592. OpCapability Shader
  2593. OpMemoryModel Logical GLSL450
  2594. OpEntryPoint GLCompute %main "main"
  2595. OpExecutionMode %main LocalSize 1 2 4
  2596. %void = OpTypeVoid
  2597. %int = OpTypeInt 32 0
  2598. %struct = OpTypeStruct %int
  2599. OpTypeForwardPointer %ptr PhysicalStorageBuffer
  2600. %ptr = OpTypePointer PhysicalStorageBuffer %struct
  2601. %3 = OpTypeFunction %void
  2602. %main = OpFunction %void None %3
  2603. %6 = OpLabel
  2604. OpReturn
  2605. OpFunctionEnd
  2606. )";
  2607. const auto result =
  2608. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2609. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2610. }
  2611. TEST_F(TrimCapabilitiesPassTest,
  2612. PhysicalStorageBuffer_RemainsWithPhysicalStorageBufferStorage) {
  2613. const std::string kTest = R"(
  2614. OpCapability PhysicalStorageBufferAddresses
  2615. ; CHECK: OpCapability PhysicalStorageBufferAddresses
  2616. OpCapability Shader
  2617. OpMemoryModel Logical GLSL450
  2618. OpEntryPoint GLCompute %main "main"
  2619. OpExecutionMode %main LocalSize 1 2 4
  2620. %void = OpTypeVoid
  2621. %int = OpTypeInt 32 0
  2622. %struct = OpTypeStruct %int
  2623. %ptr = OpTypePointer PhysicalStorageBuffer %struct
  2624. %3 = OpTypeFunction %void
  2625. %main = OpFunction %void None %3
  2626. %6 = OpLabel
  2627. OpReturn
  2628. OpFunctionEnd;
  2629. )";
  2630. const auto result =
  2631. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2632. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2633. }
  2634. TEST_F(TrimCapabilitiesPassTest,
  2635. PhysicalStorageBuffer_RemainsWithRestrictDecoration) {
  2636. const std::string kTest = R"(
  2637. OpCapability PhysicalStorageBufferAddresses
  2638. ; CHECK: OpCapability PhysicalStorageBufferAddresses
  2639. OpCapability Shader
  2640. OpMemoryModel Logical GLSL450
  2641. OpEntryPoint GLCompute %main "main"
  2642. OpExecutionMode %main LocalSize 1 2 4
  2643. OpDecorate %var RestrictPointer
  2644. %void = OpTypeVoid
  2645. %int = OpTypeInt 32 0
  2646. %struct = OpTypeStruct %int
  2647. %ptr = OpTypePointer Function %struct
  2648. %3 = OpTypeFunction %void
  2649. %main = OpFunction %void None %3
  2650. %6 = OpLabel
  2651. %var = OpVariable %ptr Function
  2652. OpReturn
  2653. OpFunctionEnd;
  2654. )";
  2655. const auto result =
  2656. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2657. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2658. }
  2659. TEST_F(TrimCapabilitiesPassTest,
  2660. PhysicalStorageBuffer_RemainsWithAliasedDecoration) {
  2661. const std::string kTest = R"(
  2662. OpCapability PhysicalStorageBufferAddresses
  2663. ; CHECK: OpCapability PhysicalStorageBufferAddresses
  2664. OpCapability Shader
  2665. OpMemoryModel Logical GLSL450
  2666. OpEntryPoint GLCompute %main "main"
  2667. OpExecutionMode %main LocalSize 1 2 4
  2668. OpDecorate %var AliasedPointer
  2669. %void = OpTypeVoid
  2670. %int = OpTypeInt 32 0
  2671. %struct = OpTypeStruct %int
  2672. %ptr = OpTypePointer Function %struct
  2673. %3 = OpTypeFunction %void
  2674. %main = OpFunction %void None %3
  2675. %6 = OpLabel
  2676. %var = OpVariable %ptr Function
  2677. OpReturn
  2678. OpFunctionEnd;
  2679. )";
  2680. const auto result =
  2681. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2682. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2683. }
  2684. TEST_F(TrimCapabilitiesPassTest, Float16_RemovedWhenUnused) {
  2685. const std::string kTest = R"(
  2686. OpCapability Float16
  2687. ; CHECK-NOT: OpCapability Float16
  2688. OpCapability Shader
  2689. OpMemoryModel Logical GLSL450
  2690. OpEntryPoint GLCompute %1 "main"
  2691. %void = OpTypeVoid
  2692. %3 = OpTypeFunction %void
  2693. %1 = OpFunction %void None %3
  2694. %6 = OpLabel
  2695. OpReturn
  2696. OpFunctionEnd;
  2697. )";
  2698. const auto result =
  2699. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2700. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2701. }
  2702. TEST_F(TrimCapabilitiesPassTest, Float16_RemainsWhenUsed) {
  2703. const std::string kTest = R"(
  2704. OpCapability Float16
  2705. ; CHECK: OpCapability Float16
  2706. OpCapability Shader
  2707. OpMemoryModel Logical GLSL450
  2708. OpEntryPoint GLCompute %1 "main"
  2709. %void = OpTypeVoid
  2710. %float = OpTypeFloat 16
  2711. %3 = OpTypeFunction %void
  2712. %1 = OpFunction %void None %3
  2713. %6 = OpLabel
  2714. OpReturn
  2715. OpFunctionEnd;
  2716. )";
  2717. const auto result =
  2718. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2719. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2720. }
  2721. TEST_F(TrimCapabilitiesPassTest, Int16_RemovedWhenUnused) {
  2722. const std::string kTest = R"(
  2723. OpCapability Int16
  2724. ; CHECK-NOT: OpCapability Int16
  2725. OpCapability Shader
  2726. OpMemoryModel Logical GLSL450
  2727. OpEntryPoint GLCompute %1 "main"
  2728. %void = OpTypeVoid
  2729. %3 = OpTypeFunction %void
  2730. %1 = OpFunction %void None %3
  2731. %6 = OpLabel
  2732. OpReturn
  2733. OpFunctionEnd;
  2734. )";
  2735. const auto result =
  2736. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2737. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2738. }
  2739. TEST_F(TrimCapabilitiesPassTest, Int16_RemainsWhenUsed) {
  2740. const std::string kTest = R"(
  2741. OpCapability Int16
  2742. ; CHECK: OpCapability Int16
  2743. OpCapability Shader
  2744. OpMemoryModel Logical GLSL450
  2745. OpEntryPoint GLCompute %1 "main"
  2746. %void = OpTypeVoid
  2747. %int = OpTypeInt 16 1
  2748. %3 = OpTypeFunction %void
  2749. %1 = OpFunction %void None %3
  2750. %6 = OpLabel
  2751. OpReturn
  2752. OpFunctionEnd;
  2753. )";
  2754. const auto result =
  2755. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2756. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2757. }
  2758. TEST_F(TrimCapabilitiesPassTest, UInt16_RemainsWhenUsed) {
  2759. const std::string kTest = R"(
  2760. OpCapability Int16
  2761. ; CHECK: OpCapability Int16
  2762. OpCapability Shader
  2763. OpMemoryModel Logical GLSL450
  2764. OpEntryPoint GLCompute %1 "main"
  2765. %void = OpTypeVoid
  2766. %uint = OpTypeInt 16 0
  2767. %3 = OpTypeFunction %void
  2768. %1 = OpFunction %void None %3
  2769. %6 = OpLabel
  2770. OpReturn
  2771. OpFunctionEnd;
  2772. )";
  2773. const auto result =
  2774. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2775. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2776. }
  2777. TEST_F(TrimCapabilitiesPassTest,
  2778. VulkanMemoryModelDeviceScope_RemovedWhenUnused) {
  2779. const std::string kTest = R"(
  2780. OpCapability VulkanMemoryModelDeviceScope
  2781. ; CHECK-NOT: OpCapability VulkanMemoryModelDeviceScope
  2782. OpCapability Shader
  2783. OpMemoryModel Logical GLSL450
  2784. OpEntryPoint GLCompute %1 "main"
  2785. %void = OpTypeVoid
  2786. %3 = OpTypeFunction %void
  2787. %1 = OpFunction %void None %3
  2788. %6 = OpLabel
  2789. OpReturn
  2790. OpFunctionEnd;
  2791. )";
  2792. const auto result =
  2793. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2794. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2795. }
  2796. TEST_F(TrimCapabilitiesPassTest,
  2797. VulkanMemoryModelDeviceScope_RemovedWhenUsedWithGLSL450) {
  2798. const std::string kTest = R"(
  2799. OpCapability VulkanMemoryModelDeviceScope
  2800. ; CHECK-NOT: OpCapability VulkanMemoryModelDeviceScope
  2801. OpCapability Shader
  2802. OpCapability ShaderClockKHR
  2803. OpCapability Int64
  2804. OpExtension "SPV_KHR_shader_clock"
  2805. OpMemoryModel Logical GLSL450
  2806. OpEntryPoint GLCompute %main "main"
  2807. OpExecutionMode %main LocalSize 1 2 4
  2808. %void = OpTypeVoid
  2809. %uint = OpTypeInt 32 0
  2810. %ulong = OpTypeInt 64 0
  2811. %uint_1 = OpConstant %uint 1
  2812. %3 = OpTypeFunction %void
  2813. %main = OpFunction %void None %3
  2814. %6 = OpLabel
  2815. %22 = OpReadClockKHR %ulong %uint_1 ; Device Scope
  2816. OpReturn
  2817. OpFunctionEnd
  2818. )";
  2819. const auto result =
  2820. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2821. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2822. }
  2823. TEST_F(TrimCapabilitiesPassTest,
  2824. VulkanMemoryModelDeviceScope_RemainsWhenUsedWithVulkan) {
  2825. const std::string kTest = R"(
  2826. OpCapability VulkanMemoryModelDeviceScope
  2827. ; CHECK: OpCapability VulkanMemoryModelDeviceScope
  2828. OpCapability Shader
  2829. OpCapability ShaderClockKHR
  2830. OpCapability Int64
  2831. OpExtension "SPV_KHR_shader_clock"
  2832. OpMemoryModel Logical Vulkan
  2833. OpEntryPoint GLCompute %main "main"
  2834. OpExecutionMode %main LocalSize 1 2 4
  2835. %void = OpTypeVoid
  2836. %uint = OpTypeInt 32 0
  2837. %ulong = OpTypeInt 64 0
  2838. %uint_1 = OpConstant %uint 1
  2839. %3 = OpTypeFunction %void
  2840. %main = OpFunction %void None %3
  2841. %6 = OpLabel
  2842. %22 = OpReadClockKHR %ulong %uint_1 ; Device Scope
  2843. OpReturn
  2844. OpFunctionEnd
  2845. )";
  2846. const auto result =
  2847. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  2848. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  2849. }
  2850. TEST_F(TrimCapabilitiesPassTest, GroupNonUniform_RemovedWhenUnused) {
  2851. const std::string kTest = R"(
  2852. OpCapability Shader
  2853. OpCapability GroupNonUniformVote
  2854. ; CHECK-NOT: OpCapability GroupNonUniformVote
  2855. OpCapability GroupNonUniformArithmetic
  2856. ; CHECK-NOT: OpCapability GroupNonUniformArithmetic
  2857. OpCapability GroupNonUniformClustered
  2858. ; CHECK-NOT: OpCapability GroupNonUniformClustered
  2859. OpCapability GroupNonUniformPartitionedNV
  2860. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  2861. OpCapability GroupNonUniform
  2862. ; CHECK-NOT: OpCapability GroupNonUniform
  2863. OpExtension "SPV_NV_shader_subgroup_partitioned"
  2864. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  2865. OpMemoryModel Logical GLSL450
  2866. OpEntryPoint GLCompute %main "main"
  2867. OpExecutionMode %main LocalSize 1 2 4
  2868. %void = OpTypeVoid
  2869. %3 = OpTypeFunction %void
  2870. %main = OpFunction %void None %3
  2871. %6 = OpLabel
  2872. OpReturn
  2873. OpFunctionEnd;
  2874. )";
  2875. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  2876. kTest, /* do_validation= */ false);
  2877. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2878. }
  2879. TEST_F(TrimCapabilitiesPassTest,
  2880. GroupNonUniform_RemainsGroupNonUniformWhenInUse) {
  2881. const std::string kTest = R"(
  2882. OpCapability GroupNonUniformVote
  2883. ; CHECK-NOT: OpCapability GroupNonUniformVote
  2884. OpCapability GroupNonUniformArithmetic
  2885. ; CHECK-NOT: OpCapability GroupNonUniformArithmetic
  2886. OpCapability GroupNonUniformClustered
  2887. ; CHECK-NOT: OpCapability GroupNonUniformClustered
  2888. OpCapability GroupNonUniformPartitionedNV
  2889. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  2890. OpCapability GroupNonUniform
  2891. ; CHECK: OpCapability GroupNonUniform
  2892. OpCapability Shader
  2893. OpExtension "SPV_NV_shader_subgroup_partitioned"
  2894. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  2895. OpMemoryModel Logical GLSL450
  2896. OpEntryPoint GLCompute %main "main"
  2897. OpExecutionMode %main LocalSize 1 2 4
  2898. %void = OpTypeVoid
  2899. %bool = OpTypeBool
  2900. %uint = OpTypeInt 32 0
  2901. %scope_subgroup = OpConstant %uint 3
  2902. %3 = OpTypeFunction %void
  2903. %main = OpFunction %void None %3
  2904. %6 = OpLabel
  2905. %7 = OpGroupNonUniformElect %bool %scope_subgroup
  2906. OpReturn
  2907. OpFunctionEnd;
  2908. )";
  2909. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  2910. kTest, /* do_validation= */ false);
  2911. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2912. }
  2913. TEST_F(TrimCapabilitiesPassTest,
  2914. GroupNonUniformVote_Remains_OpGroupNonUniformAll) {
  2915. const std::string kTest = R"(
  2916. OpCapability Shader
  2917. OpCapability GroupNonUniformVote
  2918. ; CHECK: OpCapability GroupNonUniformVote
  2919. OpCapability GroupNonUniformArithmetic
  2920. ; CHECK-NOT: OpCapability GroupNonUniformArithmetic
  2921. OpCapability GroupNonUniformClustered
  2922. ; CHECK-NOT: OpCapability GroupNonUniformClustered
  2923. OpCapability GroupNonUniformPartitionedNV
  2924. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  2925. OpCapability GroupNonUniform
  2926. ; CHECK-NOT: OpCapability GroupNonUniform
  2927. OpExtension "SPV_NV_shader_subgroup_partitioned"
  2928. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  2929. OpMemoryModel Logical GLSL450
  2930. OpEntryPoint GLCompute %main "main"
  2931. OpExecutionMode %main LocalSize 1 2 4
  2932. %void = OpTypeVoid
  2933. %bool = OpTypeBool
  2934. %uint = OpTypeInt 32 0
  2935. %scope_subgroup = OpConstant %uint 3
  2936. %true = OpConstantTrue %bool
  2937. %3 = OpTypeFunction %void
  2938. %main = OpFunction %void None %3
  2939. %6 = OpLabel
  2940. %7 = OpGroupNonUniformAll %bool %scope_subgroup %true
  2941. OpReturn
  2942. OpFunctionEnd;
  2943. )";
  2944. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  2945. kTest, /* do_validation= */ false);
  2946. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2947. }
  2948. TEST_F(TrimCapabilitiesPassTest,
  2949. GroupNonUniformVote_Remains_OpGroupNonUniformAny) {
  2950. const std::string kTest = R"(
  2951. OpCapability Shader
  2952. OpCapability GroupNonUniformVote
  2953. ; CHECK: OpCapability GroupNonUniformVote
  2954. OpCapability GroupNonUniformArithmetic
  2955. ; CHECK-NOT: OpCapability GroupNonUniformArithmetic
  2956. OpCapability GroupNonUniformClustered
  2957. ; CHECK-NOT: OpCapability GroupNonUniformClustered
  2958. OpCapability GroupNonUniformPartitionedNV
  2959. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  2960. OpCapability GroupNonUniform
  2961. ; CHECK-NOT: OpCapability GroupNonUniform
  2962. OpExtension "SPV_NV_shader_subgroup_partitioned"
  2963. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  2964. OpMemoryModel Logical GLSL450
  2965. OpEntryPoint GLCompute %main "main"
  2966. OpExecutionMode %main LocalSize 1 2 4
  2967. %void = OpTypeVoid
  2968. %bool = OpTypeBool
  2969. %uint = OpTypeInt 32 0
  2970. %scope_subgroup = OpConstant %uint 3
  2971. %true = OpConstantTrue %bool
  2972. %3 = OpTypeFunction %void
  2973. %main = OpFunction %void None %3
  2974. %6 = OpLabel
  2975. %7 = OpGroupNonUniformAny %bool %scope_subgroup %true
  2976. OpReturn
  2977. OpFunctionEnd;
  2978. )";
  2979. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  2980. kTest, /* do_validation= */ false);
  2981. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  2982. }
  2983. TEST_F(TrimCapabilitiesPassTest,
  2984. GroupNonUniformArithmetic_Remains_OpGroupNonUniformIAdd_Reduce) {
  2985. const std::string kTest = R"(
  2986. OpCapability Shader
  2987. OpCapability GroupNonUniformVote
  2988. ; CHECK-NOT: OpCapability GroupNonUniformVote
  2989. OpCapability GroupNonUniformArithmetic
  2990. ; CHECK: OpCapability GroupNonUniformArithmetic
  2991. OpCapability GroupNonUniformClustered
  2992. ; CHECK-NOT: OpCapability GroupNonUniformClustered
  2993. OpCapability GroupNonUniformPartitionedNV
  2994. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  2995. OpCapability GroupNonUniform
  2996. ; CHECK-NOT: OpCapability GroupNonUniform
  2997. OpExtension "SPV_NV_shader_subgroup_partitioned"
  2998. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  2999. OpMemoryModel Logical GLSL450
  3000. OpEntryPoint GLCompute %main "main"
  3001. OpExecutionMode %main LocalSize 1 2 4
  3002. %void = OpTypeVoid
  3003. %bool = OpTypeBool
  3004. %uint = OpTypeInt 32 0
  3005. %scope_subgroup = OpConstant %uint 3
  3006. %uint_1 = OpConstant %uint 1
  3007. %true = OpConstantTrue %bool
  3008. %3 = OpTypeFunction %void
  3009. %main = OpFunction %void None %3
  3010. %6 = OpLabel
  3011. %7 = OpGroupNonUniformIAdd %uint %scope_subgroup Reduce %uint_1
  3012. OpReturn
  3013. OpFunctionEnd;
  3014. )";
  3015. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  3016. kTest, /* do_validation= */ true);
  3017. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  3018. }
  3019. TEST_F(TrimCapabilitiesPassTest,
  3020. GroupNonUniformArithmetic_Remains_OpGroupNonUniformIAdd_InclusiveScan) {
  3021. const std::string kTest = R"(
  3022. OpCapability Shader
  3023. OpCapability GroupNonUniformVote
  3024. ; CHECK-NOT: OpCapability GroupNonUniformVote
  3025. OpCapability GroupNonUniformArithmetic
  3026. ; CHECK: OpCapability GroupNonUniformArithmetic
  3027. OpCapability GroupNonUniformClustered
  3028. ; CHECK-NOT: OpCapability GroupNonUniformClustered
  3029. OpCapability GroupNonUniformPartitionedNV
  3030. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  3031. OpCapability GroupNonUniform
  3032. ; CHECK-NOT: OpCapability GroupNonUniform
  3033. OpExtension "SPV_NV_shader_subgroup_partitioned"
  3034. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  3035. OpMemoryModel Logical GLSL450
  3036. OpEntryPoint GLCompute %main "main"
  3037. OpExecutionMode %main LocalSize 1 2 4
  3038. %void = OpTypeVoid
  3039. %bool = OpTypeBool
  3040. %uint = OpTypeInt 32 0
  3041. %scope_subgroup = OpConstant %uint 3
  3042. %uint_1 = OpConstant %uint 1
  3043. %true = OpConstantTrue %bool
  3044. %3 = OpTypeFunction %void
  3045. %main = OpFunction %void None %3
  3046. %6 = OpLabel
  3047. %7 = OpGroupNonUniformIAdd %uint %scope_subgroup InclusiveScan %uint_1
  3048. OpReturn
  3049. OpFunctionEnd;
  3050. )";
  3051. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  3052. kTest, /* do_validation= */ true);
  3053. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  3054. }
  3055. TEST_F(TrimCapabilitiesPassTest,
  3056. GroupNonUniformArithmetic_Remains_OpGroupNonUniformIAdd_ExclusiveScan) {
  3057. const std::string kTest = R"(
  3058. OpCapability Shader
  3059. OpCapability GroupNonUniformVote
  3060. ; CHECK-NOT: OpCapability GroupNonUniformVote
  3061. OpCapability GroupNonUniformArithmetic
  3062. ; CHECK: OpCapability GroupNonUniformArithmetic
  3063. OpCapability GroupNonUniformClustered
  3064. ; CHECK-NOT: OpCapability GroupNonUniformClustered
  3065. OpCapability GroupNonUniformPartitionedNV
  3066. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  3067. OpCapability GroupNonUniform
  3068. ; CHECK-NOT: OpCapability GroupNonUniform
  3069. OpExtension "SPV_NV_shader_subgroup_partitioned"
  3070. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  3071. OpMemoryModel Logical GLSL450
  3072. OpEntryPoint GLCompute %main "main"
  3073. OpExecutionMode %main LocalSize 1 2 4
  3074. %void = OpTypeVoid
  3075. %bool = OpTypeBool
  3076. %uint = OpTypeInt 32 0
  3077. %scope_subgroup = OpConstant %uint 3
  3078. %uint_1 = OpConstant %uint 1
  3079. %true = OpConstantTrue %bool
  3080. %3 = OpTypeFunction %void
  3081. %main = OpFunction %void None %3
  3082. %6 = OpLabel
  3083. %7 = OpGroupNonUniformIAdd %uint %scope_subgroup ExclusiveScan %uint_1
  3084. OpReturn
  3085. OpFunctionEnd;
  3086. )";
  3087. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  3088. kTest, /* do_validation= */ true);
  3089. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  3090. }
  3091. TEST_F(TrimCapabilitiesPassTest,
  3092. GroupNonUniformClustered_Remains_OpGroupNonUniformIAdd_ClusteredReduce) {
  3093. const std::string kTest = R"(
  3094. OpCapability Shader
  3095. OpCapability GroupNonUniformVote
  3096. ; CHECK-NOT: OpCapability GroupNonUniformVote
  3097. OpCapability GroupNonUniformArithmetic
  3098. ; CHECK-NOT: OpCapability GroupNonUniformArithmetic
  3099. OpCapability GroupNonUniformClustered
  3100. ; CHECK: OpCapability GroupNonUniformClustered
  3101. OpCapability GroupNonUniformPartitionedNV
  3102. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  3103. OpCapability GroupNonUniform
  3104. ; CHECK-NOT: OpCapability GroupNonUniform
  3105. OpExtension "SPV_NV_shader_subgroup_partitioned"
  3106. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  3107. OpMemoryModel Logical GLSL450
  3108. OpEntryPoint GLCompute %main "main"
  3109. OpExecutionMode %main LocalSize 1 2 4
  3110. %void = OpTypeVoid
  3111. %bool = OpTypeBool
  3112. %uint = OpTypeInt 32 0
  3113. %scope_subgroup = OpConstant %uint 3
  3114. %uint_1 = OpConstant %uint 1
  3115. %true = OpConstantTrue %bool
  3116. %3 = OpTypeFunction %void
  3117. %main = OpFunction %void None %3
  3118. %6 = OpLabel
  3119. %7 = OpGroupNonUniformIAdd %uint %scope_subgroup ClusteredReduce %uint_1 %uint_1
  3120. OpReturn
  3121. OpFunctionEnd;
  3122. )";
  3123. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  3124. kTest, /* do_validation= */ true);
  3125. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  3126. }
  3127. struct SubgroupTestCase {
  3128. // The result type of the subgroup instruction.
  3129. std::string resultType;
  3130. // The opcode of the subgroup instruction.
  3131. std::string opcode;
  3132. // The actual operand of the subgroup instruction.
  3133. std::string operand;
  3134. };
  3135. static const std::vector<SubgroupTestCase> kSubgroupTestCases{
  3136. // clang-format off
  3137. { "uint", "OpGroupNonUniformIAdd", "uint_1" },
  3138. { "float", "OpGroupNonUniformFAdd", "float_1" },
  3139. { "uint", "OpGroupNonUniformIMul", "uint_1" },
  3140. { "float", "OpGroupNonUniformFMul", "float_1" },
  3141. { "int", "OpGroupNonUniformSMin", "int_1" },
  3142. { "uint", "OpGroupNonUniformUMin", "uint_1" },
  3143. { "float", "OpGroupNonUniformFMin", "float_1" },
  3144. { "int", "OpGroupNonUniformSMax", "int_1" },
  3145. { "uint", "OpGroupNonUniformUMax", "uint_1" },
  3146. { "float", "OpGroupNonUniformFMax", "float_1" },
  3147. { "uint", "OpGroupNonUniformBitwiseAnd", "uint_1" },
  3148. { "uint", "OpGroupNonUniformBitwiseOr", "uint_1" },
  3149. { "uint", "OpGroupNonUniformBitwiseXor", "uint_1" },
  3150. { "bool", "OpGroupNonUniformLogicalAnd", "true" },
  3151. { "bool", "OpGroupNonUniformLogicalOr", "true" },
  3152. { "bool", "OpGroupNonUniformLogicalXor", "true" }
  3153. // clang-format on
  3154. };
  3155. using TrimCapabilitiesPassTestSubgroupNV_Unsigned = PassTest<
  3156. ::testing::TestWithParam<std::tuple<SubgroupTestCase, std::string>>>;
  3157. TEST_P(TrimCapabilitiesPassTestSubgroupNV_Unsigned,
  3158. GroupNonUniformPartitionedNV_Remains) {
  3159. SubgroupTestCase test_case = std::get<0>(GetParam());
  3160. const std::string operation = std::get<1>(GetParam());
  3161. const std::string kTest = R"(
  3162. OpCapability Shader
  3163. OpCapability GroupNonUniformVote
  3164. ; CHECK-NOT: OpCapability GroupNonUniformVote
  3165. OpCapability GroupNonUniformArithmetic
  3166. ; CHECK-NOT: OpCapability GroupNonUniformArithmetic
  3167. OpCapability GroupNonUniformClustered
  3168. ; CHECK-NOT: OpCapability GroupNonUniformClustered
  3169. OpCapability GroupNonUniformPartitionedNV
  3170. ; CHECK: OpCapability GroupNonUniformPartitionedNV
  3171. OpCapability GroupNonUniform
  3172. ; CHECK-NOT: OpCapability GroupNonUniform
  3173. OpExtension "SPV_NV_shader_subgroup_partitioned"
  3174. ; CHECK: OpExtension "SPV_NV_shader_subgroup_partitioned"
  3175. OpMemoryModel Logical GLSL450
  3176. OpEntryPoint GLCompute %main "main"
  3177. OpExecutionMode %main LocalSize 1 2 4
  3178. %void = OpTypeVoid
  3179. %bool = OpTypeBool
  3180. %uint = OpTypeInt 32 0
  3181. %int = OpTypeInt 32 1
  3182. %float = OpTypeFloat 32
  3183. %v4uint = OpTypeVector %uint 4
  3184. %scope_subgroup = OpConstant %uint 3
  3185. %uint_1 = OpConstant %uint 1
  3186. %int_1 = OpConstant %int 1
  3187. %float_1 = OpConstant %float 1
  3188. %uint4_1111 = OpConstantComposite %v4uint %uint_1 %uint_1 %uint_1 %uint_1
  3189. %true = OpConstantTrue %bool
  3190. %3 = OpTypeFunction %void
  3191. %main = OpFunction %void None %3
  3192. %6 = OpLabel
  3193. %7 = )" + test_case.opcode +
  3194. " %" + test_case.resultType + " %scope_subgroup " +
  3195. operation + " %" + test_case.operand +
  3196. R"( %uint4_1111
  3197. OpReturn
  3198. OpFunctionEnd;
  3199. )";
  3200. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  3201. kTest, /* do_validation= */ true);
  3202. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  3203. }
  3204. INSTANTIATE_TEST_SUITE_P(
  3205. TrimCapabilitiesPassTestSubgroupNV_Unsigned_I,
  3206. TrimCapabilitiesPassTestSubgroupNV_Unsigned,
  3207. ::testing::Combine(::testing::ValuesIn(kSubgroupTestCases),
  3208. ::testing::Values("PartitionedReduceNV",
  3209. "PartitionedInclusiveScanNV",
  3210. "PartitionedExclusiveScanNV")),
  3211. [](const ::testing::TestParamInfo<
  3212. TrimCapabilitiesPassTestSubgroupNV_Unsigned::ParamType>& info) {
  3213. return std::get<0>(info.param).opcode + "_" + std::get<1>(info.param);
  3214. });
  3215. using TrimCapabilitiesPassTestSubgroupArithmetic_Unsigned = PassTest<
  3216. ::testing::TestWithParam<std::tuple<SubgroupTestCase, std::string>>>;
  3217. TEST_P(TrimCapabilitiesPassTestSubgroupArithmetic_Unsigned,
  3218. GroupNonUniformPartitionedArithmetic_Remains) {
  3219. SubgroupTestCase test_case = std::get<0>(GetParam());
  3220. const std::string operation = std::get<1>(GetParam());
  3221. const std::string kTest = R"(
  3222. OpCapability Shader
  3223. OpCapability GroupNonUniformVote
  3224. ; CHECK-NOT: OpCapability GroupNonUniformVote
  3225. OpCapability GroupNonUniformArithmetic
  3226. ; CHECK: OpCapability GroupNonUniformArithmetic
  3227. OpCapability GroupNonUniformClustered
  3228. ; CHECK-NOT: OpCapability GroupNonUniformClustered
  3229. OpCapability GroupNonUniformPartitionedNV
  3230. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  3231. OpCapability GroupNonUniform
  3232. ; CHECK-NOT: OpCapability GroupNonUniform
  3233. OpExtension "SPV_NV_shader_subgroup_partitioned"
  3234. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  3235. OpMemoryModel Logical GLSL450
  3236. OpEntryPoint GLCompute %main "main"
  3237. OpExecutionMode %main LocalSize 1 2 4
  3238. %void = OpTypeVoid
  3239. %bool = OpTypeBool
  3240. %uint = OpTypeInt 32 0
  3241. %int = OpTypeInt 32 1
  3242. %float = OpTypeFloat 32
  3243. %v4uint = OpTypeVector %uint 4
  3244. %scope_subgroup = OpConstant %uint 3
  3245. %uint_1 = OpConstant %uint 1
  3246. %int_1 = OpConstant %int 1
  3247. %float_1 = OpConstant %float 1
  3248. %uint4_1111 = OpConstantComposite %v4uint %uint_1 %uint_1 %uint_1 %uint_1
  3249. %true = OpConstantTrue %bool
  3250. %3 = OpTypeFunction %void
  3251. %main = OpFunction %void None %3
  3252. %6 = OpLabel
  3253. %7 = )" + test_case.opcode +
  3254. " %" + test_case.resultType + " %scope_subgroup " +
  3255. operation + " %" + test_case.operand + R"( %uint_1
  3256. OpReturn
  3257. OpFunctionEnd;
  3258. )";
  3259. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  3260. kTest, /* do_validation= */ true);
  3261. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  3262. }
  3263. INSTANTIATE_TEST_SUITE_P(
  3264. TrimCapabilitiesPassTestSubgroupArithmetic_Unsigned_I,
  3265. TrimCapabilitiesPassTestSubgroupArithmetic_Unsigned,
  3266. ::testing::Combine(::testing::ValuesIn(kSubgroupTestCases),
  3267. ::testing::Values("Reduce", "InclusiveScan",
  3268. "ExclusiveScan")),
  3269. [](const ::testing::TestParamInfo<
  3270. TrimCapabilitiesPassTestSubgroupArithmetic_Unsigned::ParamType>& info) {
  3271. return std::get<0>(info.param).opcode + "_" + std::get<1>(info.param);
  3272. });
  3273. using TrimCapabilitiesPassTestSubgroupClustered_Unsigned = PassTest<
  3274. ::testing::TestWithParam<std::tuple<SubgroupTestCase, std::string>>>;
  3275. TEST_P(TrimCapabilitiesPassTestSubgroupClustered_Unsigned,
  3276. GroupNonUniformPartitionedClustered_Remains) {
  3277. SubgroupTestCase test_case = std::get<0>(GetParam());
  3278. const std::string operation = std::get<1>(GetParam());
  3279. const std::string kTest = R"(
  3280. OpCapability Shader
  3281. OpCapability GroupNonUniformVote
  3282. ; CHECK-NOT: OpCapability GroupNonUniformVote
  3283. OpCapability GroupNonUniformArithmetic
  3284. ; CHECK-NOT: OpCapability GroupNonUniformArithmetic
  3285. OpCapability GroupNonUniformClustered
  3286. ; CHECK: OpCapability GroupNonUniformClustered
  3287. OpCapability GroupNonUniformPartitionedNV
  3288. ; CHECK-NOT: OpCapability GroupNonUniformPartitionedNV
  3289. OpCapability GroupNonUniform
  3290. ; CHECK-NOT: OpCapability GroupNonUniform
  3291. OpExtension "SPV_NV_shader_subgroup_partitioned"
  3292. ; CHECK-NOT: OpExtension "SPV_NV_shader_subgroup_partitioned"
  3293. OpMemoryModel Logical GLSL450
  3294. OpEntryPoint GLCompute %main "main"
  3295. OpExecutionMode %main LocalSize 1 2 4
  3296. %void = OpTypeVoid
  3297. %bool = OpTypeBool
  3298. %uint = OpTypeInt 32 0
  3299. %int = OpTypeInt 32 1
  3300. %float = OpTypeFloat 32
  3301. %v4uint = OpTypeVector %uint 4
  3302. %scope_subgroup = OpConstant %uint 3
  3303. %uint_1 = OpConstant %uint 1
  3304. %int_1 = OpConstant %int 1
  3305. %float_1 = OpConstant %float 1
  3306. %uint4_1111 = OpConstantComposite %v4uint %uint_1 %uint_1 %uint_1 %uint_1
  3307. %true = OpConstantTrue %bool
  3308. %3 = OpTypeFunction %void
  3309. %main = OpFunction %void None %3
  3310. %6 = OpLabel
  3311. %7 = )" + test_case.opcode +
  3312. " %" + test_case.resultType + " %scope_subgroup " +
  3313. operation + " %" + test_case.operand + R"( %uint_1
  3314. OpReturn
  3315. OpFunctionEnd;
  3316. )";
  3317. const auto result = SinglePassRunAndMatch<TrimCapabilitiesPass>(
  3318. kTest, /* do_validation= */ true);
  3319. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  3320. }
  3321. TEST_F(TrimCapabilitiesPassTest, InterpolationFunction_RemovedIfNotUsed) {
  3322. const std::string kTest = R"(
  3323. OpCapability Shader
  3324. OpCapability InterpolationFunction
  3325. ; CHECK-NOT: OpCapability InterpolationFunction
  3326. OpMemoryModel Logical GLSL450
  3327. OpEntryPoint Fragment %main "main" %out_var_SV_Target
  3328. OpExecutionMode %main OriginUpperLeft
  3329. OpSource HLSL 660
  3330. OpName %out_var_SV_Target "out.var.SV_Target"
  3331. OpName %main "main"
  3332. OpDecorate %out_var_SV_Target Location 0
  3333. %float = OpTypeFloat 32
  3334. %v4float = OpTypeVector %float 4
  3335. %_ptr_Output_v4float = OpTypePointer Output %v4float
  3336. %void = OpTypeVoid
  3337. %7 = OpTypeFunction %void
  3338. %out_var_SV_Target = OpVariable %_ptr_Output_v4float Output
  3339. %main = OpFunction %void None %7
  3340. %8 = OpLabel
  3341. OpReturn
  3342. OpFunctionEnd
  3343. )";
  3344. const auto result =
  3345. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  3346. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
  3347. }
  3348. TEST_F(TrimCapabilitiesPassTest,
  3349. InterpolationFunction_RemainsWithInterpolateAtCentroid) {
  3350. const std::string kTest = R"(
  3351. OpCapability Shader
  3352. OpCapability InterpolationFunction
  3353. ; CHECK: OpCapability InterpolationFunction
  3354. %std450 = OpExtInstImport "GLSL.std.450"
  3355. OpMemoryModel Logical GLSL450
  3356. OpEntryPoint Fragment %main "main" %out_var_SV_Target %gl_PointCoord
  3357. OpExecutionMode %main OriginUpperLeft
  3358. OpSource HLSL 660
  3359. OpName %out_var_SV_Target "out.var.SV_Target"
  3360. OpName %main "main"
  3361. OpDecorate %out_var_SV_Target Location 0
  3362. OpDecorate %gl_PointCoord BuiltIn PointCoord
  3363. %float = OpTypeFloat 32
  3364. %v2float = OpTypeVector %float 2
  3365. %v4float = OpTypeVector %float 4
  3366. %_ptr_Output_v4float = OpTypePointer Output %v4float
  3367. %_ptr_Input_v2float = OpTypePointer Input %v2float
  3368. %void = OpTypeVoid
  3369. %7 = OpTypeFunction %void
  3370. %out_var_SV_Target = OpVariable %_ptr_Output_v4float Output
  3371. %gl_PointCoord = OpVariable %_ptr_Input_v2float Input
  3372. %main = OpFunction %void None %7
  3373. %8 = OpLabel
  3374. %9 = OpExtInst %v4float %std450 InterpolateAtCentroid %gl_PointCoord
  3375. OpReturn
  3376. OpFunctionEnd
  3377. )";
  3378. const auto result =
  3379. SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
  3380. EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
  3381. }
  3382. INSTANTIATE_TEST_SUITE_P(
  3383. TrimCapabilitiesPassTestSubgroupClustered_Unsigned_I,
  3384. TrimCapabilitiesPassTestSubgroupClustered_Unsigned,
  3385. ::testing::Combine(::testing::ValuesIn(kSubgroupTestCases),
  3386. ::testing::Values("ClusteredReduce")),
  3387. [](const ::testing::TestParamInfo<
  3388. TrimCapabilitiesPassTestSubgroupClustered_Unsigned::ParamType>& info) {
  3389. return std::get<0>(info.param).opcode + "_" + std::get<1>(info.param);
  3390. });
  3391. } // namespace
  3392. } // namespace opt
  3393. } // namespace spvtools