Prevent re-entrancy into VertexBatch.Draw()

This commit is contained in:
Dan Balasescu
2023-07-26 22:00:08 +09:00
parent 0e256ec888
commit 5ee5355c46
2 changed files with 16 additions and 20 deletions

View File

@@ -105,27 +105,27 @@ namespace osu.Framework.Graphics.OpenGL.Batches
public int Draw()
{
if (currentVertexIndex == 0)
int countToDraw = currentVertexIndex;
currentVertexIndex = 0;
if (countToDraw == 0)
return 0;
GLVertexBuffer<T> vertexBuffer = currentVertexBuffer;
if (changeBeginIndex >= 0)
vertexBuffer.UpdateRange(changeBeginIndex, changeEndIndex);
vertexBuffer.DrawRange(0, currentVertexIndex);
int count = currentVertexIndex;
vertexBuffer.DrawRange(0, countToDraw);
// When using multiple buffers we advance to the next one with every draw to prevent contention on the same buffer with future vertex updates.
//TODO: let us know if we exceed and roll over to zero here.
currentBufferIndex = (currentBufferIndex + 1) % maxBuffers;
currentVertexIndex = 0;
changeBeginIndex = -1;
FrameStatistics.Increment(StatisticsCounterType.DrawCalls);
FrameStatistics.Add(StatisticsCounterType.VerticesDraw, count);
FrameStatistics.Add(StatisticsCounterType.VerticesDraw, countToDraw);
return count;
return countToDraw;
}
}
}

View File

@@ -144,33 +144,29 @@ namespace osu.Framework.Graphics.Veldrid.Batches
public int Draw()
{
if (currentVertexIndex == currentDrawIndex)
int countToDraw = currentVertexIndex - currentDrawIndex;
int drawStartIndex = currentDrawIndex;
currentDrawIndex = currentVertexIndex;
if (countToDraw == 0)
return 0;
var buffers = currentVertexBuffers;
if (buffers.Count == 0)
return 0;
int verticesCount = currentVertexIndex - currentDrawIndex;
IVeldridVertexBuffer<T> buffer = buffers[currentBufferIndex];
IVeldridVertexBuffer<T> buffer = currentVertexBuffers[currentBufferIndex];
if (synchronisationBeginIndex >= 0)
buffer.UpdateRange(synchronisationBeginIndex, synchronisationEndIndex);
renderer.BindVertexBuffer(buffer);
renderer.BindIndexBuffer(indexLayout, Size);
renderer.DrawVertices(primitiveType, currentDrawIndex, verticesCount);
renderer.DrawVertices(primitiveType, drawStartIndex, countToDraw);
// When using multiple buffers we advance to the next one with every draw to prevent contention on the same buffer with future vertex updates.
currentDrawIndex = currentVertexIndex;
synchronisationBeginIndex = -1;
FrameStatistics.Increment(StatisticsCounterType.DrawCalls);
FrameStatistics.Add(StatisticsCounterType.VerticesDraw, verticesCount);
FrameStatistics.Add(StatisticsCounterType.VerticesDraw, countToDraw);
return verticesCount;
return countToDraw;
}
}
}