53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
|
|
#include "XCEngine/RHI/D3D12/D3D12Fence.h"
|
||
|
|
#include <Windows.h>
|
||
|
|
|
||
|
|
namespace XCEngine {
|
||
|
|
namespace RHI {
|
||
|
|
|
||
|
|
D3D12Fence::D3D12Fence()
|
||
|
|
: m_eventHandle(nullptr) {
|
||
|
|
}
|
||
|
|
|
||
|
|
D3D12Fence::~D3D12Fence() {
|
||
|
|
Shutdown();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool D3D12Fence::Initialize(ID3D12Device* device, uint64_t initialValue) {
|
||
|
|
HRESULT hResult = device->CreateFence(
|
||
|
|
initialValue,
|
||
|
|
D3D12_FENCE_FLAG_NONE,
|
||
|
|
IID_PPV_ARGS(&m_fence));
|
||
|
|
if (FAILED(hResult)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
m_eventHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||
|
|
return m_eventHandle != nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
void D3D12Fence::Shutdown() {
|
||
|
|
if (m_eventHandle) {
|
||
|
|
CloseHandle(m_eventHandle);
|
||
|
|
m_eventHandle = nullptr;
|
||
|
|
}
|
||
|
|
m_fence.Reset();
|
||
|
|
}
|
||
|
|
|
||
|
|
void D3D12Fence::Signal(uint64_t value) {
|
||
|
|
m_fence->Signal(value);
|
||
|
|
}
|
||
|
|
|
||
|
|
void D3D12Fence::Wait(uint64_t value) {
|
||
|
|
if (m_fence->GetCompletedValue() < value) {
|
||
|
|
m_fence->SetEventOnCompletion(value, m_eventHandle);
|
||
|
|
WaitForSingleObject(m_eventHandle, INFINITE);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
uint64_t D3D12Fence::GetCompletedValue() {
|
||
|
|
return m_fence->GetCompletedValue();
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace RHI
|
||
|
|
} // namespace XCEngine
|