Skip to content

Commit

Permalink
vo_gpu: don't pass ra_fbo by value
Browse files Browse the repository at this point in the history
Make it easier on compiler, no need to alloca and copy things around.
  • Loading branch information
kasper93 authored and sfan5 committed Nov 28, 2023
1 parent f7402ff commit 281b1d8
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion video/filter/vf_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static struct mp_image *gpu_render_frame(struct mp_filter *f, struct mp_image *i

// (it doesn't have access to the OSD though)
int flags = RENDER_FRAME_SUBS | RENDER_FRAME_VF_SUBS;
gl_video_render_frame(priv->renderer, &frame, (struct ra_fbo){priv->target},
gl_video_render_frame(priv->renderer, &frame, &(struct ra_fbo){priv->target},
flags);

res = mp_image_alloc(IMGFMT_RGB0, w, h);
Expand Down
2 changes: 1 addition & 1 deletion video/out/gpu/libmpv_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static int render(struct render_backend *ctx, mpv_render_param *params,
&(int){0});

struct ra_fbo target = {.tex = tex, .flip = flip};
gl_video_render_frame(p->renderer, frame, target, RENDER_FRAME_DEF);
gl_video_render_frame(p->renderer, frame, &target, RENDER_FRAME_DEF);
p->context->fns->done_frame(p->context, frame->display_synced);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions video/out/gpu/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static void get_3d_side_by_side(int stereo_mode, int div[2])
}

void mpgl_osd_draw_finish(struct mpgl_osd *ctx, int index,
struct gl_shader_cache *sc, struct ra_fbo fbo)
struct gl_shader_cache *sc, const struct ra_fbo *fbo)
{
struct mpgl_osd_part *part = ctx->parts[index];

Expand All @@ -312,7 +312,7 @@ void mpgl_osd_draw_finish(struct mpgl_osd *ctx, int index,
const int *factors = &blend_factors[part->format][0];
gl_sc_blend(sc, factors[0], factors[1], factors[2], factors[3]);

gl_sc_dispatch_draw(sc, fbo.tex, false, vertex_vao, MP_ARRAY_SIZE(vertex_vao),
gl_sc_dispatch_draw(sc, fbo->tex, false, vertex_vao, MP_ARRAY_SIZE(vertex_vao),
sizeof(struct vertex), part->vertices, part->num_vertices);
}

Expand Down
2 changes: 1 addition & 1 deletion video/out/gpu/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void mpgl_osd_resize(struct mpgl_osd *ctx, struct mp_osd_res res, int stereo_mod
bool mpgl_osd_draw_prepare(struct mpgl_osd *ctx, int index,
struct gl_shader_cache *sc);
void mpgl_osd_draw_finish(struct mpgl_osd *ctx, int index,
struct gl_shader_cache *sc, struct ra_fbo fbo);
struct gl_shader_cache *sc, const struct ra_fbo *fbo);
bool mpgl_osd_check_change(struct mpgl_osd *ctx, struct mp_osd_res *res,
double pts);

Expand Down
6 changes: 3 additions & 3 deletions video/out/gpu/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ void gl_transform_trans(struct gl_transform t, struct gl_transform *x)
gl_transform_vec(t, &x->t[0], &x->t[1]);
}

void gl_transform_ortho_fbo(struct gl_transform *t, struct ra_fbo fbo)
void gl_transform_ortho_fbo(struct gl_transform *t, const struct ra_fbo *fbo)
{
int y_dir = fbo.flip ? -1 : 1;
gl_transform_ortho(t, 0, fbo.tex->params.w, 0, fbo.tex->params.h * y_dir);
int y_dir = fbo->flip ? -1 : 1;
gl_transform_ortho(t, 0, fbo->tex->params.w, 0, fbo->tex->params.h * y_dir);
}

float gl_video_scale_ambient_lux(float lmin, float lmax,
Expand Down
2 changes: 1 addition & 1 deletion video/out/gpu/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static inline bool gl_transform_eq(struct gl_transform a, struct gl_transform b)

void gl_transform_trans(struct gl_transform t, struct gl_transform *x);

void gl_transform_ortho_fbo(struct gl_transform *t, struct ra_fbo fbo);
void gl_transform_ortho_fbo(struct gl_transform *t, const struct ra_fbo *fbo);

float gl_video_scale_ambient_lux(float lmin, float lmax,
float rmin, float rmax, float lux);
Expand Down
54 changes: 27 additions & 27 deletions video/out/gpu/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ static void dispatch_compute(struct gl_video *p, int w, int h,
}

static struct mp_pass_perf render_pass_quad(struct gl_video *p,
struct ra_fbo fbo, bool discard,
const struct ra_fbo *fbo, bool discard,
const struct mp_rect *dst)
{
// The first element is reserved for `vec2 position`
Expand Down Expand Up @@ -1274,11 +1274,11 @@ static struct mp_pass_perf render_pass_quad(struct gl_video *p,
&p->tmp_vertex[num_vertex_attribs * 1],
vertex_stride);

return gl_sc_dispatch_draw(p->sc, fbo.tex, discard, p->vao, num_vertex_attribs,
return gl_sc_dispatch_draw(p->sc, fbo->tex, discard, p->vao, num_vertex_attribs,
vertex_stride, p->tmp_vertex, num_vertices);
}

static void finish_pass_fbo(struct gl_video *p, struct ra_fbo fbo,
static void finish_pass_fbo(struct gl_video *p, const struct ra_fbo *fbo,
bool discard, const struct mp_rect *dst)
{
pass_prepare_src_tex(p);
Expand Down Expand Up @@ -1319,7 +1319,7 @@ static void finish_pass_tex(struct gl_video *p, struct ra_tex **dst_tex,
debug_check_gl(p, "after dispatching compute shader");
} else {
struct ra_fbo fbo = { .tex = *dst_tex, };
finish_pass_fbo(p, fbo, true, &(struct mp_rect){0, 0, w, h});
finish_pass_fbo(p, &fbo, true, &(struct mp_rect){0, 0, w, h});
}
}

Expand Down Expand Up @@ -2891,7 +2891,7 @@ static void pass_dither(struct gl_video *p)
// Draws the OSD, in scene-referred colors.. If cms is true, subtitles are
// instead adapted to the display's gamut.
static void pass_draw_osd(struct gl_video *p, int osd_flags, int frame_flags,
double pts, struct mp_osd_res rect, struct ra_fbo fbo,
double pts, struct mp_osd_res rect, const struct ra_fbo *fbo,
bool cms)
{
if (frame_flags & RENDER_FRAME_VF_SUBS)
Expand All @@ -2916,7 +2916,7 @@ static void pass_draw_osd(struct gl_video *p, int osd_flags, int frame_flags,
.light = MP_CSP_LIGHT_DISPLAY,
};

pass_colormanage(p, csp_srgb, fbo.color_space, frame_flags, true);
pass_colormanage(p, csp_srgb, fbo->color_space, frame_flags, true);
}
mpgl_osd_draw_finish(p->osd, n, p->sc, fbo);
}
Expand Down Expand Up @@ -3013,7 +3013,7 @@ static bool pass_render_frame(struct gl_video *p, struct mp_image *mpi,
};
finish_pass_tex(p, &p->blend_subs_tex, rect.w, rect.h);
struct ra_fbo fbo = { p->blend_subs_tex };
pass_draw_osd(p, OSD_DRAW_SUB_ONLY, flags, vpts, rect, fbo, false);
pass_draw_osd(p, OSD_DRAW_SUB_ONLY, flags, vpts, rect, &fbo, false);
pass_read_tex(p, p->blend_subs_tex);
pass_describe(p, "blend subs video");
}
Expand Down Expand Up @@ -3045,7 +3045,7 @@ static bool pass_render_frame(struct gl_video *p, struct mp_image *mpi,
}
finish_pass_tex(p, &p->blend_subs_tex, p->texture_w, p->texture_h);
struct ra_fbo fbo = { p->blend_subs_tex };
pass_draw_osd(p, OSD_DRAW_SUB_ONLY, flags, vpts, rect, fbo, false);
pass_draw_osd(p, OSD_DRAW_SUB_ONLY, flags, vpts, rect, &fbo, false);
pass_read_tex(p, p->blend_subs_tex);
pass_describe(p, "blend subs");
}
Expand All @@ -3055,7 +3055,7 @@ static bool pass_render_frame(struct gl_video *p, struct mp_image *mpi,
return true;
}

static void pass_draw_to_screen(struct gl_video *p, struct ra_fbo fbo, int flags)
static void pass_draw_to_screen(struct gl_video *p, const struct ra_fbo *fbo, int flags)
{
if (p->dumb_mode)
pass_render_frame_dumb(p);
Expand All @@ -3067,7 +3067,7 @@ static void pass_draw_to_screen(struct gl_video *p, struct ra_fbo fbo, int flags
GLSL(color.rgb = pow(color.rgb, vec3(user_gamma));)
}

pass_colormanage(p, p->image_params.color, fbo.color_space, flags, false);
pass_colormanage(p, p->image_params.color, fbo->color_space, flags, false);

// Since finish_pass_fbo doesn't work with compute shaders, and neither
// does the checkerboard/dither code, we may need an indirection via
Expand Down Expand Up @@ -3134,7 +3134,7 @@ static bool update_surface(struct gl_video *p, struct mp_image *mpi,
// Draws an interpolate frame to fbo, based on the frame timing in t
// flags: bit set of RENDER_FRAME_* flags
static void gl_video_interpolate_frame(struct gl_video *p, struct vo_frame *t,
struct ra_fbo fbo, int flags)
const struct ra_fbo *fbo, int flags)
{
bool is_new = false;

Expand Down Expand Up @@ -3306,24 +3306,24 @@ static void gl_video_interpolate_frame(struct gl_video *p, struct vo_frame *t,
}

void gl_video_render_frame(struct gl_video *p, struct vo_frame *frame,
struct ra_fbo fbo, int flags)
const struct ra_fbo *fbo, int flags)
{
gl_video_update_options(p);

struct mp_rect target_rc = {0, 0, fbo.tex->params.w, fbo.tex->params.h};
struct mp_rect target_rc = {0, 0, fbo->tex->params.w, fbo->tex->params.h};

p->broken_frame = false;

bool has_frame = !!frame->current;

struct m_color c = p->clear_color;
float clear_color[4] = {c.r / 255.0, c.g / 255.0, c.b / 255.0, c.a / 255.0};
p->ra->fns->clear(p->ra, fbo.tex, clear_color, &target_rc);
p->ra->fns->clear(p->ra, fbo->tex, clear_color, &target_rc);

if (p->hwdec_overlay) {
if (has_frame) {
float *color = p->hwdec_overlay->overlay_colorkey;
p->ra->fns->clear(p->ra, fbo.tex, color, &p->dst_rect);
p->ra->fns->clear(p->ra, fbo->tex, color, &p->dst_rect);
}

p->hwdec_overlay->driver->overlay_frame(p->hwdec_overlay, frame->current,
Expand Down Expand Up @@ -3364,41 +3364,41 @@ void gl_video_render_frame(struct gl_video *p, struct vo_frame *frame,

// For the non-interpolation case, we draw to a single "cache"
// texture to speed up subsequent re-draws (if any exist)
struct ra_fbo dest_fbo = fbo;
const struct ra_fbo *dest_fbo = fbo;
bool repeats = frame->num_vsyncs > 1 && frame->display_synced;
if ((repeats || frame->still) && !p->dumb_mode &&
(p->ra->caps & RA_CAP_BLIT) && fbo.tex->params.blit_dst)
(p->ra->caps & RA_CAP_BLIT) && fbo->tex->params.blit_dst)
{
// Attempt to use the same format as the destination FBO
// if possible. Some RAs use a wrapped dummy format here,
// so fall back to the fbo_format in that case.
const struct ra_format *fmt = fbo.tex->params.format;
const struct ra_format *fmt = fbo->tex->params.format;
if (fmt->dummy_format)
fmt = p->fbo_format;

bool r = ra_tex_resize(p->ra, p->log, &p->output_tex,
fbo.tex->params.w, fbo.tex->params.h,
fbo->tex->params.w, fbo->tex->params.h,
fmt);
if (r) {
dest_fbo = (struct ra_fbo) { p->output_tex };
dest_fbo = &(struct ra_fbo) { p->output_tex };
p->output_tex_valid = true;
}
}
pass_draw_to_screen(p, dest_fbo, flags);
}

// "output tex valid" and "output tex needed" are equivalent
if (p->output_tex_valid && fbo.tex->params.blit_dst) {
if (p->output_tex_valid && fbo->tex->params.blit_dst) {
pass_info_reset(p, true);
pass_describe(p, "redraw cached frame");
struct mp_rect src = p->dst_rect;
struct mp_rect dst = src;
if (fbo.flip) {
dst.y0 = fbo.tex->params.h - src.y0;
dst.y1 = fbo.tex->params.h - src.y1;
if (fbo->flip) {
dst.y0 = fbo->tex->params.h - src.y0;
dst.y1 = fbo->tex->params.h - src.y1;
}
timer_pool_start(p->blit_timer);
p->ra->fns->blit(p->ra, fbo.tex, p->output_tex, &dst, &src);
p->ra->fns->blit(p->ra, fbo->tex, p->output_tex, &dst, &src);
timer_pool_stop(p->blit_timer);
pass_record(p, timer_pool_measure(p->blit_timer));
}
Expand Down Expand Up @@ -3431,7 +3431,7 @@ void gl_video_render_frame(struct gl_video *p, struct vo_frame *frame,
// Make the screen solid blue to make it visually clear that an
// error has occurred
float color[4] = {0.0, 0.05, 0.5, 1.0};
p->ra->fns->clear(p->ra, fbo.tex, color, &target_rc);
p->ra->fns->clear(p->ra, fbo->tex, color, &target_rc);
}

p->frames_rendered++;
Expand Down Expand Up @@ -3522,7 +3522,7 @@ void gl_video_screenshot(struct gl_video *p, struct vo_frame *frame,
flags |= RENDER_FRAME_OSD;
if (args->scaled)
flags |= RENDER_SCREEN_COLOR;
gl_video_render_frame(p, nframe, (struct ra_fbo){target}, flags);
gl_video_render_frame(p, nframe, &(struct ra_fbo){target}, flags);

res = mp_image_alloc(mpfmt, params.w, params.h);
if (!res)
Expand Down
2 changes: 1 addition & 1 deletion video/out/gpu/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void gl_video_set_osd_source(struct gl_video *p, struct osd_state *osd);
bool gl_video_check_format(struct gl_video *p, int mp_format);
void gl_video_config(struct gl_video *p, struct mp_image_params *params);
void gl_video_render_frame(struct gl_video *p, struct vo_frame *frame,
struct ra_fbo fbo, int flags);
const struct ra_fbo *fbo, int flags);
void gl_video_resize(struct gl_video *p,
struct mp_rect *src, struct mp_rect *dst,
struct mp_osd_res *osd);
Expand Down
2 changes: 1 addition & 1 deletion video/out/vo_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
if (!sw->fns->start_frame(sw, &fbo))
return;

gl_video_render_frame(p->renderer, frame, fbo, RENDER_FRAME_DEF);
gl_video_render_frame(p->renderer, frame, &fbo, RENDER_FRAME_DEF);
if (!sw->fns->submit_frame(sw, frame)) {
MP_ERR(vo, "Failed presenting frame!\n");
return;
Expand Down
2 changes: 1 addition & 1 deletion video/out/vo_rpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static void update_osd(struct vo *vo)
.flip = true,
};
gl_video_set_osd_pts(p->gl_video, p->osd_pts);
gl_video_render_frame(p->gl_video, &frame, target, RENDER_FRAME_DEF);
gl_video_render_frame(p->gl_video, &frame, &target, RENDER_FRAME_DEF);
ra_tex_free(p->egl.ra, &target.tex);

MP_STATS(vo, "stop rpi_osd");
Expand Down

0 comments on commit 281b1d8

Please sign in to comment.