Skip to content

Conversation

BastiaanOlij
Copy link
Contributor

Small addition to #108636, we need to resolve to overridden depth buffer when depth buffer override is used as we're likely using the overridden depth buffer content elsewhere.

For OpenXR this scenario applies when we're submitting the depth buffer to OpenXR for reprojection.

With resolving to depth buffer, we don't need to resolve again when copying to back buffer or we'd be doubling up.

Note

On mobile hardware such as Quest, this is a very costly way of resolving as we're writing MSAA depth data to the MSAA texture and reading it back in. I still plan on reviving #78598. However for platforms not supporting the needed Vulkan extension, this completes our fallback scenario.

@BastiaanOlij
Copy link
Contributor Author

@dsnopek I haven't tested this yet but as a completion of the fallback logic, you may want to test this yourself as well :)

@BastiaanOlij BastiaanOlij force-pushed the fix_mobile_depth_resolve_for_openxr branch from 7586ecf to 13c3dd5 Compare October 6, 2025 13:57
@BastiaanOlij
Copy link
Contributor Author

Ok, looks like I hit a snag with this.

Because of the way we're creating our depth buffer in the OpenXR module, we can't write into it with the resolve shader. It's the wrong format, and has the wrong attachment type.

I'm looking into verifying those findings but it leaves us with a problem because we have no knowledge or access to the viewport with which we're about to render our XR content, and on which we can detect that MSAA is applicable and we need to change the format.

@BastiaanOlij
Copy link
Contributor Author

After a bunch of testing I was able to validate what I thought.
If MSAA is used and the fallback resolve is used, we need to create the depth swapchain with different settings.

I've hardcoded the changes to make it work, this is not a solution but:

In openxr_api.cpp:1271 note the usage of XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT and VK_FORMAT_D32_SFLOAT:

if (depth_swapchain_format != 0 && submit_depth_buffer && OpenXRCompositionLayerDepthExtension::get_singleton()->is_available()) {
	if (!render_state.main_swapchains[OPENXR_SWAPCHAIN_DEPTH].create(0, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT, VK_FORMAT_D32_SFLOAT, render_state.main_swapchain_size.width, render_state.main_swapchain_size.height, sample_count, view_configuration_views.size())) {
		return false;
	}

	...

And in openxr_vulkan_extension.cpp:327:

case VK_FORMAT_D32_SFLOAT:
	format = RenderingDevice::DATA_FORMAT_D32_SFLOAT;
	// usage_flags |= RenderingDevice::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
	usage_flags |= RenderingDevice::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
	break;

(this code should really switch on the usage_flags given to our create function).

But as I mentioned in my previous message, we don't have access to the MSAA configuration of the viewport here.

@BastiaanOlij
Copy link
Contributor Author

@clayjohn if you have any suggestions on the above, whether we can somehow combine these...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant