Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lift line vertex/strip count limitations #5207

Merged
merged 23 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dcb971c
allocate line strip & vertex textures dynamically
Wumpf Feb 14, 2024
e5dece8
introduce LineStripBuilderAllocator for easy allocation of line strip…
Wumpf Feb 15, 2024
7aadb04
remove shared_render_builders and update usages of line renderer
Wumpf Feb 14, 2024
1e29a6d
comment fix
Wumpf Feb 15, 2024
a785b2c
doc fix
Wumpf Feb 15, 2024
04e904c
renames. put render context inside of allocator for convenience
Wumpf Feb 15, 2024
d040e11
fix incorrect count of keypoint connections
Wumpf Feb 15, 2024
25c1911
comment fixes
Wumpf Feb 15, 2024
e0f8975
remove `reserve_batch` again
Wumpf Feb 15, 2024
1dd6d81
code cosmetics
Wumpf Feb 15, 2024
e7c2048
fix potential incorrect sampling in instance texture for line strips
Wumpf Feb 15, 2024
c7e8b54
comment fix!
Wumpf Feb 15, 2024
ad25cab
new data texture source dynamic sized buffer allocation
Wumpf Feb 16, 2024
b0244de
remove LineDrawableBuilderAllocator again and just use the improved L…
Wumpf Feb 16, 2024
105d20f
comment & warning fixes
Wumpf Feb 16, 2024
bfdd15c
address remaining comments
Wumpf Feb 16, 2024
f0547c2
comment fixes and small logic fix in DataTextureSource
Wumpf Feb 16, 2024
13e7117
fix silly compilation error
Wumpf Feb 16, 2024
d03891d
change max_texture_width to 16384 and clarify commentary
Wumpf Feb 16, 2024
764e585
add missing line preallocation on encountering line strips
Wumpf Feb 16, 2024
ca3e36a
improvements to DataTextureSource, mostly based on PR feedback
Wumpf Feb 17, 2024
3509316
fix definition of `active_buffer_index` invariant. Remove unnecessary…
Wumpf Feb 18, 2024
012ab21
renderer example compilation fixes
Wumpf Feb 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions crates/re_renderer/shader/lines.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ struct BatchUniformBuffer {
@group(2) @binding(0)
var<uniform> batch: BatchUniformBuffer;

const POSITION_TEXTURE_SIZE: u32 = 512u;
const LINE_STRIP_TEXTURE_SIZE: u32 = 256u;

// Flags
// See lines.rs#LineStripFlags
const FLAG_CAP_END_TRIANGLE: u32 = 1u;
Expand Down Expand Up @@ -89,8 +86,13 @@ struct LineStripData {

// Read and unpack line strip data at a given location
fn read_strip_data(idx: u32) -> LineStripData {
let coord = vec2u(idx % LINE_STRIP_TEXTURE_SIZE, idx / LINE_STRIP_TEXTURE_SIZE);
var raw_data = textureLoad(position_data_texture, coord, 0).xy;
let position_data_texture_size = textureDimensions(position_data_texture);
let raw_data = textureLoad(position_data_texture,
vec2u(idx % position_data_texture_size.x, idx / position_data_texture_size.x), 0);

let picking_instance_id_texture_size = textureDimensions(picking_instance_id_texture);
let picking_instance_id = textureLoad(picking_instance_id_texture,
vec2u(idx % picking_instance_id_texture_size.x, idx / picking_instance_id_texture_size.x), 0).xy;

var data: LineStripData;
data.color = linear_from_srgba(unpack4x8unorm_workaround(raw_data.x));
Expand All @@ -99,7 +101,7 @@ fn read_strip_data(idx: u32) -> LineStripData {
data.unresolved_radius = unpack2x16float(raw_data.y).y;
data.flags = ((raw_data.y >> 8u) & 0xFFu);
data.stippling = f32((raw_data.y >> 16u) & 0xFFu) * (1.0 / 255.0);
data.picking_instance_id = textureLoad(picking_instance_id_texture, coord, 0).rg;
data.picking_instance_id = picking_instance_id;
return data;
}

Expand All @@ -110,7 +112,9 @@ struct PositionData {

// Read and unpack position data at a given location
fn read_position_data(idx: u32) -> PositionData {
var raw_data = textureLoad(line_strip_texture, vec2u(idx % POSITION_TEXTURE_SIZE, idx / POSITION_TEXTURE_SIZE), 0);
let texture_size = textureDimensions(line_strip_texture);
let coord = vec2u(idx % texture_size.x, idx / texture_size.x);
var raw_data = textureLoad(line_strip_texture, coord, 0);

var data: PositionData;
let pos_4d = batch.world_from_obj * vec4f(raw_data.xyz, 1.0);
Expand Down
35 changes: 17 additions & 18 deletions crates/re_renderer/src/allocator/cpu_write_gpu_read_belt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ pub enum CpuWriteGpuReadError {
ZeroSizeBufferAllocation,

#[error("Buffer is full, can't append more data!
Buffer contains {buffer_element_size} elements and has a capacity for {buffer_element_capacity} elements.
Buffer contains {buffer_size_elements} elements and has a capacity for {buffer_capacity_elements} elements.
Tried to add {num_elements_attempted_to_add} elements.")]
BufferFull {
buffer_element_capacity: usize,
buffer_element_size: usize,
buffer_capacity_elements: usize,
buffer_size_elements: usize,
num_elements_attempted_to_add: usize,
},

Expand All @@ -26,9 +26,9 @@ pub enum CpuWriteGpuReadError {
destination_offset: u64,
},

#[error("Target texture doesn't fit the size of the written data to this buffer! Texture copy size: {copy_size:?} bytes, written data size: {written_data_size} bytes")]
#[error("Target texture doesn't fit the size of the written data to this buffer! Texture target buffer should be at most {max_copy_size} bytes, but the to be written data was {written_data_size} bytes.")]
TargetTextureBufferSizeMismatch {
copy_size: wgpu::Extent3d,
max_copy_size: u64,
written_data_size: usize,
},
}
Expand Down Expand Up @@ -100,8 +100,8 @@ where
let (result, elements) = if elements.len() > self.remaining_capacity() {
(
Err(CpuWriteGpuReadError::BufferFull {
buffer_element_capacity: self.capacity(),
buffer_element_size: self.num_written(),
buffer_capacity_elements: self.capacity(),
buffer_size_elements: self.num_written(),
num_elements_attempted_to_add: elements.len(),
}),
&elements[..self.remaining_capacity()],
Expand Down Expand Up @@ -140,8 +140,8 @@ where
for element in elements {
if self.unwritten_element_range.start >= self.unwritten_element_range.end {
return Err(CpuWriteGpuReadError::BufferFull {
buffer_element_capacity: self.capacity(),
buffer_element_size: self.num_written(),
buffer_capacity_elements: self.capacity(),
buffer_size_elements: self.num_written(),
num_elements_attempted_to_add: 1,
});
}
Expand All @@ -163,8 +163,8 @@ where
let (result, num_elements) = if num_elements > self.remaining_capacity() {
(
Err(CpuWriteGpuReadError::BufferFull {
buffer_element_capacity: self.capacity(),
buffer_element_size: self.num_written(),
buffer_capacity_elements: self.capacity(),
buffer_size_elements: self.num_written(),
num_elements_attempted_to_add: num_elements,
}),
self.remaining_capacity(),
Expand All @@ -189,13 +189,13 @@ where

/// Pushes a single element into the buffer and advances the write pointer.
///
/// Panics if the data no longer fits into the buffer.
/// Returns an error if the data no longer fits into the buffer.
#[inline]
pub fn push(&mut self, element: T) -> Result<(), CpuWriteGpuReadError> {
if self.remaining_capacity() == 0 {
return Err(CpuWriteGpuReadError::BufferFull {
buffer_element_capacity: self.capacity(),
buffer_element_size: self.num_written(),
buffer_capacity_elements: self.capacity(),
buffer_size_elements: self.num_written(),
num_elements_attempted_to_add: 1,
});
}
Expand Down Expand Up @@ -263,12 +263,11 @@ where
let buffer_info = Texture2DBufferInfo::new(destination.texture.format(), copy_size);

// Validate that we stay within the written part of the slice (wgpu can't fully know our intention here, so we have to check).
// We go one step further and require the size to be exactly equal - it's too unlikely that you wrote more than is needed!
// (and if you did you probably have regrets anyways!)
if buffer_info.buffer_size_padded as usize != self.num_written() * std::mem::size_of::<T>()
// This is a bit of a leaky check since we haven't looked at copy_size which may limit the amount of memory we need.
if (buffer_info.buffer_size_padded as usize) < self.num_written() * std::mem::size_of::<T>()
{
return Err(CpuWriteGpuReadError::TargetTextureBufferSizeMismatch {
copy_size,
max_copy_size: buffer_info.buffer_size_padded,
written_data_size: self.num_written() * std::mem::size_of::<T>(),
});
}
Expand Down
Loading
Loading