aclysma / rafx

Multi-backend renderer with asset pipeline. The objective of this repo is to build a scalable, flexible, data driven renderer.
Apache License 2.0
641 stars 32 forks source link

Runtime API Selection #164

Closed zicklag closed 3 years ago

zicklag commented 3 years ago

Would it make sense to be able to select the graphics API to use at runtime, instead of at compile time?

For instance, on Linux, if I wanted to use Vulkan when possible, but to switch to OpenGL when Vulkan is not supported.

If this would require drastic changes I can understand it being a non-goal, and for my use-case, for distributing PC games, I wouldn't mind terribly if there was a separate build that would be downloaded if OpenGL support was required, but I was curious as to the potential.

aclysma commented 3 years ago

Add the feature flags you want (such as rafx-vulkan,rafx-gles3) and use the API-specific init functions such as RafxApi::new_vulkan or RafxApi::new_gles3. RafxApi::new demonstrates this and probably does what you want by default.

https://github.com/aclysma/rafx/blob/0a495460e0ee0c3c0d320565b3e86087f940ef96/rafx-api/src/api.rs#L63-L88

Long term, API selection could be made by having a config file that explicitly pairs PCI device IDs/driver versions with APIs (for example to ban an old GPU from vulkan if it is known to have a buggy driver). This could also be used to enable/disable rendering settings based on the performance of that particular GPU. This is outside the scope of this project for the time being and is a fairly opinionated thing.

zicklag commented 3 years ago

Oh, cool, I didn't realize it would work with multiple backends enabled at the same time. Perfect!