|
| 1 | +// |
| 2 | +// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr) |
| 3 | +// |
| 4 | +// This code is released under an unmodified zlib license. |
| 5 | +// For conditions of distribution and use, please see: |
| 6 | +// https://opensource.org/licenses/Zlib |
| 7 | +// |
| 8 | + |
| 9 | +#ifndef SIEGE_ENGINE_SUBMIT_COMMANDS_H |
| 10 | +#define SIEGE_ENGINE_SUBMIT_COMMANDS_H |
| 11 | + |
| 12 | +#include <utils/collections/StackArray.h> |
| 13 | +#include <volk/volk.h> |
| 14 | + |
| 15 | +#include "Types.h" |
| 16 | + |
| 17 | +namespace Siege::Vulkan::Utils |
| 18 | +{ |
| 19 | + |
| 20 | +/** |
| 21 | + * Specifies the number of acceptable semaphores which can be submitted for signalling at any point |
| 22 | + * in time |
| 23 | + */ |
| 24 | +static inline constexpr size_t MAX_SEMAPHORES = 10; |
| 25 | + |
| 26 | +/** |
| 27 | + * The SubmitGraphicsCommand type handles all requirements for submitting draw commands to |
| 28 | + * the GPU's graphics queue. The purpose is to act as a readable storage container for submitting |
| 29 | + * graphics commands to the GPU |
| 30 | + */ |
| 31 | +struct SubmitGraphicsCommand |
| 32 | +{ |
| 33 | + /** |
| 34 | + * The number of command buffers which can be submitted for any single command submission |
| 35 | + */ |
| 36 | + static inline constexpr size_t MAX_COMMAND_BUFFERS = 10; |
| 37 | + |
| 38 | + /** |
| 39 | + * Specifies the Queue to submit to |
| 40 | + * @param targetQueue the queue to submit commands to |
| 41 | + * @return A reference to the command builder |
| 42 | + */ |
| 43 | + SubmitGraphicsCommand& ToQueue(VkQueue targetQueue); |
| 44 | + |
| 45 | + /** |
| 46 | + * Specifies which semaphores to wait on before submitting the commands |
| 47 | + * @param list a list of semaphores to wait on before submitting the commands |
| 48 | + * @return A reference to the command builder |
| 49 | + */ |
| 50 | + SubmitGraphicsCommand& WaitOnSemaphores(std::initializer_list<VkSemaphore> list); |
| 51 | + |
| 52 | + /** |
| 53 | + * Specifies which command buffers to submit to the graphics queue |
| 54 | + * @param list a list of all command buffers to use for drawing |
| 55 | + * @return A reference to the command builder |
| 56 | + */ |
| 57 | + SubmitGraphicsCommand& WithCommandBuffers(std::initializer_list<VkCommandBuffer> list); |
| 58 | + |
| 59 | + /** |
| 60 | + * Specifies which semaphores to signal once the submission has completed |
| 61 | + * @param list a list of semaphores to signal once submission is complete |
| 62 | + * @return A reference to the command builder |
| 63 | + */ |
| 64 | + SubmitGraphicsCommand& SignalSemaphores(std::initializer_list<VkSemaphore> list); |
| 65 | + |
| 66 | + /** |
| 67 | + * Specifies which pipeline stages the command applies to (vertex, fragment... etc) |
| 68 | + * @param list a list of the pipeline stages the command will affect |
| 69 | + * @return A reference to the command builder |
| 70 | + */ |
| 71 | + SubmitGraphicsCommand& WithPipelineStages(std::initializer_list<VkPipelineStageFlags> list); |
| 72 | + |
| 73 | + /** |
| 74 | + * Submits the command to the graphics queue |
| 75 | + * @param inFlightFence the per-frame fence the command should be submitted to |
| 76 | + */ |
| 77 | + void Submit(VkFence inFlightFence); |
| 78 | + |
| 79 | + VkQueue queue {VK_NULL_HANDLE}; |
| 80 | + ::Siege::Utils::MSArray<VkSemaphore, MAX_SEMAPHORES> waitSemaphores; |
| 81 | + ::Siege::Utils::MSArray<VkCommandBuffer, MAX_COMMAND_BUFFERS> commandBuffers; |
| 82 | + ::Siege::Utils::MSArray<VkSemaphore, MAX_SEMAPHORES> signalSemaphores; |
| 83 | + ::Siege::Utils::MSArray<VkPipelineStageFlags, MAX_SEMAPHORES> waitDstStageMask; |
| 84 | +}; |
| 85 | + |
| 86 | +/** |
| 87 | + * The SubmitPresentCommand type handles all requirements for submitting commands to the present |
| 88 | + * queue (the present queue actually handles the drawing of images to the screen). It acts as a |
| 89 | + * storage container for all data required to submit commands to the present queue. |
| 90 | + */ |
| 91 | +struct SubmitPresentCommand |
| 92 | +{ |
| 93 | + /** |
| 94 | + * The maximum number of swapchains to use for submission |
| 95 | + */ |
| 96 | + static inline constexpr size_t MAX_SWAPCHAINS = 10; |
| 97 | + /** |
| 98 | + * The maximum number of images (represented by indices) which can be submitted at once |
| 99 | + */ |
| 100 | + static inline constexpr size_t MAX_INDICES = 10; |
| 101 | + |
| 102 | + /** |
| 103 | + * Specifies the Queue to submit to |
| 104 | + * @param targetQueue the queue to submit commands to |
| 105 | + * @return A reference to the command builder |
| 106 | + */ |
| 107 | + SubmitPresentCommand& ToQueue(VkQueue targetQueue); |
| 108 | + |
| 109 | + /** |
| 110 | + * Specifies which semaphores to signal once the submission has completed |
| 111 | + * @param list a list of semaphores to signal once submission is complete |
| 112 | + * @return A reference to the command builder |
| 113 | + */ |
| 114 | + SubmitPresentCommand& SignalSemaphores(std::initializer_list<VkSemaphore> list); |
| 115 | + |
| 116 | + /** |
| 117 | + * Specifies which swapchains the command will apply to |
| 118 | + * @param list a list of swapchains to use for submission |
| 119 | + * @return A reference to the command builder |
| 120 | + */ |
| 121 | + SubmitPresentCommand& ForSwapchains(std::initializer_list<VkSwapchainKHR> list); |
| 122 | + |
| 123 | + /** |
| 124 | + * Specifies which images to use for submission |
| 125 | + * @param list a list of images to be used for presentation |
| 126 | + * @return A reference to the command builder |
| 127 | + */ |
| 128 | + SubmitPresentCommand& WithImageIndices(std::initializer_list<uint32_t> list); |
| 129 | + |
| 130 | + /** |
| 131 | + * @brief Submits the command to the present queue |
| 132 | + * @return the result of the submission. Can return the following:\n |
| 133 | + * SUCCESS - The submission was successful\n |
| 134 | + * SUBOPTIMAL - The swapchain no longer matches the surface exactly (this can happen when a |
| 135 | + * window is resized)\n OUT_OF_DATE - A surface has changed in such a way that the swapchain is |
| 136 | + * no longer compatible with it\n RESIZED - The window has been resized and we must rebuild our |
| 137 | + * swapchain to match the new extents\n |
| 138 | + */ |
| 139 | + Utils::Result Submit(); |
| 140 | + |
| 141 | + VkQueue queue {VK_NULL_HANDLE}; |
| 142 | + ::Siege::Utils::MSArray<VkSemaphore, MAX_SEMAPHORES> signalSemaphores; |
| 143 | + ::Siege::Utils::MSArray<VkSwapchainKHR, MAX_SWAPCHAINS> swapchains; |
| 144 | + ::Siege::Utils::MSArray<uint32_t, MAX_INDICES> indices; |
| 145 | +}; |
| 146 | +} // namespace Siege::Vulkan::Utils |
| 147 | + |
| 148 | +#endif // SIEGE_ENGINE_SUBMIT_COMMANDS_H |
0 commit comments