2
0

val_capability_test.cpp 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874
  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 %intt RelaxedPrecision\n"
  1164. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1165. ShaderDependencies()),
  1166. std::make_pair(std::string(kOpenCLMemoryModel) +
  1167. // Block applies to struct type.
  1168. "OpEntryPoint Kernel %func \"compute\" \n"
  1169. "OpDecorate %block Block\n"
  1170. "%intt = OpTypeInt 32 0\n"
  1171. "%block = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
  1172. ShaderDependencies()),
  1173. std::make_pair(std::string(kOpenCLMemoryModel) +
  1174. // BufferBlock applies to struct type.
  1175. "OpEntryPoint Kernel %func \"compute\" \n"
  1176. "OpDecorate %block BufferBlock\n"
  1177. "%intt = OpTypeInt 32 0\n"
  1178. "%block = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
  1179. ShaderDependencies()),
  1180. std::make_pair(std::string(kOpenCLMemoryModel) +
  1181. "OpEntryPoint Kernel %func \"compute\" \n"
  1182. "OpDecorate %intt RowMajor\n"
  1183. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1184. MatrixDependencies()),
  1185. std::make_pair(std::string(kOpenCLMemoryModel) +
  1186. "OpEntryPoint Kernel %func \"compute\" \n"
  1187. "OpDecorate %intt ColMajor\n"
  1188. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1189. MatrixDependencies()),
  1190. std::make_pair(std::string(kOpenCLMemoryModel) +
  1191. "OpEntryPoint Kernel %func \"compute\" \n"
  1192. "OpDecorate %intt ArrayStride 1\n"
  1193. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1194. ShaderDependencies()),
  1195. std::make_pair(std::string(kOpenCLMemoryModel) +
  1196. "OpEntryPoint Kernel %func \"compute\" \n"
  1197. "OpDecorate %intt MatrixStride 1\n"
  1198. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1199. MatrixDependencies()),
  1200. std::make_pair(std::string(kOpenCLMemoryModel) +
  1201. "OpEntryPoint Kernel %func \"compute\" \n"
  1202. "OpDecorate %intt GLSLShared\n"
  1203. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1204. ShaderDependencies()),
  1205. std::make_pair(std::string(kOpenCLMemoryModel) +
  1206. "OpEntryPoint Kernel %func \"compute\" \n"
  1207. "OpDecorate %intt GLSLPacked\n"
  1208. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1209. ShaderDependencies()),
  1210. std::make_pair(std::string(kGLSL450MemoryModel) +
  1211. "OpEntryPoint Vertex %func \"shader\" \n"
  1212. "OpDecorate %intt CPacked\n"
  1213. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1214. KernelDependencies()),
  1215. std::make_pair(std::string(kOpenCLMemoryModel) +
  1216. "OpEntryPoint Kernel %func \"compute\" \n"
  1217. "OpDecorate %intt NoPerspective\n"
  1218. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1219. ShaderDependencies()),
  1220. std::make_pair(std::string(kOpenCLMemoryModel) +
  1221. "OpEntryPoint Kernel %func \"compute\" \n"
  1222. "OpDecorate %intt Flat\n"
  1223. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1224. ShaderDependencies()),
  1225. std::make_pair(std::string(kOpenCLMemoryModel) +
  1226. "OpEntryPoint Kernel %func \"compute\" \n"
  1227. "OpDecorate %intt Patch\n"
  1228. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1229. TessellationDependencies()),
  1230. std::make_pair(std::string(kOpenCLMemoryModel) +
  1231. "OpEntryPoint Kernel %func \"compute\" \n"
  1232. "OpDecorate %intt Centroid\n"
  1233. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1234. ShaderDependencies()),
  1235. std::make_pair(std::string(kOpenCLMemoryModel) +
  1236. "OpEntryPoint Kernel %func \"compute\" \n"
  1237. "OpDecorate %intt Sample\n"
  1238. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1239. std::vector<std::string>{"SampleRateShading"}),
  1240. std::make_pair(std::string(kOpenCLMemoryModel) +
  1241. "OpEntryPoint Kernel %func \"compute\" \n"
  1242. "OpDecorate %intt Invariant\n"
  1243. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1244. ShaderDependencies()),
  1245. std::make_pair(std::string(kOpenCLMemoryModel) +
  1246. "OpEntryPoint Kernel %func \"compute\" \n"
  1247. "OpDecorate %intt Restrict\n"
  1248. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1249. AllCapabilities()),
  1250. std::make_pair(std::string(kOpenCLMemoryModel) +
  1251. "OpEntryPoint Kernel %func \"compute\" \n"
  1252. "OpDecorate %intt Aliased\n"
  1253. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1254. AllCapabilities()),
  1255. std::make_pair(std::string(kOpenCLMemoryModel) +
  1256. "OpEntryPoint Kernel %func \"compute\" \n"
  1257. "OpDecorate %intt Volatile\n"
  1258. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1259. AllCapabilities()),
  1260. std::make_pair(std::string(kGLSL450MemoryModel) +
  1261. "OpEntryPoint Vertex %func \"shader\" \n"
  1262. "OpDecorate %intt Constant\n"
  1263. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1264. KernelDependencies()),
  1265. std::make_pair(std::string(kOpenCLMemoryModel) +
  1266. "OpEntryPoint Kernel %func \"compute\" \n"
  1267. "OpDecorate %intt Coherent\n"
  1268. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1269. AllCapabilities()),
  1270. std::make_pair(std::string(kOpenCLMemoryModel) +
  1271. // NonWritable must target something valid, such as a storage image.
  1272. "OpEntryPoint Kernel %func \"compute\" \n"
  1273. "OpDecorate %var NonWritable "
  1274. "%float = OpTypeFloat 32 "
  1275. "%imstor = OpTypeImage %float 2D 0 0 0 2 Unknown "
  1276. "%ptr = OpTypePointer UniformConstant %imstor "
  1277. "%var = OpVariable %ptr UniformConstant "
  1278. + std::string(kVoidFVoid),
  1279. AllCapabilities()),
  1280. std::make_pair(std::string(kOpenCLMemoryModel) +
  1281. "OpEntryPoint Kernel %func \"compute\" \n"
  1282. "OpDecorate %intt NonReadable\n"
  1283. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1284. AllCapabilities()),
  1285. std::make_pair(std::string(kOpenCLMemoryModel) +
  1286. // Uniform must target a non-void value.
  1287. "OpEntryPoint Kernel %func \"compute\" \n"
  1288. "OpDecorate %int0 Uniform\n"
  1289. "%intt = OpTypeInt 32 0\n" +
  1290. "%int0 = OpConstantNull %intt"
  1291. + std::string(kVoidFVoid),
  1292. ShaderDependencies()),
  1293. std::make_pair(std::string(kGLSL450MemoryModel) +
  1294. "OpEntryPoint Vertex %func \"shader\" \n"
  1295. "OpDecorate %intt SaturatedConversion\n"
  1296. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1297. KernelDependencies()),
  1298. std::make_pair(std::string(kOpenCLMemoryModel) +
  1299. "OpEntryPoint Kernel %func \"compute\" \n"
  1300. "OpDecorate %intt Stream 0\n"
  1301. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1302. std::vector<std::string>{"GeometryStreams"}),
  1303. std::make_pair(std::string(kOpenCLMemoryModel) +
  1304. "OpEntryPoint Kernel %func \"compute\" \n"
  1305. "OpMemberDecorate %struct 0 Location 0\n"
  1306. "%intt = OpTypeInt 32 0\n"
  1307. "%struct = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
  1308. ShaderDependencies()),
  1309. std::make_pair(std::string(kOpenCLMemoryModel) +
  1310. "OpEntryPoint Kernel %func \"compute\" \n"
  1311. "OpDecorate %var Component 0\n"
  1312. "%intt = OpTypeInt 32 0\n"
  1313. "%ptr = OpTypePointer Input %intt\n"
  1314. "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
  1315. ShaderDependencies()),
  1316. std::make_pair(std::string(kOpenCLMemoryModel) +
  1317. "OpEntryPoint Kernel %func \"compute\" \n"
  1318. "OpDecorate %intt Index 0\n"
  1319. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1320. ShaderDependencies()),
  1321. std::make_pair(std::string(kOpenCLMemoryModel) +
  1322. "OpEntryPoint Kernel %func \"compute\" \n"
  1323. "OpDecorate %intt Binding 0\n"
  1324. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1325. ShaderDependencies()),
  1326. std::make_pair(std::string(kOpenCLMemoryModel) +
  1327. "OpEntryPoint Kernel %func \"compute\" \n"
  1328. "OpDecorate %intt DescriptorSet 0\n"
  1329. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1330. ShaderDependencies()),
  1331. std::make_pair(std::string(kOpenCLMemoryModel) +
  1332. "OpEntryPoint Kernel %func \"compute\" \n"
  1333. "OpDecorate %intt Offset 0\n"
  1334. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1335. ShaderDependencies()),
  1336. std::make_pair(std::string(kOpenCLMemoryModel) +
  1337. "OpEntryPoint Kernel %func \"compute\" \n"
  1338. "OpDecorate %intt XfbBuffer 0\n"
  1339. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1340. std::vector<std::string>{"TransformFeedback"}),
  1341. std::make_pair(std::string(kOpenCLMemoryModel) +
  1342. "OpEntryPoint Kernel %func \"compute\" \n"
  1343. "OpDecorate %intt XfbStride 0\n"
  1344. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1345. std::vector<std::string>{"TransformFeedback"}),
  1346. std::make_pair(std::string(kGLSL450MemoryModel) +
  1347. "OpEntryPoint Vertex %func \"shader\" \n"
  1348. "OpDecorate %intt FuncParamAttr Zext\n"
  1349. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1350. KernelDependencies()),
  1351. std::make_pair(std::string(kGLSL450MemoryModel) +
  1352. "OpEntryPoint Vertex %func \"shader\" \n"
  1353. "OpDecorate %intt FPFastMathMode Fast\n"
  1354. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1355. KernelDependencies()),
  1356. std::make_pair(std::string(kOpenCLMemoryModel) +
  1357. "OpEntryPoint Kernel %func \"compute\" \n"
  1358. "OpDecorate %intt LinkageAttributes \"other\" Import\n"
  1359. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1360. std::vector<std::string>{"Linkage"}),
  1361. std::make_pair(std::string(kOpenCLMemoryModel) +
  1362. "OpEntryPoint Kernel %func \"compute\" \n"
  1363. "OpDecorate %intt NoContraction\n"
  1364. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1365. ShaderDependencies()),
  1366. std::make_pair(std::string(kOpenCLMemoryModel) +
  1367. "OpEntryPoint Kernel %func \"compute\" \n"
  1368. "OpDecorate %intt InputAttachmentIndex 0\n"
  1369. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1370. std::vector<std::string>{"InputAttachment"}),
  1371. std::make_pair(std::string(kGLSL450MemoryModel) +
  1372. "OpEntryPoint Vertex %func \"shader\" \n"
  1373. "OpDecorate %intt Alignment 4\n"
  1374. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1375. KernelDependencies())
  1376. )));
  1377. // clang-format on
  1378. INSTANTIATE_TEST_SUITE_P(
  1379. DecorationSpecId, ValidateCapability,
  1380. Combine(
  1381. ValuesIn(AllSpirV10Capabilities()),
  1382. Values(std::make_pair(std::string(kOpenCLMemoryModel) +
  1383. "OpEntryPoint Vertex %func \"shader\" \n" +
  1384. "OpDecorate %1 SpecId 1\n"
  1385. "%intt = OpTypeInt 32 0\n"
  1386. "%1 = OpSpecConstant %intt 0\n" +
  1387. std::string(kVoidFVoid),
  1388. ShaderDependencies()))));
  1389. INSTANTIATE_TEST_SUITE_P(
  1390. DecorationV11, ValidateCapabilityV11,
  1391. Combine(ValuesIn(AllCapabilities()),
  1392. Values(std::make_pair(std::string(kOpenCLMemoryModel) +
  1393. "OpEntryPoint Kernel %func \"compute\" \n"
  1394. "OpDecorate %p MaxByteOffset 0 "
  1395. "%i32 = OpTypeInt 32 0 "
  1396. "%pi32 = OpTypePointer Workgroup %i32 "
  1397. "%p = OpVariable %pi32 Workgroup " +
  1398. std::string(kVoidFVoid),
  1399. AddressesDependencies()),
  1400. // Trying to test OpDecorate here, but if this fails due to
  1401. // incorrect OpMemoryModel validation, that must also be
  1402. // fixed.
  1403. std::make_pair(
  1404. std::string("OpMemoryModel Logical OpenCL "
  1405. "OpEntryPoint Kernel %func \"compute\" \n"
  1406. "OpDecorate %1 SpecId 1 "
  1407. "%intt = OpTypeInt 32 0 "
  1408. "%1 = OpSpecConstant %intt 0") +
  1409. std::string(kVoidFVoid),
  1410. KernelDependencies()),
  1411. std::make_pair(
  1412. std::string("OpMemoryModel Logical Simple "
  1413. "OpEntryPoint Vertex %func \"shader\" \n"
  1414. "OpDecorate %1 SpecId 1 "
  1415. "%intt = OpTypeInt 32 0 "
  1416. "%1 = OpSpecConstant %intt 0") +
  1417. std::string(kVoidFVoid),
  1418. ShaderDependencies()))));
  1419. // clang-format off
  1420. INSTANTIATE_TEST_SUITE_P(BuiltIn, ValidateCapability,
  1421. Combine(
  1422. ValuesIn(AllCapabilities()),
  1423. Values(
  1424. std::make_pair(std::string(kOpenCLMemoryModel) +
  1425. "OpEntryPoint Kernel %func \"compute\" \n" +
  1426. "OpDecorate %int0 BuiltIn Position\n"
  1427. "%intt = OpTypeInt 32 0\n"
  1428. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1429. ShaderDependencies()),
  1430. // Just mentioning PointSize, ClipDistance, or CullDistance as a BuiltIn does
  1431. // not trigger the requirement for the associated capability.
  1432. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/365
  1433. std::make_pair(std::string(kOpenCLMemoryModel) +
  1434. "OpEntryPoint Kernel %func \"compute\" \n" +
  1435. "OpDecorate %int0 BuiltIn PointSize\n"
  1436. "%intt = OpTypeInt 32 0\n"
  1437. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1438. AllCapabilities()),
  1439. std::make_pair(std::string(kOpenCLMemoryModel) +
  1440. "OpEntryPoint Kernel %func \"compute\" \n" +
  1441. "OpDecorate %int0 BuiltIn ClipDistance\n"
  1442. "%intt = OpTypeInt 32 0\n"
  1443. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1444. AllCapabilities()),
  1445. std::make_pair(std::string(kOpenCLMemoryModel) +
  1446. "OpEntryPoint Kernel %func \"compute\" \n" +
  1447. "OpDecorate %int0 BuiltIn CullDistance\n"
  1448. "%intt = OpTypeInt 32 0\n"
  1449. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1450. AllCapabilities()),
  1451. std::make_pair(std::string(kOpenCLMemoryModel) +
  1452. "OpEntryPoint Kernel %func \"compute\" \n" +
  1453. "OpDecorate %int0 BuiltIn VertexId\n"
  1454. "%intt = OpTypeInt 32 0\n"
  1455. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1456. ShaderDependencies()),
  1457. std::make_pair(std::string(kOpenCLMemoryModel) +
  1458. "OpEntryPoint Kernel %func \"compute\" \n" +
  1459. "OpDecorate %int0 BuiltIn InstanceId\n"
  1460. "%intt = OpTypeInt 32 0\n"
  1461. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1462. ShaderDependencies()),
  1463. std::make_pair(std::string(kOpenCLMemoryModel) +
  1464. "OpEntryPoint Kernel %func \"compute\" \n" +
  1465. "OpDecorate %int0 BuiltIn PrimitiveId\n"
  1466. "%intt = OpTypeInt 32 0\n"
  1467. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1468. GeometryTessellationDependencies()),
  1469. std::make_pair(std::string(kOpenCLMemoryModel) +
  1470. "OpEntryPoint Kernel %func \"compute\" \n" +
  1471. "OpDecorate %int0 BuiltIn InvocationId\n"
  1472. "%intt = OpTypeInt 32 0\n"
  1473. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1474. GeometryTessellationDependencies()),
  1475. std::make_pair(std::string(kOpenCLMemoryModel) +
  1476. "OpEntryPoint Kernel %func \"compute\" \n" +
  1477. "OpDecorate %int0 BuiltIn Layer\n"
  1478. "%intt = OpTypeInt 32 0\n"
  1479. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1480. GeometryDependencies()),
  1481. std::make_pair(std::string(kOpenCLMemoryModel) +
  1482. "OpEntryPoint Kernel %func \"compute\" \n" +
  1483. "OpDecorate %int0 BuiltIn ViewportIndex\n"
  1484. "%intt = OpTypeInt 32 0\n"
  1485. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1486. std::vector<std::string>{"MultiViewport"}),
  1487. std::make_pair(std::string(kOpenCLMemoryModel) +
  1488. "OpEntryPoint Kernel %func \"compute\" \n" +
  1489. "OpDecorate %int0 BuiltIn TessLevelOuter\n"
  1490. "%intt = OpTypeInt 32 0\n"
  1491. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1492. TessellationDependencies()),
  1493. std::make_pair(std::string(kOpenCLMemoryModel) +
  1494. "OpEntryPoint Kernel %func \"compute\" \n" +
  1495. "OpDecorate %int0 BuiltIn TessLevelInner\n"
  1496. "%intt = OpTypeInt 32 0\n"
  1497. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1498. TessellationDependencies()),
  1499. std::make_pair(std::string(kOpenCLMemoryModel) +
  1500. "OpEntryPoint Kernel %func \"compute\" \n" +
  1501. "OpDecorate %int0 BuiltIn TessCoord\n"
  1502. "%intt = OpTypeInt 32 0\n"
  1503. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1504. TessellationDependencies()),
  1505. std::make_pair(std::string(kOpenCLMemoryModel) +
  1506. "OpEntryPoint Kernel %func \"compute\" \n" +
  1507. "OpDecorate %int0 BuiltIn PatchVertices\n"
  1508. "%intt = OpTypeInt 32 0\n"
  1509. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1510. TessellationDependencies()),
  1511. std::make_pair(std::string(kOpenCLMemoryModel) +
  1512. "OpEntryPoint Kernel %func \"compute\" \n" +
  1513. "OpDecorate %int0 BuiltIn FragCoord\n"
  1514. "%intt = OpTypeInt 32 0\n"
  1515. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1516. ShaderDependencies()),
  1517. std::make_pair(std::string(kOpenCLMemoryModel) +
  1518. "OpEntryPoint Kernel %func \"compute\" \n" +
  1519. "OpDecorate %int0 BuiltIn PointCoord\n"
  1520. "%intt = OpTypeInt 32 0\n"
  1521. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1522. ShaderDependencies()),
  1523. std::make_pair(std::string(kOpenCLMemoryModel) +
  1524. "OpEntryPoint Kernel %func \"compute\" \n" +
  1525. "OpDecorate %int0 BuiltIn FrontFacing\n"
  1526. "%intt = OpTypeInt 32 0\n"
  1527. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1528. ShaderDependencies()),
  1529. std::make_pair(std::string(kOpenCLMemoryModel) +
  1530. "OpEntryPoint Kernel %func \"compute\" \n" +
  1531. "OpDecorate %int0 BuiltIn SampleId\n"
  1532. "%intt = OpTypeInt 32 0\n"
  1533. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1534. std::vector<std::string>{"SampleRateShading"}),
  1535. std::make_pair(std::string(kOpenCLMemoryModel) +
  1536. "OpEntryPoint Kernel %func \"compute\" \n" +
  1537. "OpDecorate %int0 BuiltIn SamplePosition\n"
  1538. "%intt = OpTypeInt 32 0\n"
  1539. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1540. std::vector<std::string>{"SampleRateShading"}),
  1541. std::make_pair(std::string(kOpenCLMemoryModel) +
  1542. "OpEntryPoint Kernel %func \"compute\" \n" +
  1543. "OpDecorate %int0 BuiltIn SampleMask\n"
  1544. "%intt = OpTypeInt 32 0\n"
  1545. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1546. ShaderDependencies()),
  1547. std::make_pair(std::string(kOpenCLMemoryModel) +
  1548. "OpEntryPoint Kernel %func \"compute\" \n" +
  1549. "OpDecorate %int0 BuiltIn FragDepth\n"
  1550. "%intt = OpTypeInt 32 0\n"
  1551. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1552. ShaderDependencies()),
  1553. std::make_pair(std::string(kOpenCLMemoryModel) +
  1554. "OpEntryPoint Kernel %func \"compute\" \n" +
  1555. "OpDecorate %int0 BuiltIn HelperInvocation\n"
  1556. "%intt = OpTypeInt 32 0\n"
  1557. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1558. ShaderDependencies()),
  1559. std::make_pair(std::string(kOpenCLMemoryModel) +
  1560. "OpEntryPoint Kernel %func \"compute\" \n" +
  1561. "OpDecorate %int0 BuiltIn VertexIndex\n"
  1562. "%intt = OpTypeInt 32 0\n"
  1563. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1564. ShaderDependencies()),
  1565. std::make_pair(std::string(kOpenCLMemoryModel) +
  1566. "OpEntryPoint Kernel %func \"compute\" \n" +
  1567. "OpDecorate %int0 BuiltIn InstanceIndex\n"
  1568. "%intt = OpTypeInt 32 0\n"
  1569. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1570. ShaderDependencies()),
  1571. std::make_pair(std::string(kOpenCLMemoryModel) +
  1572. "OpEntryPoint Kernel %func \"compute\" \n" +
  1573. "OpDecorate %int0 BuiltIn NumWorkgroups\n"
  1574. "%intt = OpTypeInt 32 0\n"
  1575. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1576. AllCapabilities()),
  1577. std::make_pair(std::string(kOpenCLMemoryModel) +
  1578. "OpEntryPoint Kernel %func \"compute\" \n" +
  1579. "OpDecorate %int0 BuiltIn WorkgroupSize\n"
  1580. "%intt = OpTypeInt 32 0\n"
  1581. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1582. AllCapabilities()),
  1583. std::make_pair(std::string(kOpenCLMemoryModel) +
  1584. "OpEntryPoint Kernel %func \"compute\" \n" +
  1585. "OpDecorate %int0 BuiltIn WorkgroupId\n"
  1586. "%intt = OpTypeInt 32 0\n"
  1587. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1588. AllCapabilities()),
  1589. std::make_pair(std::string(kOpenCLMemoryModel) +
  1590. "OpEntryPoint Kernel %func \"compute\" \n" +
  1591. "OpDecorate %int0 BuiltIn LocalInvocationId\n"
  1592. "%intt = OpTypeInt 32 0\n"
  1593. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1594. AllCapabilities()),
  1595. std::make_pair(std::string(kOpenCLMemoryModel) +
  1596. "OpEntryPoint Kernel %func \"compute\" \n" +
  1597. "OpDecorate %int0 BuiltIn GlobalInvocationId\n"
  1598. "%intt = OpTypeInt 32 0\n"
  1599. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1600. AllCapabilities()),
  1601. std::make_pair(std::string(kOpenCLMemoryModel) +
  1602. "OpEntryPoint Kernel %func \"compute\" \n" +
  1603. "OpDecorate %int0 BuiltIn LocalInvocationIndex\n"
  1604. "%intt = OpTypeInt 32 0\n"
  1605. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1606. AllCapabilities()),
  1607. std::make_pair(std::string(kGLSL450MemoryModel) +
  1608. "OpEntryPoint Vertex %func \"shader\" \n" +
  1609. "OpDecorate %int0 BuiltIn WorkDim\n"
  1610. "%intt = OpTypeInt 32 0\n"
  1611. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1612. KernelDependencies()),
  1613. std::make_pair(std::string(kGLSL450MemoryModel) +
  1614. "OpEntryPoint Vertex %func \"shader\" \n" +
  1615. "OpDecorate %int0 BuiltIn GlobalSize\n"
  1616. "%intt = OpTypeInt 32 0\n"
  1617. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1618. KernelDependencies()),
  1619. std::make_pair(std::string(kGLSL450MemoryModel) +
  1620. "OpEntryPoint Vertex %func \"shader\" \n" +
  1621. "OpDecorate %int0 BuiltIn EnqueuedWorkgroupSize\n"
  1622. "%intt = OpTypeInt 32 0\n"
  1623. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1624. KernelDependencies()),
  1625. std::make_pair(std::string(kGLSL450MemoryModel) +
  1626. "OpEntryPoint Vertex %func \"shader\" \n" +
  1627. "OpDecorate %int0 BuiltIn GlobalOffset\n"
  1628. "%intt = OpTypeInt 32 0\n"
  1629. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1630. KernelDependencies()),
  1631. std::make_pair(std::string(kGLSL450MemoryModel) +
  1632. "OpEntryPoint Vertex %func \"shader\" \n" +
  1633. "OpDecorate %int0 BuiltIn GlobalLinearId\n"
  1634. "%intt = OpTypeInt 32 0\n"
  1635. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1636. KernelDependencies()),
  1637. std::make_pair(std::string(kGLSL450MemoryModel) +
  1638. "OpEntryPoint Vertex %func \"shader\" \n" +
  1639. "OpDecorate %int0 BuiltIn SubgroupSize\n"
  1640. "%intt = OpTypeInt 32 0\n"
  1641. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1642. KernelAndGroupNonUniformDependencies()),
  1643. std::make_pair(std::string(kGLSL450MemoryModel) +
  1644. "OpEntryPoint Vertex %func \"shader\" \n" +
  1645. "OpDecorate %int0 BuiltIn SubgroupMaxSize\n"
  1646. "%intt = OpTypeInt 32 0\n"
  1647. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1648. KernelDependencies()),
  1649. std::make_pair(std::string(kGLSL450MemoryModel) +
  1650. "OpEntryPoint Vertex %func \"shader\" \n" +
  1651. "OpDecorate %int0 BuiltIn NumSubgroups\n"
  1652. "%intt = OpTypeInt 32 0\n"
  1653. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1654. KernelAndGroupNonUniformDependencies()),
  1655. std::make_pair(std::string(kGLSL450MemoryModel) +
  1656. "OpEntryPoint Vertex %func \"shader\" \n" +
  1657. "OpDecorate %int0 BuiltIn NumEnqueuedSubgroups\n"
  1658. "%intt = OpTypeInt 32 0\n"
  1659. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1660. KernelDependencies()),
  1661. std::make_pair(std::string(kGLSL450MemoryModel) +
  1662. "OpEntryPoint Vertex %func \"shader\" \n" +
  1663. "OpDecorate %int0 BuiltIn SubgroupId\n"
  1664. "%intt = OpTypeInt 32 0\n"
  1665. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1666. KernelAndGroupNonUniformDependencies()),
  1667. std::make_pair(std::string(kGLSL450MemoryModel) +
  1668. "OpEntryPoint Vertex %func \"shader\" \n" +
  1669. "OpDecorate %int0 BuiltIn SubgroupLocalInvocationId\n"
  1670. "%intt = OpTypeInt 32 0\n"
  1671. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1672. KernelAndGroupNonUniformDependencies()),
  1673. std::make_pair(std::string(kOpenCLMemoryModel) +
  1674. "OpEntryPoint Kernel %func \"compute\" \n" +
  1675. "OpDecorate %int0 BuiltIn VertexIndex\n"
  1676. "%intt = OpTypeInt 32 0\n"
  1677. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1678. ShaderDependencies()),
  1679. std::make_pair(std::string(kOpenCLMemoryModel) +
  1680. "OpEntryPoint Kernel %func \"compute\" \n" +
  1681. "OpDecorate %int0 BuiltIn InstanceIndex\n"
  1682. "%intt = OpTypeInt 32 0\n"
  1683. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1684. ShaderDependencies())
  1685. )));
  1686. // Ensure that mere mention of PointSize, ClipDistance, or CullDistance as
  1687. // BuiltIns does not trigger the requirement for the associated
  1688. // capability.
  1689. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/365
  1690. INSTANTIATE_TEST_SUITE_P(BuiltIn, ValidateCapabilityVulkan10,
  1691. Combine(
  1692. // All capabilities to try.
  1693. ValuesIn(AllSpirV10Capabilities()),
  1694. Values(
  1695. std::make_pair(std::string(kGLSL450MemoryModel) +
  1696. "OpEntryPoint Vertex %func \"shader\" \n"
  1697. "OpMemberDecorate %block 0 BuiltIn PointSize\n"
  1698. "%f32 = OpTypeFloat 32\n"
  1699. "%block = OpTypeStruct %f32\n"
  1700. "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
  1701. // Capabilities which should succeed.
  1702. AllVulkan10Capabilities()),
  1703. std::make_pair(std::string(kGLSL450MemoryModel) +
  1704. "OpEntryPoint Vertex %func \"shader\" \n"
  1705. "OpMemberDecorate %block 0 BuiltIn ClipDistance\n"
  1706. "%f32 = OpTypeFloat 32\n"
  1707. "%intt = OpTypeInt 32 0\n"
  1708. "%intt_4 = OpConstant %intt 4\n"
  1709. "%f32arr4 = OpTypeArray %f32 %intt_4\n"
  1710. "%block = OpTypeStruct %f32arr4\n" + std::string(kVoidFVoid),
  1711. AllVulkan10Capabilities()),
  1712. std::make_pair(std::string(kGLSL450MemoryModel) +
  1713. "OpEntryPoint Vertex %func \"shader\" \n"
  1714. "OpMemberDecorate %block 0 BuiltIn CullDistance\n"
  1715. "%f32 = OpTypeFloat 32\n"
  1716. "%intt = OpTypeInt 32 0\n"
  1717. "%intt_4 = OpConstant %intt 4\n"
  1718. "%f32arr4 = OpTypeArray %f32 %intt_4\n"
  1719. "%block = OpTypeStruct %f32arr4\n" + std::string(kVoidFVoid),
  1720. AllVulkan10Capabilities())
  1721. )));
  1722. INSTANTIATE_TEST_SUITE_P(BuiltIn, ValidateCapabilityOpenGL40,
  1723. Combine(
  1724. // OpenGL 4.0 is based on SPIR-V 1.0
  1725. ValuesIn(AllSpirV10Capabilities()),
  1726. Values(
  1727. std::make_pair(std::string(kGLSL450MemoryModel) +
  1728. "OpEntryPoint Vertex %func \"shader\" \n" +
  1729. "OpDecorate %int0 BuiltIn PointSize\n"
  1730. "%intt = OpTypeInt 32 0\n"
  1731. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1732. AllSpirV10Capabilities()),
  1733. std::make_pair(std::string(kGLSL450MemoryModel) +
  1734. "OpEntryPoint Vertex %func \"shader\" \n" +
  1735. "OpDecorate %int0 BuiltIn ClipDistance\n"
  1736. "%intt = OpTypeInt 32 0\n"
  1737. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1738. AllSpirV10Capabilities()),
  1739. std::make_pair(std::string(kGLSL450MemoryModel) +
  1740. "OpEntryPoint Vertex %func \"shader\" \n" +
  1741. "OpDecorate %int0 BuiltIn CullDistance\n"
  1742. "%intt = OpTypeInt 32 0\n"
  1743. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1744. AllSpirV10Capabilities())
  1745. )));
  1746. INSTANTIATE_TEST_SUITE_P(Capabilities, ValidateCapabilityVulkan11,
  1747. Combine(
  1748. // All capabilities to try.
  1749. ValuesIn(AllCapabilities()),
  1750. Values(
  1751. std::make_pair(std::string(kGLSL450MemoryModel) +
  1752. "OpEntryPoint Vertex %func \"shader\" \n" +
  1753. "OpDecorate %int0 BuiltIn PointSize\n"
  1754. "%intt = OpTypeInt 32 0\n"
  1755. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1756. AllVulkan11Capabilities()),
  1757. std::make_pair(std::string(kGLSL450MemoryModel) +
  1758. "OpEntryPoint Vertex %func \"shader\" \n" +
  1759. "OpDecorate %int0 BuiltIn CullDistance\n"
  1760. "%intt = OpTypeInt 32 0\n"
  1761. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1762. AllVulkan11Capabilities())
  1763. )));
  1764. INSTANTIATE_TEST_SUITE_P(Capabilities, ValidateCapabilityVulkan12,
  1765. Combine(
  1766. // All capabilities to try.
  1767. ValuesIn(AllSpirV15Capabilities()),
  1768. Values(
  1769. std::make_pair(std::string(kGLSL450MemoryModel) +
  1770. "OpEntryPoint Vertex %func \"shader\" \n" +
  1771. "OpDecorate %int0 BuiltIn PointSize\n"
  1772. "%intt = OpTypeInt 32 0\n"
  1773. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1774. AllVulkan12Capabilities()),
  1775. std::make_pair(std::string(kGLSL450MemoryModel) +
  1776. "OpEntryPoint Vertex %func \"shader\" \n" +
  1777. "OpDecorate %int0 BuiltIn CullDistance\n"
  1778. "%intt = OpTypeInt 32 0\n"
  1779. "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
  1780. AllVulkan12Capabilities())
  1781. )));
  1782. // TODO(umar): Selection Control
  1783. // TODO(umar): Loop Control
  1784. // TODO(umar): Function Control
  1785. // TODO(umar): Memory Semantics
  1786. // TODO(umar): Memory Access
  1787. // TODO(umar): Scope
  1788. // TODO(umar): Group Operation
  1789. // TODO(umar): Kernel Enqueue Flags
  1790. // TODO(umar): Kernel Profiling Flags
  1791. INSTANTIATE_TEST_SUITE_P(MatrixOp, ValidateCapability,
  1792. Combine(
  1793. ValuesIn(AllCapabilities()),
  1794. Values(
  1795. std::make_pair(std::string(kOpenCLMemoryModel) +
  1796. "OpEntryPoint Kernel %func \"compute\" \n" +
  1797. "%f32 = OpTypeFloat 32\n"
  1798. "%vec3 = OpTypeVector %f32 3\n"
  1799. "%mat33 = OpTypeMatrix %vec3 3\n" + std::string(kVoidFVoid),
  1800. MatrixDependencies()))));
  1801. // clang-format on
  1802. #if 0
  1803. // TODO([email protected]) The following test is not valid as it generates
  1804. // invalid combinations of images, instructions and image operands.
  1805. //
  1806. // Creates assembly containing an OpImageFetch instruction using operands for
  1807. // the image-operands part. The assembly defines constants %fzero and %izero
  1808. // that can be used for operands where IDs are required. The assembly is valid,
  1809. // apart from not declaring any capabilities required by the operands.
  1810. string ImageOperandsTemplate(const std::string& operands) {
  1811. ostringstream ss;
  1812. // clang-format off
  1813. ss << R"(
  1814. OpCapability Kernel
  1815. OpCapability Linkage
  1816. OpMemoryModel Logical OpenCL
  1817. %i32 = OpTypeInt 32 0
  1818. %f32 = OpTypeFloat 32
  1819. %v4i32 = OpTypeVector %i32 4
  1820. %timg = OpTypeImage %i32 2D 0 0 0 0 Unknown
  1821. %pimg = OpTypePointer UniformConstant %timg
  1822. %tfun = OpTypeFunction %i32
  1823. %vimg = OpVariable %pimg UniformConstant
  1824. %izero = OpConstant %i32 0
  1825. %fzero = OpConstant %f32 0.
  1826. %main = OpFunction %i32 None %tfun
  1827. %lbl = OpLabel
  1828. %img = OpLoad %timg %vimg
  1829. %r1 = OpImageFetch %v4i32 %img %izero )" << operands << R"(
  1830. OpReturnValue %izero
  1831. OpFunctionEnd
  1832. )";
  1833. // clang-format on
  1834. return ss.str();
  1835. }
  1836. INSTANTIATE_TEST_SUITE_P(
  1837. TwoImageOperandsMask, ValidateCapability,
  1838. Combine(
  1839. ValuesIn(AllCapabilities()),
  1840. Values(std::make_pair(ImageOperandsTemplate("Bias|Lod %fzero %fzero"),
  1841. ShaderDependencies()),
  1842. std::make_pair(ImageOperandsTemplate("Lod|Offset %fzero %izero"),
  1843. std::vector<std::string>{"ImageGatherExtended"}),
  1844. std::make_pair(ImageOperandsTemplate("Sample|MinLod %izero %fzero"),
  1845. std::vector<std::string>{"MinLod"}),
  1846. std::make_pair(ImageOperandsTemplate("Lod|Sample %fzero %izero"),
  1847. AllCapabilities()))), );
  1848. #endif
  1849. // TODO(umar): Instruction capability checks
  1850. spv_result_t spvCoreOperandTableNameLookup(spv_target_env env,
  1851. const spv_operand_table table,
  1852. const spv_operand_type_t type,
  1853. const char* name,
  1854. const size_t nameLength) {
  1855. if (!table) return SPV_ERROR_INVALID_TABLE;
  1856. if (!name) return SPV_ERROR_INVALID_POINTER;
  1857. for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) {
  1858. const auto& group = table->types[typeIndex];
  1859. if (type != group.type) continue;
  1860. for (uint64_t index = 0; index < group.count; ++index) {
  1861. const auto& entry = group.entries[index];
  1862. // Check for min version only.
  1863. if (spvVersionForTargetEnv(env) >= entry.minVersion &&
  1864. nameLength == strlen(entry.name) &&
  1865. !strncmp(entry.name, name, nameLength)) {
  1866. return SPV_SUCCESS;
  1867. }
  1868. }
  1869. }
  1870. return SPV_ERROR_INVALID_LOOKUP;
  1871. }
  1872. // True if capability exists in core spec of env.
  1873. bool Exists(const std::string& capability, spv_target_env env) {
  1874. ScopedContext sc(env);
  1875. return SPV_SUCCESS ==
  1876. spvCoreOperandTableNameLookup(env, sc.context->operand_table,
  1877. SPV_OPERAND_TYPE_CAPABILITY,
  1878. capability.c_str(), capability.size());
  1879. }
  1880. TEST_P(ValidateCapability, Capability) {
  1881. const std::string capability = Capability(GetParam());
  1882. spv_target_env env = SPV_ENV_UNIVERSAL_1_0;
  1883. if (!capability.empty()) {
  1884. if (Exists(capability, SPV_ENV_UNIVERSAL_1_0))
  1885. env = SPV_ENV_UNIVERSAL_1_0;
  1886. else if (Exists(capability, SPV_ENV_UNIVERSAL_1_1))
  1887. env = SPV_ENV_UNIVERSAL_1_1;
  1888. else if (Exists(capability, SPV_ENV_UNIVERSAL_1_2))
  1889. env = SPV_ENV_UNIVERSAL_1_2;
  1890. else
  1891. env = SPV_ENV_UNIVERSAL_1_3;
  1892. }
  1893. const std::string test_code = MakeAssembly(GetParam());
  1894. CompileSuccessfully(test_code, env);
  1895. ASSERT_EQ(ExpectedResult(GetParam()), ValidateInstructions(env))
  1896. << "target env: " << spvTargetEnvDescription(env) << "\ntest code:\n"
  1897. << test_code;
  1898. }
  1899. TEST_P(ValidateCapabilityV11, Capability) {
  1900. const std::string capability = Capability(GetParam());
  1901. if (Exists(capability, SPV_ENV_UNIVERSAL_1_1)) {
  1902. const std::string test_code = MakeAssembly(GetParam());
  1903. CompileSuccessfully(test_code, SPV_ENV_UNIVERSAL_1_1);
  1904. ASSERT_EQ(ExpectedResult(GetParam()),
  1905. ValidateInstructions(SPV_ENV_UNIVERSAL_1_1))
  1906. << test_code;
  1907. }
  1908. }
  1909. TEST_P(ValidateCapabilityVulkan10, Capability) {
  1910. const std::string capability = Capability(GetParam());
  1911. if (Exists(capability, SPV_ENV_VULKAN_1_0)) {
  1912. const std::string test_code = MakeAssembly(GetParam());
  1913. CompileSuccessfully(test_code, SPV_ENV_VULKAN_1_0);
  1914. ASSERT_EQ(ExpectedResult(GetParam()),
  1915. ValidateInstructions(SPV_ENV_VULKAN_1_0))
  1916. << test_code;
  1917. }
  1918. }
  1919. TEST_P(ValidateCapabilityVulkan11, Capability) {
  1920. const std::string capability = Capability(GetParam());
  1921. if (Exists(capability, SPV_ENV_VULKAN_1_1)) {
  1922. const std::string test_code = MakeAssembly(GetParam());
  1923. CompileSuccessfully(test_code, SPV_ENV_VULKAN_1_1);
  1924. ASSERT_EQ(ExpectedResult(GetParam()),
  1925. ValidateInstructions(SPV_ENV_VULKAN_1_1))
  1926. << test_code;
  1927. }
  1928. }
  1929. TEST_P(ValidateCapabilityVulkan12, Capability) {
  1930. const std::string capability = Capability(GetParam());
  1931. if (Exists(capability, SPV_ENV_VULKAN_1_2)) {
  1932. const std::string test_code = MakeAssembly(GetParam());
  1933. CompileSuccessfully(test_code, SPV_ENV_VULKAN_1_2);
  1934. ASSERT_EQ(ExpectedResult(GetParam()),
  1935. ValidateInstructions(SPV_ENV_VULKAN_1_2))
  1936. << test_code;
  1937. }
  1938. }
  1939. TEST_P(ValidateCapabilityOpenGL40, Capability) {
  1940. const std::string capability = Capability(GetParam());
  1941. if (Exists(capability, SPV_ENV_OPENGL_4_0)) {
  1942. const std::string test_code = MakeAssembly(GetParam());
  1943. CompileSuccessfully(test_code, SPV_ENV_OPENGL_4_0);
  1944. ASSERT_EQ(ExpectedResult(GetParam()),
  1945. ValidateInstructions(SPV_ENV_OPENGL_4_0))
  1946. << test_code;
  1947. }
  1948. }
  1949. TEST_F(ValidateCapability, SemanticsIdIsAnIdNotALiteral) {
  1950. // From https://github.com/KhronosGroup/SPIRV-Tools/issues/248
  1951. // The validator was interpreting the memory semantics ID number
  1952. // as the value to be checked rather than an ID that references
  1953. // another value to be checked.
  1954. // In this case a raw ID of 64 was mistaken to mean a literal
  1955. // semantic value of UniformMemory, which would require the Shader
  1956. // capability.
  1957. const char str[] = R"(
  1958. OpCapability Kernel
  1959. OpCapability Linkage
  1960. OpMemoryModel Logical OpenCL
  1961. ; %i32 has ID 1
  1962. %i32 = OpTypeInt 32 0
  1963. %tf = OpTypeFunction %i32
  1964. %pi32 = OpTypePointer CrossWorkgroup %i32
  1965. %var = OpVariable %pi32 CrossWorkgroup
  1966. %c = OpConstant %i32 100
  1967. %scope = OpConstant %i32 1 ; Device scope
  1968. ; Fake an instruction with 64 as the result id.
  1969. ; !64 = OpConstantNull %i32
  1970. !0x3002e !1 !64
  1971. %f = OpFunction %i32 None %tf
  1972. %l = OpLabel
  1973. %result = OpAtomicIAdd %i32 %var %scope !64 %c
  1974. OpReturnValue %result
  1975. OpFunctionEnd
  1976. )";
  1977. CompileSuccessfully(str);
  1978. // Since we are forcing usage of <id> 64, the "id bound" in the binary header
  1979. // must be overwritten so that <id> 64 is considered within bound.
  1980. // ID Bound is at index 3 of the binary. Set it to 65.
  1981. OverwriteAssembledBinary(3, 65);
  1982. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1983. }
  1984. TEST_F(ValidateCapability, IntSignednessKernelGood) {
  1985. const std::string spirv = R"(
  1986. OpCapability Kernel
  1987. OpCapability Linkage
  1988. OpMemoryModel Logical OpenCL
  1989. %i32 = OpTypeInt 32 0
  1990. )";
  1991. CompileSuccessfully(spirv);
  1992. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  1993. }
  1994. TEST_F(ValidateCapability, IntSignednessKernelBad) {
  1995. const std::string spirv = R"(
  1996. OpCapability Kernel
  1997. OpCapability Linkage
  1998. OpMemoryModel Logical OpenCL
  1999. %i32 = OpTypeInt 32 1
  2000. )";
  2001. CompileSuccessfully(spirv);
  2002. EXPECT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions());
  2003. EXPECT_THAT(getDiagnosticString(),
  2004. HasSubstr("The Signedness in OpTypeInt must always be 0 when "
  2005. "Kernel capability is used."));
  2006. }
  2007. TEST_F(ValidateCapability, IntSignednessShaderGood) {
  2008. const std::string spirv = R"(
  2009. OpCapability Shader
  2010. OpCapability Linkage
  2011. OpMemoryModel Logical GLSL450
  2012. %u32 = OpTypeInt 32 0
  2013. %i32 = OpTypeInt 32 1
  2014. )";
  2015. CompileSuccessfully(spirv);
  2016. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  2017. }
  2018. TEST_F(ValidateCapability, NonVulkan10Capability) {
  2019. const std::string spirv = R"(
  2020. OpCapability Shader
  2021. OpCapability Linkage
  2022. OpMemoryModel Logical GLSL450
  2023. %u32 = OpTypeInt 32 0
  2024. %i32 = OpTypeInt 32 1
  2025. )";
  2026. CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
  2027. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2028. ValidateInstructions(SPV_ENV_VULKAN_1_0));
  2029. EXPECT_THAT(getDiagnosticString(),
  2030. HasSubstr("Capability Linkage is not allowed by Vulkan 1.0"));
  2031. }
  2032. TEST_F(ValidateCapability, Vulkan10EnabledByExtension) {
  2033. const std::string spirv = R"(
  2034. OpCapability Shader
  2035. OpCapability DrawParameters
  2036. OpExtension "SPV_KHR_shader_draw_parameters"
  2037. OpMemoryModel Logical GLSL450
  2038. OpEntryPoint Vertex %func "shader"
  2039. OpMemberDecorate %block 0 BuiltIn PointSize
  2040. %f32 = OpTypeFloat 32
  2041. %block = OpTypeStruct %f32
  2042. )" + std::string(kVoidFVoid);
  2043. CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
  2044. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
  2045. }
  2046. TEST_F(ValidateCapability, Vulkan10NotEnabledByExtension) {
  2047. const std::string spirv = R"(
  2048. OpCapability Shader
  2049. OpCapability DrawParameters
  2050. OpMemoryModel Logical GLSL450
  2051. OpEntryPoint Vertex %func "shader"
  2052. OpDecorate %intt BuiltIn PointSize
  2053. %intt = OpTypeInt 32 0
  2054. )" + std::string(kVoidFVoid);
  2055. CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
  2056. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2057. ValidateInstructions(SPV_ENV_VULKAN_1_0));
  2058. EXPECT_THAT(
  2059. getDiagnosticString(),
  2060. HasSubstr("Capability DrawParameters is not allowed by Vulkan 1.0"));
  2061. }
  2062. TEST_F(ValidateCapability, NonOpenCL12FullCapability) {
  2063. const std::string spirv = R"(
  2064. OpCapability Kernel
  2065. OpCapability Addresses
  2066. OpCapability Linkage
  2067. OpCapability Pipes
  2068. OpMemoryModel Physical64 OpenCL
  2069. %u32 = OpTypeInt 32 0
  2070. )";
  2071. CompileSuccessfully(spirv, SPV_ENV_OPENCL_1_2);
  2072. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2073. ValidateInstructions(SPV_ENV_OPENCL_1_2));
  2074. EXPECT_THAT(
  2075. getDiagnosticString(),
  2076. HasSubstr("Capability Pipes is not allowed by OpenCL 1.2 Full Profile"));
  2077. }
  2078. TEST_F(ValidateCapability, OpenCL12FullEnabledByCapability) {
  2079. const std::string spirv = R"(
  2080. OpCapability Kernel
  2081. OpCapability Addresses
  2082. OpCapability Linkage
  2083. OpCapability ImageBasic
  2084. OpCapability Sampled1D
  2085. OpMemoryModel Physical64 OpenCL
  2086. %u32 = OpTypeInt 32 0
  2087. )" + std::string(kVoidFVoid);
  2088. CompileSuccessfully(spirv, SPV_ENV_OPENCL_1_2);
  2089. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_1_2));
  2090. }
  2091. TEST_F(ValidateCapability, OpenCL12FullNotEnabledByCapability) {
  2092. const std::string spirv = R"(
  2093. OpCapability Kernel
  2094. OpCapability Addresses
  2095. OpCapability Linkage
  2096. OpCapability Sampled1D
  2097. OpMemoryModel Physical64 OpenCL
  2098. %u32 = OpTypeInt 32 0
  2099. )" + std::string(kVoidFVoid);
  2100. CompileSuccessfully(spirv, SPV_ENV_OPENCL_1_2);
  2101. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2102. ValidateInstructions(SPV_ENV_OPENCL_1_2));
  2103. EXPECT_THAT(
  2104. getDiagnosticString(),
  2105. HasSubstr(
  2106. "Capability Sampled1D is not allowed by OpenCL 1.2 Full Profile"));
  2107. }
  2108. TEST_F(ValidateCapability, NonOpenCL12EmbeddedCapability) {
  2109. const std::string spirv = R"(
  2110. OpCapability Kernel
  2111. OpCapability Addresses
  2112. OpCapability Linkage
  2113. OpCapability Int64
  2114. OpMemoryModel Physical64 OpenCL
  2115. %u32 = OpTypeInt 32 0
  2116. )";
  2117. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
  2118. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2119. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
  2120. EXPECT_THAT(
  2121. getDiagnosticString(),
  2122. HasSubstr(
  2123. "Capability Int64 is not allowed by OpenCL 1.2 Embedded Profile"));
  2124. }
  2125. TEST_F(ValidateCapability, OpenCL12EmbeddedEnabledByCapability) {
  2126. const std::string spirv = R"(
  2127. OpCapability Kernel
  2128. OpCapability Addresses
  2129. OpCapability Linkage
  2130. OpCapability ImageBasic
  2131. OpCapability Sampled1D
  2132. OpMemoryModel Physical64 OpenCL
  2133. %u32 = OpTypeInt 32 0
  2134. )" + std::string(kVoidFVoid);
  2135. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
  2136. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
  2137. }
  2138. TEST_F(ValidateCapability, OpenCL12EmbeddedNotEnabledByCapability) {
  2139. const std::string spirv = R"(
  2140. OpCapability Kernel
  2141. OpCapability Addresses
  2142. OpCapability Linkage
  2143. OpCapability Sampled1D
  2144. OpMemoryModel Physical64 OpenCL
  2145. %u32 = OpTypeInt 32 0
  2146. )" + std::string(kVoidFVoid);
  2147. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
  2148. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2149. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
  2150. EXPECT_THAT(getDiagnosticString(),
  2151. HasSubstr("Capability Sampled1D is not allowed by OpenCL 1.2 "
  2152. "Embedded Profile"));
  2153. }
  2154. TEST_F(ValidateCapability, OpenCL12EmbeddedNoLongerEnabledByCapability) {
  2155. const std::string spirv = R"(
  2156. OpCapability Kernel
  2157. OpCapability Addresses
  2158. OpCapability Linkage
  2159. OpCapability Pipes
  2160. OpMemoryModel Physical64 OpenCL
  2161. %u32 = OpTypeInt 32 0
  2162. )" + std::string(kVoidFVoid);
  2163. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
  2164. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2165. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
  2166. EXPECT_THAT(getDiagnosticString(),
  2167. HasSubstr("Capability Pipes is not allowed by OpenCL 1.2 "
  2168. "Embedded Profile"));
  2169. }
  2170. TEST_F(ValidateCapability, OpenCL20FullCapability) {
  2171. const std::string spirv = R"(
  2172. OpCapability Kernel
  2173. OpCapability Addresses
  2174. OpCapability Linkage
  2175. OpCapability Groups
  2176. OpCapability Pipes
  2177. OpMemoryModel Physical64 OpenCL
  2178. %u32 = OpTypeInt 32 0
  2179. )";
  2180. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
  2181. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_0));
  2182. }
  2183. TEST_F(ValidateCapability, NonOpenCL20FullCapability) {
  2184. const std::string spirv = R"(
  2185. OpCapability Kernel
  2186. OpCapability Addresses
  2187. OpCapability Linkage
  2188. OpCapability Matrix
  2189. OpMemoryModel Physical64 OpenCL
  2190. %u32 = OpTypeInt 32 0
  2191. )";
  2192. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
  2193. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2194. ValidateInstructions(SPV_ENV_OPENCL_2_0));
  2195. EXPECT_THAT(
  2196. getDiagnosticString(),
  2197. HasSubstr(
  2198. "Capability Matrix is not allowed by OpenCL 2.0/2.1 Full Profile"));
  2199. }
  2200. TEST_F(ValidateCapability, OpenCL20FullEnabledByCapability) {
  2201. const std::string spirv = R"(
  2202. OpCapability Kernel
  2203. OpCapability Addresses
  2204. OpCapability Linkage
  2205. OpCapability ImageBasic
  2206. OpCapability Sampled1D
  2207. OpMemoryModel Physical64 OpenCL
  2208. %u32 = OpTypeInt 32 0
  2209. )" + std::string(kVoidFVoid);
  2210. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
  2211. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_0));
  2212. }
  2213. TEST_F(ValidateCapability, OpenCL20FullNotEnabledByCapability) {
  2214. const std::string spirv = R"(
  2215. OpCapability Kernel
  2216. OpCapability Addresses
  2217. OpCapability Linkage
  2218. OpCapability Sampled1D
  2219. OpMemoryModel Physical64 OpenCL
  2220. %u32 = OpTypeInt 32 0
  2221. )" + std::string(kVoidFVoid);
  2222. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
  2223. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2224. ValidateInstructions(SPV_ENV_OPENCL_2_0));
  2225. EXPECT_THAT(getDiagnosticString(),
  2226. HasSubstr("Capability Sampled1D is not allowed by OpenCL 2.0/2.1 "
  2227. "Full Profile"));
  2228. }
  2229. TEST_F(ValidateCapability, NonOpenCL20EmbeddedCapability) {
  2230. const std::string spirv = R"(
  2231. OpCapability Kernel
  2232. OpCapability Addresses
  2233. OpCapability Linkage
  2234. OpCapability Int64
  2235. OpMemoryModel Physical64 OpenCL
  2236. %u32 = OpTypeInt 32 0
  2237. )";
  2238. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_0);
  2239. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2240. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_0));
  2241. EXPECT_THAT(getDiagnosticString(),
  2242. HasSubstr("Capability Int64 is not allowed by OpenCL 2.0/2.1 "
  2243. "Embedded Profile"));
  2244. }
  2245. TEST_F(ValidateCapability, OpenCL20EmbeddedEnabledByCapability) {
  2246. const std::string spirv = R"(
  2247. OpCapability Kernel
  2248. OpCapability Addresses
  2249. OpCapability Linkage
  2250. OpCapability ImageBasic
  2251. OpCapability Sampled1D
  2252. OpMemoryModel Physical64 OpenCL
  2253. %u32 = OpTypeInt 32 0
  2254. )" + std::string(kVoidFVoid);
  2255. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_0);
  2256. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_0));
  2257. }
  2258. TEST_F(ValidateCapability, OpenCL20EmbeddedNotEnabledByCapability) {
  2259. const std::string spirv = R"(
  2260. OpCapability Kernel
  2261. OpCapability Addresses
  2262. OpCapability Linkage
  2263. OpCapability Sampled1D
  2264. OpMemoryModel Physical64 OpenCL
  2265. %u32 = OpTypeInt 32 0
  2266. )" + std::string(kVoidFVoid);
  2267. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_0);
  2268. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2269. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_0));
  2270. EXPECT_THAT(getDiagnosticString(),
  2271. HasSubstr("Capability Sampled1D is not allowed by OpenCL 2.0/2.1 "
  2272. "Embedded Profile"));
  2273. }
  2274. TEST_F(ValidateCapability, OpenCL22FullCapability) {
  2275. const std::string spirv = R"(
  2276. OpCapability Kernel
  2277. OpCapability Addresses
  2278. OpCapability Linkage
  2279. OpCapability PipeStorage
  2280. OpMemoryModel Physical64 OpenCL
  2281. %u32 = OpTypeInt 32 0
  2282. )";
  2283. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
  2284. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_2));
  2285. }
  2286. TEST_F(ValidateCapability, NonOpenCL22FullCapability) {
  2287. const std::string spirv = R"(
  2288. OpCapability Kernel
  2289. OpCapability Addresses
  2290. OpCapability Linkage
  2291. OpCapability Matrix
  2292. OpMemoryModel Physical64 OpenCL
  2293. %u32 = OpTypeInt 32 0
  2294. )";
  2295. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
  2296. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2297. ValidateInstructions(SPV_ENV_OPENCL_2_2));
  2298. EXPECT_THAT(
  2299. getDiagnosticString(),
  2300. HasSubstr("Capability Matrix is not allowed by OpenCL 2.2 Full Profile"));
  2301. }
  2302. TEST_F(ValidateCapability, OpenCL22FullEnabledByCapability) {
  2303. const std::string spirv = R"(
  2304. OpCapability Kernel
  2305. OpCapability Addresses
  2306. OpCapability Linkage
  2307. OpCapability ImageBasic
  2308. OpCapability Sampled1D
  2309. OpMemoryModel Physical64 OpenCL
  2310. %u32 = OpTypeInt 32 0
  2311. )" + std::string(kVoidFVoid);
  2312. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
  2313. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_2));
  2314. }
  2315. TEST_F(ValidateCapability, OpenCL22FullNotEnabledByCapability) {
  2316. const std::string spirv = R"(
  2317. OpCapability Kernel
  2318. OpCapability Addresses
  2319. OpCapability Linkage
  2320. OpCapability Sampled1D
  2321. OpMemoryModel Physical64 OpenCL
  2322. %u32 = OpTypeInt 32 0
  2323. )" + std::string(kVoidFVoid);
  2324. CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
  2325. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2326. ValidateInstructions(SPV_ENV_OPENCL_2_2));
  2327. EXPECT_THAT(
  2328. getDiagnosticString(),
  2329. HasSubstr(
  2330. "Capability Sampled1D is not allowed by OpenCL 2.2 Full Profile"));
  2331. }
  2332. TEST_F(ValidateCapability, NonOpenCL22EmbeddedCapability) {
  2333. const std::string spirv = R"(
  2334. OpCapability Kernel
  2335. OpCapability Addresses
  2336. OpCapability Linkage
  2337. OpCapability Int64
  2338. OpMemoryModel Physical64 OpenCL
  2339. %u32 = OpTypeInt 32 0
  2340. )";
  2341. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_2);
  2342. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2343. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_2));
  2344. EXPECT_THAT(
  2345. getDiagnosticString(),
  2346. HasSubstr(
  2347. "Capability Int64 is not allowed by OpenCL 2.2 Embedded Profile"));
  2348. }
  2349. TEST_F(ValidateCapability, OpenCL22EmbeddedEnabledByCapability) {
  2350. const std::string spirv = R"(
  2351. OpCapability Kernel
  2352. OpCapability Addresses
  2353. OpCapability Linkage
  2354. OpCapability ImageBasic
  2355. OpCapability Sampled1D
  2356. OpMemoryModel Physical64 OpenCL
  2357. %u32 = OpTypeInt 32 0
  2358. )" + std::string(kVoidFVoid);
  2359. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_2);
  2360. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_2));
  2361. }
  2362. TEST_F(ValidateCapability, OpenCL22EmbeddedNotEnabledByCapability) {
  2363. const std::string spirv = R"(
  2364. OpCapability Kernel
  2365. OpCapability Addresses
  2366. OpCapability Linkage
  2367. OpCapability Sampled1D
  2368. OpMemoryModel Physical64 OpenCL
  2369. %u32 = OpTypeInt 32 0
  2370. )" + std::string(kVoidFVoid);
  2371. CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_2);
  2372. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2373. ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_2));
  2374. EXPECT_THAT(getDiagnosticString(),
  2375. HasSubstr("Capability Sampled1D is not allowed by OpenCL 2.2 "
  2376. "Embedded Profile"));
  2377. }
  2378. // Three tests to check enablement of an enum (a decoration) which is not
  2379. // in core, and is directly enabled by a capability, but not directly enabled
  2380. // by an extension. See https://github.com/KhronosGroup/SPIRV-Tools/issues/1596
  2381. TEST_F(ValidateCapability, DecorationFromExtensionMissingEnabledByCapability) {
  2382. // Decoration ViewportRelativeNV is enabled by ShaderViewportMaskNV, which in
  2383. // turn is enabled by SPV_NV_viewport_array2.
  2384. const std::string spirv = R"(
  2385. OpCapability Shader
  2386. OpMemoryModel Logical Simple
  2387. OpDecorate %void ViewportRelativeNV
  2388. )" + std::string(kVoidFVoid);
  2389. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2390. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2391. ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
  2392. EXPECT_THAT(getDiagnosticString(),
  2393. HasSubstr("Operand 2 of Decorate requires one of these "
  2394. "capabilities: ShaderViewportMaskNV"));
  2395. }
  2396. TEST_F(ValidateCapability, CapabilityEnabledByMissingExtension) {
  2397. // Capability ShaderViewportMaskNV is enabled by SPV_NV_viewport_array2.
  2398. const std::string spirv = R"(
  2399. OpCapability Shader
  2400. OpCapability ShaderViewportMaskNV
  2401. OpMemoryModel Logical Simple
  2402. )" + std::string(kVoidFVoid);
  2403. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2404. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2405. ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
  2406. EXPECT_THAT(getDiagnosticString(),
  2407. HasSubstr("operand ShaderViewportMaskNV(5255) requires one of "
  2408. "these extensions: SPV_NV_viewport_array2"));
  2409. }
  2410. TEST_F(ValidateCapability,
  2411. DecorationEnabledByCapabilityEnabledByPresentExtension) {
  2412. // Decoration ViewportRelativeNV is enabled by ShaderViewportMaskNV, which in
  2413. // turn is enabled by SPV_NV_viewport_array2.
  2414. const std::string spirv = R"(
  2415. OpCapability Shader
  2416. OpCapability Linkage
  2417. OpCapability ShaderViewportMaskNV
  2418. OpExtension "SPV_NV_viewport_array2"
  2419. OpMemoryModel Logical Simple
  2420. OpDecorate %void ViewportRelativeNV
  2421. %void = OpTypeVoid
  2422. )";
  2423. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2424. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0))
  2425. << getDiagnosticString();
  2426. }
  2427. // Three tests to check enablement of an instruction which is not in core, and
  2428. // is directly enabled by a capability, but not directly enabled by an
  2429. // extension. See https://github.com/KhronosGroup/SPIRV-Tools/issues/1624
  2430. // Instruction OpSubgroupShuffleINTEL is enabled by SubgroupShuffleINTEL, which
  2431. // in turn is enabled by SPV_INTEL_subgroups.
  2432. TEST_F(ValidateCapability, InstructionFromExtensionMissingEnabledByCapability) {
  2433. // Decoration ViewportRelativeNV is enabled by ShaderViewportMaskNV, which in
  2434. // turn is enabled by SPV_NV_viewport_array2.
  2435. const std::string spirv = R"(
  2436. OpCapability Kernel
  2437. OpCapability Addresses
  2438. ; OpCapability SubgroupShuffleINTEL
  2439. OpExtension "SPV_INTEL_subgroups"
  2440. OpMemoryModel Physical32 OpenCL
  2441. OpEntryPoint Kernel %main "main"
  2442. %void = OpTypeVoid
  2443. %uint = OpTypeInt 32 0
  2444. %voidfn = OpTypeFunction %void
  2445. %zero = OpConstant %uint 0
  2446. %main = OpFunction %void None %voidfn
  2447. %entry = OpLabel
  2448. %foo = OpSubgroupShuffleINTEL %uint %zero %zero
  2449. OpReturn
  2450. OpFunctionEnd
  2451. )";
  2452. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2453. EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
  2454. ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
  2455. EXPECT_THAT(getDiagnosticString(),
  2456. HasSubstr("Opcode SubgroupShuffleINTEL requires one of these "
  2457. "capabilities: SubgroupShuffleINTEL"));
  2458. }
  2459. TEST_F(ValidateCapability,
  2460. InstructionEnablingCapabilityEnabledByMissingExtension) {
  2461. const std::string spirv = R"(
  2462. OpCapability Kernel
  2463. OpCapability Addresses
  2464. OpCapability SubgroupShuffleINTEL
  2465. ; OpExtension "SPV_INTEL_subgroups"
  2466. OpMemoryModel Physical32 OpenCL
  2467. OpEntryPoint Kernel %main "main"
  2468. %void = OpTypeVoid
  2469. %uint = OpTypeInt 32 0
  2470. %voidfn = OpTypeFunction %void
  2471. %zero = OpConstant %uint 0
  2472. %main = OpFunction %void None %voidfn
  2473. %entry = OpLabel
  2474. %foo = OpSubgroupShuffleINTEL %uint %zero %zero
  2475. OpReturn
  2476. OpFunctionEnd
  2477. )";
  2478. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2479. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2480. ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
  2481. EXPECT_THAT(getDiagnosticString(),
  2482. HasSubstr("operand SubgroupShuffleINTEL(5568) requires one of "
  2483. "these extensions: SPV_INTEL_subgroups"));
  2484. }
  2485. TEST_F(ValidateCapability,
  2486. InstructionEnabledByCapabilityEnabledByPresentExtension) {
  2487. const std::string spirv = R"(
  2488. OpCapability Kernel
  2489. OpCapability Addresses
  2490. OpCapability SubgroupShuffleINTEL
  2491. OpExtension "SPV_INTEL_subgroups"
  2492. OpMemoryModel Physical32 OpenCL
  2493. OpEntryPoint Kernel %main "main"
  2494. %void = OpTypeVoid
  2495. %uint = OpTypeInt 32 0
  2496. %voidfn = OpTypeFunction %void
  2497. %zero = OpConstant %uint 0
  2498. %main = OpFunction %void None %voidfn
  2499. %entry = OpLabel
  2500. %foo = OpSubgroupShuffleINTEL %uint %zero %zero
  2501. OpReturn
  2502. OpFunctionEnd
  2503. )";
  2504. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2505. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0))
  2506. << getDiagnosticString();
  2507. }
  2508. TEST_F(ValidateCapability, VulkanMemoryModelWithVulkanKHR) {
  2509. const std::string spirv = R"(
  2510. OpCapability Shader
  2511. OpCapability VulkanMemoryModelKHR
  2512. OpCapability Linkage
  2513. OpExtension "SPV_KHR_vulkan_memory_model"
  2514. OpMemoryModel Logical VulkanKHR
  2515. )";
  2516. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
  2517. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3))
  2518. << getDiagnosticString();
  2519. }
  2520. TEST_F(ValidateCapability, VulkanMemoryModelWithGLSL450) {
  2521. const std::string spirv = R"(
  2522. OpCapability Shader
  2523. OpCapability VulkanMemoryModelKHR
  2524. OpCapability Linkage
  2525. OpExtension "SPV_KHR_vulkan_memory_model"
  2526. OpMemoryModel Logical GLSL450
  2527. )";
  2528. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
  2529. EXPECT_EQ(SPV_ERROR_INVALID_DATA,
  2530. ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
  2531. EXPECT_THAT(getDiagnosticString(),
  2532. HasSubstr("VulkanMemoryModelKHR capability must only be "
  2533. "specified if the VulkanKHR memory model is used"));
  2534. }
  2535. // In the grammar, SubgroupEqMask and SubgroupMaskKHR have different enabling
  2536. // lists of extensions.
  2537. TEST_F(ValidateCapability, SubgroupEqMaskEnabledByExtension) {
  2538. const std::string spirv = R"(
  2539. OpCapability Shader
  2540. OpCapability SubgroupBallotKHR
  2541. OpExtension "SPV_KHR_shader_ballot"
  2542. OpMemoryModel Logical Simple
  2543. OpEntryPoint GLCompute %main "main"
  2544. OpDecorate %var BuiltIn SubgroupEqMask
  2545. %void = OpTypeVoid
  2546. %uint = OpTypeInt 32 0
  2547. %ptr_uint = OpTypePointer Private %uint
  2548. %var = OpVariable %ptr_uint Private
  2549. %fn = OpTypeFunction %void
  2550. %main = OpFunction %void None %fn
  2551. %entry = OpLabel
  2552. %val = OpLoad %uint %var
  2553. OpReturn
  2554. OpFunctionEnd
  2555. )";
  2556. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
  2557. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0))
  2558. << getDiagnosticString();
  2559. }
  2560. // Test that extensions incorporated into SPIR-V 1.5 no longer require
  2561. // the associated OpExtension instruction. Test one capability per extension.
  2562. struct CapabilityExtensionVersionCase {
  2563. std::string capability;
  2564. std::string capability_new_name;
  2565. std::string extension;
  2566. spv_target_env last_version_requiring_extension;
  2567. spv_target_env first_version_in_core;
  2568. };
  2569. using ValidateCapabilityExtensionVersionTest =
  2570. spvtest::ValidateBase<CapabilityExtensionVersionCase>;
  2571. // Returns a minimal shader module with the given capability instruction.
  2572. std::string MinimalShaderModuleWithCapability(std::string cap) {
  2573. std::string mem_model =
  2574. (cap.find("VulkanMemory") == 0) ? "VulkanKHR" : "GLSL450";
  2575. std::string extra_cap = (cap.find("VulkanMemoryModelDeviceScope") == 0)
  2576. ? "\nOpCapability VulkanMemoryModelKHR\n"
  2577. : "";
  2578. return std::string("OpCapability ") + cap + extra_cap + R"(
  2579. OpCapability Shader
  2580. OpMemoryModel Logical )" + mem_model + R"(
  2581. OpEntryPoint Vertex %main "main"
  2582. %void = OpTypeVoid
  2583. %void_fn = OpTypeFunction %void
  2584. %main = OpFunction %void None %void_fn
  2585. %entry = OpLabel
  2586. OpReturn
  2587. OpFunctionEnd
  2588. )";
  2589. }
  2590. TEST_P(ValidateCapabilityExtensionVersionTest, FailsInOlderSpirvVersion) {
  2591. const auto spirv = MinimalShaderModuleWithCapability(GetParam().capability);
  2592. CompileSuccessfully(spirv, GetParam().last_version_requiring_extension);
  2593. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2594. ValidateInstructions(GetParam().last_version_requiring_extension));
  2595. EXPECT_THAT(getDiagnosticString(),
  2596. HasSubstr(std::string("1st operand of Capability: operand ") +
  2597. GetParam().capability_new_name))
  2598. << spirv << "\n";
  2599. EXPECT_THAT(getDiagnosticString(),
  2600. HasSubstr(std::string("requires one of these extensions: ") +
  2601. GetParam().extension));
  2602. }
  2603. TEST_P(ValidateCapabilityExtensionVersionTest,
  2604. SucceedsInNewerSpirvVersionWithOldName) {
  2605. const auto spirv = MinimalShaderModuleWithCapability(GetParam().capability);
  2606. CompileSuccessfully(spirv, GetParam().first_version_in_core);
  2607. EXPECT_EQ(SPV_SUCCESS,
  2608. ValidateInstructions(GetParam().first_version_in_core));
  2609. EXPECT_THAT(getDiagnosticString(), Eq("")) << spirv << "\n";
  2610. }
  2611. TEST_P(ValidateCapabilityExtensionVersionTest,
  2612. SucceedsInNewerSpirvVersionWithNewName) {
  2613. const auto spirv =
  2614. MinimalShaderModuleWithCapability(GetParam().capability_new_name);
  2615. CompileSuccessfully(spirv, GetParam().first_version_in_core);
  2616. EXPECT_EQ(SPV_SUCCESS,
  2617. ValidateInstructions(GetParam().first_version_in_core));
  2618. EXPECT_THAT(getDiagnosticString(), Eq("")) << spirv << "\n";
  2619. }
  2620. std::vector<CapabilityExtensionVersionCase> CapVersionCases1_5() {
  2621. #define IN15NOSUFFIX(C, E) \
  2622. { C, C, E, SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_5 }
  2623. #define IN15(C, C_WITHOUT_SUFFIX, E) \
  2624. { C, C_WITHOUT_SUFFIX, E, SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_5 }
  2625. return std::vector<CapabilityExtensionVersionCase>{
  2626. // SPV_KHR_8bit_storage
  2627. IN15NOSUFFIX("StorageBuffer8BitAccess", "SPV_KHR_8bit_storage"),
  2628. IN15NOSUFFIX("UniformAndStorageBuffer8BitAccess", "SPV_KHR_8bit_storage"),
  2629. IN15NOSUFFIX("StoragePushConstant8", "SPV_KHR_8bit_storage"),
  2630. // SPV_EXT_descriptor_indexing
  2631. IN15("ShaderNonUniformEXT", "ShaderNonUniform",
  2632. "SPV_EXT_descriptor_indexing"),
  2633. IN15("RuntimeDescriptorArrayEXT", "RuntimeDescriptorArray",
  2634. "SPV_EXT_descriptor_indexing"),
  2635. IN15("InputAttachmentArrayDynamicIndexingEXT",
  2636. "InputAttachmentArrayDynamicIndexing",
  2637. "SPV_EXT_descriptor_indexing"),
  2638. IN15("UniformTexelBufferArrayDynamicIndexingEXT",
  2639. "UniformTexelBufferArrayDynamicIndexing",
  2640. "SPV_EXT_descriptor_indexing"),
  2641. IN15("StorageTexelBufferArrayDynamicIndexingEXT",
  2642. "StorageTexelBufferArrayDynamicIndexing",
  2643. "SPV_EXT_descriptor_indexing"),
  2644. IN15("UniformBufferArrayNonUniformIndexingEXT",
  2645. "UniformBufferArrayNonUniformIndexing",
  2646. "SPV_EXT_descriptor_indexing"),
  2647. IN15("SampledImageArrayNonUniformIndexingEXT",
  2648. "SampledImageArrayNonUniformIndexing",
  2649. "SPV_EXT_descriptor_indexing"),
  2650. IN15("StorageBufferArrayNonUniformIndexingEXT",
  2651. "StorageBufferArrayNonUniformIndexing",
  2652. "SPV_EXT_descriptor_indexing"),
  2653. IN15("StorageImageArrayNonUniformIndexingEXT",
  2654. "StorageImageArrayNonUniformIndexing",
  2655. "SPV_EXT_descriptor_indexing"),
  2656. IN15("InputAttachmentArrayNonUniformIndexingEXT",
  2657. "InputAttachmentArrayNonUniformIndexing",
  2658. "SPV_EXT_descriptor_indexing"),
  2659. IN15("UniformTexelBufferArrayNonUniformIndexingEXT",
  2660. "UniformTexelBufferArrayNonUniformIndexing",
  2661. "SPV_EXT_descriptor_indexing"),
  2662. IN15("StorageTexelBufferArrayNonUniformIndexingEXT",
  2663. "StorageTexelBufferArrayNonUniformIndexing",
  2664. "SPV_EXT_descriptor_indexing"),
  2665. // SPV_EXT_physical_storage_buffer
  2666. IN15("PhysicalStorageBufferAddressesEXT",
  2667. "PhysicalStorageBufferAddresses", "SPV_EXT_physical_storage_buffer"),
  2668. // SPV_KHR_vulkan_memory_model
  2669. IN15("VulkanMemoryModelKHR", "VulkanMemoryModel",
  2670. "SPV_KHR_vulkan_memory_model"),
  2671. IN15("VulkanMemoryModelDeviceScopeKHR", "VulkanMemoryModelDeviceScope",
  2672. "SPV_KHR_vulkan_memory_model"),
  2673. };
  2674. #undef IN15
  2675. }
  2676. INSTANTIATE_TEST_SUITE_P(NewInSpirv1_5, ValidateCapabilityExtensionVersionTest,
  2677. ValuesIn(CapVersionCases1_5()));
  2678. TEST_P(ValidateCapability,
  2679. CapShaderViewportIndexLayerFailsInOlderSpirvVersion) {
  2680. const auto spirv =
  2681. MinimalShaderModuleWithCapability("ShaderViewportIndexLayerEXT");
  2682. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
  2683. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2684. ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
  2685. EXPECT_THAT(
  2686. getDiagnosticString(),
  2687. HasSubstr(
  2688. "1st operand of Capability: operand ShaderViewportIndexLayerEXT"));
  2689. EXPECT_THAT(getDiagnosticString(),
  2690. HasSubstr("requires one of these extensions: "
  2691. "SPV_EXT_shader_viewport_index_layer"));
  2692. }
  2693. TEST_P(ValidateCapability, CapShaderViewportIndexLayerFailsInNewSpirvVersion) {
  2694. const auto spirv =
  2695. MinimalShaderModuleWithCapability("ShaderViewportIndexLayerEXT");
  2696. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_5);
  2697. EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
  2698. ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
  2699. EXPECT_THAT(
  2700. getDiagnosticString(),
  2701. HasSubstr(
  2702. "1st operand of Capability: operand ShaderViewportIndexLayerEXT"));
  2703. EXPECT_THAT(getDiagnosticString(),
  2704. HasSubstr("requires one of these extensions: "
  2705. "SPV_EXT_shader_viewport_index_layer"));
  2706. }
  2707. TEST_F(ValidateCapability, CapShaderViewportIndexSucceedsInNewSpirvVersion) {
  2708. const auto spirv = MinimalShaderModuleWithCapability("ShaderViewportIndex");
  2709. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_5);
  2710. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
  2711. EXPECT_THAT(getDiagnosticString(), Eq(""));
  2712. }
  2713. TEST_F(ValidateCapability, CapShaderLayerSucceedsInNewSpirvVersion) {
  2714. const auto spirv = MinimalShaderModuleWithCapability("ShaderLayer");
  2715. CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_5);
  2716. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
  2717. EXPECT_THAT(getDiagnosticString(), Eq(""));
  2718. }
  2719. } // namespace
  2720. } // namespace val
  2721. } // namespace spvtools