Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/GPU/Vulkan/VulkanFrameData.h
3187 views
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
// Swap chain management
56
struct SwapchainImageData {
57
VkImage image;
58
VkImageView view;
59
VkSemaphore renderingCompleteSemaphore = VK_NULL_HANDLE;
60
};
61
62
struct FrameDataShared {
63
// For synchronous readbacks.
64
VkFence readbackFence = VK_NULL_HANDLE;
65
bool useMultiThreading = false;
66
bool measurePresentTime = false;
67
68
std::vector<SwapchainImageData> swapchainImages_;
69
uint32_t swapchainImageCount_ = 0;
70
71
void Init(VulkanContext *vulkan, bool useMultiThreading, bool measurePresentTime);
72
void Destroy(VulkanContext *vulkan);
73
};
74
75
enum class FrameSubmitType {
76
Pending,
77
Sync,
78
FinishFrame,
79
};
80
81
// Per-frame data, round-robin so we can overlap submission with execution of the previous frame.
82
struct FrameData {
83
bool skipSwap = false;
84
85
std::mutex fenceMutex;
86
std::condition_variable fenceCondVar;
87
bool readyForFence = true;
88
89
VkFence fence = VK_NULL_HANDLE;
90
VkSemaphore acquireSemaphore = VK_NULL_HANDLE;
91
92
// These are on different threads so need separate pools.
93
VkCommandPool cmdPoolInit = VK_NULL_HANDLE; // Written to from main thread
94
VkCommandPool cmdPoolMain = VK_NULL_HANDLE; // Written to from render thread, which also submits
95
96
VkCommandBuffer initCmd = VK_NULL_HANDLE;
97
VkCommandBuffer mainCmd = VK_NULL_HANDLE;
98
VkCommandBuffer presentCmd = VK_NULL_HANDLE;
99
100
bool hasInitCommands = false;
101
bool hasMainCommands = false;
102
bool hasPresentCommands = false;
103
104
bool hasFencePending = false;
105
bool hasAcquired = false;
106
107
bool syncDone = false;
108
109
// Swapchain.
110
uint32_t curSwapchainImage = -1;
111
112
// Frames need unique IDs to wait for present on, let's keep them here.
113
// Also used for indexing into the frame timing history buffer.
114
uint64_t frameId = 0;
115
116
// Profiling.
117
QueueProfileContext profile{};
118
119
// Async readback cache.
120
DenseHashMap<ReadbackKey, CachedReadback *> readbacks_;
121
122
FrameData() : readbacks_(8) {}
123
124
void Init(VulkanContext *vulkan, int index);
125
void Destroy(VulkanContext *vulkan);
126
127
void AcquireNextImage(VulkanContext *vulkan);
128
VkResult QueuePresent(VulkanContext *vulkan, FrameDataShared &shared);
129
130
// Generally called from the main thread, unlike most of the rest.
131
VkCommandBuffer GetInitCmd(VulkanContext *vulkan);
132
133
// Submits pending command buffers.
134
void Submit(VulkanContext *vulkan, FrameSubmitType type, FrameDataShared &shared);
135
136
private:
137
// Metadata for logging etc
138
int index = -1;
139
};
140
141