Bicameral Engine
GPU-resident engine for a magic-research open-world game
Loading...
Searching...
No Matches
bicameral::sim::GpuPhysics Class Reference

#include <gpu_physics.h>

Collaboration diagram for bicameral::sim::GpuPhysics:
[legend]

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 &parameters, 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 {}

Detailed Description

Definition at line 74 of file gpu_physics.h.

Member Enumeration Documentation

◆ Pass

enum class bicameral::sim::GpuPhysics::Pass : uint8_t
strongprivate
Enumerator
Initialize 
BeginSubstep 
Broadphase 
Narrowphase 
PrepareManifolds 
ColorRound 
FinishColoring 
Recollide 
SolveColor 
UpdateDuals 
UpdateVelocity 
Finish 
BuildManifolds 
BroadphaseGraph 
SolveColorGraph 
Count 

Definition at line 114 of file gpu_physics.h.

Member Function Documentation

◆ AccumulateProfile()

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().

Here is the call graph for this function:

◆ BaseConstants()

GpuPhysics::Constants bicameral::sim::GpuPhysics::BaseConstants ( ) const
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().

Here is the caller graph for this function:

◆ BindRoot()

void bicameral::sim::GpuPhysics::BindRoot ( ID3D12GraphicsCommandList10 * list,
D3D12_GPU_VIRTUAL_ADDRESS debugRing,
const Constants & constants ) const
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Bodies()

ID3D12Resource * bicameral::sim::GpuPhysics::Bodies ( ) const
inlinenodiscard

Definition at line 93 of file gpu_physics.h.

References m_uavs.

◆ BodyCount()

uint32_t bicameral::sim::GpuPhysics::BodyCount ( ) const
inlinenodiscard

Definition at line 90 of file gpu_physics.h.

References m_bodyCount.

◆ Create()

std::expected< GpuPhysics, std::string > bicameral::sim::GpuPhysics::Create ( ID3D12Device5 * device,
const PhysicsScene & scene,
const physics::PxParameters & parameters,
const GpuPhysicsOptions & options = {} )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateBuffers()

std::expected< void, std::string > bicameral::sim::GpuPhysics::CreateBuffers ( ID3D12Device5 * device,
const PhysicsScene & scene )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreatePipelines()

std::expected< void, std::string > bicameral::sim::GpuPhysics::CreatePipelines ( ID3D12Device5 * device)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cursor()

GpuPhysicsCursor bicameral::sim::GpuPhysics::Cursor ( ) const
inlinenodiscard

Definition at line 98 of file gpu_physics.h.

References m_half, and m_tick.

◆ EnableProfiling()

bool bicameral::sim::GpuPhysics::EnableProfiling ( ID3D12Device * device)
nodiscard

Definition at line 272 of file gpu_physics.cpp.

References bicameral::gpu::CreateBuffer(), m_timestampReadback, m_timestamps, and bicameral::gpu::Readback.

Here is the call graph for this function:

◆ ProfileResult()

std::vector< GpuPhysicsPassTime > bicameral::sim::GpuPhysics::ProfileResult ( ) const
nodiscard

Definition at line 317 of file gpu_physics.cpp.

References Count, m_profileCounts, and m_profileTicks.

◆ ReadBodies()

std::vector< PhysicsBody > bicameral::sim::GpuPhysics::ReadBodies ( ) const
nodiscard

Definition at line 459 of file gpu_physics.cpp.

References m_bodiesReadback, m_bodyCount, and bicameral::gpu::ReadBuffer().

Here is the call graph for this function:

◆ ReadStats()

GpuPhysicsStats bicameral::sim::GpuPhysics::ReadStats ( ) const
nodiscard

Definition at line 467 of file gpu_physics.cpp.

References m_statsReadback, bicameral::sim::GpuPhysicsStats::overflow, and bicameral::gpu::ReadBuffer().

Here is the call graph for this function:

◆ RecordBroadphaseGraph()

void bicameral::sim::GpuPhysics::RecordBroadphaseGraph ( ID3D12GraphicsCommandList10 * list,
D3D12_GPU_VIRTUAL_ADDRESS debugRing,
const Constants & constants )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecordColoring()

void bicameral::sim::GpuPhysics::RecordColoring ( ID3D12GraphicsCommandList10 * list,
D3D12_GPU_VIRTUAL_ADDRESS debugRing,
Constants constants )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecordColorListStates()

