Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
skgpu::graphite::TessellateWedgesRenderStep Class Referencefinal

#include <TessellateWedgesRenderStep.h>

Inheritance diagram for skgpu::graphite::TessellateWedgesRenderStep:
skgpu::graphite::RenderStep

Public Member Functions

 TessellateWedgesRenderStep (std::string_view variantName, bool infinitySupport, DepthStencilSettings depthStencilSettings, StaticBufferManager *bufferManager)
 
 ~TessellateWedgesRenderStep () override
 
std::string vertexSkSL () const override
 
void writeVertices (DrawWriter *, const DrawParams &, skvx::ushort2 ssboIndices) const override
 
void writeUniformsAndTextures (const DrawParams &, PipelineDataGatherer *) const override
 
- Public Member Functions inherited from skgpu::graphite::RenderStep
virtual ~RenderStep ()=default
 
virtual std::string texturesAndSamplersSkSL (const ResourceBindingRequirements &, int *nextBindingIndex) const
 
virtual const char * fragmentCoverageSkSL () const
 
virtual const char * fragmentColorSkSL () const
 
uint32_t uniqueID () const
 
const char * name () const
 
bool requiresMSAA () const
 
bool performsShading () const
 
bool hasTextures () const
 
bool emitsPrimitiveColor () const
 
bool outsetBoundsForAA () const
 
Coverage coverage () const
 
PrimitiveType primitiveType () const
 
size_t vertexStride () const
 
size_t instanceStride () const
 
size_t numUniforms () const
 
size_t numVertexAttributes () const
 
size_t numInstanceAttributes () const
 
SkSpan< const Uniformuniforms () const
 
SkSpan< const AttributevertexAttributes () const
 
SkSpan< const AttributeinstanceAttributes () const
 
SkSpan< const Varyingvaryings () const
 
const DepthStencilSettingsdepthStencilSettings () const
 
SkEnumBitMask< DepthStencilFlagsdepthStencilFlags () const
 

Static Public Member Functions

static std::pair< BindBufferInfo, BindBufferInfoCreateVertexTemplate (StaticBufferManager *)
 
- Static Public Member Functions inherited from skgpu::graphite::RenderStep
static const char * ssboIndicesAttribute ()
 
static const char * ssboIndicesVarying ()
 

Additional Inherited Members

- Protected Types inherited from skgpu::graphite::RenderStep
enum class  Flags : unsigned {
  kNone = 0b0000000 , kRequiresMSAA = 0b0000001 , kPerformsShading = 0b0000010 , kHasTextures = 0b0000100 ,
  kEmitsCoverage = 0b0001000 , kLCDCoverage = 0b0010000 , kEmitsPrimitiveColor = 0b0100000 , kOutsetBoundsForAA = 0b1000000
}
 
- Protected Member Functions inherited from skgpu::graphite::RenderStep
 RenderStep (std::string_view className, std::string_view variantName, SkEnumBitMask< Flags > flags, std::initializer_list< Uniform > uniforms, PrimitiveType primitiveType, DepthStencilSettings depthStencilSettings, SkSpan< const Attribute > vertexAttrs, SkSpan< const Attribute > instanceAttrs, SkSpan< const Varying > varyings={})
 

Detailed Description

Definition at line 19 of file TessellateWedgesRenderStep.h.

Constructor & Destructor Documentation

◆ TessellateWedgesRenderStep()

skgpu::graphite::TessellateWedgesRenderStep::TessellateWedgesRenderStep ( std::string_view  variantName,
bool  infinitySupport,
DepthStencilSettings  depthStencilSettings,
StaticBufferManager bufferManager 
)

Definition at line 66 of file TessellateWedgesRenderStep.cpp.

