| 77 | } |
| 78 | |
| 79 | bool PipelineCache::prepare(const vkb::ApplicationOptions &options) |
| 80 | { |
| 81 | if (!VulkanSample::prepare(options)) |
| 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | /* Try to read pipeline cache file if exists */ |
| 87 | std::vector<uint8_t> pipeline_data; |
| 88 | |
| 89 | try |
| 90 | { |
| 91 | pipeline_data = vkb::fs::read_temp("pipeline_cache.data"); |
| 92 | } |
| 93 | catch (std::runtime_error &ex) |
| 94 | { |
| 95 | LOGW("No pipeline cache found. {}", ex.what()); |
| 96 | } |
| 97 | |
| 98 | /* Add initial pipeline cache data from the cached file */ |
| 99 | VkPipelineCacheCreateInfo create_info{VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO}; |
| 100 | create_info.initialDataSize = pipeline_data.size(); |
| 101 | create_info.pInitialData = pipeline_data.data(); |
| 102 | |
| 103 | /* Create Vulkan pipeline cache */ |
| 104 | VK_CHECK(vkCreatePipelineCache(get_device().get_handle(), &create_info, nullptr, &pipeline_cache)); |
| 105 | |
| 106 | vkb::ResourceCache &resource_cache = get_device().get_resource_cache(); |
| 107 | |
| 108 | // Use pipeline cache to store pipelines |
| 109 | resource_cache.set_pipeline_cache(pipeline_cache); |
| 110 | |
| 111 | std::vector<uint8_t> data_cache; |
| 112 | |
| 113 | try |
| 114 | { |
| 115 | data_cache = vkb::fs::read_temp("cache.data"); |
| 116 | } |
| 117 | catch (std::runtime_error &ex) |
| 118 | { |
| 119 | LOGW("No data cache found. {}", ex.what()); |
| 120 | } |
| 121 | |
| 122 | // Build all pipelines from a previous run |
| 123 | resource_cache.warmup(data_cache); |
| 124 | |
| 125 | get_stats().request_stats({vkb::StatIndex::frame_times}); |
| 126 | |
| 127 | float dpi_factor = window->get_dpi_factor(); |
| 128 | |
| 129 | button_size.x = button_size.x * dpi_factor; |
| 130 | button_size.y = button_size.y * dpi_factor; |
| 131 | |
| 132 | create_gui(*window, &get_stats()); |
| 133 | |
| 134 | load_scene("scenes/sponza/Sponza01.gltf"); |
| 135 | |
| 136 | auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); |
nothing calls this directly
no test coverage detected