val_capability_test.cpp 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982
  1. // Copyright (c) 2015-2016 The Khronos Group Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Validation tests for Logical Layout
  15. #include <sstream>
  16. #include <string>
  17. #include <tuple>
  18. #include <utility>
  19. #include <vector>
  20. #include "gmock/gmock.h"
  21. #include "source/assembly_grammar.h"
  22. #include "source/spirv_target_env.h"
  23. #include "spirv-tools/libspirv.h"
  24. #include "test/test_fixture.h"
  25. #include "test/unit_spirv.h"
  26. #include "test/val/val_fixtures.h"
  27. namespace spvtools {
  28. namespace val {
  29. namespace {
  30. using spvtest::ScopedContext;
  31. using testing::Combine;
  32. using testing::Eq;
  33. using testing::HasSubstr;
  34. using testing::Values;
  35. using testing::ValuesIn;
  36. // Parameter for validation test fixtures. The first std::string is a
  37. // capability name that will begin the assembly under test, the second the
  38. // remainder assembly, and the std::vector at the end determines whether the
  39. // test expects success or failure. See below for details and convenience
  40. // methods to access each one.
  41. //
  42. // The assembly to test is composed from a variable top line and a fixed
  43. // remainder. The top line will be an OpCapability instruction, while the
  44. // remainder will be some assembly text that succeeds or fails to assemble
  45. // depending on which capability was chosen. For instance, the following will
  46. // succeed:
  47. //
  48. // OpCapability Pipes ; implies Kernel
  49. // OpLifetimeStop %1 0 ; requires Kernel
  50. //
  51. // and the following will fail:
  52. //
  53. // OpCapability Kernel
  54. // %1 = OpTypeNamedBarrier ; requires NamedBarrier
  55. //
  56. // So how does the test parameter capture which capabilities should cause
  57. // success and which shouldn't? The answer is in the last element: it's a
  58. // std::vector of capabilities that make the remainder assembly succeed. So if
  59. // the first-line capability exists in that std::vector, success is expected;
  60. // otherwise, failure is expected in the tests.
  61. //
  62. // We will use testing::Combine() to vary the first line: when we combine
  63. // AllCapabilities() with a single remainder assembly, we generate enough test
  64. // cases to try the assembly with every possible capability that could be
  65. // declared. However, Combine() only produces tuples -- it cannot produce, say,
  66. // a struct. Therefore, this type must be a tuple.
  67. using CapTestParameter =
  68. std::tuple<std::string, std::pair<std::string, std::vector<std::string>>>;
  69. const std::string& Capability(const CapTestParameter& p) {
  70. return std::get<0>(p);
  71. }
  72. const std::string& Remainder(const CapTestParameter& p) {
  73. return std::get<1>(p).first;
  74. }
  75. const std::vector<std::string>& MustSucceed(const CapTestParameter& p) {
  76. return std::get<1>(p).second;
  77. }
  78. // Creates assembly to test from p.
  79. std::string MakeAssembly(const CapTestParameter& p) {
  80. std::ostringstream ss;
  81. const std::string& capability = Capability(p);
  82. if (!capability.empty()) {
  83. ss << "OpCapability " << capability << "\n";
  84. }
  85. ss << Remainder(p);
  86. return ss.str();
  87. }
  88. // Expected validation result for p.
  89. spv_result_t ExpectedResult(const CapTestParameter& p) {
  90. const auto& caps = MustSucceed(p);
  91. auto found = find(begin(caps), end(caps), Capability(p));
  92. return (found == end(caps)) ? SPV_ERROR_INVALID_CAPABILITY : SPV_SUCCESS;
  93. }
  94. // Assembles using v1.0, unless the parameter's capability requires v1.1.
  95. using ValidateCapability = spvtest::ValidateBase<CapTestParameter>;
  96. // Always assembles using v1.1.
  97. using ValidateCapabilityV11 = spvtest::ValidateBase<CapTestParameter>;
  98. // Always assembles using Vulkan 1.0.
  99. // TODO(dneto): Refactor all these tests to scale better across environments.
  100. using ValidateCapabilityVulkan10 = spvtest::ValidateBase<CapTestParameter>;
  101. // Always assembles using OpenGL 4.0.
  102. using ValidateCapabilityOpenGL40 = spvtest::ValidateBase<CapTestParameter>;
  103. // Always assembles using Vulkan 1.1.
  104. using ValidateCapabilityVulkan11 = spvtest::ValidateBase<CapTestParameter>;
  105. // Always assembles using Vulkan 1.2.
  106. using ValidateCapabilityVulkan12 = spvtest::ValidateBase<CapTestParameter>;
  107. TEST_F(ValidateCapability, Default) {
  108. const char str[] = R"(
  109. OpCapability Kernel
  110. OpCapability Linkage
  111. OpCapability Matrix
  112. OpMemoryModel Logical OpenCL
  113. %f32 = OpTypeFloat 32
  114. %vec3 = OpTypeVector %f32 3
  115. %mat33 = OpTypeMatrix %vec3 3
  116. )";
  117. CompileSuccessfully(str);
  118. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  119. }
  120. // clang-format off
  121. const std::vector<std::string>& AllCapabilities() {
  122. static const auto r = new std::vector<std::string>{
  123. "",
  124. "Matrix",
  125. "Shader",
  126. "Geometry",
  127. "Tessellation",
  128. "Addresses",
  129. "Linkage",
  130. "Kernel",
  131. "Vector16",
  132. "Float16Buffer",
  133. "Float16",
  134. "Float64",
  135. "Int64",
  136. "Int64Atomics",
  137. "ImageBasic",
  138. "ImageReadWrite",
  139. "ImageMipmap",
  140. "Pipes",
  141. "Groups",
  142. "DeviceEnqueue",
  143. "LiteralSampler",
  144. "AtomicStorage",
  145. "Int16",
  146. "TessellationPointSize",
  147. "GeometryPointSize",
  148. "ImageGatherExtended",
  149. "StorageImageMultisample",
  150. "UniformBufferArrayDynamicIndexing",
  151. "SampledImageArrayDynamicIndexing",
  152. "StorageBufferArrayDynamicIndexing",
  153. "StorageImageArrayDynamicIndexing",
  154. "ClipDistance",
  155. "CullDistance",
  156. "ImageCubeArray",
  157. "SampleRateShading",
  158. "ImageRect",
  159. "SampledRect",
  160. "GenericPointer",
  161. "Int8",
  162. "InputAttachment",
  163. "SparseResidency",
  164. "MinLod",
  165. "Sampled1D",
  166. "Image1D",
  167. "SampledCubeArray",
  168. "SampledBuffer",
  169. "ImageBuffer",
  170. "ImageMSArray",
  171. "StorageImageExtendedFormats",
  172. "ImageQuery",
  173. "DerivativeControl",
  174. "InterpolationFunction",
  175. "TransformFeedback",
  176. "GeometryStreams",
  177. "StorageImageReadWithoutFormat",
  178. "StorageImageWriteWithoutFormat",
  179. "MultiViewport",
  180. "SubgroupDispatch",
  181. "NamedBarrier",
  182. "PipeStorage",
  183. "GroupNonUniform",
  184. "GroupNonUniformVote",
  185. "GroupNonUniformArithmetic",
  186. "GroupNonUniformBallot",
  187. "GroupNonUniformShuffle",
  188. "GroupNonUniformShuffleRelative",
  189. "GroupNonUniformClustered",
  190. "GroupNonUniformQuad",
  191. "DrawParameters",
  192. "StorageBuffer16BitAccess",
  193. "StorageUniformBufferBlock16",
  194. "UniformAndStorageBuffer16BitAccess",
  195. "StorageUniform16",
  196. "StoragePushConstant16",
  197. "StorageInputOutput16",
  198. "DeviceGroup",
  199. "MultiView",
  200. "VariablePointersStorageBuffer",
  201. "VariablePointers"};
  202. return *r;
  203. }
  204. const std::vector<std::string>& AllSpirV15Capabilities() {
  205. static const auto r = new std::vector<std::string>{
  206. "",
  207. "Matrix",
  208. "Shader",
  209. "Geometry",
  210. "Tessellation",
  211. "Addresses",
  212. "Linkage",
  213. "Kernel",
  214. "Vector16",
  215. "Float16Buffer",
  216. "Float16",
  217. "Float64",
  218. "Int64",
  219. "Int64Atomics",
  220. "ImageBasic",
  221. "ImageReadWrite",
  222. "ImageMipmap",
  223. "Pipes",
  224. "Groups",
  225. "DeviceEnqueue",
  226. "LiteralSampler",
  227. "AtomicStorage",
  228. "Int16",
  229. "TessellationPointSize",
  230. "GeometryPointSize",
  231. "ImageGatherExtended",
  232. "StorageImageMultisample",
  233. "UniformBufferArrayDynamicIndexing",
  234. "SampledImageArrayDynamicIndexing",
  235. "StorageBufferArrayDynamicIndexing",
  236. "StorageImageArrayDynamicIndexing",
  237. "ClipDistance",
  238. "CullDistance",
  239. "ImageCubeArray",
  240. "SampleRateShading",
  241. "ImageRect",
  242. "SampledRect",
  243. "GenericPointer",
  244. "Int8",
  245. "InputAttachment",
  246. "SparseResidency",
  247. "MinLod",
  248. "Sampled1D",
  249. "Image1D",
  250. "SampledCubeArray",
  251. "SampledBuffer",
  252. "ImageBuffer",
  253. "ImageMSArray",
  254. "StorageImageExtendedFormats",
  255. "ImageQuery",
  256. "DerivativeControl",
  257. "InterpolationFunction",
  258. "TransformFeedback",
  259. "GeometryStreams",
  260. "StorageImageReadWithoutFormat",
  261. "StorageImageWriteWithoutFormat",
  262. "MultiViewport",
  263. "SubgroupDispatch",
  264. "NamedBarrier",
  265. "PipeStorage",
  266. "GroupNonUniform",
  267. "GroupNonUniformVote",
  268. "GroupNonUniformArithmetic",
  269. "GroupNonUniformBallot",
  270. "GroupNonUniformShuffle",
  271. "GroupNonUniformShuffleRelative",
  272. "GroupNonUniformClustered",
  273. "GroupNonUniformQuad",
  274. "DrawParameters",
  275. "StorageBuffer16BitAccess",
  276. "StorageUniformBufferBlock16",
  277. "UniformAndStorageBuffer16BitAccess",
  278. "StorageUniform16",
  279. "StoragePushConstant16",
  280. "StorageInputOutput16",
  281. "DeviceGroup",
  282. "MultiView",
  283. "VariablePointersStorageBuffer",
  284. "VariablePointers",
  285. "DenormPreserve",
  286. "DenormFlushToZero",
  287. "SignedZeroInfNanPreserve",
  288. "RoundingModeRTE",
  289. "RoundingModeRTZ",
  290. // Omitted due to extra validation requirements on memory model.
  291. //"VulkanMemoryModel",
  292. //"VulkanMemoryModelDeviceScope",
  293. "StorageBuffer8BitAccess",
  294. "UniformAndStorageBuffer8BitAccess",
  295. "StoragePushConstant8",
  296. "ShaderViewportIndex",
  297. "ShaderLayer",
  298. "PhysicalStorageBufferAddresses",
  299. "RuntimeDescriptorArray",
  300. "UniformTexelBufferArrayDynamicIndexing",
  301. "StorageTexelBufferArrayDynamicIndexing",
  302. "UniformBufferArrayNonUniformIndexing",
  303. "SampledImageArrayNonUniformIndexing",
  304. "StorageBufferArrayNonUniformIndexing",
  305. "StorageImageArrayNonUniformIndexing",
  306. "InputAttachmentArrayNonUniformIndexing",
  307. "UniformTexelBufferArrayNonUniformIndexing",
  308. "StorageTexelBufferArrayNonUniformIndexing"};
  309. return *r;
  310. }
  311. const std::vector<std::string>& AllSpirV10Capabilities() {
  312. static const auto r = new std::vector<std::string>{
  313. "",
  314. "Matrix",
  315. "Shader",
  316. "Geometry",
  317. "Tessellation",
  318. "Addresses",
  319. "Linkage",
  320. "Kernel",
  321. "Vector16",
  322. "Float16Buffer",
  323. "Float16",
  324. "Float64",
  325. "Int64",
  326. "Int64Atomics",
  327. "ImageBasic",
  328. "ImageReadWrite",
  329. "ImageMipmap",
  330. "Pipes",
  331. "Groups",
  332. "DeviceEnqueue",
  333. "LiteralSampler",
  334. "AtomicStorage",
  335. "Int16",
  336. "TessellationPointSize",
  337. "GeometryPointSize",
  338. "ImageGatherExtended",
  339. "StorageImageMultisample",
  340. "UniformBufferArrayDynamicIndexing",
  341. "SampledImageArrayDynamicIndexing",
  342. "StorageBufferArrayDynamicIndexing",
  343. "StorageImageArrayDynamicIndexing",
  344. "ClipDistance",
  345. "CullDistance",
  346. "ImageCubeArray",
  347. "SampleRateShading",
  348. "ImageRect",
  349. "SampledRect",
  350. "GenericPointer",
  351. "Int8",
  352. "InputAttachment",
  353. "SparseResidency",
  354. "MinLod",
  355. "Sampled1D",
  356. "Image1D",
  357. "SampledCubeArray",
  358. "SampledBuffer",
  359. "ImageBuffer",
  360. "ImageMSArray",
  361. "StorageImageExtendedFormats",
  362. "ImageQuery",
  363. "DerivativeControl",
  364. "InterpolationFunction",
  365. "TransformFeedback",
  366. "GeometryStreams",
  367. "StorageImageReadWithoutFormat",
  368. "StorageImageWriteWithoutFormat",
  369. "MultiViewport"};
  370. return *r;
  371. }
  372. const std::vector<std::string>& AllVulkan10Capabilities() {
  373. static const auto r = new std::vector<std::string>{
  374. "",
  375. "Matrix",
  376. "Shader",
  377. "InputAttachment",
  378. "Sampled1D",
  379. "Image1D",
  380. "SampledBuffer",
  381. "ImageBuffer",
  382. "ImageQuery",
  383. "DerivativeControl",
  384. "Geometry",
  385. "Tessellation",
  386. "Float16",
  387. "Float64",
  388. "Int64",
  389. "Int64Atomics",
  390. "Int16",
  391. "TessellationPointSize",
  392. "GeometryPointSize",
  393. "ImageGatherExtended",
  394. "StorageImageMultisample",
  395. "UniformBufferArrayDynamicIndexing",
  396. "SampledImageArrayDynamicIndexing",
  397. "StorageBufferArrayDynamicIndexing",
  398. "StorageImageArrayDynamicIndexing",
  399. "ClipDistance",
  400. "CullDistance",
  401. "ImageCubeArray",
  402. "SampleRateShading",
  403. "Int8",
  404. "SparseResidency",
  405. "MinLod",
  406. "SampledCubeArray",
  407. "ImageMSArray",
  408. "StorageImageExtendedFormats",
  409. "InterpolationFunction",
  410. "StorageImageReadWithoutFormat",
  411. "StorageImageWriteWithoutFormat",
  412. "MultiViewport",
  413. "TransformFeedback",
  414. "GeometryStreams"};
  415. return *r;
  416. }
  417. const std::vector<std::string>& AllVulkan11Capabilities() {
  418. static const auto r = new std::vector<std::string>{
  419. "",
  420. "Matrix",
  421. "Shader",
  422. "InputAttachment",
  423. "Sampled1D",
  424. "Image1D",
  425. "SampledBuffer",
  426. "ImageBuffer",
  427. "ImageQuery",
  428. "DerivativeControl",
  429. "Geometry",
  430. "Tessellation",
  431. "Float16",
  432. "Float64",
  433. "Int64",
  434. "Int64Atomics",
  435. "Int16",
  436. "TessellationPointSize",
  437. "GeometryPointSize",
  438. "ImageGatherExtended",
  439. "StorageImageMultisample",
  440. "UniformBufferArrayDynamicIndexing",
  441. "SampledImageArrayDynamicIndexing",
  442. "StorageBufferArrayDynamicIndexing",
  443. "StorageImageArrayDynamicIndexing",
  444. "ClipDistance",
  445. "CullDistance",
  446. "ImageCubeArray",
  447. "SampleRateShading",
  448. "Int8",
  449. "SparseResidency",
  450. "MinLod",
  451. "SampledCubeArray",
  452. "ImageMSArray",
  453. "StorageImageExtendedFormats",
  454. "InterpolationFunction",
  455. "StorageImageReadWithoutFormat",
  456. "StorageImageWriteWithoutFormat",
  457. "MultiViewport",
  458. "GroupNonUniform",
  459. "GroupNonUniformVote",
  460. "GroupNonUniformArithmetic",
  461. "GroupNonUniformBallot",
  462. "GroupNonUniformShuffle",
  463. "GroupNonUniformShuffleRelative",
  464. "GroupNonUniformClustered",
  465. "GroupNonUniformQuad",
  466. "DrawParameters",
  467. "StorageBuffer16BitAccess",
  468. "StorageUniformBufferBlock16",
  469. "UniformAndStorageBuffer16BitAccess",
  470. "StorageUniform16",
  471. "StoragePushConstant16",
  472. "StorageInputOutput16",
  473. "DeviceGroup",
  474. "MultiView",
  475. "VariablePointersStorageBuffer",
  476. "VariablePointers",
  477. "TransformFeedback",
  478. "GeometryStreams"};
  479. return *r;
  480. }
  481. const std::vector<std::string>& AllVulkan12Capabilities() {
  482. static const auto r = new std::vector<std::string>{
  483. "",
  484. "Matrix",
  485. "Shader",
  486. "InputAttachment",
  487. "Sampled1D",
  488. "Image1D",
  489. "SampledBuffer",
  490. "ImageBuffer",
  491. "ImageQuery",
  492. "DerivativeControl",
  493. "Geometry",
  494. "Tessellation",
  495. "Float16",
  496. "Float64",
  497. "Int64",
  498. "Int64Atomics",
  499. "Int16",
  500. "TessellationPointSize",
  501. "GeometryPointSize",
  502. "ImageGatherExtended",
  503. "StorageImageMultisample",
  504. "UniformBufferArrayDynamicIndexing",
  505. "SampledImageArrayDynamicIndexing",
  506. "StorageBufferArrayDynamicIndexing",
  507. "StorageImageArrayDynamicIndexing",
  508. "ClipDistance",
  509. "CullDistance",
  510. "ImageCubeArray",
  511. "SampleRateShading",
  512. "Int8",
  513. "SparseResidency",
  514. "MinLod",
  515. "SampledCubeArray",
  516. "ImageMSArray",
  517. "StorageImageExtendedFormats",
  518. "InterpolationFunction",
  519. "StorageImageReadWithoutFormat",
  520. "StorageImageWriteWithoutFormat",
  521. "MultiViewport",
  522. "GroupNonUniform",
  523. "GroupNonUniformVote",
  524. "GroupNonUniformArithmetic",
  525. "GroupNonUniformBallot",
  526. "GroupNonUniformShuffle",
  527. "GroupNonUniformShuffleRelative",
  528. "GroupNonUniformClustered",
  529. "GroupNonUniformQuad",
  530. "DrawParameters",
  531. "StorageBuffer16BitAccess",
  532. "StorageUniformBufferBlock16",
  533. "UniformAndStorageBuffer16BitAccess",
  534. "StorageUniform16",
  535. "StoragePushConstant16",
  536. "StorageInputOutput16",
  537. "DeviceGroup",
  538. "MultiView",
  539. "VariablePointersStorageBuffer",
  540. "VariablePointers",
  541. "TransformFeedback",
  542. "GeometryStreams",
  543. "DenormPreserve",
  544. "DenormFlushToZero",
  545. "SignedZeroInfNanPreserve",
  546. "RoundingModeRTE",
  547. "RoundingModeRTZ",
  548. "VulkanMemoryModel",
  549. "VulkanMemoryModelDeviceScope",
  550. "StorageBuffer8BitAccess",
  551. "UniformAndStorageBuffer8BitAccess",
  552. "StoragePushConstant8",
  553. "ShaderViewportIndex",
  554. "ShaderLayer",
  555. "PhysicalStorageBufferAddresses",
  556. "RuntimeDescriptorArray",
  557. "UniformTexelBufferArrayDynamicIndexing",
  558. "StorageTexelBufferArrayDynamicIndexing",
  559. "UniformBufferArrayNonUniformIndexing",
  560. "SampledImageArrayNonUniformIndexing",
  561. "StorageBufferArrayNonUniformIndexing",
  562. "StorageImageArrayNonUniformIndexing",
  563. "InputAttachmentArrayNonUniformIndexing",
  564. "UniformTexelBufferArrayNonUniformIndexing",
  565. "StorageTexelBufferArrayNonUniformIndexing"};
  566. return *r;
  567. }
  568. const std::vector<std::string>& MatrixDependencies() {
  569. static const auto r = new std::vector<std::string>{
  570. "Matrix",
  571. "Shader",
  572. "Geometry",
  573. "Tessellation",
  574. "AtomicStorage",
  575. "TessellationPointSize",
  576. "GeometryPointSize",
  577. "ImageGatherExtended",
  578. "StorageImageMultisample",
  579. "UniformBufferArrayDynamicIndexing",
  580. "SampledImageArrayDynamicIndexing",
  581. "StorageBufferArrayDynamicIndexing",
  582. "StorageImageArrayDynamicIndexing",
  583. "ClipDistance",
  584. "CullDistance",
  585. "ImageCubeArray",
  586. "SampleRateShading",
  587. "ImageRect",
  588. "SampledRect",
  589. "InputAttachment",
  590. "SparseResidency",
  591. "MinLod",
  592. "SampledCubeArray",
  593. "ImageMSArray",
  594. "StorageImageExtendedFormats",
  595. "ImageQuery",
  596. "DerivativeControl",
  597. "InterpolationFunction",
  598. "TransformFeedback",
  599. "GeometryStreams",
  600. "StorageImageReadWithoutFormat",
  601. "StorageImageWriteWithoutFormat",
  602. "MultiViewport",
  603. "DrawParameters",
  604. "MultiView",
  605. "VariablePointersStorageBuffer",
  606. "VariablePointers"};
  607. return *r;
  608. }
  609. const std::vector<std::string>& ShaderDependencies() {
  610. static const auto r = new std::vector<std::string>{
  611. "Shader",
  612. "Geometry",
  613. "Tessellation",
  614. "AtomicStorage",
  615. "TessellationPointSize",
  616. "GeometryPointSize",
  617. "ImageGatherExtended",
  618. "StorageImageMultisample",
  619. "UniformBufferArrayDynamicIndexing",
  620. "SampledImageArrayDynamicIndexing",
  621. "StorageBufferArrayDynamicIndexing",
  622. "StorageImageArrayDynamicIndexing",
  623. "ClipDistance",
  624. "CullDistance",
  625. "ImageCubeArray",
  626. "SampleRateShading",
  627. "ImageRect",
  628. "SampledRect",
  629. "InputAttachment",
  630. "SparseResidency",
  631. "MinLod",
  632. "SampledCubeArray",
  633. "ImageMSArray",
  634. "StorageImageExtendedFormats",
  635. "ImageQuery",
  636. "DerivativeControl",
  637. "InterpolationFunction",
  638. "TransformFeedback",
  639. "GeometryStreams",
  640. "StorageImageReadWithoutFormat",
  641. "StorageImageWriteWithoutFormat",
  642. "MultiViewport",
  643. "DrawParameters",
  644. "MultiView",
  645. "VariablePointersStorageBuffer",
  646. "VariablePointers"};
  647. return *r;
  648. }
  649. const std::vector<std::string>& TessellationDependencies() {
  650. static const auto r = new std::vector<std::string>{
  651. "Tessellation",
  652. "TessellationPointSize"};
  653. return *r;
  654. }
  655. const std::vector<std::string>& GeometryDependencies() {
  656. static const auto r = new std::vector<std::string>{
  657. "Geometry",
  658. "GeometryPointSize",
  659. "GeometryStreams",
  660. "MultiViewport"};
  661. return *r;
  662. }
  663. const std::vector<std::string>& GeometryTessellationDependencies() {
  664. static const auto r = new std::vector<std::string>{
  665. "Tessellation",
  666. "TessellationPointSize",
  667. "Geometry",
  668. "GeometryPointSize",
  669. "GeometryStreams",
  670. "MultiViewport"};
  671. return *r;
  672. }
  673. // Returns the names of capabilities that directly depend on Kernel,
  674. // plus itself.
  675. const std::vector<std::string>& KernelDependencies() {
  676. static const auto r = new std::vector<std::string>{
  677. "Kernel",
  678. "Vector16",
  679. "Float16Buffer",
  680. "ImageBasic",
  681. "ImageReadWrite",
  682. "ImageMipmap",
  683. "Pipes",
  684. "DeviceEnqueue",
  685. "LiteralSampler",
  686. "SubgroupDispatch",
  687. "NamedBarrier",
  688. "PipeStorage"};
  689. return *r;
  690. }
  691. const std::vector<std::string>& KernelAndGroupNonUniformDependencies() {
  692. static const auto r = new std::vector<std::string>{
  693. "Kernel",
  694. "Vector16",
  695. "Float16Buffer",
  696. "ImageBasic",
  697. "ImageReadWrite",
  698. "ImageMipmap",
  699. "Pipes",
  700. "DeviceEnqueue",
  701. "LiteralSampler",
  702. "SubgroupDispatch",
  703. "NamedBarrier",
  704. "PipeStorage",
  705. "GroupNonUniform",
  706. "GroupNonUniformVote",
  707. "GroupNonUniformArithmetic",
  708. "GroupNonUniformBallot",
  709. "GroupNonUniformShuffle",
  710. "GroupNonUniformShuffleRelative",
  711. "GroupNonUniformClustered",
  712. "GroupNonUniformQuad"};
  713. return *r;
  714. }
  715. const std::vector<std::string>& AddressesDependencies() {
  716. static const auto r = new std::vector<std::string>{
  717. "Addresses",
  718. "GenericPointer"};
  719. return *r;
  720. }
  721. const std::vector<std::string>& Sampled1DDependencies() {
  722. static const auto r = new std::vector<std::string>{
  723. "Sampled1D",
  724. "Image1D"};
  725. return *r;
  726. }
  727. const std::vector<std::string>& SampledRectDependencies() {
  728. static const auto r = new std::vector<std::string>{
  729. "SampledRect",
  730. "ImageRect"};
  731. return *r;
  732. }
  733. const std::vector<std::string>& SampledBufferDependencies() {
  734. static const auto r = new std::vector<std::string>{
  735. "SampledBuffer",
  736. "ImageBuffer"};
  737. return *r;
  738. }
  739. const char kOpenCLMemoryModel[] = \
  740. " OpCapability Kernel"
  741. " OpMemoryModel Logical OpenCL ";
  742. const char kGLSL450MemoryModel[] = \
  743. " OpCapability Shader"
  744. " OpMemoryModel Logical GLSL450 ";
  745. const char kVoidFVoid[] = \
  746. " %void = OpTypeVoid"
  747. " %void_f = OpTypeFunction %void"
  748. " %func = OpFunction %void None %void_f"
  749. " %label = OpLabel"
  750. " OpReturn"
  751. " OpFunctionEnd ";
  752. const char kVoidFVoid2[] = \
  753. " %void_f = OpTypeFunction %voidt"
  754. " %func = OpFunction %voidt None %void_f"
  755. " %label = OpLabel"
  756. " OpReturn"
  757. " OpFunctionEnd ";
  758. INSTANTIATE_TEST_SUITE_P(ExecutionModel, ValidateCapability,
  759. Combine(
  760. ValuesIn(AllCapabilities()),
  761. Values(
  762. std::make_pair(std::string(kOpenCLMemoryModel) +
  763. " OpEntryPoint Vertex %func \"shader\"" +
  764. std::string(kVoidFVoid), ShaderDependencies()),
  765. std::make_pair(std::string(kOpenCLMemoryModel) +
  766. " OpEntryPoint TessellationControl %func \"shader\"" +
  767. std::string(kVoidFVoid), TessellationDependencies()),
  768. std::make_pair(std::string(kOpenCLMemoryModel) +
  769. " OpEntryPoint TessellationEvaluation %func \"shader\"" +
  770. std::string(kVoidFVoid), TessellationDependencies()),
  771. std::make_pair(std::string(kOpenCLMemoryModel) +
  772. " OpEntryPoint Geometry %func \"shader\"" +
  773. " OpExecutionMode %func InputPoints" +
  774. " OpExecutionMode %func OutputPoints" +
  775. std::string(kVoidFVoid), GeometryDependencies()),
  776. std::make_pair(std::string(kOpenCLMemoryModel) +
  777. " OpEntryPoint Fragment %func \"shader\"" +
  778. " OpExecutionMode %func OriginUpperLeft" +
  779. std::string(kVoidFVoid), ShaderDependencies()),
  780. std::make_pair(std::string(kOpenCLMemoryModel) +
  781. " OpEntryPoint GLCompute %func \"shader\"" +
  782. std::string(kVoidFVoid), ShaderDependencies()),
  783. std::make_pair(std::string(kGLSL450MemoryModel) +
  784. " OpEntryPoint Kernel %func \"shader\"" +
  785. std::string(kVoidFVoid), KernelDependencies())
  786. )));
  787. INSTANTIATE_TEST_SUITE_P(AddressingAndMemoryModel, ValidateCapability,
  788. Combine(
  789. ValuesIn(AllCapabilities()),
  790. Values(
  791. std::make_pair(" OpCapability Shader"
  792. " OpMemoryModel Logical Simple"
  793. " OpEntryPoint Vertex %func \"shader\"" +
  794. std::string(kVoidFVoid), AllCapabilities()),
  795. std::make_pair(" OpCapability Shader"
  796. " OpMemoryModel Logical GLSL450"
  797. " OpEntryPoint Vertex %func \"shader\"" +
  798. std::string(kVoidFVoid), AllCapabilities()),
  799. std::make_pair(" OpCapability Kernel"
  800. " OpMemoryModel Logical OpenCL"
  801. " OpEntryPoint Kernel %func \"compute\"" +
  802. std::string(kVoidFVoid), AllCapabilities()),
  803. std::make_pair(" OpCapability Shader"
  804. " OpMemoryModel Physical32 Simple"
  805. " OpEntryPoint Vertex %func \"shader\"" +
  806. std::string(kVoidFVoid), AddressesDependencies()),
  807. std::make_pair(" OpCapability Shader"
  808. " OpMemoryModel Physical32 GLSL450"
  809. " OpEntryPoint Vertex %func \"shader\"" +
  810. std::string(kVoidFVoid), AddressesDependencies()),
  811. std::make_pair(" OpCapability Kernel"
  812. " OpMemoryModel Physical32 OpenCL"
  813. " OpEntryPoint Kernel %func \"compute\"" +
  814. std::string(kVoidFVoid), AddressesDependencies()),
  815. std::make_pair(" OpCapability Shader"
  816. " OpMemoryModel Physical64 Simple"
  817. " OpEntryPoint Vertex %func \"shader\"" +
  818. std::string(kVoidFVoid), AddressesDependencies()),
  819. std::make_pair(" OpCapability Shader"
  820. " OpMemoryModel Physical64 GLSL450"
  821. " OpEntryPoint Vertex %func \"shader\"" +
  822. std::string(kVoidFVoid), AddressesDependencies()),
  823. std::make_pair(" OpCapability Kernel"
  824. " OpMemoryModel Physical64 OpenCL"
  825. " OpEntryPoint Kernel %func \"compute\"" +
  826. std::string(kVoidFVoid), AddressesDependencies())
  827. )));
  828. INSTANTIATE_TEST_SUITE_P(ExecutionMode, ValidateCapability,
  829. Combine(
  830. ValuesIn(AllCapabilities()),
  831. Values(
  832. std::make_pair(std::string(kOpenCLMemoryModel) +
  833. "OpEntryPoint Geometry %func \"shader\" "
  834. "OpExecutionMode %func Invocations 42" +
  835. " OpExecutionMode %func InputPoints" +
  836. " OpExecutionMode %func OutputPoints" +
  837. std::string(kVoidFVoid), GeometryDependencies()),
  838. std::make_pair(std::string(kOpenCLMemoryModel) +
  839. "OpEntryPoint TessellationControl %func \"shader\" "
  840. "OpExecutionMode %func SpacingEqual" +
  841. std::string(kVoidFVoid), TessellationDependencies()),
  842. std::make_pair(std::string(kOpenCLMemoryModel) +
  843. "OpEntryPoint TessellationControl %func \"shader\" "
  844. "OpExecutionMode %func SpacingFractionalEven" +
  845. std::string(kVoidFVoid), TessellationDependencies()),
  846. std::make_pair(std::string(kOpenCLMemoryModel) +
  847. "OpEntryPoint TessellationControl %func \"shader\" "
  848. "OpExecutionMode %func SpacingFractionalOdd" +
  849. std::string(kVoidFVoid), TessellationDependencies()),
  850. std::make_pair(std::string(kOpenCLMemoryModel) +
  851. "OpEntryPoint TessellationControl %func \"shader\" "
  852. "OpExecutionMode %func VertexOrderCw" +
  853. std::string(kVoidFVoid), TessellationDependencies()),
  854. std::make_pair(std::string(kOpenCLMemoryModel) +
  855. "OpEntryPoint TessellationControl %func \"shader\" "
  856. "OpExecutionMode %func VertexOrderCcw" +
  857. std::string(kVoidFVoid), TessellationDependencies()),
  858. std::make_pair(std::string(kOpenCLMemoryModel) +
  859. "OpEntryPoint Fragment %func \"shader\" "
  860. "OpExecutionMode %func PixelCenterInteger" +
  861. " OpExecutionMode %func OriginUpperLeft" +
  862. std::string(kVoidFVoid), ShaderDependencies()),
  863. std::make_pair(std::string(kOpenCLMemoryModel) +
  864. "OpEntryPoint Fragment %func \"shader\" "
  865. "OpExecutionMode %func OriginUpperLeft" +
  866. std::string(kVoidFVoid), ShaderDependencies()),
  867. std::make_pair(std::string(kOpenCLMemoryModel) +
  868. "OpEntryPoint Fragment %func \"shader\" "
  869. "OpExecutionMode %func OriginLowerLeft" +
  870. std::string(kVoidFVoid), ShaderDependencies()),
  871. std::make_pair(std::string(kOpenCLMemoryModel) +
  872. "OpEntryPoint Fragment %func \"shader\" "
  873. "OpExecutionMode %func EarlyFragmentTests" +
  874. " OpExecutionMode %func OriginUpperLeft" +
  875. std::string(kVoidFVoid), ShaderDependencies()),
  876. std::make_pair(std::string(kOpenCLMemoryModel) +
  877. "OpEntryPoint TessellationControl %func \"shader\" "
  878. "OpExecutionMode %func PointMode" +
  879. std::string(kVoidFVoid), TessellationDependencies()),
  880. std::make_pair(std::string(kOpenCLMemoryModel) +
  881. "OpEntryPoint Vertex %func \"shader\" "
  882. "OpExecutionMode %func Xfb" +
  883. std::string(kVoidFVoid), std::vector<std::string>{"TransformFeedback"}),
  884. std::make_pair(std::string(kOpenCLMemoryModel) +
  885. "OpEntryPoint Fragment %func \"shader\" "
  886. "OpExecutionMode %func DepthReplacing" +
  887. " OpExecutionMode %func OriginUpperLeft" +
  888. std::string(kVoidFVoid), ShaderDependencies()),
  889. std::make_pair(std::string(kOpenCLMemoryModel) +
  890. "OpEntryPoint Fragment %func \"shader\" "
  891. "OpExecutionMode %func DepthGreater" +
  892. " OpExecutionMode %func OriginUpperLeft" +
  893. std::string(kVoidFVoid), ShaderDependencies()),
  894. std::make_pair(std::string(kOpenCLMemoryModel) +
  895. "OpEntryPoint Fragment %func \"shader\" "
  896. "OpExecutionMode %func DepthLess" +
  897. " OpExecutionMode %func OriginUpperLeft" +
  898. std::string(kVoidFVoid), ShaderDependencies()),
  899. std::make_pair(std::string(kOpenCLMemoryModel) +
  900. "OpEntryPoint Fragment %func \"shader\" "
  901. "OpExecutionMode %func DepthUnchanged" +
  902. " OpExecutionMode %func OriginUpperLeft" +
  903. std::string(kVoidFVoid), ShaderDependencies()),
  904. std::make_pair(std::string(kOpenCLMemoryModel) +
  905. "OpEntryPoint Kernel %func \"shader\" "
  906. "OpExecutionMode %func LocalSize 42 42 42" +
  907. std::string(kVoidFVoid), AllCapabilities()),
  908. std::make_pair(std::string(kGLSL450MemoryModel) +
  909. "OpEntryPoint Kernel %func \"shader\" "
  910. "OpExecutionMode %func LocalSizeHint 42 42 42" +
  911. std::string(kVoidFVoid), KernelDependencies()),
  912. std::make_pair(std::string(kOpenCLMemoryModel) +
  913. "OpEntryPoint Geometry %func \"shader\" "
  914. "OpExecutionMode %func InputPoints" +
  915. " OpExecutionMode %func OutputPoints" +
  916. std::string(kVoidFVoid), GeometryDependencies()),
  917. std::make_pair(std::string(kOpenCLMemoryModel) +
  918. "OpEntryPoint Geometry %func \"shader\" "
  919. "OpExecutionMode %func InputLines" +
  920. " OpExecutionMode %func OutputLineStrip" +
  921. std::string(kVoidFVoid), GeometryDependencies()),
  922. std::make_pair(std::string(kOpenCLMemoryModel) +
  923. "OpEntryPoint Geometry %func \"shader\" "
  924. "OpExecutionMode %func InputLinesAdjacency" +
  925. " OpExecutionMode %func OutputLineStrip" +
  926. std::string(kVoidFVoid), GeometryDependencies()),
  927. std::make_pair(std::string(kOpenCLMemoryModel) +
  928. "OpEntryPoint Geometry %func \"shader\" "
  929. "OpExecutionMode %func Triangles" +
  930. " OpExecutionMode %func OutputTriangleStrip" +
  931. std::string(kVoidFVoid), GeometryDependencies()),
  932. std::make_pair(std::string(kOpenCLMemoryModel) +
  933. "OpEntryPoint TessellationControl %func \"shader\" "
  934. "OpExecutionMode %func Triangles" +
  935. std::string(kVoidFVoid), TessellationDependencies()),
  936. std::make_pair(std::string(kOpenCLMemoryModel) +
  937. "OpEntryPoint Geometry %func \"shader\" "
  938. "OpExecutionMode %func InputTrianglesAdjacency" +
  939. " OpExecutionMode %func OutputTriangleStrip" +
  940. std::string(kVoidFVoid), GeometryDependencies()),
  941. std::make_pair(std::string(kOpenCLMemoryModel) +
  942. "OpEntryPoint TessellationControl %func \"shader\" "
  943. "OpExecutionMode %func Quads" +
  944. std::string(kVoidFVoid), TessellationDependencies()),
  945. std::make_pair(std::string(kOpenCLMemoryModel) +
  946. "OpEntryPoint TessellationControl %func \"shader\" "
  947. "OpExecutionMode %func Isolines" +
  948. std::string(kVoidFVoid), TessellationDependencies()),
  949. std::make_pair(std::string(kOpenCLMemoryModel) +
  950. "OpEntryPoint Geometry %func \"shader\" "
  951. "OpExecutionMode %func OutputVertices 42" +
  952. " OpExecutionMode %func OutputPoints" +
  953. " OpExecutionMode %func InputPoints" +
  954. std::string(kVoidFVoid), GeometryDependencies()),
  955. std::make_pair(std::string(kOpenCLMemoryModel) +
  956. "OpEntryPoint TessellationControl %func \"shader\" "
  957. "OpExecutionMode %func OutputVertices 42" +
  958. std::string(kVoidFVoid), TessellationDependencies()),
  959. std::make_pair(std::string(kOpenCLMemoryModel) +
  960. "OpEntryPoint Geometry %func \"shader\" "
  961. "OpExecutionMode %func OutputPoints" +
  962. " OpExecutionMode %func InputPoints" +
  963. std::string(kVoidFVoid), GeometryDependencies()),
  964. std::make_pair(std::string(kOpenCLMemoryModel) +
  965. "OpEntryPoint Geometry %func \"shader\" "
  966. "OpExecutionMode %func OutputLineStrip" +
  967. " OpExecutionMode %func InputLines" +
  968. std::string(kVoidFVoid), GeometryDependencies()),
  969. std::make_pair(std::string(kOpenCLMemoryModel) +
  970. "OpEntryPoint Geometry %func \"shader\" "
  971. "OpExecutionMode %func OutputTriangleStrip" +
  972. " OpExecutionMode %func Triangles" +
  973. std::string(kVoidFVoid), GeometryDependencies()),
  974. std::make_pair(std::string(kGLSL450MemoryModel) +
  975. "OpEntryPoint Kernel %func \"shader\" "
  976. "OpExecutionMode %func VecTypeHint 2" +
  977. std::string(kVoidFVoid), KernelDependencies()),
  978. std::make_pair(std::string(kGLSL450MemoryModel) +
  979. "OpEntryPoint Kernel %func \"shader\" "
  980. "OpExecutionMode %func ContractionOff" +
  981. std::string(kVoidFVoid), KernelDependencies()))));
  982. // clang-format on
  983. INSTANTIATE_TEST_SUITE_P(
  984. ExecutionModeV11, ValidateCapabilityV11,
  985. Combine(ValuesIn(AllCapabilities()),
  986. Values(std::make_pair(std::string(kOpenCLMemoryModel) +
  987. "OpEntryPoint Kernel %func \"shader\" "
  988. "OpExecutionMode %func SubgroupSize 1" +
  989. std::string(kVoidFVoid),
  990. std::vector<std::string>{"SubgroupDispatch"}),
  991. std::make_pair(
  992. std::string(kOpenCLMemoryModel) +
  993. "OpEntryPoint Kernel %func \"shader\" "
  994. "OpExecutionMode %func SubgroupsPerWorkgroup 65535" +
  995. std::string(kVoidFVoid),
  996. std::vector<std::string>{"SubgroupDispatch"}))));
  997. // clang-format off
  998. INSTANTIATE_TEST_SUITE_P(StorageClass, ValidateCapability,
  999. Combine(
  1000. ValuesIn(AllCapabilities()),
  1001. Values(
  1002. std::make_pair(std::string(kGLSL450MemoryModel) +
  1003. " OpEntryPoint Vertex %func \"shader\"" +
  1004. " %intt = OpTypeInt 32 0\n"
  1005. " %ptrt = OpTypePointer UniformConstant %intt\n"
  1006. " %var = OpVariable %ptrt UniformConstant\n" + std::string(kVoidFVoid),
  1007. AllCapabilities()),
  1008. std::make_pair(std::string(kOpenCLMemoryModel) +
  1009. " OpEntryPoint Kernel %func \"compute\"" +
  1010. " %intt = OpTypeInt 32 0\n"
  1011. " %ptrt = OpTypePointer Input %intt"
  1012. " %var = OpVariable %ptrt Input\n" + std::string(kVoidFVoid),
  1013. AllCapabilities()),
  1014. std::make_pair(std::string(kOpenCLMemoryModel) +
  1015. " OpEntryPoint Vertex %func \"shader\"" +
  1016. " %intt = OpTypeInt 32 0\n"
  1017. " %ptrt = OpTypePointer Uniform %intt\n"
  1018. " %var = OpVariable %ptrt Uniform\n" + std::string(kVoidFVoid),
  1019. ShaderDependencies()),
  1020. std::make_pair(std::string(kOpenCLMemoryModel) +
  1021. " OpEntryPoint Vertex %func \"shader\"" +
  1022. " %intt = OpTypeInt 32 0\n"
  1023. " %ptrt = OpTypePointer Output %intt\n"
  1024. " %var = OpVariable %ptrt Output\n" + std::string(kVoidFVoid),
  1025. ShaderDependencies()),
  1026. std::make_pair(std::string(kGLSL450MemoryModel) +
  1027. " OpEntryPoint Vertex %func \"shader\"" +
  1028. " %intt = OpTypeInt 32 0\n"
  1029. " %ptrt = OpTypePointer Workgroup %intt\n"
  1030. " %var = OpVariable %ptrt Workgroup\n" + std::string(kVoidFVoid),
  1031. AllCapabilities()),
  1032. std::make_pair(std::string(kGLSL450MemoryModel) +
  1033. " OpEntryPoint Vertex %func \"shader\"" +
  1034. " %intt = OpTypeInt 32 0\n"
  1035. " %ptrt = OpTypePointer CrossWorkgroup %intt\n"
  1036. " %var = OpVariable %ptrt CrossWorkgroup\n" + std::string(kVoidFVoid),
  1037. AllCapabilities()),
  1038. std::make_pair(std::string(kOpenCLMemoryModel) +
  1039. " OpEntryPoint Kernel %func \"compute\"" +
  1040. " %intt = OpTypeInt 32 0\n"
  1041. " %ptrt = OpTypePointer Private %intt\n"
  1042. " %var = OpVariable %ptrt Private\n" + std::string(kVoidFVoid),
  1043. ShaderDependencies()),
  1044. std::make_pair(std::string(kOpenCLMemoryModel) +
  1045. " OpEntryPoint Kernel %func \"compute\"" +
  1046. " %intt = OpTypeInt 32 0\n"
  1047. " %ptrt = OpTypePointer PushConstant %intt\n"
  1048. " %var = OpVariable %ptrt PushConstant\n" + std::string(kVoidFVoid),
  1049. ShaderDependencies()),
  1050. std::make_pair(std::string(kGLSL450MemoryModel) +
  1051. " OpEntryPoint Vertex %func \"shader\"" +
  1052. " %intt = OpTypeInt 32 0\n"
  1053. " %ptrt = OpTypePointer AtomicCounter %intt\n"
  1054. " %var = OpVariable %ptrt AtomicCounter\n" + std::string(kVoidFVoid),
  1055. std::vector<std::string>{"AtomicStorage"}),
  1056. std::make_pair(std::string(kGLSL450MemoryModel) +
  1057. " OpEntryPoint Vertex %func \"shader\"" +
  1058. " %intt = OpTypeInt 32 0\n"
  1059. " %ptrt = OpTypePointer Image %intt\n"
  1060. " %var = OpVariable %ptrt Image\n" + std::string(kVoidFVoid),
  1061. AllCapabilities())
  1062. )));
  1063. INSTANTIATE_TEST_SUITE_P(Dim, ValidateCapability,
  1064. Combine(
  1065. ValuesIn(AllCapabilities()),
  1066. Values(
  1067. std::make_pair(" OpCapability ImageBasic" +
  1068. std::string(kOpenCLMemoryModel) +
  1069. std::string(" OpEntryPoint Kernel %func \"compute\"") +
  1070. " %voidt = OpTypeVoid"
  1071. " %imgt = OpTypeImage %voidt 1D 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
  1072. Sampled1DDependencies()),
  1073. std::make_pair(" OpCapability ImageBasic" +
  1074. std::string(kOpenCLMemoryModel) +
  1075. std::string(" OpEntryPoint Kernel %func \"compute\"") +
  1076. " %voidt = OpTypeVoid"
  1077. " %imgt = OpTypeImage %voidt 2D 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
  1078. AllCapabilities()),
  1079. std::make_pair(" OpCapability ImageBasic" +
  1080. std::string(kOpenCLMemoryModel) +
  1081. std::string(" OpEntryPoint Kernel %func \"compute\"") +
  1082. " %voidt = OpTypeVoid"
  1083. " %imgt = OpTypeImage %voidt 3D 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
  1084. AllCapabilities()),
  1085. std::make_pair(" OpCapability ImageBasic" +
  1086. std::string(kOpenCLMemoryModel) +
  1087. std::string(" OpEntryPoint Kernel %func \"compute\"") +
  1088. " %voidt = OpTypeVoid"
  1089. " %imgt = OpTypeImage %voidt Cube 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
  1090. ShaderDependencies()),
  1091. std::make_pair(" OpCapability ImageBasic" +
  1092. std::string(kOpenCLMemoryModel) +
  1093. std::string(" OpEntryPoint Kernel %func \"compute\"") +
  1094. " %voidt = OpTypeVoid"
  1095. " %imgt = OpTypeImage %voidt Rect 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
  1096. SampledRectDependencies()),
  1097. std::make_pair(" OpCapability ImageBasic" +
  1098. std::string(kOpenCLMemoryModel) +
  1099. std::string(" OpEntryPoint Kernel %func \"compute\"") +
  1100. " %voidt = OpTypeVoid"
  1101. " %imgt = OpTypeImage %voidt Buffer 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
  1102. SampledBufferDependencies()),
  1103. std::make_pair(" OpCapability ImageBasic" +
  1104. std::string(kOpenCLMemoryModel) +
  1105. std::string(" OpEntryPoint Kernel %func \"compute\"") +
  1106. " %voidt = OpTypeVoid"
  1107. " %imgt = OpTypeImage %voidt SubpassData 0 0 0 2 Unknown" + std::string(kVoidFVoid2),
  1108. std::vector<std::string>{"InputAttachment"})
  1109. )));
  1110. // NOTE: All Sampler Address Modes require kernel capabilities but the
  1111. // OpConstantSampler requires LiteralSampler which depends on Kernel
  1112. INSTANTIATE_TEST_SUITE_P(SamplerAddressingMode, ValidateCapability,
  1113. Combine(
  1114. ValuesIn(AllCapabilities()),
  1115. Values(
  1116. std::make_pair(std::string(kGLSL450MemoryModel) +
  1117. " OpEntryPoint Vertex %func \"shader\""
  1118. " %samplert = OpTypeSampler"
  1119. " %sampler = OpConstantSampler %samplert None 1 Nearest" +
  1120. std::string(kVoidFVoid),
  1121. std::vector<std::string>{"LiteralSampler"}),
  1122. std::make_pair(std::string(kGLSL450MemoryModel) +
  1123. " OpEntryPoint Vertex %func \"shader\""
  1124. " %samplert = OpTypeSampler"
  1125. " %sampler = OpConstantSampler %samplert ClampToEdge 1 Nearest" +
  1126. std::string(kVoidFVoid),
  1127. std::vector<std::string>{"LiteralSampler"}),
  1128. std::make_pair(std::string(kGLSL450MemoryModel) +
  1129. " OpEntryPoint Vertex %func \"shader\""
  1130. " %samplert = OpTypeSampler"
  1131. " %sampler = OpConstantSampler %samplert Clamp 1 Nearest" +
  1132. std::string(kVoidFVoid),
  1133. std::vector<std::string>{"LiteralSampler"}),
  1134. std::make_pair(std::string(kGLSL450MemoryModel) +
  1135. " OpEntryPoint Vertex %func \"shader\""
  1136. " %samplert = OpTypeSampler"
  1137. " %sampler = OpConstantSampler %samplert Repeat 1 Nearest" +
  1138. std::string(kVoidFVoid),
  1139. std::vector<std::string>{"LiteralSampler"}),
  1140. std::make_pair(std::string(kGLSL450MemoryModel) +
  1141. " OpEntryPoint Vertex %func \"shader\""
  1142. " %samplert = OpTypeSampler"
  1143. " %sampler = OpConstantSampler %samplert RepeatMirrored 1 Nearest" +
  1144. std::string(kVoidFVoid),
  1145. std::vector<std::string>{"LiteralSampler"})
  1146. )));
  1147. // TODO(umar): Sampler Filter Mode
  1148. // TODO(umar): Image Format
  1149. // TODO(umar): Image Channel Order
  1150. // TODO(umar): Image Channel Data Type
  1151. // TODO(umar): Image Operands
  1152. // TODO(umar): FP Fast Math Mode
  1153. // TODO(umar): FP Rounding Mode
  1154. // TODO(umar): Linkage Type
  1155. // TODO(umar): Access Qualifier
  1156. // TODO(umar): Function Parameter Attribute
  1157. INSTANTIATE_TEST_SUITE_P(Decoration, ValidateCapability,
  1158. Combine(
  1159. ValuesIn(AllCapabilities()),
  1160. Values(
  1161. std::make_pair(std::string(kOpenCLMemoryModel) +
  1162. "OpEntryPoint Kernel %func \"compute\" \n"
  1163. "OpDecorate %var RelaxedPrecision\n"
  1164. "%intt = OpTypeInt 32 0\n"
  1165. "%ptr = OpTypePointer Private %intt\n"
  1166. "%var = OpVariable %ptr Private\n" + std::string(kVoidFVoid),
  1167. ShaderDependencies()),
  1168. std::make_pair(std::string(kOpenCLMemoryModel) +
  1169. // Block applies to struct type.
  1170. "OpEntryPoint Kernel %func \"compute\" \n"
  1171. "OpDecorate %block Block\n"
  1172. "%intt = OpTypeInt 32 0\n"
  1173. "%block = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
  1174. ShaderDependencies()),
  1175. std::make_pair(std::string(kOpenCLMemoryModel) +
  1176. // BufferBlock applies to struct type.
  1177. "OpEntryPoint Kernel %func \"compute\" \n"
  1178. "OpDecorate %block BufferBlock\n"
  1179. "%intt = OpTypeInt 32 0\n"
  1180. "%block = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
  1181. ShaderDependencies()),
  1182. std::make_pair(std::string(kOpenCLMemoryModel) +
  1183. "OpEntryPoint Kernel %func \"compute\" \n"
  1184. "OpMemberDecorate %structt 0 RowMajor\n"
  1185. "%floatt = OpTypeFloat 32\n"
  1186. "%float2 = OpTypeVector %floatt 2\n"
  1187. "%mat2x2 = OpTypeMatrix %float2 2\n"
  1188. "%structt = OpTypeStruct %mat2x2\n" + std::string(kVoidFVoid),
  1189. MatrixDependencies()),
  1190. std::make_pair(std::string(kOpenCLMemoryModel) +
  1191. "OpEntryPoint Kernel %func \"compute\" \n"
  1192. "OpMemberDecorate %structt 0 ColMajor\n"
  1193. "%floatt = OpTypeFloat 32\n"
  1194. "%float2 = OpTypeVector %floatt 2\n"
  1195. "%mat2x2 = OpTypeMatrix %float2 2\n"
  1196. "%structt = OpTypeStruct %mat2x2\n" + std::string(kVoidFVoid),
  1197. MatrixDependencies()),
  1198. std::make_pair(std::string(kOpenCLMemoryModel) +
  1199. "OpEntryPoint Kernel %func \"compute\" \n"
  1200. "OpDecorate %array ArrayStride 4\n"
  1201. "%intt = OpTypeInt 32 0\n"
  1202. "%array = OpTypeRuntimeArray %intt\n" + std::string(kVoidFVoid),
  1203. ShaderDependencies()),
  1204. std::make_pair(std::string(kOpenCLMemoryModel) +
  1205. "OpEntryPoint Kernel %func \"compute\" \n"
  1206. "OpMemberDecorate %structt 0 MatrixStride 8\n"
  1207. "%floatt = OpTypeFloat 32\n"
  1208. "%float2 = OpTypeVector %floatt 2\n"
  1209. "%mat2x2 = OpTypeMatrix %float2 2\n"
  1210. "%structt = OpTypeStruct %mat2x2\n" + std::string(kVoidFVoid),
  1211. MatrixDependencies()),
  1212. std::make_pair(std::string(kOpenCLMemoryModel) +
  1213. "OpEntryPoint Kernel %func \"compute\" \n"
  1214. "OpDecorate %struct GLSLShared\n"
  1215. "%struct = OpTypeStruct\n" + std::string(kVoidFVoid),
  1216. ShaderDependencies()),
  1217. std::make_pair(std::string(kOpenCLMemoryModel) +
  1218. "OpEntryPoint Kernel %func \"compute\" \n"
  1219. "OpDecorate %struct GLSLPacked\n"
  1220. "%struct = OpTypeStruct\n" + std::string(kVoidFVoid),
  1221. ShaderDependencies()),
  1222. std::make_pair(std::string(kGLSL450MemoryModel) +
  1223. "OpEntryPoint Vertex %func \"shader\" \n"
  1224. "OpDecorate %struct CPacked\n"
  1225. "%struct = OpTypeStruct\n" + std::string(kVoidFVoid),
  1226. KernelDependencies()),
  1227. std::make_pair(std::string(kOpenCLMemoryModel) +
  1228. "OpEntryPoint Kernel %func \"compute\" \n"
  1229. "OpDecorate %var NoPerspective\n"
  1230. "%intt = OpTypeInt 32 0\n"
  1231. "%ptr = OpTypePointer Input %intt\n"
  1232. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1233. ShaderDependencies()),
  1234. std::make_pair(std::string(kOpenCLMemoryModel) +
  1235. "OpEntryPoint Kernel %func \"compute\" \n"
  1236. "OpDecorate %var Flat\n"
  1237. "%intt = OpTypeInt 32 0\n"
  1238. "%ptr = OpTypePointer Input %intt\n"
  1239. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1240. ShaderDependencies()),
  1241. std::make_pair(std::string(kOpenCLMemoryModel) +
  1242. "OpEntryPoint Kernel %func \"compute\" \n"
  1243. "OpDecorate %var Patch\n"
  1244. "%intt = OpTypeInt 32 0\n"
  1245. "%ptr = OpTypePointer Input %intt\n"
  1246. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1247. TessellationDependencies()),
  1248. std::make_pair(std::string(kOpenCLMemoryModel) +
  1249. "OpEntryPoint Kernel %func \"compute\" \n"
  1250. "OpDecorate %var Centroid\n"
  1251. "%intt = OpTypeInt 32 0\n"
  1252. "%ptr = OpTypePointer Input %intt\n"
  1253. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1254. ShaderDependencies()),
  1255. std::make_pair(std::string(kOpenCLMemoryModel) +
  1256. "OpEntryPoint Kernel %func \"compute\" \n"
  1257. "OpDecorate %var Sample\n"
  1258. "%intt = OpTypeInt 32 0\n"
  1259. "%ptr = OpTypePointer Input %intt\n"
  1260. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1261. std::vector<std::string>{"SampleRateShading"}),
  1262. std::make_pair(std::string(kOpenCLMemoryModel) +
  1263. "OpEntryPoint Kernel %func \"compute\" \n"
  1264. "OpDecorate %var Invariant\n"
  1265. "%intt = OpTypeInt 32 0\n"
  1266. "%ptr = OpTypePointer Input %intt\n"
  1267. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1268. ShaderDependencies()),
  1269. std::make_pair(std::string(kOpenCLMemoryModel) +
  1270. "OpEntryPoint Kernel %func \"compute\" \n"
  1271. "OpDecorate %var Restrict\n"
  1272. "%intt = OpTypeInt 32 0\n"
  1273. "%ptr = OpTypePointer Input %intt\n"
  1274. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1275. AllCapabilities()),
  1276. std::make_pair(std::string(kOpenCLMemoryModel) +
  1277. "OpEntryPoint Kernel %func \"compute\" \n"
  1278. "OpDecorate %var Aliased\n"
  1279. "%intt = OpTypeInt 32 0\n"
  1280. "%ptr = OpTypePointer Input %intt\n"
  1281. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1282. AllCapabilities()),
  1283. std::make_pair(std::string(kOpenCLMemoryModel) +
  1284. "OpEntryPoint Kernel %func \"compute\" \n"
  1285. "OpDecorate %var Volatile\n"
  1286. "%intt = OpTypeInt 32 0\n"
  1287. "%ptr = OpTypePointer Input %intt\n"
  1288. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1289. AllCapabilities()),
  1290. std::make_pair(std::string(kGLSL450MemoryModel) +
  1291. "OpEntryPoint Vertex %func \"shader\" \n"
  1292. "OpDecorate %var Constant\n"
  1293. "%intt = OpTypeInt 32 0\n"
  1294. "%ptr = OpTypePointer Input %intt\n"
  1295. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1296. KernelDependencies()),
  1297. std::make_pair(std::string(kOpenCLMemoryModel) +
  1298. "OpEntryPoint Kernel %func \"compute\" \n"
  1299. "OpDecorate %var Coherent\n"
  1300. "%intt = OpTypeInt 32 0\n"
  1301. "%ptr = OpTypePointer Input %intt\n"
  1302. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1303. AllCapabilities()),
  1304. std::make_pair(std::string(kOpenCLMemoryModel) +
  1305. // NonWritable must target something valid, such as a storage image.
  1306. "OpEntryPoint Kernel %func \"compute\" \n"
  1307. "OpDecorate %var NonWritable "
  1308. "%float = OpTypeFloat 32 "
  1309. "%imstor = OpTypeImage %float 2D 0 0 0 2 Unknown "
  1310. "%ptr = OpTypePointer UniformConstant %imstor "
  1311. "%var = OpVariable %ptr UniformConstant "
  1312. + std::string(kVoidFVoid),
  1313. AllCapabilities()),
  1314. std::make_pair(std::string(kOpenCLMemoryModel) +
  1315. "OpEntryPoint Kernel %func \"compute\" \n"
  1316. "OpDecorate %var NonReadable "
  1317. "%float = OpTypeFloat 32 "
  1318. "%imstor = OpTypeImage %float 2D 0 0 0 2 Unknown "
  1319. "%ptr = OpTypePointer UniformConstant %imstor "
  1320. "%var = OpVariable %ptr UniformConstant "
  1321. + std::string(kVoidFVoid),
  1322. AllCapabilities()),
  1323. std::make_pair(std::string(kOpenCLMemoryModel) +
  1324. // Uniform must target a non-void value.
  1325. "OpEntryPoint Kernel %func \"compute\" \n"
  1326. "OpDecorate %int0 Uniform\n"
  1327. "%intt = OpTypeInt 32 0\n" +
  1328. "%int0 = OpConstantNull %intt"
  1329. + std::string(kVoidFVoid),
  1330. ShaderDependencies()),
  1331. std::make_pair(std::string(kGLSL450MemoryModel) +
  1332. "OpEntryPoint Vertex %func \"shader\" \n"
  1333. "OpDecorate %intt SaturatedConversion\n"
  1334. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1335. KernelDependencies()),
  1336. std::make_pair(std::string(kOpenCLMemoryModel) +
  1337. "OpEntryPoint Kernel %func \"compute\" \n"
  1338. "OpDecorate %var Stream 0\n"
  1339. "%intt = OpTypeInt 32 0\n"
  1340. "%ptr = OpTypePointer Output %intt\n"
  1341. "%var = OpVariable %ptr Output\n" + std::string(kVoidFVoid),
  1342. std::vector<std::string>{"GeometryStreams"}),
  1343. std::make_pair(std::string(kOpenCLMemoryModel) +
  1344. "OpEntryPoint Kernel %func \"compute\" \n"
  1345. "OpMemberDecorate %struct 0 Location 0\n"
  1346. "%intt = OpTypeInt 32 0\n"
  1347. "%struct = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
  1348. ShaderDependencies()),
  1349. std::make_pair(std::string(kOpenCLMemoryModel) +
  1350. "OpEntryPoint Kernel %func \"compute\" \n"
  1351. "OpDecorate %var Component 0\n"
  1352. "%intt = OpTypeInt 32 0\n"
  1353. "%ptr = OpTypePointer Input %intt\n"
  1354. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1355. ShaderDependencies()),
  1356. std::make_pair(std::string(kOpenCLMemoryModel) +
  1357. "OpEntryPoint Kernel %func \"compute\" \n"
  1358. "OpDecorate %var Index 0\n"
  1359. "%intt = OpTypeInt 32 0\n"
  1360. "%ptr = OpTypePointer Input %intt\n"
  1361. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1362. ShaderDependencies()),
  1363. std::make_pair(std::string(kOpenCLMemoryModel) +
  1364. "OpEntryPoint Kernel %func \"compute\" \n"
  1365. "OpDecorate %var Binding 0\n"
  1366. "%intt = OpTypeInt 32 0\n"
  1367. "%ptr = OpTypePointer Uniform %intt\n"
  1368. "%var = OpVariable %ptr Uniform\n" + std::string(kVoidFVoid),
  1369. ShaderDependencies()),
  1370. std::make_pair(std::string(kOpenCLMemoryModel) +
  1371. "OpEntryPoint Kernel %func \"compute\" \n"
  1372. "OpDecorate %var DescriptorSet 0\n"
  1373. "%intt = OpTypeInt 32 0\n"
  1374. "%ptr = OpTypePointer Uniform %intt\n"
  1375. "%var = OpVariable %ptr Uniform\n" + std::string(kVoidFVoid),
  1376. ShaderDependencies()),
  1377. std::make_pair(std::string(kOpenCLMemoryModel) +
  1378. "OpEntryPoint Kernel %func \"compute\" \n"
  1379. "OpMemberDecorate %structt 0 Offset 0\n"
  1380. "%intt = OpTypeInt 32 0\n"
  1381. "%structt = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
  1382. ShaderDependencies()),
  1383. std::make_pair(std::string(kOpenCLMemoryModel) +
  1384. "OpEntryPoint Kernel %func \"compute\" \n"
  1385. "OpDecorate %var XfbBuffer 0\n"
  1386. "%intt = OpTypeInt 32 0\n"
  1387. "%ptr = OpTypePointer Uniform %intt\n"
  1388. "%var = OpVariable %ptr Uniform\n" + std::string(kVoidFVoid),
  1389. std::vector<std::string>{"TransformFeedback"}),
  1390. std::make_pair(std::string(kOpenCLMemoryModel) +
  1391. "OpEntryPoint Kernel %func \"compute\" \n"
  1392. "OpDecorate %var XfbStride 0\n"
  1393. "%intt = OpTypeInt 32 0\n"
  1394. "%ptr = OpTypePointer Uniform %intt\n"
  1395. "%var = OpVariable %ptr Uniform\n" + std::string(kVoidFVoid),
  1396. std::vector<std::string>{"TransformFeedback"}),
  1397. std::make_pair(std::string(kGLSL450MemoryModel) +
  1398. "OpEntryPoint Vertex %func \"shader\" \n"
  1399. "OpDecorate %intt FuncParamAttr Zext\n"
  1400. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1401. KernelDependencies()),
  1402. std::make_pair(std::string(kGLSL450MemoryModel) +
  1403. "OpEntryPoint Vertex %func \"shader\" \n"
  1404. "OpDecorate %intt FPFastMathMode Fast\n"
  1405. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1406. KernelDependencies()),
  1407. std::make_pair(std::string(kOpenCLMemoryModel) +
  1408. "OpEntryPoint Kernel %func \"compute\" \n"
  1409. "OpDecorate %intt LinkageAttributes \"other\" Import\n"
  1410. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1411. std::vector<std::string>{"Linkage"}),
  1412. std::make_pair(std::string(kOpenCLMemoryModel) +
  1413. "OpEntryPoint Kernel %func \"compute\" \n"
  1414. "OpDecorate %intt NoContraction\n"
  1415. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1416. ShaderDependencies()),
  1417. std::make_pair(std::string(kOpenCLMemoryModel) +
  1418. "OpEntryPoint Kernel %func \"compute\" \n"
  1419. "OpDecorate %var InputAttachmentIndex 0\n"
  1420. "%intt = OpTypeInt 32 0\n"
  1421. "%ptr = OpTypePointer UniformConstant %intt\n"
  1422. "%var = OpVariable %ptr UniformConstant\n" + std::string(kVoidFVoid),
  1423. std::vector<std::string>{"InputAttachment"}),
  1424. std::make_pair(std::string(kGLSL450MemoryModel) +
  1425. "OpEntryPoint Vertex %func \"shader\" \n"
  1426. "OpDecorate %intt Alignment 4\n"
  1427. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1428. KernelDependencies())
  1429. )));
  1430. // clang-format on
  1431. INSTANTIATE_TEST_SUITE_P(
  1432. DecorationSpecId, ValidateCapability,
  1433. Combine(
  1434. ValuesIn(AllSpirV10Capabilities()),
  1435. Values(std::make_pair(std::string(kOpenCLMemoryModel) +
  1436. "OpEntryPoint Vertex %func \"shader\" \n" +
  1437. "OpDecorate %1 SpecId 1\n"
  1438. "%intt = OpTypeInt 32 0\n"
  1439. "%1 = OpSpecConstant %intt 0\n" +
  1440. std::string(kVoidFVoid),
  1441. ShaderDependencies()))));
  1442. INSTANTIATE_TEST_SUITE_P(
  1443. DecorationV11, ValidateCapabilityV11,
  1444. Combine(ValuesIn(AllCapabilities()),
  1445. Values(std::make_pair(std::string(kOpenCLMemoryModel) +
  1446. "OpEntryPoint Kernel %func \"compute\" \n"
  1447. "OpDecorate %p MaxByteOffset 0 "
  1448. "%i32 = OpTypeInt 32 0 "
  1449. "%pi32 = OpTypePointer Workgroup %i32 "
  1450. "%p = OpVariable %pi32 Workgroup " +
  1451. std::string(kVoidFVoid),
  1452. AddressesDependencies()),
  1453. // Trying to test OpDecorate here, but if this fails due to
  1454. // incorrect OpMemoryModel validation, that must also be
  1455. // fixed.
  1456. std::make_pair(
  1457. std::string("OpMemoryModel Logical OpenCL "
  1458. "OpEntryPoint Kernel %func \"compute\" \n"
  1459. "OpDecorate %1 SpecId 1 "
  1460. "%intt = OpTypeInt 32 0 "
  1461. "%1 = OpSpecConstant %intt 0") +
  1462. std::string(kVoidFVoid),
  1463. KernelDependencies()),
  1464. std::make_pair(
  1465. std::string("OpMemoryModel Logical Simple "
  1466. "OpEntryPoint Vertex %func \"shader\" \n"
  1467. "OpDecorate %1 SpecId 1 "
  1468. "%intt = OpTypeInt 32 0 "
  1469. "%1 = OpSpecConstant %intt 0") +
  1470. std::string(kVoidFVoid),
  1471. ShaderDependencies()))));
  1472. // clang-format off
  1473. INSTANTIATE_TEST_SUITE_P(BuiltIn, ValidateCapability,
  1474. Combine(
  1475. ValuesIn(AllCapabilities()),
  1476. Values(
  1477. std::make_pair(std::string(kOpenCLMemoryModel) +
  1478. "OpEntryPoint Kernel %func \"compute\" \n" +
  1479. "OpDecorate %var BuiltIn Position\n"
  1480. "%intt = OpTypeInt 32 0\n"
  1481. "%ptr = OpTypePointer Input %intt\n"
  1482. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1483. ShaderDependencies()),
  1484. // Just mentioning PointSize, ClipDistance, or CullDistance as a BuiltIn does
  1485. // not trigger the requirement for the associated capability.
  1486. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/365
  1487. std::make_pair(std::string(kOpenCLMemoryModel) +
  1488. "OpEntryPoint Kernel %func \"compute\" \n" +
  1489. "OpDecorate %var BuiltIn PointSize\n"
  1490. "%intt = OpTypeInt 32 0\n"
  1491. "%ptr = OpTypePointer Input %intt\n"
  1492. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1493. AllCapabilities()),
  1494. std::make_pair(std::string(kOpenCLMemoryModel) +
  1495. "OpEntryPoint Kernel %func \"compute\" \n" +
  1496. "OpDecorate %var BuiltIn ClipDistance\n"
  1497. "%intt = OpTypeInt 32 0\n"
  1498. "%ptr = OpTypePointer Input %intt\n"
  1499. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1500. AllCapabilities()),
  1501. std::make_pair(std::string(kOpenCLMemoryModel) +
  1502. "OpEntryPoint Kernel %func \"compute\" \n" +
  1503. "OpDecorate %var BuiltIn CullDistance\n"
  1504. "%intt = OpTypeInt 32 0\n"
  1505. "%ptr = OpTypePointer Input %intt\n"
  1506. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1507. AllCapabilities()),
  1508. std::make_pair(std::string(kOpenCLMemoryModel) +
  1509. "OpEntryPoint Kernel %func \"compute\" \n" +
  1510. "OpDecorate %var BuiltIn VertexId\n"
  1511. "%intt = OpTypeInt 32 0\n"
  1512. "%ptr = OpTypePointer Input %intt\n"
  1513. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1514. ShaderDependencies()),
  1515. std::make_pair(std::string(kOpenCLMemoryModel) +
  1516. "OpEntryPoint Kernel %func \"compute\" \n" +
  1517. "OpDecorate %var BuiltIn InstanceId\n"
  1518. "%intt = OpTypeInt 32 0\n"
  1519. "%ptr = OpTypePointer Input %intt\n"
  1520. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1521. ShaderDependencies()),
  1522. std::make_pair(std::string(kOpenCLMemoryModel) +
  1523. "OpEntryPoint Kernel %func \"compute\" \n" +
  1524. "OpDecorate %var BuiltIn PrimitiveId\n"
  1525. "%intt = OpTypeInt 32 0\n"
  1526. "%ptr = OpTypePointer Input %intt\n"
  1527. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1528. GeometryTessellationDependencies()),
  1529. std::make_pair(std::string(kOpenCLMemoryModel) +
  1530. "OpEntryPoint Kernel %func \"compute\" \n" +
  1531. "OpDecorate %var BuiltIn InvocationId\n"
  1532. "%intt = OpTypeInt 32 0\n"
  1533. "%ptr = OpTypePointer Input %intt\n"
  1534. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1535. GeometryTessellationDependencies()),
  1536. std::make_pair(std::string(kOpenCLMemoryModel) +
  1537. "OpEntryPoint Kernel %func \"compute\" \n" +
  1538. "OpDecorate %var BuiltIn Layer\n"
  1539. "%intt = OpTypeInt 32 0\n"
  1540. "%ptr = OpTypePointer Input %intt\n"
  1541. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1542. GeometryDependencies()),
  1543. std::make_pair(std::string(kOpenCLMemoryModel) +
  1544. "OpEntryPoint Kernel %func \"compute\" \n" +
  1545. "OpDecorate %var BuiltIn ViewportIndex\n"
  1546. "%intt = OpTypeInt 32 0\n"
  1547. "%ptr = OpTypePointer Input %intt\n"
  1548. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1549. std::vector<std::string>{"MultiViewport"}),
  1550. std::make_pair(std::string(kOpenCLMemoryModel) +
  1551. "OpEntryPoint Kernel %func \"compute\" \n" +
  1552. "OpDecorate %var BuiltIn TessLevelOuter\n"
  1553. "%intt = OpTypeInt 32 0\n"
  1554. "%ptr = OpTypePointer Input %intt\n"
  1555. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1556. TessellationDependencies()),
  1557. std::make_pair(std::string(kOpenCLMemoryModel) +
  1558. "OpEntryPoint Kernel %func \"compute\" \n" +
  1559. "OpDecorate %var BuiltIn TessLevelInner\n"
  1560. "%intt = OpTypeInt 32 0\n"
  1561. "%ptr = OpTypePointer Input %intt\n"
  1562. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1563. TessellationDependencies()),
  1564. std::make_pair(std::string(kOpenCLMemoryModel) +
  1565. "OpEntryPoint Kernel %func \"compute\" \n" +
  1566. "OpDecorate %var BuiltIn TessCoord\n"
  1567. "%intt = OpTypeInt 32 0\n"
  1568. "%ptr = OpTypePointer Input %intt\n"
  1569. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1570. TessellationDependencies()),
  1571. std::make_pair(std::string(kOpenCLMemoryModel) +
  1572. "OpEntryPoint Kernel %func \"compute\" \n" +
  1573. "OpDecorate %var BuiltIn PatchVertices\n"
  1574. "%intt = OpTypeInt 32 0\n"
  1575. "%ptr = OpTypePointer Input %intt\n"
  1576. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1577. TessellationDependencies()),
  1578. std::make_pair(std::string(kOpenCLMemoryModel) +
  1579. "OpEntryPoint Kernel %func \"compute\" \n" +
  1580. "OpDecorate %var BuiltIn FragCoord\n"
  1581. "%intt = OpTypeInt 32 0\n"
  1582. "%ptr = OpTypePointer Input %intt\n"
  1583. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1584. ShaderDependencies()),
  1585. std::make_pair(std::string(kOpenCLMemoryModel) +
  1586. "OpEntryPoint Kernel %func \"compute\" \n" +
  1587. "OpDecorate %var BuiltIn PointCoord\n"
  1588. "%intt = OpTypeInt 32 0\n"
  1589. "%ptr = OpTypePointer Input %intt\n"
  1590. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1591. ShaderDependencies()),
  1592. std::make_pair(std::string(kOpenCLMemoryModel) +
  1593. "OpEntryPoint Kernel %func \"compute\" \n" +
  1594. "OpDecorate %var BuiltIn FrontFacing\n"
  1595. "%intt = OpTypeInt 32 0\n"
  1596. "%ptr = OpTypePointer Input %intt\n"
  1597. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1598. ShaderDependencies()),
  1599. std::make_pair(std::string(kOpenCLMemoryModel) +
  1600. "OpEntryPoint Kernel %func \"compute\" \n" +
  1601. "OpDecorate %var BuiltIn SampleId\n"
  1602. "%intt = OpTypeInt 32 0\n"
  1603. "%ptr = OpTypePointer Input %intt\n"
  1604. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1605. std::vector<std::string>{"SampleRateShading"}),
  1606. std::make_pair(std::string(kOpenCLMemoryModel) +
  1607. "OpEntryPoint Kernel %func \"compute\" \n" +
  1608. "OpDecorate %var BuiltIn SamplePosition\n"
  1609. "%intt = OpTypeInt 32 0\n"
  1610. "%ptr = OpTypePointer Input %intt\n"
  1611. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1612. std::vector<std::string>{"SampleRateShading"}),
  1613. std::make_pair(std::string(kOpenCLMemoryModel) +
  1614. "OpEntryPoint Kernel %func \"compute\" \n" +
  1615. "OpDecorate %var BuiltIn SampleMask\n"
  1616. "%intt = OpTypeInt 32 0\n"
  1617. "%ptr = OpTypePointer Input %intt\n"
  1618. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1619. ShaderDependencies()),
  1620. std::make_pair(std::string(kOpenCLMemoryModel) +
  1621. "OpEntryPoint Kernel %func \"compute\" \n" +
  1622. "OpDecorate %var BuiltIn FragDepth\n"
  1623. "%intt = OpTypeInt 32 0\n"
  1624. "%ptr = OpTypePointer Input %intt\n"
  1625. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1626. ShaderDependencies()),
  1627. std::make_pair(std::string(kOpenCLMemoryModel) +
  1628. "OpEntryPoint Kernel %func \"compute\" \n" +
  1629. "OpDecorate %var BuiltIn HelperInvocation\n"
  1630. "%intt = OpTypeInt 32 0\n"
  1631. "%ptr = OpTypePointer Input %intt\n"
  1632. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1633. ShaderDependencies()),
  1634. std::make_pair(std::string(kOpenCLMemoryModel) +
  1635. "OpEntryPoint Kernel %func \"compute\" \n" +
  1636. "OpDecorate %var BuiltIn VertexIndex\n"
  1637. "%intt = OpTypeInt 32 0\n"
  1638. "%ptr = OpTypePointer Input %intt\n"
  1639. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1640. ShaderDependencies()),
  1641. std::make_pair(std::string(kOpenCLMemoryModel) +
  1642. "OpEntryPoint Kernel %func \"compute\" \n" +
  1643. "OpDecorate %var BuiltIn InstanceIndex\n"
  1644. "%intt = OpTypeInt 32 0\n"
  1645. "%ptr = OpTypePointer Input %intt\n"
  1646. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1647. ShaderDependencies()),
  1648. std::make_pair(std::string(kOpenCLMemoryModel) +
  1649. "OpEntryPoint Kernel %func \"compute\" \n" +
  1650. "OpDecorate %var BuiltIn NumWorkgroups\n"
  1651. "%intt = OpTypeInt 32 0\n"
  1652. "%ptr = OpTypePointer Input %intt\n"
  1653. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1654. AllCapabilities()),
  1655. std::make_pair(std::string(kOpenCLMemoryModel) +
  1656. "OpEntryPoint Kernel %func \"compute\" \n" +
  1657. "OpDecorate %var BuiltIn WorkgroupId\n"
  1658. "%intt = OpTypeInt 32 0\n"
  1659. "%ptr = OpTypePointer Input %intt\n"
  1660. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1661. AllCapabilities()),
  1662. std::make_pair(std::string(kOpenCLMemoryModel) +
  1663. "OpEntryPoint Kernel %func \"compute\" \n" +
  1664. "OpDecorate %var BuiltIn LocalInvocationId\n"
  1665. "%intt = OpTypeInt 32 0\n"
  1666. "%ptr = OpTypePointer Input %intt\n"
  1667. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1668. AllCapabilities()),
  1669. std::make_pair(std::string(kOpenCLMemoryModel) +
  1670. "OpEntryPoint Kernel %func \"compute\" \n" +
  1671. "OpDecorate %var BuiltIn GlobalInvocationId\n"
  1672. "%intt = OpTypeInt 32 0\n"
  1673. "%ptr = OpTypePointer Input %intt\n"
  1674. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1675. AllCapabilities()),
  1676. std::make_pair(std::string(kOpenCLMemoryModel) +
  1677. "OpEntryPoint Kernel %func \"compute\" \n" +
  1678. "OpDecorate %var BuiltIn LocalInvocationIndex\n"
  1679. "%intt = OpTypeInt 32 0\n"
  1680. "%ptr = OpTypePointer Input %intt\n"
  1681. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1682. AllCapabilities()),
  1683. std::make_pair(std::string(kGLSL450MemoryModel) +
  1684. "OpEntryPoint Vertex %func \"shader\" \n" +
  1685. "OpDecorate %var BuiltIn WorkDim\n"
  1686. "%intt = OpTypeInt 32 0\n"
  1687. "%ptr = OpTypePointer Input %intt\n"
  1688. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1689. KernelDependencies()),
  1690. std::make_pair(std::string(kGLSL450MemoryModel) +
  1691. "OpEntryPoint Vertex %func \"shader\" \n" +
  1692. "OpDecorate %var BuiltIn GlobalSize\n"
  1693. "%intt = OpTypeInt 32 0\n"
  1694. "%ptr = OpTypePointer Input %intt\n"
  1695. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1696. KernelDependencies()),
  1697. std::make_pair(std::string(kGLSL450MemoryModel) +
  1698. "OpEntryPoint Vertex %func \"shader\" \n" +
  1699. "OpDecorate %var BuiltIn EnqueuedWorkgroupSize\n"
  1700. "%intt = OpTypeInt 32 0\n"
  1701. "%ptr = OpTypePointer Input %intt\n"
  1702. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1703. KernelDependencies()),
  1704. std::make_pair(std::string(kGLSL450MemoryModel) +
  1705. "OpEntryPoint Vertex %func \"shader\" \n" +
  1706. "OpDecorate %var BuiltIn GlobalOffset\n"
  1707. "%intt = OpTypeInt 32 0\n"
  1708. "%ptr = OpTypePointer Input %intt\n"
  1709. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1710. KernelDependencies()),
  1711. std::make_pair(std::string(kGLSL450MemoryModel) +
  1712. "OpEntryPoint Vertex %func \"shader\" \n" +
  1713. "OpDecorate %var BuiltIn GlobalLinearId\n"
  1714. "%intt = OpTypeInt 32 0\n"
  1715. "%ptr = OpTypePointer Input %intt\n"
  1716. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1717. KernelDependencies()),
  1718. std::make_pair(std::string(kGLSL450MemoryModel) +
  1719. "OpEntryPoint Vertex %func \"shader\" \n" +
  1720. "OpDecorate %var BuiltIn SubgroupSize\n"
  1721. "%intt = OpTypeInt 32 0\n"
  1722. "%ptr = OpTypePointer Input %intt\n"
  1723. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1724. KernelAndGroupNonUniformDependencies()),
  1725. std::make_pair(std::string(kGLSL450MemoryModel) +
  1726. "OpEntryPoint Vertex %func \"shader\" \n" +
  1727. "OpDecorate %var BuiltIn SubgroupMaxSize\n"
  1728. "%intt = OpTypeInt 32 0\n"
  1729. "%ptr = OpTypePointer Input %intt\n"
  1730. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1731. KernelDependencies()),
  1732. std::make_pair(std::string(kGLSL450MemoryModel) +
  1733. "OpEntryPoint Vertex %func \"shader\" \n" +
  1734. "OpDecorate %var BuiltIn NumSubgroups\n"
  1735. "%intt = OpTypeInt 32 0\n"
  1736. "%ptr = OpTypePointer Input %intt\n"
  1737. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1738. KernelAndGroupNonUniformDependencies()),
  1739. std::make_pair(std::string(kGLSL450MemoryModel) +
  1740. "OpEntryPoint Vertex %func \"shader\" \n" +
  1741. "OpDecorate %var BuiltIn NumEnqueuedSubgroups\n"
  1742. "%intt = OpTypeInt 32 0\n"
  1743. "%ptr = OpTypePointer Input %intt\n"
  1744. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1745. KernelDependencies()),
  1746. std::make_pair(std::string(kGLSL450MemoryModel) +
  1747. "OpEntryPoint Vertex %func \"shader\" \n" +
  1748. "OpDecorate %var BuiltIn SubgroupId\n"
  1749. "%intt = OpTypeInt 32 0\n"
  1750. "%ptr = OpTypePointer Input %intt\n"
  1751. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1752. KernelAndGroupNonUniformDependencies()),
  1753. std::make_pair(std::string(kGLSL450MemoryModel) +
  1754. "OpEntryPoint Vertex %func \"shader\" \n" +
  1755. "OpDecorate %var BuiltIn SubgroupLocalInvocationId\n"
  1756. "%intt = OpTypeInt 32 0\n"
  1757. "%ptr = OpTypePointer Input %intt\n"
  1758. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1759. KernelAndGroupNonUniformDependencies()),
  1760. std::make_pair(std::string(kOpenCLMemoryModel) +
  1761. "OpEntryPoint Kernel %func \"compute\" \n" +
  1762. "OpDecorate %var BuiltIn VertexIndex\n"
  1763. "%intt = OpTypeInt 32 0\n"
  1764. "%ptr = OpTypePointer Input %intt\n"
  1765. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1766. ShaderDependencies()),
  1767. std::make_pair(std::string(kOpenCLMemoryModel) +
  1768. "OpEntryPoint Kernel %func \"compute\" \n" +
  1769. "OpDecorate %var BuiltIn InstanceIndex\n"
  1770. "%intt = OpTypeInt 32 0\n"
  1771. "%ptr = OpTypePointer Input %intt\n"
  1772. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1773. ShaderDependencies())
  1774. )));
  1775. // Ensure that mere mention of PointSize, ClipDistance, or CullDistance as
  1776. // BuiltIns does not trigger the requirement for the associated
  1777. // capability.
  1778. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/365
  1779. INSTANTIATE_TEST_SUITE_P(BuiltIn, ValidateCapabilityVulkan10,
  1780. Combine(
  1781. // All capabilities to try.
  1782. ValuesIn(AllSpirV10Capabilities()),
  1783. Values(
  1784. std::make_pair(std::string(kGLSL450MemoryModel) +
  1785. "OpEntryPoint Vertex %func \"shader\" %var\n" +
  1786. "OpDecorate %var BuiltIn PointSize\n"
  1787. "%float = OpTypeFloat 32\n"
  1788. "%ptr_output_float = OpTypePointer Output %float\n"
  1789. "%var = OpVariable %ptr_output_float Output\n" + std::string(kVoidFVoid),
  1790. // Capabilities which should succeed.
  1791. AllVulkan10Capabilities()),
  1792. std::make_pair(std::string(kGLSL450MemoryModel) +
  1793. "OpEntryPoint Vertex %func \"shader\" \n"
  1794. "OpMemberDecorate %block 0 BuiltIn ClipDistance\n"
  1795. "%f32 = OpTypeFloat 32\n"
  1796. "%intt = OpTypeInt 32 0\n"
  1797. "%intt_4 = OpConstant %intt 4\n"
  1798. "%f32arr4 = OpTypeArray %f32 %intt_4\n"
  1799. "%block = OpTypeStruct %f32arr4\n" + std::string(kVoidFVoid),
  1800. AllVulkan10Capabilities()),
  1801. std::make_pair(std::string(kGLSL450MemoryModel) +
  1802. "OpEntryPoint Vertex %func \"shader\" \n"
  1803. "OpMemberDecorate %block 0 BuiltIn CullDistance\n"
  1804. "%f32 = OpTypeFloat 32\n"
  1805. "%intt = OpTypeInt 32 0\n"
  1806. "%intt_4 = OpConstant %intt 4\n"
  1807. "%f32arr4 = OpTypeArray %f32 %intt_4\n"
  1808. "%block = OpTypeStruct %f32arr4\n" + std::string(kVoidFVoid),
  1809. AllVulkan10Capabilities())
  1810. )));
  1811. INSTANTIATE_TEST_SUITE_P(BuiltIn, ValidateCapabilityOpenGL40,
  1812. Combine(
  1813. // OpenGL 4.0 is based on SPIR-V 1.0
  1814. ValuesIn(AllSpirV10Capabilities()),
  1815. Values(
  1816. std::make_pair(std::string(kGLSL450MemoryModel) +
  1817. "OpEntryPoint Vertex %func \"shader\" %var\n" +
  1818. "OpDecorate %var BuiltIn PointSize\n"
  1819. "%float = OpTypeFloat 32\n"
  1820. "%ptr_output_float = OpTypePointer Output %float\n"
  1821. "%var = OpVariable %ptr_output_float Output\n" + std::string(kVoidFVoid),
  1822. AllSpirV10Capabilities()),
  1823. std::make_pair(std::string(kGLSL450MemoryModel) +
  1824. "OpEntryPoint Vertex %func \"shader\" %var\n" +
  1825. "OpDecorate %var BuiltIn ClipDistance\n"
  1826. "%float = OpTypeFloat 32\n"
  1827. "%int = OpTypeInt 32 0\n"
  1828. "%int_1 = OpConstant %int 1\n"
  1829. "%array = OpTypeArray %float %int_1\n"
  1830. "%ptr = OpTypePointer Output %array\n"
  1831. "%var = OpVariable %ptr Output\n" + std::string(kVoidFVoid),
  1832. AllSpirV10Capabilities()),
  1833. std::make_pair(std::string(kGLSL450MemoryModel) +
  1834. "OpEntryPoint Vertex %func \"shader\" %var\n" +
  1835. "OpDecorate %var BuiltIn CullDistance\n"
  1836. "%float = OpTypeFloat 32\n"
  1837. "%int = OpTypeInt 32 0\n"
  1838. "%int_1 = OpConstant %int 1\n"
  1839. "%array = OpTypeArray %float %int_1\n"
  1840. "%ptr = OpTypePointer Output %array\n"
  1841. "%var = OpVariable %ptr Output\n" + std::string(kVoidFVoid),
  1842. AllSpirV10Capabilities())
  1843. )));
  1844. INSTANTIATE_TEST_SUITE_P(Capabilities, ValidateCapabilityVulkan11,
  1845. Combine(
  1846. // All capabilities to try.
  1847. ValuesIn(AllCapabilities()),
  1848. Values(
  1849. std::make_pair(std::string(kGLSL450MemoryModel) +
  1850. "OpEntryPoint Vertex %func \"shader\" %var\n" +
  1851. "OpDecorate %var BuiltIn PointSize\n"
  1852. "%float = OpTypeFloat 32\n"
  1853. "%ptr_output_float = OpTypePointer Output %float\n"
  1854. "%var = OpVariable %ptr_output_float Output\n" + std::string(kVoidFVoid),
  1855. AllVulkan11Capabilities()),
  1856. std::make_pair(std::string(kGLSL450MemoryModel) +
  1857. "OpEntryPoint Vertex %func \"shader\" %var\n" +
  1858. "OpDecorate %var BuiltIn CullDistance\n"
  1859. "%float = OpTypeFloat 32\n"
  1860. "%int = OpTypeInt 32 0\n"
  1861. "%int_1 = OpConstant %int 1\n"
  1862. "%array = OpTypeArray %float %int_1\n"
  1863. "%ptr = OpTypePointer Output %array\n"
  1864. "%var = OpVariable %ptr Output\n" + std::string(kVoidFVoid),
  1865. AllVulkan11Capabilities())
  1866. )));
  1867. INSTANTIATE_TEST_SUITE_P(Capabilities, ValidateCapabilityVulkan12,
  1868. Combine(
  1869. // All capabilities to try.
  1870. ValuesIn(AllSpirV15Capabilities()),
  1871. Values(
  1872. std::make_pair(std::string(kGLSL450MemoryModel) +
  1873. "OpEntryPoint Vertex %func \"shader\" %var\n" +
  1874. "OpDecorate %var BuiltIn PointSize\n"
  1875. "%float = OpTypeFloat 32\n"
  1876. "%ptr_output_float = OpTypePointer Output %float\n"
  1877. "%var = OpVariable %ptr_output_float Output\n" + std::string(kVoidFVoid),
  1878. AllVulkan12Capabilities()),
  1879. std::make_pair(std::string(kGLSL450MemoryModel) +
  1880. "OpEntryPoint Vertex %func \"shader\" %var\n" +
  1881. "OpDecorate %var BuiltIn CullDistance\n"
  1882. "%float = OpTypeFloat 32\n"
  1883. "%int = OpTypeInt 32 0\n"
  1884. "%int_1 = OpConstant %int 1\n"
  1885. "%array = OpTypeArray %float %int_1\n"
  1886. "%ptr = OpTypePointer Output %array\n"
  1887. "%var = OpVariable %ptr Output\n" + std::string(kVoidFVoid),
  1888. AllVulkan12Capabilities())
  1889. )));
  1890. // TODO(umar): Selection Control
  1891. // TODO(umar): Loop Control
  1892. // TODO(umar): Function Control
  1893. // TODO(umar): Memory Semantics
  1894. // TODO(umar): Memory Access
  1895. // TODO(umar): Scope
  1896. // TODO(umar): Group Operation
  1897. // TODO(umar): Kernel Enqueue Flags
  1898. // TODO(umar): Kernel Profiling Flags
  1899. INSTANTIATE_TEST_SUITE_P(MatrixOp, ValidateCapability,
  1900. Combine(
  1901. ValuesIn(AllCapabilities()),
  1902. Values(
  1903. std::make_pair(std::string(kOpenCLMemoryModel) +
  1904. "OpEntryPoint Kernel %func \"compute\" \n" +
  1905. "%f32 = OpTypeFloat 32\n"
  1906. "%vec3 = OpTypeVector %f32 3\n"
  1907. "%mat33 = OpTypeMatrix %vec3 3\n" + std::string(kVoidFVoid),
  1908. MatrixDependencies()))));
  1909. // clang-format on
  1910. #if 0
  1911. // TODO([email protected]) The following test is not valid as it generates
  1912. // invalid combinations of images, instructions and image operands.
  1913. //
  1914. // Creates assembly containing an OpImageFetch instruction using operands for
  1915. // the image-operands part. The assembly defines constants %fzero and %izero
  1916. // that can be used for operands where IDs are required. The assembly is valid,
  1917. // apart from not declaring any capabilities required by the operands.
  1918. string ImageOperandsTemplate(const std::string& operands) {
  1919. ostringstream ss;
  1920. // clang-format off
  1921. ss << R"(
  1922. OpCapability Kernel
  1923. OpCapability Linkage
  1924. OpMemoryModel Logical OpenCL
  1925. %i32 = OpTypeInt 32 0
  1926. %f32 = OpTypeFloat 32
  1927. %v4i32 = OpTypeVector %i32 4
  1928. %timg = OpTypeImage %i32 2D 0 0 0 0 Unknown
  1929. %pimg = OpTypePointer UniformConstant %timg
  1930. %tfun = OpTypeFunction %i32
  1931. %vimg = OpVariable %pimg UniformConstant
  1932. %izero = OpConstant %i32 0
  1933. %fzero = OpConstant %f32 0.
  1934. %main = OpFunction %i32 None %tfun
  1935. %lbl = OpLabel
  1936. %img = OpLoad %timg %vimg
  1937. %r1 = OpImageFetch %v4i32 %img %izero )" << operands << R"(
  1938. OpReturnValue %izero
  1939. OpFunctionEnd
  1940. )";
  1941. // clang-format on
  1942. return ss.str();
  1943. }
  1944. INSTANTIATE_TEST_SUITE_P(
  1945. TwoImageOperandsMask, ValidateCapability,
  1946. Combine(
  1947. ValuesIn(AllCapabilities()),
  1948. Values(std::make_pair(ImageOperandsTemplate("Bias|Lod %fzero %fzero"),
  1949. ShaderDependencies()),
  1950. std::make_pair(ImageOperandsTemplate("Lod|Offset %fzero %izero"),
  1951. std::vector<std::string>{"ImageGatherExtended"}),
  1952. std::make_pair(ImageOperandsTemplate("Sample|MinLod %izero %fzero"),
  1953. std::vector<std::string>{"MinLod"}),
  1954. std::make_pair(ImageOperandsTemplate("Lod|Sample %fzero %izero"),
  1955. AllCapabilities()))), );
  1956. #endif
  1957. // TODO(umar): Instruction capability checks
  1958. spv_result_t spvCoreOperandTableNameLookup(spv_target_env env,
  1959. const spv_operand_table table,
  1960. const spv_operand_type_t type,
  1961. const char* name,
  1962. const size_t nameLength) {
  1963. if (!table) return SPV_ERROR_INVALID_TABLE;
  1964. if (!name) return SPV_ERROR_INVALID_POINTER;
  1965. for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) {
  1966. const auto& group = table->types[typeIndex];
  1967. if (type != group.type) continue;
  1968. for (uint64_t index = 0; index < group.count; ++index) {
  1969. const auto& entry = group.entries[index];
  1970. // Check for min version only.
  1971. if (spvVersionForTargetEnv(env) >= entry.minVersion &&
  1972. nameLength == strlen(entry.name) &&
  1973. !strncmp(entry.name, name, nameLength)) {
  1974. return SPV_SUCCESS;
  1975. }
  1976. }
  1977. }
  1978. return SPV_ERROR_INVALID_LOOKUP;
  1979. }
  1980. // True if capability exists in core spec of env.
  1981. bool Exists(const std::string& capability, spv_target_env env) {
  1982. ScopedContext sc(env);
  1983. return SPV_SUCCESS ==
  1984. spvCoreOperandTableNameLookup(env, sc.context->operand_table,
  1985. SPV_OPERAND_TYPE_CAPABILITY,
  1986. capability.c_str(), capability.size());
  1987. }
  1988. TEST_P(ValidateCapability, Capability) {
  1989. const std::string capability = Capability(GetParam());
  1990. spv_target_env env = SPV_ENV_UNIVERSAL_1_0;
  1991. if (!capability.empty()) {
  1992. if (Exists(capability, SPV_ENV_UNIVERSAL_1_0))
  1993. env = SPV_ENV_UNIVERSAL_1_0;
  1994. else if (Exists(capability, SPV_ENV_UNIVERSAL_1_1))
  1995. env = SPV_ENV_UNIVERSAL_1_1;
  1996. else if (Exists(capability, SPV_ENV_UNIVERSAL_1_2))
  1997. env = SPV_ENV_UNIVERSAL_1_2;
  1998. else
  1999. env = SPV_ENV_UNIVERSAL_1_3;
  2000. }
  2001. const std::string test_code = MakeAssembly(GetParam());
  2002. CompileSuccessfully(test_code, env);
  2003. ASSERT_EQ(ExpectedResult(GetParam()), ValidateInstructions(env))
  2004. << "target env: " << spvTargetEnvDescription(env) << "\ntest code:\n"
  2005. << test_code;
  2006. }
  2007. TEST_P(ValidateCapabilityV11, Capability) {
  2008. const std::string capability = Capability(GetParam());
  2009. if (Exists(capability, SPV_ENV_UNIVERSAL_1_1)) {
  2010. const std::string test_code = MakeAssembly(GetParam());
  2011. CompileSuccessfully(test_code, SPV_ENV_UNIVERSAL_1_1);
  2012. ASSERT_EQ(ExpectedResult(GetParam()),
  2013. ValidateInstructions(SPV_ENV_UNIVERSAL_1_1))
  2014. << test_code;
  2015. }
  2016. }
  2017. TEST_P(ValidateCapabilityVulkan10, Capability) {
  2018. const std::string capability = Capability(GetParam());
  2019. if (Exists(capability, SPV_ENV_VULKAN_1_0)) {
  2020. const std::string test_code = MakeAssembly(GetParam());
  2021. CompileSuccessfully(test_code, SPV_ENV_VULKAN_1_0);
  2022. ASSERT_EQ(ExpectedResult(GetParam()),
  2023. ValidateInstructions(SPV_ENV_VULKAN_1_0))
  2024. << test_code;
  2025. }
  2026. }
  2027. TEST_P(ValidateCapabilityVulkan11, Capability) {
  2028. const std::string capability = Capability(GetParam());
  2029. if (Exists(capability, SPV_ENV_VULKAN_1_1)) {
  2030. const std::string test_code = MakeAssembly(GetParam());
  2031. CompileSuccessfully(test_code, SPV_ENV_VULKAN_1_1);
  2032. ASSERT_EQ(ExpectedResult(GetParam()),
  2033. ValidateInstructions(SPV_ENV_VULKAN_1_1))
  2034. << test_code;
  2035. }
  2036. }
  2037. TEST_P(ValidateCapabilityVulkan12, Capability) {
  2038. const std::string capability = Capability(GetParam());
  2039. if (Exists(capability, SPV_ENV_VULKAN_1_2)) {
  2040. const std::string test_code = MakeAssembly(GetParam());
  2041. CompileSuccessfully(test_code, SPV_ENV_VULKAN_1_2);
  2042. ASSERT_EQ(ExpectedResult(GetParam()),
  2043. ValidateInstructions(SPV_ENV_VULKAN_1_2))
  2044. << test_code;
  2045. }
  2046. }
  2047. TEST_P(ValidateCapabilityOpenGL40, Capability) {
  2048. const std::string capability = Capability(GetParam());
  2049. if (Exists(capability, SPV_ENV_OPENGL_4_0)) {
  2050. const std::string test_code = MakeAssembly(GetParam());
  2051. CompileSuccessfully(test_code, SPV_ENV_OPENGL_4_0);
  2052. ASSERT_EQ(ExpectedResult(GetParam()),
  2053. ValidateInstructions(SPV_ENV_OPENGL_4_0))
  2054. << test_code;
  2055. }
  2056. }
  2057. TEST_F(ValidateCapability, SemanticsIdIsAnIdNotALiteral) {
  2058. // From https://github.com/KhronosGroup/SPIRV-Tools/issues/248
  2059. // The validator was interpreting the memory semantics ID number
  2060. // as the value to be checked rather than an ID that references
  2061. // another value to be checked.
  2062. // In this case a raw ID of 64 was mistaken to mean a literal
  2063. // semantic value of UniformMemory, which would require the Shader
  2064. // capability.
  2065. const char str[] = R"(
  2066. OpCapability Kernel
  2067. OpCapability Linkage
  2068. OpMemoryModel Logical OpenCL
  2069. ; %i32 has ID 1
  2070. %i32 = OpTypeInt 32 0
  2071. %tf = OpTypeFunction %i32
  2072. %pi32 = OpTypePointer CrossWorkgroup %i32
  2073. %var = OpVariable %pi32 CrossWorkgroup
  2074. %c = OpConstant %i32 100
  2075. %scope = OpConstant %i32 1 ; Device scope
  2076. ; Fake an instruction with 64 as the result id.
  2077. ; !64 = OpConstantNull %i32
  2078. !0x3002e !1 !64
  2079. %f = OpFunction %i32 None %tf
  2080. %l = OpLabel
  2081. %result = OpAtomicIAdd %i32 %var %scope !64 %c
  2082. OpReturnValue %result
  2083. OpFunctionEnd
  2084. )";
  2085. CompileSuccessfully(str);
  2086. // Since we are forcing usage of <id> 64, the "id bound" in the binary header
  2087. // must be overwritten so that <id> 64 is considered within bound.
  2088. // ID Bound is at index 3 of the binary. Set it to 65.
  2089. OverwriteAssembledBinary(3, 65);
  2090. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2091. }
  2092. TEST_F(ValidateCapability, IntSignednessKernelGood) {
  2093. const std::string spirv = R"(
  2094. OpCapability Kernel
  2095. OpCapability Linkage
  2096. OpMemoryModel Logical OpenCL
  2097. %i32 = OpTypeInt 32 0
  2098. )";
  2099. CompileSuccessfully(spirv);
  2100. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  2101. }
  2102. TEST_F(ValidateCapability, IntSignednessKernelBad) {
  2103. const std::string spirv = R"(
  2104. OpCapability Kernel
  2105. OpCapability Linkage
  2106. OpMemoryModel Logical OpenCL
  2107. %i32 = OpTypeInt 32 1
  2108. )";
  2109. CompileSuccessfully(spirv);
  2110. EXPECT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions());
  2111. EXPECT_THAT(getDiagnosticString(),
  2112. HasSubstr("The Signedness in OpTypeInt must always be 0 when "
  2113. "Kernel capability is used."));
  2114. }
  2115. TEST_F(ValidateCapability, IntSignednessShaderGood) {
  2116. const std::string spirv = R"(
  2117. OpCapability Shader
  2118. OpCapability Linkage
  2119. OpMemoryModel Logical GLSL450
  2120. %u32 = OpTypeInt 32 0
  2121. %i32 = OpTypeInt 32 1
  2122. )";
  2123. CompileSuccessfully(spirv);
  2124. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  2125. }
  2126. TEST_F(ValidateCapability, NonVulkan10Capability) {
  2127. const std::string spirv = R"(
  2128. OpCapability Shader
  2129. OpCapability Linkage
  2130. OpMemoryModel Logical GLSL450
  2131. %u32 = OpTypeInt 32 0
  2132. %i32 = OpTypeInt 32 1
  2133. )";
  2134. CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
  2135. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2136. ValidateInstructions(SPV_ENV_VULKAN_1_0));
  2137. EXPECT_THAT(getDiagnosticString(),
  2138. HasSubstr("Capability Linkage is not allowed by Vulkan 1.0"));
  2139. }
  2140. TEST_F(ValidateCapability, Vulkan10EnabledByExtension) {
  2141. const std::string spirv = R"(
  2142. OpCapability Shader
  2143. OpCapability DrawParameters
  2144. OpExtension "SPV_KHR_shader_draw_parameters"
  2145. OpMemoryModel Logical GLSL450
  2146. OpEntryPoint Vertex %func "shader"
  2147. OpMemberDecorate %block 0 BuiltIn PointSize
  2148. %f32 = OpTypeFloat 32
  2149. %block = OpTypeStruct %f32
  2150. )" + std::string(kVoidFVoid);
  2151. CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
  2152. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
  2153. }
  2154. TEST_F(ValidateCapability, Vulkan10NotEnabledByExtension) {
  2155. const std::string spirv = R"(
  2156. OpCapability Shader
  2157. OpCapability DrawParameters
  2158. OpMemoryModel Logical GLSL450
  2159. OpEntryPoint Vertex %func "shader"
  2160. OpDecorate %intt BuiltIn PointSize
  2161. %intt = OpTypeInt 32 0
  2162. )" + std::string(kVoidFVoid);
  2163. CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
  2164. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2165. ValidateInstructions(SPV_ENV_VULKAN_1_0));
  2166. EXPECT_THAT(
  2167. getDiagnosticString(),
  2168. HasSubstr("Capability DrawParameters is not allowed by Vulkan 1.0"));
  2169. }
  2170. TEST_F(ValidateCapability, NonOpenCL12FullCapability) {
  2171. const std::string spirv = R"(
  2172. OpCapability Kernel
  2173. OpCapability Addresses
  2174. OpCapability Linkage
  2175. OpCapability Pipes
  2176. OpMemoryModel Physical64 OpenCL
  2177. %u32 = OpTypeInt 32 0
  2178. )";
  2179. CompileSuccessfully(spirv, SPV_ENV_OPENCL_1_2);
  2180. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2181. ValidateInstructions(SPV_ENV_OPENCL_1_2));
  2182. EXPECT_THAT(
  2183. getDiagnosticString(),
  2184. HasSubstr("Capability Pipes is not allowed by OpenCL 1.2 Full Profile"));
  2185. }
  2186. TEST_F(ValidateCapability, OpenCL12FullEnabledByCapability) {
  2187. const std::string spirv = R"(
  2188. OpCapability Kernel
  2189. OpCapability Addresses
  2190. OpCapability Linkage
  2191. OpCapability ImageBasic
  2192. OpCapability Sampled1D
  2193. OpMemoryModel Physical64 OpenCL
  2194. %u32 = OpTypeInt 32 0
  2195. )" + std::string(kVoidFVoid);
  2196. CompileSuccessfully(spirv, SPV_ENV_OPENCL_1_2);
  2197. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_1_2));
  2198. }
  2199. TEST_F(ValidateCapability, OpenCL12FullNotEnabledByCapability) {
  2200. const std::string spirv = R"(
  2201. OpCapability Kernel
  2202. OpCapability Addresses
  2203. OpCapability Linkage
  2204. OpCapability Sampled1D
  2205. OpMemoryModel Physical64 OpenCL
  2206. %u32 = OpTypeInt 32 0
  2207. )" + std::string(kVoidFVoid);
  2208. CompileSuccessfully(spirv, SPV_ENV_OPENCL_1_2);
  2209. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2210. ValidateInstructions(SPV_ENV_OPENCL_1_2));
  2211. EXPECT_THAT(
  2212. getDiagnosticString(),
  2213. HasSubstr(
  2214. "Capability Sampled1D is not allowed by OpenCL 1.2 Full Profile"));
  2215. }
  2216. TEST_F(ValidateCapability, NonOpenCL12EmbeddedCapability) {
  2217. const std::string spirv = R"(
  2218. OpCapability Kernel
  2219. OpCapability Addresses
  2220. OpCapability Linkage
  2221. OpCapability Int64
  2222. OpMemoryModel Physical64 OpenCL
  2223. %u32 = OpTypeInt 32 0
  2224. )";
  2225. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
  2226. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2227. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
  2228. EXPECT_THAT(
  2229. getDiagnosticString(),
  2230. HasSubstr(
  2231. "Capability Int64 is not allowed by OpenCL 1.2 Embedded Profile"));
  2232. }
  2233. TEST_F(ValidateCapability, OpenCL12EmbeddedEnabledByCapability) {
  2234. const std::string spirv = R"(
  2235. OpCapability Kernel
  2236. OpCapability Addresses
  2237. OpCapability Linkage
  2238. OpCapability ImageBasic
  2239. OpCapability Sampled1D
  2240. OpMemoryModel Physical64 OpenCL
  2241. %u32 = OpTypeInt 32 0
  2242. )" + std::string(kVoidFVoid);
  2243. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
  2244. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
  2245. }
  2246. TEST_F(ValidateCapability, OpenCL12EmbeddedNotEnabledByCapability) {
  2247. const std::string spirv = R"(
  2248. OpCapability Kernel
  2249. OpCapability Addresses
  2250. OpCapability Linkage
  2251. OpCapability Sampled1D
  2252. OpMemoryModel Physical64 OpenCL
  2253. %u32 = OpTypeInt 32 0
  2254. )" + std::string(kVoidFVoid);
  2255. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
  2256. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2257. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
  2258. EXPECT_THAT(getDiagnosticString(),
  2259. HasSubstr("Capability Sampled1D is not allowed by OpenCL 1.2 "
  2260. "Embedded Profile"));
  2261. }
  2262. TEST_F(ValidateCapability, OpenCL12EmbeddedNoLongerEnabledByCapability) {
  2263. const std::string spirv = R"(
  2264. OpCapability Kernel
  2265. OpCapability Addresses
  2266. OpCapability Linkage
  2267. OpCapability Pipes
  2268. OpMemoryModel Physical64 OpenCL
  2269. %u32 = OpTypeInt 32 0
  2270. )" + std::string(kVoidFVoid);
  2271. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
  2272. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2273. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
  2274. EXPECT_THAT(getDiagnosticString(),
  2275. HasSubstr("Capability Pipes is not allowed by OpenCL 1.2 "
  2276. "Embedded Profile"));
  2277. }
  2278. TEST_F(ValidateCapability, OpenCL20FullCapability) {
  2279. const std::string spirv = R"(
  2280. OpCapability Kernel
  2281. OpCapability Addresses
  2282. OpCapability Linkage
  2283. OpCapability Groups
  2284. OpCapability Pipes
  2285. OpMemoryModel Physical64 OpenCL
  2286. %u32 = OpTypeInt 32 0
  2287. )";
  2288. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
  2289. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_0));
  2290. }
  2291. TEST_F(ValidateCapability, NonOpenCL20FullCapability) {
  2292. const std::string spirv = R"(
  2293. OpCapability Kernel
  2294. OpCapability Addresses
  2295. OpCapability Linkage
  2296. OpCapability Matrix
  2297. OpMemoryModel Physical64 OpenCL
  2298. %u32 = OpTypeInt 32 0
  2299. )";
  2300. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
  2301. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2302. ValidateInstructions(SPV_ENV_OPENCL_2_0));
  2303. EXPECT_THAT(
  2304. getDiagnosticString(),
  2305. HasSubstr(
  2306. "Capability Matrix is not allowed by OpenCL 2.0/2.1 Full Profile"));
  2307. }
  2308. TEST_F(ValidateCapability, OpenCL20FullEnabledByCapability) {
  2309. const std::string spirv = R"(
  2310. OpCapability Kernel
  2311. OpCapability Addresses
  2312. OpCapability Linkage
  2313. OpCapability ImageBasic
  2314. OpCapability Sampled1D
  2315. OpMemoryModel Physical64 OpenCL
  2316. %u32 = OpTypeInt 32 0
  2317. )" + std::string(kVoidFVoid);
  2318. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
  2319. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_0));
  2320. }
  2321. TEST_F(ValidateCapability, OpenCL20FullNotEnabledByCapability) {
  2322. const std::string spirv = R"(
  2323. OpCapability Kernel
  2324. OpCapability Addresses
  2325. OpCapability Linkage
  2326. OpCapability Sampled1D
  2327. OpMemoryModel Physical64 OpenCL
  2328. %u32 = OpTypeInt 32 0
  2329. )" + std::string(kVoidFVoid);
  2330. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
  2331. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2332. ValidateInstructions(SPV_ENV_OPENCL_2_0));
  2333. EXPECT_THAT(getDiagnosticString(),
  2334. HasSubstr("Capability Sampled1D is not allowed by OpenCL 2.0/2.1 "
  2335. "Full Profile"));
  2336. }
  2337. TEST_F(ValidateCapability, NonOpenCL20EmbeddedCapability) {
  2338. const std::string spirv = R"(
  2339. OpCapability Kernel
  2340. OpCapability Addresses
  2341. OpCapability Linkage
  2342. OpCapability Int64
  2343. OpMemoryModel Physical64 OpenCL
  2344. %u32 = OpTypeInt 32 0
  2345. )";
  2346. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_0);
  2347. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2348. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_0));
  2349. EXPECT_THAT(getDiagnosticString(),
  2350. HasSubstr("Capability Int64 is not allowed by OpenCL 2.0/2.1 "
  2351. "Embedded Profile"));
  2352. }
  2353. TEST_F(ValidateCapability, OpenCL20EmbeddedEnabledByCapability) {
  2354. const std::string spirv = R"(
  2355. OpCapability Kernel
  2356. OpCapability Addresses
  2357. OpCapability Linkage
  2358. OpCapability ImageBasic
  2359. OpCapability Sampled1D
  2360. OpMemoryModel Physical64 OpenCL
  2361. %u32 = OpTypeInt 32 0
  2362. )" + std::string(kVoidFVoid);
  2363. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_0);
  2364. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_0));
  2365. }
  2366. TEST_F(ValidateCapability, OpenCL20EmbeddedNotEnabledByCapability) {
  2367. const std::string spirv = R"(
  2368. OpCapability Kernel
  2369. OpCapability Addresses
  2370. OpCapability Linkage
  2371. OpCapability Sampled1D
  2372. OpMemoryModel Physical64 OpenCL
  2373. %u32 = OpTypeInt 32 0
  2374. )" + std::string(kVoidFVoid);
  2375. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_0);
  2376. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2377. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_0));
  2378. EXPECT_THAT(getDiagnosticString(),
  2379. HasSubstr("Capability Sampled1D is not allowed by OpenCL 2.0/2.1 "
  2380. "Embedded Profile"));
  2381. }
  2382. TEST_F(ValidateCapability, OpenCL22FullCapability) {
  2383. const std::string spirv = R"(
  2384. OpCapability Kernel
  2385. OpCapability Addresses
  2386. OpCapability Linkage
  2387. OpCapability PipeStorage
  2388. OpMemoryModel Physical64 OpenCL
  2389. %u32 = OpTypeInt 32 0
  2390. )";
  2391. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
  2392. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_2));
  2393. }
  2394. TEST_F(ValidateCapability, NonOpenCL22FullCapability) {
  2395. const std::string spirv = R"(
  2396. OpCapability Kernel
  2397. OpCapability Addresses
  2398. OpCapability Linkage
  2399. OpCapability Matrix
  2400. OpMemoryModel Physical64 OpenCL
  2401. %u32 = OpTypeInt 32 0
  2402. )";
  2403. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
  2404. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2405. ValidateInstructions(SPV_ENV_OPENCL_2_2));
  2406. EXPECT_THAT(
  2407. getDiagnosticString(),
  2408. HasSubstr("Capability Matrix is not allowed by OpenCL 2.2 Full Profile"));
  2409. }
  2410. TEST_F(ValidateCapability, OpenCL22FullEnabledByCapability) {
  2411. const std::string spirv = R"(
  2412. OpCapability Kernel
  2413. OpCapability Addresses
  2414. OpCapability Linkage
  2415. OpCapability ImageBasic
  2416. OpCapability Sampled1D
  2417. OpMemoryModel Physical64 OpenCL
  2418. %u32 = OpTypeInt 32 0
  2419. )" + std::string(kVoidFVoid);
  2420. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
  2421. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_2));
  2422. }
  2423. TEST_F(ValidateCapability, OpenCL22FullNotEnabledByCapability) {
  2424. const std::string spirv = R"(
  2425. OpCapability Kernel
  2426. OpCapability Addresses
  2427. OpCapability Linkage
  2428. OpCapability Sampled1D
  2429. OpMemoryModel Physical64 OpenCL
  2430. %u32 = OpTypeInt 32 0
  2431. )" + std::string(kVoidFVoid);
  2432. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
  2433. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2434. ValidateInstructions(SPV_ENV_OPENCL_2_2));
  2435. EXPECT_THAT(
  2436. getDiagnosticString(),
  2437. HasSubstr(
  2438. "Capability Sampled1D is not allowed by OpenCL 2.2 Full Profile"));
  2439. }
  2440. TEST_F(ValidateCapability, NonOpenCL22EmbeddedCapability) {
  2441. const std::string spirv = R"(
  2442. OpCapability Kernel
  2443. OpCapability Addresses
  2444. OpCapability Linkage
  2445. OpCapability Int64
  2446. OpMemoryModel Physical64 OpenCL
  2447. %u32 = OpTypeInt 32 0
  2448. )";
  2449. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_2);
  2450. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2451. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_2));
  2452. EXPECT_THAT(
  2453. getDiagnosticString(),
  2454. HasSubstr(
  2455. "Capability Int64 is not allowed by OpenCL 2.2 Embedded Profile"));
  2456. }
  2457. TEST_F(ValidateCapability, OpenCL22EmbeddedEnabledByCapability) {
  2458. const std::string spirv = R"(
  2459. OpCapability Kernel
  2460. OpCapability Addresses
  2461. OpCapability Linkage
  2462. OpCapability ImageBasic
  2463. OpCapability Sampled1D
  2464. OpMemoryModel Physical64 OpenCL
  2465. %u32 = OpTypeInt 32 0
  2466. )" + std::string(kVoidFVoid);
  2467. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_2);
  2468. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_2));
  2469. }
  2470. TEST_F(ValidateCapability, OpenCL22EmbeddedNotEnabledByCapability) {
  2471. const std::string spirv = R"(
  2472. OpCapability Kernel
  2473. OpCapability Addresses
  2474. OpCapability Linkage
  2475. OpCapability Sampled1D
  2476. OpMemoryModel Physical64 OpenCL
  2477. %u32 = OpTypeInt 32 0
  2478. )" + std::string(kVoidFVoid);
  2479. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_2);
  2480. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2481. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_2));
  2482. EXPECT_THAT(getDiagnosticString(),
  2483. HasSubstr("Capability Sampled1D is not allowed by OpenCL 2.2 "
  2484. "Embedded Profile"));
  2485. }
  2486. // Three tests to check enablement of an enum (a decoration) which is not
  2487. // in core, and is directly enabled by a capability, but not directly enabled
  2488. // by an extension. See https://github.com/KhronosGroup/SPIRV-Tools/issues/1596
  2489. TEST_F(ValidateCapability, DecorationFromExtensionMissingEnabledByCapability) {
  2490. // Decoration ViewportRelativeNV is enabled by ShaderViewportMaskNV, which in
  2491. // turn is enabled by SPV_NV_viewport_array2.
  2492. const std::string spirv = R"(
  2493. OpCapability Shader
  2494. OpMemoryModel Logical Simple
  2495. OpDecorate %void ViewportRelativeNV
  2496. )" + std::string(kVoidFVoid);
  2497. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2498. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2499. ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
  2500. EXPECT_THAT(getDiagnosticString(),
  2501. HasSubstr("Operand 2 of Decorate requires one of these "
  2502. "capabilities: ShaderViewportMaskNV"));
  2503. }
  2504. TEST_F(ValidateCapability, CapabilityEnabledByMissingExtension) {
  2505. // Capability ShaderViewportMaskNV is enabled by SPV_NV_viewport_array2.
  2506. const std::string spirv = R"(
  2507. OpCapability Shader
  2508. OpCapability ShaderViewportMaskNV
  2509. OpMemoryModel Logical Simple
  2510. )" + std::string(kVoidFVoid);
  2511. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2512. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2513. ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
  2514. EXPECT_THAT(getDiagnosticString(),
  2515. HasSubstr("operand ShaderViewportMaskNV(5255) requires one of "
  2516. "these extensions: SPV_NV_viewport_array2"));
  2517. }
  2518. TEST_F(ValidateCapability,
  2519. DecorationEnabledByCapabilityEnabledByPresentExtension) {
  2520. // Decoration ViewportRelativeNV is enabled by ShaderViewportMaskNV, which in
  2521. // turn is enabled by SPV_NV_viewport_array2.
  2522. const std::string spirv = R"(
  2523. OpCapability Shader
  2524. OpCapability Linkage
  2525. OpCapability ShaderViewportMaskNV
  2526. OpExtension "SPV_NV_viewport_array2"
  2527. OpMemoryModel Logical Simple
  2528. OpDecorate %void ViewportRelativeNV
  2529. %void = OpTypeVoid
  2530. )";
  2531. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2532. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0))
  2533. << getDiagnosticString();
  2534. }
  2535. // Three tests to check enablement of an instruction which is not in core, and
  2536. // is directly enabled by a capability, but not directly enabled by an
  2537. // extension. See https://github.com/KhronosGroup/SPIRV-Tools/issues/1624
  2538. // Instruction OpSubgroupShuffleINTEL is enabled by SubgroupShuffleINTEL, which
  2539. // in turn is enabled by SPV_INTEL_subgroups.
  2540. TEST_F(ValidateCapability, InstructionFromExtensionMissingEnabledByCapability) {
  2541. // Decoration ViewportRelativeNV is enabled by ShaderViewportMaskNV, which in
  2542. // turn is enabled by SPV_NV_viewport_array2.
  2543. const std::string spirv = R"(
  2544. OpCapability Kernel
  2545. OpCapability Addresses
  2546. ; OpCapability SubgroupShuffleINTEL
  2547. OpExtension "SPV_INTEL_subgroups"
  2548. OpMemoryModel Physical32 OpenCL
  2549. OpEntryPoint Kernel %main "main"
  2550. %void = OpTypeVoid
  2551. %uint = OpTypeInt 32 0
  2552. %voidfn = OpTypeFunction %void
  2553. %zero = OpConstant %uint 0
  2554. %main = OpFunction %void None %voidfn
  2555. %entry = OpLabel
  2556. %foo = OpSubgroupShuffleINTEL %uint %zero %zero
  2557. OpReturn
  2558. OpFunctionEnd
  2559. )";
  2560. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2561. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2562. ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
  2563. EXPECT_THAT(getDiagnosticString(),
  2564. HasSubstr("Opcode SubgroupShuffleINTEL requires one of these "
  2565. "capabilities: SubgroupShuffleINTEL"));
  2566. }
  2567. TEST_F(ValidateCapability,
  2568. InstructionEnablingCapabilityEnabledByMissingExtension) {
  2569. const std::string spirv = R"(
  2570. OpCapability Kernel
  2571. OpCapability Addresses
  2572. OpCapability SubgroupShuffleINTEL
  2573. ; OpExtension "SPV_INTEL_subgroups"
  2574. OpMemoryModel Physical32 OpenCL
  2575. OpEntryPoint Kernel %main "main"
  2576. %void = OpTypeVoid
  2577. %uint = OpTypeInt 32 0
  2578. %voidfn = OpTypeFunction %void
  2579. %zero = OpConstant %uint 0
  2580. %main = OpFunction %void None %voidfn
  2581. %entry = OpLabel
  2582. %foo = OpSubgroupShuffleINTEL %uint %zero %zero
  2583. OpReturn
  2584. OpFunctionEnd
  2585. )";
  2586. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2587. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2588. ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
  2589. EXPECT_THAT(getDiagnosticString(),
  2590. HasSubstr("operand SubgroupShuffleINTEL(5568) requires one of "
  2591. "these extensions: SPV_INTEL_subgroups"));
  2592. }
  2593. TEST_F(ValidateCapability,
  2594. InstructionEnabledByCapabilityEnabledByPresentExtension) {
  2595. const std::string spirv = R"(
  2596. OpCapability Kernel
  2597. OpCapability Addresses
  2598. OpCapability SubgroupShuffleINTEL
  2599. OpExtension "SPV_INTEL_subgroups"
  2600. OpMemoryModel Physical32 OpenCL
  2601. OpEntryPoint Kernel %main "main"
  2602. %void = OpTypeVoid
  2603. %uint = OpTypeInt 32 0
  2604. %voidfn = OpTypeFunction %void
  2605. %zero = OpConstant %uint 0
  2606. %main = OpFunction %void None %voidfn
  2607. %entry = OpLabel
  2608. %foo = OpSubgroupShuffleINTEL %uint %zero %zero
  2609. OpReturn
  2610. OpFunctionEnd
  2611. )";
  2612. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2613. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0))
  2614. << getDiagnosticString();
  2615. }
  2616. TEST_F(ValidateCapability, VulkanMemoryModelWithVulkanKHR) {
  2617. const std::string spirv = R"(
  2618. OpCapability Shader
  2619. OpCapability VulkanMemoryModelKHR
  2620. OpCapability Linkage
  2621. OpExtension "SPV_KHR_vulkan_memory_model"
  2622. OpMemoryModel Logical VulkanKHR
  2623. )";
  2624. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
  2625. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3))
  2626. << getDiagnosticString();
  2627. }
  2628. TEST_F(ValidateCapability, VulkanMemoryModelWithGLSL450) {
  2629. const std::string spirv = R"(
  2630. OpCapability Shader
  2631. OpCapability VulkanMemoryModelKHR
  2632. OpCapability Linkage
  2633. OpExtension "SPV_KHR_vulkan_memory_model"
  2634. OpMemoryModel Logical GLSL450
  2635. )";
  2636. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
  2637. EXPECT_EQ(SPV_ERROR_INVALID_DATA,
  2638. ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
  2639. EXPECT_THAT(getDiagnosticString(),
  2640. HasSubstr("VulkanMemoryModelKHR capability must only be "
  2641. "specified if the VulkanKHR memory model is used"));
  2642. }
  2643. // In the grammar, SubgroupEqMask and SubgroupMaskKHR have different enabling
  2644. // lists of extensions.
  2645. TEST_F(ValidateCapability, SubgroupEqMaskEnabledByExtension) {
  2646. const std::string spirv = R"(
  2647. OpCapability Shader
  2648. OpCapability SubgroupBallotKHR
  2649. OpExtension "SPV_KHR_shader_ballot"
  2650. OpMemoryModel Logical Simple
  2651. OpEntryPoint GLCompute %main "main"
  2652. OpDecorate %var BuiltIn SubgroupEqMask
  2653. %void = OpTypeVoid
  2654. %uint = OpTypeInt 32 0
  2655. %ptr_uint = OpTypePointer Private %uint
  2656. %var = OpVariable %ptr_uint Private
  2657. %fn = OpTypeFunction %void
  2658. %main = OpFunction %void None %fn
  2659. %entry = OpLabel
  2660. %val = OpLoad %uint %var
  2661. OpReturn
  2662. OpFunctionEnd
  2663. )";
  2664. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2665. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0))
  2666. << getDiagnosticString();
  2667. }
  2668. // Test that extensions incorporated into SPIR-V 1.5 no longer require
  2669. // the associated OpExtension instruction. Test one capability per extension.
  2670. struct CapabilityExtensionVersionCase {
  2671. std::string capability;
  2672. std::string capability_new_name;
  2673. std::string extension;
  2674. spv_target_env last_version_requiring_extension;
  2675. spv_target_env first_version_in_core;
  2676. };
  2677. using ValidateCapabilityExtensionVersionTest =
  2678. spvtest::ValidateBase<CapabilityExtensionVersionCase>;
  2679. // Returns a minimal shader module with the given capability instruction.
  2680. std::string MinimalShaderModuleWithCapability(std::string cap) {
  2681. std::string mem_model =
  2682. (cap.find("VulkanMemory") == 0) ? "VulkanKHR" : "GLSL450";
  2683. std::string extra_cap = (cap.find("VulkanMemoryModelDeviceScope") == 0)
  2684. ? "\nOpCapability VulkanMemoryModelKHR\n"
  2685. : "";
  2686. return std::string("OpCapability ") + cap + extra_cap + R"(
  2687. OpCapability Shader
  2688. OpMemoryModel Logical )" + mem_model + R"(
  2689. OpEntryPoint Vertex %main "main"
  2690. %void = OpTypeVoid
  2691. %void_fn = OpTypeFunction %void
  2692. %main = OpFunction %void None %void_fn
  2693. %entry = OpLabel
  2694. OpReturn
  2695. OpFunctionEnd
  2696. )";
  2697. }
  2698. TEST_P(ValidateCapabilityExtensionVersionTest, FailsInOlderSpirvVersion) {
  2699. const auto spirv = MinimalShaderModuleWithCapability(GetParam().capability);
  2700. CompileSuccessfully(spirv, GetParam().last_version_requiring_extension);
  2701. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2702. ValidateInstructions(GetParam().last_version_requiring_extension));
  2703. EXPECT_THAT(getDiagnosticString(),
  2704. HasSubstr(std::string("1st operand of Capability: operand ") +
  2705. GetParam().capability_new_name))
  2706. << spirv << "\n";
  2707. EXPECT_THAT(getDiagnosticString(),
  2708. HasSubstr(std::string("requires one of these extensions: ") +
  2709. GetParam().extension));
  2710. }
  2711. TEST_P(ValidateCapabilityExtensionVersionTest,
  2712. SucceedsInNewerSpirvVersionWithOldName) {
  2713. const auto spirv = MinimalShaderModuleWithCapability(GetParam().capability);
  2714. CompileSuccessfully(spirv, GetParam().first_version_in_core);
  2715. EXPECT_EQ(SPV_SUCCESS,
  2716. ValidateInstructions(GetParam().first_version_in_core));
  2717. EXPECT_THAT(getDiagnosticString(), Eq("")) << spirv << "\n";
  2718. }
  2719. TEST_P(ValidateCapabilityExtensionVersionTest,
  2720. SucceedsInNewerSpirvVersionWithNewName) {
  2721. const auto spirv =
  2722. MinimalShaderModuleWithCapability(GetParam().capability_new_name);
  2723. CompileSuccessfully(spirv, GetParam().first_version_in_core);
  2724. EXPECT_EQ(SPV_SUCCESS,
  2725. ValidateInstructions(GetParam().first_version_in_core));
  2726. EXPECT_THAT(getDiagnosticString(), Eq("")) << spirv << "\n";
  2727. }
  2728. std::vector<CapabilityExtensionVersionCase> CapVersionCases1_5() {
  2729. #define IN15NOSUFFIX(C, E) \
  2730. { C, C, E, SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_5 }
  2731. #define IN15(C, C_WITHOUT_SUFFIX, E) \
  2732. { C, C_WITHOUT_SUFFIX, E, SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_5 }
  2733. return std::vector<CapabilityExtensionVersionCase>{
  2734. // SPV_KHR_8bit_storage
  2735. IN15NOSUFFIX("StorageBuffer8BitAccess", "SPV_KHR_8bit_storage"),
  2736. IN15NOSUFFIX("UniformAndStorageBuffer8BitAccess", "SPV_KHR_8bit_storage"),
  2737. IN15NOSUFFIX("StoragePushConstant8", "SPV_KHR_8bit_storage"),
  2738. // SPV_EXT_descriptor_indexing
  2739. IN15("ShaderNonUniformEXT", "ShaderNonUniform",
  2740. "SPV_EXT_descriptor_indexing"),
  2741. IN15("RuntimeDescriptorArrayEXT", "RuntimeDescriptorArray",
  2742. "SPV_EXT_descriptor_indexing"),
  2743. IN15("InputAttachmentArrayDynamicIndexingEXT",
  2744. "InputAttachmentArrayDynamicIndexing",
  2745. "SPV_EXT_descriptor_indexing"),
  2746. IN15("UniformTexelBufferArrayDynamicIndexingEXT",
  2747. "UniformTexelBufferArrayDynamicIndexing",
  2748. "SPV_EXT_descriptor_indexing"),
  2749. IN15("StorageTexelBufferArrayDynamicIndexingEXT",
  2750. "StorageTexelBufferArrayDynamicIndexing",
  2751. "SPV_EXT_descriptor_indexing"),
  2752. IN15("UniformBufferArrayNonUniformIndexingEXT",
  2753. "UniformBufferArrayNonUniformIndexing",
  2754. "SPV_EXT_descriptor_indexing"),
  2755. IN15("SampledImageArrayNonUniformIndexingEXT",
  2756. "SampledImageArrayNonUniformIndexing",
  2757. "SPV_EXT_descriptor_indexing"),
  2758. IN15("StorageBufferArrayNonUniformIndexingEXT",
  2759. "StorageBufferArrayNonUniformIndexing",
  2760. "SPV_EXT_descriptor_indexing"),
  2761. IN15("StorageImageArrayNonUniformIndexingEXT",
  2762. "StorageImageArrayNonUniformIndexing",
  2763. "SPV_EXT_descriptor_indexing"),
  2764. IN15("InputAttachmentArrayNonUniformIndexingEXT",
  2765. "InputAttachmentArrayNonUniformIndexing",
  2766. "SPV_EXT_descriptor_indexing"),
  2767. IN15("UniformTexelBufferArrayNonUniformIndexingEXT",
  2768. "UniformTexelBufferArrayNonUniformIndexing",
  2769. "SPV_EXT_descriptor_indexing"),
  2770. IN15("StorageTexelBufferArrayNonUniformIndexingEXT",
  2771. "StorageTexelBufferArrayNonUniformIndexing",
  2772. "SPV_EXT_descriptor_indexing"),
  2773. // SPV_EXT_physical_storage_buffer
  2774. IN15("PhysicalStorageBufferAddresses", "PhysicalStorageBufferAddresses",
  2775. "SPV_EXT_physical_storage_buffer"),
  2776. // SPV_KHR_vulkan_memory_model
  2777. IN15("VulkanMemoryModelKHR", "VulkanMemoryModel",
  2778. "SPV_KHR_vulkan_memory_model"),
  2779. IN15("VulkanMemoryModelDeviceScopeKHR", "VulkanMemoryModelDeviceScope",
  2780. "SPV_KHR_vulkan_memory_model"),
  2781. };
  2782. #undef IN15
  2783. }
  2784. INSTANTIATE_TEST_SUITE_P(NewInSpirv1_5, ValidateCapabilityExtensionVersionTest,
  2785. ValuesIn(CapVersionCases1_5()));
  2786. TEST_P(ValidateCapability,
  2787. CapShaderViewportIndexLayerFailsInOlderSpirvVersion) {
  2788. const auto spirv =
  2789. MinimalShaderModuleWithCapability("ShaderViewportIndexLayerEXT");
  2790. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
  2791. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2792. ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
  2793. EXPECT_THAT(
  2794. getDiagnosticString(),
  2795. HasSubstr(
  2796. "1st operand of Capability: operand ShaderViewportIndexLayerEXT"));
  2797. EXPECT_THAT(getDiagnosticString(),
  2798. HasSubstr("requires one of these extensions: "
  2799. "SPV_EXT_shader_viewport_index_layer"));
  2800. }
  2801. TEST_P(ValidateCapability, CapShaderViewportIndexLayerFailsInNewSpirvVersion) {
  2802. const auto spirv =
  2803. MinimalShaderModuleWithCapability("ShaderViewportIndexLayerEXT");
  2804. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_5);
  2805. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2806. ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
  2807. EXPECT_THAT(
  2808. getDiagnosticString(),
  2809. HasSubstr(
  2810. "1st operand of Capability: operand ShaderViewportIndexLayerEXT"));
  2811. EXPECT_THAT(getDiagnosticString(),
  2812. HasSubstr("requires one of these extensions: "
  2813. "SPV_EXT_shader_viewport_index_layer"));
  2814. }
  2815. TEST_F(ValidateCapability, CapShaderViewportIndexSucceedsInNewSpirvVersion) {
  2816. const auto spirv = MinimalShaderModuleWithCapability("ShaderViewportIndex");
  2817. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_5);
  2818. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
  2819. EXPECT_THAT(getDiagnosticString(), Eq(""));
  2820. }
  2821. TEST_F(ValidateCapability, CapShaderLayerSucceedsInNewSpirvVersion) {
  2822. const auto spirv = MinimalShaderModuleWithCapability("ShaderLayer");
  2823. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_5);
  2824. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
  2825. EXPECT_THAT(getDiagnosticString(), Eq(""));
  2826. }
  2827. } // namespace
  2828. } // namespace val
  2829. } // namespace spvtools