Merge branch 'frame-scheduler-helper' into 'master'

Draft: render: add frame scheduler helper

See merge request wlroots/wlroots!3783
This commit is contained in:
Simon Ser 2022-11-14 17:37:40 +00:00
commit e7737537ef
13 changed files with 479 additions and 7 deletions

View file

@ -32,6 +32,10 @@ struct wlr_gles2_tex_shader {
GLint tex_attrib;
};
// Fixed here, but missing from any libglvnd release:
// https://gitlab.freedesktop.org/glvnd/libglvnd/-/merge_requests/268
typedef void (GL_APIENTRYP PFNGLGETINTEGER64VEXTPROC) (GLenum pname, GLint64 *data);
struct wlr_gles2_renderer {
struct wlr_renderer wlr_renderer;
@ -48,6 +52,7 @@ struct wlr_gles2_renderer {
bool EXT_texture_type_2_10_10_10_REV;
bool OES_texture_half_float_linear;
bool EXT_texture_norm16;
bool EXT_disjoint_timer_query;
} exts;
struct {
@ -57,6 +62,11 @@ struct wlr_gles2_renderer {
PFNGLPOPDEBUGGROUPKHRPROC glPopDebugGroupKHR;
PFNGLPUSHDEBUGGROUPKHRPROC glPushDebugGroupKHR;
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES;
PFNGLGETINTEGER64VEXTPROC glGetInteger64vEXT;
PFNGLGENQUERIESEXTPROC glGenQueriesEXT;
PFNGLDELETEQUERIESEXTPROC glDeleteQueriesEXT;
PFNGLQUERYCOUNTEREXTPROC glQueryCounterEXT;
PFNGLGETQUERYOBJECTI64VEXTPROC glGetQueryObjecti64vEXT;
} procs;
struct {
@ -112,6 +122,12 @@ struct wlr_gles2_texture {
struct wlr_addon buffer_addon;
};
struct wlr_gles2_timestamp {
struct wlr_render_timestamp base;
struct wlr_gles2_renderer *renderer;
GLuint query;
};
bool is_gles2_pixel_format_supported(const struct wlr_gles2_renderer *renderer,
const struct wlr_gles2_pixel_format *format);

View file

@ -13,11 +13,22 @@ uint32_t get_current_time_msec(void);
*/
int64_t timespec_to_msec(const struct timespec *a);
/**
* Convert a timespec to nanoseconds.
*/
int64_t timespec_to_nsec(const struct timespec *t);
/**
* Convert nanoseconds to a timespec.
*/
void timespec_from_nsec(struct timespec *r, int64_t nsec);
/**
* Add two timespec values `a` and `b`, and store the result in `r`.
*/
void timespec_add(struct timespec *r, const struct timespec *a,
const struct timespec *b);
/**
* Subtracts timespec `b` from timespec `a`, and stores the difference in `r`.
*/

View file

@ -48,6 +48,8 @@ struct wlr_renderer_impl {
uint32_t (*get_render_buffer_caps)(struct wlr_renderer *renderer);
struct wlr_texture *(*texture_from_buffer)(struct wlr_renderer *renderer,
struct wlr_buffer *buffer);
bool (*get_time)(struct wlr_renderer *r, struct timespec *t);
struct wlr_render_timestamp *(*create_timestamp)(struct wlr_renderer *r);
};
void wlr_renderer_init(struct wlr_renderer *renderer,
@ -62,4 +64,17 @@ struct wlr_texture_impl {
void wlr_texture_init(struct wlr_texture *texture,
const struct wlr_texture_impl *impl, uint32_t width, uint32_t height);
struct wlr_render_timestamp {
const struct wlr_render_timestamp_impl *impl;
};
struct wlr_render_timestamp_impl {
void (*destroy)(struct wlr_render_timestamp *timestamp);
bool (*get_time)(struct wlr_render_timestamp *timestamp,
struct timespec *t);
};
void wlr_render_timestamp_init(struct wlr_render_timestamp *timestamp,
const struct wlr_render_timestamp_impl *impl);
#endif

View file

@ -14,6 +14,8 @@
#include <wlr/backend.h>
#include <wlr/render/wlr_texture.h>
struct timespec;
struct wlr_renderer_impl;
struct wlr_drm_format_set;
struct wlr_buffer;
@ -112,6 +114,20 @@ bool wlr_renderer_init_wl_shm(struct wlr_renderer *r,
*/
int wlr_renderer_get_drm_fd(struct wlr_renderer *r);
/**
* Get the current GPU time.
*/
bool wlr_renderer_get_time(struct wlr_renderer *r, struct timespec *t);
struct wlr_render_timestamp;
struct wlr_render_timestamp *wlr_renderer_create_timestamp(struct wlr_renderer *r);
bool wlr_render_timestamp_get_time(struct wlr_render_timestamp *timestamp,
struct timespec *t);
void wlr_render_timestamp_destroy(struct wlr_render_timestamp *timestamp);
/**
* Destroys the renderer.
*

View file

@ -0,0 +1,55 @@
/*
* This an unstable interface of wlroots. No guarantees are made regarding the
* future consistency of this API.
*/
#ifndef WLR_USE_UNSTABLE
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
#endif
#ifndef WLR_TYPES_WLR_FRAME_SCHEDULER_H
#define WLR_TYPES_WLR_FRAME_SCHEDULER_H
#include <wayland-server-core.h>
#include <time.h>
struct wlr_renderer;
struct wlr_render_timestamp;
#define WLR_FRAME_SCHEDULER_HISTOGRAM_LEN 128
struct wlr_frame_scheduler_bucket {
int64_t cpu_duration_ns, gpu_duration_ns;
};
struct wlr_frame_scheduler {
struct wlr_output *output;
clockid_t presentation_clock;
struct {
struct wl_signal frame;
} events;
// private state
struct wl_event_source *timer;
struct wlr_frame_scheduler_bucket histogram[WLR_FRAME_SCHEDULER_HISTOGRAM_LEN];
size_t histogram_cur;
struct wl_listener output_present;
struct {
uint32_t commit_seq;
struct timespec frame_emitted, frame_submitted; // CPU time
struct timespec render_submitted; // GPU time
struct wlr_render_timestamp *render_complete;
} queued;
};
bool wlr_frame_scheduler_init(struct wlr_frame_scheduler *scheduler,
struct wlr_output *output);
void wlr_frame_scheduler_finish(struct wlr_frame_scheduler *scheduler);
void wlr_frame_scheduler_mark_render_submitted(
struct wlr_frame_scheduler *scheduler, struct wlr_renderer *renderer);
#endif

View file

@ -23,6 +23,7 @@
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_damage_ring.h>
#include <wlr/types/wlr_frame_scheduler.h>
struct wlr_output;
struct wlr_output_layout;
@ -166,6 +167,7 @@ struct wlr_scene_output {
struct wlr_addon addon;
struct wlr_damage_ring damage_ring;
struct wlr_frame_scheduler frame_scheduler;
int x, y;