10#include <BS_tracy_thread_pool.hpp>
17#include <unordered_map>
19#include <vulkan/vulkan_core.h>
22# include <tracy/TracyVulkan.hpp>
267 void renderToXr(
size_t swapChainImageIndex,
float time );
274 uint32_t swapChainImageIndex,
275 VkSemaphore mirrorAcquireSemaphore = VK_NULL_HANDLE
479 void setupTracy(
const std::vector<TracyVkCtx> & tracyVulkanContext );
491 void resetTracyContexts();
543 std::vector<TracyVkCtx> tracyVkContext;
546 void destroyTracyContexts();
596 const std::string & meshShader,
597 const std::string & fragShader,
710 PFN_vkCmdBeginDebugUtilsLabelEXT vkCmdBeginDebugUtilsLabelEXT =
nullptr;
711 PFN_vkCmdEndDebugUtilsLabelEXT vkCmdEndDebugUtilsLabelEXT =
nullptr;
constexpr int MAX_FRAMES_IN_FLIGHT
The application context is the core class which stores the basic openxr and vulkan objects.
The compute pass stores all resources which belong to a compute pipeline.
The render process class consolidates all the resources that needs to be duplicated for each frame th...
std::optional< VulkanBuffer > meshUnpackingDataBuffer
DispatcherComputePass & getMeshletUnpackingDispatchComputePass()
void restartRenderCommandBuffers() const
Resets the command buffers of the active frame and begins a new write.
ComputePass & getMeshletUnpackingComputePass()
void createMeshletUnpackingResources()
std::vector< RenderProcess * > renderProcesses
The render processes.
std::optional< ComputePass > primitiveCulling
void createHiZMipDescriptorSets()
std::optional< ComputePass > primitiveBinning
std::optional< ComputePass > hiZGenerationComputePass
VkDependencyInfo getObjectCullingToMeshletUnpackingDispatchBarriers(Vulkan::BarrierBundle &bundle) const
ComputePass & getObjectCullingComputePass()
VkCommandPool getTransferCommandPool() const
gets the command pool used for recording data transfer at the beginning of a frame
int64_t getFrameElapsedMs() const
Gets the elapsed time since markFrameStart() was called. Used to check if the current frame has taken...
void updateHiZSPDDescriptorSets(uint32_t frameIndex)
std::optional< ComputePass > vsPrepareDrawComputePass_
Headset * getHeadset() const
Gets the headset pointer.
VkPipelineLayout vsPipelineLayout_
void createObjectIDsBuffer()
const std::vector< RenderProcess * > & getRenderProcesses() const
Gets all render processes for cleanup/synchronization.
void createPlaceholderBuffer()
Creates a buffer which can be used anywhere and holds one single 32 bit integer.
std::optional< ComputePass > hiZSPDComputePass
std::unordered_map< PipelineNames, GraphicsPipeline * > pipelinesByName
void initializeXrSwapchainFormats()
bool freezeCulling_
When true, culling data (frustum planes, Hi-Z VP) is frozen for debugging.
bool isFreezeCulling() const
Checks if culling data is currently frozen.
bool ensureOutputBufferSizes(uint32_t primitiveCount)
Ensures output buffers are sized to handle the given primitive count. Called by RenderingDataManager ...
void createObjectMeshletDataBuffer()
static constexpr std::chrono::milliseconds STALL_THRESHOLD_MS
Threshold for considering a frame as "stalled" (1 second)
std::optional< ComputePass > binningAllocatorComputePass
Stage 1: Binning allocator.
VkPipeline vsGraphicsPipeline_
VkDependencyInfo getMeshletCullingToPrepareDrawBarriers()
const VulkanBuffer & getObjectCullingDataBuffer() const
VkDescriptorSetLayout graphicsDescriptorSetLayout
RenderProcess * getCurrentRenderProcess() const
Gets the render process of the current frame.
std::unique_ptr< TimelineSynchronizer > timelineSynchronizer_
const VulkanBuffer & getObjectMeshletDataBuffer() const
uint64_t getTimelineSemaphoreValue() const
void recordVertexShaderDraws(size_t swapChainImageIndex) const
void setFreezeCulling(bool freeze)
Freezes culling data (frustum planes, Hi-Z view-projection)
void markFrameStart()
Marks the start of a new frame for stall detection. Call this at the beginning of each render frame.
std::optional< ComputePass > drawPreparationComputePass
std::vector< VulkanStagedBufferSyncObjects > syncCopyObjects
std::unordered_map< GraphicsPipeline *, uint32_t > pipelineIndices
const VulkanBuffer & getCounterBuffer() const
void updateViewMatrix()
Requests an update of the current render processes view matrix. The matrix is pulled from the headset...
void recordXrSwapchainImageFinishedWritingBarrier(uint32_t swapChainImageIndex) const
VkDependencyInfo getMeshletCullingDispatchToMeshletCullingBarriers()
VkPipelineLayout graphicsPipelineLayout
static constexpr uint32_t MAX_HIZ_MIP_LEVELS
void renderToXr(size_t swapChainImageIndex, float time)
void resetMeshletCullingDispatchBuffers()
std::optional< VulkanBuffer > hiZSPDAtomicBuffer
bool useVertexShaderPath_
VkPipelineLayout computeObjectCullingPipelineLayout
The pipeline layout.
void initializeGpuBuffers() const
ComputePass & getMeshletCullingComputePass()
const VulkanBuffer & getPlaceholderUniformBuffer() const
const TimelineSynchronizer & getTimelineSynchronizer() const
Gets the timeline synchronizer for managing frame synchronization.
void initializeFrameIndices()
BS_tracy::tracy_thread_pool< BS_tracy::tp::none > updateThreadPool
void createVertexShaderPathResources()
void createHiZSPDResources()
VkCommandBuffer getCurrentRenderingCommandBuffer() const
DispatcherComputePass & getMeshletCullingDispatchComputePass()
const std::vector< GraphicsPipeline * > & getGraphicsPipelines() const
Gets the list of all graphics pipelines.
void createHiZGenerationResources()
std::optional< VulkanBuffer > objectMeshletDataBuffer
void recordTransfer(float time)
void submitGraphics(uint32_t swapChainImageIndex, VkSemaphore mirrorAcquireSemaphore=VK_NULL_HANDLE)
void cleanup()
Cleans up all resources of the renderer.
void createPlaceholderUniformBuffer()
VkCommandPool vkGraphicsCommandPool
The graphics and present command pool.
void createCounterBuffer()
void recordPass2RenderPass(size_t swapChainImageIndex)
Records the Pass 2 render pass using dynamic rendering Uses VK_ATTACHMENT_LOAD_OP_LOAD to preserve Pa...
std::vector< VkPushConstantRange > pushConstants
void recordVSInstancedDrawingPipeline()
std::vector< GraphicsPipeline * > graphicsPipelines
The pipelines.
VkSemaphore getTimelineSemaphore() const
Getter for the main timeline renderer semaphore.
void recordVertexShaderDrawsDepthOnly(size_t swapChainImageIndex) const
std::optional< VulkanBuffer > objectCullingDataBuffer
VkCommandPool vkTransferCommandPool
The transfer command pool for all commands submitted to the transfer queue.
void createHiZSPDDescriptorSets()
std::unique_ptr< RenderingDataManager > renderingDataManager
VkCommandBuffer getCurrentTransferCommandBuffer() const
Gets the current frame in flight and retrieves the transfer command buffer.
const VulkanBuffer & getDispatchBuffer() const
std::chrono::steady_clock::time_point lastFrameStartTime_
Time when the last frame started, for stall detection.
~Renderer()
cleans up the object
VkPipeline vsDepthOnlyPipeline_
VkPipelineLayout computeMeshletCullingPipelineLayout
VkDependencyInfo getMeshletUnpackingDispatchToMeshletUnpackingBarriers(Vulkan::BarrierBundle &bundle) const
std::optional< ComputePass > objectCullingComputePass
The descriptor set layout.
void resetMeshletUnpackingDispatchBuffers()
std::optional< VulkanBuffer > counterBuffer
void updateHiZMipDescriptorSets(uint32_t frameIndex)
void createPrepareDrawResources()
VkCommandPool getGraphicsCommandPool() const
gets the graphics command pool
void uploadFrameData(float time)
std::optional< ComputePass > drawPreparation
void prepareTransferSubmission(uint32_t frameIndex) const
VkSemaphore getCurrentPresentableSemaphore(uint32_t swapchainImageIndex) const
void createObjectCullingDataBuffer()
void createVSInstancedDrawingResources()
const std::unique_ptr< RenderingDataManager > & getRenderingDataManager() const
Getter for the rendering data manager.
std::optional< ComputePass > vsBinningAllocatorComputePass_
void advanceFrameIndices()
advances the frame indices for the next frame in flight
void createMeshletCullingDispatcherResources()
Creates the compute pipeline for the meshlet culling stage. This should only be called after the mesh...
VkPipelineLayout prepareDrawsComputePipelineLayout
std::optional< ComputePass > meshletUnpacking
VkDescriptorPool hiZDescriptorPool
uint64_t renderedFrameCounter
void allocateDescriptors()
allocates the first batch of mesh data to the shaders
std::optional< VulkanBuffer > objectIDsBuffer
ComputePass & getDrawPreparationComputePass()
int findExistingPipeline(const std::string &meshShader, const std::string &fragShader, const PipelineMaterialPayload &pipelineData) const
Searches for the first existing pipeline which has the same vertex and fragment shader.
void createPrimitiveCullingResources()
const VulkanBuffer & getObjectIDsBuffer() const
const VulkanBuffer & getMeshUnpackingDataBuffer() const
std::array< VkDescriptorSet, MAX_FRAMES_IN_FLIGHT > hiZSPDDescriptorSets
bool shouldSkipMirrorView()
Checks if mirror view should be skipped this frame.
const VulkanBuffer & getPlaceholderBuffer() const
std::vector< GraphicsPipeline * > depthOnlyGraphicsPipelines
ComputePass & getVSPrepareDrawComputePass()
static constexpr int SKIP_FRAMES_AFTER_STALL
Number of frames to skip after detecting a stall (covers all swapchain images)
void createVertexShaderPipelineResources()
VkDescriptorPool descriptorPool
The descriptor pool for all descriptors of the renderer.
bool getPipelineIndex(GraphicsPipeline *pipeline, uint32_t &pipelineIndex) const
Gets the index of a pipeline.
void getCurrentTracyVkContext() const
void createDispatchBuffer()
std::optional< VulkanBuffer > placeholderBuffer
std::optional< DispatcherComputePass > meshletCullingDispatchComputePass
std::optional< VulkanBuffer > dispatchBuffer
void createMeshUnpackingDataBuffer()
std::vector< VkSemaphore > renderFinishedSemaphores
void createBinningAllocatorResources()
void syncTimelineAfterPause()
Synchronizes the frame counter with the timeline semaphore after pausing.
std::optional< DispatcherComputePass > meshletUnpackingDispatchComputePass
ComputePass & getVSInstanceUnpackingComputePass()
void recordHiZGenerationSPD()
void recordPass2Culling(size_t swapChainImageIndex)
Records Pass 2 of two-pass occlusion culling Re-tests objects that failed Pass 1 Hi-Z against the new...
std::optional< VulkanBuffer > placeholderUniformBuffer
std::optional< ComputePass > vsInstanceUnpackingComputePass_
VkSemaphore getCurrentMirrorViewSemaphore() const
std::array< std::array< VkDescriptorSet, MAX_HIZ_MIP_LEVELS >, MAX_FRAMES_IN_FLIGHT > hiZMipDescriptorSets
void submitInitialTransfers()
ComputePass & getVSBinningAllocatorComputePass()
void createMeshletUnpackingDispatcherResources()
Creates the complete pipeline for the meshlet unpacker. This should only be called after the buffer h...
ComputePass & getBinningAllocatorComputePass()
void recordXrSwapchainImageWritableBarrier(uint32_t swapChainImageIndex) const
int skipMirrorFramesRemaining_
bool isInStallRecovery() const
Checks if we're currently in stall recovery mode. During stall recovery, extra GPU synchronization sh...
ApplicationContext * context
static PipelineConfig getPipelineConfig(PipelineNames pipelineName)
Gets the static configuration for a given pipeline type Returns shader paths and pipeline data for th...
bool useVSInstancedDrawing_
void updateCpuRenderResources(float time)
Updates all data for gpu frame buffers.
std::vector< VkCommandBuffer > getGraphicsCommandBuffers() const
Gets all graphics command buffers from all owned EngineCore::RenderProcess.
VkDependencyInfo getMeshletUnpackingToMeshletCullingDispatchBarriers(Vulkan::BarrierBundle &bundle)
std::optional< ComputePass > meshletUnpackingComputePass
std::optional< ComputePass > meshletCullingComputePass
void recordRenderPass(size_t swapChainImageIndex)
void createMeshletCullingResources()
void recordHiZGeneration()
Records the Hi-Z pyramid generation compute pass Should be called after the render pass completes.
The rendering data manager is supposed to hold all methods to update the contents of the buffers whic...
Centralized timeline semaphore management for the rendering pipeline.
RAII wrapper for Vulkan buffer and device memory.
Log category system implementation.
Used for vulkan specific helpers like something to chain pNexts together.
Static configuration for a graphics pipeline Defines which shaders to use for a given PipelineNames e...
std::filesystem::path fragmentShaderPath
PipelineMaterialPayload pipelineData
std::filesystem::path meshShaderPath
MeshConstants(uint32_t baseVisibleMeshletIndex)
uint32_t baseVisibleMeshletIndex
uint32_t drawCommandOffset
TaskConstants(const uint32_t drawCommandOffset=0)