validate_mode_setting.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. // Copyright (c) 2018 Google LLC.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. #include "source/val/validate.h"
  16. #include <algorithm>
  17. #include "source/opcode.h"
  18. #include "source/spirv_target_env.h"
  19. #include "source/val/instruction.h"
  20. #include "source/val/validation_state.h"
  21. namespace spvtools {
  22. namespace val {
  23. namespace {
  24. spv_result_t ValidateEntryPoint(ValidationState_t& _, const Instruction* inst) {
  25. const auto entry_point_id = inst->GetOperandAs<uint32_t>(1);
  26. auto entry_point = _.FindDef(entry_point_id);
  27. if (!entry_point || SpvOpFunction != entry_point->opcode()) {
  28. return _.diag(SPV_ERROR_INVALID_ID, inst)
  29. << "OpEntryPoint Entry Point <id> '" << _.getIdName(entry_point_id)
  30. << "' is not a function.";
  31. }
  32. // Only check the shader execution models
  33. const SpvExecutionModel execution_model =
  34. inst->GetOperandAs<SpvExecutionModel>(0);
  35. if (execution_model != SpvExecutionModelKernel) {
  36. const auto entry_point_type_id = entry_point->GetOperandAs<uint32_t>(3);
  37. const auto entry_point_type = _.FindDef(entry_point_type_id);
  38. if (!entry_point_type || 3 != entry_point_type->words().size()) {
  39. return _.diag(SPV_ERROR_INVALID_ID, inst)
  40. << _.VkErrorID(4633) << "OpEntryPoint Entry Point <id> '"
  41. << _.getIdName(entry_point_id)
  42. << "'s function parameter count is not zero.";
  43. }
  44. }
  45. auto return_type = _.FindDef(entry_point->type_id());
  46. if (!return_type || SpvOpTypeVoid != return_type->opcode()) {
  47. return _.diag(SPV_ERROR_INVALID_ID, inst)
  48. << _.VkErrorID(4633) << "OpEntryPoint Entry Point <id> '"
  49. << _.getIdName(entry_point_id)
  50. << "'s function return type is not void.";
  51. }
  52. const auto* execution_modes = _.GetExecutionModes(entry_point_id);
  53. if (_.HasCapability(SpvCapabilityShader)) {
  54. switch (execution_model) {
  55. case SpvExecutionModelFragment:
  56. if (execution_modes &&
  57. execution_modes->count(SpvExecutionModeOriginUpperLeft) &&
  58. execution_modes->count(SpvExecutionModeOriginLowerLeft)) {
  59. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  60. << "Fragment execution model entry points can only specify "
  61. "one of OriginUpperLeft or OriginLowerLeft execution "
  62. "modes.";
  63. }
  64. if (!execution_modes ||
  65. (!execution_modes->count(SpvExecutionModeOriginUpperLeft) &&
  66. !execution_modes->count(SpvExecutionModeOriginLowerLeft))) {
  67. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  68. << "Fragment execution model entry points require either an "
  69. "OriginUpperLeft or OriginLowerLeft execution mode.";
  70. }
  71. if (execution_modes &&
  72. 1 < std::count_if(execution_modes->begin(), execution_modes->end(),
  73. [](const SpvExecutionMode& mode) {
  74. switch (mode) {
  75. case SpvExecutionModeDepthGreater:
  76. case SpvExecutionModeDepthLess:
  77. case SpvExecutionModeDepthUnchanged:
  78. return true;
  79. default:
  80. return false;
  81. }
  82. })) {
  83. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  84. << "Fragment execution model entry points can specify at most "
  85. "one of DepthGreater, DepthLess or DepthUnchanged "
  86. "execution modes.";
  87. }
  88. if (execution_modes &&
  89. 1 < std::count_if(
  90. execution_modes->begin(), execution_modes->end(),
  91. [](const SpvExecutionMode& mode) {
  92. switch (mode) {
  93. case SpvExecutionModePixelInterlockOrderedEXT:
  94. case SpvExecutionModePixelInterlockUnorderedEXT:
  95. case SpvExecutionModeSampleInterlockOrderedEXT:
  96. case SpvExecutionModeSampleInterlockUnorderedEXT:
  97. case SpvExecutionModeShadingRateInterlockOrderedEXT:
  98. case SpvExecutionModeShadingRateInterlockUnorderedEXT:
  99. return true;
  100. default:
  101. return false;
  102. }
  103. })) {
  104. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  105. << "Fragment execution model entry points can specify at most "
  106. "one fragment shader interlock execution mode.";
  107. }
  108. if (execution_modes &&
  109. 1 < std::count_if(
  110. execution_modes->begin(), execution_modes->end(),
  111. [](const SpvExecutionMode& mode) {
  112. switch (mode) {
  113. case SpvExecutionModeStencilRefUnchangedFrontAMD:
  114. case SpvExecutionModeStencilRefLessFrontAMD:
  115. case SpvExecutionModeStencilRefGreaterFrontAMD:
  116. return true;
  117. default:
  118. return false;
  119. }
  120. })) {
  121. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  122. << "Fragment execution model entry points can specify at most "
  123. "one of StencilRefUnchangedFrontAMD, "
  124. "StencilRefLessFrontAMD or StencilRefGreaterFrontAMD "
  125. "execution modes.";
  126. }
  127. if (execution_modes &&
  128. 1 < std::count_if(
  129. execution_modes->begin(), execution_modes->end(),
  130. [](const SpvExecutionMode& mode) {
  131. switch (mode) {
  132. case SpvExecutionModeStencilRefUnchangedBackAMD:
  133. case SpvExecutionModeStencilRefLessBackAMD:
  134. case SpvExecutionModeStencilRefGreaterBackAMD:
  135. return true;
  136. default:
  137. return false;
  138. }
  139. })) {
  140. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  141. << "Fragment execution model entry points can specify at most "
  142. "one of StencilRefUnchangedBackAMD, "
  143. "StencilRefLessBackAMD or StencilRefGreaterBackAMD "
  144. "execution modes.";
  145. }
  146. break;
  147. case SpvExecutionModelTessellationControl:
  148. case SpvExecutionModelTessellationEvaluation:
  149. if (execution_modes &&
  150. 1 < std::count_if(execution_modes->begin(), execution_modes->end(),
  151. [](const SpvExecutionMode& mode) {
  152. switch (mode) {
  153. case SpvExecutionModeSpacingEqual:
  154. case SpvExecutionModeSpacingFractionalEven:
  155. case SpvExecutionModeSpacingFractionalOdd:
  156. return true;
  157. default:
  158. return false;
  159. }
  160. })) {
  161. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  162. << "Tessellation execution model entry points can specify at "
  163. "most one of SpacingEqual, SpacingFractionalOdd or "
  164. "SpacingFractionalEven execution modes.";
  165. }
  166. if (execution_modes &&
  167. 1 < std::count_if(execution_modes->begin(), execution_modes->end(),
  168. [](const SpvExecutionMode& mode) {
  169. switch (mode) {
  170. case SpvExecutionModeTriangles:
  171. case SpvExecutionModeQuads:
  172. case SpvExecutionModeIsolines:
  173. return true;
  174. default:
  175. return false;
  176. }
  177. })) {
  178. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  179. << "Tessellation execution model entry points can specify at "
  180. "most one of Triangles, Quads or Isolines execution modes.";
  181. }
  182. if (execution_modes &&
  183. 1 < std::count_if(execution_modes->begin(), execution_modes->end(),
  184. [](const SpvExecutionMode& mode) {
  185. switch (mode) {
  186. case SpvExecutionModeVertexOrderCw:
  187. case SpvExecutionModeVertexOrderCcw:
  188. return true;
  189. default:
  190. return false;
  191. }
  192. })) {
  193. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  194. << "Tessellation execution model entry points can specify at "
  195. "most one of VertexOrderCw or VertexOrderCcw execution "
  196. "modes.";
  197. }
  198. break;
  199. case SpvExecutionModelGeometry:
  200. if (!execution_modes ||
  201. 1 != std::count_if(execution_modes->begin(), execution_modes->end(),
  202. [](const SpvExecutionMode& mode) {
  203. switch (mode) {
  204. case SpvExecutionModeInputPoints:
  205. case SpvExecutionModeInputLines:
  206. case SpvExecutionModeInputLinesAdjacency:
  207. case SpvExecutionModeTriangles:
  208. case SpvExecutionModeInputTrianglesAdjacency:
  209. return true;
  210. default:
  211. return false;
  212. }
  213. })) {
  214. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  215. << "Geometry execution model entry points must specify "
  216. "exactly one of InputPoints, InputLines, "
  217. "InputLinesAdjacency, Triangles or InputTrianglesAdjacency "
  218. "execution modes.";
  219. }
  220. if (!execution_modes ||
  221. 1 != std::count_if(execution_modes->begin(), execution_modes->end(),
  222. [](const SpvExecutionMode& mode) {
  223. switch (mode) {
  224. case SpvExecutionModeOutputPoints:
  225. case SpvExecutionModeOutputLineStrip:
  226. case SpvExecutionModeOutputTriangleStrip:
  227. return true;
  228. default:
  229. return false;
  230. }
  231. })) {
  232. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  233. << "Geometry execution model entry points must specify "
  234. "exactly one of OutputPoints, OutputLineStrip or "
  235. "OutputTriangleStrip execution modes.";
  236. }
  237. break;
  238. default:
  239. break;
  240. }
  241. }
  242. if (spvIsVulkanEnv(_.context()->target_env)) {
  243. switch (execution_model) {
  244. case SpvExecutionModelGLCompute:
  245. if (!execution_modes ||
  246. !execution_modes->count(SpvExecutionModeLocalSize)) {
  247. bool ok = false;
  248. for (auto& i : _.ordered_instructions()) {
  249. if (i.opcode() == SpvOpDecorate) {
  250. if (i.operands().size() > 2) {
  251. if (i.GetOperandAs<SpvDecoration>(1) == SpvDecorationBuiltIn &&
  252. i.GetOperandAs<SpvBuiltIn>(2) == SpvBuiltInWorkgroupSize) {
  253. ok = true;
  254. break;
  255. }
  256. }
  257. }
  258. if (i.opcode() == SpvOpExecutionModeId) {
  259. const auto mode = i.GetOperandAs<SpvExecutionMode>(1);
  260. if (mode == SpvExecutionModeLocalSizeId) {
  261. ok = true;
  262. break;
  263. }
  264. }
  265. }
  266. if (!ok) {
  267. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  268. << _.VkErrorID(6426)
  269. << "In the Vulkan environment, GLCompute execution model "
  270. "entry points require either the LocalSize or "
  271. "LocalSizeId execution mode or an object decorated with "
  272. "WorkgroupSize must be specified.";
  273. }
  274. }
  275. break;
  276. default:
  277. break;
  278. }
  279. }
  280. return SPV_SUCCESS;
  281. }
  282. spv_result_t ValidateExecutionMode(ValidationState_t& _,
  283. const Instruction* inst) {
  284. const auto entry_point_id = inst->GetOperandAs<uint32_t>(0);
  285. const auto found = std::find(_.entry_points().cbegin(),
  286. _.entry_points().cend(), entry_point_id);
  287. if (found == _.entry_points().cend()) {
  288. return _.diag(SPV_ERROR_INVALID_ID, inst)
  289. << "OpExecutionMode Entry Point <id> '"
  290. << _.getIdName(entry_point_id)
  291. << "' is not the Entry Point "
  292. "operand of an OpEntryPoint.";
  293. }
  294. const auto mode = inst->GetOperandAs<SpvExecutionMode>(1);
  295. if (inst->opcode() == SpvOpExecutionModeId) {
  296. size_t operand_count = inst->operands().size();
  297. for (size_t i = 2; i < operand_count; ++i) {
  298. const auto operand_id = inst->GetOperandAs<uint32_t>(2);
  299. const auto* operand_inst = _.FindDef(operand_id);
  300. if (mode == SpvExecutionModeSubgroupsPerWorkgroupId ||
  301. mode == SpvExecutionModeLocalSizeHintId ||
  302. mode == SpvExecutionModeLocalSizeId) {
  303. if (!spvOpcodeIsConstant(operand_inst->opcode())) {
  304. return _.diag(SPV_ERROR_INVALID_ID, inst)
  305. << "For OpExecutionModeId all Extra Operand ids must be "
  306. "constant "
  307. "instructions.";
  308. }
  309. } else {
  310. return _.diag(SPV_ERROR_INVALID_ID, inst)
  311. << "OpExecutionModeId is only valid when the Mode operand is an "
  312. "execution mode that takes Extra Operands that are id "
  313. "operands.";
  314. }
  315. }
  316. } else if (mode == SpvExecutionModeSubgroupsPerWorkgroupId ||
  317. mode == SpvExecutionModeLocalSizeHintId ||
  318. mode == SpvExecutionModeLocalSizeId) {
  319. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  320. << "OpExecutionMode is only valid when the Mode operand is an "
  321. "execution mode that takes no Extra Operands, or takes Extra "
  322. "Operands that are not id operands.";
  323. }
  324. const auto* models = _.GetExecutionModels(entry_point_id);
  325. switch (mode) {
  326. case SpvExecutionModeInvocations:
  327. case SpvExecutionModeInputPoints:
  328. case SpvExecutionModeInputLines:
  329. case SpvExecutionModeInputLinesAdjacency:
  330. case SpvExecutionModeInputTrianglesAdjacency:
  331. case SpvExecutionModeOutputLineStrip:
  332. case SpvExecutionModeOutputTriangleStrip:
  333. if (!std::all_of(models->begin(), models->end(),
  334. [](const SpvExecutionModel& model) {
  335. return model == SpvExecutionModelGeometry;
  336. })) {
  337. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  338. << "Execution mode can only be used with the Geometry execution "
  339. "model.";
  340. }
  341. break;
  342. case SpvExecutionModeOutputPoints:
  343. if (!std::all_of(models->begin(), models->end(),
  344. [&_](const SpvExecutionModel& model) {
  345. switch (model) {
  346. case SpvExecutionModelGeometry:
  347. return true;
  348. case SpvExecutionModelMeshNV:
  349. return _.HasCapability(SpvCapabilityMeshShadingNV);
  350. default:
  351. return false;
  352. }
  353. })) {
  354. if (_.HasCapability(SpvCapabilityMeshShadingNV)) {
  355. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  356. << "Execution mode can only be used with the Geometry or "
  357. "MeshNV execution model.";
  358. } else {
  359. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  360. << "Execution mode can only be used with the Geometry "
  361. "execution "
  362. "model.";
  363. }
  364. }
  365. break;
  366. case SpvExecutionModeSpacingEqual:
  367. case SpvExecutionModeSpacingFractionalEven:
  368. case SpvExecutionModeSpacingFractionalOdd:
  369. case SpvExecutionModeVertexOrderCw:
  370. case SpvExecutionModeVertexOrderCcw:
  371. case SpvExecutionModePointMode:
  372. case SpvExecutionModeQuads:
  373. case SpvExecutionModeIsolines:
  374. if (!std::all_of(
  375. models->begin(), models->end(),
  376. [](const SpvExecutionModel& model) {
  377. return (model == SpvExecutionModelTessellationControl) ||
  378. (model == SpvExecutionModelTessellationEvaluation);
  379. })) {
  380. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  381. << "Execution mode can only be used with a tessellation "
  382. "execution model.";
  383. }
  384. break;
  385. case SpvExecutionModeTriangles:
  386. if (!std::all_of(models->begin(), models->end(),
  387. [](const SpvExecutionModel& model) {
  388. switch (model) {
  389. case SpvExecutionModelGeometry:
  390. case SpvExecutionModelTessellationControl:
  391. case SpvExecutionModelTessellationEvaluation:
  392. return true;
  393. default:
  394. return false;
  395. }
  396. })) {
  397. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  398. << "Execution mode can only be used with a Geometry or "
  399. "tessellation execution model.";
  400. }
  401. break;
  402. case SpvExecutionModeOutputVertices:
  403. if (!std::all_of(models->begin(), models->end(),
  404. [&_](const SpvExecutionModel& model) {
  405. switch (model) {
  406. case SpvExecutionModelGeometry:
  407. case SpvExecutionModelTessellationControl:
  408. case SpvExecutionModelTessellationEvaluation:
  409. return true;
  410. case SpvExecutionModelMeshNV:
  411. return _.HasCapability(SpvCapabilityMeshShadingNV);
  412. default:
  413. return false;
  414. }
  415. })) {
  416. if (_.HasCapability(SpvCapabilityMeshShadingNV)) {
  417. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  418. << "Execution mode can only be used with a Geometry, "
  419. "tessellation or MeshNV execution model.";
  420. } else {
  421. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  422. << "Execution mode can only be used with a Geometry or "
  423. "tessellation execution model.";
  424. }
  425. }
  426. break;
  427. case SpvExecutionModePixelCenterInteger:
  428. case SpvExecutionModeOriginUpperLeft:
  429. case SpvExecutionModeOriginLowerLeft:
  430. case SpvExecutionModeEarlyFragmentTests:
  431. case SpvExecutionModeDepthReplacing:
  432. case SpvExecutionModeDepthGreater:
  433. case SpvExecutionModeDepthLess:
  434. case SpvExecutionModeDepthUnchanged:
  435. case SpvExecutionModePixelInterlockOrderedEXT:
  436. case SpvExecutionModePixelInterlockUnorderedEXT:
  437. case SpvExecutionModeSampleInterlockOrderedEXT:
  438. case SpvExecutionModeSampleInterlockUnorderedEXT:
  439. case SpvExecutionModeShadingRateInterlockOrderedEXT:
  440. case SpvExecutionModeShadingRateInterlockUnorderedEXT:
  441. case SpvExecutionModeEarlyAndLateFragmentTestsAMD:
  442. case SpvExecutionModeStencilRefUnchangedFrontAMD:
  443. case SpvExecutionModeStencilRefGreaterFrontAMD:
  444. case SpvExecutionModeStencilRefLessFrontAMD:
  445. case SpvExecutionModeStencilRefUnchangedBackAMD:
  446. case SpvExecutionModeStencilRefGreaterBackAMD:
  447. case SpvExecutionModeStencilRefLessBackAMD:
  448. if (!std::all_of(models->begin(), models->end(),
  449. [](const SpvExecutionModel& model) {
  450. return model == SpvExecutionModelFragment;
  451. })) {
  452. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  453. << "Execution mode can only be used with the Fragment execution "
  454. "model.";
  455. }
  456. break;
  457. case SpvExecutionModeLocalSizeHint:
  458. case SpvExecutionModeVecTypeHint:
  459. case SpvExecutionModeContractionOff:
  460. case SpvExecutionModeLocalSizeHintId:
  461. if (!std::all_of(models->begin(), models->end(),
  462. [](const SpvExecutionModel& model) {
  463. return model == SpvExecutionModelKernel;
  464. })) {
  465. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  466. << "Execution mode can only be used with the Kernel execution "
  467. "model.";
  468. }
  469. break;
  470. case SpvExecutionModeLocalSize:
  471. case SpvExecutionModeLocalSizeId:
  472. if (mode == SpvExecutionModeLocalSizeId && !_.IsLocalSizeIdAllowed())
  473. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  474. << "LocalSizeId mode is not allowed by the current environment.";
  475. if (!std::all_of(models->begin(), models->end(),
  476. [&_](const SpvExecutionModel& model) {
  477. switch (model) {
  478. case SpvExecutionModelKernel:
  479. case SpvExecutionModelGLCompute:
  480. return true;
  481. case SpvExecutionModelTaskNV:
  482. case SpvExecutionModelMeshNV:
  483. return _.HasCapability(SpvCapabilityMeshShadingNV);
  484. default:
  485. return false;
  486. }
  487. })) {
  488. if (_.HasCapability(SpvCapabilityMeshShadingNV)) {
  489. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  490. << "Execution mode can only be used with a Kernel, GLCompute, "
  491. "MeshNV, or TaskNV execution model.";
  492. } else {
  493. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  494. << "Execution mode can only be used with a Kernel or "
  495. "GLCompute "
  496. "execution model.";
  497. }
  498. }
  499. default:
  500. break;
  501. }
  502. if (spvIsVulkanEnv(_.context()->target_env)) {
  503. if (mode == SpvExecutionModeOriginLowerLeft) {
  504. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  505. << _.VkErrorID(4653)
  506. << "In the Vulkan environment, the OriginLowerLeft execution mode "
  507. "must not be used.";
  508. }
  509. if (mode == SpvExecutionModePixelCenterInteger) {
  510. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  511. << _.VkErrorID(4654)
  512. << "In the Vulkan environment, the PixelCenterInteger execution "
  513. "mode must not be used.";
  514. }
  515. }
  516. return SPV_SUCCESS;
  517. }
  518. spv_result_t ValidateMemoryModel(ValidationState_t& _,
  519. const Instruction* inst) {
  520. // Already produced an error if multiple memory model instructions are
  521. // present.
  522. if (_.memory_model() != SpvMemoryModelVulkanKHR &&
  523. _.HasCapability(SpvCapabilityVulkanMemoryModelKHR)) {
  524. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  525. << "VulkanMemoryModelKHR capability must only be specified if "
  526. "the VulkanKHR memory model is used.";
  527. }
  528. if (spvIsOpenCLEnv(_.context()->target_env)) {
  529. if ((_.addressing_model() != SpvAddressingModelPhysical32) &&
  530. (_.addressing_model() != SpvAddressingModelPhysical64)) {
  531. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  532. << "Addressing model must be Physical32 or Physical64 "
  533. << "in the OpenCL environment.";
  534. }
  535. if (_.memory_model() != SpvMemoryModelOpenCL) {
  536. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  537. << "Memory model must be OpenCL in the OpenCL environment.";
  538. }
  539. }
  540. if (spvIsVulkanEnv(_.context()->target_env)) {
  541. if ((_.addressing_model() != SpvAddressingModelLogical) &&
  542. (_.addressing_model() != SpvAddressingModelPhysicalStorageBuffer64)) {
  543. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  544. << _.VkErrorID(4635)
  545. << "Addressing model must be Logical or PhysicalStorageBuffer64 "
  546. << "in the Vulkan environment.";
  547. }
  548. }
  549. return SPV_SUCCESS;
  550. }
  551. } // namespace
  552. spv_result_t ModeSettingPass(ValidationState_t& _, const Instruction* inst) {
  553. switch (inst->opcode()) {
  554. case SpvOpEntryPoint:
  555. if (auto error = ValidateEntryPoint(_, inst)) return error;
  556. break;
  557. case SpvOpExecutionMode:
  558. case SpvOpExecutionModeId:
  559. if (auto error = ValidateExecutionMode(_, inst)) return error;
  560. break;
  561. case SpvOpMemoryModel:
  562. if (auto error = ValidateMemoryModel(_, inst)) return error;
  563. break;
  564. default:
  565. break;
  566. }
  567. return SPV_SUCCESS;
  568. }
  569. } // namespace val
  570. } // namespace spvtools