70 : RenderStep("TessellateWedgesRenderStep",
71 variantName,
74 : Flags::kNone),
75 /*uniforms=*/{{"localToDevice", SkSLType::kFloat4x4}},
78 /*vertexAttrs=*/ {{"resolveLevel_and_idx",
80 /*instanceAttrs=*/kAttributes[infinitySupport])
81 , fInfinitySupport(infinitySupport) {
82 SkASSERT(this->instanceStride() ==
83 PatchStride(infinitySupport ? kAttribs : kAttribsWithCurveType));
84
85 // Initialize the static buffers we'll use when recording draw calls.
86 // NOTE: Each instance of this RenderStep gets its own copy of the data. If this ends up causing
87 // problems, we can modify StaticBufferManager to de-duplicate requests.
88 const size_t vertexSize = FixedCountWedges::VertexBufferSize();
89 auto vertexData = bufferManager->getVertexWriter(vertexSize, &fVertexBuffer);
90 if (vertexData) {
91 FixedCountWedges::WriteVertexBuffer(std::move(vertexData), vertexSize);
92 } // otherwise static buffer creation failed, so do nothing; Context initialization will fail.
93
94 const size_t indexSize = FixedCountWedges::IndexBufferSize();
95 auto indexData = bufferManager->getIndexWriter(indexSize, &fIndexBuffer);
96 if (indexData) {
97 FixedCountWedges::WriteIndexBuffer(std::move(indexData), indexSize);
98 } // otherwise static buffer creation failed, so do nothing; Context initialization will fail.
99}
#define SkASSERT(cond)
Definition SkAssert.h:116
size_t instanceStride() const
Definition Renderer.h:128
RenderStep(std::string_view className, std::string_view variantName, SkEnumBitMask< Flags > flags, std::initializer_list< Uniform > uniforms, PrimitiveType primitiveType, DepthStencilSettings depthStencilSettings, SkSpan< const Attribute > vertexAttrs, SkSpan< const Attribute > instanceAttrs, SkSpan< const Varying > varyings={})
Definition Renderer.cpp:19
const DepthStencilSettings & depthStencilSettings() const
Definition Renderer.h:148
static constexpr size_t IndexBufferSize()
static constexpr size_t VertexBufferSize()
static void WriteVertexBuffer(VertexWriter, size_t bufferSize)
static void WriteIndexBuffer(VertexWriter, size_t bufferSize)
constexpr size_t PatchStride(PatchAttribs attribs)

◆ ~TessellateWedgesRenderStep()

skgpu::graphite::TessellateWedgesRenderStep::~TessellateWedgesRenderStep ( )
override

Definition at line 101 of file TessellateWedgesRenderStep.cpp.

101{}

Member Function Documentation

◆ CreateVertexTemplate()

static std::pair< BindBufferInfo, BindBufferInfo > skgpu::graphite::TessellateWedgesRenderStep::CreateVertexTemplate ( StaticBufferManager )
static

◆ vertexSkSL()

std::string skgpu::graphite::TessellateWedgesRenderStep::vertexSkSL ( ) const
overridevirtual

Implements skgpu::graphite::RenderStep.

Definition at line 103 of file TessellateWedgesRenderStep.cpp.

103 {
105 R"(
106 float2 localCoord;
107 if (resolveLevel_and_idx.x < 0) {
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1

◆ writeUniformsAndTextures()

void skgpu::graphite::TessellateWedgesRenderStep::writeUniformsAndTextures ( const DrawParams params,
PipelineDataGatherer gatherer 
) const
overridevirtual

Implements skgpu::graphite::RenderStep.

Definition at line 175 of file TessellateWedgesRenderStep.cpp.

175 :
176 writer.writeCubic(pts);
177 lastPoint = pts[3];
178 break;
179 default: break;
180 }

◆ writeVertices()

void skgpu::graphite::TessellateWedgesRenderStep::writeVertices ( DrawWriter dw,
const DrawParams params,
skvx::ushort2  ssboIndices 
) const
overridevirtual

Implements skgpu::graphite::RenderStep.

Definition at line 109 of file TessellateWedgesRenderStep.cpp.

110 {
111 // TODO: Approximate perspective scaling to match how PatchWriter is configured
112 // (or provide explicit tessellation level in instance data instead of
113 // replicating work)
114 float2x2 vectorXform = float2x2(localToDevice[0].xy, localToDevice[1].xy);
115 localCoord = tessellate_filled_curve(
116 vectorXform, resolveLevel_and_idx.x, resolveLevel_and_idx.y, p01, p23, %s);
117 }
118 float4 devPosition = localToDevice * float4(localCoord, 0.0, 1.0);
119 devPosition.z = depth;
120 stepLocalCoords = localCoord;
121 )",
122 fInfinitySupport ? "curve_type_using_inf_support(p23)" : "curveType");
123}
124
125void TessellateWedgesRenderStep::writeVertices(DrawWriter* dw,
126 const DrawParams& params,
127 skvx::ushort2 ssboIndices) const {
128 SkPath path = params.geometry().shape().asPath(); // TODO: Iterate the Shape directly
129
130 int patchReserveCount = FixedCountWedges::PreallocCount(path.countVerbs());
131 Writer writer{fInfinitySupport ? kAttribs : kAttribsWithCurveType,
132 *dw,
133 fVertexBuffer,
134 fIndexBuffer,
135 patchReserveCount};
136 writer.updatePaintDepthAttrib(params.order().depthAsFloat());
137 writer.updateSsboIndexAttrib(ssboIndices);
138
139 // The vector xform approximates how the control points are transformed by the shader to
140 // more accurately compute how many *parametric* segments are needed.
141 // TODO: This doesn't account for perspective division yet, which will require updating the
142 // approximate transform based on each verb's control points' bounding box.
143 SkASSERT(params.transform().type() < Transform::Type::kPerspective);
144 writer.setShaderTransform(wangs_formula::VectorXform{params.transform().matrix()},
145 params.transform().maxScaleFactor());
146
147 // TODO: Essentially the same as PathWedgeTessellator::write_patches but with a different
148 // PatchWriter template.
149 // For wedges, we iterate over each contour explicitly, using a fan point position that is in
150 // the midpoint of the current contour.
151 MidpointContourParser parser{path};
152 while (parser.parseNextContour()) {
153 writer.updateFanPointAttrib(parser.currentMidpoint());
154 SkPoint lastPoint = {0, 0};
155 SkPoint startPoint = {0, 0};
156 for (auto [verb, pts, w] : parser.currentContour()) {
157 switch (verb) {
158 case SkPathVerb::kMove:
159 startPoint = lastPoint = pts[0];
160 break;
161 case SkPathVerb::kLine:
162 // Unlike curve tessellation, wedges have to handle lines as part of the patch,
163 // effectively forming a single triangle with the fan point.
164 writer.writeLine(pts[0], pts[1]);
165 lastPoint = pts[1];
166 break;
167 case SkPathVerb::kQuad:
168 writer.writeQuadratic(pts);
169 lastPoint = pts[2];
170 break;
171 case SkPathVerb::kConic:
172 writer.writeConic(pts, *w);
173 lastPoint = pts[2];
skvx::float4 float4
struct MyStruct s

The documentation for this class was generated from the following files: