MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / begin_frame

Method begin_frame

framework/rendering/render_context.h:376–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374
375template <vkb::BindingType bindingType>
376inline void RenderContext<bindingType>::begin_frame()
377{
378 // Only handle surface changes if a swapchain exists
379 if (swapchain)
380 {
381 handle_surface_changes();
382 }
383
384 assert(!frame_active && "Frame is still active, please call end_frame");
385
386 auto &prev_frame = *frames[active_frame_index];
387
388 // We will use the acquired semaphore in a different frame context,
389 // so we need to hold ownership.
390 acquired_semaphore = prev_frame.get_semaphore_pool().request_semaphore_with_ownership();
391
392 if (swapchain)
393 {
394 vk::Result result;
395 try
396 {
397 std::tie(result, active_frame_index) = swapchain->acquire_next_image(acquired_semaphore);
398 }
399 catch (vk::OutOfDateKHRError & /*err*/)
400 {
401 result = vk::Result::eErrorOutOfDateKHR;
402 }
403
404 if (result == vk::Result::eSuboptimalKHR || result == vk::Result::eErrorOutOfDateKHR)
405 {
406#if defined(PLATFORM__MACOS)
407 // On Apple platforms, force swapchain update on both eSuboptimalKHR and eErrorOutOfDateKHR
408 // eSuboptimalKHR may occur on macOS/iOS following changes to swapchain other than extent/size
409 bool swapchain_updated = handle_surface_changes(true);
410#else
411 bool swapchain_updated = handle_surface_changes(result == vk::Result::eErrorOutOfDateKHR);
412#endif
413
414 if (swapchain_updated)
415 {
416 // Need to destroy and reallocate acquired_semaphore since it may have already been signaled
417 device.get_handle().destroySemaphore(acquired_semaphore);
418 acquired_semaphore = prev_frame.get_semaphore_pool().request_semaphore_with_ownership();
419 std::tie(result, active_frame_index) = swapchain->acquire_next_image(acquired_semaphore);
420 }
421 }
422
423 if (result != vk::Result::eSuccess)
424 {
425 prev_frame.reset();
426 return;
427 }
428 }
429
430 // Now the frame is active again
431 frame_active = true;
432
433 // Wait on all resource to be freed from the previous render to this frame

Callers 1

updateMethod · 0.80

Calls 4

acquire_next_imageMethod · 0.45
get_handleMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected