vo_gpu: simplify structs / names

Due to the plethora of historical baggage from different eras getting
confusing, I decided to simplify and unify the struct organization and
naming scheme.

Structs that got renamed:

1. fbodst     -> ra_fbo  (and moved to gpu/context.h)
2. fbotex     -> removed (redundant after 2af2fa7a)
3. fbosurface -> surface
4. img_tex    -> image

In addition to these structs being renamed, all of the names have been
made consistent. The new scheme is as follows:

struct image img;
struct ra_tex *tex;
struct ra_fbo fbo;

This also affects derived names, e.g. indirect_fbo -> indirect_tex.
Notably also, finish_pass_fbo -> finish_pass_tex and finish_pass_direct
-> finish_pass_fbo.

The new equivalent of fbotex_change() is called ra_tex_resize().

This commit (should) contain no logic changes, just renaming a bunch of
crap.
This commit is contained in:
Niklas Haas 2017-09-20 10:45:33 +02:00
parent 2af2fa7a27
commit 62ddc85d17
12 changed files with 331 additions and 377 deletions

View File

@ -56,21 +56,26 @@ struct ra_swapchain {
struct ra_ctx *ctx;
struct priv *priv;
const struct ra_swapchain_fns *fns;
};
bool flip_v; // flip the rendered image vertically (set by the swapchain)
// Represents a framebuffer / render target
struct ra_fbo {
struct ra_tex *tex;
bool flip; // rendering needs to be inverted
};
struct ra_swapchain_fns {
// Gets the current framebuffer depth in bits (0 if unknown). Optional.
int (*color_depth)(struct ra_swapchain *sw);
// Retrieves a screenshot of the framebuffer. These are always the right
// side up, regardless of ra_swapchain->flip_v. Optional.
// Retrieves a screenshot of the framebuffer. Optional.
struct mp_image *(*screenshot)(struct ra_swapchain *sw);
// Called when rendering starts. Returns NULL on failure. This must be
// followed by submit_frame, to submit the rendered frame.
struct ra_tex *(*start_frame)(struct ra_swapchain *sw);
// followed by submit_frame, to submit the rendered frame. This function
// can also fail sporadically, and such errors should be ignored unless
// they persist.
bool (*start_frame)(struct ra_swapchain *sw, struct ra_fbo *out_fbo);
// Present the frame. Issued in lockstep with start_frame, with rendering
// commands in between. The `frame` is just there for timing data, for

View File

@ -291,7 +291,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 fbodst target)
struct gl_shader_cache *sc, struct ra_fbo fbo)
{
struct mpgl_osd_part *part = ctx->parts[index];
@ -303,7 +303,7 @@ void mpgl_osd_draw_finish(struct mpgl_osd *ctx, int index,
for (int x = 0; x < div[0]; x++) {
for (int y = 0; y < div[1]; y++) {
struct gl_transform t;
gl_transform_ortho_fbodst(&t, target);
gl_transform_ortho_fbo(&t, fbo);
float a_x = ctx->osd_res.w * x;
float a_y = ctx->osd_res.h * y;
@ -317,7 +317,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, target.tex, part->vertices, part->num_vertices);
gl_sc_dispatch_draw(sc, fbo.tex, part->vertices, part->num_vertices);
}
static void set_res(struct mpgl_osd *ctx, struct mp_osd_res res, int stereo_mode)

View File

@ -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 fbodst target);
struct gl_shader_cache *sc, struct ra_fbo fbo);
bool mpgl_osd_check_change(struct mpgl_osd *ctx, struct mp_osd_res *res,
double pts);

View File

