BsCommandBuffer.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 BansheeEngine
  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 hardware 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. Queue indices
  49. * are unique per buffer type (e.g. upload index 0 and graphics index 0 may map to
  50. * different queues internally). Must be in range [0, 7].
  51. * @param[in] secondary If true the command buffer will not be allowed to execute on its own, but it can
  52. * be appended to a primary command buffer.
  53. * @return New CommandBuffer instance.
  54. *
  55. * @note The parallelism provided by @p queueIdx is parallelism on the GPU itself, it has nothing to do with CPU
  56. * parallelism or threads.
  57. */
  58. static SPtr<CommandBuffer> create(GpuQueueType type, UINT32 deviceIdx = 0, UINT32 queueIdx = 0,
  59. bool secondary = false);
  60. /** Returns the type of queue the command buffer will execute on. */
  61. GpuQueueType getType() const { return mType; }
  62. /** Returns the index of the queue the command buffer will execute on. */
  63. UINT32 getQueueIdx() const { return mQueueIdx; }
  64. /** Returns the device index this buffer will execute on. */
  65. UINT32 getDeviceIdx() const { return mDeviceIdx; }
  66. protected:
  67. CommandBuffer(GpuQueueType type, UINT32 deviceIdx, UINT32 queueIdx, bool secondary);
  68. GpuQueueType mType;
  69. UINT32 mDeviceIdx;
  70. UINT32 mQueueIdx;
  71. bool mIsSecondary;
  72. };
  73. /** @} */
  74. }