feat: 实现D3D12Fence封装
- 添加D3D12Fence类封装ID3D12Fence - 包含Signal/Wait/GetCompletedValue等同步功能 - 更新测试项目使用新的封装类
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12Device.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandQueue.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Fence.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
@@ -47,8 +48,7 @@ XCEngine::RHI::D3D12CommandAllocator gCommandAllocator;
|
||||
ID3D12GraphicsCommandList* gCommandList = nullptr;
|
||||
|
||||
// 同步对象
|
||||
ID3D12Fence* gFence = nullptr;
|
||||
HANDLE gFenceEvent = nullptr;
|
||||
XCEngine::RHI::D3D12Fence gFence;
|
||||
UINT64 gFenceValue = 0;
|
||||
|
||||
//=================================================================================
|
||||
@@ -646,8 +646,7 @@ bool InitD3D12(HWND inHWND, int inWidth, int inHeight) {
|
||||
gCommandAllocator.Initialize(device, XCEngine::RHI::CommandQueueType::Direct);
|
||||
device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, gCommandAllocator.GetCommandAllocator(), nullptr, IID_PPV_ARGS(&gCommandList));
|
||||
|
||||
device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&gFence));
|
||||
gFenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
gFence.Initialize(device, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -664,9 +663,8 @@ ID3D12GraphicsCommandList* GetCommandList() {
|
||||
}
|
||||
|
||||
void WaitForCompletionOfCommandList() {
|
||||
if (gFence->GetCompletedValue() < gFenceValue) {
|
||||
gFence->SetEventOnCompletion(gFenceValue, gFenceEvent);
|
||||
WaitForSingleObject(gFenceEvent, INFINITE);
|
||||
if (gFence.GetCompletedValue() < gFenceValue) {
|
||||
gFence.Wait(gFenceValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -679,7 +677,7 @@ void EndCommandList() {
|
||||
ID3D12CommandList* ppCommandLists[] = { gCommandList };
|
||||
gCommandQueue.ExecuteCommandLists(1, ppCommandLists);
|
||||
gFenceValue += 1;
|
||||
gCommandQueue.Signal(gFence, gFenceValue);
|
||||
gCommandQueue.Signal(gFence.GetFence(), gFenceValue);
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
|
||||
Reference in New Issue
Block a user