-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Supporting Dynamic Rendering
One of the API's, I am going to start thinking about is how vulkan-cpp can support dynamic rendering.
Dynamic rendering is really useful and removes the need to keep track of the renderpass states. Directly supplying render attachments directly to your commands for executing inside that specific command.
I am still looking more into dynamic rendering to understand more of the Vulkan's API
Enabling Dynamic Rendering
Enabling dynamic rendering can be done by defining a feature structure to enable dynamic rendering and the VK_KHR_dynamic_rendering extension.
VkPhysicalDeviceDynamicRenderingFeature dynamic_rendering_feature = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES,
.pNext = NULL,
.dynamicRendering = true
};
VkDeviceCreateInfo device_ci = {
.pNext = &dynamic_rendering_feature,
};Rendering Attachments
Because dynamic rendering removes the need to handle renderpasses. This will include a very different way for specifying attachments
Meaning there will be two ways for handling attachments. Such as vk::attachment and vk::rendering_attachment.
Where vk::attachment is used by the renderpass and vk::rendering_attachment is used by dynamic rendering. I plan in having a distinction of these naming to remove confusion. These can potentially be renamed, but for now that is the name I will have it be as a placeholder.
Vulkan API (without vulkan-cpp)
This is a small code snippet of what I know about dynamic rendering in terms of specifying attachments and executing them part of a specific command buffer
// specify color and depth attachments (if we did for layout = 0 and layout = 1)
std::array<VkAttachmentReference, 2> color_attachments = {...};
VkAttachmentReference depth_attachment = {....}
// specifying the rendering attachment
VkRenderingAttachmentInfo render_attachment = {
.renderArea = {},
.layerCount = 1,
.viewMask = 0,
.colorAttachmentCount = static_cast<uint32_t>(color_attachments.size()),
.pColorAttachments = color_attachments.data(),
.pDepthAttachments = &depth_attachment,
.pStencilAttachment = nullptr
};
// this is to bind and make draw calls between these API calls
vkCmdBeginRendering(current_command_buffer, &render_attachment);
vkCmdEndRendering(current_command_buffer);
vulkan-cpp API Idea
This is just a rough idea on how I may approach in allowing this to work with using vulkan-cpp's wrappers.
This code example is meant to be a high-level overview of what the API if we used dynamic rendering would look like.
vk::command_buffer current_command = command_buffers[frame_idx];
std::array<vk::rendering_attachment, 2> attachments = {
vk::rendering_attachment{
....
},
vk::rendering_attachment{
...
}
}
};
current_command.begin_rendering(attachments);
current_command.end_rendering();