-
Notifications
You must be signed in to change notification settings - Fork 437
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
Unify all image types #2247
Unify all image types #2247
Conversation
I think what you said about the exportable memory for images sounds good 👍🏻 |
Do I understand correctly that, if the allocator is configured with external memory, then all buffers and images using it will also use external memory? It should probably be made clear in this case that you should use multiple allocators, one for normal resources and one for exportable ones. Having every single resource be exportable doesn't seem like a good idea. |
Each memory block allocated from a memory type that has external handle types configured will be allocated with those external handle types. Whether or not your resources are exportable depends on whether the resources were created with external handle types as well. Ideally those blocks could house both regular resources and ones that are exported, but of course since the spec is so anal about this, in practice you have to put each such resource in its own block of |
@Rua what do you think about me leaving out some of the previous constructors? Do you think my reasoning is justified? I wouldn't be completely opposed to adding those back if they actually serve a purpose. |
Also I forgot to mention the myriad of other constructors that |
Given how little those constructors actually did, I'm not opposed. For buffers though (which you haven't touched here), it may be a bit annoying for the user to have to calculate the size manually. A possible source of errors. |
When would one need to calculate the size manually? |
The gl-interop example is giving me a validation error with this PR, that I don't get with the latest master:
Oddly it's complaining about something related to buffers rather than images. |
No that's what I would expect actually, I forgot a buffer is allocated as well. I'll just make the example allocate |
Fixed. |
Thanks, there's no more validation error now. Was it caused by the example code misusing unsafe code, or is it a bug in Vulkano itself? |
It's a bug in vulkano, because we're using |
One thing that we could do so that the user doesn't have to bind memory manually is to always bind a separate block of |
* Move `Image` to the `image` module * Unify all image types * Fix tests * Fix examples * Oopsie * Don't re-export `ImageViewType` * Fix docs * Fix gl-interop example
It is here, the prophecy foretold long ago, of the image unification. Things went a bit too smoothly, though I did make some decisions while consolidating features of the different image types that undermine some previous functionality, which are as follows.
Constructors from iter/buffer
ImmutableImage::from_iter
Constructing an image from data on the host will always require a staging buffer, unless the image is
uselesslinear. Hiding that this is going on is not helping anyone, quite the opposite. Creating a new staging buffer for each upload of an image for instance, when you have thousands, is insanity.ImmutableImage::from_buffer
This is less tame, since there is no hidden buffer allocation. Yet it is still obstructing what is going on under the hood for no good reason. The image isn't created from the buffer. The function creates an uninitialized image. It's really awkward in my eyes, but worse still, recording a copy command is one line of code! This function has no utility.
Exporting memory
{AttachmentImage, StorageImage}::new_with_exportable_fd
My issue with this is first and foremost that it is platform-specific, and if we indulged things like this we would very quickly have an explosion of constructors. Instead, I think whether or not memory is exportable is something that should be handled by the memory allocator or when allocating
DeviceMemory
manually.What one would do now is:
StandardMemoryAllocator
to allocate memory with the desired external handle types: https://github.com/marc0246/vulkano/blob/bd68a6f601ec3e718ab3eb04f865d4d9fe27d6f4/examples/src/bin/gl-interop.rs#L576-L597Image
with the desired external handle types, using the regularImage::new
constructor: https://github.com/marc0246/vulkano/blob/bd68a6f601ec3e718ab3eb04f865d4d9fe27d6f4/examples/src/bin/gl-interop.rs#L117-L137Using
MemoryAllocatePreference::AlwaysAllocate
, one can also ensure the image gets its own separate allocation.Alternatively one could allocate
DeviceMemory
with the desired external handle types, create aMemoryAlloc
out of theDeviceMemory
, and bind it to aRawImage
.{AttachmentImage, StorageImage}::export_posix_fd
Exporting memory is not specific to images either and therefore this functionality should be present on
DeviceMemory
only IMO.{AttachmentImage, StorageImage}::mem_size
For suballocated images, having this be a method on the image itself doesn't make much sense. Instead one can get the allocation of the image and then the size of the
DeviceMemory
from that, albeit a bit more clunky.Since @hakolao originally added these, hopefully he can chime in and tell me whether this sounds adequate. Also tagging @fayalalebrun because they added the GL interop example, so maybe they have a perspective on this as well.
Importing memory
This only concerns
StorageImage::new_from_dma_buf_fd
.Most important issues I see with this are same as above, namely that this is platform-specific and importing memory is not specific to images, and so encouraging these constructors could quickly spiral out of control. Instead I would like to err on the side of caution and request that the user imports memory using
DeviceMemory
directly. That said I wouldn't be completely opposed to the idea of adding platform-specific constructors toImage
andBuffer
for memory-importing, if such a shortcut is truly wanted, but it would add a lot to the maintenance burden especially with the amount of external handle types that there are.What one would do now is:
DeviceMemory::import
together with the file descriptor(s) to import the memory.RawImage
with the desired explicit DRM format modifier(s).MemoryAlloc
(s) from theDeviceMemory
and bind them to theRawImage
.Since @DavidR86 added this constructor, hopefully they can give me their opinion on the matter.
Fixes #1988, fixes #1854, fixes #1446, fixes #1154, fixes #715, fixes #108.
Changelog:
Remove:
Add: