| 155 | } // namespace |
| 156 | |
| 157 | VulkanPipeline::VulkanPipeline(VkDevice device, uint32_t appVersionCode) : m_appVersionCode(appVersionCode) |
| 158 | { |
| 159 | // Read dump. |
| 160 | std::vector<uint8_t> dumpData; |
| 161 | auto const dumpFilePath = GetDumpFilePath(); |
| 162 | if (GetPlatform().IsFileExistsByFullPath(dumpFilePath)) |
| 163 | { |
| 164 | try |
| 165 | { |
| 166 | FileReader r(dumpFilePath); |
| 167 | NonOwningReaderSource src(r); |
| 168 | |
| 169 | auto const v = ReadPrimitiveFromSource<uint32_t>(src); |
| 170 | if (v != appVersionCode) |
| 171 | { |
| 172 | // Dump is obsolete. |
| 173 | FileWriter::DeleteFileX(dumpFilePath); |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | dumpData.resize(static_cast<size_t>(r.Size() - sizeof(uint32_t))); |
| 178 | src.Read(dumpData.data(), dumpData.size()); |
| 179 | } |
| 180 | } |
| 181 | catch (FileReader::Exception const & exception) |
| 182 | { |
| 183 | LOG(LWARNING, ("Exception while reading file:", dumpFilePath, "reason:", exception.what())); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {}; |
| 188 | pipelineCacheCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 189 | pipelineCacheCreateInfo.initialDataSize = dumpData.size(); |
| 190 | pipelineCacheCreateInfo.pInitialData = dumpData.data(); |
| 191 | auto result = vkCreatePipelineCache(device, &pipelineCacheCreateInfo, nullptr, &m_vulkanPipelineCache); |
| 192 | if (result != VK_SUCCESS && pipelineCacheCreateInfo.pInitialData != nullptr) |
| 193 | { |
| 194 | FileWriter::DeleteFileX(dumpFilePath); |
| 195 | pipelineCacheCreateInfo.initialDataSize = 0; |
| 196 | pipelineCacheCreateInfo.pInitialData = nullptr; |
| 197 | result = vkCreatePipelineCache(device, &pipelineCacheCreateInfo, nullptr, &m_vulkanPipelineCache); |
| 198 | } |
| 199 | if (result != VK_SUCCESS) |
| 200 | { |
| 201 | // The function vkCreatePipelineCache can return unspecified codes, so if we aren't able to |
| 202 | // create pipeline cache without saved state, we consider it as a driver issue and forbid Vulkan. |
| 203 | SupportManager::Instance().ForbidVulkan(); |
| 204 | CHECK(false, ("Fatal driver issue.")); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | void VulkanPipeline::Dump(VkDevice device) |
| 209 | { |
nothing calls this directly
no test coverage detected