21.7 C
New York
Monday, April 28, 2025

Renderization: Analyze the delayed spike in Monogame


The sport I’m doing is having massive peaks as soon as each 10 seconds or so whereas operating. The peaks appeared to correlate with the rubbish assortment (though I can’t be 100% positive), so I assumed that my downside was that I assigned too many issues within the replace perform () (Cache all of the buúres of vertices and indexes, and they don’t load or obtain something whereas the sport is operating, so there must be nothing within the drawing perform () that requests GC).

Anyway, I profiled replace () and drawn () throughout a spike and obtained this:

I’ve highlighted the spike. As you possibly can see, all latency comes from the Draw () perform, and is form ‘prolonged’ in a number of work. So my query is that this:

  • Can the height proceed to be brought on by the rubbish collector? Can I do one thing silly when drawing in Monogame that requires plenty of rubbish assortment?

  • If it have been rubbish assortment, would 100% seem because the replace delay ()? And would it not seem throughout only one image, or will or not it’s prolonged as seen within the profile?

  • What may cause a ‘profile’ of delay that isn’t GC? If establishing uniform shades induced a delay, for instance, it could not seem as peaks. Would it not be fixed by way of the work?

  • I’m utilizing duties for the seek for routes (so Multithreading): if the delay was associated to a way, can I besides that it could seem because the delay () elg?

Extra info:

The peaks disappear after I eradicate the drawing of the land. Drawing the terrain implies drawing plenty of surfacemeshes:

public class SurfaceMesh
{
    public readonly GraphicsDevice graphicsDevice;
    public readonly int vertexCountX;
    public readonly int vertexCountY;

    readonly int triangleCount;

    readonly VertexBuffer vertexBuffer;
    readonly IndexBuffer indexBuffer;

    public SurfaceMesh ( GraphicsDevice graphicsDevice, int nodeCountX, int nodeCountY )
    {
        Debug.Assert(graphicsDevice != null, $"{nameof(SurfaceMesh)} - GraphicsDevice was null.");
        Debug.Assert(nodeCountX > 0, $"{nameof(SurfaceMesh)} - Dimension X ({nodeCountX}) have to be better than zero.");
        Debug.Assert(nodeCountY > 0, $"{nameof(SurfaceMesh)} - Dimension Y ({nodeCountY}) have to be better than zero.");

        this.graphicsDevice = graphicsDevice;
        vertexCountX = nodeCountX + 1;
        vertexCountY = nodeCountY + 1;

        triangleCount = (vertexCountX - 1) * (vertexCountY - 1) * 2;
        int vertexCount = vertexCountX * vertexCountY;
        int indexCount = triangleCount * 3;

        vertexBuffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionColor), vertexCount, BufferUsage.WriteOnly);
        indexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort), indexCount, BufferUsage.WriteOnly);

        ushort() indices = new ushort(indexCount);
        int currentVertexCount = 0;
        for (int x = 0; x 

Setdata () is just referred to as the primary image, so all the things on this class is pretty much as good as static. Surfacemesh will not be created or destroyed whereas the sport is executed.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles