Skip to content

Commit

Permalink
Expose some debugging information for Zed
Browse files Browse the repository at this point in the history
We'd like to be able to tell users not to use a software renderer,
and to provide more information in the case of failures.

Fixes: #142
  • Loading branch information
ConradIrwin committed Jul 18, 2024
1 parent 9e47628 commit 02b6b29
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 5 deletions.
22 changes: 18 additions & 4 deletions blade-graphics/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub struct Context {
inner: Mutex<ContextInner>,
pub(super) capabilities: super::Capabilities,
pub(super) limits: super::Limits,
pub(super) device_information: crate::DeviceInformation,
}

pub struct ContextLock<'a> {
Expand Down Expand Up @@ -208,7 +209,7 @@ impl Context {

let egl_context = EglContext::init(&desc, egl, display)?;
egl_context.make_current();
let (glow, capabilities, limits) = egl_context.load_functions(&desc);
let (glow, capabilities, device_information, limits) = egl_context.load_functions(&desc);
egl_context.unmake_current();

Ok(Self {
Expand All @@ -220,6 +221,7 @@ impl Context {
}),
capabilities,
limits,
device_information,
})
}

Expand Down Expand Up @@ -322,7 +324,7 @@ impl Context {

let egl_context = EglContext::init(&desc, egl, display)?;
egl_context.make_current();
let (glow, capabilities, limits) = egl_context.load_functions(&desc);
let (glow, capabilities, device_information, limits) = egl_context.load_functions(&desc);
let renderbuf = glow.create_renderbuffer().unwrap();
let framebuf = glow.create_framebuffer().unwrap();
egl_context.unmake_current();
Expand All @@ -341,6 +343,7 @@ impl Context {
}),
capabilities,
limits,
device_information,
})
}

