VPP  0.8
A high-level modern C++ API for Vulkan
vppCommands.hpp
1 /*
2  Copyright 2016-2018 SOFT-ERG, Przemek Kuczmierczyk (www.softerg.com)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 // -----------------------------------------------------------------------------
28 namespace vpp {
29 // -----------------------------------------------------------------------------
53 {
54 public:
58  static void cmdFillBuffer (
59  const Buf& hDstBuffer,
60  size_t offset, size_t size, std::uint32_t value,
61  CommandBuffer hCmdBuffer = CommandBuffer() );
62 
66  static void cmdCopyBuffer (
67  const Buf& hSrcBuffer,
68  const Buf& hDstBuffer,
69  CommandBuffer hCmdBuffer = CommandBuffer() );
70 
74  static void cmdCopyBuffer (
75  const Buf& hSrcBuffer,
76  const Buf& hDstBuffer,
77  const std::vector< VkBufferCopy >& regions,
78  CommandBuffer hCmdBuffer = CommandBuffer() );
79 
86  static void cmdUpdateBuffer (
87  const Buf& hDstBuffer,
88  size_t offset, size_t size, const std::uint32_t* pData,
89  CommandBuffer hCmdBuffer = CommandBuffer() );
90 
94  static void cmdCopyImage (
95  const Img& hSrcImage,
96  VkImageLayout srcImageLayout,
97  const Img& hDstImage,
98  VkImageLayout dstImageLayout,
99  CommandBuffer hCmdBuffer = CommandBuffer() );
100 
104  static void cmdCopyImage (
105  const Img& hSrcImage,
106  VkImageLayout srcImageLayout,
107  const Img& hDstImage,
108  VkImageLayout dstImageLayout,
109  const std::vector< VkImageCopy >& regions,
110  CommandBuffer hCmdBuffer = CommandBuffer() );
111 
115  static void cmdCopyBufferToImage (
116  const Buf& hSrcBuffer,
117  const Img& hDstImage,
118  VkImageLayout dstImageLayout,
119  CommandBuffer hCmdBuffer = CommandBuffer() );
120 
124  static void cmdCopyBufferToImage (
125  const Buf& hSrcBuffer,
126  const Img& hDstImage,
127  VkImageLayout dstImageLayout,
128  const std::vector< VkBufferImageCopy >& regions,
129  CommandBuffer hCmdBuffer = CommandBuffer() );
130 
134  static void cmdCopyImageToBuffer (
135  const Img& hSrcImage,
136  VkImageLayout srcImageLayout,
137  const Buf& hDstBuffer,
138  CommandBuffer hCmdBuffer = CommandBuffer() );
139 
143  static void cmdCopyImageToBuffer (
144  const Img& hSrcImage,
145  VkImageLayout srcImageLayout,
146  const Buf& hDstBuffer,
147  const std::vector< VkBufferImageCopy >& regions,
148  CommandBuffer hCmdBuffer = CommandBuffer() );
149 
155  static void cmdBlitImage (
156  const Img& hSrcImage,
157  VkImageLayout srcImageLayout,
158  const Img& hDstImage,
159  VkImageLayout dstImageLayout,
160  const VkOffset3D& srcBegin, const VkOffset3D& srcEnd,
161  const VkOffset3D& dstBegin, const VkOffset3D& dstEnd,
162  CommandBuffer hCmdBuffer = CommandBuffer() );
163 
168  static void cmdBlitImage (
169  const Img& hSrcImage,
170  VkImageLayout srcImageLayout,
171  const Img& hDstImage,
172  VkImageLayout dstImageLayout,
173  const VkOffset3D& srcBegin, const VkOffset3D& srcEnd,
174  const VkOffset3D& dstBegin,
175  CommandBuffer hCmdBuffer = CommandBuffer() );
176 
182  static void cmdBlitImage (
183  const Img& hSrcImage,
184  VkImageLayout srcImageLayout,
185  const Img& hDstImage,
186  VkImageLayout dstImageLayout,
187  const std::vector< VkImageBlit >& regions,
188  CommandBuffer hCmdBuffer = CommandBuffer() );
189 
200  static void cmdResolveImage (
201  const Img& hSrcImage,
202  VkImageLayout srcImageLayout,
203  const Img& hDstImage,
204  VkImageLayout dstImageLayout,
205  const VkOffset3D& srcOffset, const VkOffset3D& dstOffset,
206  const VkExtent3D& size,
207  CommandBuffer hCmdBuffer = CommandBuffer() );
208 
219  static void cmdResolveImage (
220  const Img& hSrcImage,
221  VkImageLayout srcImageLayout,
222  const Img& hDstImage,
223  VkImageLayout dstImageLayout,
224  CommandBuffer hCmdBuffer = CommandBuffer() );
225 
236  static void cmdResolveImage (
237  const Img& hSrcImage,
238  VkImageLayout srcImageLayout,
239  const Img& hDstImage,
240  VkImageLayout dstImageLayout,
241  const std::vector< VkImageResolve >& regions,
242  CommandBuffer hCmdBuffer = CommandBuffer() );
243 
247  static void cmdClearColorImage (
248  const Img& hImage,
249  const VkClearColorValue& color,
250  CommandBuffer hCmdBuffer = CommandBuffer() );
251 
255  static void cmdClearColorImage (
256  const Img& hImage,
257  const VkClearColorValue& color,
258  const std::vector< VkImageSubresourceRange >& regions,
259  CommandBuffer hCmdBuffer = CommandBuffer() );
260 
264  static void cmdClearDepthStencilImage (
265  const Img& hImage,
266  VkImageLayout imageLayout,
267  float depth, std::uint32_t stencil,
268  CommandBuffer hCmdBuffer = CommandBuffer() );
269 
273  static void cmdClearDepthStencilImage (
274  const Img& hImage,
275  VkImageLayout imageLayout,
276  float depth, std::uint32_t stencil,
277  const std::vector< VkImageSubresourceRange >& regions,
278  CommandBuffer hCmdBuffer = CommandBuffer() );
279 
283  static void cmdResetQueryPool (
284  const QueryPool& hPool,
285  std::uint32_t first,
286  std::uint32_t count,
287  CommandBuffer hCmdBuffer = CommandBuffer() );
288 
292  static void cmdResetQueryPool (
293  const QueryPool& hPool,
294  CommandBuffer hCmdBuffer = CommandBuffer() );
295 
296  static void cmdCopyQueryPoolResults (
297  const Buf& hDstBuffer,
298  const QueryPool& hPool,
299  VkQueryResultFlags flags,
300  std::uint32_t count,
301  std::uint32_t first,
302  VkDeviceSize dstOffset,
303  CommandBuffer hCmdBuffer = CommandBuffer() );
304 
305  static void cmdCopyQueryPoolResults (
306  const Buf& hDstBuffer,
307  const QueryPool& hPool,
308  VkQueryResultFlags flags,
309  CommandBuffer hCmdBuffer = CommandBuffer() );
310 };
311 
312 // -----------------------------------------------------------------------------
334 {
335 public:
336  static void cmdExecuteCommands (
337  const VkCommandBuffer* pBuffers,
338  size_t size,
339  CommandBuffer hCmdBuffer = CommandBuffer() );
340 
341  static void cmdExecuteCommands (
342  const CommandBuffer* pBuffers,
343  size_t size,
344  CommandBuffer hCmdBuffer = CommandBuffer() );
345 
346  static void cmdExecuteCommands (
347  const std::vector< CommandBuffer >& buffers,
348  CommandBuffer hCmdBuffer = CommandBuffer() );
349 
350  static void cmdWaitEvents (
351  const std::vector< Event >& events,
352  VkPipelineStageFlags srcStageMask,
353  VkPipelineStageFlags dstStageMask,
354  const Barriers& barriers = Barriers(),
355  CommandBuffer hCmdBuffer = CommandBuffer() );
356 
357  static void cmdPipelineBarrier (
358  VkPipelineStageFlags srcStageMask,
359  VkPipelineStageFlags dstStageMask,
360  VkDependencyFlags dependencyFlags,
361  const Barriers& barriers,
362  CommandBuffer hCmdBuffer = CommandBuffer() );
363 
364  static void cmdImagePipelineBarrier (
365  const Img& image,
366  VkPipelineStageFlags srcStageMask,
367  VkPipelineStageFlags dstStageMask,
368  VkAccessFlags srcAccessMask,
369  VkAccessFlags dstAccessMask,
370  bool bByRegion,
371  VkImageLayout oldLayout = VK_IMAGE_LAYOUT_GENERAL,
372  VkImageLayout newLayout = VK_IMAGE_LAYOUT_GENERAL,
373  int mipLevel = -1,
374  int arrayLayer = -1,
375  CommandBuffer hCmdBuffer = CommandBuffer()
376  );
377 
378  static void cmdBufferPipelineBarrier (
379  const Buf& hBuffer,
380  VkPipelineStageFlags srcStageMask,
381  VkPipelineStageFlags dstStageMask,
382  VkAccessFlags srcAccessMask,
383  VkAccessFlags dstAccessMask,
384  CommandBuffer hCmdBuffer = CommandBuffer()
385  );
386 
387  static void cmdSetViewport (
388  const VkViewport& viewport,
389  std::uint32_t index = 0,
390  CommandBuffer hCmdBuffer = CommandBuffer() );
391 
392  static void cmdSetViewport (
393  const std::vector< VkViewport >& viewports,
394  std::uint32_t first = 0,
395  CommandBuffer hCmdBuffer = CommandBuffer() );
396 
397  static void cmdSetLineWidth (
398  float lineWidth,
399  CommandBuffer hCmdBuffer = CommandBuffer() );
400 
401  static void cmdSetDepthBias (
402  float constantFactor,
403  float clamp,
404  float slopeFactor,
405  CommandBuffer hCmdBuffer = CommandBuffer() );
406 
407  static void cmdSetDepthBounds (
408  float minDepthBounds,
409  float maxDepthBounds,
410  CommandBuffer hCmdBuffer = CommandBuffer() );
411 
412  static void cmdSetScissor (
413  const VkRect2D& scissor,
414  std::uint32_t index = 0,
415  CommandBuffer hCmdBuffer = CommandBuffer() );
416 
417  static void cmdSetScissor (
418  const std::vector< VkRect2D >& scissors,
419  std::uint32_t first = 0,
420  CommandBuffer hCmdBuffer = CommandBuffer() );
421 
422  static void cmdSetStencilCompareMask (
423  VkStencilFaceFlags faceMask,
424  std::uint32_t compareMask,
425  CommandBuffer hCmdBuffer = CommandBuffer() );
426 
427  static void cmdSetStencilWriteMask (
428  VkStencilFaceFlags faceMask,
429  std::uint32_t writeMask,
430  CommandBuffer hCmdBuffer = CommandBuffer() );
431 
432  static void cmdSetStencilReference (
433  VkStencilFaceFlags faceMask,
434  std::uint32_t reference,
435  CommandBuffer hCmdBuffer = CommandBuffer() );
436 
437  static void cmdSetBlendConstants (
438  const float blendConstants [ 4 ],
439  CommandBuffer hCmdBuffer = CommandBuffer() );
440 
441  static void cmdBeginQuery (
442  const QueryPool& hPool,
443  std::uint32_t query,
444  VkQueryControlFlags flags,
445  CommandBuffer hCmdBuffer = CommandBuffer() );
446 
447  static void cmdEndQuery (
448  const QueryPool& hPool,
449  std::uint32_t query,
450  CommandBuffer hCmdBuffer = CommandBuffer() );
451 
452  static void cmdWriteTimestamp (
453  const QueryPool& hPool,
454  std::uint32_t query,
455  VkPipelineStageFlagBits pipelineStage,
456  CommandBuffer hCmdBuffer = CommandBuffer() );
457 
458  static void cmdBindPipeline (
459  const Pipeline& hPipeline,
460  VkPipelineBindPoint pipelineBindPoint,
461  CommandBuffer hCmdBuffer = CommandBuffer() );
462 
463  static void cmdBindDescriptorSets (
464  const ShaderDataBlock& hDataBlock,
465  CommandBuffer hCmdBuffer = CommandBuffer() );
466 
467  static void cmdBindIndexInput (
468  const Buf& hBuffer,
469  VkIndexType indexType,
470  VkDeviceSize offset,
471  CommandBuffer hCmdBuffer = CommandBuffer() );
472 
473  static void cmdBindVertexBuffers (
474  const std::vector< Buf >& buffers,
475  const std::vector< VkDeviceSize >& offsets,
476  std::uint32_t first = 0,
477  CommandBuffer hCmdBuffer = CommandBuffer() );
478 
479  static void cmdBindVertexBuffers (
480  const std::vector< Buf >& buffers,
481  std::uint32_t first = 0,
482  CommandBuffer hCmdBuffer = CommandBuffer() );
483 
484  static void cmdPushConstants (
485  const PipelineLayoutBase& hPipelineLayout,
486  VkShaderStageFlags stageFlags,
487  const void* pValues,
488  std::uint32_t size,
489  std::uint32_t offset = 0,
490  CommandBuffer hCmdBuffer = CommandBuffer() );
491 };
492 
493 // -----------------------------------------------------------------------------
494 // -----------------------------------------------------------------------------
495 
497  public NonRenderingCommands,
498  public UniversalCommands
499 {
500 public:
501  static void cmdChangeImageLayout (
502  const Img& hImage,
503  VkImageLayout oldImageLayout,
504  VkImageLayout newImageLayout,
505  std::uint32_t levelCount = 1,
506  std::uint32_t layerCount = 1,
507  std::uint32_t baseMipLevel = 0,
508  std::uint32_t baseArrayLayer = 0,
509  VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
510  CommandBuffer hCmdBuffer = CommandBuffer() );
511 };
512 
513 // -----------------------------------------------------------------------------
514 } // namespace vpp
515 // -----------------------------------------------------------------------------
Class representing generic (untyped) Vulkan image.
Definition: vppImage.hpp:54
Compiled pipeline class for graphics pipelines.
Definition: vppPipeline.hpp:48
Set of commands that may be used anywhere (inside or outside rendering context).
Definition: vppCommands.hpp:333
The VPP namespace.
Definition: main.hpp:1
Set of commands that may be used outside rendering context.
Definition: vppCommands.hpp:52
Represents a sequence of Vulkan commands.
Definition: vppCommandBuffer.hpp:68
static void cmdResolveImage(const Img &hSrcImage, VkImageLayout srcImageLayout, const Img &hDstImage, VkImageLayout dstImageLayout, const VkOffset3D &srcOffset, const VkOffset3D &dstOffset, const VkExtent3D &size, CommandBuffer hCmdBuffer=CommandBuffer())
Resolves source multisampled image region into destination regular image.
BarrierList barriers(VkPipelineStageFlags sourceStage, VkPipelineStageFlags targetStage, Args &&... args)
Creates a BarrierList object for specified resources.
static void cmdClearDepthStencilImage(const Img &hImage, VkImageLayout imageLayout, float depth, std::uint32_t stencil, CommandBuffer hCmdBuffer=CommandBuffer())
Clears a depth or stencil image with specified value.
Definition: vppCommands.hpp:496
static void cmdClearColorImage(const Img &hImage, const VkClearColorValue &color, CommandBuffer hCmdBuffer=CommandBuffer())
Clears an image with specified color.
static void cmdCopyImageToBuffer(const Img &hSrcImage, VkImageLayout srcImageLayout, const Buf &hDstBuffer, CommandBuffer hCmdBuffer=CommandBuffer())
Copies entire contents from an image to a buffer.
General class encapsulating description of a set of pipeline barriers.
Definition: vppBarriers.hpp:211
static void cmdCopyImage(const Img &hSrcImage, VkImageLayout srcImageLayout, const Img &hDstImage, VkImageLayout dstImageLayout, CommandBuffer hCmdBuffer=CommandBuffer())
Copies entire contents from one image to another.
Generic class representing Vulkan buffers.
Definition: vppBuffer.hpp:43
static void cmdCopyBuffer(const Buf &hSrcBuffer, const Buf &hDstBuffer, CommandBuffer hCmdBuffer=CommandBuffer())
Copies entire contents from one buffer to another.
static void cmdBlitImage(const Img &hSrcImage, VkImageLayout srcImageLayout, const Img &hDstImage, VkImageLayout dstImageLayout, const VkOffset3D &srcBegin, const VkOffset3D &srcEnd, const VkOffset3D &dstBegin, const VkOffset3D &dstEnd, CommandBuffer hCmdBuffer=CommandBuffer())
Copies source image region into destination image, potentially performing format conversion, arbitrary scaling and filtering.
static void cmdResetQueryPool(const QueryPool &hPool, std::uint32_t first, std::uint32_t count, CommandBuffer hCmdBuffer=CommandBuffer())
Resets a range of queries in a query pool.
static void cmdFillBuffer(const Buf &hDstBuffer, size_t offset, size_t size, std::uint32_t value, CommandBuffer hCmdBuffer=CommandBuffer())
Fills specified buffer (or a region of it) with constant value.
static void cmdUpdateBuffer(const Buf &hDstBuffer, size_t offset, size_t size, const std::uint32_t *pData, CommandBuffer hCmdBuffer=CommandBuffer())
Modifies a buffer region with specified data.
Represents a group of resources bound to rendering or compute pipeline.
Definition: vppShaderDataBlock.hpp:129
static void cmdCopyBufferToImage(const Buf &hSrcBuffer, const Img &hDstImage, VkImageLayout dstImageLayout, CommandBuffer hCmdBuffer=CommandBuffer())
Copies entire contents from a buffer to an image.