| Flutter Impeller |

uniform_sorter.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/compiler/uniform_sorter.h"
6
7 namespace impeller {
8
9 std::vector<spirv_cross::ID> SortUniforms(
10 const spirv_cross::ParsedIR* ir,
11 const spirv_cross::Compiler* compiler,
12 std::optional<spirv_cross::SPIRType::BaseType> type_filter,
13 bool include) {
14 // Sort the IR so that the uniforms are in declaration order.
15 std::vector<spirv_cross::ID> uniforms;
16 ir->for_each_typed_id<spirv_cross::SPIRVariable>(
17 [&](uint32_t, const spirv_cross::SPIRVariable& var) {
18 if (var.storage != spv::StorageClassUniformConstant) {
19 return;
20 }
21 const auto type = compiler->get_type(var.basetype);
22 if (!type_filter.has_value() ||
23 (include && type_filter.value() == type.basetype) ||
24 (!include && type_filter.value() != type.basetype)) {
25 uniforms.push_back(var.self);
26 }
27 });
28
29 auto compare_locations = [&ir](spirv_cross::ID id1, spirv_cross::ID id2) {
30 auto& flags1 = ir->get_decoration_bitset(id1);
31 auto& flags2 = ir->get_decoration_bitset(id2);
32 // Put the uniforms with no location after the ones that have a location.
33 if (!flags1.get(spv::Decoration::DecorationLocation)) {
34 return false;
35 }
36 if (!flags2.get(spv::Decoration::DecorationLocation)) {
37 return true;
38 }
39 // Sort in increasing order of location.
40 return ir->get_decoration(id1, spv::Decoration::DecorationLocation) <
41 ir->get_decoration(id2, spv::Decoration::DecorationLocation);
42 };
43 std::sort(uniforms.begin(), uniforms.end(), compare_locations);
44
45 return uniforms;
46 }
47
48 } // namespace impeller
uniform_sorter.h
impeller::SortUniforms
std::vector< spirv_cross::ID > SortUniforms(const spirv_cross::ParsedIR *ir, const spirv_cross::Compiler *compiler, std::optional< spirv_cross::SPIRType::BaseType > type_filter, bool include)
Sorts uniform declarations in an IR according to decoration order.
Definition: uniform_sorter.cc:9
impeller
Definition: aiks_context.cc:10