Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
LockManager.h
Go to the documentation of this file.
1/*Copyright (c) 2018 DIVIDE-Studio
2Copyright (c) 2009 Ionut Cava
3
4This file is part of DIVIDE Framework.
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of
7this software
8and associated documentation files (the "Software"), to deal in the Software
9without restriction,
10including without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense,
12and/or sell copies of the Software, and to permit persons to whom the Software
13is furnished to do so,
14subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in all
17copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
22PARTICULAR PURPOSE AND NONINFRINGEMENT.
23IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24DAMAGES OR OTHER LIABILITY,
25WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26CONNECTION WITH THE SOFTWARE
27OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29*/
30
31#pragma once
32#ifndef DVD_LOCK_MANAGER_H_
33#define DVD_LOCK_MANAGER_H_
34
36
37
38//ref: https://github.com/nvMcJohn/apitest
39
40namespace Divide {
41
42 enum class RenderAPI : U8;
43
44 constexpr U8 g_MaxLockWaitRetries = 5u;
45
47 {
48 inline static constexpr U64 INVALID_FRAME_NUMBER = U64_MAX;
49
50 explicit SyncObject( U8 flag, U64 frameIdx );
51 virtual ~SyncObject();
52 virtual void reset();
53
55 U8 _flag{0u};
56 };
57
59
61 {
62 static constexpr size_t INVALID_SYNC_ID = SIZE_MAX;
63
65 size_t _generation{ 0u };
66 };
67
69 {
72 };
73
74 class LockManager : public GUIDWrapper
75 {
76 public:
77 static constexpr U8 DEFAULT_SYNC_FLAG_INTERNAL = 254u;
78 static constexpr U8 DEFAULT_SYNC_FLAG_GVD = 255u;
79 static constexpr U8 DEFAULT_SYNC_FLAG_SSBO = 252u;
80 static constexpr U8 DEFAULT_SYNC_FLAG_TEXTURE = 253u;
81
83 {
84 SyncObject_uptr _ptr{ nullptr };
85 size_t _generation{ 0u };
86 };
87
88 using BufferLockPool = eastl::fixed_vector<BufferLockPoolEntry, 1024, true>;
89
90 static void CleanExpiredSyncObjects( RenderAPI api, U64 frameNumber );
91 static void Clear();
92
93 public:
94 virtual ~LockManager() override = default;
95
97 bool waitForLockedRange(size_t lockBeginBytes, size_t lockLength);
99 bool lockRange(size_t lockBeginBytes, size_t lockLength, SyncObjectHandle syncObj);
100
102
103 protected:
104 [[nodiscard]] static bool InitLockPoolEntry( RenderAPI api, BufferLockPoolEntry& entry, U8 flag, U64 frameIdx );
105
106 virtual bool waitForLockedRangeLocked(const SyncObject_uptr& sync, const BufferRange& testRange, const BufferLockInstance& lock);
107
108 protected:
109 mutable Mutex _bufferLockslock; // :D
110 eastl::fixed_vector<BufferLockInstance, 64, true> _bufferLocks;
111 eastl::fixed_vector<BufferLockInstance, 64, true> _swapLocks;
112
115 };
116
117}; //namespace Divide
118
119#endif //DVD_LOCK_MANAGER_H_
#define FWD_DECLARE_MANAGED_STRUCT(T)
Utility class that adds basic GUID management to objects.
Definition: GUIDWrapper.h:44
static void CleanExpiredSyncObjects(RenderAPI api, U64 frameNumber)
Definition: LockManager.cpp:29
static constexpr U8 DEFAULT_SYNC_FLAG_GVD
Definition: LockManager.h:78
static constexpr U8 DEFAULT_SYNC_FLAG_SSBO
Definition: LockManager.h:79
static constexpr U8 DEFAULT_SYNC_FLAG_INTERNAL
Definition: LockManager.h:77
static void Clear()
Definition: LockManager.cpp:64
static SyncObjectHandle CreateSyncObject(RenderAPI api, U8 flag=DEFAULT_SYNC_FLAG_INTERNAL)
static Mutex s_bufferLockLock
Definition: LockManager.h:113
virtual bool waitForLockedRangeLocked(const SyncObject_uptr &sync, const BufferRange &testRange, const BufferLockInstance &lock)
bool waitForLockedRange(size_t lockBeginBytes, size_t lockLength)
Returns false if we encountered an error.
virtual ~LockManager() override=default
eastl::fixed_vector< BufferLockPoolEntry, 1024, true > BufferLockPool
Definition: LockManager.h:88
eastl::fixed_vector< BufferLockInstance, 64, true > _bufferLocks
Definition: LockManager.h:110
static BufferLockPool s_bufferLockPool
Definition: LockManager.h:114
bool lockRange(size_t lockBeginBytes, size_t lockLength, SyncObjectHandle syncObj)
Returns false if we encountered an error.
static bool InitLockPoolEntry(RenderAPI api, BufferLockPoolEntry &entry, U8 flag, U64 frameIdx)
Definition: LockManager.cpp:70
static constexpr U8 DEFAULT_SYNC_FLAG_TEXTURE
Definition: LockManager.h:80
eastl::fixed_vector< BufferLockInstance, 64, true > _swapLocks
Definition: LockManager.h:111
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
constexpr U8 g_MaxLockWaitRetries
Definition: LockManager.h:44
constexpr U64 U64_MAX
std::mutex Mutex
Definition: SharedMutex.h:40
uint8_t U8
Project const SceneEntry & entry
Definition: DefaultScene.h:41
uint64_t U64
SyncObjectHandle _syncObjHandle
Definition: LockManager.h:71
Definition: LockManager.h:83
size_t _generation
Definition: LockManager.h:85
SyncObject_uptr _ptr
Definition: LockManager.h:84
static constexpr size_t INVALID_SYNC_ID
Definition: LockManager.h:62
virtual ~SyncObject()
Definition: LockManager.cpp:19
static constexpr U64 INVALID_FRAME_NUMBER
Definition: LockManager.h:48
virtual void reset()
Definition: LockManager.cpp:24