Skip to content

Commit

Permalink
big oops
Browse files Browse the repository at this point in the history
When vertex data was upload the range was never actually set. Meaning that all vertex data would be uploaded every frame. On top of this bins that were removed or hidden would still persist as it wasn't tracked properly. Upon testing ran into overlapping regions which was sort of expected, but assumed it worked before. It didn't... it just never executed that code. Vertex buffers are now twice as large allowing for each half to be used seperately to avoid overlapping regions. There is still some performance on the table, but a very small amount. It might be possible to avoid swapping halves of the buffer reducing the gpu copies, but gpu's go brrrr.
  • Loading branch information
AustinJ235 committed Apr 30, 2024
1 parent f4ce290 commit 7c99429
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/interface/bin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::Basalt;

/// ID of a `Bin`
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BinID(pub(super) u64);
pub struct BinID(pub(crate) u64);

/// Information of a `Bin` after an update
///
Expand Down
29 changes: 22 additions & 7 deletions src/render/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ pub fn spawn(
let mut remove_bins: HashSet<BinID> = HashSet::new();
let (mut staging_buffers, mut vertex_buffers) =
create_buffers(&mem_alloc as &Arc<_>, 32768);
let mut vertex_buffer_offset = false;
let mut zeroing_buffer: Option<Subbuffer<[u8]>> = None;
let mut image_backings: Vec<ImageBacking> = Vec::new();
let mut metrics_level = window.renderer_metrics_level();
Expand Down Expand Up @@ -1478,8 +1479,8 @@ pub fn spawn(

// -- Check Buffer Size -- //

if vertex_buffers[active_index].len() < total_vertexes {
let mut new_buffer_size = vertex_buffers[active_index].len();
if vertex_buffers[active_index].len() / 2 < total_vertexes {
let mut new_buffer_size = vertex_buffers[active_index].len() / 2;

while new_buffer_size < total_vertexes {
new_buffer_size *= 2;
Expand Down Expand Up @@ -1510,7 +1511,13 @@ pub fn spawn(

if modified_vertexes {
let mut z_next_index: BTreeMap<OrderedFloat<f32>, DeviceSize> = BTreeMap::new();
let mut z_range_start = 0;
vertex_buffer_offset ^= true;

let mut z_range_start = if vertex_buffer_offset {
vertex_buffers[active_index].len() / 2
} else {
0
};

for (z, count) in z_count {
z_next_index.insert(z, z_range_start);
Expand Down Expand Up @@ -1545,6 +1552,8 @@ pub fn spawn(
size: range_len,
..BufferCopy::default()
});

z_data.range = Some(dst_range.start..(dst_range.start + range_len));
},
None => {
let mut z_vertexes = Vec::new();
Expand Down Expand Up @@ -1622,6 +1631,7 @@ pub fn spawn(
..BufferCopy::default()
});

z_data.range = Some(*next_index..(*next_index + range_len));
next_staging_index += range_len;
*next_index += range_len;
},
Expand Down Expand Up @@ -1762,11 +1772,16 @@ pub fn spawn(
metrics
});

let vertex_range = if vertex_buffer_offset {
let s = vertex_buffers[active_index].len() / 2;
s..(s + total_vertexes)
} else {
0..total_vertexes
};

if render_event_send
.send(RenderEvent::Update {
buffer: vertex_buffers[active_index]
.clone()
.slice(0..total_vertexes),
buffer: vertex_buffers[active_index].clone().slice(vertex_range),
images,
barrier: barrier.clone(),
metrics: metrics_op,
Expand Down Expand Up @@ -1834,7 +1849,7 @@ fn create_buffers(
allocate_preference: MemoryAllocatePreference::AlwaysAllocate,
..AllocationCreateInfo::default()
},
len,
len * 2,
)
.unwrap(),
);
Expand Down

0 comments on commit 7c99429

Please sign in to comment.