Document layer requirements for querying vkCreateInstance from GIPA
authorCharles Giessen <charles@lunarg.com>
Tue, 3 Sep 2024 20:55:31 +0000 (15:55 -0500)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Tue, 3 Sep 2024 22:55:38 +0000 (16:55 -0600)
The vkGetInstanceProcAddr function was ammended in header version 1.2.193
to require global functions be queried with NULL instance parameters,
including vkCreateInstance. Layers written before that time may not expect
the instance parameter to be NULL, so in order to maintain compatibility,
the loader code (which itself dates to before Vulkan's public release) is
left unmodified.

Instead, code comments were left to indicate the non-spec compliant
implementation as well as documentation in the LoaderLayerInterface mentioning
how layers should handle the now invalid API usage.

In the future, the loader could be modified to correctly follow the spec, but
a survey of existing and previous layer implementations would need to be done
to determine the impact of the change.

docs/LoaderLayerInterface.md
loader/loader.c

index 6ca9bc57cef5b94889e5865b7c2700d8192d4f89..08a417550879c9c65e41fb0612f0d109197abb4c 100644 (file)
@@ -986,7 +986,15 @@ ignore `instance` when `pName` is `vkCreateDevice`.
   - The specification **requires** `NULL` to be returned from
 `vkGetInstanceProcAddr` and `vkGetDeviceProcAddr` for disabled functions.
     - A layer may return `NULL` itself or rely on the following layers to do so.
-
+  - A layer's implementation `vkGetInstanceProcAddr` **should**, when querying for
+`vkCreateInstance`, return a valid function pointer regardless of the value of the
+`instance` parameter.
+    - The specification **requires** that the `instance` parameter **must** be NULL.
+However, older versions of the specification did not have this requirement, allowing
+for non-NULL `instance` handles to be passed in and return a valid `vkCreateInstance`
+function pointer. The Vulkan-Loader itself does this and will continue to do so to
+maintain compatibility with layers which were released before this specification
+change was made.
 
 ## Layer Dispatch Initialization
 
index 531146a958e854deab96691394f0a9eb0055206a..525334c7c73e63d87c0f95a98c43c603ea64d6f7 100644 (file)
@@ -4751,6 +4751,11 @@ VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, c
     feature_flags = windows_initialize_dxgi();
 #endif
 
+    // The following line of code is actually invalid at least according to the Vulkan spec with header update 1.2.193 and onwards.
+    // The update required calls to vkGetInstanceProcAddr querying "global" functions (which includes vkCreateInstance) to pass NULL
+    // for the instance parameter. Because it wasn't required to be NULL before, there may be layers which expect the loader's
+    // behavior of passing a non-NULL value into vkGetInstanceProcAddr.
+    // In an abundance of caution, the incorrect code remains as is, with a big comment to indicate that its wrong
     PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)next_gipa(*created_instance, "vkCreateInstance");
     if (fpCreateInstance) {
         VkLayerInstanceCreateInfo instance_dispatch;