BsVulkanCommandBufferManager.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsVulkanCommandBufferManager.h"
  4. #include "BsVulkanCommandBuffer.h"
  5. #include "BsVulkanRenderAPI.h"
  6. namespace BansheeEngine
  7. {
  8. VulkanCommandBufferManager::VulkanCommandBufferManager(const VulkanRenderAPI& rapi)
  9. :mRapi(rapi)
  10. { }
  11. VulkanCommandBufferManager::~VulkanCommandBufferManager()
  12. {
  13. }
  14. SPtr<CommandBuffer> VulkanCommandBufferManager::createInternal(UINT32 id, GpuQueueType type, UINT32 deviceIdx,
  15. UINT32 queueIdx, bool secondary)
  16. {
  17. UINT32 numDevices = mRapi._getNumDevices();
  18. if(deviceIdx >= numDevices)
  19. {
  20. LOGERR("Cannot create command buffer, invalid device index: " + toString(deviceIdx) +
  21. ". Valid range: [0, " + toString(numDevices) + ").");
  22. return nullptr;
  23. }
  24. SPtr<VulkanDevice> device = mRapi._getDevice(deviceIdx);
  25. CommandBuffer* buffer =
  26. new (bs_alloc<VulkanCommandBuffer>()) VulkanCommandBuffer(*device, id, type, deviceIdx, queueIdx, secondary);
  27. return bs_shared_ptr(buffer);
  28. }
  29. void VulkanCommandBufferManager::getSyncSemaphores(UINT32 deviceIdx, UINT32 syncMask,
  30. VkSemaphore(&semaphores)[BS_MAX_COMMAND_BUFFERS], UINT32& count)
  31. {
  32. assert(deviceIdx < BS_MAX_DEVICES);
  33. UINT32 semaphoreIdx = 0;
  34. for (UINT32 i = 0; i < BS_MAX_COMMAND_BUFFERS; i++)
  35. {
  36. if (mActiveCommandBuffers[deviceIdx][i] == nullptr) // Command buffer doesn't exist
  37. continue;
  38. VulkanCommandBuffer* cmdBuffer = static_cast<VulkanCommandBuffer*>(mActiveCommandBuffers[deviceIdx][i]);
  39. UINT32 globalQueueIdx = CommandSyncMask::getGlobalQueueIdx(cmdBuffer->getType(), cmdBuffer->getQueueIdx());
  40. if ((syncMask & (1 << globalQueueIdx)) == 0) // We don't care about the command buffer
  41. continue;
  42. VulkanCmdBuffer* lowLevelCmdBuffer = cmdBuffer->mSubmittedBuffer;
  43. if (lowLevelCmdBuffer == nullptr || !lowLevelCmdBuffer->isSubmitted()) // If not submitted, no need to sync with it
  44. continue;
  45. semaphores[semaphoreIdx++] = lowLevelCmdBuffer->getSemaphore();
  46. }
  47. count = semaphoreIdx;
  48. }
  49. void VulkanCommandBufferManager::refreshStates(UINT32 deviceIdx)
  50. {
  51. assert(deviceIdx < BS_MAX_DEVICES);
  52. UINT32 semaphoreIdx = 0;
  53. for (UINT32 i = 0; i < BS_MAX_COMMAND_BUFFERS; i++)
  54. {
  55. if (mActiveCommandBuffers[deviceIdx][i] == nullptr) // Command buffer doesn't exist
  56. continue;
  57. VulkanCommandBuffer* cmdBuffer = static_cast<VulkanCommandBuffer*>(mActiveCommandBuffers[deviceIdx][i]);
  58. cmdBuffer->refreshSubmitStatus();
  59. }
  60. }
  61. }