tune shadow and drm video engines to show FPS

This commit is contained in:
Vincent Wei
2023-07-21 10:40:31 +08:00
parent bc0efac21f
commit 73fcb8d2c3
4 changed files with 76 additions and 35 deletions
+18 -10
View File
@@ -47,6 +47,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
// #define _DEBUG
#include "common.h" #include "common.h"
#ifdef _MGGAL_DRM #ifdef _MGGAL_DRM
@@ -1135,7 +1137,7 @@ static int open_drm_device(GAL_VideoDevice *device)
int auth_result; int auth_result;
if (drmGetMagic(fd, &magic)) { if (drmGetMagic(fd, &magic)) {
_DBG_PRINTF("failed to call drmGetMagic: %m\n"); _ERR_PRINTF("failed to call drmGetMagic: %m\n");
return -errno; return -errno;
} }
@@ -2507,11 +2509,11 @@ static void update_real_screen_memcpy(_THIS)
int real_pitch = real_buff->pitch; int real_pitch = real_buff->pitch;
size_t count = cpp * RECTWP(update_rect); size_t count = cpp * RECTWP(update_rect);
#if 0 // def _DEBUG
_DBG_PRINTF("Copy pixels to real screen (pitch: %u, count: %u, %d x %d)\n", _DBG_PRINTF("Copy pixels to real screen (pitch: %u, count: %u, %d x %d)\n",
(unsigned)real_buff->pitch, (unsigned)count, (unsigned)real_buff->pitch, (unsigned)count,
RECTWP(update_rect), RECTHP(update_rect)); RECTWP(update_rect), RECTHP(update_rect));
#ifdef _DEBUG
struct timespec ts_start; struct timespec ts_start;
clock_gettime(CLOCK_REALTIME, &ts_start); clock_gettime(CLOCK_REALTIME, &ts_start);
#endif #endif
@@ -2539,7 +2541,7 @@ static void update_real_screen_memcpy(_THIS)
} }
drm_dmabuf_end(real_buff); drm_dmabuf_end(real_buff);
#ifdef _DEBUG #if 0 // def _DEBUG
double elapsed = get_elapsed_seconds(&ts_start, NULL); double elapsed = get_elapsed_seconds(&ts_start, NULL);
_MG_PRINTF("Cosumed time to update real screen: %f (seconds)\n", elapsed); _MG_PRINTF("Cosumed time to update real screen: %f (seconds)\n", elapsed);
#endif #endif
@@ -2562,7 +2564,6 @@ static void* task_do_update(void *data)
(this->hidden->crtc_idx << DRM_VBLANK_HIGH_CRTC_SHIFT); (this->hidden->crtc_idx << DRM_VBLANK_HIGH_CRTC_SHIFT);
vbl.request.sequence = 1; vbl.request.sequence = 1;
vbl.request.signal = 0; vbl.request.signal = 0;
_DBG_PRINTF("VBL type: 0x%08x\n", vbl.request.type);
if (drmWaitVBlank(this->hidden->dev_fd, &vbl)) { if (drmWaitVBlank(this->hidden->dev_fd, &vbl)) {
_WRN_PRINTF("Failed drmWaitVBlank(%d): %m\n", this->hidden->crtc_idx); _WRN_PRINTF("Failed drmWaitVBlank(%d): %m\n", this->hidden->crtc_idx);
} }
@@ -2574,6 +2575,10 @@ static void* task_do_update(void *data)
this->hidden->updater_ready = 1; this->hidden->updater_ready = 1;
sem_post(&this->hidden->sync_sem); sem_post(&this->hidden->sync_sem);
#ifdef _DEBUG
clock_gettime(CLOCK_REALTIME, &this->hidden->ts_start);
#endif
do { do {
if (vbl_ok) { if (vbl_ok) {
@@ -2584,13 +2589,15 @@ static void* task_do_update(void *data)
vbl.request.sequence = 1; vbl.request.sequence = 1;
vbl.request.signal = 0; vbl.request.signal = 0;
drmWaitVBlank(this->hidden->dev_fd, &vbl); drmWaitVBlank(this->hidden->dev_fd, &vbl);
_DBG_PRINTF("Got a VBlank, it's time to update real screen. (%ld.%06ld)\n",
vbl.reply.tval_sec, vbl.reply.tval_usec);
} }
else { else {
usleep(this->hidden->update_interval * 1000); usleep(this->hidden->update_interval * 1000);
} }
#ifdef _DEBUG
this->hidden->frames++;
#endif
sem_wait(this->hidden->update_lock); sem_wait(this->hidden->update_lock);
if (RECTH(this->hidden->update_rect)) { if (RECTH(this->hidden->update_rect)) {
update_real_screen_memcpy(this); update_real_screen_memcpy(this);
@@ -2648,6 +2655,10 @@ static void cancel_async_updater(_THIS)
if (this->hidden->updater_ready) { if (this->hidden->updater_ready) {
pthread_cancel(this->hidden->update_thd); pthread_cancel(this->hidden->update_thd);
pthread_join(this->hidden->update_thd, NULL); pthread_join(this->hidden->update_thd, NULL);
#ifdef _DEBUG
double elapsed = get_elapsed_seconds(&this->hidden->ts_start, NULL);
_DBG_PRINTF("Frames per second: %f\n", this->hidden->frames / elapsed);
#endif
sem_destroy(&this->hidden->sync_sem); sem_destroy(&this->hidden->sync_sem);
} }
@@ -2656,7 +2667,6 @@ static void cancel_async_updater(_THIS)
static int DRM_LockHWSurface(_THIS, GAL_Surface *surface) static int DRM_LockHWSurface(_THIS, GAL_Surface *surface)
{ {
if (surface == this->screen && this->hidden->updater_ready) { if (surface == this->screen && this->hidden->updater_ready) {
_DBG_PRINTF("called\n");
sem_wait(this->hidden->update_lock); sem_wait(this->hidden->update_lock);
return 0; return 0;
} }
@@ -2667,7 +2677,6 @@ static int DRM_LockHWSurface(_THIS, GAL_Surface *surface)
static void DRM_UnlockHWSurface(_THIS, GAL_Surface *surface) static void DRM_UnlockHWSurface(_THIS, GAL_Surface *surface)
{ {
if (surface == this->screen && this->hidden->updater_ready) { if (surface == this->screen && this->hidden->updater_ready) {
_DBG_PRINTF("called\n");
sem_post(this->hidden->update_lock); sem_post(this->hidden->update_lock);
} }
} }
@@ -3812,8 +3821,7 @@ static BOOL DRM_SyncUpdate(_THIS)
this->hidden->driver_ops->flush_driver(this->hidden->driver); this->hidden->driver_ops->flush_driver(this->hidden->driver);
} }
_DBG_PRINTF("called: %d, %d, %d, %d\n", _DBG_PRINTF("called: %d, %d, %d, %d\n", bound.left, bound.top,
bound.left, bound.top,
bound.right, bound.bottom); bound.right, bound.bottom);
{ {
+6
View File
@@ -122,6 +122,12 @@ typedef struct GAL_PrivateVideoData {
RECT update_rect; RECT update_rect;
pthread_t update_thd; pthread_t update_thd;
sem_t sync_sem; sem_t sync_sem;
#ifdef _DEBUG
struct timespec ts_start;
unsigned frames;
#endif
} DrmVideoData; } DrmVideoData;
#endif /* _NEWGAL_DRIVIDEO_H */ #endif /* _NEWGAL_DRIVIDEO_H */
+46 -25
View File
@@ -56,6 +56,8 @@
#include <error.h> #include <error.h>
#include <time.h> #include <time.h>
#define _DEBUG
#include "common.h" #include "common.h"
#if __LINUX__ #if __LINUX__
@@ -137,7 +139,7 @@ static void refresh_ccw_32bpp(ShadowFBHeader* shadowfb_header,
int dst_width, dst_height; int dst_width, dst_height;
int x, y; int x, y;
#ifdef _DEBUG #if 0 // def _DEBUG
struct timespec ts_start; struct timespec ts_start;
clock_gettime(CLOCK_REALTIME, &ts_start); clock_gettime(CLOCK_REALTIME, &ts_start);
#endif #endif
@@ -171,7 +173,7 @@ static void refresh_ccw_32bpp(ShadowFBHeader* shadowfb_header,
dst_line -= realfb_info->pitch; dst_line -= realfb_info->pitch;
} }
#ifdef _DEBUG #if 0 // def _DEBUG
double elapsed = get_elapsed_seconds(&ts_start, NULL); double elapsed = get_elapsed_seconds(&ts_start, NULL);
_MG_PRINTF("Cosumed time to rotate dirty rect (ccw): %f (seconds)\n", elapsed); _MG_PRINTF("Cosumed time to rotate dirty rect (ccw): %f (seconds)\n", elapsed);
#endif #endif
@@ -187,7 +189,7 @@ static void refresh_cw_32bpp(ShadowFBHeader* shadowfb_header,
int dst_width, dst_height; int dst_width, dst_height;
int x, y; int x, y;
#ifdef _DEBUG #if 0 // def _DEBUG
struct timespec ts_start; struct timespec ts_start;
clock_gettime(CLOCK_REALTIME, &ts_start); clock_gettime(CLOCK_REALTIME, &ts_start);
#endif #endif
@@ -204,48 +206,59 @@ static void refresh_cw_32bpp(ShadowFBHeader* shadowfb_header,
dst_line = (BYTE *)realfb_info->fb + dst_update.top * dst_line = (BYTE *)realfb_info->fb + dst_update.top *
realfb_info->pitch; realfb_info->pitch;
int src_pitch = shadowfb_header->pitch / 4;
int dst_pitch = realfb_info->pitch / 4;
for (x = 0; x < dst_height; x++) { for (x = 0; x < dst_height; x++) {
/* Copy the bits from vertical line to horizontal line */ /* Copy the bits from vertical line to horizontal line */
const BYTE* ver_bits = src_bits; const Uint32 *src_pixels = (const Uint32 *)src_bits;
BYTE* hor_bits = line_pixels; Uint32 *dst_pixels = (Uint32 *)dst_line;
dst_pixels += dst_update.left;
for (y = 0; y < dst_width; y++) { for (y = 0; y < dst_width; y++) {
*(Uint32 *)hor_bits = *(Uint32 *)ver_bits; *dst_pixels = *src_pixels;
ver_bits -= shadowfb_header->pitch; src_pixels -= src_pitch;
hor_bits += 4; dst_pixels += 1;
} }
memcpy(dst_line + (dst_update.left << 2), line_pixels,
dst_width << 2);
src_bits += 4; src_bits += 4;
dst_line += realfb_info->pitch; dst_line += realfb_info->pitch;
} }
#ifdef _DEBUG #if 0 // def _DEBUG
double elapsed = get_elapsed_seconds(&ts_start, NULL); double elapsed = get_elapsed_seconds(&ts_start, NULL);
_MG_PRINTF("Cosumed time to rotate dirty rect (cw): %f (seconds)\n", elapsed); _MG_PRINTF("Cosumed time to rotate dirty rect (cw): %f (seconds)\n", elapsed);
#endif #endif
} }
extern void refresh_normal_msb_left (ShadowFBHeader * shadowfb_header, RealFBInfo *realfb_info, void* update); extern void refresh_normal_msb_left (ShadowFBHeader * shadowfb_header,
RealFBInfo *realfb_info, void* update);
extern void refresh_cw_msb_left (ShadowFBHeader *shadowfb_header, RealFBInfo *realfb_info, void* update); extern void refresh_cw_msb_left (ShadowFBHeader *shadowfb_header,
RealFBInfo *realfb_info, void* update);
extern void refresh_ccw_msb_left (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update); extern void refresh_ccw_msb_left (ShadowFBHeader* shadowfb_header,
RealFBInfo* realfb_info, void* update);
extern void refresh_hflip_msb_left (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update); extern void refresh_hflip_msb_left (ShadowFBHeader* shadowfb_header,
RealFBInfo* realfb_info, void* update);
extern void refresh_vflip_msb_left (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update); extern void refresh_vflip_msb_left (ShadowFBHeader* shadowfb_header,
RealFBInfo* realfb_info, void* update);
extern void refresh_normal_msb_right (ShadowFBHeader * shadowfb_header, RealFBInfo *realfb_info, void* update); extern void refresh_normal_msb_right (ShadowFBHeader * shadowfb_header,
RealFBInfo *realfb_info, void* update);
extern void refresh_cw_msb_right (ShadowFBHeader *shadowfb_header, RealFBInfo *realfb_info, void* update); extern void refresh_cw_msb_right (ShadowFBHeader *shadowfb_header,
RealFBInfo *realfb_info, void* update);
extern void refresh_ccw_msb_right (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update); extern void refresh_ccw_msb_right (ShadowFBHeader* shadowfb_header,
RealFBInfo* realfb_info, void* update);
extern void refresh_hflip_msb_right (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update); extern void refresh_hflip_msb_right (ShadowFBHeader* shadowfb_header,
RealFBInfo* realfb_info, void* update);
extern void refresh_vflip_msb_right (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update); extern void refresh_vflip_msb_right (ShadowFBHeader* shadowfb_header,
RealFBInfo* realfb_info, void* update);
/* Initialization/Query functions */ /* Initialization/Query functions */
static int SHADOW_VideoInit (_THIS, GAL_PixelFormat *vformat); static int SHADOW_VideoInit (_THIS, GAL_PixelFormat *vformat);
@@ -550,7 +563,6 @@ static int SHADOW_LockHWSurface(_THIS, GAL_Surface *surface)
if (pthread_mutex_lock(&this->hidden->update_lock)) if (pthread_mutex_lock(&this->hidden->update_lock))
_ERR_PRINTF("Failed pthread_mutex_lock(): %m\n"); _ERR_PRINTF("Failed pthread_mutex_lock(): %m\n");
#endif #endif
_DBG_PRINTF("locked\n");
return 0; return 0;
} }
@@ -567,7 +579,6 @@ static void SHADOW_UnlockHWSurface(_THIS, GAL_Surface *surface)
if (pthread_mutex_unlock(&this->hidden->update_lock)) if (pthread_mutex_unlock(&this->hidden->update_lock))
_ERR_PRINTF("Failed pthread_mutex_unlock(): %m\n"); _ERR_PRINTF("Failed pthread_mutex_unlock(): %m\n");
#endif #endif
_DBG_PRINTF("unlocked\n");
} }
} }
@@ -627,6 +638,10 @@ static void *task_do_update(void *data)
this->hidden->async_update = 1; this->hidden->async_update = 1;
sem_post(&this->hidden->sync_sem); sem_post(&this->hidden->sync_sem);
#ifdef _DEBUG
clock_gettime(CLOCK_REALTIME, &this->hidden->ts_start);
#endif
do { do {
GAL_VideoDevice *real_device; GAL_VideoDevice *real_device;
real_device = this->hidden->realfb_info->real_device; real_device = this->hidden->realfb_info->real_device;
@@ -638,6 +653,10 @@ static void *task_do_update(void *data)
usleep(this->hidden->update_interval * 1000); usleep(this->hidden->update_interval * 1000);
} }
#ifdef _DEBUG
this->hidden->frames++;
#endif
#if USE_UPDATE_SEM #if USE_UPDATE_SEM
if (sem_wait(&this->hidden->update_sem)) if (sem_wait(&this->hidden->update_sem))
_ERR_PRINTF("Failed sem_wait(): %m\n"); _ERR_PRINTF("Failed sem_wait(): %m\n");
@@ -645,7 +664,6 @@ static void *task_do_update(void *data)
if (pthread_mutex_lock(&this->hidden->update_lock)) if (pthread_mutex_lock(&this->hidden->update_lock))
_ERR_PRINTF("Failed pthread_mutex_lock(): %m\n"); _ERR_PRINTF("Failed pthread_mutex_lock(): %m\n");
#endif #endif
_DBG_PRINTF("locked\n");
if (RECTH(this->hidden->update_rect)) { if (RECTH(this->hidden->update_rect)) {
@@ -693,7 +711,6 @@ static void *task_do_update(void *data)
if (pthread_mutex_unlock(&this->hidden->update_lock)) if (pthread_mutex_unlock(&this->hidden->update_lock))
_ERR_PRINTF("Failed pthread_mutex_unlock(): %m\n"); _ERR_PRINTF("Failed pthread_mutex_unlock(): %m\n");
#endif #endif
_DBG_PRINTF("unlocked\n");
} while (1); } while (1);
@@ -752,6 +769,10 @@ static void cancel_async_updater(_THIS)
if (this->hidden->async_update) { if (this->hidden->async_update) {
pthread_cancel(this->hidden->update_thd); pthread_cancel(this->hidden->update_thd);
pthread_join(this->hidden->update_thd, NULL); pthread_join(this->hidden->update_thd, NULL);
#ifdef _DEBUG
double elapsed = get_elapsed_seconds(&this->hidden->ts_start, NULL);
_DBG_PRINTF("Frames per second: %f\n", this->hidden->frames / elapsed);
#endif
#if USE_UPDATE_SEM #if USE_UPDATE_SEM
sem_destroy(&this->hidden->update_sem); sem_destroy(&this->hidden->update_sem);
+6
View File
@@ -49,6 +49,7 @@
#include <pthread.h> #include <pthread.h>
#include <semaphore.h> #include <semaphore.h>
#include <time.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -119,6 +120,11 @@ struct GAL_PrivateVideoData {
#else #else
pthread_mutex_t update_lock; pthread_mutex_t update_lock;
#endif #endif
#ifdef _DEBUG
struct timespec ts_start;
unsigned frames;
#endif
}; };
typedef struct _ShadowFBOps { typedef struct _ShadowFBOps {