QVulkanWindowRenderer Class▲
-
Header: QVulkanWindowRenderer
-
Since: Qt 5.10
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
-
qmake: QT += gui
Detailed Description▲
Applications typically subclass both QVulkanWindow and QVulkanWindowRenderer. The former allows handling events, for example, input, while the latter allows implementing the Vulkan resource management and command buffer building that make up the application's rendering.
In addition to event handling, the QVulkanWindow subclass is responsible for providing an implementation for QVulkanWindow::createRenderer() as well. This is where the window and renderer get connected. A typical implementation will simply create a new instance of a subclass of QVulkanWindowRenderer.
Member Function Documentation▲
[virtual] QVulkanWindowRenderer::~QVulkanWindowRenderer()▲
Virtual destructor.
[virtual] void QVulkanWindowRenderer::initResources()▲
This virtual function is called when it is time to create the renderer's graphics resources.
Depending on the QVulkanWindow::PersistentResources flag, device lost situations, etc. this function may be called more than once during the lifetime of a QVulkanWindow. However, subsequent invocations are always preceded by a call to releaseResources().
Accessors like device(), graphicsQueue() and graphicsCommandPool() are only guaranteed to return valid values inside this function and afterwards, up until releaseResources() is called.
The default implementation is empty.
[virtual] void QVulkanWindowRenderer::initSwapChainResources()▲
This virtual function is called when swapchain, framebuffer or renderpass related initialization can be performed. Swapchain and related resources are reset and then recreated in response to window resize events, and therefore a pair of calls to initResources() and releaseResources() can have multiple calls to initSwapChainResources() and releaseSwapChainResources() calls in-between.
Accessors like QVulkanWindow::swapChainImageSize() are only guaranteed to return valid values inside this function and afterwards, up until releaseSwapChainResources() is called.
This is also the place where size-dependent calculations (for example, the projection matrix) should be made since this function is called effectively on every resize.
The default implementation is empty.
[virtual] void QVulkanWindowRenderer::logicalDeviceLost()▲
This virtual function is called when the logical device (VkDevice) is lost, meaning some operation failed with VK_ERROR_DEVICE_LOST.
The default implementation is empty.
There is typically no need to perform anything special in this function. QVulkanWindow will automatically release all resources (invoking releaseSwapChainResources() and releaseResources() as necessary) and will attempt to reinitialize, acquiring a new device. When the physical device was also lost, this reinitialization attempt may then result in physicalDeviceLost().
See Also▲
See also physicalDeviceLost()
[virtual] void QVulkanWindowRenderer::physicalDeviceLost()▲
This virtual function is called when the physical device is lost, meaning the creation of the logical device fails with VK_ERROR_DEVICE_LOST.
The default implementation is empty.
There is typically no need to perform anything special in this function because QVulkanWindow will automatically retry to initialize itself after a certain amount of time.
See Also▲
See also logicalDeviceLost()
[virtual] void QVulkanWindowRenderer::preInitResources()▲
This virtual function is called right before graphics initialization, that ends up in calling initResources(), is about to begin.
Normally there is no need to reimplement this function. However, there are cases that involve decisions based on both the physical device and the surface. These cannot normally be performed before making the QVulkanWindow visible since the Vulkan surface is not retrievable at that stage.
Instead, applications can reimplement this function. Here both QVulkanWindow::physicalDevice() and QVulkanInstance::surfaceForWindow() are functional, but no further logical device initialization has taken place yet.
The default implementation is empty.
[virtual] void QVulkanWindowRenderer::releaseResources()▲
This virtual function is called when the renderer's graphics resources must be released.
The implementation must be prepared that a call to this function may be followed by an initResources() at a later point.
QVulkanWindow takes care of waiting for the device to become idle before and after invoking this function.
The default implementation is empty.
[virtual] void QVulkanWindowRenderer::releaseSwapChainResources()▲
This virtual function is called when swapchain, framebuffer or renderpass related resources must be released.
The implementation must be prepared that a call to this function may be followed by a new call to initSwapChainResources() at a later point.
QVulkanWindow takes care of waiting for the device to become idle before and after invoking this function.
The default implementation is empty.
This is the last place to act with all graphics resources intact before QVulkanWindow starts releasing them. It is therefore essential that implementations with an asynchronous, potentially multi-threaded startNextFrame() perform a blocking wait and call QVulkanWindow::frameReady() before returning from this function in case there is a pending frame submission.
[pure virtual] void QVulkanWindowRenderer::startNextFrame()▲
This virtual function is called when the draw calls for the next frame are to be added to the command buffer.
Each call to this function must be followed by a call to QVulkanWindow::frameReady(). Failing to do so will stall the rendering loop. The call can also be made at a later time, after returning from this function. This means that it is possible to kick off asynchronous work, and only update the command buffer and notify QVulkanWindow when that work has finished.
All Vulkan resources are initialized and ready when this function is invoked. The current framebuffer and main command buffer can be retrieved via QVulkanWindow::currentFramebuffer() and QVulkanWindow::currentCommandBuffer(). The logical device and the active graphics queue are available via QVulkanWindow::device() and QVulkanWindow::graphicsQueue(). Implementations can create additional command buffers from the pool returned by QVulkanWindow::graphicsCommandPool(). For convenience, the index of a host visible and device local memory type index are exposed via QVulkanWindow::hostVisibleMemoryIndex() and QVulkanWindow::deviceLocalMemoryIndex(). All these accessors are safe to be called from any thread.
See Also▲
See also QVulkanWindow::frameReady(), QVulkanWindow