Added basic vulkan info

This commit is contained in:
Ilya Zlobintsev
2020-10-19 08:34:53 +03:00
parent 95167bbd73
commit 8c042108b9
8 changed files with 219 additions and 302 deletions

View File

@@ -16,7 +16,7 @@ fn main() {
println!("VRAM: {}/{}", gpu_stats.mem_used, gpu_stats.mem_total);
}
Opt::Info => {
let gpu_info = daemon::get_gpu_info();
let gpu_info = daemon::get_gpu_info().unwrap();
println!("GPU Vendor: {}", gpu_info.gpu_vendor);
println!("GPU Model: {}", gpu_info.card_model);
println!("Driver in use: {}", gpu_info.driver);

View File

@@ -8,4 +8,5 @@ edition = "2018"
[dependencies]
bincode = "1.3"
serde = { version = "1.0", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
vulkano = "0.19"

View File

@@ -41,7 +41,7 @@ impl Daemon {
let d = self.clone();
match stream {
Ok(stream) => {
thread::spawn(move || Daemon::handle_connection(d, stream));
thread::spawn(move || d.handle_connection(stream));
}
Err(err) => {
println!("Error: {}", err);
@@ -54,7 +54,7 @@ impl Daemon {
fn handle_connection(self, mut stream: UnixStream) {
let mut buffer = Vec::<u8>::new();
stream.read_to_end(&mut buffer).unwrap();
println!("finished reading");
println!("finished reading, buffer size {}", buffer.len());
let action: Action = bincode::deserialize(&buffer).unwrap();
let response: Vec<u8> = match action {

View File

@@ -1,5 +1,6 @@
use crate::fan_controller::FanController;
use serde::{Deserialize, Serialize};
use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice};
use std::fs;
use std::path::PathBuf;
@@ -10,44 +11,53 @@ pub struct GpuStats {
}
#[derive(Clone)]
pub struct GpuController {
pub struct GpuController {
hw_path: PathBuf,
fan_controller: FanController,
pub gpu_info: GpuInfo,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct VulkanInfo {
pub device_name: String,
pub api_version: String,
pub features: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct GpuInfo {
pub gpu_vendor: String,
pub gpu_model: String,
pub card_model: String,
pub card_vendor: String,
pub model_id: String,
pub vendor_id: String,
pub driver: String,
pub vbios_version: String,
pub vram_size: u64, //in MiB
pub link_speed: String,
pub link_width: u8,
pub vulkan_info: VulkanInfo,
}
impl GpuController {
pub fn new(hw_path: &str) -> Self {
let gpu_info = GpuController::get_info(PathBuf::from(hw_path));
println!("Initializing for {:?}", gpu_info);
GpuController {
let mut controller = GpuController {
hw_path: PathBuf::from(hw_path),
fan_controller: FanController::new(hw_path),
gpu_info,
}
gpu_info: Default::default(),
};
controller.gpu_info = controller.get_info();
println!("{:?}", controller.gpu_info);
controller
}
fn get_info(hw_path: PathBuf) -> GpuInfo {
let uevent = fs::read_to_string(hw_path.join("uevent")).expect("Failed to read uevent");
fn get_info(&self) -> GpuInfo {
let uevent = fs::read_to_string(self.hw_path.join("uevent")).expect("Failed to read uevent");
//caps for raw values, lowercase for parsed
let mut driver = String::new();
let mut VENDOR_ID = String::new();
let mut MODEL_ID = String::new();
let mut vendor_id = String::new();
let mut model_id = String::new();
let mut CARD_VENDOR_ID = String::new();
let mut CARD_MODEL_ID = String::new();
@@ -57,8 +67,8 @@ impl GpuController {
"DRIVER" => driver = split[1].to_string(),
"PCI_ID" => {
let ids = split[1].split(':').collect::<Vec<&str>>();
VENDOR_ID = ids[0].to_string();
MODEL_ID = ids[1].to_string();
vendor_id = ids[0].to_string();
model_id = ids[1].to_string();
}
"PCI_SUBSYS_ID" => {
let ids = split[1].split(':').collect::<Vec<&str>>();
@@ -78,7 +88,7 @@ impl GpuController {
.expect("Could not read pci.ids. Perhaps the \"hwids\" package is not installed?");
//some weird space character, don't touch
let pci_id_line = format!(" {}", MODEL_ID.to_lowercase());
let pci_id_line = format!(" {}", model_id.to_lowercase());
let card_ids_line = format!(
" {} {}",
CARD_VENDOR_ID.to_lowercase(),
@@ -101,12 +111,12 @@ impl GpuController {
}
}
let vbios_version = fs::read_to_string(hw_path.join("vbios_version"))
let vbios_version = fs::read_to_string(self.hw_path.join("vbios_version"))
.expect("Failed to read vbios_info")
.trim()
.to_string();
let vram_size = fs::read_to_string(hw_path.join("mem_info_vram_total"))
let vram_size = fs::read_to_string(self.hw_path.join("mem_info_vram_total"))
.expect("Failed to read mem size")
.trim()
.parse::<u64>()
@@ -114,27 +124,32 @@ impl GpuController {
/ 1024
/ 1024;
let link_speed = fs::read_to_string(hw_path.join("current_link_speed"))
let link_speed = fs::read_to_string(self.hw_path.join("current_link_speed"))
.expect("Failed to read link speed")
.trim()
.to_string();
let link_width = fs::read_to_string(hw_path.join("current_link_width"))
let link_width = fs::read_to_string(self.hw_path.join("current_link_width"))
.expect("Failed to read link width")
.trim()
.parse::<u8>()
.unwrap();
let vulkan_info = GpuController::get_vulkan_info(&model_id);
GpuInfo {
gpu_vendor: vendor,
gpu_model: model,
card_vendor,
card_model,
model_id,
vendor_id,
driver,
vbios_version,
vram_size,
link_speed,
link_width,
vulkan_info,
}
}
@@ -159,4 +174,26 @@ impl GpuController {
mem_used,
}
}
fn get_vulkan_info(pci_id: &str) -> VulkanInfo {
let instance = Instance::new(None, &InstanceExtensions::none(), None)
.expect("failed to create instance");
for physical in PhysicalDevice::enumerate(&instance) {
if format!("{:x}", physical.pci_device_id()) == pci_id.to_lowercase() {
let api_version = physical.api_version().to_string();
let device_name = physical.name().to_string();
let features = format!("{:?}", physical.supported_features());
return VulkanInfo {
device_name,
api_version,
features,
};
}
}
VulkanInfo { device_name: "Not supported".to_string(), api_version: "".to_string(), features: "".to_string()}
}
}

View File

@@ -9,6 +9,7 @@ pub mod gpu_controller;
pub const SOCK_PATH: &str = "/tmp/amdgpu-configurator.sock";
#[derive(Debug)]
pub enum DaemonError {
ConnectionFailed,
}
@@ -43,4 +44,6 @@ pub fn get_gpu_info() -> Result<GpuInfo, DaemonError> {
}
Err(_) => Err(DaemonError::ConnectionFailed),
}
}

View File

@@ -41,6 +41,19 @@ fn build_ui(application: &gtk::Application) {
.get_object("link_speed_text_buffer")
.expect("Couldn't get textbuffer");
let vulkan_device_name_text_buffer: TextBuffer = builder
.get_object("vulkan_device_name_text_buffer")
.expect("Couldn't get textbuffer");
let vulkan_version_text_buffer: TextBuffer = builder
.get_object("vulkan_version_text_buffer")
.expect("Couldn't get textbuffer");
let vulkan_features_text_buffer: TextBuffer = builder
.get_object("vulkan_features_text_buffer")
.expect("Couldn't get textbuffer");
match daemon::get_gpu_info() {
Ok(gpu_info) => {
gpu_model_text_buffer.set_text(&gpu_info.card_model);
@@ -49,6 +62,10 @@ fn build_ui(application: &gtk::Application) {
driver_text_buffer.set_text(&gpu_info.driver);
vram_size_text_buffer.set_text(&format!("{} MiB", &gpu_info.vram_size));
link_speed_text_buffer.set_text(&format!("{} x{}", &gpu_info.link_speed, &gpu_info.link_width));
vulkan_device_name_text_buffer.set_text(&gpu_info.vulkan_info.device_name);
vulkan_version_text_buffer.set_text(&gpu_info.vulkan_info.api_version);
vulkan_features_text_buffer.set_text(&gpu_info.vulkan_info.features);
}
Err(_) => {
MessageDialog::new(

View File

@@ -20,6 +20,15 @@
<object class="GtkTextBuffer" id="vram_size_text_buffer">
<property name="text" translatable="yes">1024 MiB</property>
</object>
<object class="GtkTextBuffer" id="vulkan_device_name_text_buffer">
<property name="text" translatable="yes">Vulkan Device</property>
</object>
<object class="GtkTextBuffer" id="vulkan_features_text_buffer">
<property name="text" translatable="yes">orage_image_extended_formats: true, shader_storage_image_multisample: true, shader_storage_image_read_without_format: true, shader_storage_image_write_without_format: true, shader_uniform_buffer_array_dynamic_indexing: true, shader_sampled_image_array_dynamic_indexing: true, shader_storage_buffer_array_dynamic_indexing: true, shader_storage_image_array_dynamic_indexing: true, shader_clip_distance: true, shader_cull_distance: true, shader_f3264: true, shader_int64: true, shader_int16: true, shader_resource_residency: false, shader_resource_min_lod: true, sparse_binding: true, sparse_residency_buffer: false, sparse_residency_image2d: false, sparse_residency_image3d: false, sparse_residency2_samples: false, sparse_residency4_samples: false, sparse_residency8_samples: false, sparse_residency16_samples: false, sparse_residency_aliased: false, variable_multisample_rate: true, inherited_queries: true, buffer_device_address: false, buffer_device_address_capture_replay: false, buffer_device_address_multi_device: false }" } }</property>
</object>
<object class="GtkTextBuffer" id="vulkan_version_text_buffer">
<property name="text" translatable="yes">1.0.0</property>
</object>
<object class="GtkWindow" id="main_window">
<property name="can-focus">False</property>
<property name="default-width">350</property>
@@ -29,7 +38,7 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<child>
<!-- n-columns=2 n-rows=6 -->
<!-- n-columns=2 n-rows=7 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
@@ -251,6 +260,134 @@
<property name="top-attach">5</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label-xalign">0.5</property>
<property name="shadow-type">none</property>
<child>
<!-- n-columns=2 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Device Name</property>
<property name="justify">fill</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Version</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="buffer">vulkan_device_name_text_buffer</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="buffer">vulkan_version_text_buffer</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkExpander">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="label-fill">True</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<property name="propagate-natural-height">True</property>
<child>
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="wrap-mode">word</property>
<property name="buffer">vulkan_features_text_buffer</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Feature support</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
<property name="width">2</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Vulkan information</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
<property name="width">2</property>
</packing>
</child>
</object>
</child>
<child type="tab">

View File

@@ -1,278 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.1 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkMessageDialog" id="connection_error_dialog">
<property name="can-focus">False</property>
<property name="type">popup</property>
<property name="window-position">center</property>
<property name="destroy-with-parent">True</property>
<property name="type-hint">dialog</property>
<property name="urgency-hint">True</property>
<property name="message-type">error</property>
<property name="text" translatable="yes">Unable to connect to the service</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="homogeneous">True</property>
<property name="layout-style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkTextBuffer" id="driver_text_buffer">
<property name="text" translatable="yes">driver</property>
</object>
<object class="GtkTextBuffer" id="gpu_model_text_buffer">
<property name="text">gpu_model</property>
</object>
<object class="GtkTextBuffer" id="manufacturer_text_buffer">
<property name="text" translatable="yes">Manufacturer</property>
</object>
<object class="GtkTextBuffer" id="vbios_version_text_buffer">
<property name="text" translatable="yes">vbios_version</property>
</object>
<object class="GtkWindow" id="main_window">
<property name="can-focus">False</property>
<property name="default-width">350</property>
<property name="default-height">500</property>
<child>
<object class="GtkNotebook">
<property name="visible">True</property>
<property name="can-focus">True</property>
<child>
<!-- n-columns=2 n-rows=4 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">GPU Model</property>
<property name="justify">fill</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">WARNING: GPU model identification by PCI ID's may not be accurate.</property>
<property name="margin-top">6</property>
<property name="hexpand">True</property>
<property name="editable">False</property>
<property name="justification">fill</property>
<property name="cursor-visible">False</property>
<property name="buffer">gpu_model_text_buffer</property>
<property name="accepts-tab">False</property>
<property name="monospace">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">VBIOS Version</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-top">7</property>
<property name="hexpand">True</property>
<property name="editable">False</property>
<property name="justification">fill</property>
<property name="cursor-visible">False</property>
<property name="buffer">vbios_version_text_buffer</property>
<property name="accepts-tab">False</property>
<property name="monospace">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Driver in use</property>
<property name="justify">fill</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-top">7</property>
<property name="hexpand">True</property>
<property name="editable">False</property>
<property name="justification">fill</property>
<property name="cursor-visible">False</property>
<property name="buffer">driver_text_buffer</property>
<property name="accepts-tab">False</property>
<property name="monospace">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Manufacturer</property>
<property name="justify">fill</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-top">7</property>
<property name="hexpand">True</property>
<property name="editable">False</property>
<property name="justification">fill</property>
<property name="cursor-visible">False</property>
<property name="buffer">manufacturer_text_buffer</property>
<property name="accepts-tab">False</property>
<property name="monospace">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Information</property>
</object>
<packing>
<property name="tab-fill">False</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">page 2</property>
</object>
<packing>
<property name="position">1</property>
<property name="tab-fill">False</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child type="tab">
<placeholder/>
</child>
</object>
</child>
</object>
</interface>