MCPcopy Create free account
hub / github.com/carbonengine/trinity / RunSimulation

Method RunSimulation

trinity/Particle/Tr2GpuParticleSystem.cpp:411–454  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Runs physics simulation. Basically executes a single compute shader --------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

409// Runs physics simulation. Basically executes a single compute shader
410// --------------------------------------------------------------------------------------
411void Tr2GpuParticleSystem::RunSimulation( float dt, const Vector3& originShift, Tr2RenderContext& renderContext )
412{
413 m_updateTimer.Begin( renderContext );
414 ON_BLOCK_EXIT( [&] { m_updateTimer.End( renderContext ); } );
415
416 const uint32_t numthreadsX = 16;
417 const uint32_t numthreadsY = 16;
418
419 struct
420 {
421 uint32_t groupX;
422 uint32_t groupY;
423 uint32_t groupZ;
424 float dt;
425
426 Vector3 originShift;
427 uint32_t bufferSize;
428
429 Vector3 turbulenceOffset;
430 float padding1;
431
432 Vector3 turbulenceAnimation;
433 float padding2;
434
435 Vector4 frustumPlanes[6];
436 } updateCB;
437
438 updateCB.groupX = 32;
439 updateCB.groupY = std::max( m_maxParticles / 32 / numthreadsX / numthreadsY, 1u );
440 updateCB.groupZ = std::max( m_maxParticles / 32 / 32 / numthreadsX / numthreadsY, 1u );
441 updateCB.dt = dt;
442 updateCB.originShift = originShift;
443 updateCB.bufferSize = m_particleData->GetCount();
444 updateCB.turbulenceOffset = m_turbulenceOffset;
445 updateCB.turbulenceAnimation = m_turbulenceAnimation;
446
447 for( size_t i = 0; i < 6; ++i )
448 {
449 Tr2Renderer::GetFrustumPlane( i, updateCB.frustumPlanes[i] );
450 }
451 FillAndSetConstants( m_updateCB, updateCB, Tr2RenderContextEnum::COMPUTE_SHADER, Tr2Renderer::GetPerObjectVSStartRegister(), renderContext );
452 Tr2Renderer::RunComputeShader( m_update, BlueSharedString( "ClearCounters" ), 1, 1, 1, renderContext );
453 Tr2Renderer::RunComputeShader( m_update, updateCB.groupX, updateCB.groupY, updateCB.groupZ, renderContext );
454}
455
456// --------------------------------------------------------------------------------------
457// Description:

Callers

nothing calls this directly

Calls 4

FillAndSetConstantsFunction · 0.50
BeginMethod · 0.45
EndMethod · 0.45
GetCountMethod · 0.45

Tested by

no test coverage detected