• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 #include "source/opt/switch_descriptorset_pass.h"
16 
17 #include "source/opt/ir_builder.h"
18 #include "source/util/string_utils.h"
19 
20 namespace spvtools {
21 namespace opt {
22 
Process()23 Pass::Status SwitchDescriptorSetPass::Process() {
24   Status status = Status::SuccessWithoutChange;
25   auto* deco_mgr = context()->get_decoration_mgr();
26 
27   for (Instruction& var : context()->types_values()) {
28     if (var.opcode() != spv::Op::OpVariable) {
29       continue;
30     }
31     auto decos = deco_mgr->GetDecorationsFor(var.result_id(), false);
32     for (const auto& deco : decos) {
33       spv::Decoration d = spv::Decoration(deco->GetSingleWordInOperand(1u));
34       if (d == spv::Decoration::DescriptorSet &&
35           deco->GetSingleWordInOperand(2u) == ds_from_) {
36         deco->SetInOperand(2u, {ds_to_});
37         status = Status::SuccessWithChange;
38         break;
39       }
40     }
41   }
42   return status;
43 }
44 
45 }  // namespace opt
46 }  // namespace spvtools
47