1
0
mirror of https://github.com/jojo61/vdr-plugin-softhdcuvid.git synced 2023-10-10 13:37:41 +02:00

Improved libplacebo opengl performance for UHD content

This commit is contained in:
jojo61 2021-01-28 12:59:58 +01:00
parent d553a8108d
commit 8018f7d921

58
video.c
View File

@ -345,7 +345,7 @@ typedef struct
#endif #endif
#ifdef CUVID #ifdef CUVID
#define PIXEL_FORMAT AV_PIX_FMT_CUDA #define PIXEL_FORMAT AV_PIX_FMT_CUDA
#define SWAP_BUFFER_SIZE 1 #define SWAP_BUFFER_SIZE 3
#endif #endif
#if defined RASPI #if defined RASPI
#define PIXEL_FORMAT AV_PIX_FMT_MMAL #define PIXEL_FORMAT AV_PIX_FMT_MMAL
@ -3807,11 +3807,11 @@ static void CuvidMixVideo(CuvidDecoder * decoder, __attribute__((unused))
memcpy(&deband, &pl_deband_default_params, sizeof(deband)); memcpy(&deband, &pl_deband_default_params, sizeof(deband));
memcpy(&render_params, &pl_render_default_params, sizeof(render_params)); memcpy(&render_params, &pl_render_default_params, sizeof(render_params));
render_params.deband_params = &deband;
switch (decoder->ColorSpace) { switch (decoder->ColorSpace) {
case AVCOL_SPC_RGB: // BT 601 is reportet as RGB case AVCOL_SPC_RGB: // BT 601 is reportet as RGB
img->repr.sys = PL_COLOR_SYSTEM_BT_601; memcpy(&img->repr, &pl_color_repr_sdtv, sizeof(struct pl_color_repr));
img->repr.levels = PL_COLOR_LEVELS_TV;
img->color.primaries = PL_COLOR_PRIM_BT_601_625; img->color.primaries = PL_COLOR_PRIM_BT_601_625;
img->color.transfer = PL_COLOR_TRC_BT_1886; img->color.transfer = PL_COLOR_TRC_BT_1886;
img->color.light = PL_COLOR_LIGHT_DISPLAY; img->color.light = PL_COLOR_LIGHT_DISPLAY;
@ -3819,19 +3819,12 @@ static void CuvidMixVideo(CuvidDecoder * decoder, __attribute__((unused))
break; break;
case AVCOL_SPC_BT709: case AVCOL_SPC_BT709:
case AVCOL_SPC_UNSPECIFIED: // comes with UHD case AVCOL_SPC_UNSPECIFIED: // comes with UHD
img->repr.sys = PL_COLOR_SYSTEM_BT_709; memcpy(&img->repr, &pl_color_repr_hdtv, sizeof(struct pl_color_repr));
img->repr.levels = PL_COLOR_LEVELS_TV;
memcpy(&img->color, &pl_color_space_bt709, sizeof(struct pl_color_space)); memcpy(&img->color, &pl_color_space_bt709, sizeof(struct pl_color_space));
// img->color.primaries = PL_COLOR_PRIM_BT_709;
// img->color.transfer = PL_COLOR_TRC_BT_1886;
// img->color.light = PL_COLOR_LIGHT_SCENE_709_1886;
// img->color.light = PL_COLOR_LIGHT_DISPLAY;
pl->shift_x = -0.5f; pl->shift_x = -0.5f;
break; break;
case AVCOL_SPC_BT2020_NCL: case AVCOL_SPC_BT2020_NCL:
img->repr.sys = PL_COLOR_SYSTEM_BT_2020_NC;
img->repr.levels = PL_COLOR_LEVELS_TV;
memcpy(&img->repr, &pl_color_repr_uhdtv, sizeof(struct pl_color_repr)); memcpy(&img->repr, &pl_color_repr_uhdtv, sizeof(struct pl_color_repr));
memcpy(&img->color, &pl_color_space_bt2020_hlg, sizeof(struct pl_color_space)); memcpy(&img->color, &pl_color_space_bt2020_hlg, sizeof(struct pl_color_space));
deband.grain = 0.0f; // no grain in HDR deband.grain = 0.0f; // no grain in HDR
@ -3839,19 +3832,15 @@ static void CuvidMixVideo(CuvidDecoder * decoder, __attribute__((unused))
pl->shift_x = -0.5f; pl->shift_x = -0.5f;
#if defined VAAPI || defined USE_DRM #if defined VAAPI || defined USE_DRM
render_params.peak_detect_params = NULL; render_params.peak_detect_params = NULL;
render_params.deband_params = NULL;
render_params.dither_params = NULL;
render_params.skip_anti_aliasing = true;
#endif #endif
// img->color.primaries = PL_COLOR_PRIM_BT_2020;
// img->color.transfer = PL_COLOR_TRC_HLG;
// img->color.light = PL_COLOR_LIGHT_SCENE_HLG;
break; break;
default: // fallback default: // fallback
img->repr.sys = PL_COLOR_SYSTEM_BT_709; memcpy(&img->repr, &pl_color_repr_hdtv, sizeof(struct pl_color_repr));
img->repr.levels = PL_COLOR_LEVELS_TV;
memcpy(&img->color, &pl_color_space_bt709, sizeof(struct pl_color_space)); memcpy(&img->color, &pl_color_space_bt709, sizeof(struct pl_color_space));
// img->color.primaries = PL_COLOR_PRIM_BT_709;
// img->color.transfer = PL_COLOR_TRC_BT_1886;
// img->color.light = PL_COLOR_LIGHT_DISPLAY;
pl->shift_x = -0.5f; pl->shift_x = -0.5f;
break; break;
} }
@ -3955,7 +3944,6 @@ static void CuvidMixVideo(CuvidDecoder * decoder, __attribute__((unused))
render_params.upscaler = pl_named_filters[VideoScaling[decoder->Resolution]].filter; render_params.upscaler = pl_named_filters[VideoScaling[decoder->Resolution]].filter;
render_params.downscaler = pl_named_filters[VideoScaling[decoder->Resolution]].filter; render_params.downscaler = pl_named_filters[VideoScaling[decoder->Resolution]].filter;
render_params.color_adjustment = &colors; render_params.color_adjustment = &colors;
render_params.deband_params = &deband;
colors.brightness = VideoBrightness; colors.brightness = VideoBrightness;
colors.contrast = VideoContrast; colors.contrast = VideoContrast;
@ -4011,10 +3999,12 @@ static void CuvidMixVideo(CuvidDecoder * decoder, __attribute__((unused))
} }
decoder->newchannel = 0; decoder->newchannel = 0;
// uint64_t tt = GetusTicks();
if (!pl_render_image(p->renderer, &decoder->pl_images[current], target, &render_params)) { if (!pl_render_image(p->renderer, &decoder->pl_images[current], target, &render_params)) {
Debug(4, "Failed rendering frame!\n"); Debug(4, "Failed rendering frame!\n");
} }
// pl_gpu_finish(p->gpu);
//printf("Rendertime %ld -- \n,",GetusTicks() - tt);
if (VideoScalerTest) { // left side test scaler if (VideoScalerTest) { // left side test scaler
#if PL_API_VER >= 100 #if PL_API_VER >= 100
@ -4141,7 +4131,6 @@ static void CuvidDisplayFrame(void)
int RTS_flag; int RTS_flag;
int valid_frame = 0; int valid_frame = 0;
float ldiff; float ldiff;
static int first = 1;
float turnaround; float turnaround;
#ifdef PLACEBO #ifdef PLACEBO
@ -4192,32 +4181,14 @@ static void CuvidDisplayFrame(void)
} }
round_time = GetusTicks(); round_time = GetusTicks();
#if 1
diff = (GetusTicks() - last_time) / 1000;
// last_time = GetusTicks();
// printf("Roundtrip Displayframe %d\n",diff);
if (diff < 5000 && diff > 0) {
// printf("Sleep %d\n",15000-diff);
usleep((5000 - diff)); // * 1000);
}
#endif
if (!p->swapchain) if (!p->swapchain)
return; return;
#ifdef CUVID #ifdef CUVID
VideoThreadLock(); VideoThreadLock();
#if 0
if (!first) {
if (!pl_swapchain_submit_frame(p->swapchain))
Error(_("Failed to submit swapchain buffer\n"));
pl_swapchain_swap_buffers(p->swapchain); // swap buffers
}
#endif
#endif #endif
first = 0;
last_time = GetusTicks(); last_time = GetusTicks();
while (!pl_swapchain_start_frame(p->swapchain, &frame)) { // get new frame wait for previous to swap while (!pl_swapchain_start_frame(p->swapchain, &frame)) { // get new frame wait for previous to swap
@ -4234,7 +4205,7 @@ static void CuvidDisplayFrame(void)
VideoThreadLock(); VideoThreadLock();
#endif #endif
pl_render_target_from_swapchain(&target, &frame); // make target frame pl_frame_from_swapchain(&target, &frame); // make target frame
if (VideoSurfaceModesChanged) { if (VideoSurfaceModesChanged) {
pl_renderer_destroy(&p->renderer); pl_renderer_destroy(&p->renderer);
@ -5092,12 +5063,12 @@ static const VideoModule NoopModule = {
.SetClock = (void(*const)(VideoHwDecoder *, int64_t))NoopSetClock, .SetClock = (void(*const)(VideoHwDecoder *, int64_t))NoopSetClock,
.GetClock = (int64_t(*const)(const VideoHwDecoder *))NoopGetClock, .GetClock = (int64_t(*const)(const VideoHwDecoder *))NoopGetClock,
.SetClosing = (void(*const)(const VideoHwDecoder *))NoopSetClosing, .SetClosing = (void(*const)(const VideoHwDecoder *))NoopSetClosing,
.ResetStart = (void(*const)(const VideoHwDecoder *))NoopResetStart,
.SetTrickSpeed = (void(*const)(const VideoHwDecoder *, int))NoopSetTrickSpeed, .SetTrickSpeed = (void(*const)(const VideoHwDecoder *, int))NoopSetTrickSpeed,
.GrabOutput = NoopGrabOutputSurface, .GrabOutput = NoopGrabOutputSurface,
.GetStats = (void(*const)(VideoHwDecoder *, int *, int *, int *, .GetStats = (void(*const)(VideoHwDecoder *, int *, int *, int *,
int *, float *, int *, int *, int *, int *))NoopGetStats, int *, float *, int *, int *, int *, int *))NoopGetStats,
#endif #endif
.ResetStart = (void(*const)(const VideoHwDecoder *))NoopVoid,
.SetBackground = NoopSetBackground, .SetBackground = NoopSetBackground,
.SetVideoMode = NoopVoid, .SetVideoMode = NoopVoid,
@ -5486,7 +5457,7 @@ void InitPlacebo()
.swap_buffers = (void (*)(void *)) CuvidSwapBuffer, .swap_buffers = (void (*)(void *)) CuvidSwapBuffer,
.framebuffer.flipped = true, .framebuffer.flipped = true,
.framebuffer.id = 0, .framebuffer.id = 0,
.max_swapchain_depth = 2, .max_swapchain_depth = 3,
.priv = VideoWindow, .priv = VideoWindow,
}); });
@ -5536,7 +5507,6 @@ void InitPlacebo()
Fatal(_("Failed to create Vulkan Device")); Fatal(_("Failed to create Vulkan Device"));
p->gpu = p->vk->gpu; p->gpu = p->vk->gpu;
// Create initial swapchain // Create initial swapchain
p->swapchain = pl_vulkan_create_swapchain(p->vk, &(struct pl_vulkan_swapchain_params) { p->swapchain = pl_vulkan_create_swapchain(p->vk, &(struct pl_vulkan_swapchain_params) {
.surface = p->pSurface, .surface = p->pSurface,