| 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 #include <cstdint>
8
9 namespace impeller {
10
11 std::vector<spirv_cross::ID> SortUniforms(
12 const spirv_cross::ParsedIR* ir,
13 const spirv_cross::Compiler* compiler,
14 std::optional<spirv_cross::SPIRType::BaseType> type_filter,
15 bool include) {
16 // Sort the IR so that the uniforms are in declaration order.
17 std::vector<spirv_cross::ID> uniforms;
18 ir->for_each_typed_id<spirv_cross::SPIRVariable>(
19 [&](uint32_t, const spirv_cross::SPIRVariable& var) {
20 if (var.storage != spv::StorageClassUniformConstant) {
21 return;
22 }
23 const auto& type = compiler->get_type(var.basetype);
24 if (!type_filter.has_value() ||
25 (include && type_filter.value() == type.basetype) ||
26 (!include && type_filter.value() != type.basetype)) {
27 uniforms.push_back(var.self);
28 }
29 });
30
31 auto compare_locations = [&ir](spirv_cross::ID id1, spirv_cross::ID id2) {
32 auto& flags1 = ir->get_decoration_bitset(id1);
33 auto& flags2 = ir->get_decoration_bitset(id2);
34 // Put the uniforms with no location after the ones that have a location.
35 if (!flags1.get(spv::Decoration::DecorationLocation)) {
36 return false;
37 }
38 if (!flags2.get(spv::Decoration::DecorationLocation)) {
39 return true;
40 }
41 // Sort in increasing order of location.
42 return ir->get_decoration(id1, spv::Decoration::DecorationLocation) <
43 ir->get_decoration(id2, spv::Decoration::DecorationLocation);
44 };
45 std::sort(uniforms.begin(), uniforms.end(), compare_locations);
46
47 return uniforms;
48 }
49
50 } // 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:11
impeller
Definition: aiks_blur_unittests.cc:20