Pages

Monday, December 10, 2018

Cross Platform Vulkan VR

The next round of progress has been committed. We've got window resizing and fullscreen support working on Windows, Linux *and* MacOS, and VR support working on Windows and Linux.

VR on MacOS is another story though. While OpenVR does work on Mac (only just), it appears that OpenVR and Vulkan is not currently supported, as one of the OpenVR function calls required to initialise appears to not be implemented on the Mac build of OpenVR. Fortunately it seems Valve is working on it, or at the very least this is not only one of the few issues that they have assigned to someone, they did it very quickly.

Meanwhile, while VR does work on Windows and Linux, it does not work well. This is no reflection on OpenVR or Vulkan, rather a reflection on my taking the absolute quickest method to get it working. There is currently flickering on my test setup where the OpenVR Vulkan Example has none. I believe this is because of the synchronisation method I'm using, vkQueueWaitIdle() is possibly not the best method available, which comes as no surprise. I plan on smoothing out a lot of the wrinkles in its design before taking on that issue though. Having got this far, I've developed a quite good picture in my head of how all the pieces of Vulkan fit together, and plan to make use of this in writing sane texture and mesh handling code, possibly even getting FontStash working on Vulkan, which will all be very useful in the next major phase of this project, the voxels.

The mesh in this image is the LPS Head - here seen with only the lambertian texture map (no bump map).

Monday, November 12, 2018

Cross-Platform Vulkan Mesh Render Example in C


I feel I should take some time out to briefly talk about the current state of my Vulkan stuff.
The specific commit I'm talking about is this one.

This is the most simple cross platform Vulkan mesh rendering example, that is written in C, that I'm aware of. Does it do everything correctly? Probably not. It can't even handle the window being resized. What it does do is contain 100% of the Vulkan code within a single file, while leaving the platform specific code to be the simplest possible example of each. It is also utterly painless to compile, not requiring any external SDK to be installed, it requires only the compiler for your platform.

The complete steps required to prepare the build environment are in the Readme file, which for Windows, is get a good version of MinGW-w64 (specifically 8.1.0-x86_64-posix-seh), on Linux is how to install the up to date Nvidia drivers (and the Vulkan driver, which is not included by default) and Clang, and on Mac it is naught more than "Install XCode". Why no Clang on Windows? Debugging 64bit binaries created with Clang on Windows is currently an "at your own risk" case, and in my experience as of a few weeks ago when I started this was "problematic" when using VSCode as my debugging interface. Given the standard of work of the Clang and VSCode people, I'm sure this will be a distant memory quite soon, if they haven't already taken care of it.

Being that it does load a Wavefront OBJ file, it has my old OBJ loading code in there, which while it works just fine for most simple models, does do some silly things with some of the more complicated models (I'm looking at you Powerplant). It is capable of loading the San Miguel scene, and some versions of the Sponza Atrium, as well as everything from the Stanford 3D Scan Respository. It's not the main focus of this, and here it's only contribution is that it does not add a cumbersome OBJ loading library (I'm looking at you absolutely everything ever). If you know of an OBJ loader written in C that is of Sean Barrett levels of awesome, I'd love to hear about it.

This is the last point of the project being "simple". From here I'm adding OpenVR support and all the other complexity that I usually roll with, starting with my usual window handling code. Maybe at some point in the future it will return to an example-like state of commenting, but from commits after this one will break things for a while.

Friday, September 28, 2018

Cross Platform Vulkan

With the release of MacOS 10.14 Mojave, Apple has deprecated not only its long suffering OpenGL implementation, but also OpenCL. As they were the original creator of OpenCL, I think it's safe to say it's as good as dead. That leaves Apple with no viable Graphics or Compute platform. Fortunately, The Brenwill Workshop open sourced their MoltenVK library, which acts as a very lean Vulkan layer that sits on top of Metal. After getting a very rudimentary single window with a shader example going on the 3 platforms I care about, being Windows, Linux and MacOS, I can say that not only does MoltenVK work, it is arguably the best library on the entire MacOS ecosystem. There are a few small gotchas, and I wish to detail them here.

Firstly, there are only three supported surface formats. This is because MoltenVK uses a CAMetalLayer for its rendering, and this only supports five formats, and two of them are just downright odd, so justifiably ignored. These translate into the following Vulkan surface formats...

VK_FORMAT_B8G8R8A8_UNORM
VK_FORMAT_B8G8R8A8_SRGB
VK_FORMAT_R16G16B16A16_SFLOAT


...which gives us plenty to work with. This should not be considered odd at all, the current Nvidia drivers on Linux, 396.54, as well as the current Nvidia Windows drivers, 411.70, only report the first two of those formats on the 750M I tested (the same MacBookPro I tested the Mac version on). It should be noted, that on Windows and Linux, Vulkan will initialise with other formats, where as on Mac it will crash with a...

*** Terminating app due to uncaught exception 'CAMetalLayerInvalid', reason: 'invalid pixel format 70'


The only other quirk I encountered was the order of operations. As the shader takes a single float in a uniform buffer, the exact location of the vkCmdCopyBuffer() call to update the uniform buffer caused the drawing to stop right after the clear command was issued, so I was left with a ClearColor coloured window, even though everything was reporting success. That was without the full Command Queue debugging options enabled, so I suspect that will complain if you have it enabled.

If you want to play with shaders on Vulkan, on either of the three platforms, the repository is here.