Merge pull request #67227 from BastiaanOlij/vkCreateRenderPass2KHR_fallback
Added fallback to vkCreateRenderPass
This commit is contained in:
commit
d5ae80c8bd
2 changed files with 114 additions and 6 deletions
|
@ -48,15 +48,119 @@
|
||||||
|
|
||||||
VulkanHooks *VulkanContext::vulkan_hooks = nullptr;
|
VulkanHooks *VulkanContext::vulkan_hooks = nullptr;
|
||||||
|
|
||||||
VkResult VulkanContext::vkCreateRenderPass2KHR(VkDevice p_device, const VkRenderPassCreateInfo2 *p_create_info, const VkAllocationCallbacks *p_allocator, VkRenderPass *p_render_pass) {
|
Vector<VkAttachmentReference> VulkanContext::_convert_VkAttachmentReference2(uint32_t p_count, const VkAttachmentReference2 *p_refs) {
|
||||||
if (fpCreateRenderPass2KHR == nullptr) {
|
Vector<VkAttachmentReference> att_refs;
|
||||||
fpCreateRenderPass2KHR = (PFN_vkCreateRenderPass2KHR)vkGetInstanceProcAddr(inst, "vkCreateRenderPass2KHR");
|
|
||||||
|
if (p_refs != nullptr) {
|
||||||
|
for (uint32_t i = 0; i < p_count; i++) {
|
||||||
|
// We lose aspectMask in this conversion but we don't use it currently.
|
||||||
|
|
||||||
|
VkAttachmentReference ref = {
|
||||||
|
p_refs[i].attachment, /* attachment */
|
||||||
|
p_refs[i].layout /* layout */
|
||||||
|
};
|
||||||
|
|
||||||
|
att_refs.push_back(ref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fpCreateRenderPass2KHR == nullptr) {
|
return att_refs;
|
||||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
}
|
||||||
|
|
||||||
|
VkResult VulkanContext::vkCreateRenderPass2KHR(VkDevice p_device, const VkRenderPassCreateInfo2 *p_create_info, const VkAllocationCallbacks *p_allocator, VkRenderPass *p_render_pass) {
|
||||||
|
if (has_renderpass2_ext) {
|
||||||
|
if (fpCreateRenderPass2KHR == nullptr) {
|
||||||
|
fpCreateRenderPass2KHR = (PFN_vkCreateRenderPass2KHR)vkGetDeviceProcAddr(p_device, "vkCreateRenderPass2KHR");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fpCreateRenderPass2KHR == nullptr) {
|
||||||
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||||
|
} else {
|
||||||
|
return (fpCreateRenderPass2KHR)(p_device, p_create_info, p_allocator, p_render_pass);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return (fpCreateRenderPass2KHR)(p_device, p_create_info, p_allocator, p_render_pass);
|
// need to fall back on vkCreateRenderPass
|
||||||
|
|
||||||
|
const void *next = p_create_info->pNext; // ATM we only support multiview which should work if supported.
|
||||||
|
|
||||||
|
Vector<VkAttachmentDescription> attachments;
|
||||||
|
for (uint32_t i = 0; i < p_create_info->attachmentCount; i++) {
|
||||||
|
// Basically the old layout just misses type and next.
|
||||||
|
VkAttachmentDescription att = {
|
||||||
|
p_create_info->pAttachments[i].flags, /* flags */
|
||||||
|
p_create_info->pAttachments[i].format, /* format */
|
||||||
|
p_create_info->pAttachments[i].samples, /* samples */
|
||||||
|
p_create_info->pAttachments[i].loadOp, /* loadOp */
|
||||||
|
p_create_info->pAttachments[i].storeOp, /* storeOp */
|
||||||
|
p_create_info->pAttachments[i].stencilLoadOp, /* stencilLoadOp */
|
||||||
|
p_create_info->pAttachments[i].stencilStoreOp, /* stencilStoreOp */
|
||||||
|
p_create_info->pAttachments[i].initialLayout, /* initialLayout */
|
||||||
|
p_create_info->pAttachments[i].finalLayout /* finalLayout */
|
||||||
|
};
|
||||||
|
|
||||||
|
attachments.push_back(att);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<VkSubpassDescription> subpasses;
|
||||||
|
for (uint32_t i = 0; i < p_create_info->subpassCount; i++) {
|
||||||
|
// Here we need to do more, again it's just stripping out type and next
|
||||||
|
// but we have VkAttachmentReference2 to convert to VkAttachmentReference.
|
||||||
|
// Also viewmask is not supported but we don't use it outside of multiview.
|
||||||
|
|
||||||
|
Vector<VkAttachmentReference> input_attachments = _convert_VkAttachmentReference2(p_create_info->pSubpasses[i].inputAttachmentCount, p_create_info->pSubpasses[i].pInputAttachments);
|
||||||
|
Vector<VkAttachmentReference> color_attachments = _convert_VkAttachmentReference2(p_create_info->pSubpasses[i].colorAttachmentCount, p_create_info->pSubpasses[i].pColorAttachments);
|
||||||
|
Vector<VkAttachmentReference> resolve_attachments = _convert_VkAttachmentReference2(p_create_info->pSubpasses[i].colorAttachmentCount, p_create_info->pSubpasses[i].pResolveAttachments);
|
||||||
|
Vector<VkAttachmentReference> depth_attachments = _convert_VkAttachmentReference2(p_create_info->pSubpasses[i].colorAttachmentCount, p_create_info->pSubpasses[i].pDepthStencilAttachment);
|
||||||
|
|
||||||
|
VkSubpassDescription subpass = {
|
||||||
|
p_create_info->pSubpasses[i].flags, /* flags */
|
||||||
|
p_create_info->pSubpasses[i].pipelineBindPoint, /* pipelineBindPoint */
|
||||||
|
p_create_info->pSubpasses[i].inputAttachmentCount, /* inputAttachmentCount */
|
||||||
|
input_attachments.size() == 0 ? nullptr : input_attachments.ptr(), /* pInputAttachments */
|
||||||
|
p_create_info->pSubpasses[i].colorAttachmentCount, /* colorAttachmentCount */
|
||||||
|
color_attachments.size() == 0 ? nullptr : color_attachments.ptr(), /* pColorAttachments */
|
||||||
|
resolve_attachments.size() == 0 ? nullptr : resolve_attachments.ptr(), /* pResolveAttachments */
|
||||||
|
depth_attachments.size() == 0 ? nullptr : depth_attachments.ptr(), /* pDepthStencilAttachment */
|
||||||
|
p_create_info->pSubpasses[i].preserveAttachmentCount, /* preserveAttachmentCount */
|
||||||
|
p_create_info->pSubpasses[i].pPreserveAttachments /* pPreserveAttachments */
|
||||||
|
};
|
||||||
|
|
||||||
|
subpasses.push_back(subpass);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<VkSubpassDependency> dependencies;
|
||||||
|
for (uint32_t i = 0; i < p_create_info->dependencyCount; i++) {
|
||||||
|
// We lose viewOffset here but again I don't believe we use this anywhere.
|
||||||
|
VkSubpassDependency dep = {
|
||||||
|
p_create_info->pDependencies[i].srcSubpass, /* srcSubpass */
|
||||||
|
p_create_info->pDependencies[i].dstSubpass, /* dstSubpass */
|
||||||
|
p_create_info->pDependencies[i].srcStageMask, /* srcStageMask */
|
||||||
|
p_create_info->pDependencies[i].dstStageMask, /* dstStageMask */
|
||||||
|
p_create_info->pDependencies[i].srcAccessMask, /* srcAccessMask */
|
||||||
|
p_create_info->pDependencies[i].dstAccessMask, /* dstAccessMask */
|
||||||
|
p_create_info->pDependencies[i].dependencyFlags, /* dependencyFlags */
|
||||||
|
};
|
||||||
|
|
||||||
|
dependencies.push_back(dep);
|
||||||
|
}
|
||||||
|
|
||||||
|
// CorrelatedViewMask is not supported in vkCreateRenderPass but we
|
||||||
|
// currently only use this for multiview.
|
||||||
|
// We'll need to look into this.
|
||||||
|
|
||||||
|
VkRenderPassCreateInfo create_info = {
|
||||||
|
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, /* sType */
|
||||||
|
next, /* pNext*/
|
||||||
|
p_create_info->flags, /* flags */
|
||||||
|
(uint32_t)attachments.size(), /* attachmentCount */
|
||||||
|
attachments.ptr(), /* pAttachments */
|
||||||
|
(uint32_t)subpasses.size(), /* subpassCount */
|
||||||
|
subpasses.ptr(), /* pSubpasses */
|
||||||
|
(uint32_t)dependencies.size(), /* */
|
||||||
|
dependencies.ptr(), /* */
|
||||||
|
};
|
||||||
|
|
||||||
|
return vkCreateRenderPass(device, &create_info, p_allocator, p_render_pass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,6 +1164,7 @@ Error VulkanContext::_create_physical_device(VkSurfaceKHR p_surface) {
|
||||||
extension_names[enabled_extension_count++] = VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME;
|
extension_names[enabled_extension_count++] = VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME;
|
||||||
}
|
}
|
||||||
if (!strcmp(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME, device_extensions[i].extensionName)) {
|
if (!strcmp(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME, device_extensions[i].extensionName)) {
|
||||||
|
has_renderpass2_ext = true;
|
||||||
extension_names[enabled_extension_count++] = VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME;
|
extension_names[enabled_extension_count++] = VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME;
|
||||||
}
|
}
|
||||||
if (enabled_extension_count >= MAX_EXTENSIONS) {
|
if (enabled_extension_count >= MAX_EXTENSIONS) {
|
||||||
|
|
|
@ -188,6 +188,7 @@ private:
|
||||||
uint32_t enabled_extension_count = 0;
|
uint32_t enabled_extension_count = 0;
|
||||||
const char *extension_names[MAX_EXTENSIONS];
|
const char *extension_names[MAX_EXTENSIONS];
|
||||||
bool enabled_debug_utils = false;
|
bool enabled_debug_utils = false;
|
||||||
|
bool has_renderpass2_ext = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if VK_EXT_debug_report extension is used. VK_EXT_debug_report is deprecated but it is
|
* True if VK_EXT_debug_report extension is used. VK_EXT_debug_report is deprecated but it is
|
||||||
|
@ -257,6 +258,8 @@ private:
|
||||||
Error _create_swap_chain();
|
Error _create_swap_chain();
|
||||||
Error _create_semaphores();
|
Error _create_semaphores();
|
||||||
|
|
||||||
|
Vector<VkAttachmentReference> _convert_VkAttachmentReference2(uint32_t p_count, const VkAttachmentReference2 *p_refs);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const char *_get_platform_surface_extension() const = 0;
|
virtual const char *_get_platform_surface_extension() const = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue