-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFence.cpp
59 lines (48 loc) · 1.19 KB
/
Fence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "D3D12FrameWork/Fence.h"
#include "D3D12FrameWork/D3DDevice.h"
#include "D3D12FrameWork/CommandQueue.h"
#include <comdef.h>
namespace D3D12FrameWork {
Fence::Fence()
:m_pFence(nullptr)
, m_value(1)
, m_waitValue(0)
//, m_fenceEvent(nullptr)
{
}
bool Fence::Init(D3DDevice* _pDev) {
auto hr = _pDev->GetDev()->CreateFence(
m_waitValue,
D3D12_FENCE_FLAG_NONE,
IID_PPV_ARGS(m_pFence.ReleaseAndGetAddressOf())
);
if (FAILED(hr)) {
assert(false);
return false;
}
//m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
/* if (m_fenceEvent == nullptr) {
assert(false);
}*/
return true;
}
void Fence::Signal(CommandQueue* _queue) {
m_waitValue = m_value;
auto hr = _queue->GetQueue()->Signal(m_pFence.Get(), m_waitValue);
if (FAILED(hr)) assert(false);
m_value++;
}
void Fence::WaitSignal() {
if (m_pFence->GetCompletedValue() < m_waitValue) {
//fence eventでエラーが起こる。わかんない。。。
auto hr = m_pFence->SetEventOnCompletion(m_waitValue, NULL);
if (FAILED(hr)) assert(false);
//WaitForSingleObject(m_fenceEvent, INFINITE);
}
}
void Fence::Term() {
//if (!CloseHandle(m_fenceEvent)) {
// assert(false);
//}
}
}