BsCommandBuffer.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. namespace bs { namespace ct
  6. {
  7. /** @addtogroup RenderAPI
  8. * @{
  9. */
  10. /** Mask that determines synchronization between command buffers executing on different hardware queues. */
  11. class BS_CORE_EXPORT CommandSyncMask
  12. {
  13. public:
  14. /**
  15. * Registers a dependency on a command buffer. Use getMask() to get the new mask value after registering all
  16. * dependencies.
  17. */
  18. void addDependency(const SPtr<CommandBuffer>& buffer);
  19. /** Returns a combined mask that contains all the required dependencies. */
  20. UINT32 getMask() const { return mMask; }
  21. /** Uses the queue type and index to generate a mask with a bit set for that queue's global index. */
  22. static UINT32 getGlobalQueueMask(GpuQueueType type, UINT32 queueIdx);
  23. /** Uses the queue type and index to generate a global queue index. */
  24. static UINT32 getGlobalQueueIdx(GpuQueueType type, UINT32 queueIdx);
  25. /** Uses the global queue index to retrieve local queue index and queue type. */
  26. static UINT32 getQueueIdxAndType(UINT32 globalQueueIdx, GpuQueueType& type);
  27. private:
  28. UINT32 mMask = 0;
  29. };
  30. /**
  31. * Contains a list of render API commands that can be queued for execution on the GPU. User is allowed to populate the
  32. * command buffer from any thread, ensuring render API command generation can be multi-threaded. Command buffers
  33. * must always be created on the core thread. Same command buffer cannot be used on multiple threads simulateously
  34. * without external synchronization.
  35. */
  36. class BS_CORE_EXPORT CommandBuffer
  37. {
  38. public:
  39. virtual ~CommandBuffer() { }
  40. /**
  41. * Creates a new CommandBuffer.
  42. *
  43. * @param[in] type Determines what type of commands can be added to the command buffer.
  44. * @param[in] deviceIdx Index of the GPU the command buffer will be used to queue commands on. 0 is always
  45. * the primary available GPU.
  46. * @param[in] queueIdx Index of the GPU queue the command buffer will be used on. Command buffers with
  47. * the same index will execute sequentially, but command buffers with different queue
  48. * indices may execute in parallel, for a potential performance improvement.
  49. *
  50. * Caller must ensure to synchronize operations executing on different queues via
  51. * sync masks. Command buffer dependant on another command buffer should provide a sync
  52. * mask when being submitted (see RenderAPI::executeCommands).
  53. *
  54. * Queue indices are unique per buffer type (e.g. upload index 0 and graphics index 0 may
  55. * map to different queues internally). Must be in range [0, 7].
  56. * @param[in] secondary If true the command buffer will not be allowed to execute on its own, but it can
  57. * be appended to a primary command buffer.
  58. * @return New CommandBuffer instance.
  59. */
  60. static SPtr<CommandBuffer> create(GpuQueueType type, UINT32 deviceIdx = 0, UINT32 queueIdx = 0,
  61. bool secondary = false);
  62. /** Returns the type of queue the command buffer will execute on. */
  63. GpuQueueType getType() const { return mType; }
  64. /** Returns the index of the queue the command buffer will execute on. */
  65. UINT32 getQueueIdx() const { return mQueueIdx; }
  66. /** Returns the device index this buffer will execute on. */
  67. UINT32 getDeviceIdx() const { return mDeviceIdx; }
  68. protected:
  69. CommandBuffer(GpuQueueType type, UINT32 deviceIdx, UINT32 queueIdx, bool secondary);
  70. GpuQueueType mType;
  71. UINT32 mDeviceIdx;
  72. UINT32 mQueueIdx;
  73. bool mIsSecondary;
  74. };
  75. /** @} */
  76. }}