NDEVR
API Documentation
VulkanRenderPipeline.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Graphics
28File: VulkanRenderPipeline
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "VulkanDefines.h"
34#include "VulkanImage.h"
35#include "VulkanRenderDefinition.h"
36#include "ImageResources.h"
37
38#include "NDEVRGraphics/Headers/GraphicsPipeline.h"
39#include "Base/Headers/String.h"
40#include "Base/Headers/Pointer.hpp"
41#include "Base/Headers/Buffer.hpp"
42namespace NDEVR
43{
44 struct SwapChainSupportDetails;
45 class File;
46 class Log;
47 class WindowInstance;
48 class VulkanSession;
51 struct SwapChainSupportDetails;
52
57 class VulkanRenderPipeline : public GraphicsPipeline
58 {
59 protected:
62 {
63 VkSemaphore semaphore = vk_null;
64 bool is_active = false;
65 };
66
72
74 {
75 VkSurfaceCapabilitiesKHR capabilities = {};
76 PrimitiveBuffer<VkSurfaceFormatKHR> formats;
77 PrimitiveBuffer<VkPresentModeKHR> presentModes;
78 };
79 public:
80 VulkanRenderPipeline(VulkanSession* session);
81 VulkanRenderPipeline(const VulkanRenderPipeline& pipeline) = delete;
82 virtual ~VulkanRenderPipeline();
83 void cleanResources() override;
84 void setDevice(const DynamicPointer<VulkanDevice>& instance);
85 void init(GraphicsUpdateArguments& args) override;
86 void setWindowInstance(WindowInstance* instance) override;
87 void cleanup() override;
88 void getKHRImage(GraphicsUpdateArguments& args);
89 void getGrabImage(GraphicsUpdateArguments& args);
90 bool runCommand(GraphicsUpdateArguments& args) override;
91 virtual void drawFrame(GraphicsUpdateArguments& args) override;
92 virtual bool needsRecreateSwapchain(GraphicsUpdateArguments& args);
93 virtual bool executeDrawCycle(GraphicsUpdateArguments& args);
94 void invalidateImages();
95 virtual void submitQueue(GraphicsUpdateArguments& args);
96 void presentKHR(GraphicsUpdateArguments& args);
97 //void setSession(const DynamicPointer<VulkanSession>& session);
99 void setSwapChainImageFormat(VkFormat format);
100 DynamicPointer<VulkanRenderDefinition>& getRenderDefinition();
101 void setupSwapChainImages(Buffer<VkImage>& images, uint04 multisample_count);
102 virtual const ConstPointer<GraphicsDevice>& device() const override;
104 void setGrabImage(Image* image);
105 void imageWait();
106 void setClearColor(const RGBColor& color);
108 protected:
109 void ensureFinished(uint04 frame_index);
110 void addReadback(GraphicsUpdateArguments& args);
111 VkResult finishBlockingReadback(GraphicsUpdateArguments& args);
112 virtual void cleanupSwapChainResources(bool clean_khr);
113 virtual void cleanupKHR();
114 virtual void recreateSwapChainResources(GraphicsUpdateArguments& args);
115 void setShadowImages(GraphicsUpdateArguments& args);
116 void setViewportImages(GraphicsUpdateArguments& args);
117 void setMultisampleImages(GraphicsUpdateArguments& args);
118 bool needsSurfaceUpdate() const;
119 void setupSurface();
120 virtual void createKHRImages(uint04 multisample_count);
121 void createGrabImages(uint04 multisample_count);
122 static fltp08 ScreenSizeAllocationFactor();
123 [[nodiscard]] PrimitiveBuffer<VkClearValue> clearValues() const;
124 SwapChainSupportDetails queryKHRSupport(VkPhysicalDevice_T* device);
125 VkSurfaceFormatKHR chooseSwapSurfaceFormat(const PrimitiveBuffer<VkSurfaceFormatKHR>& availableFormats);
126 Vector<2, uint04> chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, const Vector<2, uint04>& requested_size);
127
128 bool needsCleanup() const { return m_needs_cleanup; }
129 virtual bool createSwapChainKHR(GraphicsUpdateArguments& args);
130 void createCommandBuffers();
131
132 virtual void commit(GraphicsUpdateArguments&) override {};
134 virtual bool hasCommand() const override { return false; };
135 protected:
136 bool updateFrameSize(GraphicsUpdateArguments& args);
137 protected:
138 VkSurfaceKHR m_surface;
139 VkSwapchainKHR m_khr_swap_chain;
149
154
158 VkQueue_T* m_present_queue = vk_null;
171
172 };
173}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
A GraphicsPipeline is a set of resources that are chained together to correctly render something.
Options that are used for performing an update on a Graphics Engine call.
A root class that stores an an array of pixel data that can be displayed as an Image.
Definition Image.h:40
Serves as the primary program interface for processes to report issues and allows any number of LogSt...
Definition Log.h:50
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
Creates specific information for performing a render pass within Vulkan.
RGBColor m_clear_color
The clear color for the render pass.
Buffer< VulkanImageResources > m_frames
Per-frame image resources.
void ensureLastRenderComplete() override
Blocks until the last submitted render is complete.
Image * m_grab_image
The CPU-side image for frame readback.
virtual const ConstPointer< GraphicsDevice > & device() const override
Returns the graphics device (const).
VkQueue_T * m_present_queue
The Vulkan queue used for presentation.
DynamicPointer< VulkanImageData > m_multisample_image_color
Multisample color resolve image.
bool m_needs_grab_image
Whether a grab image readback is pending.
DynamicPointer< VulkanImageData > m_depth_image
Depth buffer image.
ConstPointer< SwapChainSupportDetails > m_swap_chain_support_details
Cached swap chain support details.
Vector< 2, uint04 > m_draw_size
The current draw dimensions in pixels.
DynamicPointer< VulkanImageView > m_shadow_view
View for the shadow map.
DynamicPointer< VulkanDevice > m_device
The Vulkan device for this pipeline.
virtual void commit(GraphicsUpdateArguments &) override
Commits pending changes to the GPU.
uint04 m_pipeline_acquire
The current acquire index for semaphore cycling.
uint04 m_number_of_khr_images
The number of KHR swap chain images.
bool createPipeline(GraphicsUpdateArguments &args) override
Creates or recreates the rendering pipeline.
void setWindowInstance(WindowInstance *instance) override
Associates a window instance with this pipeline.
DynamicPointer< VulkanImageData > m_shadow_image
Shadow map image.
DynamicPointer< VulkanImageView > m_depth_view
View for the depth buffer.
const DynamicPointer< GraphicsDevice > & device() override
Returns the graphics device.
void cleanup() override
Releases all GPU resources.
WindowInstance * m_window_instance
The window instance this pipeline renders to.
DynamicPointer< VulkanRenderDefinition > m_render_definition
The render pass definition.
uint08 m_khr_format
The KHR swap chain image format as an integer.
VkSwapchainKHR m_khr_swap_chain
The KHR swap chain handle.
Time m_surface_update_time
The last time the surface was updated.
bool runCommand(GraphicsUpdateArguments &args) override
Executes a queued rendering command.
void init(GraphicsUpdateArguments &args) override
Initializes the pipeline with the given arguments.
uint04 m_number_of_grab_images
The number of grab image resources.
virtual void updateUniformBuffer(GraphicsUpdateArguments &) override
Updates the camera uniform buffer on the GPU.
VkSurfaceKHR m_surface
The Vulkan surface for this pipeline.
uint04 m_last_image_idx
The index of the last acquired swap chain image.
void cleanResources() override
Cleans up stale or unused GPU resources.
VulkanSession * m_session
The owning Vulkan session.
DynamicPointer< VulkanImageView > m_multisample_view_color
View for the multisample color image.
Buffer< PipelineSemaphores > m_semaphores
Semaphores for each frame in flight.
virtual void drawFrame(GraphicsUpdateArguments &args) override
Renders a single frame.
bool m_needs_pipeline_recreation
Whether the pipeline needs to be recreated.
bool m_suboptimal_khr
Whether the KHR swap chain is suboptimal.
bool m_needs_cleanup
Whether a cleanup pass is needed.
bool m_is_init
Whether the pipeline has been initialized.
DynamicPointer< VulkanImageData > m_frame_grab_image
Image used for frame readback.
virtual bool hasCommand() const override
Checks whether there are pending commands to execute.
Creates and manages the resources necessary for converting a DesignObjectLookup into 3D rendered data...
Contains core information about a Viewport.
The primary namespace for the NDEVR SDK.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
A semaphore paired with an active flag for pipeline synchronization.
bool is_active
Whether this semaphore is currently in use.
VkSemaphore semaphore
The Vulkan semaphore handle.
Paired acquire and finish semaphores for a single frame in the render pipeline.
PipelineSemaphore finished
Signaled when rendering to this frame completes.
PipelineSemaphore acquire
Signaled when the swap chain image is acquired.
Details about swap chain support on a physical device.
PrimitiveBuffer< VkSurfaceFormatKHR > formats
Supported surface formats.
VkSurfaceCapabilitiesKHR capabilities
Surface capabilities.
PrimitiveBuffer< VkPresentModeKHR > presentModes
Supported presentation modes.