mod orchestrator;
mod worker_callbacks;
mod worker_settings;
pub use orchestrator::setup_remote_rendering;
pub use worker_callbacks::setup_worker_callbacks;
pub use worker_settings::refresh_worker_options;
use crate::{gui::render::sample_scale, settings::LiveComputeTarget};
pub const REMOTE_SAMPLES_MIN_EXPONENT: u32 = 7; pub const REMOTE_SAMPLES_MAX_EXPONENT: u32 = 13;
#[must_use]
pub const fn remote_samples_exponent_to_count(exponent: u32) -> u32 {
sample_scale::exponent_to_count_bounded(
exponent,
REMOTE_SAMPLES_MIN_EXPONENT,
REMOTE_SAMPLES_MAX_EXPONENT,
)
}
#[must_use]
pub fn remote_samples_count_to_exponent(count: u32) -> u32 {
sample_scale::count_to_exponent_bounded(
count,
REMOTE_SAMPLES_MIN_EXPONENT,
REMOTE_SAMPLES_MAX_EXPONENT,
)
}
#[must_use]
pub const fn live_compute_target_from_index(index: i32) -> LiveComputeTarget {
match index {
0 => LiveComputeTarget::LocalOnly,
1 => LiveComputeTarget::RemoteOnly,
_ => LiveComputeTarget::Both,
}
}
#[must_use]
pub const fn live_compute_target_index(target: LiveComputeTarget) -> i32 {
match target {
LiveComputeTarget::LocalOnly => 0,
LiveComputeTarget::RemoteOnly => 1,
LiveComputeTarget::Both => 2,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn live_compute_target_index_and_from_index_round_trip() {
for target in [
LiveComputeTarget::LocalOnly,
LiveComputeTarget::RemoteOnly,
LiveComputeTarget::Both,
] {
let idx = live_compute_target_index(target);
assert_eq!(live_compute_target_from_index(idx), target);
}
}
#[test]
fn live_compute_target_from_index_matches_expected_pills() {
assert_eq!(
live_compute_target_from_index(0),
LiveComputeTarget::LocalOnly
);
assert_eq!(
live_compute_target_from_index(1),
LiveComputeTarget::RemoteOnly
);
assert_eq!(live_compute_target_from_index(2), LiveComputeTarget::Both);
}
#[test]
fn live_compute_target_from_index_falls_back_to_both_for_unknown_values() {
assert_eq!(live_compute_target_from_index(-1), LiveComputeTarget::Both);
assert_eq!(live_compute_target_from_index(99), LiveComputeTarget::Both);
}
#[test]
fn remote_samples_round_trip_the_default_and_endpoints() {
assert_eq!(
remote_samples_count_to_exponent(remote_samples_exponent_to_count(
REMOTE_SAMPLES_MIN_EXPONENT
)),
REMOTE_SAMPLES_MIN_EXPONENT
);
assert_eq!(
remote_samples_count_to_exponent(remote_samples_exponent_to_count(
REMOTE_SAMPLES_MAX_EXPONENT
)),
REMOTE_SAMPLES_MAX_EXPONENT
);
let exponent = remote_samples_count_to_exponent(512);
assert_eq!(remote_samples_exponent_to_count(exponent), 512);
}
#[test]
fn remote_samples_exponent_to_count_matches_expected_powers_of_two() {
assert_eq!(remote_samples_exponent_to_count(7), 128);
assert_eq!(remote_samples_exponent_to_count(9), 512);
assert_eq!(remote_samples_exponent_to_count(13), 8192);
}
#[test]
fn remote_samples_range_exceeds_the_local_interactive_targets_own_ceiling() {
assert!(remote_samples_exponent_to_count(REMOTE_SAMPLES_MAX_EXPONENT) > 1024);
}
}