BsVulkanCommandBuffer.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsVulkanPrerequisites.h"
  5. #include "Renderapi/BsCommandBuffer.h"
  6. #include "BsVulkanRenderAPI.h"
  7. #include "BsVulkanResource.h"
  8. #include "BsVulkanGpuPipelineState.h"
  9. namespace bs { namespace ct
  10. {
  11. class VulkanOcclusionQuery;
  12. class VulkanTimerQuery;
  13. class VulkanImage;
  14. /** @addtogroup Vulkan
  15. * @{
  16. */
  17. #define BS_MAX_VULKAN_CB_PER_QUEUE_FAMILY BS_MAX_QUEUES_PER_TYPE * 32
  18. // Maximum number of command buffers that another command buffer can be dependant on (via a sync mask)
  19. #define BS_MAX_VULKAN_CB_DEPENDENCIES 2
  20. /** Wrapper around a Vulkan semaphore object that manages its usage and lifetime. */
  21. class VulkanSemaphore : public VulkanResource
  22. {
  23. public:
  24. VulkanSemaphore(VulkanResourceManager* owner);
  25. ~VulkanSemaphore();
  26. /** Returns the internal handle to the Vulkan object. */
  27. VkSemaphore getHandle() const { return mSemaphore; }
  28. private:
  29. VkSemaphore mSemaphore;
  30. };
  31. class VulkanCmdBuffer;
  32. /** Pool that allocates and distributes Vulkan command buffers. */
  33. class VulkanCmdBufferPool
  34. {
  35. public:
  36. VulkanCmdBufferPool(VulkanDevice& device);
  37. ~VulkanCmdBufferPool();
  38. /**
  39. * Attempts to find a free command buffer, or creates a new one if not found. Caller must guarantee the provided
  40. * queue family is valid.
  41. */
  42. VulkanCmdBuffer* getBuffer(UINT32 queueFamily, bool secondary);
  43. private:
  44. /** Command buffer pool and related information. */
  45. struct PoolInfo
  46. {
  47. VkCommandPool pool = VK_NULL_HANDLE;
  48. VulkanCmdBuffer* buffers[BS_MAX_VULKAN_CB_PER_QUEUE_FAMILY];
  49. UINT32 queueFamily = -1;
  50. };
  51. /** Creates a new command buffer. */
  52. VulkanCmdBuffer* createBuffer(UINT32 queueFamily, bool secondary);
  53. VulkanDevice& mDevice;
  54. UnorderedMap<UINT32, PoolInfo> mPools;
  55. UINT32 mNextId;
  56. };
  57. /** Determines where are the current descriptor sets bound to. */
  58. enum class DescriptorSetBindFlag
  59. {
  60. None = 0,
  61. Graphics = 1 << 0,
  62. Compute = 1 << 1
  63. };
  64. /** Specifies for what purpose is a resource being bound to a command buffer. */
  65. enum class ResourceUsage
  66. {
  67. ShaderBind,
  68. Framebuffer,
  69. Transfer
  70. };
  71. typedef Flags<DescriptorSetBindFlag> DescriptorSetBindFlags;
  72. BS_FLAGS_OPERATORS(DescriptorSetBindFlag)
  73. /**
  74. * Represents a direct wrapper over an internal Vulkan command buffer. This is unlike VulkanCommandBuffer which is a
  75. * higher level class, and it allows for re-use by internally using multiple low-level command buffers.
  76. */
  77. class VulkanCmdBuffer
  78. {
  79. /** Possible states a command buffer can be in. */
  80. enum class State
  81. {
  82. /** Buffer is ready to be re-used. */
  83. Ready,
  84. /** Buffer is currently recording commands, but isn't recording a render pass. */
  85. Recording,
  86. /** Buffer is currently recording render pass commands. */
  87. RecordingRenderPass,
  88. /** Buffer is done recording but hasn't been submitted. */
  89. RecordingDone,
  90. /** Buffer is done recording and is currently submitted on a queue. */
  91. Submitted
  92. };
  93. public:
  94. VulkanCmdBuffer(VulkanDevice& device, UINT32 id, VkCommandPool pool, UINT32 queueFamily, bool secondary);
  95. ~VulkanCmdBuffer();
  96. /** Returns an unique identifier of this command buffer. */
  97. UINT32 getId() const { return mId; }
  98. /** Returns the index of the queue family this command buffer is executing on. */
  99. UINT32 getQueueFamily() const { return mQueueFamily; }
  100. /** Returns the index of the device this command buffer will execute on. */
  101. UINT32 getDeviceIdx() const;
  102. /** Makes the command buffer ready to start recording commands. */
  103. void begin();
  104. /** Ends command buffer command recording (as started with begin()). */
  105. void end();
  106. /** Begins render pass recording. Must be called within begin()/end() calls. */
  107. void beginRenderPass();
  108. /** Ends render pass recording (as started with beginRenderPass(). */
  109. void endRenderPass();
  110. /**
  111. * Submits the command buffer for execution.
  112. *
  113. * @param[in] queue Queue to submit the command buffer on.
  114. * @param[in] queueIdx Index of the queue the command buffer was submitted on. Note that this may be different
  115. * from the actual VulkanQueue index since multiple command buffer queue indices can map
  116. * to the same queue.
  117. * @param[in] syncMask Mask that controls which other command buffers does this command buffer depend upon
  118. * (if any). See description of @p syncMask parameter in RenderAPI::executeCommands().
  119. */
  120. void submit(VulkanQueue* queue, UINT32 queueIdx, UINT32 syncMask);
  121. /** Returns the handle to the internal Vulkan command buffer wrapped by this object. */
  122. VkCommandBuffer getHandle() const { return mCmdBuffer; }
  123. /** Returns a fence that can be used for tracking when the command buffer is done executing. */
  124. VkFence getFence() const { return mFence; }
  125. /**
  126. * Returns a semaphore that may be used for synchronizing execution between command buffers executing on the same
  127. * queue.
  128. */
  129. VulkanSemaphore* getIntraQueueSemaphore() const { return mIntraQueueSemaphore; }
  130. /**
  131. * Returns a semaphore that may be used for synchronizing execution between command buffers executing on different
  132. * queues. Note that these semaphores get used each time they are requested, and there is only a fixed number
  133. * available. If all are used up, null will be returned. New semaphores are generated when allocateSemaphores()
  134. * is called.
  135. */
  136. VulkanSemaphore* requestInterQueueSemaphore() const;
  137. /**
  138. * Allocates a new set of semaphores that may be used for synchronizing execution between different command buffers.
  139. * Releases the previously allocated semaphores, if they exist. Use getIntraQueueSemaphore() &
  140. * requestInterQueueSemaphore() to retrieve latest allocated semaphores.
  141. *
  142. * @param[out] semaphores Output array to place all allocated semaphores in. The array must be of size
  143. * (BS_MAX_VULKAN_CB_DEPENDENCIES + 1).
  144. */
  145. void allocateSemaphores(VkSemaphore* semaphores);
  146. /** Returns true if the command buffer is currently being processed by the device. */
  147. bool isSubmitted() const { return mState == State::Submitted; }
  148. /** Returns true if the command buffer is currently recording (but not within a render pass). */
  149. bool isRecording() const { return mState == State::Recording; }
  150. /** Returns true if the command buffer is ready to be submitted to a queue. */
  151. bool isReadyForSubmit() const { return mState == State::RecordingDone; }
  152. /** Returns true if the command buffer is currently recording a render pass. */
  153. bool isInRenderPass() const { return mState == State::RecordingRenderPass; }
  154. /**
  155. * Checks the internal fence if done executing.
  156. *
  157. * @param[in] block If true, the system will block until the fence is signaled.
  158. */
  159. bool checkFenceStatus(bool block) const;
  160. /**
  161. * Resets the command buffer back in Ready state. Should be called when command buffer is done executing on a
  162. * queue.
  163. */
  164. void reset();
  165. /**
  166. * Lets the command buffer know that the provided resource has been queued on it, and will be used by the
  167. * device when the command buffer is submitted. If a resource is an image or a buffer use the more specific
  168. * registerResource() overload.
  169. */
  170. void registerResource(VulkanResource* res, VulkanUseFlags flags);
  171. /**
  172. * Lets the command buffer know that the provided image resource has been queued on it, and will be used by the
  173. * device when the command buffer is submitted. Executes a layout transition to @p newLayout (if needed), and
  174. * updates the externally visible image layout field to @p finalLayout (once submitted).
  175. *
  176. * @param[in] res Image to register with the command buffer.
  177. * @param[in] range Range of sub-resources to register.
  178. * @param[in] newLayout Layout the image needs to be transitioned in before use. Set to undefined
  179. * layout if no transition is required.
  180. * @param[in] finalLayout Determines what value the externally visible image layout will be set after
  181. * submit() is called. Normally this will be same as @p newLayout, but can be
  182. * different if some form of automatic layout transitions are happening.
  183. * @param[in] flags Flags that determine how will be command buffer be using the buffer.
  184. * @param[in] usage Determines for what purpose is the resource being registered for.
  185. */
  186. void registerResource(VulkanImage* res, const VkImageSubresourceRange& range, VkImageLayout newLayout,
  187. VkImageLayout finalLayout, VulkanUseFlags flags, ResourceUsage usage);
  188. /**
  189. * Lets the command buffer know that the provided image resource has been queued on it, and will be used by the
  190. * device when the command buffer is submitted. Assumes the image is in its optimal layout.
  191. */
  192. void registerResource(VulkanImage* res, const VkImageSubresourceRange& range, VulkanUseFlags flags,
  193. ResourceUsage usage);
  194. /**
  195. * Lets the command buffer know that the provided image resource has been queued on it, and will be used by the
  196. * device when the command buffer is submitted.
  197. */
  198. void registerResource(VulkanBuffer* res, VkAccessFlags accessFlags, VulkanUseFlags flags);
  199. /**
  200. * Lets the command buffer know that the provided framebuffer resource has been queued on it, and will be used by
  201. * the device when the command buffer is submitted.
  202. */
  203. void registerResource(VulkanFramebuffer* res, RenderSurfaceMask loadMask, UINT32 readMask);
  204. /** Notifies the command buffer that the provided query has been queued on it. */
  205. void registerQuery(VulkanOcclusionQuery* query) { mOcclusionQueries.insert(query); }
  206. /** Notifies the command buffer that the provided query has been queued on it. */
  207. void registerQuery(VulkanTimerQuery* query) { mTimerQueries.insert(query); }
  208. /************************************************************************/
  209. /* COMMANDS */
  210. /************************************************************************/
  211. /**
  212. * Assigns a render target the the command buffer. This render target's framebuffer and render pass will be used
  213. * when beginRenderPass() is called. Command buffer must not be currently recording a render pass.
  214. */
  215. void setRenderTarget(const SPtr<RenderTarget>& rt, UINT32 readOnlyFlags, RenderSurfaceMask loadMask);
  216. /** Clears the entirety currently bound render target. */
  217. void clearRenderTarget(UINT32 buffers, const Color& color, float depth, UINT16 stencil, UINT8 targetMask);
  218. /** Clears the viewport portion of the currently bound render target. */
  219. void clearViewport(UINT32 buffers, const Color& color, float depth, UINT16 stencil, UINT8 targetMask);
  220. /** Assigns a pipeline state to use for subsequent draw commands. */
  221. void setPipelineState(const SPtr<GraphicsPipelineState>& state);
  222. /** Assigns a pipeline state to use for subsequent dispatch commands. */
  223. void setPipelineState(const SPtr<ComputePipelineState>& state);
  224. /** Assign GPU params to the GPU programs bound by the pipeline state. */
  225. void setGpuParams(const SPtr<GpuParams>& gpuParams);
  226. /** Sets the current viewport which determine to which portion of the render target to render to. */
  227. void setViewport(const Rect2& area);
  228. /**
  229. * Sets the scissor rectangle area which determines in which area if the viewport are the fragments allowed to be
  230. * generated. Only relevant if enabled on the pipeline state.
  231. */
  232. void setScissorRect(const Rect2I& area);
  233. /** Sets a stencil reference value that will be used for comparisons in stencil operations, if enabled. */
  234. void setStencilRef(UINT32 value);
  235. /** Changes how are primitives interpreted as during rendering. */
  236. void setDrawOp(DrawOperationType drawOp);
  237. /** Sets one or multiple vertex buffers that will be used for subsequent draw() or drawIndexed() calls. */
  238. void setVertexBuffers(UINT32 index, SPtr<VertexBuffer>* buffers, UINT32 numBuffers);
  239. /** Sets an index buffer that will be used for subsequent drawIndexed() calls. */
  240. void setIndexBuffer(const SPtr<IndexBuffer>& buffer);
  241. /** Sets a declaration that determines how are vertex buffer contents interpreted. */
  242. void setVertexDeclaration(const SPtr<VertexDeclaration>& decl);
  243. /** Executes a draw command using the currently bound graphics pipeline, vertex buffer and render target. */
  244. void draw(UINT32 vertexOffset, UINT32 vertexCount, UINT32 instanceCount);
  245. /** Executes a draw command using the currently bound graphics pipeline, index & vertex buffer and render target. */
  246. void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 instanceCount);
  247. /** Executes a dispatch command using the currently bound compute pipeline. */
  248. void dispatch(UINT32 numGroupsX, UINT32 numGroupsY, UINT32 numGroupsZ);
  249. /**
  250. * Registers a command that signals the event when executed. Will be delayed until the end of the current
  251. * render pass, if any.
  252. */
  253. void setEvent(VulkanEvent* event);
  254. /**
  255. * Registers a command that resets the query. The command will be delayed until the next submit() if a render
  256. * pass is currently in progress, but is guaranteed to execute before this command buffer is submitted.
  257. */
  258. void resetQuery(VulkanQuery* query);
  259. /**
  260. * Issues a pipeline barrier on the provided buffer. See vkCmdPipelineBarrier in Vulkan spec. for usage
  261. * information.
  262. */
  263. void memoryBarrier(VkBuffer buffer, VkAccessFlags srcAccessFlags, VkAccessFlags dstAccessFlags,
  264. VkPipelineStageFlags srcStage, VkPipelineStageFlags dstStage);
  265. /**
  266. * Issues a pipeline barrier on the provided image. See vkCmdPipelineBarrier in Vulkan spec. for usage
  267. * information.
  268. */
  269. void memoryBarrier(VkImage image, VkAccessFlags srcAccessFlags, VkAccessFlags dstAccessFlags,
  270. VkPipelineStageFlags srcStage, VkPipelineStageFlags dstStage, VkImageLayout layout,
  271. const VkImageSubresourceRange& range);
  272. /**
  273. * Issues a pipeline barrier on the provided image, changing its layout. See vkCmdPipelineBarrier in Vulkan spec.
  274. * for usage information.
  275. */
  276. void setLayout(VkImage image, VkAccessFlags srcAccessFlags, VkAccessFlags dstAccessFlags,
  277. VkImageLayout oldLayout, VkImageLayout newLayout, const VkImageSubresourceRange& range);
  278. /**
  279. * Returns the current layout of the specified image, as seen by this command buffer. This is different from the
  280. * global layout stored in VulkanImage itself, as it includes any transitions performed by the command buffer
  281. * (at the current point in time), while the global layout is only updated after a command buffer as been submitted.
  282. *
  283. * @param[in] image Image to lookup the layout for.
  284. * @param[in] range Subresource range of the image to lookup the layout for.
  285. * @param[in] inRenderPass If true this will return the layout of the image after the render pass begins.
  286. * If false it will return the current layout of the image. These may be different
  287. * in the case the image is used in the framebuffer, in which case the render pass
  288. * may perform an automated layout transition when it begins.
  289. */
  290. VkImageLayout getCurrentLayout(VulkanImage* image, const VkImageSubresourceRange& range, bool inRenderPass);
  291. private:
  292. friend class VulkanCmdBufferPool;
  293. friend class VulkanCommandBuffer;
  294. friend class VulkanQueue;
  295. /** Contains information about a single Vulkan resource bound/used on this command buffer. */
  296. struct ResourceUseHandle
  297. {
  298. bool used;
  299. VulkanUseFlags flags;
  300. };
  301. /** Contains information about a single Vulkan buffer resource bound/used on this command buffer. */
  302. struct BufferInfo
  303. {
  304. VkAccessFlags accessFlags;
  305. ResourceUseHandle useHandle;
  306. /**
  307. * True if the buffer was at some point written to by the shader during the current render pass, and barrier
  308. * wasn't issued yet.
  309. */
  310. bool needsBarrier;
  311. };
  312. /** Contains information about a single Vulkan image resource bound/used on this command buffer. */
  313. struct ImageInfo
  314. {
  315. ResourceUseHandle useHandle;
  316. UINT32 subresourceInfoIdx;
  317. UINT32 numSubresourceInfos;
  318. };
  319. /** Contains information about a range of Vulkan image sub-resources bound/used on this command buffer. */
  320. struct ImageSubresourceInfo
  321. {
  322. VkImageSubresourceRange range;
  323. // Only relevant for layout transitions
  324. VkImageLayout initialLayout;
  325. VkImageLayout currentLayout;
  326. VkImageLayout requiredLayout;
  327. VkImageLayout finalLayout;
  328. bool isFBAttachment : 1;
  329. bool isShaderInput : 1;
  330. bool hasTransitioned : 1;
  331. bool isReadOnly : 1;
  332. bool isInitialReadOnly : 1;
  333. /**
  334. * True if the buffer was at some point written to by the shader during the current render pass, and barrier
  335. * wasn't issued yet.
  336. */
  337. bool needsBarrier : 1;
  338. };
  339. /** Checks if all the prerequisites for rendering have been made (e.g. render target and pipeline state are set.) */
  340. bool isReadyForRender();
  341. /** Marks the command buffer as submitted on a queue. */
  342. void setIsSubmitted() { mState = State::Submitted; }
  343. /** Binds the current graphics pipeline to the command buffer. Returns true if bind was successful. */
  344. bool bindGraphicsPipeline();
  345. /**
  346. * Binds any dynamic states to the pipeline, as required.
  347. *
  348. * @param[in] forceAll If true all states will be bound. If false only states marked as dirty will be bound.
  349. */
  350. void bindDynamicStates(bool forceAll);
  351. /** Binds the currently stored GPU parameters object, if dirty. */
  352. void bindGpuParams();
  353. /** Clears the specified area of the currently bound render target. */
  354. void clearViewport(const Rect2I& area, UINT32 buffers, const Color& color, float depth, UINT16 stencil,
  355. UINT8 targetMask);
  356. /** Starts and ends a render pass, intended only for a clear operation. */
  357. void executeClearPass();
  358. /** Executes any queued layout transitions by issuing a pipeline barrier. */
  359. void executeLayoutTransitions();
  360. /**
  361. * Updates final layouts for images used by the current framebuffer, reflecting layout changes performed by render
  362. * pass' automatic layout transitions.
  363. */
  364. void updateFinalLayouts();
  365. /**
  366. * Updates an existing sub-resource info range with new layout, use flags and framebuffer flag. Returns true if
  367. * the bound sub-resource is a read-only framebuffer attachment.
  368. */
  369. bool updateSubresourceInfo(VulkanImage* image, UINT32 imageInfoIdx, ImageSubresourceInfo& subresourceInfo,
  370. VkImageLayout newLayout, VkImageLayout finalLayout, VulkanUseFlags flags, ResourceUsage usage);
  371. /** Finds a subresource info structure containing the specified face and mip level of the provided image. */
  372. ImageSubresourceInfo& findSubresourceInfo(VulkanImage* image, UINT32 face, UINT32 mip);
  373. /** Gets all queries registered on this command buffer that haven't been ended. */
  374. void getInProgressQueries(Vector<VulkanTimerQuery*>& timer, Vector<VulkanOcclusionQuery*>& occlusion) const;
  375. /** Returns the read mask for the current framebuffer. */
  376. RenderSurfaceMask getFBReadMask();
  377. UINT32 mId;
  378. UINT32 mQueueFamily;
  379. State mState;
  380. VulkanDevice& mDevice;
  381. VkCommandPool mPool;
  382. VkCommandBuffer mCmdBuffer;
  383. VkFence mFence;
  384. VulkanSemaphore* mIntraQueueSemaphore;
  385. VulkanSemaphore* mInterQueueSemaphores[BS_MAX_VULKAN_CB_DEPENDENCIES];
  386. mutable UINT32 mNumUsedInterQueueSemaphores;
  387. VulkanFramebuffer* mFramebuffer;
  388. UINT32 mRenderTargetWidth;
  389. UINT32 mRenderTargetHeight;
  390. UINT32 mRenderTargetReadOnlyFlags;
  391. RenderSurfaceMask mRenderTargetLoadMask;
  392. UnorderedMap<VulkanResource*, ResourceUseHandle> mResources;
  393. UnorderedMap<VulkanResource*, UINT32> mImages;
  394. UnorderedMap<VulkanResource*, BufferInfo> mBuffers;
  395. UnorderedSet<VulkanOcclusionQuery*> mOcclusionQueries;
  396. UnorderedSet<VulkanTimerQuery*> mTimerQueries;
  397. Vector<ImageInfo> mImageInfos;
  398. Vector<ImageSubresourceInfo> mSubresourceInfoStorage;
  399. Set<UINT32> mPassTouchedSubresourceInfos; // All subresource infos touched by the current render pass
  400. UINT32 mGlobalQueueIdx;
  401. SPtr<VulkanGraphicsPipelineState> mGraphicsPipeline;
  402. SPtr<VulkanComputePipelineState> mComputePipeline;
  403. SPtr<VertexDeclaration> mVertexDecl;
  404. Rect2 mViewport;
  405. Rect2I mScissor;
  406. UINT32 mStencilRef;
  407. DrawOperationType mDrawOp;
  408. UINT32 mNumBoundDescriptorSets;
  409. bool mGfxPipelineRequiresBind : 1;
  410. bool mCmpPipelineRequiresBind : 1;
  411. bool mViewportRequiresBind : 1;
  412. bool mStencilRefRequiresBind : 1;
  413. bool mScissorRequiresBind : 1;
  414. bool mBoundParamsDirty : 1;
  415. DescriptorSetBindFlags mDescriptorSetsBindState;
  416. SPtr<VulkanGpuParams> mBoundParams;
  417. std::array<VkClearValue, BS_MAX_MULTIPLE_RENDER_TARGETS + 1> mClearValues;
  418. ClearMask mClearMask;
  419. Rect2I mClearArea;
  420. Vector<VulkanSemaphore*> mSemaphoresTemp;
  421. VkBuffer mVertexBuffersTemp[BS_MAX_BOUND_VERTEX_BUFFERS];
  422. VkDeviceSize mVertexBufferOffsetsTemp[BS_MAX_BOUND_VERTEX_BUFFERS];
  423. VkDescriptorSet* mDescriptorSetsTemp;
  424. UnorderedMap<UINT32, TransitionInfo> mTransitionInfoTemp;
  425. Vector<VkImageMemoryBarrier> mLayoutTransitionBarriersTemp;
  426. UnorderedMap<VulkanImage*, UINT32> mQueuedLayoutTransitions;
  427. Vector<VulkanEvent*> mQueuedEvents;
  428. Vector<VulkanQuery*> mQueuedQueryResets;
  429. UnorderedSet<VulkanSwapChain*> mSwapChains;
  430. };
  431. /** CommandBuffer implementation for Vulkan. */
  432. class VulkanCommandBuffer : public CommandBuffer
  433. {
  434. public:
  435. /**
  436. * Submits the command buffer for execution.
  437. *
  438. * @param[in] syncMask Mask that controls which other command buffers does this command buffer depend upon
  439. * (if any). See description of @p syncMask parameter in RenderAPI::executeCommands().
  440. */
  441. void submit(UINT32 syncMask);
  442. /**
  443. * Returns the internal command buffer.
  444. *
  445. * @note This buffer will change after a submit() call.
  446. */
  447. VulkanCmdBuffer* getInternal() const { return mBuffer; }
  448. private:
  449. friend class VulkanCommandBufferManager;
  450. VulkanCommandBuffer(VulkanDevice& device, GpuQueueType type, UINT32 deviceIdx, UINT32 queueIdx,
  451. bool secondary);
  452. ~VulkanCommandBuffer();
  453. /**
  454. * Tasks the command buffer to find a new internal command buffer. Call this after the command buffer has been
  455. * submitted to a queue (it's not allowed to be used until the queue is done with it).
  456. */
  457. void acquireNewBuffer();
  458. VulkanCmdBuffer* mBuffer;
  459. VulkanDevice& mDevice;
  460. VulkanQueue* mQueue;
  461. UINT32 mIdMask;
  462. };
  463. /** @} */
  464. }}