7#include "render/Renderer.h"
8#include "render/general/resource/frame/FrameResourceManager.h"
9#include "render/vulkan/resource/VulkanResource.h"
10#include "material/Material.h"
13#include "vulkan/vulkan.h"
14#include "VulkanMemoryAllocator/include/vk_mem_alloc.h"
17 class CameraProperties;
19 struct VulkanFrameResource;
20 struct QueuedForExecutionComputeShaders;
21 class ComputeShaderInterface;
76 static std::variant<std::unique_ptr<Renderer>, std::pair<Error, std::string>>
90 Renderer* pRenderer,
void* pObject, VkObjectType objectType,
const std::string& sResourceName);
114 virtual std::variant<std::set<std::pair<unsigned int, unsigned int>>,
Error>
125 virtual std::variant<std::set<std::pair<unsigned int, unsigned int>>,
Error>
133 virtual RendererType
getType()
const override;
177 [[nodiscard]] std::optional<Error>
195 VkFormat imageFormat,
196 VkImageAspectFlags aspect,
199 VkImageLayout oldLayout,
200 VkImageLayout newLayout);
336 virtual std::variant<std::optional<AntialiasingQuality>,
Error>
454 static std::variant<std::string, Error>
468 VkRenderPass pShadowMappingRenderPass,
469 VkCommandBuffer pCommandBuffer,
470 VkFramebuffer pFramebufferToUse,
471 uint32_t iShadowMapSize);
480 [[nodiscard]]
static std::optional<Error> makeSureUsedValidationLayersSupported();
492 static VkResult createDebugUtilsMessengerEXT(
494 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
495 const VkAllocationCallbacks* pAllocator,
496 VkDebugUtilsMessengerEXT* pDebugMessenger);
505 static void destroyDebugUtilsMessengerEXT(
507 VkDebugUtilsMessengerEXT pDebugMessenger,
508 const VkAllocationCallbacks* pAllocator);
517 static PFN_vkCmdBeginDebugUtilsLabelEXT requestVkCmdBeginDebugUtilsLabelEXT(VkInstance
pInstance);
526 static PFN_vkCmdEndDebugUtilsLabelEXT requestVkCmdEndDebugUtilsLabelEXT(VkInstance
pInstance);
541 [[nodiscard]] std::optional<Error>
initialize(
const std::vector<std::string>& vBlacklistedGpuNames);
551 [[nodiscard]] std::optional<Error>
616 std::variant<VulkanRenderer::QueueFamilyIndices, Error>
645 [[nodiscard]] std::optional<Error>
682 std::variant<VkExtent2D, Error>
696 [[nodiscard]] std::optional<Error>
createRenderPasses(
bool bIsRendererInitialization);
856 size_t iCurrentFrameResourceIndex,
868 size_t iCurrentFrameResourceIndex,
869 const std::vector<Renderer::MeshesInFrustum::PipelineInFrustumInfo>& vOpaquePipelines)
override;
882 size_t iCurrentFrameResourceIndex,
883 ComputeExecutionStage stage)
override;
895 size_t iCurrentFrameResourceIndex,
896 const std::vector<Renderer::MeshesInFrustum::PipelineInFrustumInfo>& vOpaquePipelines,
897 const std::vector<Renderer::MeshesInFrustum::PipelineInFrustumInfo>& vTransparentPipelines)
917 const std::vector<Renderer::MeshesInFrustum::PipelineInFrustumInfo>& pipelinesOfSpecificType,
918 VkCommandBuffer pCommandBuffer,
919 size_t iCurrentFrameResourceIndex);
939 size_t iCurrentFrameResourceIndex,
940 std::unordered_map<
Pipeline*, std::unordered_set<ComputeShaderInterface*>>&
941 computePipelinesToSubmit);
1017 VkDebugUtilsMessengerEXT pValidationLayerDebugMessenger =
nullptr;
1153 VK_KHR_SWAPCHAIN_EXTENSION_NAME};
1161 static inline const std::vector<const char*> vUsedValidationLayerNames = {
1162 "VK_LAYER_KHRONOS_validation"};
Definition: CameraProperties.h:22
Definition: GameManager.h:34
Definition: GpuResource.h:16
Definition: Pipeline.h:20
Definition: Renderer.h:43
GameManager * pGameManager
Definition: Renderer.h:870
Definition: VulkanRenderer.h:26
std::vector< VkImageView > vSwapChainImageViews
Definition: VulkanRenderer.h:1032
std::variant< std::string, Error > isGpuSupportsSwapChain(VkPhysicalDevice pGpu)
Definition: VulkanRenderer.cpp:817
virtual std::optional< Error > onRenderSettingsChangedDerived() override
Definition: VulkanRenderer.cpp:4007
virtual void executeComputeShadersOnGraphicsQueue(FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, ComputeExecutionStage stage) override
Definition: VulkanRenderer.cpp:3514
VkInstance getInstance() const
Definition: VulkanRenderer.cpp:2774
VkRenderPass pShadowMappingPointRenderPass
Definition: VulkanRenderer.h:990
VkSampler getTextureSampler()
Definition: VulkanRenderer.cpp:2694
std::optional< Error > createSwapChain()
Definition: VulkanRenderer.cpp:1215
std::variant< VulkanRenderer::QueueFamilyIndices, Error > queryQueueFamilyIndices(VkPhysicalDevice pGpu)
Definition: VulkanRenderer.cpp:762
std::optional< Error > createComputeTextureSampler()
Definition: VulkanRenderer.cpp:2026
virtual void present(FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex) override
Definition: VulkanRenderer.cpp:3616
std::optional< Error > createSwapChainFramebuffers()
Definition: VulkanRenderer.cpp:2330
static constexpr size_t iMainRenderPassColorAttachmentIndex
Definition: VulkanRenderer.h:1105
virtual void drawShadowMappingPass(FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, GraphicsPipelineRegistry *pGraphicsPipelines) override
Definition: VulkanRenderer.cpp:3014
static constexpr VkFormat getShadowMappingPointLightColorTargetFormat()
Definition: VulkanRenderer.h:61
VkRenderPass getDepthOnlyRenderPass() const
Definition: VulkanRenderer.cpp:2778
VkRenderPass getShadowMappingRenderPass(bool bIsForPointLights) const
Definition: VulkanRenderer.cpp:2780
void destroySwapChainAndDependentResources(bool bDestroyPipelineManager)
Definition: VulkanRenderer.cpp:1879
bool bIsVulkanInitialized
Definition: VulkanRenderer.h:1090
bool bNeedToRecreateSwapchain
Definition: VulkanRenderer.h:1096
virtual GpuResource * getDepthTextureNoMultisampling() override
Definition: VulkanRenderer.cpp:2799
VkCommandPool pCommandPool
Definition: VulkanRenderer.h:993
static constexpr auto depthImageFormat
Definition: VulkanRenderer.h:1126
std::optional< VkExtent2D > swapChainExtent
Definition: VulkanRenderer.h:1078
std::optional< Error > pickPhysicalDevice(const std::vector< std::string > &vBlacklistedGpuNames)
Definition: VulkanRenderer.cpp:893
static constexpr VkFormat getShadowMapFormat()
Definition: VulkanRenderer.h:53
std::optional< Error > createShadowMappingRenderPasses()
Definition: VulkanRenderer.cpp:1751
VkRenderPass getMainRenderPass() const
Definition: VulkanRenderer.cpp:2776
uint32_t iSwapChainImageCount
Definition: VulkanRenderer.h:1084
std::optional< Error > transitionImageLayout(VkImage pImage, VkFormat imageFormat, VkImageAspectFlags aspect, uint32_t levelCount, uint32_t layerCount, VkImageLayout oldLayout, VkImageLayout newLayout)
Definition: VulkanRenderer.cpp:2900
std::unique_ptr< VulkanResource > pDepthImage
Definition: VulkanRenderer.h:965
virtual void waitForGpuToFinishWorkUpToThisPoint() override
Definition: VulkanRenderer.cpp:2723
std::optional< Error > createDepthImage()
Definition: VulkanRenderer.cpp:2146
std::optional< Error > initialize(const std::vector< std::string > &vBlacklistedGpuNames)
Definition: VulkanRenderer.cpp:204
VkSampleCountFlagBits getMsaaSampleCount() const
Definition: VulkanRenderer.cpp:2797
std::optional< Error > initializeVulkan(const std::vector< std::string > &vBlacklistedGpuNames)
Definition: VulkanRenderer.cpp:225
size_t rateGpuSuitability(VkPhysicalDevice pGpuDevice)
Definition: VulkanRenderer.cpp:495
std::variant< SwapChainSupportDetails, Error > querySwapChainSupportDetails(VkPhysicalDevice pGpu)
Definition: VulkanRenderer.cpp:691
static constexpr auto swapChainImageColorSpace
Definition: VulkanRenderer.h:1123
VkDevice pLogicalDevice
Definition: VulkanRenderer.h:953
VkCommandPool getCommandPool() const
Definition: VulkanRenderer.cpp:2787
bool bIsBeingDestroyed
Definition: VulkanRenderer.h:1102
void startDepthOnlyRenderPass(VkCommandBuffer pCommandBuffer, size_t iAcquiredImageIndex)
Definition: VulkanRenderer.cpp:2620
bool isUsedDepthImageFormatSupported()
Definition: VulkanRenderer.cpp:2131
std::unique_ptr< VulkanResource > pMsaaImage
Definition: VulkanRenderer.h:978
VkQueue pPresentQueue
Definition: VulkanRenderer.h:959
std::optional< Error > createWindowSurface()
Definition: VulkanRenderer.cpp:467
static constexpr auto depthImageTiling
Definition: VulkanRenderer.h:1137
VkSampler pComputeTextureSampler
Definition: VulkanRenderer.h:1003
std::optional< Error > submitWaitDestroyOneTimeSubmitCommandBuffer(VkCommandBuffer pOneTimeSubmitCommandBuffer)
Definition: VulkanRenderer.cpp:2850
std::vector< std::string > vSupportedGpuNames
Definition: VulkanRenderer.h:1069
static constexpr auto depthResolveMode
Definition: VulkanRenderer.h:1143
virtual std::string getCurrentlyUsedGpuName() const override
Definition: VulkanRenderer.cpp:2721
VkDevice getLogicalDevice() const
Definition: VulkanRenderer.cpp:2770
virtual std::vector< std::string > getSupportedGpuNames() const override
Definition: VulkanRenderer.cpp:2696
VkRenderPass pShadowMappingDirectionalSpotRenderPass
Definition: VulkanRenderer.h:987
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > getSupportedRenderResolutions() const override
Definition: VulkanRenderer.cpp:2699
std::variant< VkCommandBuffer, Error > createOneTimeSubmitCommandBuffer()
Definition: VulkanRenderer.cpp:2812
std::unique_ptr< VulkanResource > pDepthImageNoMultisampling
Definition: VulkanRenderer.h:975
VkSampler pTextureSampler
Definition: VulkanRenderer.h:996
static bool dispatchComputeShadersOnGraphicsQueue(VulkanFrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, std::unordered_map< Pipeline *, std::unordered_set< ComputeShaderInterface * > > &computePipelinesToSubmit)
Definition: VulkanRenderer.cpp:3959
static std::variant< std::unique_ptr< Renderer >, std::pair< Error, std::string > > create(GameManager *pGameManager, const std::vector< std::string > &vBlacklistedGpuNames)
Definition: VulkanRenderer.cpp:2679
std::optional< Error > createTextureSampler()
Definition: VulkanRenderer.cpp:1942
static void setObjectDebugOnlyName(Renderer *pRenderer, void *pObject, VkObjectType objectType, const std::string &sResourceName)
Definition: VulkanRenderer.cpp:3318
bool bIsUsingMsaaRenderTarget
Definition: VulkanRenderer.h:1099
static constexpr size_t iDepthOnlyRenderPassDepthImageAttachmentIndex
Definition: VulkanRenderer.h:1114
static const std::vector< const char * > vUsedDeviceExtensionNames
Definition: VulkanRenderer.h:1152
uint32_t iLastAcquiredImageIndex
Definition: VulkanRenderer.h:1087
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > getSupportedRefreshRates() const override
Definition: VulkanRenderer.cpp:2709
std::variant< std::string, Error > isDeviceSuitable(VkPhysicalDevice pGpu)
Definition: VulkanRenderer.cpp:551
VkSampler getComputeTextureSampler() const
Definition: VulkanRenderer.cpp:2791
static constexpr VkFormat getDepthImageFormat()
Definition: VulkanRenderer.h:46
QueueFamilyIndices physicalDeviceQueueFamilyIndices
Definition: VulkanRenderer.h:1075
virtual RendererType getType() const override
Definition: VulkanRenderer.cpp:2714
std::optional< Error > updateMsaaSampleCount()
Definition: VulkanRenderer.cpp:3897
static constexpr auto shadowMappingPointLightColorTargetFormat
Definition: VulkanRenderer.h:1134
std::vector< SwapChainImageSemaphores > vImageSemaphores
Definition: VulkanRenderer.h:1063
static constexpr size_t iMainRenderPassDepthAttachmentIndex
Definition: VulkanRenderer.h:1108
static constexpr auto indexTypeFormat
Definition: VulkanRenderer.h:1140
std::optional< Error > createVulkanInstance()
Definition: VulkanRenderer.cpp:368
virtual void drawMeshesDepthPrepass(FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vOpaquePipelines) override
Definition: VulkanRenderer.cpp:3372
VkSampleCountFlagBits msaaSampleCount
Definition: VulkanRenderer.h:1081
std::optional< Error > createMsaaImage()
Definition: VulkanRenderer.cpp:2205
VkPhysicalDevice getPhysicalDevice() const
Definition: VulkanRenderer.cpp:2772
virtual std::variant< std::optional< AntialiasingQuality >, Error > getMaxSupportedAntialiasingQuality() const override
Definition: VulkanRenderer.cpp:98
static constexpr size_t iDepthOnlyRenderPassDepthResolveTargetAttachmentIndex
Definition: VulkanRenderer.h:1117
VkPhysicalDevice pPhysicalDevice
Definition: VulkanRenderer.h:950
virtual void drawMeshesMainPass(FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vOpaquePipelines, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vTransparentPipelines) override
Definition: VulkanRenderer.cpp:3581
std::vector< VkFramebuffer > vSwapChainFramebuffersDepthOnlyRenderPass
Definition: VulkanRenderer.h:1046
std::optional< Error > recreateSwapChainAndDependentResources()
Definition: VulkanRenderer.cpp:2249
std::optional< Error > createRenderPasses(bool bIsRendererInitialization)
Definition: VulkanRenderer.cpp:1460
static std::variant< std::string, Error > isGpuSupportsUsedDeviceExtensions(VkPhysicalDevice pGpuDevice)
Definition: VulkanRenderer.cpp:4085
virtual bool isInitialized() const override
Definition: VulkanRenderer.cpp:4056
VkQueue getGraphicsQueue() const
Definition: VulkanRenderer.cpp:2789
static constexpr auto stencilResolveMode
Definition: VulkanRenderer.h:1146
void startMainRenderPass(VkCommandBuffer pCommandBuffer, size_t iAcquiredImageIndex)
Definition: VulkanRenderer.cpp:2589
std::optional< Error > createLogicalDevice()
Definition: VulkanRenderer.cpp:1127
std::optional< Error > createMainRenderPass()
Definition: VulkanRenderer.cpp:1490
std::string sUsedGpuName
Definition: VulkanRenderer.h:1072
virtual void onFramebufferSizeChangedDerived(int iWidth, int iHeight) override
Definition: VulkanRenderer.cpp:3872
std::variant< VkExtent2D, Error > pickSwapChainExtent(const VkSurfaceCapabilitiesKHR &surfaceCapabilities)
Definition: VulkanRenderer.cpp:1425
VkSwapchainKHR pSwapChain
Definition: VulkanRenderer.h:962
std::optional< VkExtent2D > getSwapChainExtent() const
Definition: VulkanRenderer.cpp:2795
static uint32_t getUsedVulkanVersion()
Definition: VulkanRenderer.cpp:202
std::vector< VkImage > vSwapChainImages
Definition: VulkanRenderer.h:1025
static std::variant< std::vector< const char * >, Error > getRequiredVulkanInstanceExtensions()
Definition: VulkanRenderer.cpp:4058
size_t iCurrentImageSemaphore
Definition: VulkanRenderer.h:1066
virtual std::string getUsedApiVersion() const override
Definition: VulkanRenderer.cpp:2716
static void startShadowMappingRenderPass(VkRenderPass pShadowMappingRenderPass, VkCommandBuffer pCommandBuffer, VkFramebuffer pFramebufferToUse, uint32_t iShadowMapSize)
Definition: VulkanRenderer.cpp:2648
VkSurfaceKHR pWindowSurface
Definition: VulkanRenderer.h:947
std::optional< Error > createCommandPool()
Definition: VulkanRenderer.cpp:1408
static constexpr size_t iMainRenderPassColorResolveTargetAttachmentIndex
Definition: VulkanRenderer.h:1111
static constexpr auto shadowMapFormat
Definition: VulkanRenderer.h:1129
VkInstance pInstance
Definition: VulkanRenderer.h:944
VkSampler getShadowTextureSampler() const
Definition: VulkanRenderer.cpp:2793
static constexpr auto swapChainImageFormat
Definition: VulkanRenderer.h:1120
std::optional< Error > createDepthOnlyRenderPass()
Definition: VulkanRenderer.cpp:1618
VkRenderPass pMainRenderPass
Definition: VulkanRenderer.h:984
virtual void prepareRenderTargetForNextFrame() override
Definition: VulkanRenderer.cpp:2479
virtual void prepareForDrawingNextFrame(CameraProperties *pCameraProperties, FrameResource *pCurrentFrameResource) override
Definition: VulkanRenderer.cpp:2501
VkRenderPass pDepthOnlyRenderPass
Definition: VulkanRenderer.h:981
std::vector< std::pair< VkFence, size_t > > vSwapChainImageFenceRefs
Definition: VulkanRenderer.h:1056
static constexpr uint32_t iUsedVulkanVersion
Definition: VulkanRenderer.h:1149
std::vector< VkFramebuffer > vSwapChainFramebuffersMainRenderPass
Definition: VulkanRenderer.h:1039
VkQueue pGraphicsQueue
Definition: VulkanRenderer.h:956
void drawMeshesMainPassSpecificPipelines(const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &pipelinesOfSpecificType, VkCommandBuffer pCommandBuffer, size_t iCurrentFrameResourceIndex)
Definition: VulkanRenderer.cpp:3728
virtual void waitForGpuToFinishUsingFrameResource(FrameResource *pFrameResource) override
Definition: VulkanRenderer.cpp:4042
std::optional< Error > createShadowTextureSampler()
Definition: VulkanRenderer.cpp:2077
virtual std::pair< unsigned int, unsigned int > getRenderTargetSize() const override
Definition: VulkanRenderer.cpp:3007
VkSampler pShadowTextureSampler
Definition: VulkanRenderer.h:1010
Definition: FrameResource.h:15
Definition: PipelineRegistry.hpp:31
Definition: VulkanFrameResource.h:17
Definition: VulkanRenderer.h:393
std::optional< uint32_t > iPresentFamilyIndex
Definition: VulkanRenderer.h:412
bool isComplete() const
Definition: VulkanRenderer.h:401
std::optional< uint32_t > iGraphicsFamilyIndex
Definition: VulkanRenderer.h:406
Definition: VulkanRenderer.h:416
VkSemaphore pQueueSubmitSemaphore
Definition: VulkanRenderer.h:429
size_t iUsedFrameResourceIndex
Definition: VulkanRenderer.h:435
VkSemaphore pAcquireImageSemaphore
Definition: VulkanRenderer.h:422
Definition: VulkanRenderer.h:378
std::vector< VkPresentModeKHR > vSupportedPresentModes
Definition: VulkanRenderer.h:386
std::vector< VkSurfaceFormatKHR > vSupportedFormats
Definition: VulkanRenderer.h:383
VkSurfaceCapabilitiesKHR capabilities
Definition: VulkanRenderer.h:380