From 62904203804afb614f4809495f1a1bb6e4006aaa Mon Sep 17 00:00:00 2001 From: Anton Kindestam Date: Sat, 28 Sep 2019 10:26:23 +0200 Subject: vo: make swapchain-depth option generic for all VOs In preparation for making vo_drm able to use swapchain-depth --- DOCS/man/options.rst | 15 +++++++-------- options/options.c | 2 ++ options/options.h | 2 ++ video/out/d3d11/context.c | 4 ++-- video/out/gpu/context.h | 1 - video/out/opengl/context.c | 2 +- video/out/opengl/context_angle.c | 4 ++-- video/out/opengl/context_drm_egl.c | 3 ++- video/out/opengl/context_dxinterop.c | 4 ++-- video/out/vo_gpu.c | 6 ------ video/out/vulkan/context.c | 2 +- 11 files changed, 21 insertions(+), 24 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index b833399a3a..0037f8e40a 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -1469,6 +1469,13 @@ Video this can break on streams not encoded by x264, or if a stream encoded by a newer x264 version contains no version info. +``--swapchain-depth=`` + Allow up to N in-flight frames. This essentially controls the frame + latency. Increasing the swapchain depth can improve pipelining and prevent + missed vsyncs, but increases visible latency. This option only mandates an + upper limit, the implementation can use a lower latency than requested + internally. A setting of 1 means that the VO will wait for every frame to + become visible before starting to render the next frame. (Default: 3) Audio ----- @@ -5170,14 +5177,6 @@ The following video options are currently all specific to ``--vo=gpu`` and Android with ``--gpu-context=android`` only. -``--swapchain-depth=`` - Allow up to N in-flight frames. This essentially controls the frame - latency. Increasing the swapchain depth can improve pipelining and prevent - missed vsyncs, but increases visible latency. This option only mandates an - upper limit, the implementation can use a lower latency than requested - internally. A setting of 1 means that the VO will wait for every frame to - become visible before starting to render the next frame. (Default: 3) - ``--gpu-sw`` Continue even if a software renderer is detected. diff --git a/options/options.c b/options/options.c index 9e74821278..7f0fde6af5 100644 --- a/options/options.c +++ b/options/options.c @@ -160,6 +160,7 @@ static const m_option_t mp_vo_opt_list[] = { #if HAVE_DRM OPT_SUBSTRUCT("", drm_opts, drm_conf, 0), #endif + OPT_INTRANGE("swapchain-depth", swapchain_depth, 0, 1, 8), {0} }; @@ -186,6 +187,7 @@ const struct m_sub_options vo_sub_opts = { .mmcss_profile = "Playback", .ontop_level = -1, .timing_offset = 0.050, + .swapchain_depth = 3, }, }; diff --git a/options/options.h b/options/options.h index d979f11e19..be76364c89 100644 --- a/options/options.h +++ b/options/options.h @@ -59,6 +59,8 @@ typedef struct mp_vo_opts { struct sws_opts *sws_opts; // vo_drm struct drm_opts *drm_opts; + + int swapchain_depth; // max number of images to render ahead } mp_vo_opts; // Subtitle options needed by the subtitle decoders/renderers. diff --git a/video/out/d3d11/context.c b/video/out/d3d11/context.c index f596fb09d4..062fdd2061 100644 --- a/video/out/d3d11/context.c +++ b/video/out/d3d11/context.c @@ -310,7 +310,7 @@ static bool d3d11_init(struct ra_ctx *ctx) .allow_warp = p->opts->warp != 0, .force_warp = p->opts->warp == 1, .max_feature_level = p->opts->feature_level, - .max_frame_latency = ctx->opts.swapchain_depth, + .max_frame_latency = ctx->vo->opts->swapchain_depth, }; if (!mp_d3d11_create_present_device(ctx->log, &dopts, &p->device)) goto error; @@ -331,7 +331,7 @@ static bool d3d11_init(struct ra_ctx *ctx) .flip = p->opts->flip, // Add one frame for the backbuffer and one frame of "slack" to reduce // contention with the window manager when acquiring the backbuffer - .length = ctx->opts.swapchain_depth + 2, + .length = ctx->vo->opts->swapchain_depth + 2, .usage = DXGI_USAGE_RENDER_TARGET_OUTPUT, }; if (!mp_d3d11_create_swapchain(p->device, ctx->log, &scopts, &p->swapchain)) diff --git a/video/out/gpu/context.h b/video/out/gpu/context.h index ef48e6053f..b080e836c8 100644 --- a/video/out/gpu/context.h +++ b/video/out/gpu/context.h @@ -10,7 +10,6 @@ struct ra_ctx_opts { int want_alpha; // create an alpha framebuffer if possible int debug; // enable debugging layers/callbacks etc. bool probing; // the backend was auto-probed - int swapchain_depth; // max number of images to render ahead }; struct ra_ctx { diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c index 9b3dd6a827..530fc54a85 100644 --- a/video/out/opengl/context.c +++ b/video/out/opengl/context.c @@ -306,7 +306,7 @@ void ra_gl_ctx_swap_buffers(struct ra_swapchain *sw) check_pattern(p, step); } - while (p->num_vsync_fences >= sw->ctx->opts.swapchain_depth) { + while (p->num_vsync_fences >= sw->ctx->vo->opts->swapchain_depth) { gl->ClientWaitSync(p->vsync_fences[0], GL_SYNC_FLUSH_COMMANDS_BIT, 1e9); gl->DeleteSync(p->vsync_fences[0]); MP_TARRAY_REMOVE_AT(p->vsync_fences, p->num_vsync_fences, 0); diff --git a/video/out/opengl/context_angle.c b/video/out/opengl/context_angle.c index 6d45e29496..76d104e9b9 100644 --- a/video/out/opengl/context_angle.c +++ b/video/out/opengl/context_angle.c @@ -226,7 +226,7 @@ static bool d3d11_device_create(struct ra_ctx *ctx) .force_warp = o->d3d11_warp == 1, .max_feature_level = o->d3d11_feature_level, .min_feature_level = D3D_FEATURE_LEVEL_9_3, - .max_frame_latency = ctx->opts.swapchain_depth, + .max_frame_latency = ctx->vo->opts->swapchain_depth, }; if (!mp_d3d11_create_present_device(vo->log, &device_opts, &p->d3d11_device)) return false; @@ -294,7 +294,7 @@ static bool d3d11_swapchain_surface_create(struct ra_ctx *ctx) .flip = o->flip, // Add one frame for the backbuffer and one frame of "slack" to reduce // contention with the window manager when acquiring the backbuffer - .length = ctx->opts.swapchain_depth + 2, + .length = ctx->vo->opts->swapchain_depth + 2, .usage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT, }; if (!mp_d3d11_create_swapchain(p->d3d11_device, vo->log, &swapchain_opts, diff --git a/video/out/opengl/context_drm_egl.c b/video/out/opengl/context_drm_egl.c index fcc31df682..736db7a4ec 100644 --- a/video/out/opengl/context_drm_egl.c +++ b/video/out/opengl/context_drm_egl.c @@ -603,7 +603,8 @@ static void drm_egl_swap_buffers(struct ra_swapchain *sw) enqueue_bo(ctx, new_bo); new_fence(ctx); - while (drain || p->gbm.num_bos > ctx->opts.swapchain_depth || !gbm_surface_has_free_buffers(p->gbm.surface)) { + while (drain || p->gbm.num_bos > ctx->vo->opts->swapchain_depth || + !gbm_surface_has_free_buffers(p->gbm.surface)) { if (p->waiting_for_flip) { wait_on_flip(ctx); swapchain_step(ctx); diff --git a/video/out/opengl/context_dxinterop.c b/video/out/opengl/context_dxinterop.c index 2e65a8956e..d4d3b874d6 100644 --- a/video/out/opengl/context_dxinterop.c +++ b/video/out/opengl/context_dxinterop.c @@ -346,7 +346,7 @@ static void fill_presentparams(struct ra_ctx *ctx, .BackBufferHeight = ctx->vo->dheight ? ctx->vo->dheight : 1, // Add one frame for the backbuffer and one frame of "slack" to reduce // contention with the window manager when acquiring the backbuffer - .BackBufferCount = ctx->opts.swapchain_depth + 2, + .BackBufferCount = ctx->vo->opts->swapchain_depth + 2, .SwapEffect = IsWindows7OrGreater() ? D3DSWAPEFFECT_FLIPEX : D3DSWAPEFFECT_FLIP, // Automatically get the backbuffer format from the display format .BackBufferFormat = D3DFMT_UNKNOWN, @@ -398,7 +398,7 @@ static int d3d_create(struct ra_ctx *ctx) return -1; } - IDirect3DDevice9Ex_SetMaximumFrameLatency(p->device, ctx->opts.swapchain_depth); + IDirect3DDevice9Ex_SetMaximumFrameLatency(p->device, ctx->vo->opts->swapchain_depth); // Register the Direct3D device with WGL_NV_dx_interop p->device_h = gl->DXOpenDeviceNV(p->device); diff --git a/video/out/vo_gpu.c b/video/out/vo_gpu.c index 0162e420e8..3229594d9f 100644 --- a/video/out/vo_gpu.c +++ b/video/out/vo_gpu.c @@ -315,14 +315,9 @@ static const m_option_t options[] = { OPT_STRING_VALIDATE("gpu-api", context_type, 0, ra_ctx_validate_api), OPT_FLAG("gpu-debug", opts.debug, 0), OPT_FLAG("gpu-sw", opts.allow_sw, 0), - OPT_INTRANGE("swapchain-depth", opts.swapchain_depth, 0, 1, 8), {0} }; -static const struct gpu_priv defaults = { .opts = { - .swapchain_depth = 3, -}}; - const struct vo_driver video_out_gpu = { .description = "Shader-based GPU Renderer", .name = "gpu", @@ -339,6 +334,5 @@ const struct vo_driver video_out_gpu = { .wakeup = wakeup, .uninit = uninit, .priv_size = sizeof(struct gpu_priv), - .priv_defaults = &defaults, .options = options, }; diff --git a/video/out/vulkan/context.c b/video/out/vulkan/context.c index f3db02f5cb..4ff48ed250 100644 --- a/video/out/vulkan/context.c +++ b/video/out/vulkan/context.c @@ -179,7 +179,7 @@ bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk, struct pl_vulkan_swapchain_params params = { .surface = vk->surface, .present_mode = preferred_mode, - .swapchain_depth = ctx->opts.swapchain_depth, + .swapchain_depth = ctx->vo->opts->swapchain_depth, }; if (p->opts->swap_mode >= 0) // user override -- cgit v1.2.3