Fusee icon indicating copy to clipboard operation
Fusee copied to clipboard

Implement update independent rendering (revisited)

Open wrestledBearOnce opened this issue 4 years ago • 4 comments

grafik

wrestledBearOnce avatar Jan 26 '22 12:01 wrestledBearOnce

First small performance test. Code

            var compList = new List<SceneComponent>
            {
                new Transform(),
                MakeEffect.FromDiffuseSpecular(new float4(.5f,0f,.5f,1f)),
                new Cube()
            };


            var rnd = new Random();
            var cube = new Cube();
            for (var i = 0; i < 1000; i++)
            {
                compList.Add(new Transform
                {
                    Translation =
                    new float3(
                    (float)((rnd.NextDouble() * 2.0f) - 1.0f ) * 5.0f,
                    (float)((rnd.NextDouble() * 2.0f) - 1.0f ) * 5.0f,
                    (float)((rnd.NextDouble() * 2.0f) - 1.0f) *  5.0f
                    )
                });
                compList.Add(cube);
            }


            _cubeScene = new SceneContainer
            {
                Children = new List<SceneNode>
                {
                    new SceneNode
                    {
                        Components = compList
                    }
                }
            };

grafik

The GPU usage is usually at 4%. The spike is caused by the Windows Snipping tool

This looks really concerning, we can't render 1000 cubes due to some strange overhead?

wrestledBearOnce avatar Jan 26 '22 17:01 wrestledBearOnce

Disabling the actual draw call leaves us at the max frame rate. The performance loss is somewhere inside the [OnVisit] Render() method

grafik

Disabling nearlly all checks during the actual render call boosts the frame rate quite a bit

grafik

Seems like frustum culling does not hurt the frame rate.

Disabling the globalFXVarCheck and something else boosts the frame rate, again.

grafik

We need to revisit our hot path. Imoh, too much work is done here.

wrestledBearOnce avatar Jan 26 '22 17:01 wrestledBearOnce

private void SetShaderParamT(FxParam param)

can be reworked. Enhance FxParam with an action which is set by the correct SetShaderParam method for the type.

This part can be deleted, as it already happens during creation grafik

wrestledBearOnce avatar Jan 26 '22 18:01 wrestledBearOnce

Some proposals (for myself 😉 )

  • [ ] remove as many branches inside the hot path as possible
  • [ ] remove all exception handling in hot path
  • [ ] replace SetShaderParamT via typeof() with already computed method
  • [ ] do not set shader program / state for each mesh if nothing has changed!
  • [ ] remove all LINQ-statements
  • [ ] remove all for each calls over collections for each collection that does not return a struct when GetEnumerator is called
  • [ ] check GetEnumerator in the scene tranversal if any memory is allocated there
  • [ ] try to use stackalloc and Span/Memory where possible

wrestledBearOnce avatar Jan 26 '22 18:01 wrestledBearOnce