summaryrefslogtreecommitdiffstats
path: root/video/out/vulkan/context.c
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2024-04-07 16:18:51 +0200
committerKacper Michajłow <kasper93@gmail.com>2024-04-07 20:16:50 +0200
commit2f76536f6211a1b80f6eca2582bb79048ca220b1 (patch)
treee8153fa43167a8a8f38e0f8de7f961dcceebc09f /video/out/vulkan/context.c
parent0f4f1bcd63612f918527c5a503dfb0c43c5b7710 (diff)
downloadmpv-2f76536f6211a1b80f6eca2582bb79048ca220b1.tar.bz2
mpv-2f76536f6211a1b80f6eca2582bb79048ca220b1.tar.xz
vulkan: use pl_vk_inst_create
This change is mostly motivated by missing VK_KHR_portability_enumeration instance extension when enumerating the devices. Which causes issues with MoltenVK which does not advertise full Vulkan conformance. To avoid duplicating code use pl_vk_inst_create() which correctly query availability and enables the mentioned extension. While at it fix the VkInstance leaking in vk_validate_dev().
Diffstat (limited to 'video/out/vulkan/context.c')
-rw-r--r--video/out/vulkan/context.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/video/out/vulkan/context.c b/video/out/vulkan/context.c
index 73afefd718..82c878afec 100644
--- a/video/out/vulkan/context.c
+++ b/video/out/vulkan/context.c
@@ -25,6 +25,7 @@
#include "options/m_config.h"
#include "video/out/placebo/ra_pl.h"
+#include "video/out/placebo/utils.h"
#include "context.h"
#include "utils.h"
@@ -39,36 +40,30 @@ struct vulkan_opts {
static inline OPT_STRING_VALIDATE_FUNC(vk_validate_dev)
{
- struct bstr param = bstr0(*value);
int ret = M_OPT_INVALID;
- VkResult res;
+ void *ta_ctx = talloc_new(NULL);
+ pl_log pllog = mppl_log_create(ta_ctx, log);
+ if (!pllog)
+ goto done;
// Create a dummy instance to validate/list the devices
- VkInstanceCreateInfo info = {
- .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
- .pApplicationInfo = &(VkApplicationInfo) {
- .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
- .apiVersion = VK_API_VERSION_1_1,
- }
- };
-
- VkInstance inst;
- VkPhysicalDevice *devices = NULL;
- uint32_t num = 0;
-
- res = vkCreateInstance(&info, NULL, &inst);
- if (res != VK_SUCCESS)
+ mppl_log_set_probing(pllog, true);
+ pl_vk_inst inst = pl_vk_inst_create(pllog, pl_vk_inst_params());
+ mppl_log_set_probing(pllog, false);
+ if (!inst)
goto done;
- res = vkEnumeratePhysicalDevices(inst, &num, NULL);
+ uint32_t num = 0;
+ VkResult res = vkEnumeratePhysicalDevices(inst->instance, &num, NULL);
if (res != VK_SUCCESS)
goto done;
- devices = talloc_array(NULL, VkPhysicalDevice, num);
- res = vkEnumeratePhysicalDevices(inst, &num, devices);
+ VkPhysicalDevice *devices = talloc_array(ta_ctx, VkPhysicalDevice, num);
+ res = vkEnumeratePhysicalDevices(inst->instance, &num, devices);
if (res != VK_SUCCESS)
goto done;
+ struct bstr param = bstr0(*value);
bool help = bstr_equals0(param, "help");
if (help) {
mp_info(log, "Available vulkan devices:\n");
@@ -110,7 +105,9 @@ static inline OPT_STRING_VALIDATE_FUNC(vk_validate_dev)
BSTR_P(param));
done:
- talloc_free(devices);
+ pl_vk_inst_destroy(&inst);
+ pl_log_destroy(&pllog);
+ talloc_free(ta_ctx);
return ret;
}