LWJGL Forum
Programming => Vulkan => Topic started by: juha on February 24, 2020, 10:51:25
-
Hello all,
First post here, on a journey to learn Vulkan. I've hit an issue I need some help with.
According to Vulkan spec, the vkGetInstanceProcAddr() should allow a NULL Vulkan instance argument when querying non-instance specific commands:
3.1. Command Function Pointers
PFN_vkVoidFunction vkGetInstanceProcAddr(
VkInstance instance,
const char* pName);
instance is the instance that the function pointer will be compatible with, or NULL for commands not dependent on any instance.
I am attempting to query the presence of vkEnumerateInstanceVersion() which was added to Vulkan 1.1 and is not present in Vulkan 1.0.
According to Javadoc: https://javadoc.lwjgl.org/org/lwjgl/vulkan/VK10.html#nvkGetInstanceProcAddr(org.lwjgl.vulkan.VkInstance,long) (https://javadoc.lwjgl.org/org/lwjgl/vulkan/VK10.html#nvkGetInstanceProcAddr(org.lwjgl.vulkan.VkInstance,long))
vkGetInstanceProcAddr behavior
instance pName return value
---------------------------------------------------------------------------------------------
* NULL undefined
invalid instance * undefined
NULL EnumerateInstanceVersion fp
Also from https://javadoc.lwjgl.org/org/lwjgl/vulkan/VkApplicationInfo.html (https://javadoc.lwjgl.org/org/lwjgl/vulkan/VkApplicationInfo.html)
Because Vulkan 1.0 implementations may fail with ERROR_INCOMPATIBLE_DRIVER, applications should determine the version of Vulkan available before calling CreateInstance. If the GetInstanceProcAddr returns NULL for EnumerateInstanceVersion, it is a Vulkan 1.0 implementation. Otherwise, the application can call EnumerateInstanceVersion to determine the version of Vulkan.
However, a method call yields a NullPointerException:
VK10.vkGetInstanceProcAddr(null, "vkEnumerateInstanceVersion");
Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.vulkan.VK10.nvkGetInstanceProcAddr(VK10.java:3322)
at org.lwjgl.vulkan.VK10.vkGetInstanceProcAddr(VK10.java:3461)
Presumably due to address() being called on a null instance.
Am I misunderstanding how the API should be used, or should a null argument for instance be allowed, and checked?
-
One rather unpleasant workaround seems to be to force creation of Vulkan instance at zero address, i.e. NULL handle. This requires turning off some basic LWJGL safety checks:
Configuration.DISABLE_CHECKS.set(true);
...
long eivAddress = VK10.vkGetInstanceProcAddr(
new VkInstance(
VK10.VK_NULL_HANDLE,
VkInstanceCreateInfo.calloc()
.sType(VK10.VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
),
"vkEnumerateInstanceVersion"
);
if (eivAddress != VK10.VK_NULL_HANDLE)
{
System.err.println(">> NOT VERSION 1.0");
}
-
Hey juha,
Thank you for this post, I'm exploring a way to address this.
-
This will be fixed in the next 3.2.4 snapshot.
-
Excellent. Thanks for your work on this.