summaryrefslogtreecommitdiffstats
path: root/video/out/gpu
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2017-09-20 10:45:33 +0200
committerNiklas Haas <git@haasn.xyz>2017-09-22 16:58:55 +0200
commit62ddc85d178e647e8cfbee6da4d173c661b4f1fc (patch)
treeab58cbd56fe8a6251ada92f7b75e002e52e0d430 /video/out/gpu
parent2af2fa7a27586f6938f4db8f45e316212e18e442 (diff)
downloadmpv-62ddc85d178e647e8cfbee6da4d173c661b4f1fc.tar.bz2
mpv-62ddc85d178e647e8cfbee6da4d173c661b4f1fc.tar.xz
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.
Diffstat (limited to 'video/out/gpu')
-rw-r--r--video/out/gpu/context.h15
-rw-r--r--video/out/gpu/osd.c6
-rw-r--r--video/out/gpu/osd.h2
-rw-r--r--video/out/gpu/utils.c58
-rw-r--r--video/out/gpu/utils.h18
-rw-r--r--video/out/gpu/video.c569
-rw-r--r--video/out/gpu/video.h4
7 files changed, 317 insertions, 355 deletions
diff --git a/video/out/gpu/context.h b/video/out/gpu/context.h
index 42de59b75f..f74087592d 100644
--- a/video/out/gpu/context.h
+++ b/video/out/gpu/context.h
@@ -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
diff --git a/video/out/gpu/osd.c b/video/out/gpu/osd.c
index f7c325d1db..350736461c 100644
--- a/video/out/gpu/osd.c
+++ b/video/out/gpu/osd.c
@@ -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)
diff --git a/video/out/gpu/osd.h b/video/out/gpu/osd.h
index 6c2b886de3..00fbc4914f 100644
--- a/video/out/gpu/osd.h
+++ b/video/out/gpu/osd.h
@@ -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);
diff --git a/video/out/gpu/utils.c b/video/out/gpu/utils.c
index 38d1e9b7cd..daf570cba5 100644
--- a/video/out/gpu/utils.c
+++ b/video/out/gpu/utils.c
@@ -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);
-
- if (!fbo->tex) {
- mp_err(log, "Error: framebuffer could not be created.\n");
- fbotex_uninit(fbo);
- return false;
- }
-
-done:
+ *tex = ra_tex_create(ra, &params);
+ if (!*tex)
+ mp_err(log, "Error: texture could not be created.\n");
- 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 {
diff --git a/video/out/gpu/utils.h b/video/out/gpu/utils.h
index 9a52246ae7..ac0cbf28d7 100644
--- a/video/out/gpu/utils.h
+++ b/video/out/gpu/utils.h
@@ -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.
diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c
index 9884b4b2e5..286a4aa9ee 100644
--- a/video/out/gpu/video.c
+++ b/video/out/gpu/video.c
@@ -115,7 +115,7 @@ static const char *plane_names[] = {
// A self-contained description of a source image which can be bound to a
// texture unit and sampled from. Contains metadata about how it's to be used
-struct img_tex {
+struct image {
enum plane_type type; // must be set to something non-zero
int components; // number of relevant coordinates
float multiplier; // multiplier to be used when sampling
@@ -124,10 +124,10 @@ struct img_tex {
struct gl_transform transform; // rendering transformation
};
-// A named img_tex, for user scripting purposes
-struct saved_tex {
+// A named image, for user scripting purposes
+struct saved_img {
const char *name;
- struct img_tex tex;
+ struct image img;
};
// A texture hook. This is some operation that transforms a named texture as
@@ -138,18 +138,18 @@ struct tex_hook {
const char *bind_tex[TEXUNIT_VIDEO_NUM];
int components; // how many components are relevant (0 = same as input)
void *priv; // this gets talloc_freed when the tex_hook is removed
- void (*hook)(struct gl_video *p, struct img_tex tex, // generates GLSL
+ void (*hook)(struct gl_video *p, struct image img, // generates GLSL
struct gl_transform *trans, void *priv);
- bool (*cond)(struct gl_video *p, struct img_tex tex, void *priv);
+ bool (*cond)(struct gl_video *p, struct image img, void *priv);
};
-struct fbosurface {
- struct fbotex fbotex;
+struct surface {
+ struct ra_tex *tex;
uint64_t id;
double pts;
};
-#define FBOSURFACES_MAX 10
+#define SURFACES_MAX 10
struct cached_file {
char *path;
@@ -216,16 +216,16 @@ struct gl_video {
bool forced_dumb_mode;
const struct ra_format *fbo_format;
- struct fbotex merge_fbo[4];
- struct fbotex scale_fbo[4];
- struct fbotex integer_fbo[4];
- struct fbotex indirect_fbo;
- struct fbotex blend_subs_fbo;
- struct fbotex screen_fbo;
- struct fbotex output_fbo;
- struct fbosurface surfaces[FBOSURFACES_MAX];
- struct fbotex vdpau_deinterleave_fbo[2];
+ struct ra_tex *merge_tex[4];
+ struct ra_tex *scale_tex[4];
+ struct ra_tex *integer_tex[4];
+ struct ra_tex *indirect_tex;
+ struct ra_tex *blend_subs_tex;
+ struct ra_tex *screen_tex;
+ struct ra_tex *output_tex;
+ struct ra_tex *vdpau_deinterleave_tex[2];
struct ra_buf *hdr_peak_ssbo;
+ struct surface surfaces[SURFACES_MAX];
// user pass descriptions and textures
struct tex_hook tex_hooks[SHADER_MAX_PASSES];
@@ -237,7 +237,7 @@ struct gl_video {
int surface_now;
int frames_drawn;
bool is_interpolated;
- bool output_fbo_valid;
+ bool output_tex_valid;
// state for configured scalers
struct scaler scaler[SCALER_COUNT];
@@ -249,9 +249,9 @@ struct gl_video {
struct mp_osd_res osd_rect; // OSD size/margins
// temporary during rendering
- struct img_tex pass_tex[TEXUNIT_VIDEO_NUM];
+ struct image pass_img[TEXUNIT_VIDEO_NUM];
struct compute_info pass_compute; // compute shader metadata for this pass
- int pass_tex_num;
+ int pass_img_num;
int texture_w, texture_h;
struct gl_transform texture_offset; // texture transform without rotation
int components;
@@ -268,9 +268,9 @@ struct gl_video {
struct timer_pool *osd_timer;
// intermediate textures
- struct saved_tex saved_tex[SHADER_MAX_SAVED];
- int saved_tex_num;
- struct fbotex hook_fbos[SHADER_MAX_SAVED];
+ struct saved_img saved_img[SHADER_MAX_SAVED];
+ int saved_img_num;
+ struct ra_tex *hook_fbos[SHADER_MAX_SAVED];
int hook_fbo_num;
int frames_uploaded;
@@ -466,14 +466,14 @@ static void debug_check_gl(struct gl_video *p, const char *msg)
static void gl_video_reset_surfaces(struct gl_video *p)
{
- for (int i = 0; i < FBOSURFACES_MAX; i++) {
+ for (int i = 0; i < SURFACES_MAX; i++) {
p->surfaces[i].id = 0;
p->surfaces[i].pts = MP_NOPTS_VALUE;
}
p->surface_idx = 0;
p->surface_now = 0;
p->frames_drawn = 0;
- p->output_fbo_valid = false;
+ p->output_tex_valid = false;
}
static void gl_video_reset_hooks(struct gl_video *p)
@@ -488,10 +488,10 @@ static void gl_video_reset_hooks(struct gl_video *p)
p->user_tex_num = 0;
}
-static inline int fbosurface_wrap(int id)
+static inline int surface_wrap(int id)
{
- id = id % FBOSURFACES_MAX;
- return id < 0 ? id + FBOSURFACES_MAX : id;
+ id = id % SURFACES_MAX;
+ return id < 0 ? id + SURFACES_MAX : id;
}
static void reinit_osd(struct gl_video *p)
@@ -510,24 +510,24 @@ static void uninit_rendering(struct gl_video *p)
ra_tex_free(p->ra, &p->dither_texture);
for (int n = 0; n < 4; n++) {
- fbotex_uninit(&p->merge_fbo[n]);
- fbotex_uninit(&p->scale_fbo[n]);
- fbotex_uninit(&p->integer_fbo[n]);
+ ra_tex_free(p->ra, &p->merge_tex[n]);
+ ra_tex_free(p->ra, &p->scale_tex[n]);
+ ra_tex_free(p->ra, &p->integer_tex[n]);
}
- fbotex_uninit(&p->indirect_fbo);
- fbotex_uninit(&p->blend_subs_fbo);
- fbotex_uninit(&p->screen_fbo);
- fbotex_uninit(&p->output_fbo);
+ ra_tex_free(p->ra, &p->indirect_tex);
+ ra_tex_free(p->ra, &p->blend_subs_tex);
+ ra_tex_free(p->ra, &p->screen_tex);
+ ra_tex_free(p->ra, &p->output_tex);
- for (int n = 0; n < FBOSURFACES_MAX; n++)
- fbotex_uninit(&p->surfaces[n].fbotex);
+ for (int n = 0; n < SURFACES_MAX; n++)
+ ra_tex_free(p->ra, &p->surfaces[n].tex);
for (int n = 0; n < SHADER_MAX_SAVED; n++)
- fbotex_uninit(&p->hook_fbos[n]);
+ ra_tex_free(p->ra, &p->hook_fbos[n]);
for (int n = 0; n < 2; n++)
- fbotex_uninit(&p->vdpau_deinterleave_fbo[n]);
+ ra_tex_free(p->ra, &p->vdpau_deinterleave_tex[n]);
gl_video_reset_surfaces(p);
gl_video_reset_hooks(p);
@@ -613,29 +613,29 @@ static bool gl_video_get_lut3d(struct gl_video *p, enum mp_csp_prim prim,
return true;
}
-// Fill an img_tex struct from an FBO + some metadata
-static struct img_tex img_tex_fbo(struct fbotex *fbo, enum plane_type type,
- int components)
+// Fill an image struct from a ra_tex + some metadata
+static struct image image_wrap(struct ra_tex *tex, enum plane_type type,
+ int components)
{
assert(type != PLANE_NONE);
- return (struct img_tex){
+ return (struct image){
.type = type,
- .tex = fbo->tex,
+ .tex = tex,
.multiplier = 1.0,
- .w = fbo->lw,
- .h = fbo->lh,
+ .w = tex->params.w,
+ .h = tex->params.h,
.transform = identity_trans,
.components = components,
};
}
-// Bind an img_tex to a free texture unit and return its ID. At most
+// Bind an image to a free texture unit and return its ID. At most
// TEXUNIT_VIDEO_NUM texture units can be bound at once
-static int pass_bind(struct gl_video *p, struct img_tex tex)
+static int pass_bind(struct gl_video *p, struct image img)
{
- assert(p->pass_tex_num < TEXUNIT_VIDEO_NUM);
- p->pass_tex[p->pass_tex_num] = tex;
- return p->pass_tex_num++;
+ assert(p->pass_img_num < TEXUNIT_VIDEO_NUM);
+ p->pass_img[p->pass_img_num] = img;
+ return p->pass_img_num++;
}
// Rotation by 90° and flipping.
@@ -684,11 +684,11 @@ static enum plane_type merge_plane_types(enum plane_type a, enum plane_type b)
return a;
}
-// Places a video_image's image textures + associated metadata into tex[]. The
+// Places a video_image's image textures + associated metadata into img[]. The
// number of textures is equal to p->plane_count. Any necessary plane offsets
// are stored in off. (e.g. chroma position)
-static void pass_get_img_tex(struct gl_video *p, struct video_image *vimg,
- struct img_tex tex[4], struct gl_transform off[4])
+static void pass_get_images(struct gl_video *p, struct video_image *vimg,
+ struct image img[4], struct gl_transform off[4])
{
assert(vimg->mpi);
@@ -721,7 +721,7 @@ static void pass_get_img_tex(struct gl_video *p, struct video_image *vimg,
msb_valid_bits,
p->ra_format.component_bits);
- memset(tex, 0, 4 * sizeof(tex[0]));
+ memset(img, 0, 4 * sizeof(img[0]));
for (int n = 0; n < p->plane_count; n++) {
struct texplane *t = &vimg->planes[n];
@@ -743,7 +743,7 @@ static void pass_get_img_tex(struct gl_video *p, struct video_image *vimg,
type = merge_plane_types(type, ctype);
}
- tex[n] = (struct img_tex){
+ img[n] = (struct image){
.type = type,
.tex = t->tex,
.multiplier = tex_mul,
@@ -752,12 +752,12 @@ static void pass_get_img_tex(struct gl_video *p, struct video_image *vimg,
};
for (int i = 0; i < 4; i++)
- tex[n].components += !!p->ra_format.components[n][i];
+ img[n].components += !!p->ra_format.components[n][i];
get_transform(t->w, t->h, p->image_params.rotate, t->flipped,
- &tex[n].transform);
+ &img[n].transform);
if (p->image_params.rotate % 180 == 90)
- MPSWAP(int, tex[n].w, tex[n].h);
+ MPSWAP(int, img[n].w, img[n].h);
off[n] = identity_trans;
@@ -1060,8 +1060,8 @@ static void pass_prepare_src_tex(struct gl_video *p)
{
struct gl_shader_cache *sc = p->sc;
- for (int n = 0; n < p->pass_tex_num; n++) {
- struct img_tex *s = &p->pass_tex[n];
+ for (int n = 0; n < p->pass_img_num; n++) {
+ struct image *s = &p->pass_img[n];
if (!s->tex)
continue;
@@ -1116,7 +1116,7 @@ static void dispatch_compute(struct gl_video *p, int w, int h,
PRELUDE("#define outcoord(id) (out_scale * (vec2(id) + vec2(0.5)))\n");
for (int n = 0; n < TEXUNIT_VIDEO_NUM; n++) {
- struct img_tex *s = &p->pass_tex[n];
+ struct image *s = &p->pass_img[n];
if (!s->tex)
continue;
@@ -1144,18 +1144,18 @@ static void dispatch_compute(struct gl_video *p, int w, int h,
pass_record(p, gl_sc_dispatch_compute(p->sc, num_x, num_y, 1));
- memset(&p->pass_tex, 0, sizeof(p->pass_tex));
- p->pass_tex_num = 0;
+ memset(&p->pass_img, 0, sizeof(p->pass_img));
+ p->pass_img_num = 0;
}
static struct mp_pass_perf render_pass_quad(struct gl_video *p,
- struct fbodst target,
+ struct ra_fbo fbo,
const struct mp_rect *dst)
{
struct vertex va[6] = {0};
struct gl_transform t;
- gl_transform_ortho_fbodst(&t, target);
+ gl_transform_ortho_fbo(&t, fbo);
float x[2] = {dst->x0, dst->x1};
float y[2] = {dst->y0, dst->y1};
@@ -1166,8 +1166,8 @@ static struct mp_pass_perf render_pass_quad(struct gl_video *p,
struct vertex *v = &va[n];
v->position.x = x[n / 2];
v->position.y = y[n % 2];
- for (int i = 0; i < p->pass_tex_num; i++) {
- struct img_tex *s = &p->pass_tex[i];
+ for (int i = 0; i < p->pass_img_num; i++) {
+ struct image *s = &p->pass_img[i];
if (!s->tex)
continue;
struct gl_transform tr = s->transform;
@@ -1183,33 +1183,32 @@ static struct mp_pass_perf render_pass_quad(struct gl_video *p,
va[4] = va[2];
va[5] = va[1];
- return gl_sc_dispatch_draw(p->sc, target.tex, va, 6);
+ return gl_sc_dispatch_draw(p->sc, fbo.tex, va, 6);
}
-static void finish_pass_direct(struct gl_video *p, struct fbodst target,
+static void finish_pass_fbo(struct gl_video *p, struct ra_fbo fbo,
const struct mp_rect *dst)
{
pass_prepare_src_tex(p);
gl_sc_set_vertex_format(p->sc, vertex_vao, sizeof(struct vertex));
- pass_record(p, render_pass_quad(p, target, dst));
+ pass_record(p, render_pass_quad(p, fbo, dst));
debug_check_gl(p, "after rendering");
- memset(&p->pass_tex, 0, sizeof(p->pass_tex));
- p->pass_tex_num = 0;
+ memset(&p->pass_img, 0, sizeof(p->pass_img));
+ p->pass_img_num = 0;
}
// dst_fbo: this will be used for rendering; possibly reallocating the whole
// FBO, if the required parameters have changed
// w, h: required FBO target dimension, and also defines the target rectangle
// used for rasterization
-static void finish_pass_fbo(struct gl_video *p, struct fbotex *dst_fbo,
+static void finish_pass_tex(struct gl_video *p, struct ra_tex **dst_tex,
int w, int h)
{
- fbotex_change(dst_fbo, p->ra, p->log, w, h, p->fbo_format);
+ if (!ra_tex_resize(p->ra, p->log, dst_tex, w, h, p->fbo_format))
+ return;
if (p->pass_compute.active) {
- if (!dst_fbo->tex)
- return;
- gl_sc_uniform_image2D_wo(p->sc, "out_image", dst_fbo->tex);
+ gl_sc_uniform_image2D_wo(p->sc, "out_image", *dst_tex);
if (!p->pass_compute.directly_writes)
GLSL(imageStore(out_image, ivec2(gl_GlobalInvocationID), color);)
@@ -1218,11 +1217,12 @@ static void finish_pass_fbo(struct gl_video *p, struct fbotex *dst_fbo,
debug_check_gl(p, "after dispatching compute shader");
} else {
- finish_pass_direct(p, dst_fbo->fbo, &(struct mp_rect){0, 0, w, h});
+ struct ra_fbo fbo = { .tex = *dst_tex, };
+ finish_pass_fbo(p, fbo, &(struct mp_rect){0, 0, w, h});
}
}
-static const char *get_tex_swizzle(struct img_tex *img)
+static const char *get_tex_swizzle(struct image *img)
{
if (!img->tex)
return "rgba";
@@ -1231,7 +1231,7 @@ static const char *get_tex_swizzle(struct img_tex *img)
// Copy a texture to the vec4 color, while increasing offset. Also applies
// the texture multiplier to the sampled color
-static void copy_img_tex(struct gl_video *p, int *offset, struct img_tex img)
+static void copy_image(struct gl_video *p, int *offset, struct image img)
{
int count = img.components;
assert(*offset + count <= 4);
@@ -1265,14 +1265,14 @@ static void skip_unused(struct gl_video *p, int num_components)
static void uninit_scaler(struct gl_video *p, struct scaler *scaler)
{
- fbotex_uninit(&scaler->sep_fbo);
+ ra_tex_free(p->ra, &scaler->sep_fbo);
ra_tex_free(p->ra, &scaler->lut);
scaler->kernel = NULL;
scaler->initialized = false;
}
static void hook_prelude(struct gl_video *p, const char *name, int id,
- struct img_tex tex)
+ struct image img)
{
GLSLHF("#define %s_raw texture%d\n", name, id);
GLSLHF("#define %s_pos texcoord%d\n", name, id);
@@ -1280,15 +1280,15 @@ static void hook_prelude(struct gl_video *p, const char *name, int id,
GLSLHF("#define %s_rot texture_rot%d\n", name, id);
GLSLHF("#define %s_pt pixel_size%d\n", name, id);
GLSLHF("#define %s_map texmap%d\n", name, id);
- GLSLHF("#define %s_mul %f\n", name, tex.multiplier);
+ GLSLHF("#define %s_mul %f\n", name, img.multiplier);
// Set up the sampling functions
GLSLHF("#define %s_tex(pos) (%s_mul * vec4(texture(%s_raw, pos)).%s)\n",
- name, name, name, get_tex_swizzle(&tex));
+ name, name, name, get_tex_swizzle(&img));
// Since the extra matrix multiplication impacts performance,
// skip it unless the texture was actually rotated
- if (gl_transform_eq(tex.transform, identity_trans)) {
+ if (gl_transform_eq(img.transform, identity_trans)) {
GLSLHF("#define %s_texOff(off) %s_tex(%s_pos + %s_pt * vec2(off))\n",
name, name, name, name);
} else {
@@ -1298,15 +1298,15 @@ static void hook_prelude(struct gl_video *p, const char *name, int id,
}
}
-static bool saved_tex_find(struct gl_video *p, const char *name,
- struct img_tex *out)
+static bool saved_img_find(struct gl_video *p, const char *name,
+ struct image *out)
{
if (!name || !out)
return false;
- for (int i = 0; i < p->saved_tex_num; i++) {
- if (strcmp(p->saved_tex[i].name, name) == 0) {
- *out = p->saved_tex[i].tex;
+ for (int i = 0; i < p->saved_img_num; i++) {
+ if (strcmp(p->saved_img[i].name, name) == 0) {
+ *out = p->saved_img[i].img;
return true;
}
}
@@ -1314,27 +1314,27 @@ static bool saved_tex_find(struct gl_video *p, const char *name,
return false;
}
-static void saved_tex_store(struct gl_video *p, const char *name,
- struct img_tex tex)
+static void saved_img_store(struct gl_video *p, const char *name,
+ struct image img)
{
assert(name);
- for (int i = 0; i < p->saved_tex_num; i++) {
- if (strcmp(p->saved_tex[i].name, name) == 0) {
- p->saved_tex[i].tex = tex;
+ for (int i = 0; i < p->saved_img_num; i++) {
+ if (strcmp(p->saved_img[i].name, name) == 0) {
+ p->saved_img[i].img = img;
return;
}
}
- assert(p->saved_tex_num < SHADER_MAX_SAVED);
- p->saved_tex[p->saved_tex_num++] = (struct saved_tex) {
+ assert(p->saved_img_num < SHADER_MAX_SAVED);
+ p->saved_img[p->saved_img_num++] = (struct saved_img) {
.name = name,
- .tex = tex
+ .img = img
};
}
static bool pass_hook_setup_binds(struct gl_video *p, const char *name,
- struct img_tex tex, struct tex_hook *hook)
+ struct image img, struct tex_hook *hook)
{
for (int t = 0; t < TEXUNIT_VIDEO_NUM; t++) {
char *bind_name = (char *)hook->bind_tex[t];
@@ -1344,9 +1344,9 @@ static bool pass_hook_setup_binds(struct gl_video *p, const char *name,
// This is a special name that means "currently hooked texture"
if (strcmp(bind_name, "HOOKED") == 0) {
- int id = pass_bind(p, tex);
- hook_prelude(p, "HOOKED", id, tex);
- hook_prelude(p, name, id, tex);
+ int id = pass_bind(p, img);
+ hook_prelude(p, "HOOKED", id, img);
+ hook_prelude(p, name, id, img);
continue;
}
@@ -1361,16 +1361,16 @@ static bool pass_hook_setup_binds(struct gl_video *p, const char *name,
}
}
- struct img_tex bind_tex;
- if (!saved_tex_find(p, bind_name, &bind_tex)) {
+ struct image bind_img;
+ if (!saved_img_find(p, bind_name, &bind_img)) {
// Clean up texture bindings and move on to the next hook
MP_DBG(p, "Skipping hook on %s due to no texture named %s.\n",
name, bind_name);
- p->pass_tex_num -= t;
+ p->pass_img_num -= t;
return false;
}
- hook_prelude(p, bind_name, pass_bind(p, bind_tex), bind_tex);
+ hook_prelude(p, bind_name, pass_bind(p, bind_img), bind_img);
next_bind: ;
}
@@ -1378,15 +1378,15 @@ next_bind: ;
return true;
}
-// Process hooks for a plane, saving the result and returning a new img_tex
-// If 'trans' is NULL, the shader is forbidden from transforming tex
-static struct img_tex pass_hook(struct gl_video *p, const char *name,
- struct img_tex tex, struct gl_transform *trans)
+// Process hooks for a plane, saving the result and returning a new image
+// If 'trans' is NULL, the shader is forbidden from transforming img
+static struct image pass_hook(struct gl_video *p, const char *name,
+ struct image img, struct gl_transform *trans)
{
if (!name)
- return tex;
+ return img;
- saved_tex_store(p, name, tex);
+ saved_img_store(p, name, img);
MP_DBG(p, "Running hooks for %s\n", name);
for (int i = 0; i < p->tex_hook_num; i++) {
@@ -1402,34 +1402,34 @@ static struct img_tex pass_hook(struct gl_video *p, const char *name,
found:
// Check the hook's condition
- if (hook->cond && !hook->cond(p, tex, hook->priv)) {
+ if (hook->cond && !hook->cond(p, img, hook->priv)) {
MP_DBG(p, "Skipping hook on %s due to condition.\n", name);
continue;
}
- if (!pass_hook_setup_binds(p, name, tex, hook))
+ if (!pass_hook_setup_binds(p, name, img, hook))
continue;
// Run the actual hook. This generates a series of GLSL shader
// instructions sufficient for drawing the hook's output
struct gl_transform hook_off = identity_trans;
- hook->hook(p, tex, &hook_off, hook->priv);
+ hook->hook(p, img, &hook_off, hook->priv);
- int comps = hook->components ? hook->components : tex.components;
+ int comps = hook->components ? hook->components : img.components;
skip_unused(p, comps);
// Compute the updated FBO dimensions and store the result
- struct mp_rect_f sz = {0, 0, tex.w, tex.h};
+ struct mp_rect_f sz = {0, 0, img.w, img.h};
gl_transform_rect(hook_off, &sz);
int w = lroundf(fabs(sz.x1 - sz.x0));
int h = lroundf(fabs(sz.y1 - sz.y0));
assert(p->hook_fbo_num < SHADER_MAX_SAVED);
- struct fbotex *fbo = &p->hook_fbos[p->hook_fbo_num++];
- finish_pass_fbo(p, fbo, w, h);
+ struct ra_tex **fbo = &p->hook_fbos[p->hook_fbo_num++];
+ finish_pass_tex(p, fbo, w, h);
const char *store_name = hook->save_tex ? hook->save_tex : name;
- struct img_tex saved_tex = img_tex_fbo(fbo, tex.type, comps);
+ struct image saved_img = image_wrap(*fbo, img.type, comps);
// If the texture we're saving overwrites the "current" texture, also
// update the tex parameter so that the future loop cycles will use the
@@ -1438,18 +1438,18 @@ found:
if (!trans && !gl_transform_eq(hook_off, identity_trans)) {
MP_ERR(p, "Hook tried changing size of unscalable texture %s!\n",
name);
- return tex;
+ return img;
}
- tex = saved_tex;
+ img = saved_img;
if (trans)
gl_transform_trans(hook_off, trans);
}
- saved_tex_store(p, store_name, saved_tex);
+ saved_img_store(p, store_name, saved_img);
}
- return tex;
+ return img;
}
// This can be used at any time in the middle of rendering to specify an
@@ -1482,12 +1482,12 @@ static void pass_opt_hook_point(struct gl_video *p, const char *name,
found:
assert(p->hook_fbo_num < SHADER_MAX_SAVED);
- struct fbotex *fbo = &p->hook_fbos[p->hook_fbo_num++];
- finish_pass_fbo(p, fbo, p->texture_w, p->texture_h);
+ struct ra_tex **tex = &p->hook_fbos[p->hook_fbo_num++];
+ finish_pass_tex(p, tex, p->texture_w, p->texture_h);
- struct img_tex img = img_tex_fbo(fbo, PLANE_RGB, p->components);
+ struct image img = image_wrap(*tex, PLANE_RGB, p->components);
img = pass_hook(p, name, img, tex_trans);
- copy_img_tex(p, &(int){0}, img);
+ copy_image(p, &(int){0}, img);
p->texture_w = img.w;
p->texture_h = img.h;
p->components = img.components;
@@ -1635,7 +1635,7 @@ static void reinit_scaler(struct gl_video *p, struct scaler *scaler,
}
// Special helper for sampling from two separated stages
-static void pass_sample_separated(struct gl_video *p, struct img_tex src,
+static void pass_sample_separated(struct gl_video *p, struct image src,
struct scaler *scaler, int w, int h)
{
// Separate the transformation into x and y components, per pass
@@ -1654,10 +1654,10 @@ static void pass_sample_separated(struct gl_video *p, struct img_tex src,
GLSLF("// first pass\n");
pass_sample_separated_gen(p->sc, scaler, 0, 1);
GLSLF("color *= %f;\n", src.multiplier);
- finish_pass_fbo(p, &scaler->sep_fbo, src.w, h);
+ finish_pass_tex(p, &scaler->sep_fbo, src.w, h);
// Second pass (scale only in the x dir)
- src = img_tex_fbo(&scaler->sep_fbo, src.type, src.components);
+ src = image_wrap(scaler->sep_fbo, src.type, src.components);
src.transform = t_x;
pass_describe(p, "%s second pass", scaler->conf.kernel.name);
sampler_prelude(p->sc, pass_bind(p, src));
@@ -1667,7 +1667,7 @@ static void pass_sample_separated(struct gl_video *p, struct img_tex src,
// Picks either the compute shader version or the regular sampler version
// depending on hardware support
static void pass_dispatch_sample_polar(struct gl_video *p, struct scaler *scaler,
-