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);
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:816
virtual std::optional< Error > onRenderSettingsChangedDerived() override
Definition: VulkanRenderer.cpp:3989
virtual void executeComputeShadersOnGraphicsQueue(FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, ComputeExecutionStage stage) override
Definition: VulkanRenderer.cpp:3500
VkInstance getInstance() const
Definition: VulkanRenderer.cpp:2760
VkRenderPass pShadowMappingPointRenderPass
Definition: VulkanRenderer.h:990
VkSampler getTextureSampler()
Definition: VulkanRenderer.cpp:2680
std::optional< Error > createSwapChain()
Definition: VulkanRenderer.cpp:1214
std::variant< VulkanRenderer::QueueFamilyIndices, Error > queryQueueFamilyIndices(VkPhysicalDevice pGpu)
Definition: VulkanRenderer.cpp:761
std::optional< Error > createComputeTextureSampler()
Definition: VulkanRenderer.cpp:2018
virtual void present(FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex) override
Definition: VulkanRenderer.cpp:3602
std::optional< Error > createSwapChainFramebuffers()
Definition: VulkanRenderer.cpp:2316
static constexpr size_t iMainRenderPassColorAttachmentIndex
Definition: VulkanRenderer.h:1105
virtual void drawShadowMappingPass(FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, GraphicsPipelineRegistry *pGraphicsPipelines) override
Definition: VulkanRenderer.cpp:3000
static constexpr VkFormat getShadowMappingPointLightColorTargetFormat()
Definition: VulkanRenderer.h:61
VkRenderPass getDepthOnlyRenderPass() const
Definition: VulkanRenderer.cpp:2764
VkRenderPass getShadowMappingRenderPass(bool bIsForPointLights) const
Definition: VulkanRenderer.cpp:2766
void destroySwapChainAndDependentResources(bool bDestroyPipelineManager)
Definition: VulkanRenderer.cpp:1871
bool bIsVulkanInitialized
Definition: VulkanRenderer.h:1090
bool bNeedToRecreateSwapchain
Definition: VulkanRenderer.h:1096
virtual GpuResource * getDepthTextureNoMultisampling() override
Definition: VulkanRenderer.cpp:2785
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:892
static constexpr VkFormat getShadowMapFormat()
Definition: VulkanRenderer.h:53
std::optional< Error > createShadowMappingRenderPasses()
Definition: VulkanRenderer.cpp:1743
VkRenderPass getMainRenderPass() const
Definition: VulkanRenderer.cpp:2762
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:2886
std::unique_ptr< VulkanResource > pDepthImage
Definition: VulkanRenderer.h:965
virtual void waitForGpuToFinishWorkUpToThisPoint() override
Definition: VulkanRenderer.cpp:2709
std::optional< Error > createDepthImage()
Definition: VulkanRenderer.cpp:2138
std::optional< Error > initialize(const std::vector< std::string > &vBlacklistedGpuNames)
Definition: VulkanRenderer.cpp:203
VkSampleCountFlagBits getMsaaSampleCount() const
Definition: VulkanRenderer.cpp:2783
std::optional< Error > initializeVulkan(const std::vector< std::string > &vBlacklistedGpuNames)
Definition: VulkanRenderer.cpp:224
size_t rateGpuSuitability(VkPhysicalDevice pGpuDevice)
Definition: VulkanRenderer.cpp:494
std::variant< SwapChainSupportDetails, Error > querySwapChainSupportDetails(VkPhysicalDevice pGpu)
Definition: VulkanRenderer.cpp:690
static constexpr auto swapChainImageColorSpace
Definition: VulkanRenderer.h:1123
VkDevice pLogicalDevice
Definition: VulkanRenderer.h:953
VkCommandPool getCommandPool() const
Definition: VulkanRenderer.cpp:2773
bool bIsBeingDestroyed
Definition: VulkanRenderer.h:1102
void startDepthOnlyRenderPass(VkCommandBuffer pCommandBuffer, size_t iAcquiredImageIndex)
Definition: VulkanRenderer.cpp:2606
virtual std::variant< AntialiasingQuality, Error > getMaxSupportedAntialiasingQuality() const override
Definition: VulkanRenderer.cpp:97
bool isUsedDepthImageFormatSupported()
Definition: VulkanRenderer.cpp:2123
std::unique_ptr< VulkanResource > pMsaaImage
Definition: VulkanRenderer.h:978
VkQueue pPresentQueue
Definition: VulkanRenderer.h:959
std::optional< Error > createWindowSurface()
Definition: VulkanRenderer.cpp:466
static constexpr auto depthImageTiling
Definition: VulkanRenderer.h:1137
VkSampler pComputeTextureSampler
Definition: VulkanRenderer.h:1003
std::optional< Error > submitWaitDestroyOneTimeSubmitCommandBuffer(VkCommandBuffer pOneTimeSubmitCommandBuffer)
Definition: VulkanRenderer.cpp:2836
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:2707
VkDevice getLogicalDevice() const
Definition: VulkanRenderer.cpp:2756
virtual std::vector< std::string > getSupportedGpuNames() const override
Definition: VulkanRenderer.cpp:2682
VkRenderPass pShadowMappingDirectionalSpotRenderPass
Definition: VulkanRenderer.h:987
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > getSupportedRenderResolutions() const override
Definition: VulkanRenderer.cpp:2685
std::variant< VkCommandBuffer, Error > createOneTimeSubmitCommandBuffer()
Definition: VulkanRenderer.cpp:2798
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:3941
static std::variant< std::unique_ptr< Renderer >, std::pair< Error, std::string > > create(GameManager *pGameManager, const std::vector< std::string > &vBlacklistedGpuNames)
Definition: VulkanRenderer.cpp:2665
std::optional< Error > createTextureSampler()
Definition: VulkanRenderer.cpp:1934
static void setObjectDebugOnlyName(Renderer *pRenderer, void *pObject, VkObjectType objectType, const std::string &sResourceName)
Definition: VulkanRenderer.cpp:3304
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:2695
std::variant< std::string, Error > isDeviceSuitable(VkPhysicalDevice pGpu)
Definition: VulkanRenderer.cpp:550
VkSampler getComputeTextureSampler() const
Definition: VulkanRenderer.cpp:2777
static constexpr VkFormat getDepthImageFormat()
Definition: VulkanRenderer.h:46
QueueFamilyIndices physicalDeviceQueueFamilyIndices
Definition: VulkanRenderer.h:1075
virtual RendererType getType() const override
Definition: VulkanRenderer.cpp:2700
std::optional< Error > updateMsaaSampleCount()
Definition: VulkanRenderer.cpp:3883
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:367
virtual void drawMeshesDepthPrepass(FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vOpaquePipelines) override
Definition: VulkanRenderer.cpp:3358
VkSampleCountFlagBits msaaSampleCount
Definition: VulkanRenderer.h:1081
std::optional< Error > createMsaaImage()
Definition: VulkanRenderer.cpp:2197
VkPhysicalDevice getPhysicalDevice() const
Definition: VulkanRenderer.cpp:2758
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:3567
std::vector< VkFramebuffer > vSwapChainFramebuffersDepthOnlyRenderPass
Definition: VulkanRenderer.h:1046
std::optional< Error > recreateSwapChainAndDependentResources()
Definition: VulkanRenderer.cpp:2241
std::optional< Error > createRenderPasses(bool bIsRendererInitialization)
Definition: VulkanRenderer.cpp:1452
static std::variant< std::string, Error > isGpuSupportsUsedDeviceExtensions(VkPhysicalDevice pGpuDevice)
Definition: VulkanRenderer.cpp:4067
virtual bool isInitialized() const override
Definition: VulkanRenderer.cpp:4038
VkQueue getGraphicsQueue() const
Definition: VulkanRenderer.cpp:2775
static constexpr auto stencilResolveMode
Definition: VulkanRenderer.h:1146
void startMainRenderPass(VkCommandBuffer pCommandBuffer, size_t iAcquiredImageIndex)
Definition: VulkanRenderer.cpp:2575
std::optional< Error > createLogicalDevice()
Definition: VulkanRenderer.cpp:1126
std::optional< Error > createMainRenderPass()
Definition: VulkanRenderer.cpp:1482
std::string sUsedGpuName
Definition: VulkanRenderer.h:1072
virtual void onFramebufferSizeChangedDerived(int iWidth, int iHeight) override
Definition: VulkanRenderer.cpp:3858
std::variant< VkExtent2D, Error > pickSwapChainExtent(const VkSurfaceCapabilitiesKHR &surfaceCapabilities)
Definition: VulkanRenderer.cpp:1417
VkSwapchainKHR pSwapChain
Definition: VulkanRenderer.h:962
std::optional< VkExtent2D > getSwapChainExtent() const
Definition: VulkanRenderer.cpp:2781
static uint32_t getUsedVulkanVersion()
Definition: VulkanRenderer.cpp:201
std::vector< VkImage > vSwapChainImages
Definition: VulkanRenderer.h:1025
static std::variant< std::vector< const char * >, Error > getRequiredVulkanInstanceExtensions()
Definition: VulkanRenderer.cpp:4040
size_t iCurrentImageSemaphore
Definition: VulkanRenderer.h:1066
virtual std::string getUsedApiVersion() const override
Definition: VulkanRenderer.cpp:2702
static void startShadowMappingRenderPass(VkRenderPass pShadowMappingRenderPass, VkCommandBuffer pCommandBuffer, VkFramebuffer pFramebufferToUse, uint32_t iShadowMapSize)
Definition: VulkanRenderer.cpp:2634
VkSurfaceKHR pWindowSurface
Definition: VulkanRenderer.h:947
std::optional< Error > createCommandPool()
Definition: VulkanRenderer.cpp:1400
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:2779
static constexpr auto swapChainImageFormat
Definition: VulkanRenderer.h:1120
std::optional< Error > createDepthOnlyRenderPass()
Definition: VulkanRenderer.cpp:1610
VkRenderPass pMainRenderPass
Definition: VulkanRenderer.h:984
virtual void prepareRenderTargetForNextFrame() override
Definition: VulkanRenderer.cpp:2465
virtual void prepareForDrawingNextFrame(CameraProperties *pCameraProperties, FrameResource *pCurrentFrameResource) override
Definition: VulkanRenderer.cpp:2487
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:3714
virtual void waitForGpuToFinishUsingFrameResource(FrameResource *pFrameResource) override
Definition: VulkanRenderer.cpp:4024
std::optional< Error > createShadowTextureSampler()
Definition: VulkanRenderer.cpp:2069
virtual std::pair< unsigned int, unsigned int > getRenderTargetSize() const override
Definition: VulkanRenderer.cpp:2993
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