Plasma Engine  2.0
Loading...
Searching...
No Matches
QueryPoolVulkan.h
1#pragma once
2
3#include <RendererVulkan/RendererVulkanDLL.h>
4
5#include <vulkan/vulkan.hpp>
6
8
10class PL_RENDERERVULKAN_DLL plQueryPoolVulkan
11{
12public:
14
17 void Initialize(plUInt32 uiValidBits);
18 void DeInitialize();
19
21 void BeginFrame(vk::CommandBuffer commandBuffer);
22
27 plGALTimestampHandle InsertTimestamp(vk::CommandBuffer commandBuffer, vk::PipelineStageFlagBits pipelineStage = vk::PipelineStageFlagBits::eBottomOfPipe);
28
34 plEnum<plGALAsyncResult> GetTimestampResult(plGALTimestampHandle hTimestamp, plTime& out_result, bool bForce = false);
35
36 plGALPoolHandle BeginOcclusionQuery(vk::CommandBuffer commandBuffer, plEnum<plGALQueryType> type);
37 void EndOcclusionQuery(vk::CommandBuffer commandBuffer, plGALPoolHandle hPool);
38 plEnum<plGALAsyncResult> GetOcclusionQueryResult(plGALPoolHandle hPool, plUInt64& out_uiQueryResult, bool bForce = false);
39
40private:
42 void Calibrate();
43
44 static constexpr plUInt32 s_uiRetainFrames = 4;
45
47 struct Query
48 {
49 vk::QueryPool m_pool;
50 plUInt32 uiQueryIndex;
51 };
52
55 struct QueryPool
56 {
57 vk::QueryPool m_pool;
58 bool m_bReady = false;
59 plDynamicArray<uint64_t> m_queryResults;
60 };
61
63 struct FramePool
64 {
65 plUInt64 m_uiNextIndex = 0; // Next query index in this frame. Use % and / to find the pool / element index.
66 plUInt64 m_uiFrameCounter = 0; // plGALDevice::GetCurrentFrame
67 plUInt8 m_uiReadyFrames = 0;
69 };
70
73 struct Pool
74 {
75 Pool(plAllocator* pAllocator);
76
77 void Initialize(vk::Device device, plUInt32 uiPoolSize, vk::QueryType queryType);
78 void DeInitialize();
79
80 QueryPool* GetFreePool();
81 void BeginFrame(vk::CommandBuffer commandBuffer, plUInt64 uiCurrentFrame, plUInt64 uiSafeFrame);
82 plGALPoolHandle CreateQuery(vk::CommandBuffer commandBuffer);
83 Query GetQuery(plGALPoolHandle hPool);
84 plEnum<plGALAsyncResult> GetResult(plGALPoolHandle hPool, plUInt64& out_uiResult, bool bForce);
85
86 // Current active data.
87 FramePool* m_pCurrentFrame = nullptr;
88 plUInt64 m_uiFirstFrameIndex = 0;
89 plDeque<FramePool> m_pendingFrames;
90
91 // Pools.
94
95 vk::Device m_device;
96 plUInt32 m_uiPoolSize = 0;
97 vk::QueryType m_QueryType;
98 };
99
100 plGALDeviceVulkan* m_pDevice = nullptr;
101
102 // Timestamp conversion and calibration data.
103 double m_fNanoSecondsPerTick = 0;
104 plUInt64 m_uiValidBitsMask = 0;
105 plTime m_gpuToCpuDelta;
106
107 // Pools
108 Pool m_TimestampPool;
109 Pool m_OcclusionPool;
110};
Base class for all memory allocators.
Definition Allocator.h:23
Definition Deque.h:270
Definition DynamicArray.h:81
The Vulkan device implementation of the graphics abstraction layer.
Definition DeviceVulkan.h:58
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Pool for GPU queries.
Definition QueryPoolVulkan.h:11
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
A generic id class that holds an id combined of an instance index and a generation counter.
Definition Id.h:52
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12