diff --git a/generator/vk_codegen/device_defs.txt b/generator/vk_codegen/device_defs.txt index 3c627c1..3b87173 100644 --- a/generator/vk_codegen/device_defs.txt +++ b/generator/vk_codegen/device_defs.txt @@ -2,9 +2,12 @@ #include #include +// Include from per-layer code #include "utils.hpp" #include "device.hpp" -#include "device_functions.hpp" + +// Include from common code +#include "framework/device_functions.hpp" extern std::mutex g_vulkanLock; diff --git a/generator/vk_codegen/function_vkCreateDevice.txt b/generator/vk_codegen/function_vkCreateDevice.txt index 218d8a3..4f5d4da 100644 --- a/generator/vk_codegen/function_vkCreateDevice.txt +++ b/generator/vk_codegen/function_vkCreateDevice.txt @@ -5,7 +5,7 @@ // Release the lock to call into the driver lock.unlock(); - auto* chainInfo = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); + auto* chainInfo = getChainInfo(pCreateInfo, VK_LAYER_LINK_INFO); auto fpGetInstanceProcAddr = chainInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr; auto fpGetDeviceProcAddr = chainInfo->u.pLayerInfo->pfnNextGetDeviceProcAddr; auto fpCreateDevice = reinterpret_cast(fpGetInstanceProcAddr(layer->instance, "vkCreateDevice")); diff --git a/generator/vk_codegen/function_vkCreateInstance.txt b/generator/vk_codegen/function_vkCreateInstance.txt index be127a2..ce267e5 100644 --- a/generator/vk_codegen/function_vkCreateInstance.txt +++ b/generator/vk_codegen/function_vkCreateInstance.txt @@ -1,4 +1,4 @@ - auto* chainInfo = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); + auto* chainInfo = getChainInfo(pCreateInfo, VK_LAYER_LINK_INFO); auto fpGetInstanceProcAddr = chainInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr; auto fpCreateInstance = reinterpret_cast(fpGetInstanceProcAddr(nullptr, "vkCreateInstance")); diff --git a/generator/vk_codegen/instance_defs.txt b/generator/vk_codegen/instance_defs.txt index 6b43588..bd28163 100644 --- a/generator/vk_codegen/instance_defs.txt +++ b/generator/vk_codegen/instance_defs.txt @@ -2,11 +2,14 @@ #include #include +// Include from per-layer code #include "device.hpp" -#include "entry_utils.hpp" #include "instance.hpp" -#include "instance_functions.hpp" -#include "utils.hpp" + +// Include from common code +#include "framework/instance_functions_manual.hpp" +#include "framework/instance_functions.hpp" +#include "framework/utils.hpp" extern std::mutex g_vulkanLock; diff --git a/generator/vk_layer/source/entry.cpp b/generator/vk_layer/source/entry.cpp index dc340cd..3c77631 100644 --- a/generator/vk_layer/source/entry.cpp +++ b/generator/vk_layer/source/entry.cpp @@ -36,7 +36,7 @@ #include #include "framework/utils.hpp" -#include "framework/entry_utils.hpp" +#include "framework/instance_functions_manual.hpp" std::mutex g_vulkanLock; diff --git a/layer_example/source/entry.cpp b/layer_example/source/entry.cpp index dc340cd..3c77631 100644 --- a/layer_example/source/entry.cpp +++ b/layer_example/source/entry.cpp @@ -36,7 +36,7 @@ #include #include "framework/utils.hpp" -#include "framework/entry_utils.hpp" +#include "framework/instance_functions_manual.hpp" std::mutex g_vulkanLock; diff --git a/source_common/framework/CMakeLists.txt b/source_common/framework/CMakeLists.txt index 86889ca..29921a1 100644 --- a/source_common/framework/CMakeLists.txt +++ b/source_common/framework/CMakeLists.txt @@ -26,8 +26,8 @@ set(LIB_BINARY lib_layer_framework) add_library( ${LIB_BINARY} STATIC device_functions.cpp - entry_utils.cpp - instance_functions.cpp) + instance_functions.cpp + instance_functions_manual.cpp) target_include_directories( ${LIB_BINARY} PRIVATE diff --git a/source_common/framework/device_functions.cpp b/source_common/framework/device_functions.cpp index 6939b18..ff1a76d 100644 --- a/source_common/framework/device_functions.cpp +++ b/source_common/framework/device_functions.cpp @@ -27,9 +27,12 @@ #include #include +// Include from per-layer code #include "utils.hpp" #include "device.hpp" -#include "device_functions.hpp" + +// Include from common code +#include "framework/device_functions.hpp" extern std::mutex g_vulkanLock; diff --git a/source_common/framework/instance_functions.cpp b/source_common/framework/instance_functions.cpp index e422bfe..3bdd0b4 100644 --- a/source_common/framework/instance_functions.cpp +++ b/source_common/framework/instance_functions.cpp @@ -27,11 +27,14 @@ #include #include +// Include from per-layer code #include "device.hpp" -#include "entry_utils.hpp" #include "instance.hpp" -#include "instance_functions.hpp" -#include "utils.hpp" + +// Include from common code +#include "framework/instance_functions_manual.hpp" +#include "framework/instance_functions.hpp" +#include "framework/utils.hpp" extern std::mutex g_vulkanLock; @@ -109,7 +112,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default( // Release the lock to call into the driver lock.unlock(); - auto* chainInfo = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); + auto* chainInfo = getChainInfo(pCreateInfo, VK_LAYER_LINK_INFO); auto fpGetInstanceProcAddr = chainInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr; auto fpGetDeviceProcAddr = chainInfo->u.pLayerInfo->pfnNextGetDeviceProcAddr; auto fpCreateDevice = reinterpret_cast(fpGetInstanceProcAddr(layer->instance, "vkCreateDevice")); @@ -179,7 +182,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateInstance_default( ) { LAYER_TRACE(__func__); - auto* chainInfo = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); + auto* chainInfo = getChainInfo(pCreateInfo, VK_LAYER_LINK_INFO); auto fpGetInstanceProcAddr = chainInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr; auto fpCreateInstance = reinterpret_cast(fpGetInstanceProcAddr(nullptr, "vkCreateInstance")); diff --git a/source_common/framework/entry_utils.cpp b/source_common/framework/instance_functions_manual.cpp similarity index 87% rename from source_common/framework/entry_utils.cpp rename to source_common/framework/instance_functions_manual.cpp index b59bf78..a1bfc54 100644 --- a/source_common/framework/entry_utils.cpp +++ b/source_common/framework/instance_functions_manual.cpp @@ -30,9 +30,51 @@ * implementations on a per-layer basis if needed. */ -#include "framework/entry_utils.hpp" +#include "framework/instance_functions_manual.hpp" -VkLayerInstanceCreateInfo* get_chain_info( +/** + * @brief Shared globals. + */ +extern std::mutex g_vulkanLock; + +/** + * @brief The layer configuration. + */ +#define LGL_VERSION VK_MAKE_VERSION(LGL_VER_MAJOR, LGL_VER_MINOR, LGL_VER_PATCH) + +static const std::array layerProps = { + {{ LGL_LAYER_NAME, LGL_VERSION, 1, LGL_LAYER_DESC }}, +}; + +/** + * @brief Dispatch table lookup entry. + */ +struct DispatchTableEntry +{ + /** + * @brief The function entrypoint name. + */ + const char* name; + + /** + * @brief The function pointer. + */ + PFN_vkVoidFunction function; +}; + +/** + * @brief Utility macro to define a lookup for a core function. + */ +#define VK_TABLE_ENTRY(func) \ + { STR(func), reinterpret_cast(func) } + +/** + * @brief Utility macro to define a lookup for a layer-dispatch-only function. + */ +#define VK_TABLE_ENTRYL(func) \ + { STR(func), reinterpret_cast(layer_##func) } + +VkLayerInstanceCreateInfo* getChainInfo( const VkInstanceCreateInfo* pCreateInfo, VkLayerFunction func ) { @@ -45,7 +87,7 @@ VkLayerInstanceCreateInfo* get_chain_info( return const_cast(info); } -VkLayerDeviceCreateInfo* get_chain_info( +VkLayerDeviceCreateInfo* getChainInfo( const VkDeviceCreateInfo* pCreateInfo, VkLayerFunction func ) { @@ -66,7 +108,7 @@ VkLayerDeviceCreateInfo* get_chain_info( * \return The layer function pointer, or \c nullptr if the layer doesn't * intercept the function. */ -PFN_vkVoidFunction get_fixed_instance_layer_function( +PFN_vkVoidFunction getFixedInstanceLayerFunction( const char* name ) { static const DispatchTableEntry layerFunctions[] = { @@ -96,7 +138,7 @@ PFN_vkVoidFunction get_fixed_instance_layer_function( * \return The layer function pointer, or \c nullptr if the layer doesn't * intercept the function. */ -PFN_vkVoidFunction get_instance_layer_function( +PFN_vkVoidFunction getInstanceLayerFunction( const char* name ) { for (auto &function : instanceIntercepts) @@ -117,7 +159,7 @@ PFN_vkVoidFunction get_instance_layer_function( * * \return The layer function pointer, or \c nullptr if the layer doesn't intercept the function. */ -PFN_vkVoidFunction get_device_layer_function( +PFN_vkVoidFunction getDeviceLayerFunction( const char* name ) { static const DispatchTableEntry layerFunctions[] = { @@ -158,7 +200,7 @@ PFN_vkVoidFunction vkGetDeviceProcAddr_default( // Only expose functions that the driver exposes to avoid changing // queryable interface behavior seen by the application auto driver_function = layer->driver.vkGetDeviceProcAddr(device, pName); - auto layer_function = get_device_layer_function(pName); + auto layer_function = getDeviceLayerFunction(pName); // If driver exposes it and the layer has one, use the layer function if (driver_function && layer_function) @@ -176,7 +218,7 @@ PFN_vkVoidFunction vkGetInstanceProcAddr_default( const char* pName ) { // Always expose these functions ... - PFN_vkVoidFunction layerFunction = get_fixed_instance_layer_function(pName); + PFN_vkVoidFunction layerFunction = getFixedInstanceLayerFunction(pName); if (layerFunction) { return layerFunction; @@ -184,7 +226,7 @@ PFN_vkVoidFunction vkGetInstanceProcAddr_default( // Otherwise, only expose functions that the driver exposes to avoid // changing queryable interface behavior seen by the application - layerFunction = get_instance_layer_function(pName); + layerFunction = getInstanceLayerFunction(pName); if (instance) { std::unique_lock lock { g_vulkanLock }; auto* layer = Instance::retrieve(instance); @@ -213,7 +255,7 @@ std::vector getInstanceExtensionList( std::vector foundExtensions; // Get layer chain info, and save next pointer so we can restore later - auto* chainInfo = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); + auto* chainInfo = getChainInfo(pCreateInfo, VK_LAYER_LINK_INFO); // Fetch the functions needed to query extensions availability auto fpGetProcAddr = chainInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr; diff --git a/source_common/framework/entry_utils.hpp b/source_common/framework/instance_functions_manual.hpp similarity index 78% rename from source_common/framework/entry_utils.hpp rename to source_common/framework/instance_functions_manual.hpp index 09f7601..103a80a 100644 --- a/source_common/framework/entry_utils.hpp +++ b/source_common/framework/instance_functions_manual.hpp @@ -45,8 +45,6 @@ #include "device_dispatch_table.hpp" #include "device_functions.hpp" -extern std::mutex g_vulkanLock; - #define VK_LAYER_EXPORT __attribute__((visibility("default"))) #if defined(VK_USE_PLATFORM_ANDROID_KHR) @@ -55,49 +53,11 @@ extern std::mutex g_vulkanLock; #define VK_LAYER_EXPORT_ANDROID #endif -/** - * @brief The layer configuration. - */ -#define LGL_VERSION VK_MAKE_VERSION(LGL_VER_MAJOR, LGL_VER_MINOR, LGL_VER_PATCH) - -static const std::array layerProps = { - {{ LGL_LAYER_NAME, LGL_VERSION, 1, LGL_LAYER_DESC }}, -}; - -/** - * @brief Dispatch table lookup entry. - */ -struct DispatchTableEntry -{ - /** - * @brief The function entrypoint name. - */ - const char* name; - - /** - * @brief The function pointer. - */ - PFN_vkVoidFunction function; -}; - -/** - * @brief Utility macro to define a lookup for a core function. - */ -#define VK_TABLE_ENTRY(func) \ - { STR(func), reinterpret_cast(func) } - -/** - * @brief Utility macro to define a lookup for a layer-dispatch-only function. - */ -#define VK_TABLE_ENTRYL(func) \ - { STR(func), reinterpret_cast(layer_##func) } - - -VkLayerInstanceCreateInfo* get_chain_info( +VkLayerInstanceCreateInfo* getChainInfo( const VkInstanceCreateInfo* pCreateInfo, VkLayerFunction func); -VkLayerDeviceCreateInfo* get_chain_info( +VkLayerDeviceCreateInfo* getChainInfo( const VkDeviceCreateInfo* pCreateInfo, VkLayerFunction func); @@ -109,7 +69,7 @@ VkLayerDeviceCreateInfo* get_chain_info( * \return The layer function pointer, or \c nullptr if the layer doesn't * intercept the function. */ -PFN_vkVoidFunction get_fixed_instance_layer_function( +PFN_vkVoidFunction getFixedInstanceLayerFunction( const char* name); /** @@ -120,7 +80,7 @@ PFN_vkVoidFunction get_fixed_instance_layer_function( * \return The layer function pointer, or \c nullptr if the layer doesn't * intercept the function. */ -PFN_vkVoidFunction get_instance_layer_function( +PFN_vkVoidFunction getInstanceLayerFunction( const char* name); /** @@ -130,9 +90,13 @@ PFN_vkVoidFunction get_instance_layer_function( * * \return The layer function pointer, or \c nullptr if the layer doesn't intercept the function. */ -PFN_vkVoidFunction get_device_layer_function( +PFN_vkVoidFunction getDeviceLayerFunction( const char* name); +/* TODO. */ +std::vector getInstanceExtensionList( + const VkInstanceCreateInfo* pCreateInfo); + /** See Vulkan API for documentation. */ PFN_vkVoidFunction vkGetDeviceProcAddr_default( VkDevice device, @@ -143,10 +107,6 @@ PFN_vkVoidFunction vkGetInstanceProcAddr_default( VkInstance instance, const char* pName); -/* TODO. */ -std::vector getInstanceExtensionList( - const VkInstanceCreateInfo* pCreateInfo); - /** See Vulkan API for documentation. */ VkResult vkEnumerateInstanceExtensionProperties_default( const char* pLayerName,