refactor: drop redundant ClockSettings structure in the ui

This commit is contained in:
Ilya Zlobintsev
2024-11-09 10:07:57 +02:00
parent 508dd174e5
commit 3d783d6348
2 changed files with 27 additions and 64 deletions

View File

@@ -598,38 +598,9 @@ impl AppModel {
.context("Could not commit config")?; .context("Could not commit config")?;
} }
let clocks_settings = self.oc_page.clocks_frame.get_settings(); let clocks_commands = self.oc_page.clocks_frame.get_commands();
let mut clocks_commands = Vec::new();
debug!("applying clocks settings {clocks_settings:#?}"); debug!("applying clocks commands {clocks_commands:#?}");
if let Some(clock) = clocks_settings.min_core_clock {
clocks_commands.push(SetClocksCommand::MinCoreClock(clock));
}
if let Some(clock) = clocks_settings.min_memory_clock {
clocks_commands.push(SetClocksCommand::MinMemoryClock(clock));
}
if let Some(voltage) = clocks_settings.min_voltage {
clocks_commands.push(SetClocksCommand::MinVoltage(voltage));
}
if let Some(clock) = clocks_settings.max_core_clock {
clocks_commands.push(SetClocksCommand::MaxCoreClock(clock));
}
if let Some(clock) = clocks_settings.max_memory_clock {
clocks_commands.push(SetClocksCommand::MaxMemoryClock(clock));
}
if let Some(voltage) = clocks_settings.max_voltage {
clocks_commands.push(SetClocksCommand::MaxVoltage(voltage));
}
if let Some(offset) = clocks_settings.voltage_offset {
clocks_commands.push(SetClocksCommand::VoltageOffset(offset));
}
let enabled_power_states = self.oc_page.get_enabled_power_states(); let enabled_power_states = self.oc_page.get_enabled_power_states();

View File

@@ -7,7 +7,7 @@ use amdgpu_sysfs::gpu_handle::overdrive::{ClocksTable as _, ClocksTableGen as Am
use glib::clone; use glib::clone;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::*; use gtk::*;
use lact_schema::{ClocksTable, NvidiaClockInfo, NvidiaClocksTable}; use lact_schema::{request::SetClocksCommand, ClocksTable, NvidiaClockInfo, NvidiaClocksTable};
use subclass::prelude::ObjectSubclassIsExt; use subclass::prelude::ObjectSubclassIsExt;
use tracing::debug; use tracing::debug;
@@ -353,32 +353,35 @@ impl ClocksFrame {
self.reset_button.connect_clicked(move |_| f()); self.reset_button.connect_clicked(move |_| f());
} }
pub fn get_settings(&self) -> ClocksSettings { pub fn get_commands(&self) -> Vec<SetClocksCommand> {
if self.tweaking_grid.get_visible() { if self.tweaking_grid.get_visible() {
let min_core_clock = self.min_sclk_adjustment.get_value(); type ClocksCommandFn = fn(i32) -> SetClocksCommand;
let min_memory_clock = self.min_mclk_adjustment.get_value();
let min_voltage = self.min_voltage_adjustment.get_value();
let max_core_clock = self.max_sclk_adjustment.get_value();
let max_memory_clock = self.max_mclk_adjustment.get_value();
let max_voltage = self.max_voltage_adjustment.get_value();
let voltage_offset = if self.voltage_offset_adjustment.get_visible() { let adjustments: &[(&AdjustmentRow, ClocksCommandFn)] = &[
self.voltage_offset_adjustment.get_value() (&self.min_sclk_adjustment, SetClocksCommand::MinCoreClock),
} else { (&self.min_mclk_adjustment, SetClocksCommand::MinMemoryClock),
None (&self.min_voltage_adjustment, SetClocksCommand::MinVoltage),
}; (&self.max_sclk_adjustment, SetClocksCommand::MaxCoreClock),
(&self.max_mclk_adjustment, SetClocksCommand::MaxMemoryClock),
(&self.max_voltage_adjustment, SetClocksCommand::MaxVoltage),
];
let mut commands: Vec<SetClocksCommand> = adjustments
.iter()
.filter_map(|(row, f)| {
let value = row.get_value()?;
Some(f(value))
})
.collect();
ClocksSettings { if self.voltage_offset_adjustment.get_visible() {
min_core_clock, if let Some(offset) = self.voltage_offset_adjustment.get_value() {
min_memory_clock, commands.push(SetClocksCommand::VoltageOffset(offset));
min_voltage,
max_core_clock,
max_memory_clock,
max_voltage,
voltage_offset,
} }
}
commands
} else { } else {
ClocksSettings::default() vec![]
} }
} }
@@ -405,17 +408,6 @@ fn extract_value_and_range_amd(
Some((value, min, max)) Some((value, min, max))
} }
#[derive(Debug, Default)]
pub struct ClocksSettings {
pub min_core_clock: Option<i32>,
pub min_memory_clock: Option<i32>,
pub min_voltage: Option<i32>,
pub max_core_clock: Option<i32>,
pub max_memory_clock: Option<i32>,
pub max_voltage: Option<i32>,
pub voltage_offset: Option<i32>,
}
fn set_nvidia_clock_offset(clock_info: &NvidiaClockInfo, adjustment_row: &AdjustmentRow) { fn set_nvidia_clock_offset(clock_info: &NvidiaClockInfo, adjustment_row: &AdjustmentRow) {
let oc_adjustment = &adjustment_row.imp().adjustment; let oc_adjustment = &adjustment_row.imp().adjustment;
oc_adjustment.set_lower((clock_info.max + clock_info.offset_range.0) as f64); oc_adjustment.set_lower((clock_info.max + clock_info.offset_range.0) as f64);