Bicameral Engine
GPU-resident engine for a magic-research open-world game
Loading...
Searching...
No Matches
gpu_lab_box.h
Go to the documentation of this file.
1// gpu_lab_box.h — 実験室の箱(sim/lab_box.h)を GPU で刻む(T-0142)。多重解像度の木(sim/gpu_multires)に根 1 つの箱を置き、
2// 刻みの前にコマンド(common/lab_box.hlsli)を shaders/sim/lab_box.hlsl で当ててから RecordStep(反応 + 熱の伝導)。
3// CPU が書くのはコマンドの列の写しとルート定数だけ(箱のセルには触れない。D-107)。初めの箱は RecordUpload で 1 度だけ写す。
4//
5// 使い方(1 本のリストに 1 刻みまで。コマンドの写しの置き場が 1 つなので、前のリストが終わってから次を記録する):
6// auto box = GpuLabBox::Create(device, table);
7// box->RecordUpload(list, MakeLabBoxNest(table)); // 最初だけ
8// box->RecordTick(list, ring, tick, この刻みのコマンド); box->RecordReadback(list); → 投げて待つ → box->Read(nest)
9#pragma once
10
11#include <cstdint>
12#include <expected>
13#include <span>
14#include <string>
15
16#include "gpu/com_ptr.h"
17#include "sim/command.h"
18#include "sim/gpu_multires.h"
19#include "sim/lab_box.h"
20
21namespace bicameral::sim {
22
23 class GpuLabBox {
24 public:
25 [[nodiscard]] static std::expected<GpuLabBox, std::string> Create(ID3D12Device5* device,
26 const BakedReactionTable& table);
27
28 // 初めの箱(MakeLabBoxNest)を GPU へ写す
29 [[nodiscard]] bool RecordUpload(ID3D12GraphicsCommandList10* list, const MultiresNest& nest);
30
31 // 刻み tick: コマンド(LAB_MAX_COMMANDS_PER_TICK まで。(targetTick, sequence) の昇順)を当てて、1 刻み
32 [[nodiscard]] bool RecordTick(ID3D12GraphicsCommandList10* list, D3D12_GPU_VIRTUAL_ADDRESS debugRing,
33 uint64_t tick, std::span<const Command> commands);
34
35 void RecordReadback(ID3D12GraphicsCommandList10* list) { m_nest.RecordReadback(list); }
36 [[nodiscard]] bool Read(MultiresNest& nest) const { return m_nest.Read(nest); }
37
38 private:
39 explicit GpuLabBox(GpuMultires nest) : m_nest(std::move(nest)) {}
40
41 [[nodiscard]] bool RecordCommandUpload(ID3D12GraphicsCommandList10* list, std::span<const Command> commands);
42
44 ComPtr<ID3D12PipelineState> m_applyPipeline;
45 ComPtr<ID3D12Resource> m_commands; // この刻みのコマンドの列(u4)
46 ComPtr<ID3D12Resource> m_commandUpload; // CPU が書く写し
47 uint32_t m_speciesCount = 0;
48 };
49
50} // namespace bicameral::sim
ComPtr< ID3D12Resource > m_commands
Definition gpu_lab_box.h:45
GpuLabBox(GpuMultires nest)
Definition gpu_lab_box.h:39
void RecordReadback(ID3D12GraphicsCommandList10 *list)
Definition gpu_lab_box.h:35
bool Read(MultiresNest &nest) const
Definition gpu_lab_box.h:36
ComPtr< ID3D12Resource > m_commandUpload
Definition gpu_lab_box.h:46
bool RecordUpload(ID3D12GraphicsCommandList10 *list, const MultiresNest &nest)
ComPtr< ID3D12PipelineState > m_applyPipeline
Definition gpu_lab_box.h:44
static std::expected< GpuLabBox, std::string > Create(ID3D12Device5 *device, const BakedReactionTable &table)
bool RecordCommandUpload(ID3D12GraphicsCommandList10 *list, std::span< const Command > commands)
bool RecordTick(ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing, uint64_t tick, std::span< const Command > commands)