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

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

vulkan: add layers_extensions.h

Move everything for layers_extensions.cpp out of loader.h to
layers_extensions.h, and into vulkan::api namespace.

Remove now unused InstanceExtensionFromName and DeviceExtensionFromName.

Change-Id: I06be98986f40de35e9dffb5499bc1423e9eb3d48
parent ff4a6c77
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
#include <vulkan/vk_layer_interface.h>
#include "api.h"
#include "driver.h"
#include "loader.h"
#include "layers_extensions.h"

namespace vulkan {
namespace api {
+4 −24
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

// #define LOG_NDEBUG 0

#include "loader.h"
#include "layers_extensions.h"
#include <alloca.h>
#include <dirent.h>
#include <dlfcn.h>
@@ -28,8 +28,6 @@
#include <log/log.h>
#include <vulkan/vulkan_loader_data.h>

using namespace vulkan;

// TODO(jessehall): The whole way we deal with extensions is pretty hokey, and
// not a good long-term solution. Having a hard-coded enum of extensions is
// bad, of course. Representing sets of extensions (requested, supported, etc.)
@@ -50,12 +48,13 @@ using namespace vulkan;
// with a mask saying what kind(s) it is.

namespace vulkan {
namespace api {

struct Layer {
    VkLayerProperties properties;
    size_t library_idx;
    std::vector<VkExtensionProperties> extensions;
};
}  // namespace vulkan

namespace {

@@ -341,8 +340,6 @@ LayerRef GetLayerRef(std::vector<Layer>& layers, const char* name) {

}  // anonymous namespace

namespace vulkan {

void DiscoverLayers() {
    if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0))
        DiscoverLayersInDirectory("/data/local/debug/vulkan");
@@ -425,22 +422,5 @@ bool LayerRef::SupportsExtension(const char* name) const {
                        }) != layer_->extensions.cend();
}

InstanceExtension InstanceExtensionFromName(const char* name) {
    if (strcmp(name, VK_KHR_SURFACE_EXTENSION_NAME) == 0)
        return kKHR_surface;
    if (strcmp(name, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0)
        return kKHR_android_surface;
    if (strcmp(name, VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0)
        return kEXT_debug_report;
    return kInstanceExtensionCount;
}

DeviceExtension DeviceExtensionFromName(const char* name) {
    if (strcmp(name, VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)
        return kKHR_swapchain;
    if (strcmp(name, VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME) == 0)
        return kANDROID_native_buffer;
    return kDeviceExtensionCount;
}

}  // namespace api
}  // namespace vulkan
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LIBVULKAN_LAYERS_EXTENSIONS_H
#define LIBVULKAN_LAYERS_EXTENSIONS_H 1

#include <vulkan/vulkan.h>

namespace vulkan {
namespace api {

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

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

    // 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:
    Layer* layer_;
};

void DiscoverLayers();
uint32_t EnumerateInstanceLayers(uint32_t count, VkLayerProperties* properties);
uint32_t EnumerateDeviceLayers(uint32_t count, VkLayerProperties* properties);
void GetInstanceLayerExtensions(const char* name,
                                const VkExtensionProperties** properties,
                                uint32_t* count);
void GetDeviceLayerExtensions(const char* name,
                              const VkExtensionProperties** properties,
                              uint32_t* count);
LayerRef GetInstanceLayerRef(const char* name);
LayerRef GetDeviceLayerRef(const char* name);

}  // namespace api
}  // namespace vulkan

#endif  // LIBVULKAN_LAYERS_EXTENSIONS_H
+0 −57
Original line number Diff line number Diff line
@@ -26,21 +26,6 @@ struct hwvulkan_device_t;

namespace vulkan {

enum InstanceExtension {
    kKHR_surface,
    kKHR_android_surface,
    kEXT_debug_report,
    kInstanceExtensionCount
};
typedef std::bitset<kInstanceExtensionCount> InstanceExtensionSet;

enum DeviceExtension {
    kKHR_swapchain,
    kANDROID_native_buffer,
    kDeviceExtensionCount
};
typedef std::bitset<kDeviceExtensionCount> DeviceExtensionSet;

// -----------------------------------------------------------------------------
// loader.cpp

@@ -69,48 +54,6 @@ VKAPI_ATTR VkResult AcquireNextImageKHR_Bottom(VkDevice device, VkSwapchainKHR s
VKAPI_ATTR VkResult QueuePresentKHR_Bottom(VkQueue queue, const VkPresentInfoKHR* present_info);
// clang-format on

// -----------------------------------------------------------------------------
// layers_extensions.cpp

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

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

    // 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:
    Layer* layer_;
};

void DiscoverLayers();
uint32_t EnumerateInstanceLayers(uint32_t count, VkLayerProperties* properties);
uint32_t EnumerateDeviceLayers(uint32_t count, VkLayerProperties* properties);
void GetInstanceLayerExtensions(const char* name,
                                const VkExtensionProperties** properties,
                                uint32_t* count);
void GetDeviceLayerExtensions(const char* name,
                              const VkExtensionProperties** properties,
                              uint32_t* count);
LayerRef GetInstanceLayerRef(const char* name);
LayerRef GetDeviceLayerRef(const char* name);

InstanceExtension InstanceExtensionFromName(const char* name);
DeviceExtension DeviceExtensionFromName(const char* name);

}  // namespace vulkan

#endif  // LIBVULKAN_LOADER_H