Redesign program key construction
This does two things:
1) Moves responsibility for bit-packing portions of the key into the key
itself. A new GrKeyBuilder type manages adding bits, with asserts to
ensure a value always fits in the requested number. In theory this
will let us generate smaller keys overall, at the expense of slightly
more complex code during construction.
2) Adds a string label parameter for key methods that fold in data. For
new methods, the label is required. To ease migration, the old add32
does not require a label (yet). This will let us generate detailed,
human readable keys, either based on SK_DEBUG, or a runtime option
(if we're comfortable paying the cost).
Bug: skia:11372
Change-Id: Ib0f941551e0dbadabbd2a7de912b00e9e766b166
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/377876
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 18af842..e3d09e1 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -2349,7 +2349,7 @@
static bool gLoadPending = false;
if (gLoadPending) {
auto collectShaders = [this](sk_sp<const SkData> key, sk_sp<SkData> data,
- int hitCount) {
+ const SkString& description, int hitCount) {
CachedShader& entry(fCachedShaders.push_back());
entry.fKey = key;
SkMD5 hash;
@@ -2358,6 +2358,7 @@
for (int i = 0; i < 16; ++i) {
entry.fKeyString.appendf("%02x", digest.data[i]);
}
+ entry.fKeyDescription = description;
SkReadBuffer reader(data->data(), data->size());
entry.fShaderType = GrPersistentCacheUtils::GetType(&reader);
@@ -2414,6 +2415,10 @@
ImVec2 boxSize(-1.0f, ImGui::GetTextLineHeight() * std::min(lines, 30));
ImGui::InputTextMultiline(label, str, boxSize);
};
+ if (ImGui::TreeNode("Key")) {
+ ImGui::TextWrapped("%s", entry.fKeyDescription.c_str());
+ ImGui::TreePop();
+ }
stringBox("##VP", &entry.fShader[kVertex_GrShaderType]);
stringBox("##FP", &entry.fShader[kFragment_GrShaderType]);
ImGui::TreePop();
@@ -2461,7 +2466,7 @@
entry.fShader,
entry.fInputs,
kGrShaderTypeCount);
- fPersistentCache.store(*entry.fKey, *data);
+ fPersistentCache.store(*entry.fKey, *data, entry.fKeyDescription);
entry.fShader[kFragment_GrShaderType] = backup;
}