CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/GPU/Vulkan/VulkanFrameData.h
Views: 1401
#pragma once12#include <cstdint>34#include <mutex>5#include <condition_variable>67#include "Common/GPU/Vulkan/VulkanContext.h"8#include "Common/Data/Collections/Hashmaps.h"910enum {11MAX_TIMESTAMP_QUERIES = 128,12};1314enum class VKRRunType {15SUBMIT,16PRESENT,17SYNC,18EXIT,19};2021struct QueueProfileContext {22bool enabled = false;23bool timestampsEnabled = false;24VkQueryPool queryPool;25std::vector<std::string> timestampDescriptions;26std::string profileSummary;27double cpuStartTime;28double cpuEndTime;29double descWriteTime;30int descriptorsWritten;31int descriptorsDeduped;32#ifdef _DEBUG33int commandCounts[11];34#endif35};3637class VKRFramebuffer;3839struct ReadbackKey {40const VKRFramebuffer *framebuf;41int width;42int height;43};4445struct CachedReadback {46VkBuffer buffer;47VmaAllocation allocation;48VkDeviceSize bufferSize;49bool isCoherent;5051void Destroy(VulkanContext *vulkan);52};5354struct FrameDataShared {55// For synchronous readbacks.56VkFence readbackFence = VK_NULL_HANDLE;57bool useMultiThreading;58bool measurePresentTime;5960void Init(VulkanContext *vulkan, bool useMultiThreading, bool measurePresentTime);61void Destroy(VulkanContext *vulkan);62};6364enum class FrameSubmitType {65Pending,66Sync,67FinishFrame,68};6970// Per-frame data, round-robin so we can overlap submission with execution of the previous frame.71struct FrameData {72bool skipSwap = false;7374std::mutex fenceMutex;75std::condition_variable fenceCondVar;76bool readyForFence = true;7778VkFence fence = VK_NULL_HANDLE;79VkSemaphore acquireSemaphore = VK_NULL_HANDLE;80VkSemaphore renderingCompleteSemaphore = VK_NULL_HANDLE;8182// These are on different threads so need separate pools.83VkCommandPool cmdPoolInit = VK_NULL_HANDLE; // Written to from main thread84VkCommandPool cmdPoolMain = VK_NULL_HANDLE; // Written to from render thread, which also submits8586VkCommandBuffer initCmd = VK_NULL_HANDLE;87VkCommandBuffer mainCmd = VK_NULL_HANDLE;88VkCommandBuffer presentCmd = VK_NULL_HANDLE;8990bool hasInitCommands = false;91bool hasMainCommands = false;92bool hasPresentCommands = false;9394bool hasFencePending = false;95bool hasAcquired = false;9697bool syncDone = false;9899// Swapchain.100uint32_t curSwapchainImage = -1;101102// Frames need unique IDs to wait for present on, let's keep them here.103// Also used for indexing into the frame timing history buffer.104uint64_t frameId = 0;105106// Profiling.107QueueProfileContext profile{};108109// Async readback cache.110DenseHashMap<ReadbackKey, CachedReadback *> readbacks_;111112FrameData() : readbacks_(8) {}113114void Init(VulkanContext *vulkan, int index);115void Destroy(VulkanContext *vulkan);116117void AcquireNextImage(VulkanContext *vulkan);118VkResult QueuePresent(VulkanContext *vulkan, FrameDataShared &shared);119120// Generally called from the main thread, unlike most of the rest.121VkCommandBuffer GetInitCmd(VulkanContext *vulkan);122123// Submits pending command buffers.124void Submit(VulkanContext *vulkan, FrameSubmitType type, FrameDataShared &shared);125126private:127// Metadata for logging etc128int index = -1;129};130131132