1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef VULKAN_RENDER_FRAME_SYNC_VK_H
17 #define VULKAN_RENDER_FRAME_SYNC_VK_H
18 
19 #include <cstdint>
20 #include <vulkan/vulkan_core.h>
21 
22 #include <base/containers/vector.h>
23 #include <render/namespace.h>
24 
25 #include "device/render_frame_sync.h"
26 
27 RENDER_BEGIN_NAMESPACE()
28 class Device;
29 
30 struct LowLevelFenceVk {
31     VkFence fence { VK_NULL_HANDLE };
32 };
33 
34 class RenderFrameSyncVk final : public RenderFrameSync {
35 public:
36     explicit RenderFrameSyncVk(Device& device);
37     ~RenderFrameSyncVk() override;
38 
39     void BeginFrame() override;
40     void WaitForFrameFence() override;
41     // set flag that the fence has been signalled
42     void FrameFenceIsSignalled();
43 
44     LowLevelFenceVk GetFrameFence() const;
45 
46 private:
47     Device& device_;
48 
49     struct FrameFence {
50         VkFence fence { VK_NULL_HANDLE };
51         bool signalled { true };
52     };
53     BASE_NS::vector<FrameFence> frameFences_;
54     uint32_t bufferingIndex_ { 0 };
55 };
56 RENDER_END_NAMESPACE()
57 
58 #endif // VULKAN_RENDER_FRAME_SYNC_VK_H
59