public void BindMemory(SoftwareDeviceMemory memory, int memoryOffset) { this.m_deviceMemory = memory; this.m_memoryOffset = memoryOffset; if (createInfo.usage.HasFlag(VkBufferUsageFlagBits.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT)) { m_VertexBufferCache = new VertexBufferCache(memory.m_bytes, memoryOffset); } }
protected virtual void ProcessVertexBuffer(DynamicModelContent dynamicModel, ContentProcessorContext context, DynamicModelMeshPartContent part) { if (VertexBufferType != DynamicModelContent.BufferType.Default) { // Replace the default VertexBufferContent with CpuAnimatedVertexBufferContent. if (!VertexBufferCache.TryGetValue(part.VertexBuffer, out var vb)) { vb = part.VertexBuffer; vb.IsWriteOnly = VertexBufferType == DynamicModelContent.BufferType.DynamicWriteOnly; VertexBufferCache[part.VertexBuffer] = vb; } part.VertexBuffer = vb; } }
public void Flush(CommandList cl) { var posInBuffer = bufferPos % buffer.Length; var bufferCount = (bufferPos - posInBuffer) / buffer.Length + 1; if (posInBuffer == 0) { bufferCount--; posInBuffer = buffer.Length; } if (bufferCount == 0) { return; } while (VertexBufferCache.Count < bufferCount) { var newBuffer = Factory.CreateBuffer(new BufferDescription((uint)(buffer.Length * itemSizeInBytes), BufferUsage.VertexBuffer | BufferUsage.Dynamic)); VertexBufferCache.Add(newBuffer); } var bufferToWrite = VertexBufferCache[bufferCount - 1]; lock (GraphicsDevice) GraphicsDevice.UpdateBuffer(bufferToWrite, 0, ref buffer[0], (uint)(posInBuffer * itemSizeInBytes)); cl.SetVertexBuffer(0, bufferToWrite); if (indices == null) { cl.Draw((uint)posInBuffer); } else { cl.SetIndexBuffer(IndexBuffer, IndexFormat.UInt32); if (posInBuffer % vertsPerShape != 0) { throw new Exception("Submitted an incomplete shape to the buffer flushing"); } cl.DrawIndexed((uint)(posInBuffer / vertsPerShape * indicesPerShape)); } }