-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
[RFC] Treat all types in the Vulkan
namespace as fundamental
#1134
base: main
Are you sure you want to change the base?
Conversation
a04cc7c
to
f2db976
Compare
How is it different for GL, and can the Vulkan-1.0.gir maybe be changed the same way? |
None of the GL types appear to be used in public API anywhere (try searching for those names in other |
f2db976
to
c599d79
Compare
As discussed on IRC, let's go with that because also GTK4 will likely need such a thing sooner or later. |
I'd treat them as such by using some string interning library. That's going to make all this simpler (although the "borrowing churn" is in now, it's independent of this really). |
I don't know what this means exactly, but I prefer no hardcoding and you should be able to just go via namespace or not? :) |
c599d79
to
3e98854
Compare
See the massive list in
We'll see, probably going to keep it owned I'll give this another shot later this weekend. |
3e98854
to
0fe1d2b
Compare
0fe1d2b
to
de5ebd9
Compare
de5ebd9
to
6055301
Compare
6055301
to
34d88c4
Compare
34d88c4
to
cc1e9bf
Compare
cc1e9bf
to
a843820
Compare
a843820
to
7412855
Compare
7412855
to
f83f10b
Compare
ed10f65
to
f260d82
Compare
f260d82
to
ca50417
Compare
Hi @MarijnS95. Don't suppose you have any capacity to progress this? Getting gstreamer-vulkan pushed through (even if just the -sys bindings) would be very useful, and it looks like this is the main blocker at the moment. |
@spencercw I'm willing to invent time for it as I'd hate to see all this effort thus far go to waste. For starters I think I should rebase all relevant branches. Then we can go from there, and this (binding We should either extend the file to include relevant type information, and/or extend the |
Good stuff, thanks. Yes your name seems to come up all over the place 😂 I'm not particularly familiar with the gstreamer stack, but might be able to help fill in some of the details once you've got the fundamentals in place. |
You're welcome 🙂 Conveniently I got back into gstreamer-rs development just two weeks ago by refactoring the GL example to use the new For starters, if you're interested in just https://gitlab.freedesktop.org/MarijnS95/gstreamer-rs/-/tree/vulkan Meanwhile I'll see what/when can be done to rebase these branches and figure something out for |
Thanks, yes I found your branch yesterday and was able to hack together a working |
It's not. There's no such concept in gobject-introspection, there's not even a concept of mutability in general. We're adding this here on top with some very basic heuristics that easily go wrong.
I don't mind either way |
Well Gir.toml is adding the Rust flavour on top of gobject-introspection so it might be something that's already supported, or am I misunderstanding you? |
It doesn't support that. For boxed types it is possible to change mutability of function parameters (if taken by reference), but that's all you can do right now in that regard. Arrays are IIRC always considered immutable (both the array as well as the elements) and you can't configure that, and usually functions that need mutability there in some way need manual bindings (and often are slightly different in behaviour). |
Yeah the code is generated with immutable slices (correct!) but the FFI function signature expects I think if we fix it in Again, I'm not going to reimplement every Rust function by hand just to work around this bindings issue. |
It should use the same mix of const/mut as the C API. Doesn't it?
But why not. I think this can actually be implemented just fine? The returned array is always a copy anyway, the items are either full copies (including for e.g. The only problem is for functions that assume that the array is passed in by the caller, modified by the function, and then the caller has the modified version (I guess that would also have to be marked |
Right now it does, but as said the C API is wrong and so is the resulting Rust
Can I implement
The reason I marked them as If you want to take a look the arrays in question are |
The implementation that I had (assuming the C bindings were fixed) uses It doesn't copy anything for now; should it? |
@spencercw I've squashed and pushed the results of various short hacking sessions over the past few days; the bindings now compile and should be in a somewhat-usable state. Please let me know if anything is off or missing, but note that I still have to do another pass to recollect all the new functions and types, and either generate or manually implement them. As for the things to discuss, I don't think it's worth repeating what I already wrote in the PR description (most/all are still applicable), doing it in GitHub discussions has so far proven worthless. @sdroege is there some kind of weekly syncup for gtk-rs/gstreamer-rs that I might be able to join and where we could have an agenda item to discuss the various points of contention to unblock Vulkan bindings in gstreamer-rs? For now, specific to this We still have to figure out:
|
Thanks for working on this. Couple of issues (possibly self-inflicted; not really sure what I'm doing): In If I re-run |
@spencercw good point, I ran into that on my development machine where I have the I think for that the custom use ash::vk::*;
use ash::vk::QueueFlags as QueueFlagBits; And it might require more manual conversion.
Correct, that is the first point above regarding "How to annotate what types are passed as borrow/pointer;". |
dc5e4fc
to
f49cec5
Compare
@spencercw in the latest push everything compiles fine with the |
Thanks. Is there a safe way to access fields on the underlying C type from the safe wrappers? E.g., I want to read Some issues I found while migrating to the safe bindings (sorry if you're already aware of these):
|
@spencercw Thanks for checking this out. I don't exactly recall what the right/desired way was to get at the public fields of glib objects, maybe manual getters on the type? It's already quite a handful to deal with so many repositories and changes just to get some bindings generated and see how close we can get to a compiling repo, that there has not yet been any time to actually test-drive the bindings, not to mention analyzing every individual generated struct and function to tell whether they make sense. I hope to get that at some point, but you're beating me to it quite nicely and it helps polishing the bindings before even getting the boilerplate in a barely acceptable state 👍 The first two points are obviously yet again missing annotations upstream; I've opened a PR for it and the patches are coming in fast and hot :( For the ref/unref, these turn out to be GStreamer mini objects that |
One more thing that caught me out is I can't work out how to call
But |
@spencercw just like the changes I pushed for However, maybe there is a case for an extension struct instead (like |
Anyway, what kind of app/usage are you building with this @spencercw? My initial intent was to start with a
And in the future this could be extended to use a fullscreen quad shader like Then we're spiraling quite out of context for this PR. A better place might be the issue for adding Vulkan bindings to Alternatively we could find another place, or I could open a preliminary MR where we can start discussions on the diff (though I'm afraid it'd get too much review before I can even go over things myself). |
@spencercw here's an example of how a setter extension on Now it seems that the function(s) you're linking are only relevant for a |
@spencercw so we now have this API: let pool = gst_vulkan::VulkanImageBufferPool::new(&d);
let mut config = pool.config();
config.set_allocation_params(
ImageUsageFlags::TRANSFER_DST,
MemoryPropertyFlags::DEVICE_LOCAL,
);
dbg!(config); Looks like it works:
Will tackle the same functions on images before pushing later. |
That sounds like a good starting point. Personally, I'm implementing a filter deriving
In the sink caps I don't specify I do use Within the transform logic I'm mostly just using plain ash to do the actual rendering. Happy to take this discussion somewhere else if you prefer. The revised Footnotes
|
By the way, I'm relying on gstreamer to initialise Vulkan for me, rather than the other way around, so my logic for getting the instance/device is basically a direct translation of this. I use |
Hmm this is nasty, there are two functions (currently) doing the exact same thing: gst_vulkan_buffer_pool_config_set_allocation_params();
gst_vulkan_image_buffer_pool_config_set_allocation_params(); And they should both be implemented on the
Good point, I've also been wondering this while looking in DMA scenarios and wondering how "smart" GStreamer is with automatically uploading, copying, or mapping (and allocating compatible in the first place) buffers in an efficient way. E.g. Vulkan could map DMA buffers and vice versa, and as you've found out Vulkan can create host-visible/writable memory. IIRC you can specify multiple memory types, maybe that works here? (And then you allocate matching memory on the Vulkan side, depending on the final caps that were negotiated?)
I expected this to be tricky when extra extensions (e.g. for WSI) are needed. There's an But it sounds like you're only using the device for a filter, and leaving windowing/presentation to I'd have proposed https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/389 to continue our discussions but it's already a cesspool of unrelated comments and noise. Maybe we should start a new issue; perhaps on my personal fork where the branch lives? https://gitlab.freedesktop.org/MarijnS95/gstreamer-rs |
Yeah it doesn't seem to have much smarts in that regard at the moment. If you do a
I was thinking something like that might be possible, but right now I know my upstream source is in system memory so I haven't looked into it any further.
Probably, yeah. I don't need any extra extensions right now, so again I haven't looked into it.
I'm actually just feeding into an encoder for streaming. At some point I may need to import the images into CUDA for use with NVENC or something else, which is sure to bring its own set of headaches because while you can import Vulkan semaphores into CUDA, gstreamer doesn't seem to use CUDA semaphores anywhere at the moment.
Sounds good to me. |
@spencercw my reply is in https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/389#note_2188252 Feel free to jump back here if you have anything about mapping the |
f49cec5
to
c196256
Compare
c196256
to
1e902d7
Compare
This crate would be the place where either: 1. `ash::vk::*` is reexported; 2. manual reexports are generated from `Vulkan-1.0.gir`; 3. something else.
Gir.toml glob matches don't seem to function: [[object]] name = "vulkan.*" status = "generate" [[object]] name = "vulkan.*" status = "generate"
1e902d7
to
490977f
Compare
All Vulkan handles, enumerations, bitfields and structs in G-IR reflection have one fundamental flaw: they are empty records. As such
gir
is unable to generate anything representative for them and treats them as incomplete instead, breaking pretty much every struct that needs to use these to do anything with it.Instead of trying to fill this reflection with the right fields and types we should opt to map them to a Rust crate that already provides bindings directly to Vulkan. Introducing
Ash
, Rust's most widely used Vulkan wrapper crate (disclaimer: I'm an active maintainer). This PR takes care of mapping the types properly. Most notably it makes sure that "safe" and FFI types are the same, instead of generating conversion code with.to_glib_none()
and friends - that makes no sense at all.An initial user of these bindings is GStreamer, but it's very much work-in-progress: https://gitlab.freedesktop.org/MarijnS95/gstreamer-rs/-/tree/vulkan. With this massive issue out of the way though I hope to get started on a Vulkan pipeline and window in Rust (
glwindow
equivalent) rather soon.Things to discuss:
Type::Custom
be used for this as well (iow: did I just invent something that already exists in a different form already, without explicitly adding a new enum variant)?;Vulkan.
namespace) and/orVulkan-1.0.gir
instead of hardcoding them inconst VULKAN
;Fundamental::Vulkan
as&'static str
so that all this borrowing churn isn't necessary (not possible if we parse types from G-IR);OTOH some of the
*
andref
removal is actually quite a nice simplification!vulkan
/vulkan_sys
crate ingtk-rs-core
instead (representingVulkan-1.0.gir
, this is where I "started" but that's the broken approach). This crate is then solely responsible for selecting anAsh
version and only consists ofpub use ash::vk::*;
. Of course it can more easily map to a different crate as well if desired, assuming names are the same (ie. stripped of theirvk
prefix). Where necessary it would be a nice place for generic Vulkan-related helpers, re-mapping types that are wrongly named if any, etc.