use super::BondChunkPlacement;
use molgfx_core::{ChunkId, ChunkSpan, DatasetId, LogicalRow, ResidencyTicket};
use molgfx_gpu::ArenaAllocation;
#[repr(C, align(16))]
#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct PagedBondGpu {
pub(crate) coordinate_a: u32,
pub(crate) coordinate_b: u32,
pub(crate) _padding: [u32; 2],
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct ResidentAtomPage {
pub(crate) ticket: ResidencyTicket,
pub(crate) span: ChunkSpan,
pub(crate) coordinate_base: u32,
}
impl ResidentAtomPage {
pub(crate) fn resolve(self, dataset: DatasetId, row: LogicalRow) -> Option<u32> {
if self.ticket.key.dataset != dataset {
return None;
}
let local = self.span.local_row(self.ticket.key.chunk, row).ok()?.get();
self.coordinate_base.checked_add(local.checked_mul(3)?)
}
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct ResidentBondRange {
pub(crate) ticket: ResidencyTicket,
pub(crate) allocation: ArenaAllocation,
pub(crate) span: ChunkSpan,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct ResidentBondPlacement {
pub(crate) placement: BondChunkPlacement,
pub(crate) range: ResidentBondRange,
}
impl ResidentBondPlacement {
pub(crate) const fn dataset(self) -> DatasetId {
self.range.ticket.key.dataset
}
pub(crate) const fn chunk(self) -> ChunkId {
self.range.ticket.key.chunk
}
}