-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Queue::write_buffer_with #1670
Comments
I've actually had a very similar thought and I support having an API like this where you can see directly into the staging buffer. I do caution against the callback based API though. I did that in my library The implementation might not be so easy, but I always wanted an api which worked like buffer mapping
I'm not sure if having a separate view type is necissary, but we might need custom unmap code. |
We can expose something like this, but we aren't going to be able to do anything smart on the Web for it. Would you be happy using this API on native-only? |
In my use case I think it would be preferable to have write_buffer_with to fall back on a regular dumb queue.write_buffer. You can't really do any better than that as a user anyway. |
Agreed! |
I'm trying to implement this however I'm unsure how it should be implemented at the level of What I've done so far is: Added the fn write_buffer_with(&self, buffer: &Buffer, offset: BufferAddress, size: BufferSize) -> QueueWriteBufferView where Implemented it for the web backend by creating a temporary Started to implement it for the direct backend but unsure how to proceed due to potential API FFI compatibility issues. The 2 ways I can think of achieving it are:
On another note, do we want to issue the write on drop or should we require the user to call a method ( |
Tentatively: The overall principle is that As to whether the flush should be implicit on drop, or explicit: I guess I'd want to try using the API and see what it's like. It makes me a little uncomfortable to imagine saying, "this action which is the whole point of all this activity occurs... here at this closing bracket, where no code is written." If people of the more careful persuasion end up writing comments at the end of blocks, like
or perhaps
just to keep things straight, then I don't think the API is being helpful. Having an explicit |
(@teoxoy Thanks for working on this!) |
The nice thing about a callback-based API is that the type system can make sure you've dropped all the references to the buffer before you submit. What about an API like this?
That way, you can write as many buffers as you want, you can have (This is my attempt to address @cwfitzgerald's concern about awkward nesting and helper functions.) |
In chat @cwfitzgerald points out that you can have another thread do a submit in the midst of this, so "preventing" the borrows from overlapping with a submit isn't going to be practical. What might work better is if the writes are collected in the scope object, and they're included in the first submit after |
I think drop-based approach would be more consistent with the rest of our API. And in general the idea is sound. |
@jimblandy Thanks for your thoughts! I went with a drop-based approach for now. I'm not sure if I understand the benefits of the scope-callback approach; the current approach for |
Is your feature request related to a problem? Please describe.
Currently I'm using the Queue to write an array of Std140-convertible data to a Buffer (using Queue::write_buffer).
This takes the following form:
Vec<u8>
as "scratch space" to write the final Std140-formatted bytes toVec<u8>
as a reference to Queue::write_buffer (which accepts&[u8]
)Under the hood, I know that Queue::write_buffer is writing to a memory-mapped staging buffer internally. It occurred to me that the intermediate Vec allocation shouldn't be necessary. Instead I could just write the "converted std140 bytes" directly to the memory-mapped staging buffer.
Describe the solution you'd like
It would be nice to have something like:
This would reserve the requested amount of space in the staging buffer and expose a slice that I could then pass directly into the
std140::Writer
.Describe alternatives you've considered
Use a staging buffer manually (this is what i used to do). This requires more machinery because we need manage the staging buffer, call copy_buffer_to_buffer on a CommandEncoder, and then manually submit the encoder. I personally like the ergonomics of Queue::write_buffer.
The text was updated successfully, but these errors were encountered: