Reland "Redesign program key construction"
This is a reland of bbbf1a7f50a303bd76163793bd5968c72f5f4432
Original change's description:
> 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>
Bug: skia:11372
Cq-Include-Trybots: luci.skia.skia.primary:Test-Win10-MSVC-Golo-GPU-QuadroP400-x86_64-Debug-All-Vulkan
Change-Id: I179ed581bc9ba772191e727274ac0ac6979ebdf3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/378778
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrStencilSettings.cpp b/src/gpu/GrStencilSettings.cpp
index f57b7a4..7313858 100644
--- a/src/gpu/GrStencilSettings.cpp
+++ b/src/gpu/GrStencilSettings.cpp
@@ -244,39 +244,30 @@
}
void GrStencilSettings::genKey(GrProcessorKeyBuilder* b, bool includeRefs) const {
- b->add32(fFlags);
+ b->addBits(6, fFlags, "stencilFlags");
if (this->isDisabled()) {
return;
}
if (!this->isTwoSided()) {
- constexpr int kCount16 = sizeof(Face) / sizeof(uint16_t);
- static_assert(0 == sizeof(Face) % sizeof(uint16_t));
- uint16_t* key = reinterpret_cast<uint16_t*>(b->add32n((kCount16 + 1) / 2));
if (includeRefs) {
- memcpy(key, &fCWFace, sizeof(Face));
+ b->addBytes(sizeof(Face), &fCWFace, "stencilCWFace");
} else {
Face tempFace = fCWFace;
tempFace.fRef = 0;
- memcpy(key, &tempFace, sizeof(Face));
+ b->addBytes(sizeof(Face), &tempFace, "stencilCWFace");
}
- key[kCount16] = 0;
- static_assert(1 == kCount16 % 2);
} else {
- constexpr int kCount32 = (2 * sizeof(Face)) / sizeof(uint32_t);
- static_assert(0 == (2 * sizeof(Face)) % sizeof(uint32_t));
- uint32_t* key = b->add32n(kCount32);
if (includeRefs) {
- memcpy(key, &fCWFace, 2 * sizeof(Face));
- static_assert(
- sizeof(Face) ==
- offsetof(GrStencilSettings, fCCWFace) - offsetof(GrStencilSettings, fCWFace));
+ b->addBytes(sizeof(Face), &fCWFace, "stencilCWFace");
+ b->addBytes(sizeof(Face), &fCCWFace, "stencilCCWFace");
} else {
Face tempFaces[2];
tempFaces[0] = fCWFace;
tempFaces[0].fRef = 0;
tempFaces[1] = fCCWFace;
tempFaces[1].fRef = 0;
- memcpy(key, &tempFaces, 2 * sizeof(Face));
+ b->addBytes(sizeof(Face), &tempFaces[0], "stencilCWFace");
+ b->addBytes(sizeof(Face), &tempFaces[1], "stencilCCWFace");
}
}
// We rely on GrStencilSettings::Face being tightly packed for the key to be reliable.