[PERF] Host Debug Overlay Isolation
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
use crate::memory_banks::{GlyphBankPoolInstaller, SoundBankPoolInstaller};
|
||||
use prometeu_hal::AssetBridge;
|
||||
use prometeu_hal::asset::{
|
||||
AssetCodec, AssetEntry, AssetId, AssetLoadError, AssetOpStatus, BankStats, BankType, HandleId,
|
||||
LoadStatus, PreloadEntry, SlotRef, SlotStats,
|
||||
AssetCodec, AssetEntry, AssetId, AssetLoadError, AssetOpStatus, BankTelemetry, BankType,
|
||||
HandleId, LoadStatus, PreloadEntry, SlotRef, SlotStats,
|
||||
};
|
||||
use prometeu_hal::cartridge::AssetsPayloadSource;
|
||||
use prometeu_hal::color::Color;
|
||||
@@ -161,11 +161,6 @@ pub struct AssetManager {
|
||||
/// Residency policy for sound banks.
|
||||
sound_policy: BankPolicy<SoundBank>,
|
||||
|
||||
/// Count of occupied slots for GFX.
|
||||
gfx_slots_occupied: AtomicUsize,
|
||||
/// Count of occupied slots for sounds.
|
||||
sound_slots_occupied: AtomicUsize,
|
||||
|
||||
// Commits that are ready to be applied at the next frame boundary.
|
||||
pending_commits: Mutex<Vec<HandleId>>,
|
||||
}
|
||||
@@ -206,8 +201,8 @@ impl AssetBridge for AssetManager {
|
||||
fn apply_commits(&self) {
|
||||
self.apply_commits()
|
||||
}
|
||||
fn bank_info(&self, kind: BankType) -> BankStats {
|
||||
self.bank_info(kind)
|
||||
fn bank_telemetry(&self) -> Vec<BankTelemetry> {
|
||||
self.bank_telemetry()
|
||||
}
|
||||
fn slot_info(&self, slot: SlotRef) -> SlotStats {
|
||||
self.slot_info(slot)
|
||||
@@ -302,8 +297,6 @@ impl AssetManager {
|
||||
sound_slots: Arc::new(RwLock::new(std::array::from_fn(|_| None))),
|
||||
gfx_policy: BankPolicy::new(),
|
||||
sound_policy: BankPolicy::new(),
|
||||
gfx_slots_occupied: AtomicUsize::new(0),
|
||||
sound_slots_occupied: AtomicUsize::new(0),
|
||||
handles: Arc::new(RwLock::new(HashMap::new())),
|
||||
next_handle_id: Mutex::new(1),
|
||||
assets_data: Arc::new(RwLock::new(assets_data)),
|
||||
@@ -732,9 +725,6 @@ impl AssetManager {
|
||||
self.gfx_installer.install_glyph_bank(h.slot.index, bank);
|
||||
let mut slots = self.gfx_slots.write().unwrap();
|
||||
if h.slot.index < slots.len() {
|
||||
if slots[h.slot.index].is_none() {
|
||||
self.gfx_slots_occupied.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
slots[h.slot.index] = Some(h._asset_id);
|
||||
}
|
||||
h.status = LoadStatus::COMMITTED;
|
||||
@@ -745,9 +735,6 @@ impl AssetManager {
|
||||
self.sound_installer.install_sound_bank(h.slot.index, bank);
|
||||
let mut slots = self.sound_slots.write().unwrap();
|
||||
if h.slot.index < slots.len() {
|
||||
if slots[h.slot.index].is_none() {
|
||||
self.sound_slots_occupied.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
slots[h.slot.index] = Some(h._asset_id);
|
||||
}
|
||||
h.status = LoadStatus::COMMITTED;
|
||||
@@ -759,37 +746,21 @@ impl AssetManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bank_info(&self, kind: BankType) -> BankStats {
|
||||
match kind {
|
||||
BankType::GLYPH => {
|
||||
let used_bytes = self.gfx_policy.used_bytes.load(Ordering::Relaxed);
|
||||
let inflight_bytes = self.gfx_policy.inflight_bytes.load(Ordering::Relaxed);
|
||||
let slots_occupied = self.gfx_slots_occupied.load(Ordering::Relaxed);
|
||||
pub fn bank_telemetry(&self) -> Vec<BankTelemetry> {
|
||||
vec![self.bank_telemetry_for(BankType::GLYPH), self.bank_telemetry_for(BankType::SOUNDS)]
|
||||
}
|
||||
|
||||
BankStats {
|
||||
total_bytes: 16 * 1024 * 1024,
|
||||
used_bytes,
|
||||
free_bytes: (16usize * 1024 * 1024).saturating_sub(used_bytes),
|
||||
inflight_bytes,
|
||||
slot_count: 16,
|
||||
slots_occupied,
|
||||
}
|
||||
fn bank_telemetry_for(&self, kind: BankType) -> BankTelemetry {
|
||||
let used_slots = match kind {
|
||||
BankType::GLYPH => {
|
||||
self.gfx_slots.read().unwrap().iter().filter(|slot| slot.is_some()).count()
|
||||
}
|
||||
BankType::SOUNDS => {
|
||||
let used_bytes = self.sound_policy.used_bytes.load(Ordering::Relaxed);
|
||||
let inflight_bytes = self.sound_policy.inflight_bytes.load(Ordering::Relaxed);
|
||||
let slots_occupied = self.sound_slots_occupied.load(Ordering::Relaxed);
|
||||
|
||||
BankStats {
|
||||
total_bytes: 32 * 1024 * 1024,
|
||||
used_bytes,
|
||||
free_bytes: (32usize * 1024 * 1024).saturating_sub(used_bytes),
|
||||
inflight_bytes,
|
||||
slot_count: 16,
|
||||
slots_occupied,
|
||||
}
|
||||
self.sound_slots.read().unwrap().iter().filter(|slot| slot.is_some()).count()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BankTelemetry { bank_type: kind, used_slots, total_slots: 16 }
|
||||
}
|
||||
|
||||
pub fn slot_info(&self, slot: SlotRef) -> SlotStats {
|
||||
@@ -842,8 +813,6 @@ impl AssetManager {
|
||||
pub fn shutdown(&self) {
|
||||
self.gfx_policy.clear();
|
||||
self.sound_policy.clear();
|
||||
self.gfx_slots_occupied.store(0, Ordering::Relaxed);
|
||||
self.sound_slots_occupied.store(0, Ordering::Relaxed);
|
||||
self.handles.write().unwrap().clear();
|
||||
self.pending_commits.lock().unwrap().clear();
|
||||
self.gfx_slots.write().unwrap().fill(None);
|
||||
@@ -1196,7 +1165,6 @@ mod tests {
|
||||
|
||||
let width = 16;
|
||||
let height = 16;
|
||||
let decoded_bytes = expected_glyph_decoded_size(width, height);
|
||||
let data = test_glyph_asset_data();
|
||||
|
||||
let am = AssetManager::new(
|
||||
@@ -1207,10 +1175,10 @@ mod tests {
|
||||
);
|
||||
|
||||
// Initially zero
|
||||
let info = am.bank_info(BankType::GLYPH);
|
||||
assert_eq!(info.used_bytes, 0);
|
||||
assert_eq!(info.inflight_bytes, 0);
|
||||
assert_eq!(info.slots_occupied, 0);
|
||||
let info = am.bank_telemetry();
|
||||
assert_eq!(info[0].bank_type, BankType::GLYPH);
|
||||
assert_eq!(info[0].used_slots, 0);
|
||||
assert_eq!(info[0].total_slots, 16);
|
||||
|
||||
// Loading
|
||||
let handle = am.load(0, 0).expect("load must allocate handle");
|
||||
@@ -1221,26 +1189,21 @@ mod tests {
|
||||
thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
|
||||
let info = am.bank_info(BankType::GLYPH);
|
||||
// Note: put_resident happens in worker thread, then stage happens.
|
||||
assert_eq!(info.used_bytes, decoded_bytes);
|
||||
assert_eq!(info.inflight_bytes, decoded_bytes);
|
||||
assert_eq!(info.slots_occupied, 0);
|
||||
let info = am.bank_telemetry();
|
||||
assert_eq!(info[0].used_slots, 0);
|
||||
|
||||
// Commit
|
||||
am.commit(handle);
|
||||
am.apply_commits();
|
||||
|
||||
let info = am.bank_info(BankType::GLYPH);
|
||||
assert_eq!(info.used_bytes, decoded_bytes);
|
||||
assert_eq!(info.inflight_bytes, 0);
|
||||
assert_eq!(info.slots_occupied, 1);
|
||||
let info = am.bank_telemetry();
|
||||
assert_eq!(info[0].used_slots, 1);
|
||||
assert_eq!(info[1].bank_type, BankType::SOUNDS);
|
||||
assert_eq!(info[1].used_slots, 0);
|
||||
|
||||
// Shutdown resets
|
||||
am.shutdown();
|
||||
let info = am.bank_info(BankType::GLYPH);
|
||||
assert_eq!(info.used_bytes, 0);
|
||||
assert_eq!(info.inflight_bytes, 0);
|
||||
assert_eq!(info.slots_occupied, 0);
|
||||
let info = am.bank_telemetry();
|
||||
assert_eq!(info[0].used_slots, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user