void IBufferGenerator.Reset() { lock (_StateLock) { _FillingHardwareBufferEntry = null; _FlushedToBuffers = 0; _VertexCount = _IndexCount = 0; // Any buffers that remain unused (either from being too small, or being unnecessary now) // should be disposed. THardwareBuffer hb; using (var e = _UnusedHardwareBuffers.GetEnumerator()) while (e.GetNext(out hb)) { hb.Age += 1; bool shouldKill = (hb.Age >= MaxBufferAge) || ((_UnusedHardwareBuffers.Count > MaxUnusedBuffers) && (hb.Age > 1)); if (shouldKill) { e.RemoveCurrent(); hb.Invalidate(); DisposeResource(hb); } } // Return any buffers that were used this frame to the unused state. foreach (var _hb in _UsedHardwareBuffers) { // HACK var hwb = _hb.Buffer; hwb.Invalidate(); _UnusedHardwareBuffers.Add(hwb); } _UsedHardwareBuffers.Clear(); foreach (var swb in _SoftwareBuffers) { swb.Uninitialize(); _SoftwareBufferPool.Release(swb); } _SoftwareBuffers.Clear(); /* * Array.Clear(_VertexArray, 0, _VertexArray.Length); * Array.Clear(_IndexArray, 0, _IndexArray.Length); */ } }
public void Reset(int frameIndex) { lock (_StateLock) { _FillingHardwareBufferEntry = null; _FlushedToBuffers = 0; _VertexCount = _IndexCount = 0; lock (_StaticStateLock) StaticReset(frameIndex, RenderManager); // Return any buffers that were used this frame to the unused state. foreach (var _hb in _UsedHardwareBuffers) { // HACK var hwb = _hb.Buffer; hwb.Invalidate(frameIndex); lock (_StaticStateLock) _UnusedHardwareBuffers.Add(hwb); } _UsedHardwareBuffers.Clear(); _BufferCache.Clear(); foreach (var swb in _SoftwareBuffers) { swb.Uninitialize(); _SoftwareBufferPool.Release(swb); } _SoftwareBuffers.Clear(); _LastFrameReset = frameIndex; /* * Array.Clear(_VertexArray, 0, _VertexArray.Length); * Array.Clear(_IndexArray, 0, _IndexArray.Length); */ } }
public void Reset(int frameIndex) { var id = RenderManager.DeviceManager.DeviceId; lock (_StateLock) { _FillingHardwareBufferEntry = null; _FlushedToBuffers = 0; _VertexCount = _IndexCount = 0; lock (_StaticStateLock) StaticReset(frameIndex, RenderManager); foreach (var _hb in _PreviouslyUsedHardwareBufferEntries) { _ReusableHardwareBufferEntries.Add(_hb); } _PreviouslyUsedHardwareBufferEntries.Clear(); // Return any buffers that were used this frame to the unused state. foreach (var _hb in _UsedHardwareBufferEntries) { _hb.AddedToList = false; _PreviouslyUsedHardwareBufferEntries.Add(_hb); // HACK var hwb = _hb.Buffer; if (hwb.DeviceId < id) { continue; } hwb.Invalidate(frameIndex); lock (_StaticStateLock) { if (hwb.IsLarge) { _LargeUnusedBufferCount++; } else { _SmallUnusedBufferCount++; } _UnusedHardwareBuffers.Add(hwb); } } _UsedHardwareBufferEntries.Clear(); foreach (var kvp in _BufferCache) { var swb = kvp.Value; if (!swb.IsInitialized) { continue; } // Console.WriteLine($"Uninit corner buffer {swb}"); swb.Uninitialize(); _SoftwareBufferPool.Release(swb); } _BufferCache.Clear(); foreach (var swb in _SoftwareBuffers) { if (!swb.IsInitialized) { continue; } swb.Uninitialize(); _SoftwareBufferPool.Release(swb); } _SoftwareBuffers.Clear(); _LastFrameReset = frameIndex; /* * Array.Clear(_VertexArray, 0, _VertexArray.Length); * Array.Clear(_IndexArray, 0, _IndexArray.Length); */ } }