mirror of
https://github.com/mpv-player/mpv
synced 2025-01-09 00:19:32 +00:00
8c1f94f0e7
Previously, there appeared to be implicit synchronisation in the GL interop path, and we never observed any visual glitches. However, recently, I started seeing stuttering in the GL path and on closer examination it looked like read-before-write behaviour where GL would display an old frame again rather than the current one. After verifying that disabling hwdec made the problem go away, I tried adding a cuStreamSynchronize() after the memcpys and that also resolved the problem, so it's clearly sync related. cuStreamSynchronize() is a CPU sync and so more heavy-weight than you want, but it's the only tool we have. There is no mechanism defined for synchronising GL to CUDA (It looks like there is a way to synchronise CUDA to EGL but it appears one way and so wouldn't directly address this problem). Anyway, empirically, the output now looks the same as with hwdec off.
63 lines
1.8 KiB
C
63 lines
1.8 KiB
C
/*
|
|
* Copyright (c) 2019 Philip Langdale <philipl@overt.org>
|
|
*
|
|
* This file is part of mpv.
|
|
*
|
|
* mpv is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* mpv is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <ffnvcodec/dynlink_loader.h>
|
|
|
|
#include "video/out/gpu/hwdec.h"
|
|
|
|
struct cuda_hw_priv {
|
|
struct mp_hwdec_ctx hwctx;
|
|
CudaFunctions *cu;
|
|
CUcontext display_ctx;
|
|
CUcontext decode_ctx;
|
|
|
|
// Stored as int to avoid depending on libplacebo enum
|
|
int handle_type;
|
|
|
|
// Do we need to do a full CPU sync after copying
|
|
bool do_full_sync;
|
|
|
|
bool (*ext_init)(struct ra_hwdec_mapper *mapper,
|
|
const struct ra_format *format, int n);
|
|
void (*ext_uninit)(const struct ra_hwdec_mapper *mapper, int n);
|
|
|
|
// These are only necessary if the gpu api requires synchronisation
|
|
bool (*ext_wait)(const struct ra_hwdec_mapper *mapper, int n);
|
|
bool (*ext_signal)(const struct ra_hwdec_mapper *mapper, int n);
|
|
};
|
|
|
|
struct cuda_mapper_priv {
|
|
struct mp_image layout;
|
|
CUarray cu_array[4];
|
|
|
|
CUcontext display_ctx;
|
|
|
|
void *ext[4];
|
|
};
|
|
|
|
typedef bool (*cuda_interop_init)(const struct ra_hwdec *hw);
|
|
|
|
bool cuda_gl_init(const struct ra_hwdec *hw);
|
|
|
|
bool cuda_vk_init(const struct ra_hwdec *hw);
|
|
|
|
int check_cu(const struct ra_hwdec *hw, CUresult err, const char *func);
|