Skip to content

Commit

Permalink
[Vulkan] Improve how shared VkCommandPools are recycled.
Browse files Browse the repository at this point in the history
  • Loading branch information
mellinoe committed Apr 13, 2018
1 parent b1cbac3 commit a1ce176
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/Veldrid/Vk/VkGraphicsDevice.cs
Expand Up @@ -247,7 +247,6 @@ private void CheckSubmittedFences()
{
if (sharedPool.IsCached)
{
sharedPool.Reset();
_sharedGraphicsCommandPools.Push(sharedPool);
}
else
Expand Down Expand Up @@ -1203,6 +1202,8 @@ private class SharedCommandPool
{
private readonly VkGraphicsDevice _gd;
private readonly VkCommandPool _pool;
private readonly VkCommandBuffer _cb;

public bool IsCached { get; }

public SharedCommandPool(VkGraphicsDevice gd, bool isCached)
Expand All @@ -1211,27 +1212,27 @@ public SharedCommandPool(VkGraphicsDevice gd, bool isCached)
IsCached = isCached;

VkCommandPoolCreateInfo commandPoolCI = VkCommandPoolCreateInfo.New();
commandPoolCI.flags = VkCommandPoolCreateFlags.Transient;
commandPoolCI.flags = VkCommandPoolCreateFlags.Transient | VkCommandPoolCreateFlags.ResetCommandBuffer;
commandPoolCI.queueFamilyIndex = _gd.GraphicsQueueIndex;
VkResult result = vkCreateCommandPool(_gd.Device, ref commandPoolCI, null, out _pool);
CheckResult(result);
}

public VkCommandBuffer BeginNewCommandBuffer()
{
VkCommandBufferAllocateInfo allocateInfo = VkCommandBufferAllocateInfo.New();
allocateInfo.commandBufferCount = 1;
allocateInfo.level = VkCommandBufferLevel.Primary;
allocateInfo.commandPool = _pool;
VkResult result = vkAllocateCommandBuffers(_gd.Device, ref allocateInfo, out VkCommandBuffer cb);
result = vkAllocateCommandBuffers(_gd.Device, ref allocateInfo, out _cb);
CheckResult(result);
}

public VkCommandBuffer BeginNewCommandBuffer()
{
VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.New();
beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmit;
result = vkBeginCommandBuffer(cb, ref beginInfo);
VkResult result = vkBeginCommandBuffer(_cb, ref beginInfo);
CheckResult(result);

return cb;
return _cb;
}

public void EndAndSubmit(VkCommandBuffer cb)
Expand All @@ -1245,12 +1246,6 @@ public void EndAndSubmit(VkCommandBuffer cb)
}
}

public void Reset()
{
VkResult result = vkResetCommandPool(_gd.Device, _pool, VkCommandPoolResetFlags.None);
CheckResult(result);
}

internal void Destroy()
{
vkDestroyCommandPool(_gd.Device, _pool, null);
Expand Down

0 comments on commit a1ce176

Please sign in to comment.