// Copyright 2019-2023, Collabora, Ltd.
// Copyright 2025-2026, NVIDIA CORPORATION.
// SPDX-License-Identifier: BSL-1.0
/*!
 * @file
 * @brief Functions to fill in the functions.
 *
 * Note that some functionality in this file is generated by the script
 * `src/xrt/auxiliary/vk/vk_generate_inc_files.py`. The generated parts are
 * included via .c.inc files.
 *
 * @author Jakob Bornecrantz <jakob@collabora.com>
 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
 * @author Moshi Turner <moshiturner@protonmail.com>
 * @ingroup aux_vk
 */

#include "vk/vk_helpers.h"


/*
 *
 * Helpers.
 *
 */

#define GET_PROC(vk, name) (PFN_##name) vk->vkGetInstanceProcAddr(NULL, #name);

#define GET_INS_PROC(vk, name) (PFN_##name) vk->vkGetInstanceProcAddr(vk->instance, #name);

#define GET_DEV_PROC(vk, name) (PFN_##name) vk->vkGetDeviceProcAddr(vk->device, #name);


/*
 *
 * 'Exported' functions.
 *
 */

VkResult
vk_get_loader_functions(struct vk_bundle *vk, PFN_vkGetInstanceProcAddr g)
{
	vk->vkGetInstanceProcAddr = g;

	// Fill in all loader functions.
	// clang-format off
	vk->vkCreateInstance = GET_PROC(vk, vkCreateInstance);
	vk->vkEnumerateInstanceExtensionProperties = GET_PROC(vk, vkEnumerateInstanceExtensionProperties);
	// clang-format on

	return VK_SUCCESS;
}

VkResult
vk_get_instance_functions(struct vk_bundle *vk)
{
	// Include the generated function loading code.
#include "vk_function_loaders_instance.c.inc"

	return VK_SUCCESS;
}

VkResult
vk_get_device_functions(struct vk_bundle *vk)
{
	// Include the generated function loading code.
#include "vk_function_loaders_device.c.inc"

	return VK_SUCCESS;
}
