17#ifndef _FGE_VULKAN_C_CONTEXT_HPP_INCLUDED
18#define _FGE_VULKAN_C_CONTEXT_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
22#include "FastEngine/vulkan/vulkanGlobal.hpp"
24#include <unordered_map>
27#include "FastEngine/vulkan/C_commandBuffer.hpp"
28#include "FastEngine/vulkan/C_descriptorPool.hpp"
29#include "FastEngine/vulkan/C_descriptorSetLayout.hpp"
30#include "FastEngine/vulkan/C_garbageCollector.hpp"
31#include "FastEngine/vulkan/C_graphicPipeline.hpp"
32#include "FastEngine/vulkan/C_instance.hpp"
33#include "FastEngine/vulkan/C_logicalDevice.hpp"
34#include "FastEngine/vulkan/C_physicalDevice.hpp"
35#include "FastEngine/vulkan/C_surface.hpp"
36#include "FastEngine/vulkan/C_textureImage.hpp"
37#include "FastEngine/vulkan/C_uniformBuffer.hpp"
41#define FGE_VULKAN_USE_STRICT_LAYOUT_BINDINGS_STAGE 0
43#define FGE_VULKAN_TEXTURE_BINDING 0
44#define FGE_VULKAN_TRANSFORM_BINDING 0
45#define FGE_MULTIUSE_POOL_MAX_COMBINED_IMAGE_SAMPLER FGE_SHADER_MAX_BINDING_VARIABLE_DESCRIPTOR_COUNT
47#define FGE_CONTEXT_OUTSIDE_RENDER_SCOPE_COMMAND_WAITSTAGE VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
49#define FGE_CONTEXT_GLOBALTRANSFORMS_COUNT_START 200
54struct TransformUboData;
74 DIRECT_WAIT_EXECUTION,
81 using CommandBuffer::CommandBuffer;
83 [[nodiscard]]
inline SubmitTypes getSubmitType()
const {
return g_submitType; }
86 inline void setSubmitType(
SubmitTypes type) { this->g_submitType = type; }
102 uint32_t _transformsCount;
152 CommandBuffer::RenderPassScopes wantedRenderPassScope,
153 CommandBuffer::SupportedQueueTypes_t wantedQueue)
const;
205 std::string_view applicationName,
206 uint16_t versionMajor = 1,
207 uint16_t versionMinor = 0,
208 uint16_t versionPatch = 0);
226 void initVulkanSurfaceless(
Instance const& instance);
249 [[nodiscard]]
Instance const& getInstance()
const;
250 [[nodiscard]]
Surface const& getSurface()
const;
277 VkCommandBuffer commandBuffers[],
278 uint32_t commandBufferCount)
const;
368 void startMainRenderTarget(
RenderTarget& renderTarget)
const;
369 [[nodiscard]]
RenderTarget* getMainRenderTarget()
const;
370 [[nodiscard]]
bool isMainRenderTarget(
RenderTarget const& renderTarget)
const;
371 void endMainRenderTarget(
RenderTarget const& renderTarget)
const;
375 [[nodiscard]] std::pair<uint32_t, fge::TransformUboData*> requestGlobalTransform()
const;
377 void clearLayoutPipelineCache()
const;
392 void clearDescriptorLayoutCache()
const;
406 Shader const* geometryShader,
407 Shader const* fragmentShader)
const;
408 [[nodiscard]] std::vector<DescriptorSetLayout>
const* requestDescriptorLayout(
Shader const* shader)
const;
421 [[nodiscard]] std::optional<DescriptorSet>
427 void createCommandPool();
428 void createMultiUseDescriptorPool();
429 void createTextureDescriptorPool();
430 void createTransformDescriptorPool();
431 void createSyncObjects();
435 struct ReusableCommandBuffer
437 constexpr ReusableCommandBuffer() =
default;
438 constexpr ReusableCommandBuffer(VkCommandBuffer commandBuffer,
bool isRecording) :
439 _commandBuffer(commandBuffer),
440 _isRecording(isRecording)
443 VkCommandBuffer _commandBuffer{VK_NULL_HANDLE};
444 bool _isRecording{
false};
447 PhysicalDevice g_physicalDevice;
448 LogicalDevice g_logicalDevice;
449 Surface
const* g_surface;
450 Instance
const* g_instance;
452 mutable std::unordered_map<LayoutPipeline::Key,
453 std::vector<DescriptorSetLayout>,
454 LayoutPipeline::Key::Hash,
455 LayoutPipeline::Key::Compare>
456 g_cacheDescriptorLayouts;
458 unordered_map<LayoutPipeline::Key, LayoutPipeline, LayoutPipeline::Key::Hash, LayoutPipeline::Key::Compare>
459 g_cachePipelineLayouts;
460 DescriptorPool g_multiUseDescriptorPool;
462 DescriptorSetLayout g_textureLayout;
463 DescriptorSetLayout g_transformLayout;
464 DescriptorPool g_textureDescriptorPool;
465 DescriptorPool g_transformDescriptorPool;
467 mutable RenderTarget* g_mainRenderTarget;
469 mutable VmaAllocator g_allocator;
471 mutable uint32_t g_currentFrame;
473 mutable std::vector<VkCommandBuffer> g_graphicsSubmitableCommandBuffers;
475 std::array<VkSemaphore, FGE_MAX_FRAMES_IN_FLIGHT> g_indirectFinishedSemaphores{};
476 mutable std::array<std::vector<CommandBuffer>, FGE_MAX_FRAMES_IN_FLIGHT> g_indirectSubmitableCommandBuffers{};
477 mutable std::array<ReusableCommandBuffer, FGE_MAX_FRAMES_IN_FLIGHT>
478 g_indirectOutsideRenderScopeGraphicsSubmitableCommandBuffers{};
480 VkCommandPool g_graphicsCommandPool;
Definition C_renderTarget.hpp:56
Vulkan command buffer wrapper.
Definition C_commandBuffer.hpp:36
Definition C_context.hpp:79
Vulkan context.
Definition C_context.hpp:70
std::vector< VkCommandBuffer > const & getGraphicsCommandBuffers() const
Retrieve the list of submitable graphics command buffers.
DescriptorPool const & getMultiUseDescriptorPool() const
Retrieve a "multi-usage" descriptor pool.
SubmitTypes
Definition C_context.hpp:73
static void enumerateExtensions()
Enumerate to standard output the available extensions.
LayoutPipeline & requestLayoutPipeline(Shader const *vertexShader, Shader const *geometryShader, Shader const *fragmentShader) const
Retrieve a layout pipeline.
void waitIdle()
Wait for the device to be idle.
DescriptorPool const & getTransformDescriptorPool() const
Retrieve a "transform" descriptor pool.
std::vector< DescriptorSetLayout > const * requestDescriptorLayout(Shader const *vertexShader, Shader const *geometryShader, Shader const *fragmentShader) const
Retrieve a descriptor set layout.
void initVulkan(Surface const &surface)
Initialize Vulkan.
void pushGraphicsCommandBuffer(VkCommandBuffer commandBuffer) const
Push a graphics command buffer to a list.
static std::vector< std::string > retrieveExtensions()
Retrieve the available extensions.
Context(Surface const &surface)
Shortcut to initVulkan(surface)
DescriptorSetLayout const & getTextureLayout() const
Retrieve a "texture" descriptor set layout.
bool submitCommands(SubmitableCommandBuffer &&buffer) const
Submit commands.
static void initVolk()
Initialize Volk (Vulkan loader)
void clearGraphicsCommandBuffers() const
Clear the list of submitable graphics command buffers.
std::optional< DescriptorSet > createDescriptorSet(std::string_view shaderName, uint32_t setIndex, uint32_t variableElements=0) const
Helper to request a descriptor set.
void allocateGraphicsCommandBuffers(VkCommandBufferLevel level, VkCommandBuffer commandBuffers[], uint32_t commandBufferCount) const
Allocate graphics command buffers.
void submit() const
Submit Context command buffers.
VmaAllocator getAllocator() const
Retrieve the VMA (Vulkan Memory Allocator)
VkCommandPool getGraphicsCommandPool() const
Retrieve a command pool for graphics commands.
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.
VkSemaphore getIndirectSemaphore() const
Retrieve the semaphore that is signaled when all indirect command buffers have finished executing.
SubmitableCommandBuffer beginCommands(SubmitTypes type, CommandBuffer::RenderPassScopes wantedRenderPassScope, CommandBuffer::SupportedQueueTypes_t wantedQueue) const
Begin commands.
DescriptorPool const & getTextureDescriptorPool() const
Retrieve a "texture" descriptor pool.
DescriptorSetLayout const & getTransformLayout() const
Retrieve a "transform" descriptor set layout.
This class abstract the vulkan descriptor pool for easier use.
Definition C_descriptorPool.hpp:41
This class abstract the vulkan descriptor set layout for easier use.
Definition C_descriptorSetLayout.hpp:38
This class abstract the vulkan descriptor set for easier use.
Definition C_descriptorSet.hpp:41
A garbage collector for Vulkan objects.
Definition C_garbageCollector.hpp:306
Vulkan instance abstraction.
Definition C_instance.hpp:39
Definition C_graphicPipeline.hpp:35
Logical device abstraction.
Definition C_logicalDevice.hpp:37
Vulkan physical device abstraction.
Definition C_physicalDevice.hpp:34
Definition C_shader.hpp:36
Vulkan surface abstraction.
Definition vulkan/C_surface.hpp:42
Definition C_context.hpp:94