2017-08-04 17:09:46 +00:00
|
|
|
#include "common/msg.h"
|
2017-08-05 16:20:45 +00:00
|
|
|
#include "video/out/vo.h"
|
2015-08-29 02:12:56 +00:00
|
|
|
#include "utils.h"
|
2015-01-28 18:40:46 +00:00
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
// Standard parallel 2D projection, except y1 < y0 means that the coordinate
|
|
|
|
// system is flipped, not the projection.
|
|
|
|
void gl_transform_ortho(struct gl_transform *t, float x0, float x1,
|
|
|
|
float y0, float y1)
|
2015-01-28 21:22:29 +00:00
|
|
|
{
|
2017-08-04 17:09:46 +00:00
|
|
|
if (y1 < y0) {
|
|
|
|
float tmp = y0;
|
|
|
|
y0 = tmp - y1;
|
|
|
|
y1 = tmp;
|
2015-01-28 21:22:29 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
t->m[0][0] = 2.0f / (x1 - x0);
|
|
|
|
t->m[0][1] = 0.0f;
|
|
|
|
t->m[1][0] = 0.0f;
|
|
|
|
t->m[1][1] = 2.0f / (y1 - y0);
|
|
|
|
t->t[0] = -(x1 + x0) / (x1 - x0);
|
|
|
|
t->t[1] = -(y1 + y0) / (y1 - y0);
|
2015-01-28 21:22:29 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 17:09:46 +00:00
|
|
|
// Apply the effects of one transformation to another, transforming it in the
|
|
|
|
// process. In other words: post-composes t onto x
|
|
|
|
void gl_transform_trans(struct gl_transform t, struct gl_transform *x)
|
2015-01-29 16:19:01 +00:00
|
|
|
{
|
2017-08-04 17:09:46 +00:00
|
|
|
struct gl_transform xt = *x;
|
|
|
|
x->m[0][0] = t.m[0][0] * xt.m[0][0] + t.m[0][1] * xt.m[1][0];
|
|
|
|
x->m[1][0] = t.m[1][0] * xt.m[0][0] + t.m[1][1] * xt.m[1][0];
|
|
|
|
x->m[0][1] = t.m[0][0] * xt.m[0][1] + t.m[0][1] * xt.m[1][1];
|
|
|
|
x->m[1][1] = t.m[1][0] * xt.m[0][1] + t.m[1][1] * xt.m[1][1];
|
|
|
|
gl_transform_vec(t, &x->t[0], &x->t[1]);
|
2015-01-29 16:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-29 13:58:26 +00:00
|
|
|
// Create a texture and a FBO using the texture as color attachments.
|
2017-08-04 11:48:37 +00:00
|
|
|
// fmt: texture internal format
|
2015-01-29 13:58:26 +00:00
|
|
|
// Returns success.
|
2017-08-04 11:48:37 +00:00
|
|
|
bool fbotex_init(struct fbotex *fbo, struct ra *ra, struct mp_log *log,
|
|
|
|
int w, int h, const struct ra_format *fmt)
|
2015-01-29 13:58:26 +00:00
|
|
|
{
|
2017-08-04 11:48:37 +00:00
|
|
|
assert(!fbo->tex);
|
|
|
|
return fbotex_change(fbo, ra, log, w, h, fmt, 0);
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Like fbotex_init(), except it can be called on an already initialized FBO;
|
|
|
|
// and if the parameters are the same as the previous call, do not touch it.
|
2017-07-25 04:31:34 +00:00
|
|
|
// flags can be 0, or a combination of FBOTEX_FUZZY_W and FBOTEX_FUZZY_H.
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
// Enabling FUZZY for W or H means the w or h does not need to be exact.
|
2017-08-04 11:48:37 +00:00
|
|
|
bool fbotex_change(struct fbotex *fbo, struct ra *ra, struct mp_log *log,
|
|
|
|
int w, int h, const struct ra_format *fmt, int flags)
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
{
|
2017-08-04 11:48:37 +00:00
|
|
|
if (fbo->tex) {
|
|
|
|
int cw = w, ch = h;
|
|
|
|
int rw = fbo->tex->params.w, rh = fbo->tex->params.h;
|
|
|
|
|
|
|
|
if ((flags & FBOTEX_FUZZY_W) && cw < rw)
|
|
|
|
cw = rw;
|
|
|
|
if ((flags & FBOTEX_FUZZY_H) && ch < rh)
|
|
|
|
ch = rh;
|
|
|
|
|
|
|
|
if (rw == cw && rh == ch && fbo->tex->params.format == fmt) {
|
|
|
|
fbo->lw = w;
|
|
|
|
fbo->lh = h;
|
|
|
|
return true;
|
|
|
|
}
|
vo_opengl: refactor pass_read_video and texture binding
This is a pretty major rewrite of the internal texture binding
mechanic, which makes it more flexible.
In general, the difference between the old and current approaches is
that now, all texture description is held in a struct img_tex and only
explicitly bound with pass_bind. (Once bound, a texture unit is assumed
to be set in stone and no longer tied to the img_tex)
This approach makes the code inside pass_read_video significantly more
flexible and cuts down on the number of weird special cases and
spaghetti logic.
It also has some improvements, e.g. cutting down greatly on the number
of unnecessary conversion passes inside pass_read_video (which was
previously mostly done to cope with the fact that the alternative would
have resulted in a combinatorial explosion of code complexity).
Some other notable changes (and potential improvements):
- texture expansion is now *always* handled in pass_read_video, and the
colormatrix never does this anymore. (Which means the code could
probably be removed from the colormatrix generation logic, modulo some
other VOs)
- struct fbo_tex now stores both its "physical" and "logical"
(configured) size, which cuts down on the amount of width/height
baggage on some function calls
- vo_opengl can now technically support textures with different bit
depths (e.g. 10 bit luma, 8 bit chroma) - but the APIs it queries
inside img_format.c doesn't export this (nor does ffmpeg support it,
really) so the status quo of using the same tex_mul for all planes is
kept.
- dumb_mode is now only needed because of the indirect_fbo being in the
main rendering pipeline. If we reintroduce p->use_indirect and thread
a transform through the entire program this could be skipped where
unnecessary, allowing for the removal of dumb_mode. But I'm not sure
how to do this in a clean way. (Which is part of why it got introduced
to begin with)
- It would be trivial to resurrect source-shader now (it would just be
one extra 'if' inside pass_read_video).
2016-03-05 10:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int lw = w, lh = h;
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
|
|
|
|
if (flags & FBOTEX_FUZZY_W)
|
|
|
|
w = MP_ALIGN_UP(w, 256);
|
|
|
|
if (flags & FBOTEX_FUZZY_H)
|
|
|
|
h = MP_ALIGN_UP(h, 256);
|
|
|
|
|
2016-05-12 18:08:49 +00:00
|
|
|
mp_verbose(log, "Create FBO: %dx%d (%dx%d)\n", lw, lh, w, h);
|
2015-01-29 13:58:26 +00:00
|
|
|
|
2017-08-04 11:48:37 +00:00
|
|
|
if (!fmt || !fmt->renderable || !fmt->linear_filter) {
|
|
|
|
mp_err(log, "Format %s not supported.\n", fmt ? fmt->name : "(unset)");
|
2016-05-12 18:08:49 +00:00
|
|
|
return false;
|
2015-11-19 20:17:57 +00:00
|
|
|
}
|
2016-05-12 18:08:49 +00:00
|
|
|
|
2016-06-08 15:49:10 +00:00
|
|
|
fbotex_uninit(fbo);
|
|
|
|
|
2015-01-29 13:58:26 +00:00
|
|
|
*fbo = (struct fbotex) {
|
2017-08-04 11:48:37 +00:00
|
|
|
.ra = ra,
|
vo_opengl: refactor pass_read_video and texture binding
This is a pretty major rewrite of the internal texture binding
mechanic, which makes it more flexible.
In general, the difference between the old and current approaches is
that now, all texture description is held in a struct img_tex and only
explicitly bound with pass_bind. (Once bound, a texture unit is assumed
to be set in stone and no longer tied to the img_tex)
This approach makes the code inside pass_read_video significantly more
flexible and cuts down on the number of weird special cases and
spaghetti logic.
It also has some improvements, e.g. cutting down greatly on the number
of unnecessary conversion passes inside pass_read_video (which was
previously mostly done to cope with the fact that the alternative would
have resulted in a combinatorial explosion of code complexity).
Some other notable changes (and potential improvements):
- texture expansion is now *always* handled in pass_read_video, and the
colormatrix never does this anymore. (Which means the code could
probably be removed from the colormatrix generation logic, modulo some
other VOs)
- struct fbo_tex now stores both its "physical" and "logical"
(configured) size, which cuts down on the amount of width/height
baggage on some function calls
- vo_opengl can now technically support textures with different bit
depths (e.g. 10 bit luma, 8 bit chroma) - but the APIs it queries
inside img_format.c doesn't export this (nor does ffmpeg support it,
really) so the status quo of using the same tex_mul for all planes is
kept.
- dumb_mode is now only needed because of the indirect_fbo being in the
main rendering pipeline. If we reintroduce p->use_indirect and thread
a transform through the entire program this could be skipped where
unnecessary, allowing for the removal of dumb_mode. But I'm not sure
how to do this in a clean way. (Which is part of why it got introduced
to begin with)
- It would be trivial to resurrect source-shader now (it would just be
one extra 'if' inside pass_read_video).
2016-03-05 10:29:19 +00:00
|
|
|
.rw = w,
|
|
|
|
.rh = h,
|
|
|
|
.lw = lw,
|
|
|
|
.lh = lh,
|
2015-01-29 13:58:26 +00:00
|
|
|
};
|
|
|
|
|
2017-08-04 11:48:37 +00:00
|
|
|
struct ra_tex_params params = {
|
|
|
|
.dimensions = 2,
|
|
|
|
.w = w,
|
|
|
|
.h = h,
|
|
|
|
.d = 1,
|
|
|
|
.format = fmt,
|
|
|
|
.src_linear = true,
|
|
|
|
.render_src = true,
|
|
|
|
.render_dst = true,
|
|
|
|
};
|
2015-01-29 13:58:26 +00:00
|
|
|
|
2017-08-04 11:48:37 +00:00
|
|
|
fbo->tex = ra_tex_create(fbo->ra, ¶ms);
|
2017-07-25 04:31:34 +00:00
|
|
|
|
2017-08-04 11:48:37 +00:00
|
|
|
if (!fbo->tex) {
|
|
|
|
mp_err(log, "Error: framebuffer could not be created.\n");
|
|
|
|
fbotex_uninit(fbo);
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-25 04:31:34 +00:00
|
|
|
|
2017-08-04 11:48:37 +00:00
|
|
|
return true;
|
2015-01-29 13:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fbotex_uninit(struct fbotex *fbo)
|
|
|
|
{
|
2017-08-04 11:48:37 +00:00
|
|
|
if (fbo->ra) {
|
|
|
|
ra_tex_free(fbo->ra, &fbo->tex);
|
2015-01-29 13:58:26 +00:00
|
|
|
*fbo = (struct fbotex) {0};
|
|
|
|
}
|
|
|
|
}
|
2017-08-05 16:20:45 +00:00
|
|
|
|
|
|
|
struct timer_pool {
|
|
|
|
struct ra *ra;
|
|
|
|
ra_timer *timer;
|
|
|
|
bool running; // detect invalid usage
|
|
|
|
|
|
|
|
uint64_t samples[PERF_SAMPLE_COUNT];
|
|
|
|
int sample_idx;
|
|
|
|
int sample_count;
|
|
|
|
|
|
|
|
uint64_t avg_sum;
|
|
|
|
uint64_t peak;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct timer_pool *timer_pool_create(struct ra *ra)
|
|
|
|
{
|
|
|
|
ra_timer *timer = ra->fns->timer_create(ra);
|
|
|
|
if (!timer)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
struct timer_pool *pool = talloc(NULL, struct timer_pool);
|
|
|
|
if (!pool) {
|
|
|
|
ra->fns->timer_destroy(ra, timer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pool = (struct timer_pool){ .ra = ra, .timer = timer };
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_pool_destroy(struct timer_pool *pool)
|
|
|
|
{
|
|
|
|
if (!pool)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pool->ra->fns->timer_destroy(pool->ra, pool->timer);
|
|
|
|
talloc_free(pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_pool_start(struct timer_pool *pool)
|
|
|
|
{
|
|
|
|
if (!pool)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(!pool->running);
|
|
|
|
pool->ra->fns->timer_start(pool->ra, pool->timer);
|
|
|
|
pool->running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_pool_stop(struct timer_pool *pool)
|
|
|
|
{
|
|
|
|
if (!pool)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(pool->running);
|
|
|
|
uint64_t res = pool->ra->fns->timer_stop(pool->ra, pool->timer);
|
|
|
|
pool->running = false;
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
// Input res into the buffer and grab the previous value
|
|
|
|
uint64_t old = pool->samples[pool->sample_idx];
|
|
|
|
pool->samples[pool->sample_idx++] = res;
|
|
|
|
pool->sample_idx %= PERF_SAMPLE_COUNT;
|
|
|
|
|
|
|
|
// Update average and sum
|
|
|
|
pool->avg_sum = pool->avg_sum + res - old;
|
|
|
|
pool->sample_count = MPMIN(pool->sample_count + 1, PERF_SAMPLE_COUNT);
|
|
|
|
|
|
|
|
// Update peak if necessary
|
|
|
|
if (res >= pool->peak) {
|
|
|
|
pool->peak = res;
|
|
|
|
} else if (pool->peak == old) {
|
|
|
|
// It's possible that the last peak was the value we just removed,
|
|
|
|
// if so we need to scan for the new peak
|
|
|
|
uint64_t peak = res;
|
|
|
|
for (int i = 0; i < PERF_SAMPLE_COUNT; i++)
|
|
|
|
peak = MPMAX(peak, pool->samples[i]);
|
|
|
|
pool->peak = peak;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mp_pass_perf timer_pool_measure(struct timer_pool *pool)
|
|
|
|
{
|
|
|
|
if (!pool)
|
|
|
|
return (struct mp_pass_perf){0};
|
|
|
|
|
|
|
|
struct mp_pass_perf res = {
|
|
|
|
.count = pool->sample_count,
|
|
|
|
.index = (pool->sample_idx - pool->sample_count) % PERF_SAMPLE_COUNT,
|
|
|
|
.peak = pool->peak,
|
|
|
|
.samples = pool->samples,
|
|
|
|
};
|
|
|
|
|
|
|
|
res.last = pool->samples[(pool->sample_idx - 1) % PERF_SAMPLE_COUNT];
|
|
|
|
|
|
|
|
if (pool->sample_count > 0) {
|
|
|
|
res.avg = pool->avg_sum / pool->sample_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2017-08-05 17:38:43 +00:00
|
|
|
|
|
|
|
void mp_log_source(struct mp_log *log, int lev, const char *src)
|
|
|
|
{
|
|
|
|
int line = 1;
|
|
|
|
if (!src)
|
|
|
|
return;
|
|
|
|
while (*src) {
|
|
|
|
const char *end = strchr(src, '\n');
|
|
|
|
const char *next = end + 1;
|
|
|
|
if (!end)
|
|
|
|
next = end = src + strlen(src);
|
|
|
|
mp_msg(log, lev, "[%3d] %.*s\n", line, (int)(end - src), src);
|
|
|
|
line++;
|
|
|
|
src = next;
|
|
|
|
}
|
|
|
|
}
|