Skip to content

Commit

Permalink
Add fallback buckets config.
Browse files Browse the repository at this point in the history
If we don't match to any engine or application, use bucket variants
which depend on whatever we configure. Useful to ensure we get different
buckets based on AppName/EngineName.
  • Loading branch information
HansKristian-Work committed May 26, 2021
1 parent d2e4776 commit 92c565d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
29 changes: 22 additions & 7 deletions fossilize_application_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct ApplicationInfoFilter::Impl
std::unordered_set<std::string> blacklisted_engine_names;
std::unordered_map<std::string, AppInfo> application_infos;
std::unordered_map<std::string, AppInfo> engine_infos;
std::vector<VariantDependency> default_variant_dependencies;

bool parsing_done = false;
bool parsing_success = false;
Expand Down Expand Up @@ -177,7 +178,7 @@ bool ApplicationInfoFilter::Impl::needs_buckets(const VkApplicationInfo *info)
return true;
}

return false;
return !default_variant_dependencies.empty();
}

template <typename T>
Expand Down Expand Up @@ -302,25 +303,36 @@ Hash ApplicationInfoFilter::Impl::get_bucket_hash(const VkPhysicalDeviceProperti
return 0;

Hasher h;
bool use_default_variant = true;

h.u32(0);
if (info->pApplicationName)
{
auto itr = application_infos.find(info->pApplicationName);
if (itr != application_infos.end())
{
use_default_variant = false;
for (auto &dep : itr->second.variant_dependencies)
hash_variant(h, dep, props, info, features2);
}
}

h.u32(0);
if (info->pEngineName)
{
auto itr = engine_infos.find(info->pEngineName);
if (itr != engine_infos.end())
{
use_default_variant = false;
for (auto &dep : itr->second.variant_dependencies)
hash_variant(h, dep, props, info, features2);
}
}

if (use_default_variant)
for (auto &dep : default_variant_dependencies)
hash_variant(h, dep, props, info, features2);

return h.get();
}

Expand Down Expand Up @@ -530,9 +542,8 @@ static bool add_blacklists(std::unordered_set<std::string> &output, const Value
return true;
}

static bool parse_blacklist_environments(const Value &value, std::vector<EnvInfo> &infos)
static bool parse_blacklist_environments(const Value &envs, std::vector<EnvInfo> &infos)
{
auto &envs = value["blacklistedEnvironments"];
if (!envs.IsObject())
{
LOGE("blacklistedEnvironments must be an object.\n");
Expand Down Expand Up @@ -566,9 +577,8 @@ static bool parse_blacklist_environments(const Value &value, std::vector<EnvInfo
return true;
}

static bool parse_bucket_variant_dependencies(const Value &value, std::vector<VariantDependency> &variant_deps)
static bool parse_bucket_variant_dependencies(const Value &deps, std::vector<VariantDependency> &variant_deps)
{
auto &deps = value["bucketVariantDependencies"];
if (!deps.IsArray())
{
LOGE("bucketVariantDependencies must be an array.\n");
Expand Down Expand Up @@ -619,10 +629,10 @@ static bool add_application_filters(std::unordered_map<std::string, AppInfo> &ou
info.minimum_engine_version = default_get_member_uint(value, "minimumEngineVersion");
info.minimum_application_version = default_get_member_uint(value, "minimumApplicationVersion");
if (value.HasMember("blacklistedEnvironments"))
if (!parse_blacklist_environments(value, info.env_infos))
if (!parse_blacklist_environments(value["blacklistedEnvironments"], info.env_infos))
return false;
if (value.HasMember("bucketVariantDependencies"))
if (!parse_bucket_variant_dependencies(value, info.variant_dependencies))
if (!parse_bucket_variant_dependencies(value["bucketVariantDependencies"], info.variant_dependencies))
return false;
output[itr->name.GetString()] = std::move(info);
}
Expand Down Expand Up @@ -666,6 +676,11 @@ bool ApplicationInfoFilter::Impl::parse(const std::string &path)
if (!add_application_filters(engine_infos, filters))
return false;

auto *default_variants = maybe_get_member(doc, "defaultBucketVariantDependencies");
if (default_variants)
if (!parse_bucket_variant_dependencies(*default_variants, default_variant_dependencies))
return false;

return true;
}

Expand Down
16 changes: 14 additions & 2 deletions test/application_info_filter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ R"delim(
"TEST" : { "nonnull" : true }
}
}
}
},
"defaultBucketVariantDependencies" : [
"ApplicationName",
"EngineName"
]
}
)delim";

Expand Down Expand Up @@ -254,7 +258,7 @@ R"delim(
// Test bucket variant filter.
appinfo.pEngineName = nullptr;
appinfo.pApplicationName = "test1";
if (filter.needs_buckets(&appinfo))
if (!filter.needs_buckets(&appinfo))
return EXIT_FAILURE;

appinfo.pEngineName = "test1";
Expand Down Expand Up @@ -317,6 +321,14 @@ R"delim(
auto hash7 = filter.get_bucket_hash(&props2, &appinfo, &features2);
if (hash7 == hash6)
return EXIT_FAILURE;

// Check that the default variant hash is used.
appinfo.pApplicationName = "blah";
appinfo.pEngineName = "blah2";
auto hash8 = filter.get_bucket_hash(&props2, &appinfo, &features2);
auto hash9 = filter.get_bucket_hash(&props2, &appinfo, nullptr);
if (hash8 != hash9)
return EXIT_FAILURE;
}

remove(".__test_appinfo.json");
Expand Down

0 comments on commit 92c565d

Please sign in to comment.