Hi fellow vulkan programmers
I have a few questions about proper adding instance extensions and new layers to vkInstanceCreateInfo in vkCreateInstance inside another layer
- Firsly in layer manifest file there is a section with instance_extension
“instance_extensions”: [
{
“name”: “VK_KHR_get_physical_device_properties2”,
“spec_version”: “2”
}
]
Does it have only informative nature or does it actually do something ?
I didn’t notice any changes when i put that section in json file. I had
to add infotmation about that instance extension in vkCreateInstance either way.
-
If my layer uses another layer if available should I put this information in json file (it is not meta layer) ?
-
Assuming that vulkan application doesn’t fill vkInstanceCreateInfo with instance extensions and layers
that I need. I destroy that instance and create another one with needed data added. But I’m not sure I did that
correctly because on AMD graphic card it crashes while destroying old instance (it works on NVIDIA). It is possible
to not destroy old instance and it will work but I don’t think it is proper way to do that.
VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(
const VkInstanceCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkInstance* pInstance)
{
VkLayerInstanceDispatchTable* pDispatchTable = *((VkLayerInstanceDispatchTable **)*pInstance);
VkLayerInstanceCreateInfo* pLayerCreateInfo = (VkLayerInstanceCreateInfo *)pCreateInfo->pNext;
// step through the chain of pNext until we get to the link info
while (pLayerCreateInfo && (pLayerCreateInfo->sType != VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO || pLayerCreateInfo->function != VK_LAYER_LINK_INFO))
{
pLayerCreateInfo = (VkLayerInstanceCreateInfo *)pLayerCreateInfo->pNext;
}
if (nullptr == pLayerCreateInfo)
{
// No loader instance create info
return VK_ERROR_INITIALIZATION_FAILED;
}
PFN_vkGetInstanceProcAddr vkNextGetInstanceProcAddr = pLayerCreateInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr;
// move chain on for next layer
pLayerCreateInfo->u.pLayerInfo = pLayerCreateInfo->u.pLayerInfo->pNext;
//........... Adding instance extensions and layers if available and not active code
if(createNewInstance) // This variable is true if new extensions or layers has been added
{
VkLayerInstanceDispatchTable* pInstanceDispatch = *((VkLayerInstanceDispatchTable **)*pInstance);
PFN_vkCreateInstance pLoaderCreateInstance = (PFN_vkCreateInstance)pInstanceDispatch->GetInstanceProcAddr(nullptr, "vkCreateInstance");
PFN_vkCreateInstance pNextCreateInstance = (PFN_vkCreateInstance)vkNextGetInstanceProcAddr(VK_NULL_HANDLE, "vkCreateInstance");
VkResult ret = pNextCreateInstance(&oldCreateInfo, pAllocator, pInstance); // Send information about creating instance to next layer
PFN_vkDestroyInstance pLoaderDestroyInstance = (PFN_vkDestroyInstance)vkNextGetInstanceProcAddr(*pInstance, "vkDestroyInstance");
pLoaderDestroyInstance(*pInstance, pAllocator); // Destroy instance with old vkInstanceCreateInfo. It crashes on AMD cards but works on NVIDIA
VkResult result = pLoaderCreateInstance(&newCreateInfo, pAllocator, pInstance); // Creating instance with new vkInstanceCreateInfo it will call this function again
return result;
}
PFN_vkCreateInstance vkNextCreateInstance = (PFN_vkCreateInstance)vkNextGetInstanceProcAddr(VK_NULL_HANDLE, "vkCreateInstance");
VkResult ret = vkNextCreateInstance(pCreateInfo, pAllocator, pInstance);
return ret;
}
I tested that code with VIA and it didn’t catch any errors. What did I do wrong ?