Add a "path_fuzz" mode to the PLS fuzzer

Merge all fuzzers into a single application named "fuzz". Add another fuzzer that generates random paths. Fix some bugs it found.

Diffs=
1d0d2b6ac Add a "path_fuzz" mode to the PLS fuzzer (#7211)

Co-authored-by: Chris Dalton <99840794+csmartdalton@users.noreply.github.com>
diff --git a/.rive_head b/.rive_head
index cb09d2a..2b396c2 100644
--- a/.rive_head
+++ b/.rive_head
@@ -1 +1 @@
-0d03a416b584cdd95aa4b496df105c14cdd2c05c
+1d0d2b6acd58a8541bf0fa01a9ac0b5bb761e65a
diff --git a/renderer/pls_draw.cpp b/renderer/pls_draw.cpp
index bd39ed0..d311117 100644
--- a/renderer/pls_draw.cpp
+++ b/renderer/pls_draw.cpp
@@ -370,6 +370,7 @@
         const AABB& localBounds = path->getBounds();
         // FIXME! Implement interior triangulation in depthStencil mode.
         if (context->frameInterlockMode() != pls::InterlockMode::depthStencil &&
+            path->getRawPath().verbs().count() < 1000 &&
             pls::FindTransformedArea(localBounds, matrix) > 512 * 512)
         {
             return PLSDrawUniquePtr(context->make<InteriorTriangulationDraw>(
@@ -406,6 +407,7 @@
     m_paintType(paint->getType())
 {
     assert(m_pathRef != nullptr);
+    assert(!m_pathRef->getRawPath().empty());
     assert(paint != nullptr);
     if (m_blendMode == BlendMode::srcOver && paint->getIsOpaque())
     {
@@ -470,23 +472,21 @@
 {
     // Make sure the rawPath in our path reference hasn't changed since we began holding!
     assert(m_rawPathMutationID == m_pathRef->getRawPathMutationID());
+    assert(!m_pathRef->getRawPath().empty());
 
     size_t tessVertexCount = m_type == Type::midpointFanPath
                                  ? m_resourceCounts.midpointFanTessVertexCount
                                  : m_resourceCounts.outerCubicTessVertexCount;
-    if (tessVertexCount == 0)
+    if (tessVertexCount > 0)
     {
-        return;
+        // Push a path record.
+        flush->pushPath(this,
+                        m_type == Type::midpointFanPath ? PatchType::midpointFan
+                                                        : PatchType::outerCurves,
+                        tessVertexCount);
+
+        onPushToRenderContext(flush);
     }
-    assert(!m_pathRef->getRawPath().empty());
-
-    // Push a path record.
-    flush->pushPath(this,
-                    m_type == Type::midpointFanPath ? PatchType::midpointFan
-                                                    : PatchType::outerCurves,
-                    tessVertexCount);
-
-    onPushToRenderContext(flush);
 }
 
 void PLSPathDraw::releaseRefs()
@@ -520,11 +520,7 @@
     // Count up how much temporary storage this function will need to reserve in CPU buffers.
     const RawPath& rawPath = m_pathRef->getRawPath();
     size_t contourCount = rawPath.countMoveTos();
-    if (contourCount == 0)
-    {
-        // The entire batch is empty.
-        return;
-    }
+    assert(contourCount != 0);
 
     m_contours = reinterpret_cast<ContourInfo*>(
         context->perFrameAllocator().alloc(sizeof(ContourInfo) * contourCount));
@@ -601,9 +597,9 @@
         if (closed)
         {
             Vec2D finalPtInContour = iter.rawPtsPtr()[-1];
-            // Bit-cast to uint64_t because we don't want the special equality rules for NaN inside
-            // of Vec2D::operator==. If we're empty or otherwise return back to p0, we want to
-            // detect this, regardless of whether there are NaN values.
+            // Bit-cast to uint64_t because we don't want the special equality rules for NaN. If
+            // we're empty or otherwise return back to p0, we want to detect this, regardless of
+            // whether there are NaN values.
             if (math::bit_cast<uint64_t>(startOfContour.movePt()) !=
                 math::bit_cast<uint64_t>(finalPtInContour))
             {
@@ -1274,7 +1270,11 @@
         else if (contour.closed)
         {
             implicitClose[0] = end.rawPtsPtr()[-1];
-            if (implicitClose[0] != implicitClose[1])
+            // Bit-cast to uint64_t because we don't want the special equality rules for NaN. If
+            // we're empty or otherwise return back to p0, we want to detect this, regardless of
+            // whether there are NaN values.
+            if (math::bit_cast<uint64_t>(implicitClose[0]) !=
+                math::bit_cast<uint64_t>(implicitClose[1]))
             {
                 // Draw a line back to the beginning of the contour.
                 std::array<Vec2D, 4> cubic = convert_line_to_cubic(implicitClose);
@@ -1512,18 +1512,22 @@
         // We also draw each "grout" triangle using an outerCubic patch.
         patchCount += m_triangulator->groutList().count();
 
-        m_resourceCounts.pathCount = 1;
-        m_resourceCounts.contourCount = contourCount;
-        // maxTessellatedSegmentCount does not get doubled when we emit both forward and mirrored
-        // contours because the forward and mirrored pair both get packed into a single
-        // pls::TessVertexSpan.
-        m_resourceCounts.maxTessellatedSegmentCount = patchCount;
-        // outerCubic patches emit their tessellated geometry twice: once forward and once mirrored.
-        m_resourceCounts.outerCubicTessVertexCount =
-            m_contourDirections == pls::ContourDirections::reverseAndForward
-                ? patchCount * kOuterCurvePatchSegmentSpan * 2
-                : patchCount * kOuterCurvePatchSegmentSpan;
-        m_resourceCounts.maxTriangleVertexCount = m_triangulator->maxVertexCount();
+        if (patchCount > 0)
+        {
+            m_resourceCounts.pathCount = 1;
+            m_resourceCounts.contourCount = contourCount;
+            // maxTessellatedSegmentCount does not get doubled when we emit both forward and
+            // mirrored contours because the forward and mirrored pair both get packed into a single
+            // pls::TessVertexSpan.
+            m_resourceCounts.maxTessellatedSegmentCount = patchCount;
+            // outerCubic patches emit their tessellated geometry twice: once forward and once
+            // mirrored.
+            m_resourceCounts.outerCubicTessVertexCount =
+                m_contourDirections == pls::ContourDirections::reverseAndForward
+                    ? patchCount * kOuterCurvePatchSegmentSpan * 2
+                    : patchCount * kOuterCurvePatchSegmentSpan;
+            m_resourceCounts.maxTriangleVertexCount = m_triangulator->maxVertexCount();
+        }
     }
     else
     {
diff --git a/renderer/pls_render_context.cpp b/renderer/pls_render_context.cpp
index 9f03815..785a9e0 100644
--- a/renderer/pls_render_context.cpp
+++ b/renderer/pls_render_context.cpp
@@ -22,11 +22,12 @@
 
 constexpr size_t kMaxTextureHeight = 2048; // TODO: Move this variable to PlatformFeatures.
 constexpr size_t kMaxTessellationVertexCount = kMaxTextureHeight * kTessTextureWidth;
+constexpr size_t kMaxTessellationPaddingVertexCount =
+    pls::kMidpointFanPatchSegmentSpan +      // Padding at the beginning of the tess texture
+    (pls::kOuterCurvePatchSegmentSpan - 1) + // Max padding between patch types in the tess texture
+    1;                                       // Padding at the end of the tessellation texture
 constexpr size_t kMaxTessellationVertexCountBeforePadding =
-    kMaxTessellationVertexCount -
-    pls::kMidpointFanPatchSegmentSpan -       // Padding at the beginning of the tess texture
-    (pls::kMidpointFanPatchSegmentSpan - 1) - // Max padding between patch types in the tess texture
-    1;                                        // Padding at the end of the tessellation texture
+    kMaxTessellationVertexCount - kMaxTessellationPaddingVertexCount;
 
 // We can only reorder 32767 draws at a time since the one-based groupIndex returned by
 // IntersectionBoard is a signed 16-bit integer.
@@ -598,21 +599,24 @@
     {
         // midpointFan tessellation vertices reside at the beginning of the tessellation texture,
         // after 1 patch of padding vertices.
-        constexpr uint32_t padding = pls::kMidpointFanPatchSegmentSpan;
-        m_midpointFanTessVertexIdx = padding;
+        constexpr uint32_t kPrePadding = pls::kMidpointFanPatchSegmentSpan;
+        m_midpointFanTessVertexIdx = kPrePadding;
         m_midpointFanTessEndLocation =
             m_midpointFanTessVertexIdx + m_resourceCounts.midpointFanTessVertexCount;
 
         // outerCubic tessellation vertices reside after the midpointFan vertices, aligned on a
         // multiple of the outerCubic patch size.
-        m_outerCubicTessVertexIdx =
-            m_midpointFanTessEndLocation +
+        uint32_t interiorPadding =
             PaddingToAlignUp<pls::kOuterCurvePatchSegmentSpan>(m_midpointFanTessEndLocation);
+        m_outerCubicTessVertexIdx = m_midpointFanTessEndLocation + interiorPadding;
         m_outerCubicTessEndLocation =
             m_outerCubicTessVertexIdx + m_resourceCounts.outerCubicTessVertexCount;
 
         // We need one more padding vertex after all the tessellation vertices.
-        totalTessVertexCountWithPadding = m_outerCubicTessEndLocation + 1;
+        constexpr uint32_t kPostPadding = 1;
+        totalTessVertexCountWithPadding = m_outerCubicTessEndLocation + kPostPadding;
+
+        assert(kPrePadding + interiorPadding + kPostPadding <= kMaxTessellationPaddingVertexCount);
         assert(totalTessVertexCountWithPadding <= kMaxTessellationVertexCount);
     }
 
@@ -748,6 +752,9 @@
 {
     const pls::PlatformFeatures& platformFeatures = m_ctx->platformFeatures();
     assert(m_hasDoneLayout);
+    assert(m_flushDesc.firstPath == m_ctx->m_pathData.elementsWritten());
+    assert(m_flushDesc.firstPaint == m_ctx->m_paintData.elementsWritten());
+    assert(m_flushDesc.firstPaintAux == m_ctx->m_paintAuxData.elementsWritten());
 
     // Wait until here to layout the gradient texture because the final gradient texture height is
     // not decided until after all LogicalFlushes have run layoutResources().
@@ -1005,6 +1012,15 @@
     m_ctx->m_paintAuxData.push_back_n(nullptr, m_paintAuxPaddingCount);
     m_ctx->m_contourData.push_back_n(nullptr, m_contourPaddingCount);
 
+    assert(m_ctx->m_pathData.elementsWritten() ==
+           m_flushDesc.firstPath + m_resourceCounts.pathCount + m_pathPaddingCount);
+    assert(m_ctx->m_paintData.elementsWritten() ==
+           m_flushDesc.firstPaint + m_resourceCounts.pathCount + m_paintPaddingCount);
+    assert(m_ctx->m_paintAuxData.elementsWritten() ==
+           m_flushDesc.firstPaintAux + m_resourceCounts.pathCount + m_paintAuxPaddingCount);
+    assert(m_ctx->m_contourData.elementsWritten() ==
+           m_flushDesc.firstContour + m_resourceCounts.contourCount + m_contourPaddingCount);
+
     assert(m_pathTessLocation == m_expectedPathTessLocationAtEndOfPath);
     assert(m_pathMirroredTessLocation == m_expectedPathMirroredTessLocationAtEndOfPath);
     assert(m_midpointFanTessVertexIdx == m_midpointFanTessEndLocation);
@@ -1337,6 +1353,9 @@
 
     m_currentPathIsStroked = draw->strokeRadius() != 0;
     m_currentPathContourDirections = draw->contourDirections();
+    ++m_currentPathID;
+    assert(0 < m_currentPathID && m_currentPathID <= m_ctx->m_maxPathID);
+
     m_ctx->m_pathData.set_back(draw->matrix(), draw->strokeRadius(), m_currentZIndex);
     m_ctx->m_paintData.set_back(draw->fillRule(),
                                 draw->paintType(),
@@ -1354,12 +1373,10 @@
                                    m_flushDesc.renderTarget,
                                    m_ctx->platformFeatures());
 
-    ++m_currentPathID;
-    assert(0 < m_currentPathID && m_currentPathID <= m_ctx->m_maxPathID);
-    assert(m_flushDesc.firstPath + m_currentPathID == m_ctx->m_pathData.elementsWritten() - 1);
-    assert(m_flushDesc.firstPaint + m_currentPathID == m_ctx->m_paintData.elementsWritten() - 1);
-    assert(m_flushDesc.firstPaintAux + m_currentPathID ==
-           m_ctx->m_paintAuxData.elementsWritten() - 1);
+    assert(m_flushDesc.firstPath + m_currentPathID + 1 == m_ctx->m_pathData.elementsWritten());
+    assert(m_flushDesc.firstPaint + m_currentPathID + 1 == m_ctx->m_paintData.elementsWritten());
+    assert(m_flushDesc.firstPaintAux + m_currentPathID + 1 ==
+           m_ctx->m_paintAuxData.elementsWritten());
 
     pls::DrawType drawType;
     size_t tessLocation;
diff --git a/renderer/pls_renderer.cpp b/renderer/pls_renderer.cpp
index cf9fb26..cf87418 100644
--- a/renderer/pls_renderer.cpp
+++ b/renderer/pls_renderer.cpp
@@ -103,8 +103,12 @@
     LITE_RTTI_CAST_OR_RETURN(path, PLSPath*, renderPath);
     LITE_RTTI_CAST_OR_RETURN(paint, PLSPaint*, renderPaint);
 
-    bool stroked = paint->getIsStroked();
+    if (path->getRawPath().empty())
+    {
+        return;
+    }
 
+    bool stroked = paint->getIsStroked();
     if (stroked && m_context->frameDescriptor().strokesDisabled)
     {
         return;
@@ -130,6 +134,12 @@
 {
     LITE_RTTI_CAST_OR_RETURN(path, PLSPath*, renderPath);
 
+    if (path->getRawPath().empty())
+    {
+        m_stack.back().clipIsEmpty = true;
+        return;
+    }
+
     // First try to handle axis-aligned rectangles using the "ENABLE_CLIP_RECT" shader feature.
     // Multiple axis-aligned rectangles can be intersected into a single rectangle if their matrices
     // are compatible.
diff --git a/submodules/rive-cpp b/submodules/rive-cpp
index 785bee1..1fadc01 160000
--- a/submodules/rive-cpp
+++ b/submodules/rive-cpp
@@ -1 +1 @@
-Subproject commit 785bee1ff7a6d5f5a484f2158342061a4e31f536
+Subproject commit 1fadc01a78f67f0599e98d91d36b1472b8b7f2c1