feat: 实现D3D12Fence封装
- 添加D3D12Fence类封装ID3D12Fence - 包含Signal/Wait/GetCompletedValue等同步功能 - 更新测试项目使用新的封装类
This commit is contained in:
52
engine/src/RHI/D3D12Fence.cpp
Normal file
52
engine/src/RHI/D3D12Fence.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user