vkCreateWin32SurfaceKHR succeeds when the HWND is bad

The function vkCreateWin32SurfaceKHR takes a VkWin32SurfaceCreateInfoKHR structure. When that structure’s hwnd field is not 0, but is not a valid window handle, vkCreateWin32SurfaceKHR will return VK_SUCCESS. Passing an invalid hwnd will result in some functions returning an VK_ERROR_SURFACE_LOST_KHR error when called using the surface created with an invalid hwnd.

While this is clearly an issue with the application’s code, and not so much an implementation bug, the driver clearly can tell that there’s something wrong with the window handle but instead of giving an error during the surface creation, it succeeds and fails when you try to use the surface.

Would it be possible to make vkCreateWin32SurfaceKHR fail if the window handle is not valid?

vkCreateWin32SurfaceKHR is actually implemented by the loader, unless the driver opts-in to do it and both the loader and driver support this opt-in:

So, in theory, the loader could do this, or you could do this yourself (which kinda defeats the point). But i have seen a similar request on LunarXchange and it was rejected for validation layers as there seems to be no feasible way to do this.

And the validation layers are really the only appropriate place for such a test. The driver assumes you do the right thing, so i would not want this kind of test in a release run.

Regards