Add -gl-debug option to make it easier to debug user issues that cant easily be reproduced

This commit is contained in:
dec05eba
2025-01-16 22:55:20 +01:00
parent 4211dfa2f8
commit b68400ca20
3 changed files with 38 additions and 25 deletions

View File

@@ -277,7 +277,7 @@ struct gsr_egl {
unsigned char (*glUnmapBuffer)(unsigned int target); unsigned char (*glUnmapBuffer)(unsigned int target);
}; };
bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture); bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture, bool enable_debug);
void gsr_egl_unload(gsr_egl *self); void gsr_egl_unload(gsr_egl *self);
/* Does opengl swap with egl or glx, depending on which one is active */ /* Does opengl swap with egl or glx, depending on which one is active */

View File

@@ -344,25 +344,18 @@ static bool gsr_egl_load_gl(gsr_egl *self, void *library) {
return true; return true;
} }
// #define GL_DEBUG_TYPE_ERROR 0x824C #define GL_DEBUG_TYPE_ERROR 0x824C
// static void debug_callback( unsigned int source, #define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B
// unsigned int type, static void debug_callback(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char* message, const void* userParam) {
// unsigned int id, (void)source;
// unsigned int severity, (void)id;
// int length, (void)length;
// const char* message, (void)userParam;
// const void* userParam ) if(severity != GL_DEBUG_SEVERITY_NOTIFICATION)
// { fprintf(stderr, "gsr info: gl callback: %s type = 0x%x, severity = 0x%x, message = %s\n", type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "", type, severity, message);
// (void)source; }
// (void)id;
// (void)length;
// (void)userParam;
// fprintf( stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
// ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ),
// type, severity, message );
// }
bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture) { bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture, bool enable_debug) {
memset(self, 0, sizeof(gsr_egl)); memset(self, 0, sizeof(gsr_egl));
self->context_type = GSR_GL_CONTEXT_TYPE_EGL; self->context_type = GSR_GL_CONTEXT_TYPE_EGL;
self->window = window; self->window = window;
@@ -418,8 +411,10 @@ bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture) {
self->glEnable(GL_BLEND); self->glEnable(GL_BLEND);
self->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); self->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//self->glEnable(GL_DEBUG_OUTPUT); if(enable_debug) {
//self->glDebugMessageCallback(debug_callback, NULL); self->glEnable(GL_DEBUG_OUTPUT);
self->glDebugMessageCallback(debug_callback, NULL);
}
return true; return true;

View File

