diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-05-21 04:06:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-21 04:06:15 +0300 |
commit | 36301e4195148d6f3b60b75f8a30f7a08e8bf2a7 (patch) | |
tree | 0f02909e5f2db1c6035c984f2e11909222cf8072 | |
parent | 6e7f466c68b387f41726757eed4f3e70d05479d2 (diff) | |
download | alacritty-36301e4195148d6f3b60b75f8a30f7a08e8bf2a7.tar.gz alacritty-36301e4195148d6f3b60b75f8a30f7a08e8bf2a7.zip |
Improve renderer debuggability
Make the renderer more debuggable by adding extra logging and using
`GL_KHR_debug` when running with the debug log level.
-rw-r--r-- | alacritty/build.rs | 9 | ||||
-rw-r--r-- | alacritty/src/renderer/mod.rs | 49 | ||||
-rw-r--r-- | alacritty/src/renderer/platform.rs | 23 |
3 files changed, 70 insertions, 11 deletions
diff --git a/alacritty/build.rs b/alacritty/build.rs index de2e6195..e5f0141e 100644 --- a/alacritty/build.rs +++ b/alacritty/build.rs @@ -15,9 +15,12 @@ fn main() { let dest = env::var("OUT_DIR").unwrap(); let mut file = File::create(Path::new(&dest).join("gl_bindings.rs")).unwrap(); - Registry::new(Api::Gl, (3, 3), Profile::Core, Fallbacks::All, ["GL_ARB_blend_func_extended"]) - .write_bindings(GlobalGenerator, &mut file) - .unwrap(); + Registry::new(Api::Gl, (3, 3), Profile::Core, Fallbacks::All, [ + "GL_ARB_blend_func_extended", + "GL_KHR_debug", + ]) + .write_bindings(GlobalGenerator, &mut file) + .unwrap(); #[cfg(windows)] embed_resource::compile("./windows/alacritty.rc"); diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index 8f708d33..64aee821 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -1,12 +1,12 @@ use std::collections::HashSet; use std::ffi::{CStr, CString}; -use std::fmt; use std::sync::atomic::{AtomicBool, Ordering}; +use std::{fmt, ptr}; use crossfont::Metrics; use glutin::context::{ContextApi, GlContext, PossiblyCurrentContext}; use glutin::display::{GetGlDisplay, GlDisplay}; -use log::info; +use log::{debug, error, info, warn, LevelFilter}; use once_cell::sync::OnceCell; use alacritty_terminal::index::Point; @@ -102,13 +102,17 @@ impl Renderer { }); } - let (version, renderer) = unsafe { - let renderer = CStr::from_ptr(gl::GetString(gl::RENDERER) as *mut _); - let version = CStr::from_ptr(gl::GetString(gl::SHADING_LANGUAGE_VERSION) as *mut _); - (version.to_string_lossy(), renderer.to_string_lossy()) + let (shader_version, gl_version, renderer) = unsafe { + let renderer = CStr::from_ptr(gl::GetString(gl::RENDERER) as *mut _).to_string_lossy(); + let shader_version = + CStr::from_ptr(gl::GetString(gl::SHADING_LANGUAGE_VERSION) as *mut _) + .to_string_lossy(); + let gl_version = CStr::from_ptr(gl::GetString(gl::VERSION) as *mut _).to_string_lossy(); + (shader_version, gl_version, renderer) }; - info!("Running on {}", renderer); + info!("Running on {renderer}"); + info!("OpenGL version {gl_version}, shader_version {shader_version}"); let is_gles_context = matches!(context.context_api(), ContextApi::Gles(_)); @@ -117,7 +121,7 @@ impl Renderer { Some(RendererPreference::Glsl3) => (true, true), Some(RendererPreference::Gles2) => (false, true), Some(RendererPreference::Gles2Pure) => (false, false), - None => (version.as_ref() >= "3.3" && !is_gles_context, true), + None => (shader_version.as_ref() >= "3.3" && !is_gles_context, true), }; let (text_renderer, rect_renderer) = if use_glsl3 { @@ -131,6 +135,16 @@ impl Renderer { (text_renderer, rect_renderer) }; + // Enable debug logging for OpenGL as well. + if log::max_level() >= LevelFilter::Debug && GlExtensions::contains("GL_KHR_debug") { + debug!("Enabled debug logging for OpenGL"); + unsafe { + gl::Enable(gl::DEBUG_OUTPUT); + gl::Enable(gl::DEBUG_OUTPUT_SYNCHRONOUS); + gl::DebugMessageCallback(Some(gl_debug_log), ptr::null_mut()); + } + } + Ok(Self { text_renderer, rect_renderer }) } @@ -289,3 +303,22 @@ impl GlExtensions { } } } + +extern "system" fn gl_debug_log( + _: gl::types::GLenum, + kind: gl::types::GLenum, + _: gl::types::GLuint, + _: gl::types::GLenum, + _: gl::types::GLsizei, + msg: *const gl::types::GLchar, + _: *mut std::os::raw::c_void, +) { + let msg = unsafe { CStr::from_ptr(msg).to_string_lossy() }; + match kind { + gl::DEBUG_TYPE_ERROR | gl::DEBUG_TYPE_UNDEFINED_BEHAVIOR => { + error!("[gl_render] {}", msg) + }, + gl::DEBUG_TYPE_DEPRECATED_BEHAVIOR => warn!("[gl_render] {}", msg), + _ => debug!("[gl_render] {}", msg), + } +} diff --git a/alacritty/src/renderer/platform.rs b/alacritty/src/renderer/platform.rs index c9802e0a..10c17cb7 100644 --- a/alacritty/src/renderer/platform.rs +++ b/alacritty/src/renderer/platform.rs @@ -10,6 +10,7 @@ use glutin::display::{Display, DisplayApiPreference, GetGlDisplay}; use glutin::error::Result as GlutinResult; use glutin::prelude::*; use glutin::surface::{Surface, SurfaceAttributesBuilder, WindowSurface}; +use log::{debug, LevelFilter}; use raw_window_handle::{RawDisplayHandle, RawWindowHandle}; use winit::dpi::PhysicalSize; @@ -69,6 +70,24 @@ pub fn pick_gl_config( }; if let Some(gl_config) = gl_config { + debug!( + r#"Picked GL Config: + buffer_type: {:?} + alpha_size: {} + num_samples: {} + hardware_accelerated: {:?} + supports_transparency: {:?} + config_api: {:?} + srgb_capable: {}"#, + gl_config.color_buffer_type(), + gl_config.alpha_size(), + gl_config.num_samples(), + gl_config.hardware_accelerated(), + gl_config.supports_transparency(), + gl_config.api(), + gl_config.srgb_capable(), + ); + return Ok(gl_config); } } @@ -81,15 +100,19 @@ pub fn create_gl_context( gl_config: &Config, raw_window_handle: Option<RawWindowHandle>, ) -> GlutinResult<NotCurrentContext> { + let debug = log::max_level() >= LevelFilter::Debug; let mut profiles = [ ContextAttributesBuilder::new() + .with_debug(debug) .with_context_api(ContextApi::OpenGl(Some(Version::new(3, 3)))) .build(raw_window_handle), // Try gles before OpenGL 2.1 as it tends to be more stable. ContextAttributesBuilder::new() + .with_debug(debug) .with_context_api(ContextApi::Gles(Some(Version::new(2, 0)))) .build(raw_window_handle), ContextAttributesBuilder::new() + .with_debug(debug) .with_profile(GlProfile::Compatibility) .with_context_api(ContextApi::OpenGl(Some(Version::new(2, 1)))) .build(raw_window_handle), |