Skip to content

Commit

Permalink
improve ogre2 gpu rays perf
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Jan 12, 2024
1 parent eeaf6e8 commit 00dd53f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
45 changes: 45 additions & 0 deletions ogre2/src/Ogre2GpuRays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <gz/math/Vector3.hh>

#include <gz/common/Console.hh>
#include <gz/common/Timer.hh>
#include <gz/math/Helpers.hh>

#include "gz/rendering/ogre2/Ogre2Camera.hh"
Expand Down Expand Up @@ -230,6 +231,10 @@ Ogre2LaserRetroMaterialSwitcher::Ogre2LaserRetroMaterialSwitcher(
void Ogre2LaserRetroMaterialSwitcher::passPreExecute(
Ogre::CompositorPass *_pass)
{
common::Timer t;
t.Start();


if(_pass->getDefinition()->mIdentifier == kLaserRetro1stPassQuad)
{
GZ_ASSERT(dynamic_cast<Ogre::CompositorPassQuad *>(_pass),
Expand Down Expand Up @@ -485,12 +490,17 @@ void Ogre2LaserRetroMaterialSwitcher::passPreExecute(

// Remove the reference count on noBlend we created
hlmsManager->destroyBlendblock(noBlend);

t.Stop();
// std::cerr << " Ogre2GpuRays passPre " << t.ElapsedTime().count() << std::endl;
}

//////////////////////////////////////////////////
void Ogre2LaserRetroMaterialSwitcher::passPosExecute(
Ogre::CompositorPass *_pass)
{
common::Timer t;
t.Start();
if(_pass->getDefinition()->mIdentifier != kLaserRetroMainDepthPassId)
return;

Expand Down Expand Up @@ -546,6 +556,10 @@ void Ogre2LaserRetroMaterialSwitcher::passPosExecute(
}

engine->SetGzOgreRenderingMode(GORM_NORMAL);

t.Stop();
// std::cerr << " Ogre2GpuRays passPost " << t.ElapsedTime().count() << std::endl;

}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -1204,6 +1218,10 @@ void Ogre2GpuRays::CreateGpuRaysTextures()
/////////////////////////////////////////////////
void Ogre2GpuRays::UpdateRenderTarget1stPass()
{

common::Timer t;
t.Start();

Ogre::vector<Ogre::TextureGpu *>::type swappedTargets;
swappedTargets.reserve(2u);

Expand All @@ -1218,7 +1236,13 @@ void Ogre2GpuRays::UpdateRenderTarget1stPass()

this->dataPtr->ogreCompositorWorkspace1st[i]->_validateFinalTarget();
this->dataPtr->ogreCompositorWorkspace1st[i]->_beginUpdate(false);

common::Timer t2;
t2.Start();
this->dataPtr->ogreCompositorWorkspace1st[i]->_update();
t2.Stop();
// std::cerr << " Ogre2GpuRays 1stPass _update " << t2.ElapsedTime().count() << std::endl;

this->dataPtr->ogreCompositorWorkspace1st[i]->_endUpdate(false);

swappedTargets.clear();
Expand All @@ -1227,11 +1251,18 @@ void Ogre2GpuRays::UpdateRenderTarget1stPass()

this->dataPtr->ogreCompositorWorkspace1st[i]->setEnabled(false);
}

t.Stop();
// std::cerr << " Ogre2GpuRays 1stPass " << t.ElapsedTime().count() << " : " << this->dataPtr->cubeFaceIdx.size() << std::endl;
}

/////////////////////////////////////////////////
void Ogre2GpuRays::UpdateRenderTarget2ndPass()
{
common::Timer t;
t.Start();


this->dataPtr->ogreCompositorWorkspace2nd->_validateFinalTarget();
this->dataPtr->ogreCompositorWorkspace2nd->_beginUpdate(false);
this->dataPtr->ogreCompositorWorkspace2nd->_update();
Expand All @@ -1240,11 +1271,16 @@ void Ogre2GpuRays::UpdateRenderTarget2ndPass()
Ogre::vector<Ogre::TextureGpu *>::type swappedTargets;
swappedTargets.reserve(2u);
this->dataPtr->ogreCompositorWorkspace2nd->_swapFinalTarget(swappedTargets);

t.Stop();
// std::cerr << " Ogre2GpuRays 2ndPass " << t.ElapsedTime().count() << std::endl;
}

//////////////////////////////////////////////////
void Ogre2GpuRays::Render()
{
common::Timer t;
t.Start();
this->scene->StartRendering(this->dataPtr->ogreCamera);

auto engine = Ogre2RenderEngine::Instance();
Expand All @@ -1264,6 +1300,9 @@ void Ogre2GpuRays::Render()
hlmsCustomizations.minDistanceClip = -1;

this->scene->FlushGpuCommandsAndStartNewFrame(6u, false);
t.Stop();
// std::cerr << "============================================= Ogre2GpuRays Render() " << t.ElapsedTime().count() << std::endl;
std::cerr << t.ElapsedTime().count() << std::endl;
}

//////////////////////////////////////////////////
Expand All @@ -1276,6 +1315,9 @@ void Ogre2GpuRays::PreRender()
//////////////////////////////////////////////////
void Ogre2GpuRays::PostRender()
{
common::Timer t;
t.Start();

unsigned int width = this->dataPtr->w2nd;
unsigned int height = this->dataPtr->h2nd;

Expand Down Expand Up @@ -1341,6 +1383,9 @@ void Ogre2GpuRays::PostRender()
this->dataPtr->newGpuRaysFrame(this->dataPtr->gpuRaysScan,
width, height, this->Channels(), "PF_FLOAT32_RGB");

t.Stop();
// std::cerr << "Ogre2GpuRays PostRender() " << t.ElapsedTime().count() << " : " << width << "x" << height << std::endl;

// Uncomment to debug output
// std::cerr << "wxh: " << width << " x " << height << std::endl;
// for (unsigned int i = 0; i < height; ++i)
Expand Down
5 changes: 5 additions & 0 deletions ogre2/src/Ogre2RenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <gz/common/Console.hh>
#include <gz/common/Timer.hh>

#include "gz/rendering/Material.hh"

Expand Down Expand Up @@ -430,9 +431,13 @@ void Ogre2RenderTarget::Copy(Image &_image) const
}
else
{
common::Timer t;
t.Start();
dstBox.data = _image.Data();
Ogre::Image2::copyContentsToMemory(
texture, texture->getEmptyBox(0u), dstBox, dstOgrePf);
t.Stop();
std::cerr << "Ogre2RenderTarget copyContents " << t.ElapsedTime().count() << std::endl;
}
}

Expand Down
8 changes: 7 additions & 1 deletion ogre2/src/media/materials/scripts/GpuRays.compositor
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ compositor_node GpuRays1stPass
// kLaserRetroMainDepthPassId
identifier 9525

// IGN_VISIBILITY_ALL & ~Ogre2ParticleEmitter::kParticleVisibilityFlags
// GZ_VISIBILITY_ALL & ~Ogre2ParticleEmitter::kParticleVisibilityFlags
visibility_mask 0xFEFFFFF

enable_forwardplus no
light_visibility_mask 0x0

profiling_id "GpuRays1stPass Color"
}
}
Expand All @@ -53,6 +56,9 @@ compositor_node GpuRays1stPass
// Ogre2ParticleEmitter::kParticleVisibilityFlags
visibility_mask 0x00100000

enable_forwardplus no
light_visibility_mask 0x0

profiling_id "GpuRays1stPass Particle"
}
}
Expand Down

0 comments on commit 00dd53f

Please sign in to comment.