Skip to content

Commit c415c66

Browse files
N-R-Kkasper93
authored andcommitted
vo_gpu/utils: add gpu_get_auto_param()
deduplicates some code between vo_gpu and vo_gpu_next
1 parent 3e0729e commit c415c66

4 files changed

Lines changed: 47 additions & 68 deletions

File tree

video/out/gpu/utils.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "common/msg.h"
22
#include "video/out/vo.h"
3+
#include "video/mp_image.h"
34
#include "utils.h"
45

56
// Standard parallel 2D projection, except y1 < y0 means that the coordinate
@@ -54,6 +55,41 @@ double gl_video_scale_ambient_lux(float lmin, float lmax,
5455
return MPMAX(MPMIN(result, max), min);
5556
}
5657

58+
bool gpu_get_auto_param(const struct mp_image *mpi, struct bstr name, double *out)
59+
{
60+
const struct mp_image_params *params = &mpi->params;
61+
float chroma_offset_x, chroma_offset_y;
62+
pl_chroma_location_offset(params->chroma_location,
63+
&chroma_offset_x, &chroma_offset_y);
64+
65+
const struct {
66+
const char *name;
67+
double value;
68+
} opts[] = {
69+
{ "PTS", mpi->pts },
70+
{ "chroma_offset_x", chroma_offset_x },
71+
{ "chroma_offset_y", chroma_offset_y },
72+
{ "min_luma", params->color.hdr.min_luma },
73+
{ "max_luma", params->color.hdr.max_luma },
74+
{ "max_cll", params->color.hdr.max_cll },
75+
{ "max_fall", params->color.hdr.max_fall },
76+
{ "scene_max_r", params->color.hdr.scene_max[0] },
77+
{ "scene_max_g", params->color.hdr.scene_max[1] },
78+
{ "scene_max_b", params->color.hdr.scene_max[2] },
79+
{ "scene_avg", params->color.hdr.scene_avg },
80+
{ "max_pq_y", params->color.hdr.max_pq_y },
81+
{ "avg_pq_y", params->color.hdr.avg_pq_y },
82+
};
83+
84+
for (int n = 0; n < MP_ARRAY_SIZE(opts); n++) {
85+
if (bstrcmp0(name, opts[n].name) != 0)
86+
continue;
87+
*out = opts[n].value;
88+
return true;
89+
}
90+
return false;
91+
}
92+
5793
void ra_buf_pool_uninit(struct ra *ra, struct ra_buf_pool *pool)
5894
{
5995
for (int i = 0; i < pool->num_buffers; i++)

video/out/gpu/utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ void gl_transform_ortho_fbo(struct gl_transform *t, const struct ra_fbo *fbo);
6868
double gl_video_scale_ambient_lux(float lmin, float lmax,
6969
float rmin, float rmax, double lux);
7070

71+
// Get automatic parameter value for user shaders
72+
bool gpu_get_auto_param(const struct mp_image *mpi, struct bstr name, double *out);
73+
7174
// A pool of buffers, which can grow as needed
7275
struct ra_buf_pool {
7376
struct ra_buf_params current_params;

video/out/gpu/video.c

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,43 +2156,6 @@ static void update_user_shader_opts(struct gl_video *p, const char *path,
21562156
}
21572157
}
21582158

2159-
static bool get_param_dynamic(struct gl_video *p, struct bstr name, double *out)
2160-
{
2161-
const struct mp_image_params *params = &p->image.mpi->params;
2162-
float chroma_offset_x, chroma_offset_y;
2163-
pl_chroma_location_offset(params->chroma_location,
2164-
&chroma_offset_x, &chroma_offset_y);
2165-
2166-
const struct {
2167-
const char *name;
2168-
double value;
2169-
} opts[] = {
2170-
{ "PTS", p->image.mpi->pts },
2171-
{ "chroma_offset_x", chroma_offset_x },
2172-
{ "chroma_offset_y", chroma_offset_y },
2173-
{ "min_luma", params->color.hdr.min_luma },
2174-
{ "max_luma", params->color.hdr.max_luma },
2175-
{ "max_cll", params->color.hdr.max_cll },
2176-
{ "max_fall", params->color.hdr.max_fall },
2177-
{ "scene_max_r", params->color.hdr.scene_max[0] },
2178-
{ "scene_max_g", params->color.hdr.scene_max[1] },
2179-
{ "scene_max_b", params->color.hdr.scene_max[2] },
2180-
{ "scene_avg", params->color.hdr.scene_avg },
2181-
{ "max_pq_y", params->color.hdr.max_pq_y },
2182-
{ "avg_pq_y", params->color.hdr.avg_pq_y },
2183-
};
2184-
2185-
for (int n = 0; n < MP_ARRAY_SIZE(opts); n++) {
2186-
if (bstrcmp(name, bstr0(opts[n].name)) != 0)
2187-
continue;
2188-
2189-
*out = opts[n].value;
2190-
return true;
2191-
}
2192-
2193-
return false;
2194-
}
2195-
21962159
static void user_hook(struct gl_video *p, struct image img,
21972160
struct gl_transform *trans, void *priv)
21982161
{
@@ -2213,7 +2176,7 @@ static void user_hook(struct gl_video *p, struct image img,
22132176
}
22142177

22152178
double value = param->value;
2216-
get_param_dynamic(p, param->name, &value);
2179+
gpu_get_auto_param(p->image.mpi, param->name, &value);
22172180

22182181
switch (param->type) {
22192182
case GL_USER_SHADER_PARAM_FLOAT:

video/out/vo_gpu_next.c

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,39 +2433,16 @@ static void update_lut(struct priv *p, struct user_lut *lut)
24332433
static void update_hook_opts_dynamic(struct priv *p, const struct pl_hook *hook,
24342434
const struct mp_image *mpi)
24352435
{
2436-
float chroma_offset_x, chroma_offset_y;
2437-
pl_chroma_location_offset(mpi->params.chroma_location,
2438-
&chroma_offset_x, &chroma_offset_y);
2439-
const struct {
2440-
const char *name;
2441-
double value;
2442-
} opts[] = {
2443-
{ "PTS", mpi->pts },
2444-
{ "chroma_offset_x", chroma_offset_x },
2445-
{ "chroma_offset_y", chroma_offset_y },
2446-
{ "min_luma", mpi->params.color.hdr.min_luma },
2447-
{ "max_luma", mpi->params.color.hdr.max_luma },
2448-
{ "max_cll", mpi->params.color.hdr.max_cll },
2449-
{ "max_fall", mpi->params.color.hdr.max_fall },
2450-
{ "scene_max_r", mpi->params.color.hdr.scene_max[0] },
2451-
{ "scene_max_g", mpi->params.color.hdr.scene_max[1] },
2452-
{ "scene_max_b", mpi->params.color.hdr.scene_max[2] },
2453-
{ "scene_avg", mpi->params.color.hdr.scene_avg },
2454-
{ "max_pq_y", mpi->params.color.hdr.max_pq_y },
2455-
{ "avg_pq_y", mpi->params.color.hdr.avg_pq_y },
2456-
};
2457-
24582436
for (int i = 0; i < hook->num_parameters; i++) {
2437+
double val;
24592438
const struct pl_hook_par *hp = &hook->parameters[i];
2460-
for (int n = 0; n < MP_ARRAY_SIZE(opts); n++) {
2461-
if (strcmp(hp->name, opts[n].name) != 0)
2462-
continue;
2439+
if (!gpu_get_auto_param(mpi, bstr0(hp->name), &val))
2440+
continue;
24632441

2464-
switch (hp->type) {
2465-
case PL_VAR_FLOAT: hp->data->f = opts[n].value; break;
2466-
case PL_VAR_SINT: hp->data->i = lrint(opts[n].value); break;
2467-
case PL_VAR_UINT: hp->data->u = lrint(opts[n].value); break;
2468-
}
2442+
switch (hp->type) {
2443+
case PL_VAR_FLOAT: hp->data->f = val; break;
2444+
case PL_VAR_SINT: hp->data->i = lrint(val); break;
2445+
case PL_VAR_UINT: hp->data->u = lrint(val); break;
24692446
}
24702447
}
24712448
}

0 commit comments

Comments
 (0)