BsCommandBuffer.h 3.3 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 global queue index. */
  22. static UINT32 getGlobalQueueIdx(GpuQueueType type, UINT32 queueIdx);
  23. private:
  24. UINT32 mMask = 0;
  25. };
  26. /**
  27. * Contains a list of render API commands that can be queued for execution on the GPU. User is allowed to populate the
  28. * command buffer from any thread, ensuring render API command generation can be multi-threaded. Command buffers
  29. * must always be created on the core thread. Same command buffer cannot be used on multiple threads simulateously
  30. * without external synchronization.
  31. */
  32. class BS_CORE_EXPORT CommandBuffer
  33. {
  34. public:
  35. virtual ~CommandBuffer();
  36. /**
  37. * Creates a new CommandBuffer.
  38. *
  39. * @param[in] type Determines what type of commands can be added to the command buffer.
  40. * @param[in] deviceIdx Index of the GPU the command buffer will be used to queue commands on. 0 is always
  41. * the primary available GPU.
  42. * @param[in] queueIdx Index of the hardware queue the command buffer will be used on. Command buffers with
  43. * the same index will execute sequentially, but command buffers with different queue
  44. * indices may execute in parallel, for a potential performance improvement. Queue indices
  45. * are unique per buffer type (e.g. upload index 0 and graphics index 0 may map to
  46. * different queues internally). Must be in range [0, 7].
  47. * @param[in] secondary If true the command buffer will not be allowed to execute on its own, but it can
  48. * be appended to a primary command buffer.
  49. * @return New CommandBuffer instance.
  50. *
  51. * @note The parallelism provided by @p queueIdx is parallelism on the GPU itself, it has nothing to do with CPU
  52. * parallelism or threads.
  53. */
  54. static SPtr<CommandBuffer> create(GpuQueueType type, UINT32 deviceIdx = 0, UINT32 queueIdx = 0,
  55. bool secondary = false);
  56. /** Returns the type of queue the command buffer will execute on. */
  57. GpuQueueType getType() const { return mType; }
  58. /** Returns the index of the queue the command buffer will execute on. */
  59. UINT32 getQueueIdx() const { return mQueueIdx; }
  60. /** @name Internal
  61. * @{
  62. */
  63. /** Returns a unique ID of this command buffer. */
  64. UINT32 _getId() const { return mId; }
  65. /** @} */
  66. protected:
  67. CommandBuffer(UINT32 id, GpuQueueType type, UINT32 deviceIdx, UINT32 queueIdx, bool secondary);
  68. UINT32 mId;
  69. GpuQueueType mType;
  70. UINT32 mDeviceIdx;
  71. UINT32 mQueueIdx;
  72. bool mIsSecondary;
  73. };
  74. /** @} */
  75. }