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

#include <VerticesRenderStep.h>

Inheritance diagram for skgpu::graphite::VerticesRenderStep:
skgpu::graphite::RenderStep

Public Member Functions

 VerticesRenderStep (PrimitiveType, bool hasColor, bool hasTexCoords)
 
 ~VerticesRenderStep () override
 
std::string vertexSkSL () const override
 
void writeVertices (DrawWriter *writer, const DrawParams &params, skvx::ushort2 ssboIndices) const override
 
void writeUniformsAndTextures (const DrawParams &, PipelineDataGatherer *) const override
 
const char * fragmentColorSkSL () 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
 
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
 

Additional Inherited Members

- Static Public Member Functions inherited from skgpu::graphite::RenderStep
static const char * ssboIndicesAttribute ()
 
static const char * ssboIndicesVarying ()
 
- 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 16 of file VerticesRenderStep.h.

Constructor & Destructor Documentation

◆ VerticesRenderStep()

skgpu::graphite::VerticesRenderStep::VerticesRenderStep ( PrimitiveType  type,
bool  hasColor,
bool  hasTexCoords 
)
explicit

Definition at line 70 of file VerticesRenderStep.cpp.

71 : RenderStep("VerticesRenderStep",
72 variant_name(type, hasColor, hasTexCoords),
75 /*uniforms=*/{{"localToDevice", SkSLType::kFloat4x4},
76 {"depth", SkSLType::kFloat}},
77 type,
79 /*vertexAttrs=*/ kAttributes[2*hasTexCoords + hasColor],
80 /*instanceAttrs=*/{},
81 /*varyings=*/ kVaryings[hasColor])
82 , fHasColor(hasColor)
83 , fHasTexCoords(hasTexCoords) {}
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
static constexpr DepthStencilSettings kDirectDepthGEqualPass

◆ ~VerticesRenderStep()

skgpu::graphite::VerticesRenderStep::~VerticesRenderStep ( )
override

Definition at line 85 of file VerticesRenderStep.cpp.

85{}

Member Function Documentation

◆ fragmentColorSkSL()

const char * skgpu::graphite::VerticesRenderStep::fragmentColorSkSL ( ) const
overridevirtual

Reimplemented from skgpu::graphite::RenderStep.

Definition at line 117 of file VerticesRenderStep.cpp.

117 {
118 if (fHasColor) {
119 return "primitiveColor = color;\n";
120 } else {
121 return "";
122 }
123}

◆ vertexSkSL()

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

Implements skgpu::graphite::RenderStep.

Definition at line 87 of file VerticesRenderStep.cpp.

87 {
88 if (fHasColor && fHasTexCoords) {
89 return R"(
90 color = half4(vertColor.bgr * vertColor.a, vertColor.a);
91 float4 devPosition = localToDevice * float4(position, 0.0, 1.0);
92 devPosition.z = depth;
93 stepLocalCoords = texCoords;
94 )";
95 } else if (fHasTexCoords) {
96 return R"(
97 float4 devPosition = localToDevice * float4(position, 0.0, 1.0);
98 devPosition.z = depth;
99 stepLocalCoords = texCoords;
100 )";
101 } else if (fHasColor) {
102 return R"(
103 color = half4(vertColor.bgr * vertColor.a, vertColor.a);
104 float4 devPosition = localToDevice * float4(position, 0.0, 1.0);
105 devPosition.z = depth;
106 stepLocalCoords = position;
107 )";
108 } else {
109 return R"(
110 float4 devPosition = localToDevice * float4(position, 0.0, 1.0);
111 devPosition.z = depth;
112 stepLocalCoords = position;
113 )";
114 }
115}

◆ writeUniformsAndTextures()

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

Implements skgpu::graphite::RenderStep.

Definition at line 175 of file VerticesRenderStep.cpp.

176 {
177 // Vertices are transformed on the GPU. Store PaintDepth as a uniform to avoid copying the
178 // same depth for each vertex.
179 SkDEBUGCODE(UniformExpectationsValidator uev(gatherer, this->uniforms());)
180 gatherer->write(params.transform().matrix());
181 gatherer->write(params.order().depthAsFloat());
182}
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
SkSpan< const Uniform > uniforms() const
Definition Renderer.h:143
const EmbeddedViewParams * params

◆ writeVertices()

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

Implements skgpu::graphite::RenderStep.

Definition at line 125 of file VerticesRenderStep.cpp.

127 {
128 SkVerticesPriv info(params.geometry().vertices()->priv());
129 const int vertexCount = info.vertexCount();
130 const int indexCount = info.indexCount();
131 const SkPoint* positions = info.positions();
132 const uint16_t* indices = info.indices();
133 const SkColor* colors = info.colors();
134 const SkPoint* texCoords = info.texCoords();
135
136 // This should always be the case if the Renderer was chosen appropriately, but the vertex
137 // writing loop is set up in such a way that if the shader expects color or tex coords and they
138 // are missing, it will just read 0s, so release builds are safe.
139 SkASSERT(fHasColor == SkToBool(colors));
140 SkASSERT(fHasTexCoords == SkToBool(texCoords));
141
142 // TODO: We could access the writer's DrawBufferManager and upload the SkVertices index buffer
143 // but that would require we manually manage the VertexWriter for interleaving the position,
144 // color, and tex coord arrays together. This wouldn't be so bad if we let ::Vertices() take
145 // a CPU index buffer that indexes into the accumulated vertex data (and handles offsetting for
146 // merged drawIndexed calls), or if we could bind multiple attribute sources and copy the
147 // position/color/texCoord data separately in bulk w/o using an Appender.
148 DrawWriter::Vertices verts{*writer};
149 verts.reserve(indices ? indexCount : vertexCount);
150
151 VertState state(vertexCount, indices, indexCount);
152 VertState::Proc vertProc = state.chooseProc(info.mode());
153 while (vertProc(&state)) {
154 verts.append(3) << positions[state.f0]
155 << VertexWriter::If(fHasColor, colors ? colors[state.f0]
157 << VertexWriter::If(fHasTexCoords, texCoords ? texCoords[state.f0]
158 : SkPoint{0.f, 0.f})
159 << ssboIndices
160 << positions[state.f1]
161 << VertexWriter::If(fHasColor, colors ? colors[state.f1]
163 << VertexWriter::If(fHasTexCoords, texCoords ? texCoords[state.f1]
164 : SkPoint{0.f, 0.f})
165 << ssboIndices
166 << positions[state.f2]
167 << VertexWriter::If(fHasColor, colors ? colors[state.f2]
169 << VertexWriter::If(fHasTexCoords, texCoords ? texCoords[state.f2]
170 : SkPoint{0.f, 0.f})
171 << ssboIndices;
172 }
173}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkASSERT(cond)
Definition SkAssert.h:116
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
AtkStateType state
PODArray< SkColor > colors
Definition SkRecords.h:276
bool(* Proc)(VertState *)
Definition SkVertState.h:39
static Conditional< T > If(bool condition, const T &value)

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