1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-29 16:16:38 +00:00

Resolve depth buffer in pass if supported by driver

This commit is contained in:
Bastiaan Olij
2025-10-08 23:23:51 +11:00
parent ef34c3d534
commit 21ffbecfa9
12 changed files with 152 additions and 37 deletions

View File

@@ -535,6 +535,7 @@ Error RenderingDeviceDriverVulkan::_initialize_device_extensions() {
_register_requested_device_extension(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME, false);
_register_requested_device_extension(VK_KHR_VULKAN_MEMORY_MODEL_EXTENSION_NAME, false);
_register_requested_device_extension(VK_EXT_TEXTURE_COMPRESSION_ASTC_HDR_EXTENSION_NAME, false);
_register_requested_device_extension(VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME, false);
// We don't actually use this extension, but some runtime components on some platforms
// can and will fill the validation layers with useless info otherwise if not enabled.
@@ -745,6 +746,9 @@ Error RenderingDeviceDriverVulkan::_check_device_capabilities() {
device_capabilities.version_major = VK_API_VERSION_MAJOR(physical_device_properties.apiVersion);
device_capabilities.version_minor = VK_API_VERSION_MINOR(physical_device_properties.apiVersion);
// Cache extension availability we query often.
framebuffer_depth_resolve = enabled_device_extension_names.has(VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME);
// References:
// https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_KHR_multiview.html
// https://www.khronos.org/blog/vulkan-subgroup-tutorial
@@ -1982,7 +1986,7 @@ RDD::TextureID RenderingDeviceDriverVulkan::texture_create(const TextureFormat &
if ((p_format.usage_bits & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT)) {
create_info.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
}
if ((p_format.usage_bits & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
if ((p_format.usage_bits & (TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | TEXTURE_USAGE_DEPTH_RESOLVE_ATTACHMENT_BIT))) {
create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
if ((p_format.usage_bits & TEXTURE_USAGE_INPUT_ATTACHMENT_BIT)) {
@@ -2073,7 +2077,7 @@ RDD::TextureID RenderingDeviceDriverVulkan::texture_create(const TextureFormat &
image_view_create_info.components.a = (VkComponentSwizzle)p_view.swizzle_a;
image_view_create_info.subresourceRange.levelCount = create_info.mipLevels;
image_view_create_info.subresourceRange.layerCount = create_info.arrayLayers;
if ((p_format.usage_bits & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
if ((p_format.usage_bits & (TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | TEXTURE_USAGE_DEPTH_RESOLVE_ATTACHMENT_BIT))) {
image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
} else {
image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
@@ -2454,6 +2458,7 @@ BitField<RDD::TextureUsageBits> RenderingDeviceDriverVulkan::texture_get_usages_
}
if (!(flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
supported.clear_flag(TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
supported.clear_flag(TEXTURE_USAGE_DEPTH_RESOLVE_ATTACHMENT_BIT);
}
if (!(flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) {
supported.clear_flag(TEXTURE_USAGE_STORAGE_BIT);
@@ -4851,12 +4856,32 @@ RDD::RenderPassID RenderingDeviceDriverVulkan::render_pass_create(VectorView<Att
VkFragmentShadingRateAttachmentInfoKHR *vk_fsr_info = ALLOCA_SINGLE(VkFragmentShadingRateAttachmentInfoKHR);
*vk_fsr_info = {};
vk_fsr_info->sType = VK_STRUCTURE_TYPE_FRAGMENT_SHADING_RATE_ATTACHMENT_INFO_KHR;
vk_fsr_info->pNext = vk_subpasses[i].pNext;
vk_fsr_info->pFragmentShadingRateAttachment = vk_subpass_fsr_attachment;
vk_fsr_info->shadingRateAttachmentTexelSize.width = p_subpasses[i].fragment_shading_rate_texel_size.x;
vk_fsr_info->shadingRateAttachmentTexelSize.height = p_subpasses[i].fragment_shading_rate_texel_size.y;
vk_subpasses[i].pNext = vk_fsr_info;
}
// Depth resolve.
if (framebuffer_depth_resolve && p_subpasses[i].depth_resolve_reference.attachment != AttachmentReference::UNUSED) {
VkAttachmentReference2KHR *vk_subpass_depth_resolve_attachment = ALLOCA_SINGLE(VkAttachmentReference2KHR);
*vk_subpass_depth_resolve_attachment = {};
vk_subpass_depth_resolve_attachment->sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR;
vk_subpass_depth_resolve_attachment->attachment = p_subpasses[i].depth_resolve_reference.attachment;
vk_subpass_depth_resolve_attachment->layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkSubpassDescriptionDepthStencilResolveKHR *vk_depth_resolve_info = ALLOCA_SINGLE(VkSubpassDescriptionDepthStencilResolveKHR);
*vk_depth_resolve_info = {};
vk_depth_resolve_info->sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE;
vk_depth_resolve_info->pNext = vk_subpasses[i].pNext;
vk_depth_resolve_info->depthResolveMode = VK_RESOLVE_MODE_MAX_BIT_KHR;
vk_depth_resolve_info->stencilResolveMode = VK_RESOLVE_MODE_NONE_KHR; // we don't resolve our stencil (for now)
vk_depth_resolve_info->pDepthStencilResolveAttachment = vk_subpass_depth_resolve_attachment;
vk_subpasses[i].pNext = vk_depth_resolve_info;
}
}
VkSubpassDependency2KHR *vk_subpass_dependencies = ALLOCA_ARRAY(VkSubpassDependency2KHR, p_subpass_dependencies.size());
@@ -6225,6 +6250,8 @@ bool RenderingDeviceDriverVulkan::has_feature(Features p_feature) {
#endif
case SUPPORTS_VULKAN_MEMORY_MODEL:
return vulkan_memory_model_support && vulkan_memory_model_device_scope_support;
case SUPPORTS_FRAMEBUFFER_DEPTH_RESOLVE:
return framebuffer_depth_resolve;
default:
return false;
}