spatialrust_gpu/kernels/
gpu_segments.rs1use spatialrust_core::SpatialResult;
4
5use crate::kernels::voxel_compact::{finalize_segments_from_readback, read_segment_metadata};
6use crate::kernels::voxel_segments::VoxelSegments;
7use crate::runtime::WgpuRuntime;
8
9pub struct GpuVoxelSegments {
11 cell_count: u32,
12 point_count: u32,
13 construction_readback_bytes: u64,
14 keys: wgpu::Buffer,
15 point_indices: wgpu::Buffer,
16 cell_starts: wgpu::Buffer,
17}
18
19impl GpuVoxelSegments {
20 pub(crate) fn new(
22 cell_count: u32,
23 point_count: u32,
24 keys: wgpu::Buffer,
25 point_indices: wgpu::Buffer,
26 cell_starts: wgpu::Buffer,
27 construction_readback_bytes: u64,
28 ) -> Self {
29 Self {
30 cell_count,
31 point_count,
32 construction_readback_bytes,
33 keys,
34 point_indices,
35 cell_starts,
36 }
37 }
38
39 #[must_use]
44 pub const fn construction_readback_bytes(&self) -> u64 {
45 self.construction_readback_bytes
46 }
47
48 #[must_use]
50 pub fn cell_count(&self) -> u32 {
51 self.cell_count
52 }
53
54 #[must_use]
56 pub fn point_count(&self) -> u32 {
57 self.point_count
58 }
59
60 #[must_use]
62 pub fn keys_buffer(&self) -> &wgpu::Buffer {
63 &self.keys
64 }
65
66 #[must_use]
68 pub fn point_indices_buffer(&self) -> &wgpu::Buffer {
69 &self.point_indices
70 }
71
72 #[must_use]
74 pub fn cell_starts_buffer(&self) -> &wgpu::Buffer {
75 &self.cell_starts
76 }
77
78 pub fn to_voxel_segments(&self, runtime: &WgpuRuntime) -> SpatialResult<VoxelSegments> {
80 if self.cell_count == 0 {
81 return Ok(VoxelSegments {
82 keys: Vec::new(),
83 point_indices: Vec::new(),
84 cell_starts: Vec::new(),
85 cell_counts: Vec::new(),
86 });
87 }
88
89 let (keys, cell_starts, cell_counts, point_indices) =
90 read_segment_metadata(runtime, self, self.cell_count as usize)?;
91
92 Ok(finalize_segments_from_readback(keys, point_indices, cell_starts, cell_counts))
93 }
94}