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

Dynamic meshes #251

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Dynamic meshes #251

wants to merge 2 commits into from

Conversation

zakarumych
Copy link
Member

No description provided.

let ptr = slice.as_ptr();
unsafe { std::slice::from_raw_parts(ptr as _, len) }
}

/// Cast slice of some arbitrary type into slice of bytes.
pub unsafe fn cast_arbitrary_slice<T, U>(slice: &[T]) -> &[U] {
let bytes = size_of::<T>() * slice.len();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is terribly unsafe in so many ways, a comment should definitely mention that it's effectively equivalen to transmute. You are only using it on Copy types, so it should probably be typeguarded as such. That way we at least get rid of Drop related issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also intended as internal method. Shouldn't be pub.

}
}

Ok(unsafe { cast_arbitrary_slice_mut(&mut vertices.bytes[bytes_range]) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a safety issue. We probably should annotate AsVertex trait as unsafe so it is a responsibility of implementer to make sure it's safe to represent it as a byte slice (basically enforce #[repr(C)]).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is always safe to represent any type as bytes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And should be also safe to represent back. Alignment should be preserved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not always safe. See this thread https://internals.rust-lang.org/t/pre-rfc-v2-safe-transmute/11431

In fact, there are crates that help with this today. See bytemuck. Notice that Pod trait is actually unsafe and has quite some safety rules attached to it.

&mut self,
index: usize,
range: Range<u32>,
fill: V,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename fill to default_value or something like that. I interpreted those arguments as if the function would fill the whole provided range with fill value.

/// # Panics
///
/// This function will panic if wrong index type is requested.
pub fn modify_indices_16(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that it would be better to have a single modify_indices that returns either &mut [u16] or &mut [u32], then possibly have those two methods use it. There is quite some duplication here.

Also, doc is inaccurate. It doesn't panic, it returns an error on mismatch.

Ok(unsafe { cast_arbitrary_slice_mut(&mut indices.bytes[bytes_range]) })
}

pub fn update(&mut self, queue: QueueId, factory: &Factory<B>) -> Result<(), UploadError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this should be called upload or flush. Also the upload should only really happen if it was updated since last time (it should have a dirty flag or something).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does use dirty regions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shit, you are totally right. I somehow skipped that in reading. Then it's only the naming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants