• Stars
    star
    1,473
  • Rank 31,917 (Top 0.7 %)
  • Language
    C++
  • License
    MIT License
  • Created over 7 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

My personal Vulkan renderer

Granite

Granite is my personal Vulkan renderer project.

Why release this?

The most interesting part of this project compared to the other open-source Vulkan renderers so far is probably the render graph implementation.

The project is on GitHub in the hope it might be useful as-is for learning purposes or generating implementation ideas.

Disclaimer

Do not expect any support or help. Pull requests will likely be ignored or dismissed.

License

The code is licensed under MIT. Feel free to use it for whatever purpose.

High-level documentation

See OVERVIEW.md.

Low-level rendering backend

The rendering backend focuses entirely on Vulkan, so it reuses Vulkan enums and data structures where appropriate. However, the API greatly simplifies the more painful points of writing straight Vulkan. It's not designed to be the fastest renderer ever made, it's likely a happy middle ground between "perfect" Vulkan and OpenGL/D3D11 w.r.t. CPU overhead.

  • Memory manager
  • Deferred destruction and release of API objects and memory
  • Automatic descriptor set management
  • Linear allocators for vertex/index/uniform/staging data
  • Automatic pipeline creation
  • Command buffer tracks state similar to older APIs
  • Uses TRANSFER-queue on desktop to upload linear-allocated vertex/index/uniform data in bulk
  • Vulkan GLSL for shaders, shaders are compiled in runtime with shaderc
  • Pipeline cache save-to-disk and reload
  • Warm up internal hashmaps with Fossilize
  • Easier-to-use fences and semaphores

Missing bits:

  • Multithreaded rendering
  • Precompile all shaders to optimized SPIR-V

Implementation is found in vulkan/.

High-level rendering backend

A basic scene graph, component system and other higher-level scaffolding lives in renderer/. This is probably the most unoptimized and naive part.

PBR renderer

Pretty barebones, half-assed PBR renderer. Very simplified IBL support. Fancy rendering is not the real motivation behind this project.

Post-AA

Fairly straight forward FXAA, SMAA and TAA (no true velocity buffer though).

Automatic shader recompile and texture reload (Linux/Android only)

Immediately when shaders are modified or textures are changed, the resources are automatically reloaded. The implementation uses inotify to do this, so it's exclusive to Linux unless a backend is implemented on Windows (no).

Network VFS

For Linux host and Android device, assets and shaders can be pulled over TCP (via ADB port-forwarding) with network/netfs_server.cpp. Quite convenient.

Validation

In debug build, LunarG validation layers are enabled. Granite is squeaky clean.

Render graph

renderer/render_graph.hpp and renderer/render_graph.cpp contains a fairly complete render graph. It supports:

  • Automatic layout transitions
  • Automatic loadOp/storeOp usage
  • Automatic scaled loadOp for simple lower-res game -> high-res UI rendering scenarios
  • Uses async compute queues automatically
  • Optimal barrier placement, signals as early as possible, waits as late as possible VkEvent is used for in-queue resources, VkSemaphore for cross-queue resources
  • Basic render target aliasing
  • Can merge two or more passes into multiple subpasses for efficient rendering on tile-based architectures
  • Automatic mip-mapping if requested
  • Uses transient attachments automatically to save memory on tile-based architectures
  • Render target history, read previous frame's results in next frame for feedback
  • Conditional render passes, can preserve render passes if necessary
  • Render passes are reordered for optimal (?) overlap in execution
  • Automatic, optimal multisampled resolve with pResolveAttachments

I have written up a longer blog post about its implementation here.

The default application scene renderer in application/application.cpp sets up a render graph which does:

  • Conditionally renders a shadow map covering entire scene
  • Renders a close shadow map
  • Automatically pulls in reflection/refraction render passes if present in the scene graph
  • Renders scene G-Buffer with deferred
  • Lighting pass (merged with G-Buffer pass into a single render pass)
  • Bloom threshold pass
  • Bloom pyramid downsampling
  • Async compute is kicked off to get average luminance of scene, adjusts exposure
  • Two upsampling steps to complete blurring in parallel with async
  • Tonemap (HDR + Bloom) rendered to backbuffer (sRGB)
  • (Potentially UI can be rendered on top with merged subpasses)

Scene format

glTF 2.0 with PBR materials is mostly supported. A custom JSON format is also added in order to plug multiple glTF files together for rapid prototyping of test scenes.

Texture formats

  • PNG, JPG, TGA, HDR (via stb)
  • GTX (Granite Texture Format, custom texture format for compressed formats)

ASTC, ETC2 and BCn/DXTn compressed formats are supported.

gltf-repacker

There's a tool to repack glTF models. Textures can be compressed to ASTC or BC using ISPC Texture Compressor. zeux's meshoptimizer library can also optimize meshes. The glTF emitted uses some Granite specific extras to be more optimal, so it's mostly for internal use.

Compilers

Tested on GCC, Clang, and MSVC 2017.

Platforms

  • GLFW (Linux / Windows)
  • VK_KHR_display (headless Linux w/ basic keyboard, mouse, gamepad support)
  • libretro Vulkan HW interface
  • Headless (benchmarking)
  • Custom surface plugin
  • Android

Vulkan implementations tested

  • AMD Linux (Mesa, AMDVLK)
  • Intel Linux (Mesa)
  • AMD Windows
  • nVidia Linux
  • Arm Mali (Galaxy S7/S8/S9)
  • Pixel C tablet (Tegra X1)

