BsCommandBuffer.h 2.9 KB

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