Skip to content

Commit f94bf17

Browse files
committed
Merge pull request godotengine#87466 from BastiaanOlij/fix_openxr_render_target_multiplier
OpenXR: Cleanup swapchain logic (was Fix render target multiplier)
2 parents bff6955 + c388fe2 commit f94bf17

File tree

4 files changed

+346
-241
lines changed

4 files changed

+346
-241
lines changed

modules/openxr/extensions/openxr_composition_layer_extension.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,20 @@ XrCompositionLayerBaseHeader *OpenXRViewportCompositionLayerProvider::get_compos
196196
return nullptr;
197197
}
198198

199-
if (swapchain_info.swapchain == XR_NULL_HANDLE) {
199+
if (swapchain_info.get_swapchain() == XR_NULL_HANDLE) {
200200
// Don't have a swapchain to display? Ignore our layer.
201201
return nullptr;
202202
}
203203

204-
if (swapchain_info.image_acquired) {
205-
openxr_api->release_image(swapchain_info);
204+
if (swapchain_info.is_image_acquired()) {
205+
swapchain_info.release();
206206
}
207207

208208
// Update the layer struct for the swapchain.
209209
switch (composition_layer->type) {
210210
case XR_TYPE_COMPOSITION_LAYER_QUAD: {
211211
XrCompositionLayerQuad *quad_layer = (XrCompositionLayerQuad *)composition_layer;
212-
quad_layer->subImage.swapchain = swapchain_info.swapchain;
212+
quad_layer->subImage.swapchain = swapchain_info.get_swapchain();
213213
quad_layer->subImage.imageArrayIndex = 0;
214214
quad_layer->subImage.imageRect.offset.x = 0;
215215
quad_layer->subImage.imageRect.offset.y = 0;
@@ -219,7 +219,7 @@ XrCompositionLayerBaseHeader *OpenXRViewportCompositionLayerProvider::get_compos
219219

220220
case XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR: {
221221
XrCompositionLayerCylinderKHR *cylinder_layer = (XrCompositionLayerCylinderKHR *)composition_layer;
222-
cylinder_layer->subImage.swapchain = swapchain_info.swapchain;
222+
cylinder_layer->subImage.swapchain = swapchain_info.get_swapchain();
223223
cylinder_layer->subImage.imageArrayIndex = 0;
224224
cylinder_layer->subImage.imageRect.offset.x = 0;
225225
cylinder_layer->subImage.imageRect.offset.y = 0;
@@ -229,7 +229,7 @@ XrCompositionLayerBaseHeader *OpenXRViewportCompositionLayerProvider::get_compos
229229

230230
case XR_TYPE_COMPOSITION_LAYER_EQUIRECT2_KHR: {
231231
XrCompositionLayerEquirect2KHR *equirect_layer = (XrCompositionLayerEquirect2KHR *)composition_layer;
232-
equirect_layer->subImage.swapchain = swapchain_info.swapchain;
232+
equirect_layer->subImage.swapchain = swapchain_info.get_swapchain();
233233
equirect_layer->subImage.imageArrayIndex = 0;
234234
equirect_layer->subImage.imageRect.offset.x = 0;
235235
equirect_layer->subImage.imageRect.offset.y = 0;
@@ -269,14 +269,16 @@ bool OpenXRViewportCompositionLayerProvider::update_and_acquire_swapchain(bool p
269269
}
270270

271271
// See if our current swapchain is outdated.
272-
if (swapchain_info.swapchain != XR_NULL_HANDLE) {
272+
if (swapchain_info.get_swapchain() != XR_NULL_HANDLE) {
273273
// If this swap chain, or the previous one, were static, then we can't reuse it.
274274
if (swapchain_size == viewport_size && !p_static_image && !static_image) {
275275
// We're all good! Just acquire it.
276-
return openxr_api->acquire_image(swapchain_info);
276+
// We can ignore should_render here, return will be false.
277+
XrBool32 should_render = true;
278+
return swapchain_info.acquire(should_render);
277279
}
278280

279-
openxr_api->free_swapchain(swapchain_info);
281+
swapchain_info.queue_free();
280282
}
281283

282284
// Create our new swap chain
@@ -287,22 +289,24 @@ bool OpenXRViewportCompositionLayerProvider::update_and_acquire_swapchain(bool p
287289
if (p_static_image) {
288290
create_flags |= XR_SWAPCHAIN_CREATE_STATIC_IMAGE_BIT;
289291
}
290-
if (!openxr_api->create_swapchain(create_flags, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT | XR_SWAPCHAIN_USAGE_MUTABLE_FORMAT_BIT, swapchain_format, viewport_size.width, viewport_size.height, sample_count, array_size, swapchain_info.swapchain, &swapchain_info.swapchain_graphics_data)) {
292+
if (!swapchain_info.create(create_flags, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT | XR_SWAPCHAIN_USAGE_MUTABLE_FORMAT_BIT, swapchain_format, viewport_size.width, viewport_size.height, sample_count, array_size)) {
291293
swapchain_size = Size2i();
292294
return false;
293295
}
294296

295-
// Acquire our image so we can start rendering into it
296-
bool ret = openxr_api->acquire_image(swapchain_info);
297+
// Acquire our image so we can start rendering into it,
298+
// we can ignore should_render here, ret will be false.
299+
XrBool32 should_render = true;
300+
bool ret = swapchain_info.acquire(should_render);
297301

298302
swapchain_size = viewport_size;
299303
static_image = p_static_image;
300304
return ret;
301305
}
302306

303307
void OpenXRViewportCompositionLayerProvider::free_swapchain() {
304-
if (swapchain_info.swapchain != XR_NULL_HANDLE) {
305-
openxr_api->free_swapchain(swapchain_info);
308+
if (swapchain_info.get_swapchain() != XR_NULL_HANDLE) {
309+
swapchain_info.queue_free();
306310
}
307311

308312
swapchain_size = Size2i();
@@ -314,5 +318,5 @@ RID OpenXRViewportCompositionLayerProvider::get_current_swapchain_texture() {
314318
return RID();
315319
}
316320

317-
return openxr_api->get_image(swapchain_info);
321+
return swapchain_info.get_image();
318322
}

modules/openxr/extensions/platform/openxr_vulkan_extension.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ void OpenXRVulkanExtension::get_usable_swapchain_formats(Vector<int64_t> &p_usab
229229
}
230230

231231
void OpenXRVulkanExtension::get_usable_depth_formats(Vector<int64_t> &p_usable_swap_chains) {
232+
// Note, it is very likely we do NOT support any of depth formats where we can combine our stencil support (e.g. _S8_UINT).
233+
// Right now this isn't a problem but once stencil support becomes an issue, we need to check for this in the rendering engine
234+
// and create a separate buffer for the stencil.
235+
232236
p_usable_swap_chains.push_back(VK_FORMAT_D24_UNORM_S8_UINT);
233237
p_usable_swap_chains.push_back(VK_FORMAT_D32_SFLOAT_S8_UINT);
234238
p_usable_swap_chains.push_back(VK_FORMAT_D32_SFLOAT);

0 commit comments

Comments
 (0)