Build

Plain CMake. Remember to check out submodules with git submodule update --init.

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
ninja -j16 # YMMV :3

For MSVC, it should work to use the appropriate -G flag. There aren't any real samples yet, so not much to do unless you use Granite as a submodule.

viewer/gltf-viewer is a basic glTF viewer used as my sandbox for more complex testing. Try some models from glTF-Sample-Models.

Android

Something ala:

cd viewer
gradle build

Assets used in the default gltf-viewer target are pulled from viewer/assets.

Third party software

These are pulled in as submodules.

More Repositories

1

libfmsynth

A C library which implements an FM synthesizer
C
327
star
2

GLFFT

A C++11/OpenGL library for the Fast Fourier Transform
C
207
star
3

muFFT

A library for computing the Fast Fourier Transform (FFT) in one or two dimensions.
C
154
star
4

parallel-rdp

A low-level Vulkan compute emulation of the N64 RDP
C++
141
star
5

Emulator-Shader-Pack

Various pixel shaders in Cg for oldschool emulators
87
star
6

RetroWarp

A Vulkan compute shader implementation of a fictional retro GPU
C++
52
star
7

MIPS-LLVM-Jitter

A simple MIPS to LLVM IR recompiler with ahead-of-time recompilation support
C++
42
star
8

slang-shaders

C
41
star
9

Dinothawr

Dinothawr is a block pushing puzzle game on slippery surfaces. Our hero is a dinosaur whose friends are trapped in ice. Through puzzles it is your task to free the dinos from their ice prison.
C
40
star
10

libmaru

USB audio class driver in userspace using libusb.
C
37
star
11

Fossilize

This repository is discontinued, see https://github.com/ValveSoftware/Fossilize
C
34
star
12

simple-irc-bot

A simple IRC bot. Hackable.
C
32
star
13

RSound

A multi-platform, simple PCM audio server and client.
C
30
star
14

RetroArch-Phoenix

Simple GUI frontend for RetroArch using Phoenix
C++
28
star
15

boxes

OpenGL 4.3 experiment with compute shaders and tons of instanced geometry! Targets libretro GL.
C
25
star
16

Granite-MicroSamples

Micro-samples for Granite to read along with my blog post: http://themaister.net/blog/2019/04/14/a-tour-of-granites-vulkan-backend-part-1/
C++
19
star
17

parallel-rdp-standalone

A standalone, distilled codebase of parallel-rdp. Autogenerated.
C++
17
star
18

alsa-plugins-rsound

RSound plugin for ALSA
C
16
star
19

SimpleGL

NIH library for OpenGL window/context creation for X11/Win32/OSX.
C
11
star
20

ToneFilterVST

Basic recreation of the Nier Automata tone filter in VST form
C++
10
star
21

SLIMPlayer

Simple and Lightweight Media Player (using FFmpeg)
C++
9
star
22

pyrofling

PyroFling is a simple solution for capturing Vulkan applications and broadcast video and audio to streaming platforms using FFmpeg.
C++
8
star
23

SFC-Pong

A very newbish Pong game for Super Nintendo.
Assembly
5
star
24

airsynth

Multi-instrument polyphonic synthesizer for LV2 with a standalone JACK implementation.
C++
5
star
25

bsnes-Qt

Fork of BSNES/QT (v073)
C++
4
star
26

MIPS-Toolchain-PKGBUILD

A set of PKGBUILDs to build a MIPS (big-endian) toolchain
Shell
4
star
27

SC-MIPS

Simple, single cycle MIPS implementation in VHDL. Extended to support most instructions.
VHDL
4
star
28

libretro-ffmpeg

Video player implemented in libretro.
C++
2
star
29

XMLShaderView

View XML shaders in your browser!
JavaScript
2
star
30

parallel-psx-dump-replayer

Standalone tool to replay dumps from Parallel PSX
C++
2
star
31

alsa-reroute

Small script/preloaded lib that intercepts calls to ALSA and force them to open different devices.
C
2
star
32

Quickbuild

Simplistic build system written in sh to help with configuring building from source.
Shell
2
star
33

blipper

Band-limited decimator for emulators.
C
2
star
34

umusd

Microscopic music player controlled over TCP.
C++
2
star
35

Scale

Small and simple image scaler.
C
2
star
36

DirectRSound

Reimplement a subset of DirectSound with RSound.
C++
2
star
37

RetroArch-DSP-plugins

Audio DSP plugins for RetroArch.
C++
2
star
38

sussybard

Simple app which converts MIDI key inputs to X key presses, designed for playing FF XIV Bard
C++
2
star
39

SSNES-core

Futile attempt to create a SNES emulator :)
C
2
star
40

SC-MIPS-Chain

Simple toolchain for SC-MIPS
C
2
star
41

GLModelViewer

Simple modelviewer in OpenGL 3.0+
C
2
star
42

stile

Simple picture converter to SNES-format tilemap/tileset palette and stuff.
C++
1
star
43

midiviz

Crappy ad-hoc MIDI visualizer
C
1
star
44

iceypuzzle

Some simple engine for doing sliding puzzles, or something... :')
C++
1
star
45

RetroArch-D3D9

D3D9 external driver plugin for RetroArch.
C++
1
star
46

libretro-remotejoy

RemoteJoy client side code rewritten for libretro.
C
1
star
47

rtorrent-nogui

Attempts to run rtorrent as a pure daemon without GUI.
C++
1
star