@ -33,7 +33,7 @@ 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_fbodst(struct gl_transform *t, struct fbodst fbo)
void gl_transform_ortho_fbo(struct gl_transform *t, 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);
@ -167,35 +167,24 @@ struct ra_layout std430_layout(struct ra_renderpass_input *inp)
};
}
// Create a texture and a FBO using the texture as color attachments.
// fmt: texture internal format
// If the parameters are the same as the previous call, do not touch it.
bool fbotex_change(struct fbotex *fbo, struct ra *ra, struct mp_log *log,
// Resize a texture to a new desired size and format if necessary
bool ra_tex_resize(struct ra *ra, struct mp_log *log, struct ra_tex **tex,
int w, int h, const struct ra_format *fmt)
{
int lw = w, lh = h;
if (fbo->tex) {
int cw = w, ch = h;
int rw = fbo->tex->params.w, rh = fbo->tex->params.h;
if (rw == cw && rh == ch && fbo->tex->params.format == fmt)
goto done;
if (*tex) {
struct ra_tex_params cur_params = (*tex)->params;
if (cur_params.w == w && cur_params.h == h && cur_params.format == fmt)
return true;
}
mp_verbose(log, "Create FBO: %dx%d (%dx%d)\n", lw, lh, w, h);
mp_verbose(log, "Resizing texture: %dx%d\n", w, h);
if (!fmt || !fmt->renderable || !fmt->linear_filter) {
mp_err(log, "Format %s not supported.\n", fmt ? fmt->name : "(unset)");
return false;
}
fbotex_uninit(fbo);
*fbo = (struct fbotex) {
.ra = ra,
};
ra_tex_free(ra, tex);
struct ra_tex_params params = {
.dimensions = 2,
.w = w,
@ -209,32 +198,11 @@ bool fbotex_change(struct fbotex *fbo, struct ra *ra, struct mp_log *log,
.blit_src = true,
};
fbo->tex = ra_tex_create(fbo->ra, &params);
*tex = ra_tex_create(ra, &params);
if (!*tex)
mp_err(log, "Error: texture could not be created.\n");
if (!fbo->tex) {
mp_err(log, "Error: framebuffer could not be created.\n");
fbotex_uninit(fbo);
return false;
}
done:
fbo->lw = lw;
fbo->lh = lh;
fbo->fbo = (struct fbodst){
.tex = fbo->tex,
};
return true;
}
void fbotex_uninit(struct fbotex *fbo)
{
if (fbo->ra) {
ra_tex_free(fbo->ra, &fbo->tex);
*fbo = (struct fbotex) {0};
}
return *tex;
}
struct timer_pool {

View File

@ -4,6 +4,7 @@
#include <math.h>
#include "ra.h"
#include "context.h"
// A 3x2 matrix, with the translation part separate.
struct gl_transform {
@ -62,12 +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);
struct fbodst {
struct ra_tex *tex;
bool flip; // mirror vertically
};
void gl_transform_ortho_fbodst(struct gl_transform *t, struct fbodst fbo);
void gl_transform_ortho_fbo(struct gl_transform *t, struct ra_fbo fbo);
// A pool of buffers, which can grow as needed
struct ra_buf_pool {
@ -92,15 +88,7 @@ bool ra_tex_upload_pbo(struct ra *ra, struct ra_buf_pool *pbo,
struct ra_layout std140_layout(struct ra_renderpass_input *inp);
struct ra_layout std430_layout(struct ra_renderpass_input *inp);
struct fbotex {
struct ra *ra;
struct ra_tex *tex;
int lw, lh; // logical (configured) size, <= than texture size
struct fbodst fbo;
};
void fbotex_uninit(struct fbotex *fbo);
bool fbotex_change(struct fbotex *fbo, struct ra *ra, struct mp_log *log,
bool ra_tex_resize(struct ra *ra, struct mp_log *log, struct ra_tex **tex,
int w, int h, const struct ra_format *fmt);
// A wrapper around ra_timer that does result pooling, averaging etc.

File diff suppressed because it is too large Load Diff

View File

@ -55,7 +55,7 @@ struct scaler {
bool initialized;
struct filter_kernel *kernel;
struct ra_tex *lut;
struct fbotex sep_fbo;
struct ra_tex *sep_fbo;
bool insufficient;
int lut_size;
@ -159,7 +159,7 @@ 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_set_output_depth(struct gl_video *p, int r, int g, int b);
void gl_video_render_frame(struct gl_video *p, struct vo_frame *frame,
struct fbodst target);
struct ra_fbo fbo);
void gl_video_resize(struct gl_video *p,
struct mp_rect *src, struct mp_rect *dst,
struct mp_osd_res *osd);

View File

@ -155,8 +155,7 @@ bool ra_gl_ctx_init(struct ra_ctx *ctx, GL *gl, struct ra_gl_ctx_params params)
{
struct ra_swapchain *sw = ctx->swapchain = talloc_ptrtype(NULL, sw);
*sw = (struct ra_swapchain) {
.ctx = ctx,
.flip_v = !params.flipped, // OpenGL framebuffers are normally inverted
.ctx = ctx,
};
struct priv *p = sw->priv = talloc_ptrtype(sw, p);
@ -266,11 +265,12 @@ struct mp_image *ra_gl_ctx_screenshot(struct ra_swapchain *sw)
return screen;
}
struct ra_tex *ra_gl_ctx_start_frame(struct ra_swapchain *sw)
bool ra_gl_ctx_start_frame(struct ra_swapchain *sw, struct ra_fbo *out_fbo)
{
struct priv *p = sw->priv;
return p->wrapped_fb;
out_fbo->tex = p->wrapped_fb;
out_fbo->flip = !p->params.flipped; // OpenGL FBs are normally flipped
return true;
}
bool ra_gl_ctx_submit_frame(struct ra_swapchain *sw, const struct vo_frame *frame)

View File

@ -51,6 +51,6 @@ void ra_gl_ctx_resize(struct ra_swapchain *sw, int w, int h, int fbo);
// for whatever reason, these can be used to inherit the original behavior.
int ra_gl_ctx_color_depth(struct ra_swapchain *sw);
struct mp_image *ra_gl_ctx_screenshot(struct ra_swapchain *sw);
struct ra_tex *ra_gl_ctx_start_frame(struct ra_swapchain *sw);
bool ra_gl_ctx_start_frame(struct ra_swapchain *sw, struct ra_fbo *out_fbo);
bool ra_gl_ctx_submit_frame(struct ra_swapchain *sw, const struct vo_frame *frame);
void ra_gl_ctx_swap_buffers(struct ra_swapchain *sw);

View File

@ -336,7 +336,7 @@ uninit:
return false;
}
static struct ra_tex *vdpau_start_frame(struct ra_swapchain *sw)
static bool vdpau_start_frame(struct ra_swapchain *sw, struct ra_fbo *out_fbo)
{
struct priv *p = sw->ctx->priv;
struct vo *vo = sw->ctx->vo;
@ -355,7 +355,7 @@ static struct ra_tex *vdpau_start_frame(struct ra_swapchain *sw)
surf->mapped = true;
ra_gl_ctx_resize(sw, surf->w, surf->h, surf->fbo);
return ra_gl_ctx_start_frame(sw);
return ra_gl_ctx_start_frame(sw, out_fbo);
}
static bool vdpau_submit_frame(struct ra_swapchain *sw,

View File

@ -77,18 +77,11 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
struct gpu_priv *p = vo->priv;
struct ra_swapchain *sw = p->ctx->swapchain;
struct ra_tex *tex = sw->fns->start_frame(sw);
if (!tex) {
MP_ERR(vo, "Failed starting frame!\n");
struct ra_fbo fbo;
if (!sw->fns->start_frame(sw, &fbo))
return;
}
struct fbodst dst = {
.tex = tex,
.flip = sw->flip_v,
};
gl_video_render_frame(p->renderer, frame, dst);
gl_video_render_frame(p->renderer, frame, fbo);
if (!sw->fns->submit_frame(sw, frame)) {
MP_ERR(vo, "Failed presenting frame!\n");
return;

View File

@ -335,11 +335,10 @@ int mpv_opengl_cb_draw(mpv_opengl_cb_context *ctx, int fbo, int vp_w, int vp_h)
MP_STATS(ctx, "glcb-render");
struct ra_swapchain *sw = ctx->ra_ctx->swapchain;
struct ra_fbo target;
ra_gl_ctx_resize(sw, vp_w, abs(vp_h), fbo);
struct fbodst target = {
.tex = ra_gl_ctx_start_frame(sw),
.flip = vp_h < 0,
};
ra_gl_ctx_start_frame(sw, &target);
target.flip = vp_h < 0;
gl_video_render_frame(ctx->renderer, frame, target);
ra_gl_ctx_submit_frame(sw, frame);