Rootless GPU Debug
Add the ability to load GPU debug layers from the base
directory of debuggable applications.
This update concides with changes to framework/base to
control the enabling logic in GraphicsEnvironment.
This commit changes the Vulkan loader to:
* Scan an additional location for debug layers.
* Use the provided order of layers from GraphicsEnvironment,
overriding system properties.
* Use the first instance of a layer found, in the case of duplicates.
* Move layers paths and namespace to GraphicsEnv, removing vulkan_loader_data
Bug: 63708377
Test: Manual, CTS tests to follow
Change-Id: I38dc91bbc26671f5093ee1b12454fc024c0b5892
diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp
index d840786..673a066 100644
--- a/vulkan/libvulkan/api.cpp
+++ b/vulkan/libvulkan/api.cpp
@@ -29,14 +29,17 @@
#include <new>
#include <utility>
+#include <android-base/strings.h>
#include <cutils/properties.h>
#include <log/log.h>
#include <vulkan/vk_layer_interface.h>
+#include <graphicsenv/GraphicsEnv.h>
#include "api.h"
#include "driver.h"
#include "layers_extensions.h"
+
namespace vulkan {
namespace api {
@@ -121,15 +124,33 @@
if (!is_instance_ || !driver::Debuggable())
return;
- ParseDebugVulkanLayers();
- property_list(ParseDebugVulkanLayer, this);
+ GetLayersFromSettings();
- // sort by priorities
- auto& arr = implicit_layers_;
- std::sort(arr.elements, arr.elements + arr.count,
- [](const ImplicitLayer& a, const ImplicitLayer& b) {
- return (a.priority < b.priority);
- });
+ // If no layers specified via Settings, check legacy properties
+ if (implicit_layers_.count <= 0) {
+ ParseDebugVulkanLayers();
+ property_list(ParseDebugVulkanLayer, this);
+
+ // sort by priorities
+ auto& arr = implicit_layers_;
+ std::sort(arr.elements, arr.elements + arr.count,
+ [](const ImplicitLayer& a, const ImplicitLayer& b) {
+ return (a.priority < b.priority);
+ });
+ }
+ }
+
+ void GetLayersFromSettings() {
+ // These will only be available if conditions are met in GraphicsEnvironemnt
+ // gpu_debug_layers = layer1:layer2:layerN
+ const std::string layers = android::GraphicsEnv::getInstance().getDebugLayers();
+ if (!layers.empty()) {
+ ALOGV("Debug layer list: %s", layers.c_str());
+ std::vector<std::string> paths = android::base::Split(layers, ":");
+ for (uint32_t i = 0; i < paths.size(); i++) {
+ AddImplicitLayer(int(i), paths[i].c_str(), paths[i].length());
+ }
+ }
}
void ParseDebugVulkanLayers() {