Bicameral Engine
GPU-resident engine for a magic-research open-world game
Loading...
Searching...
No Matches
immediate_queue.cpp
Go to the documentation of this file.
1// immediate_queue.cpp — 1 本記録して投げて待つキュー(T-0013)。
2// 待つのは ID3D12Fence::SetEventOnCompletion にイベントを渡さない形(終わるまで呼んだスレッドを止める)。
4
5#include "core/hresult.h"
6#include "core/log.h"
7#include "gpu/com_ptr.h"
8#include "gpu/device.h"
9
10namespace bicameral::gpu {
11
12 std::expected<ImmediateQueue, std::string> ImmediateQueue::Create(ID3D12Device5* device,
13 D3D12_COMMAND_LIST_TYPE type) {
14 ImmediateQueue queue;
15 const D3D12_COMMAND_QUEUE_DESC queueDesc{.Type = type};
16 if (!BICAMERAL_CHECK_HR(Channel::Gpu, device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&queue.m_queue))) ||
17 !BICAMERAL_CHECK_HR(Channel::Gpu, device->CreateCommandAllocator(type, IID_PPV_ARGS(&queue.m_allocator))) ||
18 !BICAMERAL_CHECK_HR(Channel::Gpu, device->CreateCommandList1(0, type, D3D12_COMMAND_LIST_FLAG_NONE,
19 IID_PPV_ARGS(&queue.m_list))) ||
21 device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&queue.m_fence)))) {
22 return std::unexpected("キュー・コマンドリスト・フェンスを作れない");
23 }
24
25 // DRED と debug layer の報告に出る名前
26 queue.m_queue->SetName(L"ImmediateQueue");
27 queue.m_list->SetName(L"ImmediateQueue.list");
28
29 return queue;
30 }
31
32 ID3D12GraphicsCommandList10* ImmediateQueue::Begin() {
34 return nullptr;
35
36 if (!BICAMERAL_CHECK_HR(Channel::Gpu, m_list->Reset(m_allocator.Get(), nullptr)))
37 return nullptr;
38
39 return m_list.Get();
40 }
41
43 // 記録の誤りはここで分かる
45 return false;
46
47 ID3D12CommandList* lists[] = {m_list.Get()};
48 m_queue->ExecuteCommandLists(1, lists);
49
52 return false;
53
54 if (!BICAMERAL_CHECK_HR(Channel::Gpu, m_fence->SetEventOnCompletion(m_fenceValue, nullptr)))
55 return false;
56
57 // デバイスが失われるとフェンスの値は UINT64_MAX になる。理由と DRED の記録(有効なら)をログへ
58 if (m_fence->GetCompletedValue() != UINT64_MAX)
59 return true;
60
61 ComPtr<ID3D12Device> device;
62 if (SUCCEEDED(m_queue->GetDevice(IID_PPV_ARGS(&device))))
63 LogDeviceRemoved(device.Get());
64
65 return false;
66 }
67
68} // namespace bicameral::gpu
ComPtr< ID3D12Fence > m_fence
static std::expected< ImmediateQueue, std::string > Create(ID3D12Device5 *device, D3D12_COMMAND_LIST_TYPE type)
ComPtr< ID3D12GraphicsCommandList10 > m_list
ComPtr< ID3D12CommandQueue > m_queue
ID3D12GraphicsCommandList10 * Begin()
ComPtr< ID3D12CommandAllocator > m_allocator
#define BICAMERAL_CHECK_HR(channel, expression)
Definition hresult.h:32
DeviceRemovedReport LogDeviceRemoved(ID3D12Device *device)
Definition device.cpp:379