CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/GPU/Vulkan/VulkanFrameData.h
Views: 1401
1
#pragma once
2
3
#include <cstdint>
4
5
#include <mutex>
6
#include <condition_variable>
7
8
#include "Common/GPU/Vulkan/VulkanContext.h"
9
#include "Common/Data/Collections/Hashmaps.h"
10
11
enum {
12
MAX_TIMESTAMP_QUERIES = 128,
13
};
14
15
enum class VKRRunType {
16
SUBMIT,
17
PRESENT,
18
SYNC,
19
EXIT,
20
};
21
22
struct QueueProfileContext {
23
bool enabled = false;
24
bool timestampsEnabled = false;
25
VkQueryPool queryPool;
26
std::vector<std::string> timestampDescriptions;
27
std::string profileSummary;
28
double cpuStartTime;
29
double cpuEndTime;
30
double descWriteTime;
31
int descriptorsWritten;
32
int descriptorsDeduped;
33
#ifdef _DEBUG
34
int commandCounts[11];
35
#endif
36
};
37
38
class VKRFramebuffer;
39
40
struct ReadbackKey {
41
const VKRFramebuffer *framebuf;
42
int width;
43
int height;
44
};
45
46
struct CachedReadback {
47
VkBuffer buffer;
48
VmaAllocation allocation;
49
VkDeviceSize bufferSize;
50
bool isCoherent;
51
52
void Destroy(VulkanContext *vulkan);
53
};
54
55
struct FrameDataShared {
56
// For synchronous readbacks.
57
VkFence readbackFence = VK_NULL_HANDLE;
58
bool useMultiThreading;
59
bool measurePresentTime;
60
61
void Init(VulkanContext *vulkan, bool useMultiThreading, bool measurePresentTime);
62
void Destroy(VulkanContext *vulkan);
63
};
64
65
enum class FrameSubmitType {
66
Pending,
67
Sync,
68
FinishFrame,
69
};
70
71
// Per-frame data, round-robin so we can overlap submission with execution of the previous frame.
72
struct FrameData {
73
bool skipSwap = false;
74
75
std::mutex fenceMutex;
76
std::condition_variable fenceCondVar;
77
bool readyForFence = true;
78
79
VkFence fence = VK_NULL_HANDLE;
80
VkSemaphore acquireSemaphore = VK_NULL_HANDLE;
81
VkSemaphore renderingCompleteSemaphore = VK_NULL_HANDLE;
82
83
// These are on different threads so need separate pools.
84
VkCommandPool cmdPoolInit = VK_NULL_HANDLE; // Written to from main thread
85
VkCommandPool cmdPoolMain = VK_NULL_HANDLE; // Written to from render thread, which also submits
86
87
VkCommandBuffer initCmd = VK_NULL_HANDLE;
88
VkCommandBuffer mainCmd = VK_NULL_HANDLE;
89
VkCommandBuffer presentCmd = VK_NULL_HANDLE;
90
91
bool hasInitCommands = false;
92
bool hasMainCommands = false;
93
bool hasPresentCommands = false;
94
95
bool hasFencePending = false;
96
bool hasAcquired = false;
97
98
bool syncDone = false;
99
100
// Swapchain.
101
uint32_t curSwapchainImage = -1;
102
103
// Frames need unique IDs to wait for present on, let's keep them here.
104
// Also used for indexing into the frame timing history buffer.
105
uint64_t frameId = 0;
106
107
// Profiling.
108
QueueProfileContext profile{};
109
110
// Async readback cache.
111
DenseHashMap<ReadbackKey, CachedReadback *> readbacks_;
112
113
FrameData() : readbacks_(8) {}
114
115
void Init(VulkanContext *vulkan, int index);
116
void Destroy(VulkanContext *vulkan);
117
118
void AcquireNextImage(VulkanContext *vulkan);
119
VkResult QueuePresent(VulkanContext *vulkan, FrameDataShared &shared);
120
121
// Generally called from the main thread, unlike most of the rest.
122
VkCommandBuffer GetInitCmd(VulkanContext *vulkan);
123
124
// Submits pending command buffers.
125
void Submit(VulkanContext *vulkan, FrameSubmitType type, FrameDataShared &shared);
126
127
private:
128
// Metadata for logging etc
129
int index = -1;
130
};
131
132