Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6e6f514 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

vulkan: make Get*LayerRef take a Layer

The only user-visible change should be improved error messages.

Bug: 27911856
Change-Id: Ie50a9d37f07b590026176642f2c67270225f9280
parent 04c6551e
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -543,13 +543,19 @@ LayerChain::ActiveLayer* LayerChain::AllocateLayerArray(uint32_t count) const {
}

VkResult LayerChain::LoadLayer(ActiveLayer& layer, const char* name) {
    const Layer* l = FindLayer(name);
    if (!l || (!is_instance_ && !IsLayerGlobal(*l))) {
        ALOGW("Failed to find layer %s", name);
        return VK_ERROR_LAYER_NOT_PRESENT;
    }

    if (is_instance_)
        new (&layer) ActiveLayer{GetInstanceLayerRef(name), {}};
        new (&layer) ActiveLayer{GetInstanceLayerRef(*l), {}};
    else
        new (&layer) ActiveLayer{GetDeviceLayerRef(name), {}};
        new (&layer) ActiveLayer{GetDeviceLayerRef(*l), {}};

    if (!layer.ref) {
        ALOGE("Failed to load layer %s", name);
        ALOGW("Failed to open layer %s", name);
        layer.ref.~LayerRef();
        return VK_ERROR_LAYER_NOT_PRESENT;
    }
+7 −27
Original line number Diff line number Diff line
@@ -330,15 +330,6 @@ void DiscoverLayersInDirectory(const std::string& dir_path) {
    closedir(directory);
}

const Layer* FindInstanceLayer(const char* name) {
    return FindLayer(name);
}

const Layer* FindDeviceLayer(const char* name) {
    const Layer* layer = FindInstanceLayer(name);
    return (layer && layer->is_global) ? layer : nullptr;
}

void* GetLayerGetProcAddr(const Layer& layer,
                          const char* gpa_name,
                          size_t gpa_name_len) {
@@ -392,26 +383,15 @@ const VkExtensionProperties* GetLayerDeviceExtensions(const Layer& layer,
    return layer.device_extensions.data();
}

LayerRef GetInstanceLayerRef(const char* name) {
    const Layer* layer = FindInstanceLayer(name);
    if (layer) {
        LayerLibrary& library = g_layer_libraries[layer->library_idx];
        if (!library.Open())
            layer = nullptr;
    }

    return LayerRef(layer, true);
}

LayerRef GetDeviceLayerRef(const char* name) {
    const Layer* layer = FindDeviceLayer(name);
    if (layer) {
        LayerLibrary& library = g_layer_libraries[layer->library_idx];
        if (!library.Open())
            layer = nullptr;
LayerRef GetInstanceLayerRef(const Layer& layer) {
    LayerLibrary& library = g_layer_libraries[layer.library_idx];
    return LayerRef((library.Open()) ? &layer : nullptr, true);
}

    return LayerRef(layer, false);
LayerRef GetDeviceLayerRef(const Layer& layer) {
    LayerLibrary& library = g_layer_libraries[layer.library_idx];
    return LayerRef((layer.is_global && library.Open()) ? &layer : nullptr,
                    false);
}

LayerRef::LayerRef(const Layer* layer, bool is_instance)
+2 −2
Original line number Diff line number Diff line
@@ -61,8 +61,8 @@ const VkExtensionProperties* GetLayerInstanceExtensions(const Layer& layer,
const VkExtensionProperties* GetLayerDeviceExtensions(const Layer& layer,
                                                      uint32_t& count);

LayerRef GetInstanceLayerRef(const char* name);
LayerRef GetDeviceLayerRef(const char* name);
LayerRef GetInstanceLayerRef(const Layer& layer);
LayerRef GetDeviceLayerRef(const Layer& layer);

}  // namespace api
}  // namespace vulkan