2026-03-15 03:15:12 +08:00
|
|
|
#include "XCEngine/RHI/D3D12/D3D12CommandQueue.h"
|
2026-03-15 23:03:06 +08:00
|
|
|
#include "XCEngine/RHI/D3D12/D3D12CommandList.h"
|
|
|
|
|
#include "XCEngine/RHI/D3D12/D3D12Fence.h"
|
|
|
|
|
#include <vector>
|
2026-03-15 03:15:12 +08:00
|
|
|
|
|
|
|
|
namespace XCEngine {
|
|
|
|
|
namespace RHI {
|
|
|
|
|
|
|
|
|
|
D3D12CommandQueue::D3D12CommandQueue()
|
|
|
|
|
: m_timestampFrequency(0)
|
|
|
|
|
, m_type(CommandQueueType::Direct) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3D12CommandQueue::~D3D12CommandQueue() {
|
|
|
|
|
Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool D3D12CommandQueue::Initialize(ID3D12Device* device, CommandQueueType type) {
|
|
|
|
|
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
|
|
|
|
queueDesc.Type = ToD3D12(type);
|
|
|
|
|
queueDesc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
|
|
|
|
|
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
|
|
|
|
queueDesc.NodeMask = 0;
|
|
|
|
|
|
|
|
|
|
HRESULT hResult = device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue));
|
|
|
|
|
if (FAILED(hResult)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_type = type;
|
|
|
|
|
m_commandQueue->GetTimestampFrequency(&m_timestampFrequency);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void D3D12CommandQueue::Shutdown() {
|
|
|
|
|
m_commandQueue.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void D3D12CommandQueue::ExecuteCommandLists(uint32_t count, ID3D12CommandList** lists) {
|
|
|
|
|
m_commandQueue->ExecuteCommandLists(count, lists);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 21:50:54 +08:00
|
|
|
void D3D12CommandQueue::Signal(D3D12Fence* fence, uint64_t value) {
|
2026-03-15 23:03:06 +08:00
|
|
|
if (fence) {
|
2026-03-16 21:50:54 +08:00
|
|
|
m_commandQueue->Signal(fence->GetFence(), value);
|
2026-03-15 23:03:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 03:15:12 +08:00
|
|
|
void D3D12CommandQueue::Signal(ID3D12Fence* fence, uint64_t value) {
|
2026-03-15 23:03:06 +08:00
|
|
|
if (fence) {
|
|
|
|
|
m_commandQueue->Signal(fence, value);
|
|
|
|
|
}
|
2026-03-15 03:15:12 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-16 21:50:54 +08:00
|
|
|
void D3D12CommandQueue::Wait(D3D12Fence* fence, uint64_t value) {
|
2026-03-15 23:03:06 +08:00
|
|
|
if (fence) {
|
2026-03-16 21:50:54 +08:00
|
|
|
m_commandQueue->Wait(fence->GetFence(), value);
|
2026-03-15 23:03:06 +08:00
|
|
|
}
|
2026-03-15 03:15:12 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-15 23:03:06 +08:00
|
|
|
void D3D12CommandQueue::Wait(ID3D12Fence* fence, uint64_t value) {
|
2026-03-15 03:15:12 +08:00
|
|
|
if (fence) {
|
2026-03-15 23:03:06 +08:00
|
|
|
m_commandQueue->Wait(fence, value);
|
2026-03-15 03:15:12 +08:00
|
|
|
}
|
2026-03-15 23:03:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t D3D12CommandQueue::GetCompletedValue() {
|
2026-03-15 03:15:12 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void D3D12CommandQueue::WaitForIdle() {
|
|
|
|
|
ID3D12Fence* fence = nullptr;
|
|
|
|
|
HRESULT hResult = m_commandQueue->GetDevice(IID_PPV_ARGS(&fence));
|
|
|
|
|
if (SUCCEEDED(hResult)) {
|
|
|
|
|
m_commandQueue->Wait(fence, UINT64_MAX);
|
|
|
|
|
fence->Release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RHI
|
|
|
|
|
} // namespace XCEngine
|