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

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

vulkan: do not distinguish instance or device LayerRef

Merge Get*LayerRef into GetLayerRef and remove LayerRef::is_instance_.
With the removal, LayerRef::SupportsExtension becomes ambiguous.  Replace
it with FindLayer*Extension.  Remove unused LayerRef::GetName and
LayerRef::GetSpecName while at it.

There should be no user-visible change.

Bug: 27911856
Change-Id: I38340654b52338e9ed46d1c4462a6b254b0cab64
parent d6e6f514
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -549,11 +549,7 @@ VkResult LayerChain::LoadLayer(ActiveLayer& layer, const char* name) {
        return VK_ERROR_LAYER_NOT_PRESENT;
    }

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

    new (&layer) ActiveLayer{GetLayerRef(*l), {}};
    if (!layer.ref) {
        ALOGW("Failed to open layer %s", name);
        layer.ref.~LayerRef();
@@ -878,11 +874,19 @@ VkExtensionProperties* LayerChain::AllocateDriverExtensionArray(
}

bool LayerChain::IsLayerExtension(const char* name) const {
    if (is_instance_) {
        for (uint32_t i = 0; i < layer_count_; i++) {
            const ActiveLayer& layer = layers_[i];
        if (layer.ref.SupportsExtension(name))
            if (FindLayerInstanceExtension(*layer.ref, name))
                return true;
        }
    } else {
        for (uint32_t i = 0; i < layer_count_; i++) {
            const ActiveLayer& layer = layers_[i];
            if (FindLayerDeviceExtension(*layer.ref, name))
                return true;
        }
    }

    return false;
}
+22 −27
Original line number Diff line number Diff line
@@ -330,6 +330,16 @@ void DiscoverLayersInDirectory(const std::string& dir_path) {
    closedir(directory);
}

const VkExtensionProperties* FindExtension(
    const std::vector<VkExtensionProperties>& extensions,
    const char* name) {
    auto it = std::find_if(extensions.cbegin(), extensions.cend(),
                           [=](const VkExtensionProperties& ext) {
                               return (strcmp(ext.extensionName, name) == 0);
                           });
    return (it != extensions.cend()) ? &*it : nullptr;
}

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

LayerRef GetInstanceLayerRef(const Layer& layer) {
    LayerLibrary& library = g_layer_libraries[layer.library_idx];
    return LayerRef((library.Open()) ? &layer : nullptr, true);
const VkExtensionProperties* FindLayerInstanceExtension(const Layer& layer,
                                                        const char* name) {
    return FindExtension(layer.instance_extensions, name);
}

const VkExtensionProperties* FindLayerDeviceExtension(const Layer& layer,
                                                      const char* name) {
    return FindExtension(layer.device_extensions, name);
}

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

LayerRef::LayerRef(const Layer* layer, bool is_instance)
    : layer_(layer), is_instance_(is_instance) {}
LayerRef::LayerRef(const Layer* layer) : layer_(layer) {}

LayerRef::~LayerRef() {
    if (layer_) {
@@ -404,16 +417,7 @@ LayerRef::~LayerRef() {
    }
}

const char* LayerRef::GetName() const {
    return layer_->properties.layerName;
}

uint32_t LayerRef::GetSpecVersion() const {
    return layer_->properties.specVersion;
}

LayerRef::LayerRef(LayerRef&& other)
    : layer_(other.layer_), is_instance_(other.is_instance_) {
LayerRef::LayerRef(LayerRef&& other) : layer_(other.layer_) {
    other.layer_ = nullptr;
}

@@ -429,14 +433,5 @@ PFN_vkGetDeviceProcAddr LayerRef::GetGetDeviceProcAddr() const {
                  : nullptr;
}

bool LayerRef::SupportsExtension(const char* name) const {
    const auto& extensions = (is_instance_) ? layer_->instance_extensions
                                            : layer_->device_extensions;
    return std::find_if(extensions.cbegin(), extensions.cend(),
                        [=](const VkExtensionProperties& ext) {
                            return strcmp(ext.extensionName, name) == 0;
                        }) != extensions.cend();
}

}  // namespace api
}  // namespace vulkan
+7 −9
Original line number Diff line number Diff line
@@ -26,26 +26,20 @@ struct Layer;

class LayerRef {
   public:
    LayerRef(const Layer* layer, bool is_instance);
    LayerRef(const Layer* layer);
    LayerRef(LayerRef&& other);
    ~LayerRef();
    LayerRef(const LayerRef&) = delete;
    LayerRef& operator=(const LayerRef&) = delete;

    const char* GetName() const;
    uint32_t GetSpecVersion() const;

    // provides bool-like behavior
    operator const Layer*() const { return layer_; }

    PFN_vkGetInstanceProcAddr GetGetInstanceProcAddr() const;
    PFN_vkGetDeviceProcAddr GetGetDeviceProcAddr() const;

    bool SupportsExtension(const char* name) const;

   private:
    const Layer* layer_;
    bool is_instance_;
};

void DiscoverLayers();
@@ -61,8 +55,12 @@ const VkExtensionProperties* GetLayerInstanceExtensions(const Layer& layer,
const VkExtensionProperties* GetLayerDeviceExtensions(const Layer& layer,
                                                      uint32_t& count);

LayerRef GetInstanceLayerRef(const Layer& layer);
LayerRef GetDeviceLayerRef(const Layer& layer);
const VkExtensionProperties* FindLayerInstanceExtension(const Layer& layer,
                                                        const char* name);
const VkExtensionProperties* FindLayerDeviceExtension(const Layer& layer,
                                                      const char* name);

LayerRef GetLayerRef(const Layer& layer);

}  // namespace api
}  // namespace vulkan