BsCommandBuffer.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "RenderAPI/BsCommandBuffer.h"
  4. #include "Managers/BsCommandBufferManager.h"
  5. namespace bs { namespace ct
  6. {
  7. void CommandSyncMask::addDependency(const SPtr<CommandBuffer>& buffer)
  8. {
  9. if (buffer == nullptr)
  10. return;
  11. mMask |= getGlobalQueueMask(buffer->getType(), buffer->getQueueIdx());
  12. }
  13. UINT32 CommandSyncMask::getGlobalQueueMask(GpuQueueType type, UINT32 queueIdx)
  14. {
  15. UINT32 bitShift = 0;
  16. switch (type)
  17. {
  18. case GQT_GRAPHICS:
  19. break;
  20. case GQT_COMPUTE:
  21. bitShift = 8;
  22. break;
  23. case GQT_UPLOAD:
  24. bitShift = 16;
  25. break;
  26. default:
  27. break;
  28. }
  29. return (1 << queueIdx) << bitShift;
  30. }
  31. UINT32 CommandSyncMask::getGlobalQueueIdx(GpuQueueType type, UINT32 queueIdx)
  32. {
  33. switch (type)
  34. {
  35. case GQT_COMPUTE:
  36. return 8 + queueIdx;
  37. case GQT_UPLOAD:
  38. return 16 + queueIdx;
  39. default:
  40. return queueIdx;
  41. }
  42. }
  43. UINT32 CommandSyncMask::getQueueIdxAndType(UINT32 globalQueueIdx, GpuQueueType& type)
  44. {
  45. if(globalQueueIdx >= 16)
  46. {
  47. type = GQT_UPLOAD;
  48. return globalQueueIdx - 16;
  49. }
  50. if(globalQueueIdx >= 8)
  51. {
  52. type = GQT_COMPUTE;
  53. return globalQueueIdx - 8;
  54. }
  55. type = GQT_GRAPHICS;
  56. return globalQueueIdx;
  57. }
  58. CommandBuffer::CommandBuffer(GpuQueueType type, UINT32 deviceIdx, UINT32 queueIdx, bool secondary)
  59. :mType(type), mDeviceIdx(deviceIdx), mQueueIdx(queueIdx), mIsSecondary(secondary)
  60. {
  61. }
  62. SPtr<CommandBuffer> CommandBuffer::create(GpuQueueType type, UINT32 deviceIdx, UINT32 queueIdx,
  63. bool secondary)
  64. {
  65. return CommandBufferManager::instance().create(type, deviceIdx, queueIdx, secondary);
  66. }
  67. }}