summaryrefslogtreecommitdiffstats
path: root/video/out
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
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')
-rw-r--r--video/out/vulkan/context.c37
-rw-r--r--video/out/vulkan/context_display.c41
2 files changed, 39 insertions, 39 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;
}
diff --git a/video/out/vulkan/context_display.c b/video/out/vulkan/context_display.c
index fd2baf0a44..72f73adb20 100644
--- a/video/out/vulkan/context_display.c
+++ b/video/out/vulkan/context_display.c
@@ -19,6 +19,7 @@
#include "context.h"
#include "options/m_config.h"
#include "utils.h"
+#include "video/out/placebo/utils.h"
#if HAVE_DRM
#include <errno.h>
@@ -215,35 +216,36 @@ done:
}
static int print_display_info(struct mp_log *log, const struct m_option *opt,
- struct bstr name) {
- VkResult res;
- VkPhysicalDevice *devices = NULL;
+ struct bstr name)
+{
+ void *ta_ctx = talloc_new(NULL);
+ pl_log pllog = mppl_log_create(ta_ctx, log);
+ if (!pllog)
+ goto done;
// Create a dummy instance to list the resources
- VkInstanceCreateInfo info = {
- .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
- .enabledExtensionCount = 1,
- .ppEnabledExtensionNames = (const char*[]) {
- VK_KHR_DISPLAY_EXTENSION_NAME
+ mppl_log_set_probing(pllog, true);
+ pl_vk_inst inst = pl_vk_inst_create(pllog, pl_vk_inst_params(
+ .extensions = (const char *[]){
+ VK_KHR_DISPLAY_EXTENSION_NAME,
},
- };
-
- VkInstance inst = NULL;
- res = vkCreateInstance(&info, NULL, &inst);
- if (res != VK_SUCCESS) {
+ .num_extensions = 1,
+ ));
+ mppl_log_set_probing(pllog, false);
+ if (!inst) {
mp_warn(log, "Unable to create Vulkan instance.\n");
goto done;
}
uint32_t num_devices = 0;
- vkEnumeratePhysicalDevices(inst, &num_devices, NULL);
- if (!num_devices) {
+ VkResult res = vkEnumeratePhysicalDevices(inst->instance, &num_devices, NULL);
+ if (res != VK_SUCCESS || !num_devices) {
mp_info(log, "No Vulkan devices detected.\n");
goto done;
}
- devices = talloc_array(NULL, VkPhysicalDevice, num_devices);
- vkEnumeratePhysicalDevices(inst, &num_devices, devices);
+ VkPhysicalDevice *devices = talloc_array(ta_ctx, VkPhysicalDevice, num_devices);
+ res = vkEnumeratePhysicalDevices(inst->instance, &num_devices, devices);
if (res != VK_SUCCESS) {
mp_warn(log, "Failed enumerating physical devices.\n");
goto done;
@@ -255,8 +257,9 @@ static int print_display_info(struct mp_log *log, const struct m_option *opt,
}
done:
- talloc_free(devices);
- vkDestroyInstance(inst, NULL);
+ pl_vk_inst_destroy(&inst);
+ pl_log_destroy(&pllog);
+ talloc_free(ta_ctx);
return M_OPT_EXIT;
}