diff --git a/experimental/graphite/src/Device.cpp b/experimental/graphite/src/Device.cpp index 55e21cf43e..f4031b310b 100644 --- a/experimental/graphite/src/Device.cpp +++ b/experimental/graphite/src/Device.cpp @@ -487,20 +487,21 @@ void Device::recordDraw(const Transform& localToDevice, // are large enough to exceed the fixed count tessellation limits. const Renderer* renderer = nullptr; - // TODO: Combine this heuristic with what is used in PathStencilCoverOp to choose between wedges - // curves consistently in Graphite and Ganesh. - const bool preferWedges = (shape.isPath() && shape.path().countVerbs() < 50) || - clip.drawBounds().area() <= (256 * 256); - - // TODO: Route all filled shapes to stencil-and-cover for the sprint; convex will draw - // correctly but uses an unnecessary stencil step. - // if (shape.convex()) { - // renderer = Renderer::ConvexPath(); - // } else { - if (preferWedges) { - renderer = &Renderer::StencilTessellatedWedges(shape.fillType()); + if (shape.convex() && !shape.inverted()) { + // TODO: Ganesh doesn't have a curve+middle-out triangles option for convex paths, but it + // would be pretty trivial to spin up. + renderer = &Renderer::ConvexTessellatedWedges(); } else { - renderer = &Renderer::StencilTessellatedCurvesAndTris(shape.fillType()); + // TODO: Combine this heuristic with what is used in PathStencilCoverOp to choose between + // wedges curves consistently in Graphite and Ganesh. + const bool preferWedges = (shape.isPath() && shape.path().countVerbs() < 50) || + clip.drawBounds().area() <= (256 * 256); + + if (preferWedges) { + renderer = &Renderer::StencilTessellatedWedges(shape.fillType()); + } else { + renderer = &Renderer::StencilTessellatedCurvesAndTris(shape.fillType()); + } } if (!renderer) { diff --git a/experimental/graphite/src/Renderer.h b/experimental/graphite/src/Renderer.h index b7ce8d9dea..16b77eaaa2 100644 --- a/experimental/graphite/src/Renderer.h +++ b/experimental/graphite/src/Renderer.h @@ -209,8 +209,10 @@ public: static const Renderer& StencilTessellatedCurvesAndTris(SkPathFillType); static const Renderer& StencilTessellatedWedges(SkPathFillType); + + static const Renderer& ConvexTessellatedWedges(); + // TODO: Not on the immediate sprint target, but show what needs to be added for DrawList's API - // static const Renderer& FillConvexPath(); // static const Renderer& StrokePath(); // TODO: Will add more of these as primitive rendering etc. is fleshed out diff --git a/experimental/graphite/src/mtl/MtlUtils.mm b/experimental/graphite/src/mtl/MtlUtils.mm index fc204d349b..d17b0d6249 100644 --- a/experimental/graphite/src/mtl/MtlUtils.mm +++ b/experimental/graphite/src/mtl/MtlUtils.mm @@ -23,6 +23,7 @@ namespace skgpu::mtl { bool FormatIsDepthOrStencil(MTLPixelFormat format) { switch (format) { case MTLPixelFormatStencil8: // fallthrough + case MTLPixelFormatDepth32Float: case MTLPixelFormatDepth32Float_Stencil8: return true; default: @@ -32,6 +33,7 @@ bool FormatIsDepthOrStencil(MTLPixelFormat format) { bool FormatIsDepth(MTLPixelFormat format) { switch (format) { + case MTLPixelFormatDepth32Float: case MTLPixelFormatDepth32Float_Stencil8: return true; default: diff --git a/experimental/graphite/src/render/StencilAndCoverDSS.h b/experimental/graphite/src/render/StencilAndCoverDSS.h index a396ca82eb..ebeb27eac3 100644 --- a/experimental/graphite/src/render/StencilAndCoverDSS.h +++ b/experimental/graphite/src/render/StencilAndCoverDSS.h @@ -103,7 +103,7 @@ constexpr DepthStencilSettings::Face kPassZero = { // stencil buffer has been modified by either kWindingStencilPass or kEvenOddStencilPass. constexpr DepthStencilSettings kRegularCoverPass = { /*frontStencil=*/kPassNonZero, - /*frontStencil=*/kPassNonZero, + /*backStencil=*/ kPassNonZero, /*refValue=*/ 0, /*stencilTest=*/ true, /*depthCompare=*/CompareOp::kAlways, // TODO: kGreater once steps know the right depth value @@ -115,7 +115,7 @@ constexpr DepthStencilSettings kRegularCoverPass = { // stencil buffer has been modified by either kWindingStencilPass or kEvenOddStencilPass. constexpr DepthStencilSettings kInverseCoverPass = { /*frontStencil=*/kPassZero, - /*frontStencil=*/kPassZero, + /*backStencil=*/ kPassZero, /*refValue=*/ 0, /*stencilTest=*/ true, /*depthCompare=*/CompareOp::kAlways, // TODO: kGreater once steps know the right depth value diff --git a/experimental/graphite/src/render/StencilAndFillPathRenderer.cpp b/experimental/graphite/src/render/StencilAndFillPathRenderer.cpp index c9437330fd..2ac4d9562a 100644 --- a/experimental/graphite/src/render/StencilAndFillPathRenderer.cpp +++ b/experimental/graphite/src/render/StencilAndFillPathRenderer.cpp @@ -9,6 +9,7 @@ #include "experimental/graphite/src/render/CoverBoundsRenderStep.h" #include "experimental/graphite/src/render/MiddleOutFanRenderStep.h" +#include "experimental/graphite/src/render/StencilAndCoverDSS.h" #include "experimental/graphite/src/render/TessellateCurvesRenderStep.h" #include "experimental/graphite/src/render/TessellateWedgesRenderStep.h" #include "include/core/SkPathTypes.h" @@ -27,6 +28,16 @@ const RenderStep* inverse_cover_step() { return &kInverseFill; } +static constexpr DepthStencilSettings kDirectShadingPass = { + /*frontStencil=*/{}, + /*backStencil=*/ {}, + /*refValue=*/ 0, + /*stencilTest=*/ false, + /*depthCompare=*/CompareOp::kAlways, // TODO: switch to greater + /*depthTest=*/ true, + /*depthWrite=*/ true +}; + } // namespace const Renderer& Renderer::StencilTessellatedCurvesAndTris(SkPathFillType fillType) { @@ -64,8 +75,8 @@ const Renderer& Renderer::StencilTessellatedCurvesAndTris(SkPathFillType fillTyp } const Renderer& Renderer::StencilTessellatedWedges(SkPathFillType fillType) { - static const TessellateWedgesRenderStep kWindingStencilWedges{false}; - static const TessellateWedgesRenderStep kEvenOddStencilWedges{true}; + static const TessellateWedgesRenderStep kWindingStencilWedges{"winding", kWindingStencilPass}; + static const TessellateWedgesRenderStep kEvenOddStencilWedges{"even-odd", kEvenOddStencilPass}; static const Renderer kWindingRenderer{"StencilTessellatedWedges[winding]", &kWindingStencilWedges, @@ -89,4 +100,10 @@ const Renderer& Renderer::StencilTessellatedWedges(SkPathFillType fillType) { SkUNREACHABLE; } +const Renderer& Renderer::ConvexTessellatedWedges() { + static const TessellateWedgesRenderStep kConvexWedges{"convex", kDirectShadingPass}; + static const Renderer kConvexWedgeRenderer{"ConvexTessellatedWedges", &kConvexWedges}; + return kConvexWedgeRenderer; +} + } // namespace skgpu diff --git a/experimental/graphite/src/render/TessellateWedgesRenderStep.cpp b/experimental/graphite/src/render/TessellateWedgesRenderStep.cpp index 69d79272e9..31f43ff037 100644 --- a/experimental/graphite/src/render/TessellateWedgesRenderStep.cpp +++ b/experimental/graphite/src/render/TessellateWedgesRenderStep.cpp @@ -10,7 +10,6 @@ #include "experimental/graphite/src/DrawWriter.h" #include "experimental/graphite/src/geom/Shape.h" #include "experimental/graphite/src/geom/Transform_graphite.h" -#include "experimental/graphite/src/render/StencilAndCoverDSS.h" #include "src/gpu/tessellate/AffineMatrix.h" #include "src/gpu/tessellate/MidpointContourParser.h" @@ -67,13 +66,16 @@ size_t fixed_index_buffer_size() { } // namespace -TessellateWedgesRenderStep::TessellateWedgesRenderStep(bool evenOdd) +TessellateWedgesRenderStep::TessellateWedgesRenderStep(std::string_view variantName, + DepthStencilSettings depthStencilSettings) : RenderStep("TessellateWedgesRenderStep", - evenOdd ? "even-odd" : "winding", - Flags::kRequiresMSAA, + variantName, + Flags::kRequiresMSAA | + (depthStencilSettings.fDepthWriteEnabled ? Flags::kPerformsShading + : Flags::kNone), /*uniforms=*/{}, PrimitiveType::kTriangles, - evenOdd ? kEvenOddStencilPass : kWindingStencilPass, + depthStencilSettings, /*vertexAttrs=*/ {{"resolveLevel_and_idx", VertexAttribType::kFloat2, SkSLType::kFloat2}}, /*instanceAttrs=*/{{"p01", VertexAttribType::kFloat4, SkSLType::kFloat4}, diff --git a/experimental/graphite/src/render/TessellateWedgesRenderStep.h b/experimental/graphite/src/render/TessellateWedgesRenderStep.h index 4593d27434..fa5ed25949 100644 --- a/experimental/graphite/src/render/TessellateWedgesRenderStep.h +++ b/experimental/graphite/src/render/TessellateWedgesRenderStep.h @@ -14,10 +14,8 @@ namespace skgpu { class TessellateWedgesRenderStep final : public RenderStep { public: - // TODO: If this takes DepthStencilSettings directly and a way to adjust the flags to specify - // that it performs shading, this RenderStep definition can be shared between the stencil and - // the convex rendering variants. - TessellateWedgesRenderStep(bool evenOdd); + TessellateWedgesRenderStep(std::string_view variantName, + DepthStencilSettings depthStencilSettings); ~TessellateWedgesRenderStep() override; @@ -30,6 +28,7 @@ public: const SkIRect&, const Transform&, const Shape&) const override; + }; } // namespace skgpu