void bicameral::sim::GpuPhysics::RecordColorListStates ( ID3D12GraphicsCommandList10 * list,
bool toGraphInput ) const
private

Definition at line 234 of file gpu_physics.cpp.

References m_uavs, and bicameral::gpu::Transition().

Referenced by RecordIterations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecordColorPredicateStates()

void bicameral::sim::GpuPhysics::RecordColorPredicateStates ( ID3D12GraphicsCommandList10 * list,
bool toPredication ) const
private

Definition at line 441 of file gpu_physics.cpp.

References m_uavs, and bicameral::gpu::Transition().

Referenced by RecordSubstep().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecordInitialize()

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().

Here is the call graph for this function:

◆ RecordIterations()

void bicameral::sim::GpuPhysics::RecordIterations ( ID3D12GraphicsCommandList10 * list,
D3D12_GPU_VIRTUAL_ADDRESS debugRing,
Constants constants )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecordPass()

void bicameral::sim::GpuPhysics::RecordPass ( ID3D12GraphicsCommandList10 * list,
D3D12_GPU_VIRTUAL_ADDRESS debugRing,
Pass pass,
const Constants & constants,
uint32_t threadCount )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecordProfileStart()

void bicameral::sim::GpuPhysics::RecordProfileStart ( ID3D12GraphicsCommandList10 * list) const
private

Definition at line 285 of file gpu_physics.cpp.

References m_profiledPasses, and m_timestamps.

Referenced by RecordBroadphaseGraph(), RecordPass(), and RecordSolveColorGraph().

Here is the caller graph for this function:

◆ RecordReadback()

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().

Here is the call graph for this function:

◆ RecordSolveColorGraph()

void bicameral::sim::GpuPhysics::RecordSolveColorGraph ( ID3D12GraphicsCommandList10 * list,
D3D12_GPU_VIRTUAL_ADDRESS debugRing,
const Constants & constants,
int32_t color )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecordSolveColors()

void bicameral::sim::GpuPhysics::RecordSolveColors ( ID3D12GraphicsCommandList10 * list,
D3D12_GPU_VIRTUAL_ADDRESS debugRing,
Constants constants )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecordStep()

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().

Here is the call graph for this function:

◆ RecordSubstep()

void bicameral::sim::GpuPhysics::RecordSubstep ( ID3D12GraphicsCommandList10 * list,
D3D12_GPU_VIRTUAL_ADDRESS debugRing,
uint32_t substep )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecordTimestamp()

void bicameral::sim::GpuPhysics::RecordTimestamp ( ID3D12GraphicsCommandList10 * list,
Pass pass )
private

Definition at line 291 of file gpu_physics.cpp.

References m_profiledPasses, and m_timestamps.

Referenced by RecordBroadphaseGraph(), RecordPass(), and RecordSolveColorGraph().

Here is the caller graph for this function:

◆ SetCursor()

void bicameral::sim::GpuPhysics::SetCursor ( const GpuPhysicsCursor & cursor)
inline

◆ SetGraphProgram()

void bicameral::sim::GpuPhysics::SetGraphProgram ( ID3D12GraphicsCommandList10 * list)
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().

Here is the caller graph for this function:

◆ SkipsEmptyColors()

bool bicameral::sim::GpuPhysics::SkipsEmptyColors ( ) const
inlinenodiscardprivate

Definition at line 161 of file gpu_physics.h.

References bicameral::sim::Compute, and m_options.

Referenced by RecordSolveColors(), and RecordSubstep().

Here is the caller graph for this function:

◆ StateBuffers()

std::span< const ComPtr< ID3D12Resource > > bicameral::sim::GpuPhysics::StateBuffers ( ) const
inlinenodiscard

Definition at line 97 of file gpu_physics.h.

References m_uavs.

◆ StateHash()

uint64_t bicameral::sim::GpuPhysics::StateHash ( uint64_t tick,
const std::vector< PhysicsBody > & bodies )
staticnodiscard

Definition at line 475 of file gpu_physics.cpp.

◆ Tick()

uint64_t bicameral::sim::GpuPhysics::Tick ( ) const
inlinenodiscard

Definition at line 89 of file gpu_physics.h.

References m_tick.

Member Data Documentation

◆ m_bodiesReadback

ComPtr<ID3D12Resource> bicameral::sim::GpuPhysics::m_bodiesReadback
private

Definition at line 194 of file gpu_physics.h.

Referenced by CreateBuffers(), ReadBodies(), and RecordReadback().

◆ m_bodyCount

