-
I have a PC emulator written in Rust, using winit, wgpu and egui. I'd love to implement Librashader, but I confess I am a bit confused as to how I'd go about doing it. There are examples under each 'runtime' but I don't see an example of just importing the librashader crate and going from there. The docs say
How do I get a FilterChain? It seems that it is defined for each runtime. Do I have to choose a runtime statically? Is there a way to query what runtimes are supported on a specific platform? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
WGPU might be a little more complicated for the fact that the current runtimes work with the underlying surface of a HAL but it's probably doable with some arm twisting.. You'll have to figure out which graphics backend is being used at runtime, and select for the appropriate librashader Getting the use librashader::runtime::vk::*;
fn load_vulkan_filter_chain(path: impl AsRef<Path>, pd: ash::vk::PhysicalDevice, instance: ash::Instance, device: ash::Device) -> Result<FilterChain, FilterChainError> {
let preset = ShaderPreset::try_parse(path)?;
FilterChain::load_from_preset(preset, (pd, instance, device), None)
} Then after rendering, but before you present, call The rough structure is the same for every runtime, Usually in every runtime you'll find a working minimal example in the |
Beta Was this translation helpful? Give feedback.
-
I'm starting a branch over at https://github.com/SnowflakePowered/librashader/tree/feat-wgpu-runtime to build a WGPU runtime, but the only (kind of big) issue is that it needs This is pretty much because of gfx-rs/wgpu#4342, since most if not all RetroArch shaders rely on combined image samplers. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the info. I'm working on a display abstraction for my emulator so I'm not necessarily committed to rendering with wgpu for a given window. I can create a new window and attach anything that I've implemented my RenderBackend trait. Here's what I'm thinking: Before creating this backend I can query the main wgpu instance to see what backend it selects and then attempt to create a librashader FilterChain of the same type. But this assumes I can render to an existing Winit window handle, or retrieve the raw window handle from the new window and use to render. I'd rather avoid having a window created externally as it is convenient for all my windows to share the same event loop. A wgpu backend would probably be pretty convenient at least to me, even if it only worked on Vulkan. My emulator's wgpu frontend already pretty much performs poorly on any backend that isn't Vulkan already. I have a built in CRT shader, so I assume anyone wanting to play with Retroarch shader presets probably has a decent graphics card that will support Vulkan. It would especially be nice if it would cut down on the number of additional dependencies required. I'll play around with the Vulkan runtime example and see if I can get this working. Thanks for creating this, by the way - shader support has been one of the more popular feature requests I've received and I had no idea how I was going to implement that on my own. |
Beta Was this translation helpful? Give feedback.
-
Just to give a quick update, it was apparent fairly early on that simply loading SPIR-V shaders wasn’t going to work for WGPU, since it has no API to actually bind combined image samplers. To that end, I’m working on a couple of SPIR-V transforms over at https://github.com/chyyran/kirisaku that will split up combined image samplers and put the samplers in bind group 1. I’ll also have to put push constants into their own UBO since WGSL doesn’t support those either and it’s a much more trivial transform than splitting up That should mean though that the WGPU runtime will hopefully be compatible with more than just Vulkan, and also WebAssembly-compatible since it’ll be working with valid WGSL. May need to tweak which features get compiled in for WASM targets though. |
Beta Was this translation helpful? Give feedback.
-
As of #24 librashader now provides a wgpu runtime. |
Beta Was this translation helpful? Give feedback.
As of #24 librashader now provides a wgpu runtime.