/** Please see header for specification */ Anvil::PipelineCache::PipelineCache(const Anvil::BaseDevice* in_device_ptr, bool in_mt_safe, size_t in_initial_data_size, const void* in_initial_data) :DebugMarkerSupportProvider(in_device_ptr, Anvil::ObjectType::PIPELINE_CACHE), MTSafetySupportProvider (in_mt_safe), m_device_ptr (in_device_ptr), m_pipeline_cache (VK_NULL_HANDLE) { VkPipelineCacheCreateInfo cache_create_info; VkResult result_vk (VK_ERROR_INITIALIZATION_FAILED); ANVIL_REDUNDANT_VARIABLE(result_vk); cache_create_info.flags = 0; cache_create_info.initialDataSize = in_initial_data_size; cache_create_info.pInitialData = in_initial_data; cache_create_info.pNext = nullptr; cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; result_vk = Anvil::Vulkan::vkCreatePipelineCache(m_device_ptr->get_device_vk(), &cache_create_info, nullptr, /* pAllocator */ &m_pipeline_cache); anvil_assert_vk_call_succeeded(result_vk); if (is_vk_call_successful(result_vk) ) { set_vk_handle(m_pipeline_cache); } anvil_assert(m_pipeline_cache != VK_NULL_HANDLE); /* Register the instance */ Anvil::ObjectTracker::get()->register_object(Anvil::ObjectType::PIPELINE_CACHE, this); }
/** Please see header for specification */ uint32_t Anvil::Swapchain::acquire_image(Anvil::Semaphore* in_opt_semaphore_ptr, bool in_should_block) { uint32_t result (UINT32_MAX); VkResult result_vk (VK_ERROR_INITIALIZATION_FAILED); const WindowPlatform window_platform (m_create_info_ptr->get_window()->get_platform() ); const bool is_offscreen_rendering_enabled( (window_platform == WINDOW_PLATFORM_DUMMY || window_platform == WINDOW_PLATFORM_DUMMY_WITH_PNG_SNAPSHOTS) ); ANVIL_REDUNDANT_VARIABLE(result_vk); if (!is_offscreen_rendering_enabled) { VkFence fence_handle = VK_NULL_HANDLE; if (in_opt_semaphore_ptr != nullptr) { in_opt_semaphore_ptr->lock(); } m_image_available_fence_ptr->lock(); lock(); { const auto& khr_swapchain_entrypoints = m_device_ptr->get_extension_khr_swapchain_entrypoints(); if (in_should_block) { m_image_available_fence_ptr->reset(); fence_handle = m_image_available_fence_ptr->get_fence(); } result_vk = khr_swapchain_entrypoints.vkAcquireNextImageKHR(m_device_ptr->get_device_vk(), m_swapchain, UINT64_MAX, (in_opt_semaphore_ptr != nullptr) ? in_opt_semaphore_ptr->get_semaphore() : VK_NULL_HANDLE, fence_handle, &result); if (fence_handle != VK_NULL_HANDLE) { result_vk = vkWaitForFences(m_device_ptr->get_device_vk(), 1, /* fenceCount */ &fence_handle, VK_TRUE, /* waitAll */ UINT64_MAX); anvil_assert_vk_call_succeeded(result_vk); } } unlock(); m_image_available_fence_ptr->unlock(); if (in_opt_semaphore_ptr != nullptr) { in_opt_semaphore_ptr->unlock(); } anvil_assert_vk_call_succeeded(result_vk); } else { if (in_should_block) { m_device_ptr->wait_idle(); } if (in_opt_semaphore_ptr != nullptr) { /* We need to set the semaphore manually in this scenario */ m_device_ptr->get_universal_queue(0)->submit( Anvil::SubmitInfo::create_signal(1, /* n_semaphores_to_signal */ &in_opt_semaphore_ptr) ); } result = m_n_acquire_counter_rounded; } m_n_acquire_counter++; m_n_acquire_counter_rounded = (m_n_acquire_counter_rounded + 1) % m_create_info_ptr->get_n_images(); m_last_acquired_image_index = result; return result; }