ngscopeclient 0.1-dev+51fbda87c
PipelineCacheManager.h
1/***********************************************************************************************************************
2* *
3* libscopeprotocols *
4* *
5* Copyright (c) 2012-2022 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
30#ifndef PipelineCacheManager_h
31#define PipelineCacheManager_h
32
33#include <vulkan/vulkan_raii.hpp>
34#include <memory>
35#include <string>
36#include <vector>
37#include <map>
38
39#pragma pack(push, 1)
41{
42 uint8_t cache_uuid[16];
43 time_t file_mtime;
44 int32_t vkfft_ver;
45 uint32_t driver_ver;
46 uint32_t len;
47 uint32_t crc;
48};
49#pragma pack(pop)
50
60{
61public:
64
65 std::shared_ptr< std::vector<uint8_t> > LookupRaw(const std::string& key);
66 void StoreRaw(const std::string& key, std::shared_ptr< std::vector<uint8_t> > value);
67
68 std::shared_ptr<vk::raii::PipelineCache> Lookup(const std::string& key, time_t target);
69
70 void LoadFromDisk();
71 void SaveToDisk();
72 void Clear();
73
74protected:
75 void FindPath();
76
78 std::mutex m_mutex;
79
81 std::map<std::string, std::shared_ptr<vk::raii::PipelineCache> > m_vkCache;
82
84 std::map<std::string, std::shared_ptr<std::vector<uint8_t> > > m_rawDataCache;
85
87 std::map<std::string, time_t> m_vkCacheTimestamps;
88
90 std::string m_cacheRootDir;
91};
92
93extern std::unique_ptr<PipelineCacheManager> g_pipelineCacheMgr;
94
95#endif
Helper for managing Vulkan / vkFFT pipeline cache objects.
Definition: PipelineCacheManager.h:60
std::map< std::string, std::shared_ptr< std::vector< uint8_t > > > m_rawDataCache
The actual cache data store.
Definition: PipelineCacheManager.h:84
~PipelineCacheManager()
Destroys the cache and writes it out to disk.
Definition: PipelineCacheManager.cpp:63
void Clear()
Removes all content from the cache.
Definition: PipelineCacheManager.cpp:114
void StoreRaw(const std::string &key, std::shared_ptr< std::vector< uint8_t > > value)
Store a raw blob to the cache.
Definition: PipelineCacheManager.cpp:140
std::map< std::string, std::shared_ptr< vk::raii::PipelineCache > > m_vkCache
Vulkan pipeline cache objects.
Definition: PipelineCacheManager.h:81
std::string m_cacheRootDir
Root directory of the cache.
Definition: PipelineCacheManager.h:90
void LoadFromDisk()
Loads cache content from disk.
Definition: PipelineCacheManager.cpp:196
void SaveToDisk()
Writes cache content out to disk.
Definition: PipelineCacheManager.cpp:293
std::shared_ptr< std::vector< uint8_t > > LookupRaw(const std::string &key)
Look up a blob which may or may not be in the cache.
Definition: PipelineCacheManager.cpp:124
std::mutex m_mutex
Mutex to interlock access to the STL containers.
Definition: PipelineCacheManager.h:78
std::map< std::string, time_t > m_vkCacheTimestamps
Modification timestamps of the files.
Definition: PipelineCacheManager.h:87
std::shared_ptr< vk::raii::PipelineCache > Lookup(const std::string &key, time_t target)
Returns a Vulkan pipeline cache object for the given path.
Definition: PipelineCacheManager.cpp:153
Definition: PipelineCacheManager.h:41