Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrTessellationShader.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
11
13 GrAAType aaType,
14 GrAppliedClip&& appliedClip,
15 GrProcessorSet&& processors) {
16 GrPipeline::InitArgs pipelineArgs;
17
18 pipelineArgs.fCaps = args.fCaps;
19 pipelineArgs.fDstProxyView = *args.fDstProxyView;
20 pipelineArgs.fWriteSwizzle = args.fWriteView.swizzle();
21
22 return args.fArena->make<GrPipeline>(pipelineArgs,
23 std::move(processors),
24 std::move(appliedClip));
25}
26
28 static_assert(skgpu::wangs_formula::length_term<3>(1) == 0.75);
29 static_assert(skgpu::wangs_formula::length_term_p2<3>(1) == 0.5625);
30
31 return
32// Returns the length squared of the largest forward difference from Wang's cubic formula.
33"float wangs_formula_max_fdiff_p2(float2 p0, float2 p1, float2 p2, float2 p3,"
34 "float2x2 matrix) {"
35 "float2 d0 = matrix * (fma(float2(-2), p1, p2) + p0);"
36 "float2 d1 = matrix * (fma(float2(-2), p2, p3) + p1);"
37 "return max(dot(d0,d0), dot(d1,d1));"
38"}"
39"float wangs_formula_cubic(float _precision_, float2 p0, float2 p1, float2 p2, float2 p3,"
40 "float2x2 matrix) {"
41 "float m = wangs_formula_max_fdiff_p2(p0, p1, p2, p3, matrix);"
42 "return max(ceil(sqrt(0.75 * _precision_ * sqrt(m))), 1.0);"
43"}"
44"float wangs_formula_cubic_log2(float _precision_, float2 p0, float2 p1, float2 p2, float2 p3,"
45 "float2x2 matrix) {"
46 "float m = wangs_formula_max_fdiff_p2(p0, p1, p2, p3, matrix);"
47 "return ceil(log2(max(0.5625 * _precision_ * _precision_ * m, 1.0)) * .25);"
48"}"
49"float wangs_formula_conic_p2(float _precision_, float2 p0, float2 p1, float2 p2, float w) {"
50 // Translate the bounding box center to the origin.
51 "float2 C = (min(min(p0, p1), p2) + max(max(p0, p1), p2)) * 0.5;"
52 "p0 -= C;"
53 "p1 -= C;"
54 "p2 -= C;"
55
56 // Compute max length.
57 "float m = sqrt(max(max(dot(p0,p0), dot(p1,p1)), dot(p2,p2)));"
58
59 // Compute forward differences.
60 "float2 dp = fma(float2(-2.0 * w), p1, p0) + p2;"
61 "float dw = abs(fma(-2.0, w, 2.0));"
62
63 // Compute numerator and denominator for parametric step size of linearization. Here, the
64 // epsilon referenced from the cited paper is 1/precision.
65 "float rp_minus_1 = max(0.0, fma(m, _precision_, -1.0));"
66 "float numer = length(dp) * _precision_ + rp_minus_1 * dw;"
67 "float denom = 4 * min(w, 1.0);"
68
69 "return numer/denom;"
70"}"
71"float wangs_formula_conic(float _precision_, float2 p0, float2 p1, float2 p2, float w) {"
72 "float n2 = wangs_formula_conic_p2(_precision_, p0, p1, p2, w);"
73 "return max(ceil(sqrt(n2)), 1.0);"
74"}"
75"float wangs_formula_conic_log2(float _precision_, float2 p0, float2 p1, float2 p2, float w) {"
76 "float n2 = wangs_formula_conic_p2(_precision_, p0, p1, p2, w);"
77 "return ceil(log2(max(n2, 1.0)) * .5);"
78"}"
79;
80}
GrAAType
static const char * WangsFormulaSkSL()
static const GrPipeline * MakePipeline(const ProgramArgs &, GrAAType, GrAppliedClip &&, GrProcessorSet &&)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
skgpu::Swizzle fWriteSwizzle
Definition GrPipeline.h:66
const GrCaps * fCaps
Definition GrPipeline.h:64
GrDstProxyView fDstProxyView
Definition GrPipeline.h:65