tint/utils/UniqueVector: Use utils::Vector and utils::Hashset

For fewer heap allocations, faster lookups.

Change-Id: I02da7c1a63608096ec898b0d89f9f97c6db8733f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98141
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton
2022-08-17 18:07:20 +00:00
committed by Dawn LUCI CQ
parent b79238d7ec
commit dce63f5717
27 changed files with 224 additions and 218 deletions

View File

@@ -505,7 +505,7 @@ std::vector<ResourceBinding> Inspector::GetExternalTextureResourceBindings(
ResourceBinding::ResourceType::kExternalTexture);
}
std::vector<sem::SamplerTexturePair> Inspector::GetSamplerTextureUses(
utils::Vector<sem::SamplerTexturePair, 4> Inspector::GetSamplerTextureUses(
const std::string& entry_point) {
auto* func = FindEntryPointByName(entry_point);
if (!func) {
@@ -570,7 +570,7 @@ uint32_t Inspector::GetWorkgroupStorageSize(const std::string& entry_point) {
std::vector<std::string> Inspector::GetUsedExtensionNames() {
auto& extensions = program_->Sem().Module()->Extensions();
std::vector<std::string> out;
out.reserve(extensions.size());
out.reserve(extensions.Length());
for (auto ext : extensions) {
out.push_back(utils::ToString(ext));
}
@@ -789,7 +789,7 @@ void Inspector::GenerateSamplerTargets() {
}
sampler_targets_ = std::make_unique<
std::unordered_map<std::string, utils::UniqueVector<sem::SamplerTexturePair>>>();
std::unordered_map<std::string, utils::UniqueVector<sem::SamplerTexturePair, 4>>>();
auto& sem = program_->Sem();
@@ -849,7 +849,7 @@ void Inspector::GenerateSamplerTargets() {
for (auto* entry_point : entry_points) {
const auto& ep_name =
program_->Symbols().NameFor(entry_point->Declaration()->symbol);
(*sampler_targets_)[ep_name].add(
(*sampler_targets_)[ep_name].Add(
{sampler_binding_point, texture_binding_point});
}
});
@@ -868,7 +868,7 @@ void Inspector::GetOriginatingResources(std::array<const ast::Expression*, N> ex
std::array<const sem::GlobalVariable*, N> globals{};
std::array<const sem::Parameter*, N> parameters{};
utils::UniqueVector<const ast::CallExpression*> callsites;
utils::UniqueVector<const ast::CallExpression*, 8> callsites;
for (size_t i = 0; i < N; i++) {
const sem::Variable* source_var = sem.Get(exprs[i])->SourceVariable();
@@ -882,7 +882,7 @@ void Inspector::GetOriginatingResources(std::array<const ast::Expression*, N> ex
return;
}
for (auto* call : func->CallSites()) {
callsites.add(call->Declaration());
callsites.Add(call->Declaration());
}
parameters[i] = param;
} else {
@@ -893,7 +893,7 @@ void Inspector::GetOriginatingResources(std::array<const ast::Expression*, N> ex
}
}
if (callsites.size()) {
if (callsites.Length()) {
for (auto* call_expr : callsites) {
// Make a copy of the expressions for this callsite
std::array<const ast::Expression*, N> call_exprs = exprs;

View File

@@ -122,7 +122,7 @@ class Inspector {
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the sampler/texture sampling pairs that are used
/// by that entry point.
std::vector<sem::SamplerTexturePair> GetSamplerTextureUses(const std::string& entry_point);
utils::Vector<sem::SamplerTexturePair, 4> GetSamplerTextureUses(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @param placeholder the sampler binding point to use for texture-only
@@ -153,7 +153,8 @@ class Inspector {
private:
const Program* program_;
diag::List diagnostics_;
std::unique_ptr<std::unordered_map<std::string, utils::UniqueVector<sem::SamplerTexturePair>>>
std::unique_ptr<
std::unordered_map<std::string, utils::UniqueVector<sem::SamplerTexturePair, 4>>>
sampler_targets_;
/// @param name name of the entry point to find

View File

@@ -2971,7 +2971,7 @@ fn main() {
auto result = inspector.GetSamplerTextureUses("main");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(0u, result.size());
ASSERT_EQ(0u, result.Length());
}
TEST_F(InspectorGetSamplerTextureUsesTest, Simple) {
@@ -2989,7 +2989,7 @@ fn main(@location(0) fragUV: vec2<f32>,
auto result = inspector.GetSamplerTextureUses("main");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
ASSERT_EQ(1u, result.Length());
EXPECT_EQ(0u, result[0].sampler_binding_point.group);
EXPECT_EQ(1u, result[0].sampler_binding_point.binding);
@@ -3053,7 +3053,7 @@ fn main(@location(0) fragUV: vec2<f32>,
auto result = inspector.GetSamplerTextureUses("main");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
ASSERT_EQ(1u, result.Length());
EXPECT_EQ(0u, result[0].sampler_binding_point.group);
EXPECT_EQ(1u, result[0].sampler_binding_point.binding);
@@ -3080,7 +3080,7 @@ fn main(@location(0) fragUV: vec2<f32>,
auto result = inspector.GetSamplerTextureUses("main");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
ASSERT_EQ(1u, result.Length());
EXPECT_EQ(0u, result[0].sampler_binding_point.group);
EXPECT_EQ(1u, result[0].sampler_binding_point.binding);
@@ -3107,7 +3107,7 @@ fn main(@location(0) fragUV: vec2<f32>,
auto result = inspector.GetSamplerTextureUses("main");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
ASSERT_EQ(1u, result.Length());
EXPECT_EQ(0u, result[0].sampler_binding_point.group);
EXPECT_EQ(1u, result[0].sampler_binding_point.binding);
@@ -3134,7 +3134,7 @@ fn main(@location(0) fragUV: vec2<f32>,
auto result = inspector.GetSamplerTextureUses("main");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
ASSERT_EQ(1u, result.Length());
EXPECT_EQ(0u, result[0].sampler_binding_point.group);
EXPECT_EQ(1u, result[0].sampler_binding_point.binding);
@@ -3188,7 +3188,7 @@ fn direct(@location(0) fragUV: vec2<f32>,
auto result = inspector.GetSamplerTextureUses("via_call");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
ASSERT_EQ(1u, result.Length());
EXPECT_EQ(0u, result[0].sampler_binding_point.group);
EXPECT_EQ(1u, result[0].sampler_binding_point.binding);
@@ -3200,7 +3200,7 @@ fn direct(@location(0) fragUV: vec2<f32>,
auto result = inspector.GetSamplerTextureUses("via_ptr");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
ASSERT_EQ(1u, result.Length());
EXPECT_EQ(0u, result[0].sampler_binding_point.group);
EXPECT_EQ(1u, result[0].sampler_binding_point.binding);
@@ -3212,7 +3212,7 @@ fn direct(@location(0) fragUV: vec2<f32>,
auto result = inspector.GetSamplerTextureUses("direct");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
ASSERT_EQ(1u, result.Length());
EXPECT_EQ(0u, result[0].sampler_binding_point.group);
EXPECT_EQ(1u, result[0].sampler_binding_point.binding);