Bicameral Engine
GPU-resident engine for a magic-research open-world game
Loading...
Searching...
No Matches
work_graph.h
Go to the documentation of this file.
1// work_graph.h — Work Graph のプログラムを作り、コマンドリストに設定して起動する(T-0013)。
2// DXIL ライブラリ(lib_6_8)の中の全部のノードを 1 つのグラフにし、グラフが要る裏のメモリ(バッキングメモリ)も持つ。
3// ルート署名はグローバルの 1 つだけ(ノードごとのローカルのルート署名は使わない)。
4//
5// auto graph = WorkGraph::Create(device, rootSignature, library, L"Probe");
6// list->SetComputeRootSignature(rootSignature);
7// graph->SetProgram(list, true); // 最初の 1 回は裏のメモリを初期化する
8// list->SetComputeRootUnorderedAccessView(0, ...);
9// graph->DispatchFromCpu(list, graph->EntrypointIndex(L"Root"), &record, 1, sizeof(record));
10#pragma once
11
12#include <cstddef>
13#include <cstdint>
14#include <expected>
15#include <span>
16#include <string>
17#include <string_view>
18
19#include "gpu/com_ptr.h"
20
21namespace bicameral::gpu {
22
23 class WorkGraph {
24 public:
25 [[nodiscard]] static std::expected<WorkGraph, std::string> Create(ID3D12Device5* device,
26 ID3D12RootSignature* globalRootSignature,
27 std::span<const std::byte> library,
28 std::wstring_view programName);
29
30 // 入口のノードの番号。名前が無ければ UINT32_MAX
31 [[nodiscard]] uint32_t EntrypointIndex(std::wstring_view nodeName) const;
32
33 // グラフをコマンドリストに設定する。initialize は裏のメモリを初期化するか(作ってから最初の 1 回は true)
34 void SetProgram(ID3D12GraphicsCommandList10* list, bool initialize) const;
35
36 // CPU が持つレコードを入口のノードへ渡して起動する(D3D12_DISPATCH_MODE_NODE_CPU_INPUT)
37 static void DispatchFromCpu(ID3D12GraphicsCommandList10* list, uint32_t entrypointIndex, const void* records,
38 uint32_t recordCount, uint64_t recordStrideBytes);
39
40 // GPU のメモリにある D3D12_NODE_GPU_INPUT(入口・レコードの数・レコードのアドレスと間隔)を実行の時に読んで起動する
41 // (D3D12_DISPATCH_MODE_NODE_GPU_INPUT)。レコードの数を GPU が決められる。nodeGpuInput は 8 バイト境界で、
42 // それとレコードのメモリは NON_PIXEL_SHADER_RESOURCE か COMMON の状態でなければならない(仕様の D3D12_NODE_GPU_INPUT)
43 static void DispatchFromGpu(ID3D12GraphicsCommandList10* list, D3D12_GPU_VIRTUAL_ADDRESS nodeGpuInput);
44
45 [[nodiscard]] uint64_t BackingMemoryBytes() const { return m_backingMemoryBytes; }
46
47 private:
48 WorkGraph() = default;
49
50 // --- プログラム ---
51 ComPtr<ID3D12StateObject> m_stateObject;
52 ComPtr<ID3D12WorkGraphProperties> m_properties;
53 D3D12_PROGRAM_IDENTIFIER m_programIdentifier{};
54 uint32_t m_graphIndex = 0;
55
56 // --- 裏のメモリ(ドライバが決める大きさ)---
57 ComPtr<ID3D12Resource> m_backingMemory;
59 };
60
61} // namespace bicameral::gpu
static std::expected< WorkGraph, std::string > Create(ID3D12Device5 *device, ID3D12RootSignature *globalRootSignature, std::span< const std::byte > library, std::wstring_view programName)
D3D12_PROGRAM_IDENTIFIER m_programIdentifier
Definition work_graph.h:53
static void DispatchFromCpu(ID3D12GraphicsCommandList10 *list, uint32_t entrypointIndex, const void *records, uint32_t recordCount, uint64_t recordStrideBytes)
uint32_t EntrypointIndex(std::wstring_view nodeName) const
void SetProgram(ID3D12GraphicsCommandList10 *list, bool initialize) const
ComPtr< ID3D12Resource > m_backingMemory
Definition work_graph.h:57
uint64_t BackingMemoryBytes() const
Definition work_graph.h:45
static void DispatchFromGpu(ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS nodeGpuInput)
ComPtr< ID3D12WorkGraphProperties > m_properties
Definition work_graph.h:52
ComPtr< ID3D12StateObject > m_stateObject
Definition work_graph.h:51