@@ -358,43 +358,14 @@ void gloamLoaderReset{{ api | api_display }}(void) {
358358{% elif fs .spec_name == "vk" %}
359359/* ---- Vulkan built-in discovery loader ----------------------------------- */
360360
361- /* The built-in loader threads instance and device handles through this struct
362- so that a single scope-aware callback can serve all dispatch paths. */
363- struct gloam_vk_userptr {
364- void *lib_handle;
365- VkInstance instance;
366- VkDevice device;
367- PFN_vkGetInstanceProcAddr get_instance_proc_addr;
368- PFN_vkGetDeviceProcAddr get_device_proc_addr;
369- };
370-
371- static GloamAPIProc gloam_vk_get_proc(void *vuserptr, const char *name, GloamCommandScope scope) {
372- struct gloam_vk_userptr *u = (struct gloam_vk_userptr *)vuserptr;
373- switch (scope) {
374- case GloamCommandScopeUnknown:
375- return (GloamAPIProc)gloam_dlsym(u->lib_handle, name);
376- case GloamCommandScopeGlobal:
377- return (GloamAPIProc)u->get_instance_proc_addr(NULL, name);
378- case GloamCommandScopeInstance:
379- if (u->instance != NULL)
380- return (GloamAPIProc)u->get_instance_proc_addr(u->instance, name);
381- return NULL;
382- case GloamCommandScopeDevice:
383- if (u->device != NULL)
384- return (GloamAPIProc)u->get_device_proc_addr(u->device, name);
385- return NULL;
386- }
387- return NULL;
388- }
389-
390361/* gloamLoaderLoadVulkanContext
391362 *
392363 * Opens the Vulkan library into context->gloam_loader_handle if it is not
393- * already set, then delegates to gloamVulkanDiscoverContextUserPtr. Follows
394- * the same additive multi-call contract as the underlying discover function. */
364+ * already set, stores vkGetInstanceProcAddr in the context, then delegates to
365+ * gloamVulkanDiscoverContext. Follows the same additive multi-call contract
366+ * as the underlying discover function. */
395367int gloamLoaderLoadVulkanContext({{ u.ctx_arg(', ') }}VkInstance instance,
396368 VkPhysicalDevice physical_device, VkDevice device) {
397- struct gloam_vk_userptr userptr;
398369 int did_open = 0;
399370 int version;
400371 void *handle;
@@ -406,32 +377,22 @@ int gloamLoaderLoadVulkanContext({{ u.ctx_arg(', ') }}VkInstance instance,
406377 }
407378
408379 handle = context->gloam_loader_handle;
409- if (!handle) return 0;
380+ if (!handle)
381+ return 0;
410382
411- userptr.lib_handle = handle;
412- userptr.instance = instance;
413- userptr.device = device;
414- userptr.get_instance_proc_addr =
415- (PFN_vkGetInstanceProcAddr)gloam_dlsym(handle, "vkGetInstanceProcAddr");
416- userptr.get_device_proc_addr = NULL;
383+ if (!context->GetInstanceProcAddr)
384+ context->GetInstanceProcAddr =
385+ (PFN_vkGetInstanceProcAddr)gloam_dlsym(handle, "vkGetInstanceProcAddr");
417386
418- if (!userptr.get_instance_proc_addr ) {
387+ if (!context->GetInstanceProcAddr ) {
419388 if (did_open) {
420389 gloam_dlclose(handle);
421390 context->gloam_loader_handle = NULL;
422391 }
423392 return 0;
424393 }
425394
426- /* Get vkGetDeviceProcAddr through the instance when available. */
427- if (instance != NULL) {
428- userptr.get_device_proc_addr =
429- (PFN_vkGetDeviceProcAddr)userptr.get_instance_proc_addr(
430- instance, "vkGetDeviceProcAddr");
431- }
432-
433- version = gloamVulkanDiscoverContextUserPtr(context, instance, physical_device, device,
434- gloam_vk_get_proc, &userptr);
395+ version = gloamVulkanDiscoverContext(context, instance, physical_device, device);
435396 if (!version && did_open) {
436397 gloam_dlclose(handle);
437398 context->gloam_loader_handle = NULL;
0 commit comments