vulkano-rs / vulkano

Safe and rich Rust wrapper around the Vulkan API
Apache License 2.0
4.52k stars 435 forks source link

vk-sys should be autogenerated from vk.xml #89

Closed cwabbott0 closed 2 years ago

cwabbott0 commented 8 years ago

Instead of hand-coding all the definitions, they should be parsed from the same XML definitions that are used to create vulkan.h. This should also add support for the recent extensions for free. I have some WIP code that parses it and generates something that at least seems like rust, I'll try and beat it into shape so it can autogenerate vk-sys/lib.rs.

tomaka commented 8 years ago

There's also the vk_generator crate which was written for this purpose.

tomaka commented 8 years ago

See also this issue: https://github.com/KhronosGroup/Vulkan-Docs/issues/210

kvark commented 6 years ago

I'd like to bump this in priority, if possible, in relation to #525. Being able to run on Metal, D3D12, and even GL, would vastly expand the reach-ability of Vulkano and remove the blockers potential users may see in this library.

We can't replace the existing vk-sys types directly, but we could easily get away with changing the generation parameters if it was done automatically with vk_generator. Also see the issue on the other side - https://github.com/Osspial/vk-rs/issues/10

tomaka commented 6 years ago

This is blocked by https://github.com/Osspial/vk-rs/issues/7, https://github.com/Osspial/vk-rs/issues/8 and https://github.com/Osspial/vk-rs/issues/11

kvark commented 6 years ago

@tomaka all those vk-rs blockers are resolved now 🎉

Osspial commented 6 years ago

I just published vk_generator 0.3, which should resolve any issues blocking vulkano using it to autogenerate the functions.

Osspial commented 6 years ago

I'm in the process of writing a PR to bring vk-sys over to using vk_generator, and there are a couple of sticking points:

tomaka commented 6 years ago

@Osspial I'd prefer to leave vk-sys untouched and switch vulkano directly to vk_generator. Your last point is important but I think I can go with hardcoding the necessary function names in vulkano.

kvark commented 6 years ago

@Osspial @tomaka where are we on that issue? We are increasingly more eager to run Vulkano on top of gfx-hal without going through C boundary.

Osspial commented 6 years ago

I've pushed some code that should resolve the Vulkan handle issue, but that isn't on crates.io yet. AFAIK that was the last issue in vk_generator that needed to be resolved, and now it's just a matter of implementing the changes within vulkano.

Osspial commented 6 years ago

Began migrating the code! This still isn't fully working, as I haven't gotten the multiple-structs-for-different-function-categories thing resolved, but most other changes needed to get this working within Vulkano have been made.

I'll submit a PR when that's ready. My instinct here is to share the function pointers between all the structs that need them with a Rc<Vk> - @tomaka, do you see any issues with that?

https://github.com/Osspial/vulkano/tree/vk-sys-autogenerated

Osspial commented 6 years ago

Actually, scratch that - I can see a reasonably simple way to automatically split up the function pointer structs now. Besides a few entry-point functions (GetInstanceProcAddr, CreateInstance, EnumerateInstanceExtensionProperties, and EnumerateInstanceLayerProperties), I'm pretty sure every Vulkan function takes a dispatchable handle as the first parameter. I can set up vk_generator to make a function struct for each dispatchable handle (so VkInstance gets VkInstanceFns, VkDevice gets VkDeviceFns, etc.). There are relatively few dispatchable handles so that should pretty easy to manage, and would let vulkano use a function loading system that's similar to what's there today. Thoughts?

tomaka commented 6 years ago

@Osspial I'm not 100% certain that this is an entirely robust solution, but I'm willing to give it a go.

knappador commented 5 years ago

@Osspial what's your understanding of what remains to be done here? I don't think anyone's driving at the moment. The work does sound like a valuable addition.

Osspial commented 5 years ago

@knappador It probably wouldn't be difficult to implement, but I haven't thought about vk-rs for a while since I've got a whole bunch of other projects I've been focusing on. I'd accept PRs to implement it (and would happily mentor anyone trying to do it since vk-rs was one of my first big Rust projects and the code's kinda messy), but I don't have the time to do it myself right now.

knappador commented 5 years ago

@Osspial can you dump off any dirty work in a spiked PR or just write up the process you expect needs to be completed? I'm finishing up splitting the shaderc crate and can likely take on the groundwork if the design is laid out. If there's too much work, delegate! =)

Osspial commented 5 years ago

Sorry it took a few weeks to get back on this!

Adding the feature should be fairly simple - you need to modify the gen_struct function to generate different structs based on the first parameter in the function and its type. You probably also need to modify the struct generation macro based on whether the struct contains the bootstrapping functions or the handle-based functions.

Let me know if any more questions come up if you get around to implementing this. I'll aim to respond sooner than I did this time.

Rua commented 3 years ago

How is this project going, two years onwards? Does it work? Can Vulkano use it?

Rua commented 2 years ago

Vulkano now uses ash as its backend, so this is no longer needed.