![]() |
VR-Forces Developer's Guide
|
Interface for GPU compute operations driving the ballistic simulation pipeline.
Manages all compute shader dispatches (trajectory update, octree build, frustum cull, proximity queries) and the associated SSBO/UBO GPU buffers. Instantiated via the DtBallisticComputeComponentCreator factory.

Public Types | |
| enum | CullMode { CullMode::Octree, CullMode::BruteForce } |
| enum | QueryMode { QueryMode::Octree, QueryMode::BruteForce } |
| using | SlotReleasedCallback = std::function< void(int slotIndex)> |
Public Member Functions | |
| virtual std::string | buildShaderPreamble () const |
| virtual | ~DtBallisticComputeComponent () |
| virtual void | slot_reloadShaders () |
| virtual void | slot_windSpeedChanged (float metersPerSecond) |
| virtual void | slot_windDirectionChanged (float radians) |
| virtual void | execute () |
| virtual void | update (osg::RenderInfo &renderInfo) |
| virtual void | apply (osg::RenderInfo &renderInfo) |
| virtual void | releaseGLObjects (osg::State *state) |
| virtual bool | shouldDraw (bool isShadowPass) |
| virtual void | drainReleasedSlots (SlotReleasedCallback callback) |
| virtual void | setSimulationActive (bool active) |
| virtual void | beginFrame () |
| virtual void | insertFrameFence () |
| virtual void | pollReadback () |
| virtual void | pollQueryReadback () |
| virtual void | writeSpawnData (int slotIndex, const BulletSpawn &spawn) |
| virtual uint32_t | registerTracerDefinition (const DtTracerDefinition &def, const float otherData0[4]) |
| virtual void | unregisterTracerDefinition (uint32_t index) |
| virtual void | setSlotActive (int slotIndex, uint32_t active) |
| virtual void | deactivateSlot (int slotIndex) |
| virtual void | updateEnvironment (float gravity, float windSpeed, float windDirection, float deltaTime, double currentTime) |
| virtual void | dispatchTrajectoryUpdate () |
| virtual void | dispatchOctreeBuild () |
| virtual void | dispatchSoundQuery (DtOsgBallisticManager *mgr) |
| virtual void | bindGlobalCullBuffers () |
| virtual void | bindGlobalDrawBuffers () |
| virtual void | drainSoundTriggers (std::function< void(const std::vector< std::vector< DtBallisticSoundTrigger >> &)> callback) |
| virtual void | unbindCullBuffers () |
| virtual void | unbindDrawBuffers () |
| virtual void | initIndirectDrawCommands (GLuint indexCount) |
| virtual void | setFrustumCullMode (CullMode mode) |
| virtual CullMode | frustumCullMode () const |
| virtual void | setProximityQueryMode (QueryMode mode) |
| virtual QueryMode | proximityQueryMode () const |
| virtual void | setGravity (float gravity) |
| virtual float | gravity () const |
| virtual void | setMaxQueryResults (int n) |
| virtual void | dispatchFrustumCull () |
| virtual void | dispatchOctreeCull () |
| virtual void | dispatchGatherActiveFlags () |
| virtual void | bindProjectileBuffer (unsigned int bindingPoint) |
| virtual DtBallisticDrawComponent * | drawComponent () const |
| virtual void | debugDumpBuffers () |
| virtual void | debugDrawCullResults (DtGlBuffer *visibleSSBO) |
| virtual void | debugDrawPositions () |
| virtual void | debugDumpCullBuffers (DtGlBuffer *visibleSSBO) |
| virtual void | initializeBuffers () |
| virtual void | doReloadShaders () |
Public Member Functions inherited from makVrv::DtGpuOperation | |
| DtGpuOperation (const std::string &name, DtDe &de) | |
| virtual | ~DtGpuOperation () |
| virtual void | execute (DtGpuArenaUploadState &uploadState) |
Public Attributes | |
| friend | DtBallisticComputeComponentCreator |
Static Public Attributes | |
| static constexpr uint32_t | MAX_BULLETS = 16384 |
Protected Member Functions | |
| DtBallisticComputeComponent (DtDe &de) | |
| virtual void | recomputeOctreeConstants () |
Private Member Functions | |
| DtBallisticComputeComponent ()=delete | |
| DtBallisticComputeComponent (const DtBallisticComputeComponent &rhs)=delete | |
| DtBallisticComputeComponent & | operator= (const DtBallisticComputeComponent &rhs)=delete |
| using makVrv::DtBallisticComputeComponent::SlotReleasedCallback = std::function<void(int slotIndex)> |
Callback type invoked on the CPU thread for each pool slot the GPU has killed.
|
strong |
|
strong |
|
protected |
Protected constructor; use the creator factory to instantiate.
| de | Simulation environment. |
|
privatedelete |
Default construction is not supported.
|
privatedelete |
Copy construction is not supported.
|
virtual |
Virtual destructor.
|
virtual |
Builds the GLSL preamble prepended to every ballistic shader at load time.
Emits #version 460 core followed by #define directives for all pipeline constants, using MAX_BULLETS and myOctreeDepth.
|
privatedelete |
Copy assignment is not supported.
|
virtual |
Schedules a shader reload on the next execute() frame; safe to call from any thread.
|
virtual |
Handles a wind speed changed signal.
| metersPerSecond | New wind speed in meters per second. |
|
virtual |
Handles a wind direction changed signal.
| radians | New wind direction in radians (clockwise from north). |
|
virtual |
Performs all per-frame GPU compute dispatches; must be overridden by concrete subclasses.
Implements makVrv::DtGpuOperation.
|
virtual |
Updates GPU-visible state for the current frame.
|
virtual |
Applies GPU state for the current frame.
|
virtual |
Releases all OpenGL objects associated with this component.
Returns true if this component should execute during shadow passes.
|
virtual |
Drains the pending-release queue and invokes the callback for each released slot.
Must be called from the CPU/simulation thread to safely access DtOsgBallisticManager state.
| callback | Invoked once per released slot index. |
|
virtual |
Called by DtOsgBallisticManager from the sim thread to enable or disable GPU dispatches.
When false, execute() releases any outstanding fences and returns immediately. The manager sets this to true when the first bullet is spawned and to false when the pool is empty and no burst rounds are pending.
|
virtual |
Advances the triple-buffer frame index and binds all persistent buffers.
Must be called once at the start of each GPU execute pass.
|
virtual |
Inserts a GL fence for the current frame's readback buffer slot.
Must be called after all dispatches and buffer copies for the current frame.
|
virtual |
Non-blocking poll of the oldest readback fence on the GPU thread.
When the fence signals, maps the readback buffer and enqueues newly-dead slot indices for delivery via drainReleasedSlots() on the CPU thread.
|
virtual |
Non-blocking poll of the query fence; enqueues sound triggers for drainSoundTriggers().
Called once per execute() after pollReadback().
|
virtual |
Writes spawn data for one pool slot into the SpawnBuffer and marks it live.
| slotIndex | 0-based pool slot index. |
| spawn | Fully populated BulletSpawn structure. |
|
virtual |
Searches live slots in the CPU-side tracer type table for an identical configuration and returns its index, incrementing its reference count. If no match is found, recycles a free slot or appends a new entry. Must be called only from the simulation thread.
| def | Tracer definition to look up or register. |
| otherData0 | The 4-float array from sgObject::getPerObjectData(). Pass all zeros if SensorFX is not loaded or the pip has not been registered. The values are written into the GPU TracerDefinition struct at the tracer type slot, and the vertex shader reads them to write vpOutOtherData0 for per-tracer SensorFX material selection. |
|
virtual |
Decrements the reference count for the given tracer definition slot.
When the count reaches zero the slot is zeroed and returned to the free list for reuse by a future registerTracerDefinition() call. Must be called only from the simulation thread.
| index | Slot index previously returned by registerTracerDefinition(). |
|
virtual |
Writes the active flag for one StateBuffer slot.
| slotIndex | 0-based pool slot index. |
| active | 1 to mark alive, 0 to mark dead. |
|
virtual |
Atomically deactivates a pool slot on CPU-initiated removal.
Preferred over setSlotActive(slot, 0) when the CPU is explicitly killing a projectile, as it also prevents a redundant release callback on readback.
| slotIndex | 0-based pool slot index. |
|
virtual |
Updates the BallisticEnvironment UBO staging buffer.
| gravity | Gravity magnitude (m/s^2). |
| windSpeed | Wind speed (m/s). |
| windDirection | Wind bearing (radians, clockwise from north). |
| deltaTime | Frame delta time in seconds. |
| currentTime | Absolute simulation time in seconds. |
|
virtual |
Dispatches the trajectory update compute shader.
currentTime is read from the BallisticEnvironment UBO (set each execute()).
|
virtual |
Dispatches the two-pass octree build (bounds pass then insert pass).
|
virtual |
Dispatches the sound proximity query and sort passes for this frame.
| mgr | Ballistic manager; provides observer position cache and sound settings access. |
|
virtual |
Re-binds the global SSBO/UBO targets consumed by cull shaders (SSBO 1,2,3,11 and UBO 0 only – not the per-camera SSBO 7, 13, UBO 1).
Called before each per-camera cull dispatch.
|
virtual |
Re-binds the global SSBO/UBO targets consumed by draw shaders (SSBO 1 only).
Per-camera buffer bindings (SSBO 12, UBO 1) are set up by DtBallisticRendererUserData::bindForDraw().
|
virtual |
Drain all pending sound trigger frame batches; invokes callback on the drained batch.
Must be called from the simulation tick thread in DtOsgBallisticManager::slot_postTick(). Each inner vector is one frame's raw GPU results; the proxy classifies and deduplicates them. Mirrors drainReleasedSlots() but for sound triggers.
| callback | Invoked with all pending per-frame batches. |
|
virtual |
Unbinds all SSBO and UBO binding points used by the ballistic pipeline.
|
virtual |
Unbinds all SSBO and UBO binding points without resetting the active GL program.
Called after the draw pass to restore clean indexed-buffer state while keeping the VirtualProgram's composed program active so OSG tracking stays consistent.
|
virtual |
Stores the mesh index count for use in indirect draw command initialization.
Called once from DtBallisticDrawComponent::initialize() after the bullet mesh is created.
| indexCount | Number of indices in the bullet mesh element buffer. |
|
virtual |
Selects the frustum cull algorithm; takes effect on the next cull dispatch.
|
virtual |
Returns the active frustum cull algorithm.
|
virtual |
Selects the proximity query algorithm; takes effect on the next query dispatch.
|
virtual |
Returns the active proximity query algorithm.
|
virtual |
Sets the gravity magnitude applied to all projectiles (m/s^2).
|
virtual |
Returns the gravity magnitude (m/s^2).
|
virtual |
Sets the maximum query results read back per frame.
Must be called before initializeBuffers() runs (i.e. before the first GPU execute pass). Values less than 1 are clamped to 1; values greater than the GPU sort workgroup size are clamped to that ceiling.
| n | Desired maximum result count. |
|
virtual |
Dispatches the brute-force frustum cull shader for the current camera.
Per-camera UBO and visible/indirect SSBOs must already be bound via bindForCull() on the DtBallisticRendererUserData before calling this.
|
virtual |
Dispatches the two-pass octree frustum cull for the current camera.
Per-camera UBO and visible/indirect SSBOs must already be bound via bindForCull() on the DtBallisticRendererUserData before calling this.
|
virtual |
Dispatches the gather-active-flags shader and copies results to the readback buffer.
|
virtual |
Binds the SpawnBuffer SSBO to an arbitrary binding point.
| bindingPoint | Target SSBO binding point. |
|
virtual |
Returns the shared draw component.
|
virtual |
Debug readback: dumps active bullet state and buffer statistics to stdout.
For debug builds only. Calling this stalls the GPU pipeline.
|
virtual |
Maps the GPU StateBuffer and the provided per-camera VisibleBulletLists SSBO to render a sphere per active bullet.
Green spheres passed the GPU frustum cull; red spheres were culled out. Active when DebugTrajectoryVis is set. Stalls the GPU pipeline – debug use only.
| visibleSSBO | Per-camera visible bullet SSBO. |
|
virtual |
Maps the GPU StateBuffer to render a position-only sphere per active bullet.
All spheres are drawn in orange regardless of cull state. Called by DtBallisticDebugGeometry on every cull pass when DebugTrajectoryVis is set. When ShowTracers is also enabled for the same camera, debugDrawCullResults() is called afterwards (the ShowTracers DtChannelSpecificGroup is a later sibling in the model-set root) and overwrites the same DtDebugShapes name keys with cull-state-colored spheres. Stalls the GPU pipeline – debug use only.
|
virtual |
Dumps visible bullet count and indices for the provided per-camera SSBO to stdout.
Stalls the GPU pipeline – debug use only.
| visibleSSBO | Per-camera visible bullet SSBO. |
|
virtual |
One-time creation of all GPU buffers (SSBOs, UBOs, readback buffers).
Called from execute() on the first frame. Subsequent calls are no-ops. Mirrors the separation used by DtBallisticDrawComponent::initialize().
|
virtual |
Performs the actual GL shader (re)initialization; must be called on the GL thread.
|
protectedvirtual |
Recomputes myLeafCount, myOctreeTotalNodes, myInternalNodeCount, and myBulletsPerLeaf from MAX_BULLETS and myOctreeDepth.
|
static |
Maximum bullet pool slots in SpawnBuffer/StateBuffer. Injected into shaders via buildShaderPreamble().
| friend makVrv::DtBallisticComputeComponent::DtBallisticComputeComponentCreator |
|
protected |
Reference to the simulation environment.
|
protected |
Manages signal connections for wind change notifications.
|
protected |
Current gravity magnitude (m/s^2).
|
protected |
Current wind speed (m/s).
|
protected |
Current wind direction (radians, clockwise from north).
|
protected |
Current octree depth; all derived octree constants are recomputed when this changes.
|
protected |
8^myOctreeDepth leaf nodes.
|
protected |
Total nodes in the uniform octree (breadth-first).
|
protected |
Internal (non-leaf) node count; used to size the node-flags SSBO.
|
protected |
Bullet slots per leaf = MAX_BULLETS / myLeafCount.
|
protected |
Reference to the shared ballistic runtime settings.
|
mutableprotected |
True if the most recent shader compilation failed.
|
protected |
Compute program for trajectory integration.
|
protected |
Compute program for octree bounds calculation.
|
protected |
Compute program for octree structure build.
|
protected |
Compute program for octree bullet insertion.
|
protected |
Compute program for gathering active-flags.
|
protected |
Compute program for brute-force frustum cull.
|
protected |
Compute program for octree internal-node frustum mark pass.
|
protected |
Compute program for octree leaf frustum cull pass.
|
protected |
Compute program for brute-force proximity queries.
|
protected |
Compute program for octree-accelerated proximity queries.
|
protected |
Active frustum cull algorithm.
|
protected |
Active proximity query algorithm.
|
protected |
BallisticEnvironment UBO (gravity, wind, deltaTime, currentTime).
|
protected |
SpawnBuffer SSBO (immutable per-bullet spawn data).
|
protected |
StateBuffer SSBO (GPU-updated per-bullet state).
|
protected |
OctreeBuffer SSBO (octree node array).
|
protected |
OctreeBulletLists SSBO (per-leaf bullet index arrays).
|
protected |
BoundsBuffer SSBO (world AABB for octree root).
|
protected |
NodeCounter SSBO (total node and bullet-list counts).
|
protected |
Dense active-flag output buffer used for CPU readback.
|
protected |
OctreeNodeFlags SSBO (per-node frustum visibility from the mark pass).
|
protected |
TracerDefinitionBuffer SSBO (per-type tracer visual/physical parameters).
|
protected |
CPU-side table of registered tracer types; mirrored to myTracerDefinitionSSBO each frame.
|
protected |
Reference count per entry in myTracerDefTable; zero means the slot is free and available for reuse.
|
protected |
Indices of free slots in myTracerDefTable (reference count == 0), available for reuse.
|
protected |
Triple-buffered CPU-mappable readback buffers (one per frame slot).
|
protected |
GL sync fence per triple-buffer slot.
|
protected |
Current triple-buffer frame slot (cycles 0, 1, 2).
|
protected |
Per-slot CPU liveness tracker; 0 = free, non-zero = frame number when spawned.
Stores the value of (myGlobalFrameCount + 1) at the time writeSpawnData() is called. pollReadback() only considers a slot dead when the readback frame >= the spawn frame, preventing false deaths from stale readback data that predates the spawn.
|
protected |
Monotonically increasing frame counter, incremented once per execute().
|
protected |
Records which global frame wrote each triple-buffer readback slot.
Set in execute() after dispatchGatherActiveFlags(); read in pollReadback() to compare against each slot's spawn frame.
|
protected |
Slot indices confirmed dead by GPU readback, pending CPU-thread processing.
|
protected |
Guards myPendingReleasedSlots for cross-thread access.
|
protected |
Triple-buffer query input – one ProximityQuery per slot.
|
protected |
Triple-buffer query compute results – VRAM; written by sort shader via SSBO.
|
protected |
Triple-buffer query readback – pinned RAM; populated by glCopyNamedBufferSubData; CPU maps this.
|
protected |
GL sync fence per query triple-buffer slot; nullptr until first dispatch.
|
protected |
Sort shader (sort_query_results.cs.glsl).
|
protected |
Maximum result entries to read back per frame; immutable after init.
|
mutableprotected |
One-shot warning flag for dispatchSoundQuery() early-return conditions.
|
protected |
Pending raw sound trigger frame batches enqueued by pollQueryReadback(); drained each tick. Each inner vector is one frame's GPU proximity query results; classification is done by the proxy.
|
protected |
Guards myPendingSoundTriggers for render/sim cross-thread access.
|
protected |
Set from any thread by slot_reloadShaders(); consumed on the GL thread at the top of execute().
|
protected |
True when the manager has active bullets or pending burst rounds. Written by the sim thread via setSimulationActive(); read by the GL thread in execute().
|
protected |
Number of slots currently non-zero in myLifeTracker.
Maintained by writeSpawnData() (+1), deactivateSlot() (-1 if slot was live), and pollReadback() (-1 per newly-dead slot). Used by the octree-overflow warning in execute() to avoid an O(MAX_BULLETS) count_if scan each frame.
|
protected |
Simulation time of the previous execute() call, used to compute deltaTime.
|
protected |
Shared indirect shader manager for loading/caching compute shaders.
|
protected |
True after initializeBuffers() has completed; reset by releaseGLObjects().
|
protected |
Shared draw component; all ballistic geometries reference this single instance.
|
protected |
Mesh index count set by initIndirectDrawCommands(); cached for reference.