Update SPIRV caching to use SkWriter32/SkReader32 and allow inspection
Change-Id: I6656d971c05f0ed3515f095ffcd41ae73a5c483f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206687
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrPersistentCacheUtils.h b/src/gpu/GrPersistentCacheUtils.h
index 88b4840..a3c34ef 100644
--- a/src/gpu/GrPersistentCacheUtils.h
+++ b/src/gpu/GrPersistentCacheUtils.h
@@ -14,7 +14,9 @@
#include "SkSLString.h"
#include "SkWriter32.h"
-// Pack/unpack functions, to be shared by backend and debugging utils?
+// The GrPersistentCache stores opaque blobs, as far as clients are concerned. It's helpful to
+// inspect certain kinds of cached data within our tools, so for those cases (GLSL, SPIR-V), we
+// put the serialization logic here, to be shared by the backend code and the tool code.
namespace GrPersistentCacheUtils {
static inline void PackCachedGLSL(SkWriter32& writer, const SkSL::Program::Inputs& inputs,
@@ -35,6 +37,24 @@
}
}
+static inline void PackCachedSPIRV(SkWriter32& writer, const SkSL::String shaders[],
+ const SkSL::Program::Inputs inputs[]) {
+ for (int i = 0; i < kGrShaderTypeCount; ++i) {
+ writer.writeString(shaders[i].c_str(), shaders[i].size());
+ writer.writePad(&inputs[i], sizeof(inputs[i]));
+ }
+}
+
+static inline void UnpackCachedSPIRV(SkReader32& reader, SkSL::String shaders[],
+ SkSL::Program::Inputs inputs[]) {
+ for (int i = 0; i < kGrShaderTypeCount; ++i) {
+ size_t stringLen = 0;
+ const char* string = reader.readString(&stringLen);
+ shaders[i] = SkSL::String(string, stringLen);
+ reader.read(&inputs[i], sizeof(inputs[i]));
+ }
+}
+
}
#endif