![]() |
FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
|
Vulkan context. More...
#include <C_context.hpp>
Classes | |
struct | GlobalTransform |
class | SubmitableCommandBuffer |
Public Types | |
enum class | SubmitTypes { DIRECT_WAIT_EXECUTION , INDIRECT_EXECUTION } |
Public Member Functions | |
Context (Surface const &surface) | |
Shortcut to initVulkan(surface) | |
Context (Context const &r)=delete | |
Context (Context &&r) noexcept=delete | |
Context & | operator= (Context const &r)=delete |
Context & | operator= (Context &&r) noexcept=delete |
void | destroy () |
SubmitableCommandBuffer | beginCommands (SubmitTypes type, CommandBuffer::RenderPassScopes wantedRenderPassScope, CommandBuffer::SupportedQueueTypes_t wantedQueue) const |
Begin commands. | |
bool | submitCommands (SubmitableCommandBuffer &&buffer) const |
Submit commands. | |
VkSemaphore | getIndirectSemaphore () const |
Retrieve the semaphore that is signaled when all indirect command buffers have finished executing. | |
void | submit () const |
Submit Context command buffers. | |
void | initVulkan (Surface const &surface) |
Initialize Vulkan. | |
void | initVulkanSurfaceless (Instance const &instance) |
void | waitIdle () |
Wait for the device to be idle. | |
Instance const & | getInstance () const |
Surface const & | getSurface () const |
LogicalDevice const & | getLogicalDevice () const |
PhysicalDevice const & | getPhysicalDevice () const |
VkCommandPool | getGraphicsCommandPool () const |
Retrieve a command pool for graphics commands. | |
void | allocateGraphicsCommandBuffers (VkCommandBufferLevel level, VkCommandBuffer commandBuffers[], uint32_t commandBufferCount) const |
Allocate graphics command buffers. | |
DescriptorPool const & | getMultiUseDescriptorPool () const |
Retrieve a "multi-usage" descriptor pool. | |
DescriptorSetLayout const & | getTextureLayout () const |
Retrieve a "texture" descriptor set layout. | |
DescriptorSetLayout const & | getTransformLayout () const |
Retrieve a "transform" descriptor set layout. | |
DescriptorPool const & | getTextureDescriptorPool () const |
Retrieve a "texture" descriptor pool. | |
DescriptorPool const & | getTransformDescriptorPool () const |
Retrieve a "transform" descriptor pool. | |
VmaAllocator | getAllocator () const |
Retrieve the VMA (Vulkan Memory Allocator) | |
void | pushGraphicsCommandBuffer (VkCommandBuffer commandBuffer) const |
Push a graphics command buffer to a list. | |
std::vector< VkCommandBuffer > const & | getGraphicsCommandBuffers () const |
Retrieve the list of submitable graphics command buffers. | |
void | clearGraphicsCommandBuffers () const |
Clear the list of submitable graphics command buffers. | |
void | startMainRenderTarget (RenderTarget &renderTarget) const |
RenderTarget * | getMainRenderTarget () const |
bool | isMainRenderTarget (RenderTarget const &renderTarget) const |
void | endMainRenderTarget (RenderTarget const &renderTarget) const |
GlobalTransform const & | getGlobalTransform () const |
fge::TransformUboData const * | getGlobalTransform (uint32_t index) const |
std::pair< uint32_t, fge::TransformUboData * > | requestGlobalTransform () const |
void | clearLayoutPipelineCache () const |
LayoutPipeline & | requestLayoutPipeline (Shader const *vertexShader, Shader const *geometryShader, Shader const *fragmentShader) const |
Retrieve a layout pipeline. | |
void | clearDescriptorLayoutCache () const |
std::vector< DescriptorSetLayout > const * | requestDescriptorLayout (Shader const *vertexShader, Shader const *geometryShader, Shader const *fragmentShader) const |
Retrieve a descriptor set layout. | |
std::vector< DescriptorSetLayout > const * | requestDescriptorLayout (Shader const *shader) const |
std::optional< DescriptorSet > | createDescriptorSet (std::string_view shaderName, uint32_t setIndex, uint32_t variableElements=0) const |
Helper to request a descriptor set. | |
Static Public Member Functions | |
static Instance | init (uint32_t sdlFlag, std::string_view applicationName, uint16_t versionMajor=1, uint16_t versionMinor=0, uint16_t versionPatch=0) |
Helper to init SDL, volk and create an Instance. | |
static void | initVolk () |
Initialize Volk (Vulkan loader) | |
static void | enumerateExtensions () |
Enumerate to standard output the available extensions. | |
static std::vector< std::string > | retrieveExtensions () |
Retrieve the available extensions. | |
Public Attributes | |
GarbageCollector | _garbageCollector |
Vulkan context.
This class is the main starting point for Vulkan usage.
|
strong |
|
explicit |
void fge::vulkan::Context::allocateGraphicsCommandBuffers | ( | VkCommandBufferLevel | level, |
VkCommandBuffer | commandBuffers[], | ||
uint32_t | commandBufferCount ) const |
Allocate graphics command buffers.
This is a shortcut for vkAllocateCommandBuffers with the graphics command pool.
level | The level of the command buffers (primary or secondary) |
commandBuffers | An array of VkCommandBuffer structures in which the resulting command buffer objects are returned |
commandBufferCount | The number of command buffers to allocate |
|
nodiscard |
Begin commands.
This return a command buffer that is ready to be used.
The DIRECT_WAIT_EXECUTION type is used to execute a command buffer directly, this implies create the buffer, submit the buffer, and waiting for the corresponding queue operations to be finished. This is not ideal for performance.
The INDIRECT_EXECUTION type will create a command buffer that will be submitted later and executed with a semaphore that is signaled after every command is done so this assures that every command are finished before graphics commands. This is ideal for performance like copying staging buffers to device local buffers.
On certain cases, a reusable command buffer is returned in order to optimize command buffer creation/destruction. Current case is when the command buffer is used outside a render scope and the graphics queue is wanted.
type | The submit type of the command buffer |
wantedRenderPassScope | The wanted render pass scope (for optimization purposes) |
wantedQueue | The wanted queue (for optimization purposes) |
void fge::vulkan::Context::clearGraphicsCommandBuffers | ( | ) | const |
Clear the list of submitable graphics command buffers.
|
nodiscard |
Helper to request a descriptor set.
This function will create a new descriptor set with the provided shader and set index. This will also select for you the correct descriptor pool to use.
shaderName | The name of the shader from the manager |
setIndex | The index of the wanted set in the shader (not the set number) |
variableElements | The number of elements in the descriptor set (for variable descriptor sets) |
|
static |
Enumerate to standard output the available extensions.
|
nodiscard |
Retrieve the VMA (Vulkan Memory Allocator)
|
nodiscard |
Retrieve the list of submitable graphics command buffers.
|
nodiscard |
Retrieve a command pool for graphics commands.
This command pool is used to create command buffers that will be used to submit commands to the graphics queue.
This command pool is created with the following flags: VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT
|
nodiscard |
Retrieve the semaphore that is signaled when all indirect command buffers have finished executing.
This can return VK_NULL_HANDLE if there is no command buffers to execute.
|
nodiscard |
Retrieve a "multi-usage" descriptor pool.
This pool was created with the following types: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER VK_DESCRIPTOR_TYPE_STORAGE_BUFFER VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
|
nodiscard |
Retrieve a "texture" descriptor pool.
This pool can only contain VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER type.
|
nodiscard |
Retrieve a "texture" descriptor set layout.
This layout is used with default provided shaders.
This layout was created with the following: binding: FGE_VULKAN_TEXTURE_BINDING type: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER stage: VK_SHADER_STAGE_FRAGMENT_BIT
|
nodiscard |
Retrieve a "transform" descriptor pool.
This pool can only contain VK_DESCRIPTOR_TYPE_STORAGE_BUFFER type.
|
nodiscard |
Retrieve a "transform" descriptor set layout.
This layout is used with default provided shaders.
This layout was created with the following: binding: FGE_VULKAN_TRANSFORM_BINDING type: VK_DESCRIPTOR_TYPE_STORAGE_BUFFER stage: VK_SHADER_STAGE_VERTEX_BIT
|
staticnodiscard |
Helper to init SDL, volk and create an Instance.
This function do that in order :
sdlFlag | SDL flag passed to SDL_Init() |
applicationName | The name of the application |
versionMajor | |
versionMinor | |
versionPatch |
|
static |
Initialize Volk (Vulkan loader)
void fge::vulkan::Context::initVulkan | ( | Surface const & | surface | ) |
Initialize Vulkan.
Once a surface is correctly created, this function must be called to initialize Vulkan. Automatically call SetActiveContext() when no error.
surface | A valid surface |
void fge::vulkan::Context::pushGraphicsCommandBuffer | ( | VkCommandBuffer | commandBuffer | ) | const |
Push a graphics command buffer to a list.
This is used to keep track of submitable command buffers that will be submitted to the graphics queue. This list must be cleared once the command buffers are submitted. Generally, this is done by a RenderScreen when the RenderScreen::display() method is called.
commandBuffer | The command buffer to push |
|
nodiscard |
Retrieve a descriptor set layout.
This function will create a new descriptor set layout if it doesn't exist. The descriptor set layout is created with the provided shader with reflection of the SPIR-V code to retrieve the descriptor set layouts.
vertexShader | The vertex shader, can be nullptr |
geometryShader | The geometry shader, can be nullptr |
fragmentShader | The fragment shader, can be nullptr |
|
nodiscard |
Retrieve a layout pipeline.
This function will create a new layout pipeline if it doesn't exist. The layout pipeline is created with the provided shaders with reflection of the SPIR-V code to retrieve the descriptor set layouts and push constant ranges.
vertexShader | The vertex shader, can be nullptr |
geometryShader | The geometry shader, can be nullptr |
fragmentShader | The fragment shader, can be nullptr |
|
staticnodiscard |
Retrieve the available extensions.
void fge::vulkan::Context::submit | ( | ) | const |
Submit Context command buffers.
Indirect CommandBuffers are submitted with a semaphore that is signaled when the all of them have finished executing.
The semaphore should be retrieved with getIndirectSemaphore() and you must wait for it to be signaled before rendering commands as this buffer generally contain some buffer transfer operations.
This also increment the internal current frame counter.
This is automatically called by a RenderScreen when the RenderScreen::display() method is called.
bool fge::vulkan::Context::submitCommands | ( | SubmitableCommandBuffer && | buffer | ) | const |
void fge::vulkan::Context::waitIdle | ( | ) |
Wait for the device to be idle.
This is generally called before any new commands submission. Also when the program is about to exit, this function must be called to make sure that all commands are finished.