Expand Down Expand Up @@ -775,7 +778,12 @@ impl EglContext {
unsafe fn load_functions(
&self,
desc: &crate::ContextDesc,
) -> (glow::Context, super::Capabilities, super::Limits) {
) -> (
glow::Context,
super::Capabilities,
crate::DeviceInformation,
super::Limits,
) {
let mut gl = glow::Context::from_loader_function(|name| {
self.instance
.get_proc_address(name)
Expand Down Expand Up @@ -804,6 +812,12 @@ impl EglContext {
log::info!("Vendor: {}", vendor);
log::info!("Renderer: {}", renderer);
log::info!("Version: {}", version);
let device_information = crate::DeviceInformation {
device_kind: crate::DeviceKind::Unknown, // todo
device_name: vendor,
driver_name: renderer,
driver_info: version,
};

let mut capabilities = super::Capabilities::empty();
capabilities.set(
Expand All @@ -825,7 +839,7 @@ impl EglContext {
uniform_buffer_alignment: gl.get_parameter_i32(glow::UNIFORM_BUFFER_OFFSET_ALIGNMENT)
as u32,
};
(gl, capabilities, limits)
(gl, capabilities, device_information, limits)
}
}

Expand Down
4 changes: 4 additions & 0 deletions blade-graphics/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ impl Context {
ray_query: crate::ShaderVisibility::empty(),
}
}

pub fn device_information(&self) -> &crate::DeviceInformation {
&self.device_information
}
}

#[hidden_trait::expose]
Expand Down
9 changes: 9 additions & 0 deletions blade-graphics/src/gles/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Context {
swapchain: Swapchain,
pub(super) capabilities: super::Capabilities,
pub(super) limits: super::Limits,
pub(super) device_information: crate::DeviceInformation,
}

impl Context {
Expand Down Expand Up @@ -73,12 +74,20 @@ impl Context {
extent: Cell::default(),
};

let device_information = crate::DeviceInformation {
device_kind: crate::DeviceKind::VirtualGPU,
device_name: glow.get_parameter_string(glow::VENDOR),
driver_name: glow.get_parameter_string(glow::RENDERER),
driver_info: glow.get_parameter_string(glow::VERSION),
};

Ok(Self {
webgl2,
glow,
swapchain,
capabilities,
limits,
device_information,
})
}

Expand Down
26 changes: 26 additions & 0 deletions blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,32 @@ pub struct Capabilities {
pub ray_query: ShaderVisibility,
}

#[derive(Clone, Debug, Default, PartialEq)]
pub enum DeviceKind {
#[default]
Unknown,
/// Integrated hardware GPU
IntegratedGPU,
/// Discrete hardware GPU
DiscreteGPU,
/// Virtualized GPU
VirtualGPU,
/// Emulated software GPU
SoftwareEmulator,
}

#[derive(Clone, Debug, Default)]
pub struct DeviceInformation {
/// The kind of GPU
pub device_kind: DeviceKind,
/// The name of the GPU device
pub device_name: String,
/// The driver used to talk to the GPU
pub driver_name: String,
/// Further information about the driver
pub driver_info: String,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Memory {
/// Device-local memory. Fast for GPU operations.
Expand Down
4 changes: 4 additions & 0 deletions blade-graphics/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ impl Context {
}
}

pub fn device_information(&self) -> &crate::DeviceInformation {
todo!();
}

/// Get the CALayerMetal for this surface, if any.
/// This is platform specific API.
pub fn metal_layer(&self) -> Option<metal::MetalLayer> {
Expand Down
36 changes: 35 additions & 1 deletion blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct SystemBugs {
struct AdapterCapabilities {
api_version: u32,
properties: vk::PhysicalDeviceProperties,
device_information: crate::DeviceInformation,
queue_family_index: u32,
layered: bool,
ray_tracing: bool,
Expand Down Expand Up @@ -88,12 +89,15 @@ unsafe fn inspect_adapter(
vk::PhysicalDeviceAccelerationStructurePropertiesKHR::default();
let mut portability_subset_properties =
vk::PhysicalDevicePortabilitySubsetPropertiesKHR::default();

let mut driver_properties = vk::PhysicalDeviceDriverPropertiesKHR::default();
let mut properties2_khr = vk::PhysicalDeviceProperties2KHR::default()
.push_next(&mut inline_uniform_block_properties)
.push_next(&mut timeline_semaphore_properties)
.push_next(&mut descriptor_indexing_properties)
.push_next(&mut acceleration_structure_properties)
.push_next(&mut portability_subset_properties);
.push_next(&mut portability_subset_properties)
.push_next(&mut driver_properties);
instance
.get_physical_device_properties2
.get_physical_device_properties2(phd, &mut properties2_khr);
Expand Down Expand Up @@ -153,6 +157,10 @@ unsafe fn inspect_adapter(
.get_physical_device_properties2
.get_physical_device_features2(phd, &mut features2_khr);

instance
.get_physical_device_properties2
.get_physical_device_properties2(phd, &mut properties2_khr);

let properties = properties2_khr.properties;
let name = ffi::CStr::from_ptr(properties.device_name.as_ptr());
log::info!("Adapter {:?}", name);
Expand Down Expand Up @@ -232,9 +240,30 @@ unsafe fn inspect_adapter(
let shader_info = supported_extensions.contains(&vk::AMD_SHADER_INFO_NAME);
let full_screen_exclusive = supported_extensions.contains(&vk::EXT_FULL_SCREEN_EXCLUSIVE_NAME);

let device_kind = match properties.device_type {
ash::vk::PhysicalDeviceType::CPU => crate::DeviceKind::SoftwareEmulator,

Check warning on line 244 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 244 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 244 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 244 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification

Check warning on line 244 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification

Check warning on line 244 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification
ash::vk::PhysicalDeviceType::INTEGRATED_GPU => crate::DeviceKind::IntegratedGPU,

Check warning on line 245 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 245 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 245 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 245 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification

Check warning on line 245 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification

Check warning on line 245 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification
ash::vk::PhysicalDeviceType::DISCRETE_GPU => crate::DeviceKind::DiscreteGPU,

Check warning on line 246 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 246 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 246 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 246 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification

Check warning on line 246 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification

Check warning on line 246 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification
ash::vk::PhysicalDeviceType::VIRTUAL_GPU => crate::DeviceKind::VirtualGPU,

Check warning on line 247 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 247 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 247 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unnecessary qualification

Check warning on line 247 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification

Check warning on line 247 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification

Check warning on line 247 in blade-graphics/src/vulkan/init.rs

View workflow job for this annotation

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unnecessary qualification
_ => crate::DeviceKind::Unknown,
};
let device_information = crate::DeviceInformation {
device_kind,
device_name: ffi::CStr::from_ptr(properties.device_name.as_ptr())
.to_string_lossy()
.to_string(),
driver_name: ffi::CStr::from_ptr(driver_properties.driver_name.as_ptr())
.to_string_lossy()
.to_string(),
driver_info: ffi::CStr::from_ptr(driver_properties.driver_info.as_ptr())
.to_string_lossy()
.to_string(),
};

Some(AdapterCapabilities {
api_version,
properties,
device_information,
queue_family_index,
layered: portability_subset_properties.min_vertex_input_binding_stride_alignment != 0,
ray_tracing,
Expand Down Expand Up @@ -530,6 +559,7 @@ impl super::Context {
None
},
core: device_core,
device_information: capabilities.device_information,
//TODO: detect GPU family
workarounds: super::Workarounds {
extra_sync_src_access: vk::AccessFlags::TRANSFER_WRITE,
Expand Down Expand Up @@ -701,6 +731,10 @@ impl super::Context {
},
}
}

pub fn device_information(&self) -> &crate::DeviceInformation {
&self.device.device_information
}
}

impl super::Context {
Expand Down
1 change: 1 addition & 0 deletions blade-graphics/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct Workarounds {
#[derive(Clone)]
struct Device {
core: ash::Device,
device_information: crate::DeviceInformation,
debug_utils: ash::ext::debug_utils::Device,
timeline_semaphore: khr::timeline_semaphore::Device,
dynamic_rendering: khr::dynamic_rendering::Device,
Expand Down
1 change: 1 addition & 0 deletions examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl Example {
)
.unwrap()
};
println!("{:?}", context.device_information());

let surface_info = context.resize(gpu::SurfaceConfig {
size: gpu::Extent {
Expand Down

0 comments on commit 02b6b29

Please sign in to comment.