Final Platform Layer  0.9.6-beta

Initialize Vulkan

Initializing Vulkan is different than initializing other graphics APIs such as OpenGL, but FPL helps you in the first steps.

The very first thing you need is a Vulkan Instance (VkInstance).

Secondly you require a Vulkan Surface (VkSurfaceKHR) to present the graphical result to the screen.

FPL can create the Instance and the Surface for you.

The surface creation is mandatory, but an exiting instance can optionally be passed to the fplSettings structure if needed.

Create a Vulkan Instance and a Surface

First you have to create a fplSettings structure and initialize it with default settings using fplSetDefaultSettings().

Second you set the fplVideoSettings::backend to fplVideoBackendType_Vulkan .

We can reference the fplVulkanSettings type stored in fplGraphicsApiSettings::vulkan for convenience usage later.

fplSettings settings;
// Reference of the video settings
fplVideoSettings *videoSettings = &;
// Forcing the video backend to Vulkan
// Reference of the vulkan settings for later usage
fplVulkanSettings *vulkanSettings = &;

Fill in the application, engine and api versions

fplVulkanSettings *vulkanSettings = &;
vulkanSettings->appName = "The name of your application";
vulkanSettings->appVersion = fplStructInit(fplVersionInfo, "1.0.0", "1", "0", "0"); // Version of your application
vulkanSettings->engineName = "The name of your engine";
vulkanSettings->engineVersion = fplStructInit(fplVersionInfo, "1.0.0", "1", "0", "0"); // Version of your engine
vulkanSettings->apiVersion = fplStructInit(fplVersionInfo, "1.1.0", "1", "1", "0"); // Preferred Vulkan API version (should be greater or equal than 1.1.0)

Choose a Vulkan validation mode

