Add MVK_EXCLUDE_CEREAL build option to avoid use of Cereal library.
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
index dc056f0..a6b7af4 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
@@ -25,9 +25,11 @@
#include "MTLRenderPipelineDescriptor+MoltenVK.h"
#include "mvk_datatypes.hpp"
+#ifndef MVK_EXCLUDE_CEREAL
#include <cereal/archives/binary.hpp>
#include <cereal/types/string.hpp>
#include <cereal/types/vector.hpp>
+#endif
using namespace std;
using namespace SPIRV_CROSS_NAMESPACE;
@@ -1971,7 +1973,9 @@
#pragma mark Streaming pipeline cache to and from offline memory
+#ifndef MVK_EXCLUDE_CEREAL
static uint32_t kDataHeaderSize = (sizeof(uint32_t) * 4) + VK_UUID_SIZE;
+#endif
// Entry type markers to be inserted into data stream
typedef enum {
@@ -2005,6 +2009,7 @@
// returns the number of bytes required to serialize the contents of this pipeline cache.
// This is the compliment of the readData() function. The two must be kept aligned.
VkResult MVKPipelineCache::writeData(size_t* pDataSize, void* pData) {
+#ifndef MVK_EXCLUDE_CEREAL
lock_guard<mutex> lock(_shaderCacheLock);
try {
@@ -2037,11 +2042,15 @@
*pDataSize = 0;
return reportError(VK_INCOMPLETE, "Error writing pipeline cache data: %s", ex.what());
}
+#else
+ MVKAssert(false, "Pipeline cache serialization is unavailable. To enable pipeline cache serialization, build MoltenVK without the MVK_EXCLUDE_CEREAL build setting.");
+ return reportError(VK_INCOMPLETE, "Pipeline cache serialization is unavailable.");
+#endif
}
// Serializes the data in this cache to a stream
void MVKPipelineCache::writeData(ostream& outstream, bool isCounting) {
-
+#ifndef MVK_EXCLUDE_CEREAL
MVKPerformanceTracker& activityTracker = isCounting
? _device->_performanceStatistics.pipelineCache.sizePipelineCache
: _device->_performanceStatistics.pipelineCache.writePipelineCache;
@@ -2077,11 +2086,15 @@
// Mark the end of the archive
cacheEntryType = MVKPipelineCacheEntryTypeEOF;
writer(cacheEntryType);
+#else
+ MVKAssert(false, "Pipeline cache serialization is unavailable. To enable pipeline cache serialization, build MoltenVK without the MVK_EXCLUDE_CEREAL build setting.");
+#endif
}
// Loads any data indicated by the creation info.
// This is the compliment of the writeData() function. The two must be kept aligned.
void MVKPipelineCache::readData(const VkPipelineCacheCreateInfo* pCreateInfo) {
+#ifndef MVK_EXCLUDE_CEREAL
try {
size_t byteCount = pCreateInfo->initialDataSize;
@@ -2151,6 +2164,9 @@
} catch (cereal::Exception& ex) {
setConfigurationResult(reportError(VK_SUCCESS, "Error reading pipeline cache data: %s", ex.what()));
}
+#else
+ MVKAssert(false, "Pipeline cache serialization is unavailable. To enable pipeline cache serialization, build MoltenVK without the MVK_EXCLUDE_CEREAL build setting.");
+#endif
}
// Mark the cache as dirty, so that existing streaming info is released