mirror of
https://gitee.com/openharmony/third_party_vulkan-loader
synced 2024-11-23 15:20:52 +00:00
Refactor FrameworkEnvironment API a bit
Redo some of API's for adding layers and ICD's to the test framework.
This commit is contained in:
parent
859fb722c2
commit
5b84b6d09a
@ -135,7 +135,6 @@ There are many utilities that the test framework and tests have access to. These
|
||||
* `FRAMEWORK_EXPORT` - macro used for exporting shared library funtions
|
||||
* Environment Variable helpers: `get_env_var`, `set_env_var`, `remove_env_var`
|
||||
* Windows API error handling helpers
|
||||
* DebugMode enum - defines which actions to take when debugging the test suite.
|
||||
* filesystem abstractions:
|
||||
* `fs::path` - wrapper around std::string that has a similar API to C++17's `filesystem::path` library
|
||||
* `create_folder`/`delete_folder`
|
||||
|
@ -114,7 +114,7 @@ struct D3DKMT_Adapter {
|
||||
// defined in the .cpp wont be found by the rest of the application
|
||||
struct PlatformShim {
|
||||
// Test Framework interface
|
||||
void reset(DebugMode debug_mode = DebugMode::none);
|
||||
void reset();
|
||||
|
||||
void redirect_all_paths(fs::path const& path);
|
||||
void redirect_category(fs::path const& new_path, ManifestCategory category);
|
||||
|
@ -86,7 +86,7 @@ std::string category_path_name(ManifestCategory category) {
|
||||
return "Drivers";
|
||||
}
|
||||
|
||||
void PlatformShim::reset(DebugMode debug_mode) {
|
||||
void PlatformShim::reset() {
|
||||
hkey_current_user_explicit_layers.clear();
|
||||
hkey_current_user_implicit_layers.clear();
|
||||
hkey_local_machine_explicit_layers.clear();
|
||||
@ -144,7 +144,7 @@ std::string category_path_name(ManifestCategory category) {
|
||||
return "icd.d";
|
||||
}
|
||||
|
||||
void PlatformShim::reset(DebugMode debug_mode) { redirection_map.clear(); }
|
||||
void PlatformShim::reset() { redirection_map.clear(); }
|
||||
|
||||
void PlatformShim::redirect_path(fs::path const& path, fs::path const& new_path) { redirection_map[path.str()] = new_path; }
|
||||
void PlatformShim::remove_redirect(fs::path const& path) { redirection_map.erase(path.str()); }
|
||||
|
@ -136,7 +136,7 @@ void FillDebugUtilsCreateDetails(InstanceCreateInfo& create_info, DebugUtilsWrap
|
||||
create_info.instance_info.pNext = wrapper.get();
|
||||
}
|
||||
|
||||
PlatformShimWrapper::PlatformShimWrapper(DebugMode debug_mode) noexcept : debug_mode(debug_mode) {
|
||||
PlatformShimWrapper::PlatformShimWrapper() noexcept {
|
||||
#if defined(WIN32) || defined(__APPLE__)
|
||||
shim_library = LibraryWrapper(SHIM_LIBRARY_NAME);
|
||||
PFN_get_platform_shim get_platform_shim_func = shim_library.get_symbol(GET_PLATFORM_SHIM_STR);
|
||||
@ -145,12 +145,12 @@ PlatformShimWrapper::PlatformShimWrapper(DebugMode debug_mode) noexcept : debug_
|
||||
#elif defined(__linux__) || defined(__FreeBSD__)
|
||||
platform_shim = get_platform_shim();
|
||||
#endif
|
||||
platform_shim->reset(debug_mode);
|
||||
platform_shim->reset();
|
||||
|
||||
// leave it permanently on at full blast
|
||||
set_env_var("VK_LOADER_DEBUG", "all");
|
||||
}
|
||||
PlatformShimWrapper::~PlatformShimWrapper() noexcept { platform_shim->reset(debug_mode); }
|
||||
PlatformShimWrapper::~PlatformShimWrapper() noexcept { platform_shim->reset(); }
|
||||
|
||||
TestICDHandle::TestICDHandle() noexcept {}
|
||||
TestICDHandle::TestICDHandle(fs::path const& icd_path) noexcept : icd_library(icd_path) {
|
||||
@ -184,35 +184,35 @@ TestLayer& TestLayerHandle::reset_layer() noexcept {
|
||||
fs::path TestLayerHandle::get_layer_full_path() noexcept { return layer_library.lib_path; }
|
||||
fs::path TestLayerHandle::get_layer_manifest_path() noexcept { return manifest_path; }
|
||||
|
||||
FrameworkEnvironment::FrameworkEnvironment(DebugMode debug_mode, bool override_icds, bool override_explicit_layers) noexcept
|
||||
: platform_shim(debug_mode),
|
||||
null_folder(FRAMEWORK_BUILD_DIRECTORY, "null_dir", debug_mode),
|
||||
icd_folder(FRAMEWORK_BUILD_DIRECTORY, "icd_manifests", debug_mode),
|
||||
explicit_layer_folder(FRAMEWORK_BUILD_DIRECTORY, "explicit_layer_manifests", debug_mode),
|
||||
implicit_layer_folder(FRAMEWORK_BUILD_DIRECTORY, "implicit_layer_manifests", debug_mode),
|
||||
FrameworkEnvironment::FrameworkEnvironment() noexcept
|
||||
: platform_shim(),
|
||||
null_folder(FRAMEWORK_BUILD_DIRECTORY, "null_dir"),
|
||||
icd_folder(FRAMEWORK_BUILD_DIRECTORY, "icd_manifests"),
|
||||
icd_env_vars_folder(FRAMEWORK_BUILD_DIRECTORY, "icd_env_vars_manifests"),
|
||||
explicit_layer_folder(FRAMEWORK_BUILD_DIRECTORY, "explicit_layer_manifests"),
|
||||
explicit_env_var_layer_folder(FRAMEWORK_BUILD_DIRECTORY, "explicit_env_var_layer_folder"),
|
||||
explicit_add_env_var_layer_folder(FRAMEWORK_BUILD_DIRECTORY, "explicit_add_env_var_layer_folder"),
|
||||
implicit_layer_folder(FRAMEWORK_BUILD_DIRECTORY, "implicit_layer_manifests"),
|
||||
override_layer_folder(FRAMEWORK_BUILD_DIRECTORY, "override_layer_manifests"),
|
||||
vulkan_functions() {
|
||||
platform_shim->redirect_all_paths(null_folder.location());
|
||||
|
||||
if (override_icds) {
|
||||
platform_shim->set_path(ManifestCategory::icd, null_folder.location());
|
||||
} else {
|
||||
platform_shim->set_path(ManifestCategory::icd, icd_folder.location());
|
||||
}
|
||||
if (override_explicit_layers) {
|
||||
platform_shim->set_path(ManifestCategory::explicit_layer, null_folder.location());
|
||||
} else {
|
||||
platform_shim->set_path(ManifestCategory::explicit_layer, explicit_layer_folder.location());
|
||||
}
|
||||
platform_shim->set_path(ManifestCategory::icd, icd_folder.location());
|
||||
platform_shim->set_path(ManifestCategory::explicit_layer, explicit_layer_folder.location());
|
||||
platform_shim->set_path(ManifestCategory::implicit_layer, implicit_layer_folder.location());
|
||||
}
|
||||
|
||||
void FrameworkEnvironment::add_icd(TestICDDetails icd_details) noexcept {
|
||||
size_t cur_icd_index = icds.size();
|
||||
fs::FolderManager* folder = &icd_folder;
|
||||
if (icd_details.discovery_type == ManifestDiscoveryType::env_var ||
|
||||
icd_details.discovery_type == ManifestDiscoveryType::add_env_var) {
|
||||
folder = &icd_env_vars_folder;
|
||||
}
|
||||
if (!icd_details.is_fake) {
|
||||
fs::path new_driver_name = fs::path(icd_details.icd_manifest.lib_path).stem() + "_" + std::to_string(cur_icd_index) +
|
||||
fs::path(icd_details.icd_manifest.lib_path).extension();
|
||||
|
||||
auto new_driver_location = icd_folder.copy_file(icd_details.icd_manifest.lib_path, new_driver_name.str());
|
||||
auto new_driver_location = folder->copy_file(icd_details.icd_manifest.lib_path, new_driver_name.str());
|
||||
|
||||
icds.push_back(TestICDHandle(new_driver_location));
|
||||
icds.back().reset_icd();
|
||||
@ -220,61 +220,87 @@ void FrameworkEnvironment::add_icd(TestICDDetails icd_details) noexcept {
|
||||
}
|
||||
std::string full_json_name = icd_details.json_name + "_" + std::to_string(cur_icd_index) + ".json";
|
||||
|
||||
auto driver_loc = icd_folder.write_manifest(full_json_name, icd_details.icd_manifest.get_manifest_str());
|
||||
icds.back().manifest_path = driver_loc;
|
||||
|
||||
if (icd_details.use_env_var_icd_filenames) {
|
||||
if (!env_var_vk_icd_filenames.empty()) {
|
||||
env_var_vk_icd_filenames += OS_ENV_VAR_LIST_SEPARATOR;
|
||||
}
|
||||
env_var_vk_icd_filenames += (icd_folder.location() / full_json_name).str();
|
||||
set_env_var("VK_DRIVER_FILES", env_var_vk_icd_filenames);
|
||||
} else if (icd_details.use_add_env_var_icd_filenames) {
|
||||
if (!add_env_var_vk_icd_filenames.empty()) {
|
||||
add_env_var_vk_icd_filenames += OS_ENV_VAR_LIST_SEPARATOR;
|
||||
}
|
||||
add_env_var_vk_icd_filenames += (icd_folder.location() / full_json_name).str();
|
||||
set_env_var("VK_ADD_DRIVER_FILES", add_env_var_vk_icd_filenames);
|
||||
} else if (icd_details.add_manifest_to_default_driver_location) {
|
||||
platform_shim->add_manifest(ManifestCategory::icd, driver_loc);
|
||||
icds.back().manifest_path = folder->write_manifest(full_json_name, icd_details.icd_manifest.get_manifest_str());
|
||||
switch (icd_details.discovery_type) {
|
||||
default:
|
||||
case (ManifestDiscoveryType::generic):
|
||||
platform_shim->add_manifest(ManifestCategory::icd, icds.back().manifest_path);
|
||||
break;
|
||||
case (ManifestDiscoveryType::env_var):
|
||||
if (!env_var_vk_icd_filenames.empty()) {
|
||||
env_var_vk_icd_filenames += OS_ENV_VAR_LIST_SEPARATOR;
|
||||
}
|
||||
env_var_vk_icd_filenames += (folder->location() / full_json_name).str();
|
||||
set_env_var("VK_DRIVER_FILES", env_var_vk_icd_filenames);
|
||||
break;
|
||||
case (ManifestDiscoveryType::add_env_var):
|
||||
if (!add_env_var_vk_icd_filenames.empty()) {
|
||||
add_env_var_vk_icd_filenames += OS_ENV_VAR_LIST_SEPARATOR;
|
||||
}
|
||||
add_env_var_vk_icd_filenames += (folder->location() / full_json_name).str();
|
||||
set_env_var("VK_ADD_DRIVER_FILES", add_env_var_vk_icd_filenames);
|
||||
break;
|
||||
case (ManifestDiscoveryType::none):
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FrameworkEnvironment::add_implicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
|
||||
add_layer_impl(TestLayerDetails{layer_manifest, json_name}, implicit_layer_folder, ManifestCategory::implicit_layer);
|
||||
add_layer_impl(TestLayerDetails{layer_manifest, json_name}, ManifestCategory::implicit_layer);
|
||||
}
|
||||
void FrameworkEnvironment::add_explicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
|
||||
add_layer_impl(TestLayerDetails{layer_manifest, json_name}, explicit_layer_folder, ManifestCategory::explicit_layer);
|
||||
add_layer_impl(TestLayerDetails{layer_manifest, json_name}, ManifestCategory::explicit_layer);
|
||||
}
|
||||
void FrameworkEnvironment::add_fake_implicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
|
||||
TestLayerDetails fake_details{layer_manifest, json_name};
|
||||
fake_details.is_fake = true;
|
||||
add_layer_impl(fake_details, implicit_layer_folder, ManifestCategory::implicit_layer);
|
||||
add_layer_impl(TestLayerDetails{layer_manifest, json_name}.set_is_fake(true), ManifestCategory::implicit_layer);
|
||||
}
|
||||
void FrameworkEnvironment::add_fake_explicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
|
||||
TestLayerDetails fake_details{layer_manifest, json_name};
|
||||
fake_details.is_fake = true;
|
||||
add_layer_impl(fake_details, explicit_layer_folder, ManifestCategory::explicit_layer);
|
||||
add_layer_impl(TestLayerDetails{layer_manifest, json_name}.set_is_fake(true), ManifestCategory::explicit_layer);
|
||||
}
|
||||
void FrameworkEnvironment::add_implicit_layer(TestLayerDetails layer_details) noexcept {
|
||||
add_layer_impl(layer_details,
|
||||
layer_details.destination_folder == nullptr ? implicit_layer_folder : *layer_details.destination_folder,
|
||||
ManifestCategory::implicit_layer);
|
||||
add_layer_impl(layer_details, ManifestCategory::implicit_layer);
|
||||
}
|
||||
void FrameworkEnvironment::add_explicit_layer(TestLayerDetails layer_details) noexcept {
|
||||
add_layer_impl(layer_details,
|
||||
layer_details.destination_folder == nullptr ? explicit_layer_folder : *layer_details.destination_folder,
|
||||
ManifestCategory::explicit_layer);
|
||||
add_layer_impl(layer_details, ManifestCategory::explicit_layer);
|
||||
}
|
||||
|
||||
void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, fs::FolderManager& folder_manager,
|
||||
ManifestCategory category) {
|
||||
void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, ManifestCategory category) {
|
||||
fs::FolderManager* fs_ptr = &explicit_layer_folder;
|
||||
switch (layer_details.discovery_type) {
|
||||
default:
|
||||
case (ManifestDiscoveryType::generic):
|
||||
if (category == ManifestCategory::implicit_layer) fs_ptr = &implicit_layer_folder;
|
||||
break;
|
||||
case (ManifestDiscoveryType::env_var):
|
||||
fs_ptr = &explicit_env_var_layer_folder;
|
||||
if (!env_var_vk_layer_paths.empty()) {
|
||||
env_var_vk_layer_paths += OS_ENV_VAR_LIST_SEPARATOR;
|
||||
}
|
||||
env_var_vk_layer_paths += explicit_env_var_layer_folder.location().str();
|
||||
set_env_var("VK_LAYER_PATH", env_var_vk_layer_paths);
|
||||
break;
|
||||
case (ManifestDiscoveryType::add_env_var):
|
||||
fs_ptr = &explicit_add_env_var_layer_folder;
|
||||
if (!add_env_var_vk_layer_paths.empty()) {
|
||||
add_env_var_vk_layer_paths += OS_ENV_VAR_LIST_SEPARATOR;
|
||||
}
|
||||
add_env_var_vk_layer_paths += explicit_add_env_var_layer_folder.location().str();
|
||||
set_env_var("VK_ADD_LAYER_PATH", add_env_var_vk_layer_paths);
|
||||
break;
|
||||
case (ManifestDiscoveryType::override_folder):
|
||||
fs_ptr = &override_layer_folder;
|
||||
break;
|
||||
case (ManifestDiscoveryType::none):
|
||||
break;
|
||||
}
|
||||
auto& folder = *fs_ptr;
|
||||
size_t new_layers_start = layers.size();
|
||||
for (auto& layer : layer_details.layer_manifest.layers) {
|
||||
size_t cur_layer_index = layers.size();
|
||||
if (!layer.lib_path.str().empty()) {
|
||||
std::string new_layer_name = layer.name + "_" + std::to_string(cur_layer_index) + "_" + layer.lib_path.filename().str();
|
||||
|
||||
auto new_layer_location = folder_manager.copy_file(layer.lib_path, new_layer_name);
|
||||
auto new_layer_location = folder.copy_file(layer.lib_path, new_layer_name);
|
||||
|
||||
// Don't load the layer binary if using any of the wrap objects layers, since it doesn't export the same interface
|
||||
// functions
|
||||
@ -286,8 +312,8 @@ void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, fs::Fo
|
||||
layer.lib_path = new_layer_location;
|
||||
}
|
||||
}
|
||||
if (layer_details.add_to_regular_search_paths) {
|
||||
auto layer_loc = folder_manager.write_manifest(layer_details.json_name, layer_details.layer_manifest.get_manifest_str());
|
||||
if (layer_details.discovery_type != ManifestDiscoveryType::none) {
|
||||
auto layer_loc = folder.write_manifest(layer_details.json_name, layer_details.layer_manifest.get_manifest_str());
|
||||
platform_shim->add_manifest(category, layer_loc);
|
||||
for (size_t i = new_layers_start; i < layers.size(); i++) {
|
||||
layers.at(i).manifest_path = layer_loc;
|
||||
|
@ -259,7 +259,7 @@ void FillDebugUtilsCreateDetails(InstanceCreateInfo& create_info, DebugUtilsLogg
|
||||
void FillDebugUtilsCreateDetails(InstanceCreateInfo& create_info, DebugUtilsWrapper& wrapper);
|
||||
|
||||
struct PlatformShimWrapper {
|
||||
PlatformShimWrapper(DebugMode debug_mode = DebugMode::none) noexcept;
|
||||
PlatformShimWrapper() noexcept;
|
||||
~PlatformShimWrapper() noexcept;
|
||||
PlatformShimWrapper(PlatformShimWrapper const&) = delete;
|
||||
PlatformShimWrapper& operator=(PlatformShimWrapper const&) = delete;
|
||||
@ -269,7 +269,6 @@ struct PlatformShimWrapper {
|
||||
|
||||
LibraryWrapper shim_library;
|
||||
PlatformShim* platform_shim;
|
||||
DebugMode debug_mode = DebugMode::none;
|
||||
};
|
||||
|
||||
struct TestICDHandle {
|
||||
@ -301,6 +300,14 @@ struct TestLayerHandle {
|
||||
fs::path manifest_path;
|
||||
};
|
||||
|
||||
enum class ManifestDiscoveryType {
|
||||
generic, // put the manifest in the regular locations
|
||||
none, // don't add to regular locations - eg D3DKMT
|
||||
env_var, // use the corresponding env-var for it
|
||||
add_env_var, // use the corresponding add-env-var for it
|
||||
override_folder, // add to a special folder for the override layer to use
|
||||
};
|
||||
|
||||
struct TestICDDetails {
|
||||
TestICDDetails(ManifestICD icd_manifest) noexcept : icd_manifest(icd_manifest) {}
|
||||
TestICDDetails(fs::path icd_path, uint32_t api_version = VK_API_VERSION_1_0) noexcept {
|
||||
@ -308,9 +315,7 @@ struct TestICDDetails {
|
||||
}
|
||||
BUILDER_VALUE(TestICDDetails, ManifestICD, icd_manifest, {});
|
||||
BUILDER_VALUE(TestICDDetails, std::string, json_name, "test_icd");
|
||||
BUILDER_VALUE(TestICDDetails, bool, use_env_var_icd_filenames, false);
|
||||
BUILDER_VALUE(TestICDDetails, bool, use_add_env_var_icd_filenames, false);
|
||||
BUILDER_VALUE(TestICDDetails, bool, add_manifest_to_default_driver_location, true);
|
||||
BUILDER_VALUE(TestICDDetails, ManifestDiscoveryType, discovery_type, ManifestDiscoveryType::generic);
|
||||
BUILDER_VALUE(TestICDDetails, bool, is_fake, false);
|
||||
};
|
||||
|
||||
@ -319,14 +324,12 @@ struct TestLayerDetails {
|
||||
: layer_manifest(layer_manifest), json_name(json_name) {}
|
||||
BUILDER_VALUE(TestLayerDetails, ManifestLayer, layer_manifest, {});
|
||||
BUILDER_VALUE(TestLayerDetails, std::string, json_name, "test_layer");
|
||||
BUILDER_VALUE(TestLayerDetails, fs::FolderManager*, destination_folder, nullptr);
|
||||
BUILDER_VALUE(TestLayerDetails, bool, add_to_regular_search_paths, true);
|
||||
BUILDER_VALUE(TestLayerDetails, ManifestDiscoveryType, discovery_type, ManifestDiscoveryType::generic);
|
||||
BUILDER_VALUE(TestLayerDetails, bool, is_fake, false);
|
||||
};
|
||||
|
||||
struct FrameworkEnvironment {
|
||||
FrameworkEnvironment(DebugMode debug_mode = DebugMode::none, bool override_icds = false,
|
||||
bool override_explicit_layers = false) noexcept;
|
||||
FrameworkEnvironment() noexcept;
|
||||
|
||||
void add_icd(TestICDDetails icd_details) noexcept;
|
||||
void add_implicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept;
|
||||
@ -349,8 +352,13 @@ struct FrameworkEnvironment {
|
||||
PlatformShimWrapper platform_shim;
|
||||
fs::FolderManager null_folder;
|
||||
fs::FolderManager icd_folder;
|
||||
fs::FolderManager icd_env_vars_folder;
|
||||
fs::FolderManager explicit_layer_folder;
|
||||
fs::FolderManager explicit_env_var_layer_folder;
|
||||
fs::FolderManager explicit_add_env_var_layer_folder;
|
||||
fs::FolderManager implicit_layer_folder;
|
||||
fs::FolderManager override_layer_folder;
|
||||
|
||||
DebugUtilsLogger debug_log;
|
||||
VulkanFunctions vulkan_functions;
|
||||
|
||||
@ -360,8 +368,11 @@ struct FrameworkEnvironment {
|
||||
std::string env_var_vk_icd_filenames;
|
||||
std::string add_env_var_vk_icd_filenames;
|
||||
|
||||
std::string env_var_vk_layer_paths;
|
||||
std::string add_env_var_vk_layer_paths;
|
||||
|
||||
private:
|
||||
void add_layer_impl(TestLayerDetails layer_details, fs::FolderManager& folder_manager, ManifestCategory category);
|
||||
void add_layer_impl(TestLayerDetails layer_details, ManifestCategory category);
|
||||
};
|
||||
|
||||
// The following helpers setup an icd with the required extensions and setting to use with WSI
|
||||
|
@ -416,7 +416,7 @@ int delete_folder(path const& folder) {
|
||||
#endif
|
||||
}
|
||||
|
||||
FolderManager::FolderManager(path root_path, std::string name, DebugMode debug) : debug(debug), folder(root_path / name) {
|
||||
FolderManager::FolderManager(path root_path, std::string name) : folder(root_path / name) {
|
||||
delete_folder_contents(folder);
|
||||
create_folder(folder);
|
||||
}
|
||||
@ -427,17 +427,9 @@ FolderManager::~FolderManager() {
|
||||
// removing those. Since this is in an OOM situation, it is a low priority to fix. It does have the effect that Windows will
|
||||
// be unable to delete the binaries that were leaked.
|
||||
for (auto& file : list_of_files_to_delete) {
|
||||
if (debug >= DebugMode::log) std::cout << "Removing manifest " << file << " at " << (folder / file).str() << "\n";
|
||||
if (debug != DebugMode::no_delete) {
|
||||
remove(file);
|
||||
}
|
||||
}
|
||||
if (debug != DebugMode::no_delete) {
|
||||
delete_folder(folder);
|
||||
}
|
||||
if (debug >= DebugMode::log) {
|
||||
std::cout << "Deleting folder " << folder.str() << "\n";
|
||||
remove(file);
|
||||
}
|
||||
delete_folder(folder);
|
||||
}
|
||||
path FolderManager::write_manifest(std::string const& name, std::string const& contents) {
|
||||
path out_path = folder / name;
|
||||
@ -445,7 +437,6 @@ path FolderManager::write_manifest(std::string const& name, std::string const& c
|
||||
if (found != files.end()) {
|
||||
std::cout << "Overwriting manifest " << name << ". Was this intended?\n";
|
||||
} else {
|
||||
if (debug >= DebugMode::log) std::cout << "Creating manifest " << name << " at " << out_path.str() << "\n";
|
||||
files.emplace_back(name);
|
||||
}
|
||||
auto file = std::ofstream(out_path.str(), std::ios_base::trunc | std::ios_base::out);
|
||||
@ -461,17 +452,15 @@ void FolderManager::remove(std::string const& name) {
|
||||
path out_path = folder / name;
|
||||
auto found = std::find(files.begin(), files.end(), name);
|
||||
if (found != files.end()) {
|
||||
if (debug >= DebugMode::log) std::cout << "Removing file " << name << " at " << out_path.str() << "\n";
|
||||
if (debug != DebugMode::no_delete) {
|
||||
int rc = std::remove(out_path.c_str());
|
||||
if (rc != 0 && debug >= DebugMode::log) {
|
||||
std::cerr << "Failed to remove file " << name << " at " << out_path.str() << "\n";
|
||||
}
|
||||
|
||||
files.erase(found);
|
||||
int rc = std::remove(out_path.c_str());
|
||||
if (rc != 0) {
|
||||
std::cerr << "Failed to remove file " << name << " at " << out_path.str() << "\n";
|
||||
}
|
||||
|
||||
files.erase(found);
|
||||
|
||||
} else {
|
||||
if (debug >= DebugMode::log) std::cout << "Couldn't remove file " << name << " at " << out_path.str() << ".\n";
|
||||
std::cout << "Couldn't remove file " << name << " at " << out_path.str() << ".\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -480,11 +469,10 @@ path FolderManager::copy_file(path const& file, std::string const& new_name) {
|
||||
auto new_filepath = folder / new_name;
|
||||
auto found = std::find(files.begin(), files.end(), new_name);
|
||||
if (found != files.end()) {
|
||||
if (debug >= DebugMode::log) std::cout << "File location already contains" << new_name << ". Is this a bug?\n";
|
||||
std::cout << "File location already contains" << new_name << ". Is this a bug?\n";
|
||||
} else if (file.str() == new_filepath.str()) {
|
||||
if (debug >= DebugMode::log) std::cout << "Trying to copy " << new_name << " into itself. Is this a bug?\n";
|
||||
std::cout << "Trying to copy " << new_name << " into itself. Is this a bug?\n";
|
||||
} else {
|
||||
if (debug >= DebugMode::log) std::cout << "Copying file" << file.str() << " to " << new_filepath.str() << "\n";
|
||||
files.emplace_back(new_name);
|
||||
}
|
||||
std::ifstream src(file.str(), std::ios::binary);
|
||||
|
@ -124,13 +124,6 @@ const char* win_api_error_str(LSTATUS status);
|
||||
void print_error_message(LSTATUS status, const char* function_name, std::string optional_message = "");
|
||||
#endif
|
||||
|
||||
enum class DebugMode {
|
||||
none,
|
||||
log, // log all folder and file creation & deletion
|
||||
no_delete // Will not delete create folders & files, but will report 'deleting them' to show when something *should* of been
|
||||
// deleted
|
||||
};
|
||||
|
||||
struct ManifestICD; // forward declaration for FolderManager::write
|
||||
struct ManifestLayer; // forward declaration for FolderManager::write
|
||||
|
||||
@ -211,7 +204,7 @@ int delete_folder(path const& folder);
|
||||
|
||||
class FolderManager {
|
||||
public:
|
||||
explicit FolderManager(path root_path, std::string name, DebugMode debug = DebugMode::none);
|
||||
explicit FolderManager(path root_path, std::string name);
|
||||
~FolderManager();
|
||||
FolderManager(FolderManager const&) = delete;
|
||||
FolderManager& operator=(FolderManager const&) = delete;
|
||||
@ -228,7 +221,6 @@ class FolderManager {
|
||||
path location() const { return folder; }
|
||||
|
||||
private:
|
||||
DebugMode debug;
|
||||
path folder;
|
||||
std::vector<std::string> files;
|
||||
};
|
||||
|
@ -650,7 +650,7 @@ TEST(Allocation, EnumeratePhysicalDevicesIntentionalAllocFail) {
|
||||
// leak memory if one of the out-of-memory conditions trigger.
|
||||
TEST(Allocation, CreateInstanceDeviceWithDXGIDriverIntentionalAllocFail) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_6).set_add_manifest_to_default_driver_location(false));
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_6).set_discovery_type(ManifestDiscoveryType::none));
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
|
||||
|
||||
for (uint32_t i = 0; i < 2; i++) {
|
||||
|
@ -49,7 +49,7 @@ class EnvVarICDOverrideSetup : public ::testing::Test {
|
||||
// must export vkGetInstanceProcAddr, vkCreateInstance, vkEnumerateInstanceExtensionProperties
|
||||
TEST(EnvVarICDOverrideSetup, version_0_none) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_use_env_var_icd_filenames(true));
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var));
|
||||
|
||||
InstWrapper inst{env.vulkan_functions};
|
||||
inst.CheckCreate();
|
||||
@ -61,7 +61,7 @@ TEST(EnvVarICDOverrideSetup, version_0_none) {
|
||||
// the loader calls vk_icdGetInstanceProcAddr first
|
||||
TEST(EnvVarICDOverrideSetup, version_1_icd_gipa) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_ICD_GIPA).set_use_env_var_icd_filenames(true));
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_ICD_GIPA).set_discovery_type(ManifestDiscoveryType::env_var));
|
||||
|
||||
InstWrapper inst{env.vulkan_functions};
|
||||
inst.CheckCreate();
|
||||
@ -72,7 +72,8 @@ TEST(EnvVarICDOverrideSetup, version_1_icd_gipa) {
|
||||
// support vk_icdNegotiateLoaderICDInterfaceVersion but not vk_icdGetInstanceProcAddr
|
||||
TEST(EnvVarICDOverrideSetup, version_negotiate_interface_version_death_test) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NEGOTIATE_INTERFACE_VERSION).set_use_env_var_icd_filenames(true));
|
||||
env.add_icd(
|
||||
TestICDDetails(TEST_ICD_PATH_EXPORT_NEGOTIATE_INTERFACE_VERSION).set_discovery_type(ManifestDiscoveryType::env_var));
|
||||
|
||||
InstWrapper inst{env.vulkan_functions};
|
||||
inst.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
|
||||
@ -81,7 +82,7 @@ TEST(EnvVarICDOverrideSetup, version_negotiate_interface_version_death_test) {
|
||||
// export vk_icdNegotiateLoaderICDInterfaceVersion and vk_icdGetInstanceProcAddr
|
||||
TEST(EnvVarICDOverrideSetup, version_2_negotiate_interface_version_and_icd_gipa) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2).set_use_env_var_icd_filenames(true));
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2).set_discovery_type(ManifestDiscoveryType::env_var));
|
||||
|
||||
InstWrapper inst{env.vulkan_functions};
|
||||
inst.CheckCreate();
|
||||
@ -91,8 +92,8 @@ TEST(EnvVarICDOverrideSetup, version_2_negotiate_interface_version_and_icd_gipa)
|
||||
|
||||
// Test VK_DRIVER_FILES environment variable
|
||||
TEST(EnvVarICDOverrideSetup, TestOnlyDriverEnvVar) {
|
||||
FrameworkEnvironment env{DebugMode::none, true};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_use_env_var_icd_filenames(true));
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var));
|
||||
env.get_test_icd(0).physical_devices.emplace_back("pd0");
|
||||
|
||||
InstWrapper inst1{env.vulkan_functions};
|
||||
@ -107,7 +108,7 @@ TEST(EnvVarICDOverrideSetup, TestOnlyDriverEnvVar) {
|
||||
ASSERT_EQ(phys_dev_count, 1U);
|
||||
|
||||
for (uint32_t add = 0; add < 2; ++add) {
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_use_env_var_icd_filenames(true));
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var));
|
||||
env.get_test_icd(add + 1).physical_devices.emplace_back("pd" + std::to_string(add) + "0");
|
||||
env.get_test_icd(add + 1).physical_devices.emplace_back("pd" + std::to_string(add) + "1");
|
||||
}
|
||||
@ -190,8 +191,8 @@ TEST(EnvVarICDOverrideSetup, XDG) {
|
||||
|
||||
// Test VK_ADD_DRIVER_FILES environment variable
|
||||
TEST(EnvVarICDOverrideSetup, TestOnlyAddDriverEnvVar) {
|
||||
FrameworkEnvironment env{DebugMode::none, true};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_use_add_env_var_icd_filenames(true));
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::add_env_var));
|
||||
env.get_test_icd(0).physical_devices.emplace_back("pd0");
|
||||
|
||||
InstWrapper inst1{env.vulkan_functions};
|
||||
@ -218,14 +219,14 @@ TEST(EnvVarICDOverrideSetup, TestOnlyAddDriverEnvVar) {
|
||||
|
||||
// Test Both VK_DRIVER_FILES and VK_ADD_DRIVER_FILES environment variable
|
||||
TEST(EnvVarICDOverrideSetup, TestBothDriverEnvVars) {
|
||||
FrameworkEnvironment env{DebugMode::none, true};
|
||||
FrameworkEnvironment env{};
|
||||
|
||||
// Add a driver that isn't enabled with the environment variable
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_use_env_var_icd_filenames(true));
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var));
|
||||
env.get_test_icd(0).physical_devices.emplace_back("pd0");
|
||||
env.get_test_icd(0).physical_devices.emplace_back("pd1");
|
||||
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_use_add_env_var_icd_filenames(true));
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::add_env_var));
|
||||
env.get_test_icd(0).physical_devices.emplace_back("pd2");
|
||||
|
||||
InstWrapper inst{env.vulkan_functions};
|
||||
@ -244,7 +245,19 @@ TEST(EnvVarICDOverrideSetup, TestBothDriverEnvVars) {
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
// Test VK_LAYER_PATH environment variable
|
||||
TEST(EnvVarICDOverrideSetup, TestOnlyLayerEnvVar) {
|
||||
// Set up a layer path that includes default and user-specified locations,
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
|
||||
env.get_test_icd().physical_devices.push_back({});
|
||||
env.platform_shim->redirect_path("/tmp/carol", env.explicit_env_var_layer_folder.location());
|
||||
|
||||
const char* layer_name = "TestLayer";
|
||||
env.add_explicit_layer(
|
||||
TestLayerDetails(ManifestLayer{}.add_layer(
|
||||
ManifestLayer::LayerDescription{}.set_name(layer_name).set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)),
|
||||
"test_layer.json")
|
||||
.set_discovery_type(ManifestDiscoveryType::env_var));
|
||||
|
||||
// Now set up a layer path that includes default and user-specified locations,
|
||||
// so that the test app can find them. Include some badly specified elements as well.
|
||||
// Need to redirect the 'home' directory
|
||||
fs::path HOME = "/home/fake_home";
|
||||
@ -253,17 +266,6 @@ TEST(EnvVarICDOverrideSetup, TestOnlyLayerEnvVar) {
|
||||
vk_layer_path += (HOME / "/ with spaces/:::::/tandy:").str();
|
||||
set_env_var("VK_LAYER_PATH", vk_layer_path);
|
||||
|
||||
FrameworkEnvironment env{DebugMode::none, false, true};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
|
||||
env.get_test_icd().physical_devices.push_back({});
|
||||
env.platform_shim->redirect_path("/tmp/carol", env.explicit_layer_folder.location());
|
||||
|
||||
const char* layer_name = "TestLayer";
|
||||
env.add_explicit_layer(
|
||||
ManifestLayer{}.add_layer(
|
||||
ManifestLayer::LayerDescription{}.set_name(layer_name).set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)),
|
||||
"test_layer.json");
|
||||
|
||||
InstWrapper inst1{env.vulkan_functions};
|
||||
inst1.create_info.add_layer(layer_name);
|
||||
FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
|
||||
@ -292,6 +294,18 @@ TEST(EnvVarICDOverrideSetup, TestOnlyLayerEnvVar) {
|
||||
|
||||
// Test VK_ADD_LAYER_PATH environment variable
|
||||
TEST(EnvVarICDOverrideSetup, TestOnlyAddLayerEnvVar) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
|
||||
env.get_test_icd().physical_devices.push_back({});
|
||||
env.platform_shim->redirect_path("/tmp/carol", env.explicit_add_env_var_layer_folder.location());
|
||||
|
||||
const char* layer_name = "TestLayer";
|
||||
env.add_explicit_layer(
|
||||
TestLayerDetails(ManifestLayer{}.add_layer(
|
||||
ManifestLayer::LayerDescription{}.set_name(layer_name).set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)),
|
||||
"test_layer.json")
|
||||
.set_discovery_type(ManifestDiscoveryType::add_env_var));
|
||||
|
||||
// Set up a layer path that includes default and user-specified locations,
|
||||
// so that the test app can find them. Include some badly specified elements as well.
|
||||
// Need to redirect the 'home' directory
|
||||
@ -301,17 +315,6 @@ TEST(EnvVarICDOverrideSetup, TestOnlyAddLayerEnvVar) {
|
||||
vk_layer_path += (HOME / "/ with spaces/:::::/tandy:").str();
|
||||
set_env_var("VK_ADD_LAYER_PATH", vk_layer_path);
|
||||
|
||||
FrameworkEnvironment env{DebugMode::none, false, true};
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
|
||||
env.get_test_icd().physical_devices.push_back({});
|
||||
env.platform_shim->redirect_path("/tmp/carol", env.explicit_layer_folder.location());
|
||||
|
||||
const char* layer_name = "TestLayer";
|
||||
env.add_explicit_layer(
|
||||
ManifestLayer{}.add_layer(
|
||||
ManifestLayer::LayerDescription{}.set_name(layer_name).set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)),
|
||||
"test_layer.json");
|
||||
|
||||
InstWrapper inst1{env.vulkan_functions};
|
||||
inst1.create_info.add_layer(layer_name);
|
||||
FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
|
||||
|
@ -1026,10 +1026,6 @@ TEST(OverrideMetaLayer, OverridePathsInteractionWithVK_LAYER_PATH) {
|
||||
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
|
||||
env.get_test_icd().add_physical_device({});
|
||||
|
||||
fs::FolderManager vk_layer_path_folder{FRAMEWORK_BUILD_DIRECTORY, "vk_layer_folder"};
|
||||
set_env_var("VK_LAYER_PATH", vk_layer_path_folder.location().str());
|
||||
fs::FolderManager override_path_folder{FRAMEWORK_BUILD_DIRECTORY, "override_path_folder"};
|
||||
|
||||
// add explicit layer to VK_LAYER_PATH folder
|
||||
const char* env_var_layer_name = "VK_LAYER_env_var_set_path";
|
||||
env.add_explicit_layer(TestLayerDetails{ManifestLayer{}
|
||||
@ -1039,7 +1035,7 @@ TEST(OverrideMetaLayer, OverridePathsInteractionWithVK_LAYER_PATH) {
|
||||
.set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
|
||||
.set_api_version(VK_MAKE_API_VERSION(0, 1, 0, 0))),
|
||||
"regular_test_layer.json"}
|
||||
.set_destination_folder(&vk_layer_path_folder));
|
||||
.set_discovery_type(ManifestDiscoveryType::env_var));
|
||||
|
||||
// add layer to regular explicit layer folder
|
||||
const char* regular_layer_name = "VK_LAYER_regular_layer_path";
|
||||
@ -1048,7 +1044,7 @@ TEST(OverrideMetaLayer, OverridePathsInteractionWithVK_LAYER_PATH) {
|
||||
.set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
|
||||
.set_api_version(VK_MAKE_API_VERSION(0, 1, 1, 0))),
|
||||
"regular_test_layer.json"}
|
||||
.set_destination_folder(&override_path_folder));
|
||||
.set_discovery_type(ManifestDiscoveryType::override_folder));
|
||||
|
||||
env.add_implicit_layer(ManifestLayer{}
|
||||
.set_file_format_version(ManifestVersion(1, 2, 0))
|
||||
@ -1057,7 +1053,7 @@ TEST(OverrideMetaLayer, OverridePathsInteractionWithVK_LAYER_PATH) {
|
||||
.set_api_version(VK_MAKE_API_VERSION(0, 1, 1, 0))
|
||||
.add_component_layer(regular_layer_name)
|
||||
.set_disable_environment("DisableMeIfYouCan")
|
||||
.add_override_path(override_path_folder.location().str())),
|
||||
.add_override_path(env.override_layer_folder.location().str())),
|
||||
"meta_test_layer.json");
|
||||
|
||||
InstWrapper inst{env.vulkan_functions};
|
||||
|
@ -133,7 +133,7 @@ TEST(ICDInterfaceVersion2PlusEnumerateAdapterPhysicalDevices, version_6_in_drive
|
||||
// Make the version_6 driver found through the D3DKMT driver discovery mechanism of the loader
|
||||
TEST(ICDInterfaceVersion2PlusEnumerateAdapterPhysicalDevices, version_6) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_6, VK_API_VERSION_1_3}.set_add_manifest_to_default_driver_location(false));
|
||||
env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_6, VK_API_VERSION_1_3}.set_discovery_type(ManifestDiscoveryType::none));
|
||||
// Version 6 provides a mechanism to allow the loader to sort physical devices.
|
||||
// The loader will only attempt to sort physical devices on an ICD if version 6 of the interface is supported.
|
||||
// This version provides the vk_icdEnumerateAdapterPhysicalDevices function.
|
||||
@ -186,7 +186,7 @@ TEST(ICDInterfaceVersion2PlusEnumerateAdapterPhysicalDevices, version_6) {
|
||||
// EnumerateAdapterPhysicalDevices
|
||||
TEST(ICDInterfaceVersion2, EnumAdapters2) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA}.set_add_manifest_to_default_driver_location(false));
|
||||
env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA}.set_discovery_type(ManifestDiscoveryType::none));
|
||||
InstWrapper inst{env.vulkan_functions};
|
||||
auto& driver = env.get_test_icd();
|
||||
driver.physical_devices.emplace_back("physical_device_1");
|
||||
@ -211,8 +211,8 @@ TEST(ICDInterfaceVersion2, EnumAdapters2) {
|
||||
// Verify that the handles are correct by calling vkGetPhysicalDeviceProperties with them
|
||||
TEST(ICDInterfaceVersion2PlusEnumerateAdapterPhysicalDevices, VerifyPhysDevResults) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_2_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES}
|
||||
.set_add_manifest_to_default_driver_location(false));
|
||||
env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_2_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES}.set_discovery_type(
|
||||
ManifestDiscoveryType::none));
|
||||
auto& driver = env.get_test_icd();
|
||||
driver.min_icd_interface_version = 6;
|
||||
driver.set_icd_api_version(VK_API_VERSION_1_1);
|
||||
@ -255,8 +255,8 @@ TEST(ICDInterfaceVersion2PlusEnumerateAdapterPhysicalDevices, VerifyPhysDevResul
|
||||
// Make sure physical device groups enumerated through EnumerateAdapterPhysicalDevices are properly found
|
||||
TEST(ICDInterfaceVersion2PlusEnumerateAdapterPhysicalDevices, VerifyGroupResults) {
|
||||
FrameworkEnvironment env{};
|
||||
env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_2_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES}
|
||||
.set_add_manifest_to_default_driver_location(false));
|
||||
env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_2_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES}.set_discovery_type(
|
||||
ManifestDiscoveryType::none));
|
||||
auto& driver = env.get_test_icd();
|
||||
driver.min_icd_interface_version = 6;
|
||||
driver.set_icd_api_version(VK_API_VERSION_1_1);
|
||||
|
Loading…
Reference in New Issue
Block a user