static void VulkanValidationLayerCallback(void *userData, const char *message, const VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, const VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *debugUtilsMessengerCallbackData) {
fplConsoleFormatOut("Vulkan Validation: %s\n", message);
fplVulkanSettings *vulkanSettings = &;
vulkanSettings->validationLayerMode = fplVulkanValidationLayerMode_Disabled; // Do not use the Vulkan Validation Layer as an instance extension
// or
vulkanSettings->validationLayerMode = fplVulkanValidationLayerMode_Logging; // Enable Vulkan Validation Layer as an instance extension and log everything to FPL directly, using the FPL logging system
// or
vulkanSettings->validationLayerMode = fplVulkanValidationLayerMode_User; // Enable Vulkan Validation Layer as an instance extension and let the user handle the logging
vulkanSettings->validationLayerCallback = VulkanValidationLayerCallback; // The user callback
vulkanSettings->userData = (void *)YourUserData; // The user data passed to the callback

Continue with Vulkan Usage

Create a Vulkan Surface from an existing Instance

If you already have a Vulkan Instance (VkInstance), you can simply pass that to the fplVulkanSettings::instanceHandle field and initialize FPL with fplPlatformInit():

VkInstance yourVulkanInstance;
fplVulkanSettings *vulkanSettings = &;
vulkanSettings->instance = yourVulkanInstance; // Pass in your vulkan instance to FPL
// ... Vulkan Surface is created now and are ready to use

Continue with Vulkan Usage

Vulkan Usage

After you have created a Vulkan Instance and a Surface, you can query it by calling fplGetVideoSurface() directly after fplPlatformInit():

// Get video surface
const fplVideoSurface *surface = fplGetVideoSurface();
fplAssert(surface != fpl_null);
// Get the VkInstance and VkSurfaceKHR
VkInstance instanceHandle = (VkInstance)surface->vulkan.instanceHandle;
VkSurfaceKHR surfaceHandle = (VkSurfaceKHR)surface->vulkan.surfaceKHR;
fplAssert(instanceHandle != VK_NULL_HANDLE);
fplAssert(surfaceHandle != VK_NULL_HANDLE);
// ... continue the Vulkan initialization process

After that, the typical Vulkan process continues:

See the FPL_Vulkan demo for more details or learn more about Vulkan: Vulkan-Tutorials

Memory Allocator

If you have an existing memory allocator for Vulkan, you can pass that to FPL before calling fplPlatformInit():

VkAllocationCallbacks *yourMemoryAllocator;
fplVulkanSettings *vulkanSettings = &;
vulkanSettings->allocator = (void *)yourMemoryAllocator; // Pass in your memory allocator
fplVideoSurfaceVulkan vulkan
The Vulkan surface properties.
Definition: final_platform_layer.h:6543
fplVulkanSettings vulkan
Vulkan settings.
Definition: final_platform_layer.h:3554
Definition: final_platform_layer.h:3454
void * userData
User data passed to any callbacks.
Definition: final_platform_layer.h:3538
Stores the surface properties for the active video backend.
Definition: final_platform_layer.h:6537
const void * allocator
The vulkan allocator (VkAllocationCallbacks)
Definition: final_platform_layer.h:3534
Enable validations and use fplVulkanValidationLayerCallback to call back to to the user.
Definition: final_platform_layer.h:3500
const char * appName
The application name (Only required if fplVulkanSettings::instanceHandle is fpl_null)
Definition: final_platform_layer.h:3528
fplVulkanValidationLayerCallback * validationLayerCallback
The validation layer callback (Only used when fplVulkanSettings::validationLayerMode is set to fplVul...
Definition: final_platform_layer.h:3536
const fpl_common_api fplVideoSurface * fplGetVideoSurface()
Gets the current fplVideoSurface that stores all handles used for the active video backend.
A structure containing settings, such as window, video, etc.
Definition: final_platform_layer.h:3930
#define fplStructInit
Initializes a struct by the given type.
Definition: final_platform_layer.h:2212
fplVersionInfo engineVersion
The engine version (Only required if fplVulkanSettings::instanceHandle is fpl_null)
Definition: final_platform_layer.h:3524
fplVideoBackendType backend
video backend type
Definition: final_platform_layer.h:3565
const char * engineName
The engine name (Only required if fplVulkanSettings::instanceHandle is fpl_null)
Definition: final_platform_layer.h:3530
All init flags.
Definition: final_platform_layer.h:3390
A structure that contains Vulkan video settings.
Definition: final_platform_layer.h:3520
fpl_common_api bool fplPlatformInit(const fplInitFlags initFlags, const fplSettings *initSettings)
Initializes the platform layer.
#define fplAssert(exp)
Breaks with an runtime assertion, when the specified expression evaluates to false.
Definition: final_platform_layer.h:2081
fplGraphicsApiSettings graphics
Graphics API settings.
Definition: final_platform_layer.h:3563
Enable validations and print out validations to the FPL logging system.
Definition: final_platform_layer.h:3498
fplVulkanValidationLayerMode validationLayerMode
The fplVulkanValidationLayerMode.
Definition: final_platform_layer.h:3540
fplVideoSettings video
Video settings.
Definition: final_platform_layer.h:3934
void * surfaceKHR
The Vulkan Surface KHR (VkSurfaceKHR)
Definition: final_platform_layer.h:6489
Use a video backbuffer (This flag ensures that fplInitFlags_Window is included always)
Definition: final_platform_layer.h:3384
Do not use the validation.
Definition: final_platform_layer.h:3496
#define fpl_null
Definition: final_platform_layer.h:2166
fplVersionInfo apiVersion
The preferred Vulkan api version (Only required if fplVulkanSettings::instanceHandle is fpl_null)
Definition: final_platform_layer.h:3526
A structure that contains video settings such as backend, v-sync, API-settings, etc.
Definition: final_platform_layer.h:3561
fplVersionInfo appVersion
The application version (Only required if fplVulkanSettings::instanceHandle is fpl_null)
Definition: final_platform_layer.h:3522
A structure that contains version informations.
Definition: final_platform_layer.h:3178
fpl_common_api void fplConsoleFormatOut(const char *format,...)
Writes the given formatted text to the standard output console buffer.
fpl_common_api void fplSetDefaultSettings(fplSettings *settings)
Resets the given settings container to default values for window, video, audio, etc.