|
Bicameral Engine
GPU-resident engine for a magic-research open-world game
|
#include <gpu_physics.h>
Classes | |
| struct | Constants |
Public Member Functions | |
| void | RecordInitialize (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing) |
| void | RecordStep (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing) |
| void | RecordReadback (ID3D12GraphicsCommandList10 *list) const |
| std::vector< PhysicsBody > | ReadBodies () const |
| GpuPhysicsStats | ReadStats () const |
| uint64_t | Tick () const |
| uint32_t | BodyCount () const |
| ID3D12Resource * | Bodies () const |
| std::span< const ComPtr< ID3D12Resource > > | StateBuffers () const |
| GpuPhysicsCursor | Cursor () const |
| void | SetCursor (const GpuPhysicsCursor &cursor) |
| bool | EnableProfiling (ID3D12Device *device) |
| void | AccumulateProfile () |
| std::vector< GpuPhysicsPassTime > | ProfileResult () const |
Static Public Member Functions | |
| static std::expected< GpuPhysics, std::string > | Create (ID3D12Device5 *device, const PhysicsScene &scene, const physics::PxParameters ¶meters, const GpuPhysicsOptions &options={}) |
| static uint64_t | StateHash (uint64_t tick, const std::vector< PhysicsBody > &bodies) |
Private Types | |
| enum class | Pass : uint8_t { Initialize , BeginSubstep , Broadphase , Narrowphase , PrepareManifolds , ColorRound , FinishColoring , Recollide , SolveColor , UpdateDuals , UpdateVelocity , Finish , BuildManifolds , BroadphaseGraph , SolveColorGraph , Count } |
Private Member Functions | |
| std::expected< void, std::string > | CreatePipelines (ID3D12Device5 *device) |
| std::expected< void, std::string > | CreateBuffers (ID3D12Device5 *device, const PhysicsScene &scene) |
| void | RecordSubstep (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing, uint32_t substep) |
| void | RecordColoring (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing, Constants constants) |
| void | RecordIterations (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing, Constants constants) |
| void | RecordSolveColors (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing, Constants constants) |
| void | RecordColorPredicateStates (ID3D12GraphicsCommandList10 *list, bool toPredication) const |
| bool | SkipsEmptyColors () const |
| void | RecordPass (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing, Pass pass, const Constants &constants, uint32_t threadCount) |
| void | RecordSolveColorGraph (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing, const Constants &constants, int32_t color) |
| void | RecordColorListStates (ID3D12GraphicsCommandList10 *list, bool toGraphInput) const |
| void | SetGraphProgram (ID3D12GraphicsCommandList10 *list) |
| void | RecordBroadphaseGraph (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing, const Constants &constants) |
| void | BindRoot (ID3D12GraphicsCommandList10 *list, D3D12_GPU_VIRTUAL_ADDRESS debugRing, const Constants &constants) const |
| void | RecordProfileStart (ID3D12GraphicsCommandList10 *list) const |
| void | RecordTimestamp (ID3D12GraphicsCommandList10 *list, Pass pass) |
| Constants | BaseConstants () const |
Private Attributes | |
| physics::PxParameters | m_parameters {} |
| GpuPhysicsOptions | m_options |
| uint32_t | m_bodyCount = 0 |
| uint32_t | m_frictionQ16 = 0 |
| uint64_t | m_tick = 0 |
| uint32_t | m_half = 1 |
| ComPtr< ID3D12RootSignature > | m_rootSignature |
| std::array< ComPtr< ID3D12PipelineState >,(size_t) Pass::Count > | m_pipelines |
| std::unique_ptr< gpu::WorkGraph > | m_graph |
| uint32_t | m_broadphaseEntry = 0 |
| uint32_t | m_solveEntry = 0 |
| bool | m_graphInitialized = false |
| bool | m_graphProgramSet = false |
| std::array< ComPtr< ID3D12Resource >, 14 > | m_uavs |
| std::array< ComPtr< ID3D12Resource >, 2 > | m_srvs |
| ComPtr< ID3D12Resource > | m_bodiesReadback |
| ComPtr< ID3D12Resource > | m_statsReadback |
| ComPtr< ID3D12QueryHeap > | m_timestamps |
| ComPtr< ID3D12Resource > | m_timestampReadback |
| std::vector< Pass > | m_profiledPasses |
| std::array< uint64_t,(size_t) Pass::Count > | m_profileCounts {} |
| std::array< uint64_t,(size_t) Pass::Count > | m_profileTicks {} |
Definition at line 74 of file gpu_physics.h.
|
strongprivate |
Definition at line 114 of file gpu_physics.h.
| void bicameral::sim::GpuPhysics::AccumulateProfile | ( | ) |
Definition at line 300 of file gpu_physics.cpp.
References m_profileCounts, m_profiledPasses, m_profileTicks, m_timestampReadback, m_timestamps, and bicameral::gpu::ReadBuffer().
|
nodiscardprivate |
Definition at line 176 of file gpu_physics.cpp.
References m_bodyCount, m_frictionQ16, m_half, m_options, m_solveEntry, m_tick, and m_uavs.
Referenced by RecordInitialize(), and RecordSubstep().
|
private |
Definition at line 257 of file gpu_physics.cpp.
References bicameral::gpu::RootSignatureLayout::DebugRingIndex(), m_srvs, m_uavs, bicameral::gpu::RootSignatureLayout::RootConstantIndex(), bicameral::gpu::RootSignatureLayout::SrvIndex(), and bicameral::gpu::RootSignatureLayout::uavCount.
Referenced by RecordBroadphaseGraph(), RecordPass(), and RecordSolveColorGraph().
|
inlinenodiscard |
Definition at line 93 of file gpu_physics.h.
References m_uavs.
|
inlinenodiscard |
Definition at line 90 of file gpu_physics.h.
References m_bodyCount.
|
staticnodiscard |
Definition at line 75 of file gpu_physics.cpp.
References bicameral::sim::PhysicsScene::bodies, CreateBuffers(), CreatePipelines(), bicameral::sim::PhysicsScene::frictionQ16, m_bodyCount, m_frictionQ16, m_options, m_parameters, and bicameral::sim::GpuPhysicsOptions::slotsPerBody.
Referenced by bicameral::sim::ProbeSim::CreatePhysics().
|
nodiscardprivate |
Definition at line 135 of file gpu_physics.cpp.
References bicameral::sim::PhysicsScene::bodies, bicameral::gpu::CreateBuffer(), m_bodiesReadback, m_bodyCount, m_options, m_parameters, m_srvs, m_statsReadback, m_uavs, bicameral::sim::MakePhysicsBody(), bicameral::gpu::Readback, and bicameral::gpu::UnorderedAccess.
Referenced by Create().
|
nodiscardprivate |
Definition at line 97 of file gpu_physics.cpp.
References bicameral::gpu::WorkGraph::Create(), bicameral::gpu::CreateComputePipeline(), bicameral::gpu::CreateRootSignature(), bicameral::sim::Graph, bicameral::gpu::LoadShader(), m_bodyCount, m_broadphaseEntry, m_graph, m_options, m_pipelines, m_rootSignature, and m_solveEntry.
Referenced by Create().
|
inlinenodiscard |
Definition at line 98 of file gpu_physics.h.
|
nodiscard |
Definition at line 272 of file gpu_physics.cpp.
References bicameral::gpu::CreateBuffer(), m_timestampReadback, m_timestamps, and bicameral::gpu::Readback.
|
nodiscard |
Definition at line 317 of file gpu_physics.cpp.
References Count, m_profileCounts, and m_profileTicks.
|
nodiscard |
Definition at line 459 of file gpu_physics.cpp.
References m_bodiesReadback, m_bodyCount, and bicameral::gpu::ReadBuffer().
|
nodiscard |
Definition at line 467 of file gpu_physics.cpp.
References m_statsReadback, bicameral::sim::GpuPhysicsStats::overflow, and bicameral::gpu::ReadBuffer().
|
private |
Definition at line 204 of file gpu_physics.cpp.
References BindRoot(), BroadphaseGraph, bicameral::gpu::WorkGraph::DispatchFromCpu(), m_bodyCount, m_broadphaseEntry, RecordProfileStart(), RecordTimestamp(), SetGraphProgram(), and bicameral::gpu::UavBarrier().
Referenced by RecordSubstep().
|
private |
Definition at line 378 of file gpu_physics.cpp.
References bicameral::sim::GpuPhysics::Constants::colorIn, ColorRound, FinishColoring, m_bodyCount, m_options, and RecordPass().
Referenced by RecordSubstep().
|
private |
Definition at line 234 of file gpu_physics.cpp.
References m_uavs, and bicameral::gpu::Transition().
Referenced by RecordIterations().
|
private |
Definition at line 441 of file gpu_physics.cpp.
References m_uavs, and bicameral::gpu::Transition().
Referenced by RecordSubstep().
| void bicameral::sim::GpuPhysics::RecordInitialize | ( | ID3D12GraphicsCommandList10 * | list, |
| D3D12_GPU_VIRTUAL_ADDRESS | debugRing ) |
Definition at line 332 of file gpu_physics.cpp.
References BaseConstants(), Initialize, m_bodyCount, m_half, m_tick, and RecordPass().
|
private |
Definition at line 390 of file gpu_physics.cpp.
References bicameral::sim::GpuPhysics::Constants::alphaQ16, bicameral::sim::Graph, m_bodyCount, m_options, m_parameters, Recollide, RecordColorListStates(), RecordPass(), RecordSolveColors(), UpdateDuals, and UpdateVelocity.
Referenced by RecordSubstep().
|
private |
Definition at line 190 of file gpu_physics.cpp.
References BindRoot(), m_graphProgramSet, m_pipelines, m_rootSignature, RecordProfileStart(), RecordTimestamp(), and bicameral::gpu::UavBarrier().
Referenced by RecordColoring(), RecordInitialize(), RecordIterations(), RecordSolveColors(), and RecordSubstep().
|
private |
Definition at line 285 of file gpu_physics.cpp.
References m_profiledPasses, and m_timestamps.
Referenced by RecordBroadphaseGraph(), RecordPass(), and RecordSolveColorGraph().
| void bicameral::sim::GpuPhysics::RecordReadback | ( | ID3D12GraphicsCommandList10 * | list | ) | const |
Definition at line 450 of file gpu_physics.cpp.
References m_bodiesReadback, m_profiledPasses, m_statsReadback, m_timestampReadback, m_timestamps, m_uavs, and bicameral::gpu::RecordCopyToReadback().
|
private |
Definition at line 218 of file gpu_physics.cpp.
References BindRoot(), bicameral::gpu::WorkGraph::DispatchFromGpu(), m_uavs, RecordProfileStart(), RecordTimestamp(), SetGraphProgram(), SolveColorGraph, and bicameral::gpu::UavBarrier().
Referenced by RecordSolveColors().
|
private |
Definition at line 418 of file gpu_physics.cpp.
References bicameral::sim::GpuPhysics::Constants::color, bicameral::sim::Graph, m_bodyCount, m_options, m_uavs, RecordPass(), RecordSolveColorGraph(), SkipsEmptyColors(), and SolveColor.
Referenced by RecordIterations().
| void bicameral::sim::GpuPhysics::RecordStep | ( | ID3D12GraphicsCommandList10 * | list, |
| D3D12_GPU_VIRTUAL_ADDRESS | debugRing ) |
Definition at line 338 of file gpu_physics.cpp.
References m_graphProgramSet, m_parameters, m_tick, and RecordSubstep().
|
private |
Definition at line 347 of file gpu_physics.cpp.
References BaseConstants(), BeginSubstep, Broadphase, BuildManifolds, Finish, m_bodyCount, m_graph, m_half, m_options, Narrowphase, PrepareManifolds, RecordBroadphaseGraph(), RecordColoring(), RecordColorPredicateStates(), RecordIterations(), RecordPass(), bicameral::sim::GpuPhysics::Constants::resetStats, and SkipsEmptyColors().
Referenced by RecordStep().
|
private |
Definition at line 291 of file gpu_physics.cpp.
References m_profiledPasses, and m_timestamps.
Referenced by RecordBroadphaseGraph(), RecordPass(), and RecordSolveColorGraph().
|
inline |
Definition at line 99 of file gpu_physics.h.
References bicameral::sim::GpuPhysicsCursor::currentHalf, m_half, m_tick, and bicameral::sim::GpuPhysicsCursor::tick.
|
private |
Definition at line 246 of file gpu_physics.cpp.
References m_graph, m_graphInitialized, m_graphProgramSet, and m_rootSignature.
Referenced by RecordBroadphaseGraph(), and RecordSolveColorGraph().
|
inlinenodiscardprivate |
Definition at line 161 of file gpu_physics.h.
References bicameral::sim::Compute, and m_options.
Referenced by RecordSolveColors(), and RecordSubstep().
|
inlinenodiscard |
Definition at line 97 of file gpu_physics.h.
References m_uavs.
|
staticnodiscard |
Definition at line 475 of file gpu_physics.cpp.
|
inlinenodiscard |
Definition at line 89 of file gpu_physics.h.
References m_tick.
|
private |
Definition at line 194 of file gpu_physics.h.
Referenced by CreateBuffers(), ReadBodies(), and RecordReadback().
|
private |
Definition at line 180 of file gpu_physics.h.
Referenced by BaseConstants(), BodyCount(), Create(), CreateBuffers(), CreatePipelines(), ReadBodies(), RecordBroadphaseGraph(), RecordColoring(), RecordInitialize(), RecordIterations(), RecordSolveColors(), and RecordSubstep().
|
private |
Definition at line 188 of file gpu_physics.h.
Referenced by CreatePipelines(), and RecordBroadphaseGraph().
|
private |
Definition at line 181 of file gpu_physics.h.
Referenced by BaseConstants(), and Create().
|
private |
Definition at line 187 of file gpu_physics.h.
Referenced by CreatePipelines(), RecordSubstep(), and SetGraphProgram().
|
private |
Definition at line 190 of file gpu_physics.h.
Referenced by SetGraphProgram().
|
private |
Definition at line 191 of file gpu_physics.h.
Referenced by RecordPass(), RecordStep(), and SetGraphProgram().
|
private |
Definition at line 183 of file gpu_physics.h.
Referenced by BaseConstants(), Cursor(), RecordInitialize(), RecordSubstep(), and SetCursor().
|
private |
Definition at line 179 of file gpu_physics.h.
Referenced by BaseConstants(), Create(), CreateBuffers(), CreatePipelines(), RecordColoring(), RecordIterations(), RecordSolveColors(), RecordSubstep(), and SkipsEmptyColors().
|
private |
Definition at line 178 of file gpu_physics.h.
Referenced by Create(), CreateBuffers(), RecordIterations(), and RecordStep().
|
private |
Definition at line 186 of file gpu_physics.h.
Referenced by CreatePipelines(), and RecordPass().
|
private |
Definition at line 201 of file gpu_physics.h.
Referenced by AccumulateProfile(), and ProfileResult().
|
private |
Definition at line 200 of file gpu_physics.h.
Referenced by AccumulateProfile(), RecordProfileStart(), RecordReadback(), and RecordTimestamp().
|
private |
Definition at line 202 of file gpu_physics.h.
Referenced by AccumulateProfile(), and ProfileResult().
|
private |
Definition at line 185 of file gpu_physics.h.
Referenced by CreatePipelines(), RecordPass(), and SetGraphProgram().
|
private |
Definition at line 189 of file gpu_physics.h.
Referenced by BaseConstants(), and CreatePipelines().
|
private |
Definition at line 193 of file gpu_physics.h.
Referenced by BindRoot(), and CreateBuffers().
|
private |
Definition at line 195 of file gpu_physics.h.
Referenced by CreateBuffers(), ReadStats(), and RecordReadback().
|
private |
Definition at line 182 of file gpu_physics.h.
Referenced by BaseConstants(), Cursor(), RecordInitialize(), RecordStep(), SetCursor(), and Tick().
|
private |
Definition at line 199 of file gpu_physics.h.
Referenced by AccumulateProfile(), EnableProfiling(), and RecordReadback().
|
private |
Definition at line 198 of file gpu_physics.h.
Referenced by AccumulateProfile(), EnableProfiling(), RecordProfileStart(), RecordReadback(), and RecordTimestamp().
|
private |
Definition at line 192 of file gpu_physics.h.
Referenced by BaseConstants(), BindRoot(), Bodies(), CreateBuffers(), RecordColorListStates(), RecordColorPredicateStates(), RecordReadback(), RecordSolveColorGraph(), RecordSolveColors(), and StateBuffers().