Skip to content

Add wgpu graphics server - #927

Draft
nice0hack wants to merge 36 commits into
FyroxEngine:masterfrom
nice0hack:master
Draft

Add wgpu graphics server#927
nice0hack wants to merge 36 commits into
FyroxEngine:masterfrom
nice0hack:master

Conversation

@nice0hack

Copy link
Copy Markdown

Description

This PR introduces the initial draft implementation of the wgpu backend for the Fyrox Engine.

A critical aspect of this PR is that backward compatibility with the existing OpenGL backend is fully preserved. The new wgpu integration is wrapped as an optional Cargo feature, meaning it does not affect the current default engine behavior.
To test the engine with the new backend, you need to run it using the following flags:
cargo run --package fyroxed --profile=editor-standalone --no-default-features --features backend_wgpu

One of the greatest advantages of wgpu introduced in this PR is its smart backend selection. It dynamically evaluates the most relevant graphics APIs available on the user's OS (e.g., DirectX 12, Vulkan, Metal) and automatically selects the most performant one. For example, on my Windows 10 machine with an older GPU, it seamlessly fell back to Vulkan to ensure optimal compatibility and performance.

Related Issue(s)

#721

Review Guidance

Testing Environment:
So far, this implementation has only been tested on Windows 10 and Fedora Linux 43. Feedback from macOS or other environments would be highly appreciated.

Known Bugs & Limitations (To-Do):
I have encountered a few complex bugs that I haven't been able to resolve yet. Fixing them might require a significant amount of time and deep debugging:

  • A mesh object in deferred rendering moves away from its original position depending on the camera's rotation.
  • When adding any external light source, the entire scene rendering breaks.
  • Debug rendering doesn't render properly.
  • The camera in orthographic projection breaks completely.

Discussion: MSAA & Deferred Rendering:
Currently, MSAA (Multisample Anti-Aliasing) support is not implemented for the wgpu backend. Integrating MSAA with wgpu in our Deferred Rendering pipeline would cause a massive drop in performance and heavily inflate VRAM usage. We should discuss whether it's worth implementing MSAA at all, or if we should rely on post-processing anti-aliasing solutions (like FXAA or SMAA), which fit the deferred pipeline much better.

Final Thoughts & Proposal for Merging:
Integrating wgpu is a massive and fundamental shift for the engine's architecture. Since my changes are entirely isolated behind a feature flag (backend_wgpu) and do not break or affect the stable OpenGL backend, I highly recommend merging this PR in its current state.

Having this foundational codebase in the master branch will allow the community to test it, try out the wgpu backend, and contribute. We can then split the remaining bugs listed above into separate, manageable issues and gradually polish the wgpu transition together rather than keeping this giant update stuck in a single PR.

Checklist

  • My code follows the project's code style guidelines
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes don't generate new warnings or errors
  • No unsafe code introduced (or if introduced, thoroughly justified and documented)

/// Each entry is a `(location, format, &'static [VertexAttribute])` triple. The
/// attribute arrays are `const` statics so they have `'static` lifetime without
/// needing `Box::leak`, avoiding per-draw-call memory leaks.
const EXTRA_VERTEX_LAYOUTS: &[(u32, &[wgpu::VertexAttribute])] = &[

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a hack, because it adds info about vertex layout in frame buffer itself. It is not necessarily a bad thing for a prototype, but looks like something that needs to be addressed later.

@nice0hack
nice0hack marked this pull request as draft July 31, 2026 09:50
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