Skip to content

WGPU (WebGPU/Vulkan/Metal etc) renderer#112

Draft
ArcturusEmrys wants to merge 36 commits intoInochi2D:mainfrom
ArcturusEmrys:inox2d-wgpu
Draft

WGPU (WebGPU/Vulkan/Metal etc) renderer#112
ArcturusEmrys wants to merge 36 commits intoInochi2D:mainfrom
ArcturusEmrys:inox2d-wgpu

Conversation

@ArcturusEmrys
Copy link
Contributor

This PR adds a renderer using wgpu, allowing the use of modern graphics APIs.

Due to requirements on the wgpu side, the InoxRenderer trait has been significantly modified. All methods now take &mut self and on_begin_draw/on_end_draw have been moved into the trait proper.

(I also anticipate potentially splitting out all the individual draw methods into a separate InoxRendererDraw trait that is returned from on_begin_draw as it works better for wgpu. Currently, we have to unwrap/take stuff in InoxRenderer that could just be owned by the individual draw operation until done.)

This also includes wgpu-compatible versions of all the OpenGL shaders. While it would technically be possible to share the shaders between renderers, it would impact the OpenGL side. (Specifically, everything has to use explicit layout and uniform blocks, and I increased the GLSL version to support this.) There is additionally a build script that precompiles all GLSL to SPIR-V and generates Rust code for bindings. That is necessary in wgpu as all the GLSL introspection in OpenGL is gone. I am not aware of a Rust library that can do this codegen, but there should be (and it'd probably be more generic than mine).

There's also an example app that uses the wgpu renderer.

This PR is NOT complete yet, as I have yet to get my model to work properly in inox2d in general before comparison testing the two.

This necessitates newer GLSL shaders that use explicit uniform blocks and other things not in use in the OpenGL version of these shaders. They may be copied back to their OpenGL versions in the future.
I've decided to make the convention call that the vertex shader is always in slot 0, and the fragment shader in slot 1.
More advanced build scripts and codegen would allow other configurations of the shaders, but I'm not sure if that time is justified just for this project.
This one isn't code-genned, but if I wind up needing variadic parameters or whatever it might wind up being so in the future.
Already, I've had to add methods to InoxRenderer and make a few take &mut instead of &. I suspect I will be completely revising InoxRenderer by the end of this.
I originally considered making this a normal array, but the const generics threatened to spill over to the entire program. Instead, we have an associated type which acts like an array and expected to be one.
…ven pipeline.

The OpenGL renderer just assumes we can change these options on the fly, which isn't how modern GPUs work. I suspect it might have been easier to ubershader this, but I didn't want to change the shader code too much. Even with all 24 possible pipeline combinations compiling this shouldn't be too much of a drag on performance.
OpenGL muddied the naming a bit but WGPU / vulkan etc are pretty clear
The GBuffer type is only intended to be rendered to for Composite nodes.

I'm still not sure how emissive/bump works outside of Composite nodes - the OpenGL renderer renders straight to the window surface without binding any other textures. I may have to experiment...
@Speykious
Copy link
Member

I'd love to have a WGPU renderer back, but I don't know WGPU myself. We had one previously but I ended up removing it because I couldn't maintain it. If you want this merged I'd want you to commit to maintaining at least the renderer.

Though that's contingent on me maintaining inox2d itself, which I'm not really doing right now, so...

@ArcturusEmrys
Copy link
Contributor Author

I wasn't aware you'd had a wgpu renderer in the past. Would you be OK with me just PRing the InoxRenderer changes (mutability + begin/end changes) separately? The wgpu renderer can live in a fork for now.

@Speykious
Copy link
Member

a33c92e FYI.

Would you be OK with me just PRing the InoxRenderer changes (mutability + begin/end changes) separately?

Sure!

@ArcturusEmrys
Copy link
Contributor Author

@Speykious #115 contains all the trait changes necessary for rendering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants