diff options
Diffstat (limited to 'video/out/vulkan')
-rw-r--r-- | video/out/vulkan/context.c | 95 | ||||
-rw-r--r-- | video/out/vulkan/context.h | 6 | ||||
-rw-r--r-- | video/out/vulkan/context_android.c | 1 | ||||
-rw-r--r-- | video/out/vulkan/context_display.c | 42 | ||||
-rw-r--r-- | video/out/vulkan/context_mac.m | 10 | ||||
-rw-r--r-- | video/out/vulkan/context_wayland.c | 1 | ||||
-rw-r--r-- | video/out/vulkan/context_win.c | 1 | ||||
-rw-r--r-- | video/out/vulkan/context_xlib.c | 1 |
8 files changed, 93 insertions, 64 deletions
diff --git a/video/out/vulkan/context.c b/video/out/vulkan/context.c index 73afefd718..196f6f468d 100644 --- a/video/out/vulkan/context.c +++ b/video/out/vulkan/context.c @@ -25,9 +25,9 @@ #include "options/m_config.h" #include "video/out/placebo/ra_pl.h" +#include "video/out/placebo/utils.h" #include "context.h" -#include "utils.h" struct vulkan_opts { char *device; // force a specific GPU @@ -39,36 +39,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 +104,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; } @@ -177,19 +173,11 @@ void ra_vk_ctx_uninit(struct ra_ctx *ctx) TA_FREEP(&ctx->swapchain); } -bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk, - struct ra_vk_ctx_params params, - VkPresentModeKHR preferred_mode) +pl_vulkan mppl_create_vulkan(struct vulkan_opts *opts, + pl_vk_inst vkinst, + pl_log pllog, + VkSurfaceKHR surface) { - struct ra_swapchain *sw = ctx->swapchain = talloc_zero(NULL, struct ra_swapchain); - sw->ctx = ctx; - sw->fns = &vulkan_swapchain; - - struct priv *p = sw->priv = talloc_zero(sw, struct priv); - p->vk = vk; - p->params = params; - p->opts = mp_get_config_group(p, ctx->global, &vulkan_conf); - VkPhysicalDeviceFeatures2 features = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, }; @@ -227,30 +215,47 @@ bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk, #endif AVUUID param_uuid = { 0 }; - bool is_uuid = p->opts->device && - av_uuid_parse(p->opts->device, param_uuid) == 0; + bool is_uuid = opts->device && + av_uuid_parse(opts->device, param_uuid) == 0; - assert(vk->pllog); - assert(vk->vkinst); + assert(pllog); + assert(vkinst); struct pl_vulkan_params device_params = { - .instance = vk->vkinst->instance, - .get_proc_addr = vk->vkinst->get_proc_addr, - .surface = vk->surface, - .async_transfer = p->opts->async_transfer, - .async_compute = p->opts->async_compute, - .queue_count = p->opts->queue_count, + .instance = vkinst->instance, + .get_proc_addr = vkinst->get_proc_addr, + .surface = surface, + .async_transfer = opts->async_transfer, + .async_compute = opts->async_compute, + .queue_count = opts->queue_count, #if HAVE_VULKAN_INTEROP .extra_queues = VK_QUEUE_VIDEO_DECODE_BIT_KHR, .opt_extensions = opt_extensions, .num_opt_extensions = MP_ARRAY_SIZE(opt_extensions), #endif .features = &features, - .device_name = is_uuid ? NULL : p->opts->device, + .device_name = is_uuid ? NULL : opts->device, }; if (is_uuid) av_uuid_copy(device_params.device_uuid, param_uuid); - vk->vulkan = pl_vulkan_create(vk->pllog, &device_params); + return pl_vulkan_create(pllog, &device_params); + +} + +bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk, + struct ra_vk_ctx_params params, + VkPresentModeKHR preferred_mode) +{ + struct ra_swapchain *sw = ctx->swapchain = talloc_zero(NULL, struct ra_swapchain); + sw->ctx = ctx; + sw->fns = &vulkan_swapchain; + + struct priv *p = sw->priv = talloc_zero(sw, struct priv); + p->vk = vk; + p->params = params; + p->opts = mp_get_config_group(p, ctx->global, &vulkan_conf); + + vk->vulkan = mppl_create_vulkan(p->opts, vk->vkinst, vk->pllog, vk->surface); if (!vk->vulkan) goto error; diff --git a/video/out/vulkan/context.h b/video/out/vulkan/context.h index c846942b0e..32f08bf2d8 100644 --- a/video/out/vulkan/context.h +++ b/video/out/vulkan/context.h @@ -21,6 +21,12 @@ bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk, struct ra_vk_ctx_params params, VkPresentModeKHR preferred_mode); +// Helper for initializing mpvk_ctx->vulkan +pl_vulkan mppl_create_vulkan(struct vulkan_opts *opts, + pl_vk_inst vkinst, + pl_log pllog, + VkSurfaceKHR surface); + // Handles a resize request, and updates ctx->vo->dwidth/dheight bool ra_vk_ctx_resize(struct ra_ctx *ctx, int width, int height); diff --git a/video/out/vulkan/context_android.c b/video/out/vulkan/context_android.c index ddab3917f1..d668bb4b94 100644 --- a/video/out/vulkan/context_android.c +++ b/video/out/vulkan/context_android.c @@ -89,6 +89,7 @@ static int android_control(struct ra_ctx *ctx, int *events, int request, void *a const struct ra_ctx_fns ra_ctx_vulkan_android = { .type = "vulkan", .name = "androidvk", + .description = "Android/Vulkan", .reconfig = android_reconfig, .control = android_control, .init = android_init, diff --git a/video/out/vulkan/context_display.c b/video/out/vulkan/context_display.c index fd2baf0a44..7e3bc8ea2f 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; } @@ -483,6 +486,7 @@ static void display_wait_events(struct ra_ctx *ctx, int64_t until_time_ns) const struct ra_ctx_fns ra_ctx_vulkan_display = { .type = "vulkan", .name = "displayvk", + .description = "VK_KHR_display", .reconfig = display_reconfig, .control = display_control, .wakeup = display_wakeup, diff --git a/video/out/vulkan/context_mac.m b/video/out/vulkan/context_mac.m index 5621e6dca3..66093dd110 100644 --- a/video/out/vulkan/context_mac.m +++ b/video/out/vulkan/context_mac.m @@ -15,6 +15,8 @@ * License along with mpv. If not, see <http://www.gnu.org/licenses/>. */ +#import <QuartzCore/QuartzCore.h> + #include "video/out/gpu/context.h" #include "osdep/mac/swift.h" @@ -42,6 +44,12 @@ static void mac_vk_swap_buffers(struct ra_ctx *ctx) [p->vo_mac swapBuffer]; } +static void mac_vk_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info) +{ + struct priv *p = ctx->priv; + [p->vo_mac fillVsyncWithInfo:info]; +} + static bool mac_vk_init(struct ra_ctx *ctx) { struct priv *p = ctx->priv = talloc_zero(ctx, struct priv); @@ -64,6 +72,7 @@ static bool mac_vk_init(struct ra_ctx *ctx) struct ra_vk_ctx_params params = { .swap_buffers = mac_vk_swap_buffers, + .get_vsync = mac_vk_get_vsync, }; VkInstance inst = vk->vkinst->instance; @@ -119,6 +128,7 @@ static int mac_vk_control(struct ra_ctx *ctx, int *events, int request, void *ar const struct ra_ctx_fns ra_ctx_vulkan_mac = { .type = "vulkan", .name = "macvk", + .description = "mac/Vulkan (via Metal)", .reconfig = mac_vk_reconfig, .control = mac_vk_control, .init = mac_vk_init, diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c index cdf1ba60b8..3af644ab8a 100644 --- a/video/out/vulkan/context_wayland.c +++ b/video/out/vulkan/context_wayland.c @@ -157,6 +157,7 @@ static void wayland_vk_update_render_opts(struct ra_ctx *ctx) const struct ra_ctx_fns ra_ctx_vulkan_wayland = { .type = "vulkan", .name = "waylandvk", + .description = "Wayland/Vulkan", .reconfig = wayland_vk_reconfig, .control = wayland_vk_control, .wakeup = wayland_vk_wakeup, diff --git a/video/out/vulkan/context_win.c b/video/out/vulkan/context_win.c index 328753fa69..6484a31355 100644 --- a/video/out/vulkan/context_win.c +++ b/video/out/vulkan/context_win.c @@ -107,6 +107,7 @@ static void win_update_render_opts(struct ra_ctx *ctx) const struct ra_ctx_fns ra_ctx_vulkan_win = { .type = "vulkan", .name = "winvk", + .description = "Win32/Vulkan", .reconfig = win_reconfig, .control = win_control, .update_render_opts = win_update_render_opts, diff --git a/video/out/vulkan/context_xlib.c b/video/out/vulkan/context_xlib.c index 673dc312b7..dadfabdeb8 100644 --- a/video/out/vulkan/context_xlib.c +++ b/video/out/vulkan/context_xlib.c @@ -134,6 +134,7 @@ static void xlib_wait_events(struct ra_ctx *ctx, int64_t until_time_ns) const struct ra_ctx_fns ra_ctx_vulkan_xlib = { .type = "vulkan", .name = "x11vk", + .description = "X11/Vulkan", .reconfig = xlib_reconfig, .control = xlib_control, .wakeup = xlib_wakeup, |