@@ -1069,7 +1069,7 @@ static void open_video_hardware(AVCodecContext *codec_context, VideoQuality vide
static void usage_header() { static void usage_header() {
const bool inside_flatpak = getenv("FLATPAK_ID") != NULL; const bool inside_flatpak = getenv("FLATPAK_ID") != NULL;
const char *program_name = inside_flatpak ? "flatpak run --command=gpu-screen-recorder com.dec05eba.gpu_screen_recorder" : "gpu-screen-recorder"; const char *program_name = inside_flatpak ? "flatpak run --command=gpu-screen-recorder com.dec05eba.gpu_screen_recorder" : "gpu-screen-recorder";
printf("usage: %s -w <window_id|monitor|focused|portal> [-c <container_format>] [-s WxH] -f <fps> [-a <audio_input>] [-q <quality>] [-r <replay_buffer_size_sec>] [-k h264|hevc|av1|vp8|vp9|hevc_hdr|av1_hdr|hevc_10bit|av1_10bit] [-ac aac|opus|flac] [-ab <bitrate>] [-oc yes|no] [-fm cfr|vfr|content] [-bm auto|qp|vbr|cbr] [-cr limited|full] [-df yes|no] [-sc <script_path>] [-cursor yes|no] [-keyint <value>] [-restore-portal-session yes|no] [-portal-session-token-filepath filepath] [-encoder gpu|cpu] [-o <output_file>] [--list-capture-options [card_path] [vendor]] [--list-audio-devices] [--list-application-audio] [-v yes|no] [--version] [-h|--help]\n", program_name); printf("usage: %s -w <window_id|monitor|focused|portal> [-c <container_format>] [-s WxH] -f <fps> [-a <audio_input>] [-q <quality>] [-r <replay_buffer_size_sec>] [-k h264|hevc|av1|vp8|vp9|hevc_hdr|av1_hdr|hevc_10bit|av1_10bit] [-ac aac|opus|flac] [-ab <bitrate>] [-oc yes|no] [-fm cfr|vfr|content] [-bm auto|qp|vbr|cbr] [-cr limited|full] [-df yes|no] [-sc <script_path>] [-cursor yes|no] [-keyint <value>] [-restore-portal-session yes|no] [-portal-session-token-filepath filepath] [-encoder gpu|cpu] [-o <output_file>] [--list-capture-options [card_path] [vendor]] [--list-audio-devices] [--list-application-audio] [-v yes|no] [-gl-debug yes|no] [--version] [-h|--help]\n", program_name);
fflush(stdout); fflush(stdout);
} }
@@ -1229,6 +1229,9 @@ static void usage_full() {
printf("\n"); printf("\n");
printf(" -v Prints fps and damage info once per second. Optional, set to 'yes' by default.\n"); printf(" -v Prints fps and damage info once per second. Optional, set to 'yes' by default.\n");
printf("\n"); printf("\n");
printf(" -gl-debug\n");
printf(" Print opengl debug output. Optional, set to 'no' by default.\n");
printf("\n");
printf(" -h, --help\n"); printf(" -h, --help\n");
printf(" Show this help.\n"); printf(" Show this help.\n");
printf("\n"); printf("\n");
@@ -2122,7 +2125,7 @@ static void info_command() {
} }
gsr_egl egl; gsr_egl egl;
if(!gsr_egl_load(&egl, window, false)) { if(!gsr_egl_load(&egl, window, false, false)) {
fprintf(stderr, "gsr error: failed to load opengl\n"); fprintf(stderr, "gsr error: failed to load opengl\n");
_exit(22); _exit(22);
} }
@@ -2234,7 +2237,7 @@ static void list_capture_options_command(const char *card_path, gsr_gpu_vendor v
list_supported_capture_options(window, card_path, true); list_supported_capture_options(window, card_path, true);
} else { } else {
gsr_egl egl; gsr_egl egl;
if(!gsr_egl_load(&egl, window, false)) { if(!gsr_egl_load(&egl, window, false, false)) {
fprintf(stderr, "gsr error: failed to load opengl\n"); fprintf(stderr, "gsr error: failed to load opengl\n");
_exit(1); _exit(1);
} }
@@ -3060,6 +3063,7 @@ int main(int argc, char **argv) {
{ "-bm", Arg { {}, true, false } }, { "-bm", Arg { {}, true, false } },
{ "-pixfmt", Arg { {}, true, false } }, { "-pixfmt", Arg { {}, true, false } },
{ "-v", Arg { {}, true, false } }, { "-v", Arg { {}, true, false } },
{ "-gl-debug", Arg { {}, true, false } },
{ "-df", Arg { {}, true, false } }, { "-df", Arg { {}, true, false } },
{ "-sc", Arg { {}, true, false } }, { "-sc", Arg { {}, true, false } },
{ "-cr", Arg { {}, true, false } }, { "-cr", Arg { {}, true, false } },
@@ -3227,6 +3231,20 @@ int main(int argc, char **argv) {
usage(); usage();
} }
bool gl_debug = false;
const char *gl_debug_str = args["-gl-debug"].value();
if(!gl_debug_str)
gl_debug_str = "no";
if(strcmp(gl_debug_str, "yes") == 0) {
gl_debug = true;
} else if(strcmp(gl_debug_str, "no") == 0) {
gl_debug = false;
} else {
fprintf(stderr, "Error: -gl-debug should either be either 'yes' or 'no', got: '%s'\n", gl_debug_str);
usage();
}
bool record_cursor = true; bool record_cursor = true;
const char *record_cursor_str = args["-cursor"].value(); const char *record_cursor_str = args["-cursor"].value();
if(!record_cursor_str) if(!record_cursor_str)
@@ -3409,7 +3427,7 @@ int main(int argc, char **argv) {
const bool is_monitor_capture = strcmp(window_str.c_str(), "focused") != 0 && !is_portal_capture && contains_non_hex_number(window_str.c_str()); const bool is_monitor_capture = strcmp(window_str.c_str(), "focused") != 0 && !is_portal_capture && contains_non_hex_number(window_str.c_str());
gsr_egl egl; gsr_egl egl;
if(!gsr_egl_load(&egl, window, is_monitor_capture)) { if(!gsr_egl_load(&egl, window, is_monitor_capture, gl_debug)) {
fprintf(stderr, "gsr error: failed to load opengl\n"); fprintf(stderr, "gsr error: failed to load opengl\n");
_exit(1); _exit(1);
} }