Cap the number of vertexes per flush.

Might not be realistic, but we crash if we go over.  Pretty unlikely to
happen in real games, but I suppose not impossible.  Happens in the vertex
speed demo (#3106.)
This commit is contained in:
Unknown W. Brackets 2013-10-27 14:43:58 -07:00
parent e5d802e82f
commit 1e65a691f4
4 changed files with 18 additions and 8 deletions

View File

@ -69,9 +69,10 @@ int D3DPrimCount(D3DPRIMITIVETYPE prim, int size) {
}
enum {
DECODED_VERTEX_BUFFER_SIZE = 65536 * 48,
DECODED_INDEX_BUFFER_SIZE = 65536 * 20,
TRANSFORMED_VERTEX_BUFFER_SIZE = 65536 * sizeof(TransformedVertex)
VERTEX_BUFFER_MAX = 65536,
DECODED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * 48,
DECODED_INDEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * 20,
TRANSFORMED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * sizeof(TransformedVertex)
};
@ -90,6 +91,7 @@ TransformDrawEngineDX9::TransformDrawEngineDX9()
textureCache_(0),
framebufferManager_(0),
numDrawCalls(0),
vertexCountInDrawCalls(0),
uvScale(0) {
decimationCounter_ = VERTEXCACHE_DECIMATION_INTERVAL;
// Allocate nicely aligned memory. Maybe graphics drivers will
@ -914,7 +916,7 @@ void TransformDrawEngineDX9::SubmitPrim(void *verts, void *inds, GEPrimitiveType
if (vertexCount == 0)
return; // we ignore zero-sized draw calls.
if (!indexGen.PrimCompatible(prevPrim_, prim) || numDrawCalls >= MAX_DEFERRED_DRAW_CALLS)
if (!indexGen.PrimCompatible(prevPrim_, prim) || numDrawCalls >= MAX_DEFERRED_DRAW_CALLS || vertexCountInDrawCalls + vertexCount > VERTEX_BUFFER_MAX)
Flush();
// TODO: Is this the right thing to do?
@ -951,6 +953,7 @@ void TransformDrawEngineDX9::SubmitPrim(void *verts, void *inds, GEPrimitiveType
uvScale[numDrawCalls] = gstate_c.uv;
}
numDrawCalls++;
vertexCountInDrawCalls += vertexCount;
}
void TransformDrawEngineDX9::DecodeVerts() {
@ -1330,6 +1333,7 @@ rotateVBO:
indexGen.Reset();
collectedVerts = 0;
numDrawCalls = 0;
vertexCountInDrawCalls = 0;
prevPrim_ = GE_PRIM_INVALID;
#ifndef _XBOX

View File

@ -186,6 +186,7 @@ private:
enum { MAX_DEFERRED_DRAW_CALLS = 128 };
DeferredDrawCall drawCalls[MAX_DEFERRED_DRAW_CALLS];
int numDrawCalls;
int vertexCountInDrawCalls;
int decimationCounter_;

View File

@ -99,9 +99,10 @@ const GLuint glprim[8] = {
};
enum {
DECODED_VERTEX_BUFFER_SIZE = 65536 * 48,
DECODED_INDEX_BUFFER_SIZE = 65536 * 20,
TRANSFORMED_VERTEX_BUFFER_SIZE = 65536 * sizeof(TransformedVertex)
VERTEX_BUFFER_MAX = 65536,
DECODED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * 48,
DECODED_INDEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * 20,
TRANSFORMED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * sizeof(TransformedVertex)
};
#define QUAD_INDICES_MAX 32768
@ -123,6 +124,7 @@ TransformDrawEngine::TransformDrawEngine()
textureCache_(0),
framebufferManager_(0),
numDrawCalls(0),
vertexCountInDrawCalls(0),
uvScale(0) {
decimationCounter_ = VERTEXCACHE_DECIMATION_INTERVAL;
// Allocate nicely aligned memory. Maybe graphics drivers will
@ -914,7 +916,7 @@ void TransformDrawEngine::SubmitPrim(void *verts, void *inds, GEPrimitiveType pr
if (vertexCount == 0)
return; // we ignore zero-sized draw calls.
if (!indexGen.PrimCompatible(prevPrim_, prim) || numDrawCalls >= MAX_DEFERRED_DRAW_CALLS)
if (!indexGen.PrimCompatible(prevPrim_, prim) || numDrawCalls >= MAX_DEFERRED_DRAW_CALLS || vertexCountInDrawCalls + vertexCount > VERTEX_BUFFER_MAX)
Flush();
// TODO: Is this the right thing to do?
@ -951,6 +953,7 @@ void TransformDrawEngine::SubmitPrim(void *verts, void *inds, GEPrimitiveType pr
uvScale[numDrawCalls] = gstate_c.uv;
}
numDrawCalls++;
vertexCountInDrawCalls += vertexCount;
}
void TransformDrawEngine::DecodeVerts() {
@ -1326,6 +1329,7 @@ rotateVBO:
indexGen.Reset();
collectedVerts = 0;
numDrawCalls = 0;
vertexCountInDrawCalls = 0;
prevPrim_ = GE_PRIM_INVALID;
#ifndef USING_GLES2

View File

@ -191,6 +191,7 @@ private:
enum { MAX_DEFERRED_DRAW_CALLS = 128 };
DeferredDrawCall drawCalls[MAX_DEFERRED_DRAW_CALLS];
int numDrawCalls;
int vertexCountInDrawCalls;
int decimationCounter_;