Too many unique state objects?

0

So I've experienced a DirectX issue, and an exception is thrown as describes:

D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS
0x887C0001

The application has exceeded the maximum number of unique state objects per Direct3D device. 
The limit is 4096 for feature levels up to 11.1

And cannot find documentation on this issue. For reference there are only 3 models being draw to screen using Monogame's BasicEffect, each model has less than 50 polygons.

How is this occurring, and how can it be resolved?

c#
directx
monogame
asked on Stack Overflow Oct 25, 2018 by Linas Paz

1 Answer

0

This was the fix that I found most effective:

static void Render(GraphicsDevice gd, ModelMesh mesh) {
    gd.RasterizerState = RasterizerState.CullNone;

    for (int i = 0; i < mesh.MeshParts.Count; i++) {
        int vertexCount = mesh.MeshParts[i].NumVertices;
        VertexBuffer vb = mesh.MeshParts[i].VertexBuffer;
        IndexBuffer ib = mesh.MeshParts[i].IndexBuffer;

        gd.SetVertexBuffer(vb);
        gd.Indices = ib;

        EffectPass pass = mesh.MeshParts[i].Effect.CurrentTechnique.Passes[0];
        pass.Apply();
        int startIndex = mesh.MeshParts[i].StartIndex;
        int primitiveCount = mesh.MeshParts[i].PrimitiveCount;

        gd.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, startIndex, primitiveCount, 0);
    }
answered on Stack Overflow Oct 26, 2018 by Linas Paz

User contributions licensed under CC BY-SA 3.0