switch_descriptorset_pass.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2023 LunarG Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "source/opt/switch_descriptorset_pass.h"
  15. #include "source/opt/ir_builder.h"
  16. #include "source/util/string_utils.h"
  17. namespace spvtools {
  18. namespace opt {
  19. Pass::Status SwitchDescriptorSetPass::Process() {
  20. Status status = Status::SuccessWithoutChange;
  21. auto* deco_mgr = context()->get_decoration_mgr();
  22. for (Instruction& var : context()->types_values()) {
  23. if (var.opcode() != spv::Op::OpVariable) {
  24. continue;
  25. }
  26. auto decos = deco_mgr->GetDecorationsFor(var.result_id(), false);
  27. for (const auto& deco : decos) {
  28. spv::Decoration d = spv::Decoration(deco->GetSingleWordInOperand(1u));
  29. if (d == spv::Decoration::DescriptorSet &&
  30. deco->GetSingleWordInOperand(2u) == ds_from_) {
  31. deco->SetInOperand(2u, {ds_to_});
  32. status = Status::SuccessWithChange;
  33. break;
  34. }
  35. }
  36. }
  37. return status;
  38. }
  39. } // namespace opt
  40. } // namespace spvtools