mirror of
https://github.com/mpv-player/mpv
synced 2025-01-10 00:49:32 +00:00
46d86da630
- tex_uploads args are moved to a struct - the ability to directly upload texture data without going through a buffer is made explicit - the concept of buffer updates and buffer polling is made more explicit and generalized to buf_update as well (not just mapped buffers) - the ability to call tex_upload/buf_update on a tex/buf is made explicit during tex/buf creation - uploading from buffers now uses an explicit offset instead of implicitly comparing *src against buf->data, because not all buffers may actually be persistently mapped - the initial_data = immutable requirement is dropped. (May be re-added later for D3D11 if that ever becomes a thing) This change helps the vulkan abstraction immensely and also helps move common code (like the PBO pooling) out of ra_gl and into the opengl/utils.c This also technically has the side-benefit / side-constraint of using PBOs for OSD texture uploads as well, which actually seems to help performance on machines where --opengl-pbo is faster than the naive code path. Because of this, I decided to hook up the OSD code to the opengl-pbo option as well. One drawback of this refactor is that the GL_STREAM_COPY hack for texture uploads "got lost", but I think I'm happy with that going away anyway since DR almost fully deprecates it, and it's not the "right thing" anyway - but instead an nvidia-only hack to make this stuff work somewhat better on NUMA systems with discrete GPUs. Another change is that due to the way fencing works with ra_buf (we get one fence per ra_buf per upload) we have to use multiple ra_bufs instead of offsets into a shared buffer. But for OpenGL this is probably better anyway. It's possible that in future, we could support having independent “buffer slices” (each with their own fence/sync object), but this would be an optimization more than anything. I also think that we could address the underlying problem (memory closeness) differently by making the ra_vk memory allocator smart enough to chunk together allocations under the hood.
113 lines
3.1 KiB
C
113 lines
3.1 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <math.h>
|
|
|
|
#include "ra.h"
|
|
|
|
// A 3x2 matrix, with the translation part separate.
|
|
struct gl_transform {
|
|
// row-major, e.g. in mathematical notation:
|
|
// | m[0][0] m[0][1] |
|
|
// | m[1][0] m[1][1] |
|
|
float m[2][2];
|
|
float t[2];
|
|
};
|
|
|
|
static const struct gl_transform identity_trans = {
|
|
.m = {{1.0, 0.0}, {0.0, 1.0}},
|
|
.t = {0.0, 0.0},
|
|
};
|
|
|
|
void gl_transform_ortho(struct gl_transform *t, float x0, float x1,
|
|
float y0, float y1);
|
|
|
|
// This treats m as an affine transformation, in other words m[2][n] gets
|
|
// added to the output.
|
|
static inline void gl_transform_vec(struct gl_transform t, float *x, float *y)
|
|
{
|
|
float vx = *x, vy = *y;
|
|
*x = vx * t.m[0][0] + vy * t.m[0][1] + t.t[0];
|
|
*y = vx * t.m[1][0] + vy * t.m[1][1] + t.t[1];
|
|
}
|
|
|
|
struct mp_rect_f {
|
|
float x0, y0, x1, y1;
|
|
};
|
|
|
|
// Semantic equality (fuzzy comparison)
|
|
static inline bool mp_rect_f_seq(struct mp_rect_f a, struct mp_rect_f b)
|
|
{
|
|
return fabs(a.x0 - b.x0) < 1e-6 && fabs(a.x1 - b.x1) < 1e-6 &&
|
|
fabs(a.y0 - b.y0) < 1e-6 && fabs(a.y1 - b.y1) < 1e-6;
|
|
}
|
|
|
|
static inline void gl_transform_rect(struct gl_transform t, struct mp_rect_f *r)
|
|
{
|
|
gl_transform_vec(t, &r->x0, &r->y0);
|
|
gl_transform_vec(t, &r->x1, &r->y1);
|
|
}
|
|
|
|
static inline bool gl_transform_eq(struct gl_transform a, struct gl_transform b)
|
|
{
|
|
for (int x = 0; x < 2; x++) {
|
|
for (int y = 0; y < 2; y++) {
|
|
if (a.m[x][y] != b.m[x][y])
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return a.t[0] == b.t[0] && a.t[1] == b.t[1];
|
|
}
|
|
|
|
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);
|
|
|
|
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,
|
|
int w, int h, const struct ra_format *fmt, int flags);
|
|
#define FBOTEX_FUZZY_W 1
|
|
#define FBOTEX_FUZZY_H 2
|
|
#define FBOTEX_FUZZY (FBOTEX_FUZZY_W | FBOTEX_FUZZY_H)
|
|
|
|
#define NUM_PBO_BUFFERS 3
|
|
|
|
// A wrapper around tex_upload that uses PBOs internally if requested or
|
|
// required
|
|
struct tex_upload {
|
|
size_t buffer_size;
|
|
struct ra_buf *buffers[NUM_PBO_BUFFERS];
|
|
int index;
|
|
};
|
|
|
|
bool tex_upload(struct ra *ra, struct tex_upload *pbo, bool want_pbo,
|
|
const struct ra_tex_upload_params *params);
|
|
|
|
void tex_upload_uninit(struct ra *ra, struct tex_upload *pbo);
|
|
|
|
// A wrapper around ra_timer that does result pooling, averaging etc.
|
|
struct timer_pool;
|
|
|
|
struct timer_pool *timer_pool_create(struct ra *ra);
|
|
void timer_pool_destroy(struct timer_pool *pool);
|
|
void timer_pool_start(struct timer_pool *pool);
|
|
void timer_pool_stop(struct timer_pool *pool);
|
|
struct mp_pass_perf timer_pool_measure(struct timer_pool *pool);
|
|
|
|
// print a multi line string with line numbers (e.g. for shader sources)
|
|
// log, lev: module and log level, as in mp_msg()
|
|
void mp_log_source(struct mp_log *log, int lev, const char *src);
|