- Remove IsSignaled() from RHIFence interface (semantic inconsistency) - Remove Reset() from OpenGL implementation (no D3D12 counterpart) - OpenGL Fence now uses single GLsync + CPU counters for timeline simulation - OpenGL Fence Initialize() now accepts uint64_t initialValue (was bool) - Add comprehensive timeline semantics tests for all backends: - Signal increment/decrement scenarios - Multiple signals - Wait smaller than completed value - GetCompletedValue stages verification - Update documentation to reflect actual implementation
57 lines
1.2 KiB
C++
57 lines
1.2 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() {
|
|
Signal(1);
|
|
}
|
|
|
|
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() const {
|
|
return m_fence->GetCompletedValue();
|
|
}
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|