VPP  0.7
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  VkImageLayout imageLayout,
250  const VkClearColorValue& color,
251  CommandBuffer hCmdBuffer = CommandBuffer() );
252 
256  static void cmdClearColorImage (
257  const Img& hImage,
258  VkImageLayout imageLayout,
259  const VkClearColorValue& color,
260  const std::vector< VkImageSubresourceRange >& regions,
261  CommandBuffer hCmdBuffer = CommandBuffer() );
262 
266  static void cmdClearDepthStencilImage (
267  const Img& hImage,
268  VkImageLayout imageLayout,
269  float depth, std::uint32_t stencil,
270  CommandBuffer hCmdBuffer = CommandBuffer() );
271 
275  static void cmdClearDepthStencilImage (
276  const Img& hImage,
277  VkImageLayout imageLayout,
278  float depth, std::uint32_t stencil,
279  const std::vector< VkImageSubresourceRange >& regions,
280  CommandBuffer hCmdBuffer = CommandBuffer() );
281 
285  static void cmdResetQueryPool (
286  const QueryPool& hPool,
287  std::uint32_t first,
288  std::uint32_t count,
289  CommandBuffer hCmdBuffer = CommandBuffer() );
290 
294  static void cmdResetQueryPool (
295  const QueryPool& hPool,
296  CommandBuffer hCmdBuffer = CommandBuffer() );
297 
298  static void cmdCopyQueryPoolResults (
299  const Buf& hDstBuffer,
300  const QueryPool& hPool,
301  VkQueryResultFlags flags,
302  std::uint32_t count,
303  std::uint32_t first,
304  VkDeviceSize dstOffset,
305  CommandBuffer hCmdBuffer = CommandBuffer() );
306 
307  static void cmdCopyQueryPoolResults (
308  const Buf& hDstBuffer,
309  const QueryPool& hPool,
310  VkQueryResultFlags flags,
311  CommandBuffer hCmdBuffer = CommandBuffer() );
312 };
313 
314 // -----------------------------------------------------------------------------
336 {
337 public:
338  static void cmdExecuteCommands (
339  const VkCommandBuffer* pBuffers,
340  size_t size,
341  CommandBuffer hCmdBuffer = CommandBuffer() );
342 
343  static void cmdExecuteCommands (
344  const CommandBuffer* pBuffers,
345  size_t size,
346  CommandBuffer hCmdBuffer = CommandBuffer() );
347 
348  static void cmdExecuteCommands (
349  const std::vector< CommandBuffer >& buffers,
350  CommandBuffer hCmdBuffer = CommandBuffer() );
351 
352  static void cmdWaitEvents (
353  const std::vector< Event >& events,
354  VkPipelineStageFlags srcStageMask,
355  VkPipelineStageFlags dstStageMask,
356  const Barriers& barriers = Barriers(),
357  CommandBuffer hCmdBuffer = CommandBuffer() );
358 
359  static void cmdPipelineBarrier (
360  VkPipelineStageFlags srcStageMask,
361  VkPipelineStageFlags dstStageMask,
362  VkDependencyFlags dependencyFlags,
363  const Barriers& barriers,
364  CommandBuffer hCmdBuffer = CommandBuffer() );
365 
366  static void cmdImagePipelineBarrier (
367  const Img& image,
368  VkPipelineStageFlags srcStageMask,
369  VkPipelineStageFlags dstStageMask,
370  VkAccessFlags srcAccessMask,
371  VkAccessFlags dstAccessMask,
372  bool bByRegion,
373  VkImageLayout oldLayout = VK_IMAGE_LAYOUT_GENERAL,
374  VkImageLayout newLayout = VK_IMAGE_LAYOUT_GENERAL,
375  int mipLevel = -1,
376  int arrayLayer = -1,
377  CommandBuffer hCmdBuffer = CommandBuffer()
378  );
379 
380  static void cmdBufferPipelineBarrier (
381  const Buf& hBuffer,
382  VkPipelineStageFlags srcStageMask,
383  VkPipelineStageFlags dstStageMask,
384  VkAccessFlags srcAccessMask,
385  VkAccessFlags dstAccessMask,
386  CommandBuffer hCmdBuffer = CommandBuffer()
387  );
388 
389  static void cmdSetViewport (
390  const VkViewport& viewport,
391  std::uint32_t index = 0,
392  CommandBuffer hCmdBuffer = CommandBuffer() );
393 
394  static void cmdSetViewport (
395  const std::vector< VkViewport >& viewports,
396  std::uint32_t first = 0,
397  CommandBuffer hCmdBuffer = CommandBuffer() );
398 
399  static void cmdSetLineWidth (
400  float lineWidth,
401  CommandBuffer hCmdBuffer = CommandBuffer() );
402 
403  static void cmdSetDepthBias (
404  float constantFactor,
405  float clamp,
406  float slopeFactor,
407  CommandBuffer hCmdBuffer = CommandBuffer() );
408 
409  static void cmdSetDepthBounds (
410  float minDepthBounds,
411  float maxDepthBounds,
412  CommandBuffer hCmdBuffer = CommandBuffer() );
413 
414  static void cmdSetScissor (
415  const VkRect2D& scissor,
416  std::uint32_t index = 0,
417  CommandBuffer hCmdBuffer = CommandBuffer() );
418 
419  static void cmdSetScissor (
420  const std::vector< VkRect2D >& scissors,
421  std::uint32_t first = 0,
422  CommandBuffer hCmdBuffer = CommandBuffer() );
423 
424  static void cmdSetStencilCompareMask (
425  VkStencilFaceFlags faceMask,
426  std::uint32_t compareMask,
427  CommandBuffer hCmdBuffer = CommandBuffer() );
428 
429  static void cmdSetStencilWriteMask (
430  VkStencilFaceFlags faceMask,
431  std::uint32_t writeMask,
432  CommandBuffer hCmdBuffer = CommandBuffer() );
433 
434  static void cmdSetStencilReference (
435  VkStencilFaceFlags faceMask,
436  std::uint32_t reference,
437  CommandBuffer hCmdBuffer = CommandBuffer() );
438 
439  static void cmdSetBlendConstants (
440  const float blendConstants [ 4 ],
441  CommandBuffer hCmdBuffer = CommandBuffer() );
442 
443  static void cmdBeginQuery (
444  const QueryPool& hPool,
445  std::uint32_t query,
446  VkQueryControlFlags flags,
447  CommandBuffer hCmdBuffer = CommandBuffer() );
448 
449  static void cmdEndQuery (
450  const QueryPool& hPool,
451  std::uint32_t query,
452  CommandBuffer hCmdBuffer = CommandBuffer() );
453 
454  static void cmdWriteTimestamp (
455  const QueryPool& hPool,
456  std::uint32_t query,
457  VkPipelineStageFlagBits pipelineStage,
458  CommandBuffer hCmdBuffer = CommandBuffer() );
459 
460  static void cmdBindPipeline (
461  const Pipeline& hPipeline,
462  VkPipelineBindPoint pipelineBindPoint,
463  CommandBuffer hCmdBuffer = CommandBuffer() );
464 
465  static void cmdBindDescriptorSets (
466  const ShaderDataBlock& hDataBlock,
467  CommandBuffer hCmdBuffer = CommandBuffer() );
468 
469  static void cmdBindIndexInput (
470  const Buf& hBuffer,
471  VkIndexType indexType,
472  VkDeviceSize offset,
473  CommandBuffer hCmdBuffer = CommandBuffer() );
474 
475  static void cmdBindVertexBuffers (
476  const std::vector< Buf >& buffers,
477  const std::vector< VkDeviceSize >& offsets,
478  std::uint32_t first = 0,
479  CommandBuffer hCmdBuffer = CommandBuffer() );
480 
481  static void cmdBindVertexBuffers (
482  const std::vector< Buf >& buffers,
483  std::uint32_t first = 0,
484  CommandBuffer hCmdBuffer = CommandBuffer() );
485 
486  static void cmdPushConstants (
487  const PipelineLayoutBase& hPipelineLayout,
488  VkShaderStageFlags stageFlags,
489  const void* pValues,
490  std::uint32_t size,
491  std::uint32_t offset = 0,
492  CommandBuffer hCmdBuffer = CommandBuffer() );
493 };
494 
495 // -----------------------------------------------------------------------------
496 // -----------------------------------------------------------------------------
497 
499  public NonRenderingCommands,
500  public UniversalCommands
501 {
502 public:
503  static void cmdChangeImageLayout (
504  const Img& hImage,
505  VkImageLayout oldImageLayout,
506  VkImageLayout newImageLayout,
507  std::uint32_t levelCount = 1,
508  std::uint32_t layerCount = 1,
509  std::uint32_t baseMipLevel = 0,
510  std::uint32_t baseArrayLayer = 0,
511  VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
512  CommandBuffer hCmdBuffer = CommandBuffer() );
513 };
514 
515 // -----------------------------------------------------------------------------
516 } // namespace vpp
517 // -----------------------------------------------------------------------------
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:335
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.
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:498
static void cmdCopyImageToBuffer(const Img &hSrcImage, VkImageLayout srcImageLayout, const Buf &hDstBuffer, CommandBuffer hCmdBuffer=CommandBuffer())
Copies entire contents from an image to a buffer.
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.
static void cmdClearColorImage(const Img &hImage, VkImageLayout imageLayout, const VkClearColorValue &color, CommandBuffer hCmdBuffer=CommandBuffer())
Clears an image with specified color.
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.