validate_execution_limitations.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2018 Google LLC.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "source/val/validate.h"
  15. #include "source/val/validation_state.h"
  16. namespace spvtools {
  17. namespace val {
  18. spv_result_t ValidateExecutionLimitations(ValidationState_t& _,
  19. const Instruction* inst) {
  20. if (inst->opcode() != spv::Op::OpFunction) {
  21. return SPV_SUCCESS;
  22. }
  23. const auto func = _.function(inst->id());
  24. if (!func) {
  25. return _.diag(SPV_ERROR_INTERNAL, inst)
  26. << "Internal error: missing function id " << inst->id() << ".";
  27. }
  28. for (uint32_t entry_id : _.FunctionEntryPoints(inst->id())) {
  29. const auto* models = _.GetExecutionModels(entry_id);
  30. if (models) {
  31. if (models->empty()) {
  32. return _.diag(SPV_ERROR_INTERNAL, inst)
  33. << "Internal error: empty execution models for function id "
  34. << entry_id << ".";
  35. }
  36. for (const auto model : *models) {
  37. std::string reason;
  38. if (!func->IsCompatibleWithExecutionModel(model, &reason)) {
  39. return _.diag(SPV_ERROR_INVALID_ID, inst)
  40. << "OpEntryPoint Entry Point <id> " << _.getIdName(entry_id)
  41. << "s callgraph contains function <id> "
  42. << _.getIdName(inst->id())
  43. << ", which cannot be used with the current execution "
  44. "model:\n"
  45. << reason;
  46. }
  47. }
  48. }
  49. std::string reason;
  50. if (!func->CheckLimitations(_, _.function(entry_id), &reason)) {
  51. return _.diag(SPV_ERROR_INVALID_ID, inst)
  52. << "OpEntryPoint Entry Point <id> " << _.getIdName(entry_id)
  53. << "s callgraph contains function <id> " << _.getIdName(inst->id())
  54. << ", which cannot be used with the current execution "
  55. "modes:\n"
  56. << reason;
  57. }
  58. }
  59. return SPV_SUCCESS;
  60. }
  61. } // namespace val
  62. } // namespace spvtools