-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[impellerc] sort uniforms on metal backend #39366
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9a1796c
[impellerc] sort uniforms on metal backend
jonahwilliams 4b86f2e
dont double loop
jonahwilliams d580d6a
add comment
jonahwilliams 65c7fad
Merge branch 'master' of github.com:flutter/engine into spriv_sort
jonahwilliams 520c09f
ensure sksl backend picks up all uniforms
jonahwilliams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "impeller/compiler/uniform_sorter.h" | ||
|
||
namespace impeller { | ||
|
||
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) { | ||
// Sort the IR so that the uniforms are in declaration order. | ||
std::vector<spirv_cross::ID> uniforms; | ||
ir->for_each_typed_id<spirv_cross::SPIRVariable>( | ||
[&](uint32_t, const spirv_cross::SPIRVariable& var) { | ||
if (var.storage != spv::StorageClassUniformConstant) { | ||
return; | ||
} | ||
const auto type = compiler->get_type(var.basetype); | ||
if (!type_filter.has_value() || | ||
(include && type_filter.value() == type.basetype) || | ||
(!include && type_filter.value() != type.basetype)) { | ||
uniforms.push_back(var.self); | ||
} | ||
}); | ||
|
||
auto compare_locations = [&ir](spirv_cross::ID id1, spirv_cross::ID id2) { | ||
auto& flags1 = ir->get_decoration_bitset(id1); | ||
auto& flags2 = ir->get_decoration_bitset(id2); | ||
// Put the uniforms with no location after the ones that have a location. | ||
if (!flags1.get(spv::Decoration::DecorationLocation)) { | ||
return false; | ||
} | ||
if (!flags2.get(spv::Decoration::DecorationLocation)) { | ||
return true; | ||
} | ||
// Sort in increasing order of location. | ||
return ir->get_decoration(id1, spv::Decoration::DecorationLocation) < | ||
ir->get_decoration(id2, spv::Decoration::DecorationLocation); | ||
}; | ||
std::sort(uniforms.begin(), uniforms.end(), compare_locations); | ||
|
||
return uniforms; | ||
} | ||
|
||
} // namespace impeller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#pragma once | ||
|
||
#include <optional> | ||
|
||
#include "impeller/compiler/compiler_backend.h" | ||
|
||
#include "spirv_msl.hpp" | ||
#include "spirv_parser.hpp" | ||
|
||
namespace impeller { | ||
|
||
/// @brief Sorts uniform declarations in an IR according to decoration order. | ||
/// | ||
/// The [type_filter] may be optionally supplied to limit which types are | ||
/// returned The [include] value can be set to false change this filter to | ||
/// exclude instead of include. | ||
std::vector<spirv_cross::ID> SortUniforms( | ||
const spirv_cross::ParsedIR* ir, | ||
const spirv_cross::Compiler* compiler, | ||
std::optional<spirv_cross::SPIRType::BaseType> type_filter = std::nullopt, | ||
bool include = true); | ||
|
||
} // namespace impeller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The revert was required because this change was filtering out non float uniforms, which we would never emit, and therefore never error check. We could move the error checking earlier in the pipeline, now that I'm more familiar with the API that is probably a better place to do it.
That said for now, the minimal change is to sort all unfiorms except sampled images instead of all float uniforms.