1 unstable release
0.0.2 | Jan 17, 2021 |
---|
#2415 in Game dev
3MB
65K
SLoC
Rafx
This is a multi-backend renderer built on top of the atelier-assets
asset
pipeline. It's intended to be performant, flexible, workflow-friendly, and suitable for use in real-world projects in a
team environment.
The asset pipeline is designed with user workflow in mind (including dedicated artists!), supporting workflow-friendly features like hot reloading assets, including on remote devices. The architecture of the renderer is intended to support advanced use-cases such as streaming, LODs, visibility systems, and multi-threaded draw call submission.
This crate contains several layers:
- Low-level graphics API abstraction
- Higher-level resource management and lifetime handling (via render graph and other helpful utilities)
- Asset layer that integrates with
atelier-assets
- Tools for packing assets for a shipped build and auto-generating shader binding code
NOTE: Some cr
Supported Platforms:
- Windows
- macOS (via MoltenVK)
- iOS (via MoltenVK)
- Linux
Android might work but I don't have hardware to test with.
References:
- The job/phase rendering design is inspired by the 2015 GDC talk "Destiny's Multithreaded Rendering Architecture".
- The render graph is inspired by the 2017 GDC talk "FrameGraph: Extensible Rendering Architecture in Frostbite"
- see also "Render Graphs and Vulkan - a deep dive"
- The low-level API is somewhat similar to the API from "The Forge"
^ Video of this renderer running on iOS hardware
Diagrams
Status
Not production ready!
The demo includes:
- Render thread decoupled from main thread (diagram)
- Asynchronous asset loading
- Assets can be streamed to remote hardware (i.e. a phone)
- OR assets can be cooked into a binary blob for shipping
- Hot-reloading assets (needs more work, some asset types do not work reliably)
- Render graph can be used for efficient and flexible definition of a render pipeline, including rendering to textures and multiple cameras.
- Auto-generated shader bindings make working with descriptor sets convenient and less error prone.
- Material System supporting multiple passes
- Multi-camera support (to produce shadow maps, for example)
- Demo game state stored in ECS (NOTE: demo uses legion but the renderer is ECS-agnostic)
- PBR Meshes
- Sprites
- Debug Draw
- imgui
- HDR Pipeline with Bloom
- Point, Spot, and Directional Lights
- Multiple Spot/Directional/Point light soft shadows
Running the Demo
The demo should be run from the root of the repository. These commands should clone the repo and run the demo.
git clone https://github.com/aclysma/rafx.git
cd rafx
cargo run --bin demo --release
Running in release reduces logging and disables GPU validation. The first time it will load more slowly because it has to import the assets, including a GLTF mesh with large textures. Using profile overrides to optimize upstream crates is highly recommeneded. Asset processing is extremely slow in debug mode. (i.e. 30s instead of 2s)
The demo uses SDL2 and in debug mode, vulkan validation. If you have trouble running the demo, please check that dependencies for both SDL2 and vulkan are available.
Tools
The renderer includes a few tools for processing shaders and packing data in a binary blob.
Shader Compiler
This tool parses GLSL and produces matching rust code. This makes working with descriptor sets easier and safer!
- The tool is located at /shader-processor
- The demo includes a
shaders
crate to compile the generated rust code. It's located at /demo/shaders. Just the rust code is auto-generated, not the Cargo.toml. - The easiest way to "refresh shaders" in the demo is to hit compile.bat or compile.sh in that folder
CLI
This tool currently is only useful for packing assets.
- Pack files like this:
run --package cli -- --pack out.pack
- Run the demo like this:
run --package demo -- --packfile out.pack
Features
rafx-base
- Shared helpers/data structures. Nothing excitingrafx-api
- Rendering API abstraction layer.- Vulkan backend for windows/linux (native/direct, not through a translation layer)
- MoltenVK currently required for macOS but native metal backend coming soon!
rafx-nodes
- Inspired by the 2015 GDC talk "Destiny's Multithreaded Rendering Architecture." (A low-budget version and jobs are not actually MT yet)- A job system with extract, prepare, and write phases
- Rendering is pipelined with simulation thread, and the job structure is intended to be highly parallel
- Handles multiple views and phases allowing advanced features like shadow maps
- Flexible sorting mechanism for interleaving and batching write commands from multiple rendering features
rafx-visibility
- Placeholder visibility system. Doesn't do anything yet (returns all things visible all the time). See the GDC talk for more info on how this will work.rafx-resources
- Resource management for images, buffers, descriptor sets, etc.- Most things are hashed and reference counted
- Provides a render graph
- Nearly all vulkan assets are data-driven from serializable and hashable structures rather than hard-coded.
- Buffers and images are asynchronously uploaded on dedicated transfer queue when available
rafx-assets
- An asset loading and management system.- Assets can hot reload from files (but see #14)
- Because atelier-assets pre-processes and stores cached assets as they change, custom processing/packing can be implemented while maintaining extremely fast load times. For example, texture compression could be implemented as an import step.
- Separate multi-thread friendly path for creating assets at runtime
- Multi-pass material abstraction with bindable parameters
Roadmap
- Better shadows
- More rendering techniques like SSAO
- Support for more rendering backends (mainly metal and dx12)
The demo shows a basic rendering pipeline with a GLTF importer, PBR, bloom, imgui, debug draw, sprites, and dynamic light/shadows. It also demonstrates how to pipeline rendering on a separate thread from simulation.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Upstream Dependencies
The demo/fonts directory contains several fonts under their own licenses:
- Feather, MIT
- Material Design Icons, SIL OFL 1.1
- FontAwesome 4.7.0, available under SIL OFL 1.1
mplus-1p-regular.ttf
, available under its own license.
The assets/blender contains some shaders from from https://freepbr.com, available under its own license
Some dependencies may be licensed under other terms. These licenses include "ISC", "CC0-1.0", "BSD-2-Clause", "BSD-3-Clause", and "Zlib". This is validated on a best-effort basis in every CI run using cargo-deny.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
See LICENSE-APACHE and LICENSE-MIT.
Dependencies
~4.5–6.5MB
~155K SLoC