Skip to content

Commit 750caf3

Browse files
committed
Framework: Support vkGetInstanceProcAddr for global functions
1 parent ba6b2aa commit 750caf3

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

source_common/framework/manual_functions.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,34 @@ VkLayerDeviceCreateInfo* getChainInfo(const VkDeviceCreateInfo* pCreateInfo)
111111
}
112112

113113
/* See header for documentation. */
114-
PFN_vkVoidFunction getInstanceLayerFunction(const char* name)
114+
std::pair<bool, PFN_vkVoidFunction> getInstanceLayerFunction(const char* name)
115115
{
116+
const std::array<const char*, 4> globalFunctions {
117+
"vkCreateInstance",
118+
"vkEnumerateInstanceVersion",
119+
"vkEnumerateInstanceExtensionProperties",
120+
"vkEnumerateInstanceLayerProperties"
121+
};
122+
123+
bool isGlobal {false};
124+
for (const auto* globalName : globalFunctions)
125+
{
126+
if (!strcmp(globalName, name))
127+
{
128+
isGlobal = true;
129+
break;
130+
}
131+
}
132+
116133
for (auto& function : instanceIntercepts)
117134
{
118135
if (!strcmp(function.name, name))
119136
{
120-
return function.function;
137+
return {isGlobal, function.function};
121138
}
122139
}
123140

124-
return nullptr;
141+
return {isGlobal, nullptr};
125142
}
126143

127144
/* See header for documentation. */
@@ -474,9 +491,18 @@ void enableDeviceVkExtImageCompressionControl(Instance& instance,
474491
/** See Vulkan API for documentation. */
475492
PFN_vkVoidFunction layer_vkGetInstanceProcAddr_default(VkInstance instance, const char* pName)
476493
{
477-
// Only expose functions that the driver exposes to avoid changing
478-
// queryable interface behavior seen by the application
479-
auto layerFunction = getInstanceLayerFunction(pName);
494+
auto [isGlobal, layerFunction] = getInstanceLayerFunction(pName);
495+
496+
// Global functions must be exposed and do not require the caller to pass
497+
// a valid instance pointer, although it is required to be nullptr in
498+
// Vulkan 1.2.193 or later
499+
if (isGlobal)
500+
{
501+
return layerFunction;
502+
}
503+
504+
// For other functions, only expose functions that the driver exposes to
505+
// avoid changing queryable interface behavior seen by the application
480506
if (instance)
481507
{
482508
std::unique_lock<std::mutex> lock {g_vulkanLock};

source_common/framework/manual_functions.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <mutex>
4545
#include <string>
4646
#include <thread>
47+
#include <utility>
4748
#include <vector>
4849

4950
/**
@@ -85,10 +86,11 @@ PFN_vkVoidFunction getFixedInstanceLayerFunction(const char* name);
8586
*
8687
* @param name The Vulkan function name.
8788
*
88-
* @return The layer function pointer, or \c nullptr if the layer doesn't
89+
* @return Boolean indicating if this is a globally accessible function, and
90+
* the layer function pointer, or \c nullptr if the layer doesn't
8991
* intercept the function.
9092
*/
91-
PFN_vkVoidFunction getInstanceLayerFunction(const char* name);
93+
std::pair<bool, PFN_vkVoidFunction> getInstanceLayerFunction(const char* name);
9294

9395
/**
9496
* @brief Fetch the function for a given dynamic instance entrypoint name.

0 commit comments

Comments
 (0)