1 | /* |
2 | * Copyright 2015-2021 Arm Limited |
3 | * SPDX-License-Identifier: Apache-2.0 OR MIT |
4 | * |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | * you may not use this file except in compliance with the License. |
7 | * You may obtain a copy of the License at |
8 | * |
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
11 | * Unless required by applicable law or agreed to in writing, software |
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | * See the License for the specific language governing permissions and |
15 | * limitations under the License. |
16 | */ |
17 | |
18 | /* |
19 | * At your option, you may choose to accept this material under either: |
20 | * 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or |
21 | * 2. The MIT License, found at <http://opensource.org/licenses/MIT>. |
22 | */ |
23 | |
24 | #include "spirv_cross_util.hpp" |
25 | #include "spirv_common.hpp" |
26 | |
27 | using namespace spv; |
28 | using namespace SPIRV_CROSS_NAMESPACE; |
29 | |
30 | namespace spirv_cross_util |
31 | { |
32 | void rename_interface_variable(Compiler &compiler, const SmallVector<Resource> &resources, uint32_t location, |
33 | const std::string &name) |
34 | { |
35 | for (auto &v : resources) |
36 | { |
37 | if (!compiler.has_decoration(id: v.id, decoration: spv::DecorationLocation)) |
38 | continue; |
39 | |
40 | auto loc = compiler.get_decoration(id: v.id, decoration: spv::DecorationLocation); |
41 | if (loc != location) |
42 | continue; |
43 | |
44 | auto &type = compiler.get_type(id: v.base_type_id); |
45 | |
46 | // This is more of a friendly variant. If we need to rename interface variables, we might have to rename |
47 | // structs as well and make sure all the names match up. |
48 | if (type.basetype == SPIRType::Struct) |
49 | { |
50 | compiler.set_name(id: v.base_type_id, name: join(ts: "SPIRV_Cross_Interface_Location" , ts&: location)); |
51 | for (uint32_t i = 0; i < uint32_t(type.member_types.size()); i++) |
52 | compiler.set_member_name(id: v.base_type_id, index: i, name: join(ts: "InterfaceMember" , ts&: i)); |
53 | } |
54 | |
55 | compiler.set_name(id: v.id, name); |
56 | } |
57 | } |
58 | |
59 | void inherit_combined_sampler_bindings(Compiler &compiler) |
60 | { |
61 | auto &samplers = compiler.get_combined_image_samplers(); |
62 | for (auto &s : samplers) |
63 | { |
64 | if (compiler.has_decoration(id: s.image_id, decoration: spv::DecorationDescriptorSet)) |
65 | { |
66 | uint32_t set = compiler.get_decoration(id: s.image_id, decoration: spv::DecorationDescriptorSet); |
67 | compiler.set_decoration(id: s.combined_id, decoration: spv::DecorationDescriptorSet, argument: set); |
68 | } |
69 | |
70 | if (compiler.has_decoration(id: s.image_id, decoration: spv::DecorationBinding)) |
71 | { |
72 | uint32_t binding = compiler.get_decoration(id: s.image_id, decoration: spv::DecorationBinding); |
73 | compiler.set_decoration(id: s.combined_id, decoration: spv::DecorationBinding, argument: binding); |
74 | } |
75 | } |
76 | } |
77 | } // namespace spirv_cross_util |
78 | |