-
Notifications
You must be signed in to change notification settings - Fork 13
Vulkan
- Initialize Vulkan
- Create a Vulkan Instance and a Surface
- Create a Vulkan Surface from an existing Instance
- Vulkan Usage
- Memory Allocator
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 existing instance can optionally be passed to the fplSettings structure if needed.
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.
settings;
(&settings);
// Reference of the video settings
*videoSettings = &settings.;
// Forcing the video backend to Vulkan
videoSettings-> = ;
// Reference of the vulkan settings for later usage
*vulkanSettings = &videoSettings..; *vulkanSettings = &videoSettings..;
vulkanSettings-> = "The name of your application";
vulkanSettings-> = (, "1.0.0", "1", "0", "0"); // Version of your application
vulkanSettings-> = "The name of your engine";
vulkanSettings-> = (, "1.0.0", "1", "0", "0"); // Version of your engine
vulkanSettings-> = (, "1.1.0", "1", "1", "0"); // Preferred Vulkan API version (should be greater or equal than 1.1.0)static void VulkanValidationLayerCallback(void *userData, const char *message, const VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, const VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *debugUtilsMessengerCallbackData) {
("Vulkan Validation: %s\n", message);
}
*vulkanSettings = &videoSettings..;
vulkanSettings-> = ; // Do not use the Vulkan Validation Layer as an instance extension
// or
vulkanSettings-> = fplVulkanValidationLayerMode_Logging; // Enable Vulkan Validation Layer as an instance extension and log everything to FPL directly, using the FPL logging system
// or
vulkanSettings-> = fplVulkanValidationLayerMode_User; // Enable Vulkan Validation Layer as an instance extension and let the user handle the logging
vulkanSettings-> = VulkanValidationLayerCallback; // The user callback
vulkanSettings-> = (void *)YourUserData; // The user data passed to the callbackContinue with Vulkan Usage
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;
*vulkanSettings = &videoSettings..;
vulkanSettings->instance = yourVulkanInstance; // Pass in your vulkan instance to FPL
if ((, &settings)) {
// ... Vulkan Surface is created now and ready to use
}Continue with Vulkan Usage
After you have created a Vulkan Instance and a Surface, you can query it by calling fplGetVideoSurface() directly after fplPlatformInit():
if ((, &settings)) {
// Get video surface
const *surface = ();
(surface != );
// Get the VkInstance and VkSurfaceKHR
VkInstance instanceHandle = (VkInstance)surface->.instanceHandle;
VkSurfaceKHR surfaceHandle = (VkSurfaceKHR)surface->vulkan.surfaceKHR;
(instanceHandle != VK_NULL_HANDLE);
(surfaceHandle != VK_NULL_HANDLE);
// ... continue the Vulkan initialization process
}After that, the typical Vulkan process continues:
- Finding the physical device (VkPhysicalDevice)
- Creating a logical device (VkDevice)
- Find the right queue families, surface formats, frame buffer formats, etc.
- Creating a VkSwapChainKHR with VkImageView, etc.
- Creating the full pipeline with VkCommandPool, VkCommandBuffer, etc.
See the FPL_Vulkan demo for more details or learn more about Vulkan: Vulkan-Tutorials
If you have an existing memory allocator for Vulkan, you can pass that to FPL before calling fplPlatformInit():
VkAllocationCallbacks *yourMemoryAllocator;
*vulkanSettings = &videoSettings..;
vulkanSettings-> = (void *)yourMemoryAllocator; // Pass in your memory allocator- Assertion & Debug
- Atomic operations
- Audio functions
- Clipboard functions
- Console functions
- Constants
- Display/Monitor functions
- Dynamic library loading
- Error Handling
- Files/IO functions
- Function macros
- Hardware Infos
- Input types and functions
- Localization functions
- Logging
- Memory Macros
- Memory functions
- Operating system Infos
- Path functions
- Platform functions
- Session Infos
- Settings & Configurations
- Storage class identifiers
- String functions
- Threading and synchronizations routines
- Timing functions
- Video functions
- Window events
- Window functions
- fplARMCPUCapabilities
- fplAudioChannelMap
- fplAudioDeviceID
- fplAudioDeviceInfo
- fplAudioFormat
- fplAudioSettings
- fplColor32
- fplConditionVariable
- fplConsoleSettings
- fplCPUCapabilities
- fplCPUIDLeaf
- fplDateTime
- fplDateTimeCreationResult
- fplDateTimeResult
- fplDisplayInfo
- fplDisplayMode
- fplDynamicLibraryHandle
- fplEndianess
- fplEvent
- fplFileEntry
- fplFileHandle
- fplFilePermissions
- fplFileTimeStamps
- fplGamepadButton
- fplGamepadData
- fplGamepadEvent
- fplGamepadInfo
- fplGamepadInputBinding
- fplGamepadMapping
- fplGamepadSettings
- fplGamepadState
- fplGamepadStates
- fplGraphicsApiSettings
- fplImageSource
- fplInputBackendMask
- fplInputBackendSupport
- fplInputDevice
- fplInputDeviceGuid
- fplInputSettings
- fplInternalConditionVariable
- fplInternalDynamicLibraryHandle
- fplInternalFileEntryHandle
- fplInternalFileHandle
- fplInternalFileRootInfo
- fplInternalMutexHandle
- fplInternalSemaphoreHandle
- fplInternalSignalHandle
- fplInternalThreadHandle
- fplKeyboardEvent
- fplKeyboardState
- fplLogSettings
- fplLogWriter
- fplLogWriterConsole
- fplLogWriterCustom
- fplMemoryAllocationSettings
- fplMemoryBlock
- fplMemoryInfos
- fplMemorySettings
- fplMouseEvent
- fplMouseState
- fplMutexHandle
- fplOpenGLSettings
- fplOSVersionInfos
- fplSemaphoreHandle
- fplSettings
- fplSignalHandle
- fplSpecificAudioSettings
- fplThreadHandle
- fplThreadParameters
- fplTimestamp
- fplVersionInfo
- fplVideoBackBuffer
- fplVideoRect
- fplVideoRequirements
- fplVideoRequirementsVulkan
- fplVideoSettings
- fplVideoSurface
- fplVideoSurfaceOpenGL
- fplVideoSurfaceVulkan
- fplVideoWindow
- fplVulkanSettings
- fplWindowCallbacks
- fplWindowDropFiles
- fplWindowEvent
- fplWindowPosition
- fplWindowSettings
- fplWindowSize
- fplX86CPUCapabilities