◆ m_broadphaseEntry

uint32_t bicameral::sim::GpuPhysics::m_broadphaseEntry = 0
private

Definition at line 188 of file gpu_physics.h.

Referenced by CreatePipelines(), and RecordBroadphaseGraph().

◆ m_frictionQ16

uint32_t bicameral::sim::GpuPhysics::m_frictionQ16 = 0
private

Definition at line 181 of file gpu_physics.h.

Referenced by BaseConstants(), and Create().

◆ m_graph

std::unique_ptr<gpu::WorkGraph> bicameral::sim::GpuPhysics::m_graph
private

Definition at line 187 of file gpu_physics.h.

Referenced by CreatePipelines(), RecordSubstep(), and SetGraphProgram().

◆ m_graphInitialized

bool bicameral::sim::GpuPhysics::m_graphInitialized = false
private

Definition at line 190 of file gpu_physics.h.

Referenced by SetGraphProgram().

◆ m_graphProgramSet

bool bicameral::sim::GpuPhysics::m_graphProgramSet = false
private

Definition at line 191 of file gpu_physics.h.

Referenced by RecordPass(), RecordStep(), and SetGraphProgram().

◆ m_half

uint32_t bicameral::sim::GpuPhysics::m_half = 1
private

Definition at line 183 of file gpu_physics.h.

Referenced by BaseConstants(), Cursor(), RecordInitialize(), RecordSubstep(), and SetCursor().

◆ m_options

◆ m_parameters

physics::PxParameters bicameral::sim::GpuPhysics::m_parameters {}
private

Definition at line 178 of file gpu_physics.h.

Referenced by Create(), CreateBuffers(), RecordIterations(), and RecordStep().

◆ m_pipelines

std::array<ComPtr<ID3D12PipelineState>, (size_t)Pass::Count> bicameral::sim::GpuPhysics::m_pipelines
private

Definition at line 186 of file gpu_physics.h.

Referenced by CreatePipelines(), and RecordPass().

◆ m_profileCounts

std::array<uint64_t, (size_t)Pass::Count> bicameral::sim::GpuPhysics::m_profileCounts {}
private

Definition at line 201 of file gpu_physics.h.

Referenced by AccumulateProfile(), and ProfileResult().

◆ m_profiledPasses

std::vector<Pass> bicameral::sim::GpuPhysics::m_profiledPasses
private

◆ m_profileTicks

std::array<uint64_t, (size_t)Pass::Count> bicameral::sim::GpuPhysics::m_profileTicks {}
private

Definition at line 202 of file gpu_physics.h.

Referenced by AccumulateProfile(), and ProfileResult().

◆ m_rootSignature

ComPtr<ID3D12RootSignature> bicameral::sim::GpuPhysics::m_rootSignature
private

Definition at line 185 of file gpu_physics.h.

Referenced by CreatePipelines(), RecordPass(), and SetGraphProgram().

◆ m_solveEntry

uint32_t bicameral::sim::GpuPhysics::m_solveEntry = 0
private

Definition at line 189 of file gpu_physics.h.

Referenced by BaseConstants(), and CreatePipelines().

◆ m_srvs

std::array<ComPtr<ID3D12Resource>, 2> bicameral::sim::GpuPhysics::m_srvs
private

Definition at line 193 of file gpu_physics.h.

Referenced by BindRoot(), and CreateBuffers().

◆ m_statsReadback

ComPtr<ID3D12Resource> bicameral::sim::GpuPhysics::m_statsReadback
private

Definition at line 195 of file gpu_physics.h.

Referenced by CreateBuffers(), ReadStats(), and RecordReadback().

◆ m_tick

uint64_t bicameral::sim::GpuPhysics::m_tick = 0
private

Definition at line 182 of file gpu_physics.h.

Referenced by BaseConstants(), Cursor(), RecordInitialize(), RecordStep(), SetCursor(), and Tick().

◆ m_timestampReadback

ComPtr<ID3D12Resource> bicameral::sim::GpuPhysics::m_timestampReadback
private

Definition at line 199 of file gpu_physics.h.

Referenced by AccumulateProfile(), EnableProfiling(), and RecordReadback().

◆ m_timestamps

ComPtr<ID3D12QueryHeap> bicameral::sim::GpuPhysics::m_timestamps
private

◆ m_uavs

std::array<ComPtr<ID3D12Resource>, 14> bicameral::sim::GpuPhysics::m_uavs
private

The documentation for this class was generated from the following files: