0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

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().
This commit is contained in:
Kacper Michajłow 2024-04-07 16:18:51 +02:00
parent 0f4f1bcd63
commit 2f76536f62
2 changed files with 39 additions and 39 deletions

View File

@ -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,
}
};
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;
VkInstance inst;
VkPhysicalDevice *devices = NULL;
uint32_t num = 0;
res = vkCreateInstance(&info, NULL, &inst);
VkResult res = vkEnumeratePhysicalDevices(inst->instance, &num, NULL);
if (res != VK_SUCCESS)
goto done;
res = vkEnumeratePhysicalDevices(inst, &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;
}

View File

@ -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;
}