Skip to content

Commit ba6b2aa

Browse files
authored
Framework: vkCreateDevice uses Instance dispatch table (#129)
This changes the code in vkCreateDevice to use the instance methods queried during vkCreateInstance, rather than re-fetching them from the chain.
1 parent 0653762 commit ba6b2aa

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

source_common/framework/manual_functions.cpp

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,11 @@ APIVersion getApplicationAPIVersion(const VkInstanceCreateInfo* pCreateInfo)
178178
}
179179

180180
/* See header for documentation. */
181-
APIVersion getDeviceAPIVersion(PFN_vkGetInstanceProcAddr fpGetProcAddr,
182-
VkInstance instance,
181+
APIVersion getDeviceAPIVersion(Instance& instance,
183182
VkPhysicalDevice physicalDevice)
184183
{
185-
auto fpFunctionRaw = fpGetProcAddr(instance, "vkGetPhysicalDeviceProperties");
186-
auto fpFunction = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(fpFunctionRaw);
187-
if (!fpFunction)
188-
{
189-
LAYER_ERR("Failed to get vkGetPhysicalDeviceProperties()");
190-
return {0, 0};
191-
}
192-
193184
VkPhysicalDeviceProperties properties {};
194-
fpFunction(physicalDevice, &properties);
185+
instance.driver.vkGetPhysicalDeviceProperties(physicalDevice, &properties);
195186

196187
uint32_t major = VK_API_VERSION_MAJOR(properties.apiVersion);
197188
uint32_t minor = VK_API_VERSION_MINOR(properties.apiVersion);
@@ -291,32 +282,21 @@ std::vector<std::string> getInstanceExtensionList(const VkInstanceCreateInfo* pC
291282
}
292283

293284
/* See header for documentation. */
294-
std::vector<std::string> getDeviceExtensionList(VkInstance instance,
295-
VkPhysicalDevice physicalDevice,
296-
const VkDeviceCreateInfo* pCreateInfo)
285+
std::vector<std::string> getDeviceExtensionList(Instance& instance,
286+
VkPhysicalDevice physicalDevice)
297287
{
298-
std::vector<std::string> foundExtensions;
299-
300-
// Fetch the functions needed to query extensions availability
301-
auto* chainInfo = getChainInfo(pCreateInfo);
302-
auto fpGetProcAddr = chainInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr;
303-
auto fpGetExtensionsRaw = fpGetProcAddr(instance, "vkEnumerateDeviceExtensionProperties");
304-
auto fpGetExtensions = reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>(fpGetExtensionsRaw);
305-
if (!fpGetExtensions)
306-
{
307-
return foundExtensions;
308-
}
309-
310288
// Query number of extensions
311289
uint32_t count;
312-
fpGetExtensions(physicalDevice, nullptr, &count, nullptr);
290+
instance.driver.vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &count, nullptr);
313291

314292
// Reserve memory for, and then query, the extensions
315293
std::vector<VkExtensionProperties> extensions;
316294
extensions.resize(count);
317-
fpGetExtensions(physicalDevice, nullptr, &count, extensions.data());
295+
instance.driver.vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &count, extensions.data());
318296

319297
// Build the function return list
298+
std::vector<std::string> foundExtensions;
299+
foundExtensions.reserve(count);
320300
for (uint32_t i = 0; i < count; i++)
321301
{
322302
foundExtensions.emplace_back(extensions[i].extensionName);
@@ -329,6 +309,7 @@ std::vector<std::string> getDeviceExtensionList(VkInstance instance,
329309
std::vector<const char*> cloneExtensionList(uint32_t extensionCount, const char* const* extensionList)
330310
{
331311
std::vector<const char*> data;
312+
data.reserve(extensionCount);
332313
for (uint32_t i = 0; i < extensionCount; i++)
333314
{
334315
data.emplace_back(extensionList[i]);
@@ -763,15 +744,15 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default(VkPhysicalDevice phy
763744
lock.unlock();
764745

765746
// Get the list is supported extensions
766-
auto supportedExtensions = getDeviceExtensionList(layer->instance, physicalDevice, pCreateInfo);
747+
auto supportedExtensions = getDeviceExtensionList(*layer, physicalDevice);
767748

768749
// Query the supported Vulkan version
769750
auto* chainInfo = getChainInfo(pCreateInfo);
770751
auto fpGetInstanceProcAddr = chainInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr;
771752
auto fpGetDeviceProcAddr = chainInfo->u.pLayerInfo->pfnNextGetDeviceProcAddr;
772753

773754
// Log this for support purposes ...
774-
APIVersion apiVersion = getDeviceAPIVersion(fpGetInstanceProcAddr, layer->instance, physicalDevice);
755+
APIVersion apiVersion = getDeviceAPIVersion(*layer, physicalDevice);
775756
LAYER_LOG("Device API version %u.%u", apiVersion.first, apiVersion.second);
776757

777758
// Create a modifiable structure we can patch
@@ -790,7 +771,9 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default(VkPhysicalDevice phy
790771
LAYER_LOG("Requested device extension list: [%u] = %s", i, newCreateInfo->ppEnabledExtensionNames[i]);
791772
}
792773

793-
// TODO: Issue #123: Why can't we just use layer.driver.vkGetInstanceProcAddr?
774+
// This must be resolved here rather than via the instance tables because
775+
// the desktop loader sets this up on device creation, however now that
776+
// device-time layers are deprecated this may no longer be necessary
794777
auto fpCreateDeviceRaw = fpGetInstanceProcAddr(layer->instance, "vkCreateDevice");
795778
auto fpCreateDevice = reinterpret_cast<PFN_vkCreateDevice>(fpCreateDeviceRaw);
796779
if (!fpCreateDevice)

0 commit comments

Comments
 (0)