diff --git a/src/gpu.cpp b/src/gpu.cpp index f5ce57394..eaec7e40a 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -1612,6 +1612,11 @@ int create_gpu_instance() return 0; } +VkInstance get_gpu_instance() +{ + return (VkInstance)g_instance; +} + void destroy_gpu_instance() { MutexLockGuard lock(g_instance_lock); diff --git a/src/gpu.h b/src/gpu.h index 497cba44e..4b6484486 100644 --- a/src/gpu.h +++ b/src/gpu.h @@ -28,7 +28,19 @@ namespace ncnn { // instance + +// Create VkInstance and initialize some objects that need to be calculated by GPU +// Creates a VkInstance object, Checks the extended attributes supported by the Vulkan instance concerned, +// Initializes, and creates Vulkan validation layers (if ENABLE_VALIDATION_LAYER is enabled), +// Iterates over all supported physical devices, etc. NCNN_EXPORT int create_gpu_instance(); + +// Get global VkInstance variable +// Must be called after create_gpu_instance() and before destroy_gpu_instance() +NCNN_EXPORT VkInstance get_gpu_instance(); + +// Destroy VkInstance object and free the memory of the associated object +// Usually called in the destructor of the main program exit NCNN_EXPORT void destroy_gpu_instance(); // instance extension capability