Skip to content
New issue

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

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

Already on GitHub? # to your account

Allow slicing on BufferAccess? #1281

Closed
Rua opened this issue Nov 24, 2019 · 4 comments · Fixed by #2127
Closed

Allow slicing on BufferAccess? #1281

Rua opened this issue Nov 24, 2019 · 4 comments · Fixed by #2127

Comments

@Rua
Copy link
Contributor

Rua commented Nov 24, 2019

I have buffers containing different vertex formats, but I want to store them in a single data structure, which necessitates storing them as dyn BufferAccess to erase the type. However, this means that I am no longer able to create slices of the buffers, because that requires TypedBufferAccess.

It seems to me that the type parameter of buffers and slices isn't really needed, and is sometimes even counterproductive. Vulkano doesn't check the type of vertex inside the buffer against the pipeline layout, so you can put anything in the buffer and Vulkano will accept it. This makes sense, because you may want to load vertex information dynamically and construct a buffer of [u8] without having the "correct" static Rust type to use, and Vulkano shouldn't choke on that.

From the Rust side of things, all that really matters for slices is getting the element size correct to avoid cutting vertex elements in half. The Rust type of the buffer elements is totally irrelevant because they are never accessed from Rust code. So I think it would make sense if buffers simply store their element size instead of relying on the Rust type. That would allow them to become untyped, making TypedBufferAccess obsolete and allowing slicing directly with BufferAccess.

@Rua
Copy link
Contributor Author

Rua commented Nov 25, 2019

I found another related issue. It's apparently not possible to draw with a Arc<TypedBufferAccess>, the draw function requires a Arc<BufferAccess>. I can, however, get around this by creating a slice.

@AustinJ235
Copy link
Member

The BufferAccess trait provides the method as_buffer_slice . For creating a slice from a TypeBufferAccess the BufferSlice struct provides a method called from_typed_buffer_access.

Perhaps you overlooked something or I didn't answer your question.

@Rua
Copy link
Contributor Author

Rua commented Nov 26, 2019

You still need a TypedBufferAccess for that to work, though. If you erase the type entirely by using a dyn BufferAccess, you lose the ability to slice, even though it would be very much feasible to allow this.

@AustinJ235
Copy link
Member

AustinJ235 commented Nov 27, 2019

I read your original question again. Perhaps dropping the type from these traits would be a good idea although would leave out some dummy checks for simple users. I myself am guilty of transmuting to another type for uploads. So I guess maybe we should implement a type like RawBufferAccess that doesn't care about type as long as the data len matches.

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

Successfully merging a pull request may close this issue.

2 participants