evan 2026.1.4
Evan
Loading...
Searching...
No Matches
PipelineCache.hpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** PipelineCache
6*/
7
8#pragma once
9
10#include "evan/EvanPlatform.hpp"
11
12#include <utility/logging/loggable.hpp>
13#include <utility/logging/default_logger.hpp>
14
15#include <cstddef>
16#include <filesystem>
17#include <vector>
18
19namespace evan
20{
48 protected utility::logging::Loggable<PipelineCache,
49 utility::logging::DefaultLogger>
50 {
51 public:
52 PipelineCache() = default;
53
54 ~PipelineCache() = default;
55
56 PipelineCache(const PipelineCache &) = delete;
57 PipelineCache &operator=(const PipelineCache &) = delete;
58
73
87 [[nodiscard]] static bool isBlobCompatible(
88 const std::vector<std::byte> &blob,
90
99 [[nodiscard]] static bool
100 readBlob(const std::filesystem::path &path,
101 std::vector<std::byte> &blob);
102
114 [[nodiscard]] static bool
115 writeBlob(const std::filesystem::path &path,
116 const std::vector<std::byte> &blob);
117
137 const std::filesystem::path &path);
138
146 void persist();
147
158
166 [[nodiscard]] VkPipelineCache getHandle() const { return _handle; }
167
173 [[nodiscard]] bool isPersistent() const { return !_path.empty(); }
174
175 private:
179 VkDevice _device = VK_NULL_HANDLE;
180
188
193 std::filesystem::path _path;
194
198 VkPipelineCacheHeaderVersionOne _expectedHeader {};
199 };
200} // namespace evan
Owns the Vulkan pipeline cache used when creating pipelines and persists it across runs.
VkPipelineCache getHandle() const
Retrieves the Vulkan handle to pass to vkCreateGraphicsPipelines.
void persist()
Flushes the pipeline cache to the path given to init().
static VkPipelineCacheHeaderVersionOne buildHeader(const VkPhysicalDeviceProperties &properties)
Builds the cache key of a physical device.
void init(VkDevice device, VkPhysicalDevice physicalDevice, const std::filesystem::path &path)
Creates the Vulkan pipeline cache.
void destroy(VkDevice device)
Destroys the Vulkan pipeline cache.
bool isPersistent() const
Tells whether the cache is written to and read from disk.
static bool writeBlob(const std::filesystem::path &path, const std::vector< std::byte > &blob)
Writes a pipeline cache blob to disk atomically.
static bool isBlobCompatible(const std::vector< std::byte > &blob, const VkPipelineCacheHeaderVersionOne &expected)
Tells whether a blob can safely be handed to the driver.
static bool readBlob(const std::filesystem::path &path, std::vector< std::byte > &blob)
Reads a whole pipeline cache blob from disk.
Small result wrapper used by helpers that must return both a status and a value (e....
Definition Error.hpp:89