Reland "Centralize geometry processor vertex shader transform code"
This is a reland of 0426947243e1d6b470830c4d3b1c5704ed1f23e1
Original change's description:
> Centralize geometry processor vertex shader transform code
>
> GrGLSLGeometryProcessors no longer have to call emitTransforms() in
> their onEmitCode() function. Instead, the GpArgs struct allows them to
> set a GrShaderVar that holds the computed or explicitly provided local
> coordinates in the vertex shader.
>
> The base GrGLSLGeometryProcessor now automatically uses that to collect
> all of the transforms that can then be lifted out of FPs to the vertex
> shader, and base their computation on the GP provided local coordinate.
>
> As part of this, there is no more built-in magic concatenation of a
> local matrix / inverse view matrix to these coordinate transforms. GP
> implementations that relied on this now manage their own uniform for this
> matrix and compute the local coordinate before assigning to GpArgs.
>
> The base GrGLSLGeometryProcessor is updated to provide helpers for this
> pattern.
>
> Bug: skia:10396
> Change-Id: I56afb3fff4b806f6015ab13626ac1afde9ef5c2b
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297027
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
Bug: skia:10396
Change-Id: If1347bcacb7c405a66f9d4c5b0059e9d735b3f9a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/298062
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp
index 4f93238..94ba184 100644
--- a/src/gpu/GrDefaultGeoProcFactory.cpp
+++ b/src/gpu/GrDefaultGeoProcFactory.cpp
@@ -57,6 +57,7 @@
public:
GLSLProcessor()
: fViewMatrix(SkMatrix::InvalidMatrix())
+ , fLocalMatrix(SkMatrix::InvalidMatrix())
, fColor(SK_PMColor4fILLEGAL)
, fCoverage(0xff) {}
@@ -111,14 +112,14 @@
&fViewMatrixUniform);
// emit transforms using either explicit local coords or positions
- const auto& coordsAttr = gp.fInLocalCoords.isInitialized() ? gp.fInLocalCoords
- : gp.fInPosition;
- this->emitTransforms(vertBuilder,
- varyingHandler,
- uniformHandler,
- coordsAttr.asShaderVar(),
- gp.localMatrix(),
- args.fFPCoordTransformHandler);
+ if (gp.fInLocalCoords.isInitialized()) {
+ SkASSERT(gp.localMatrix().isIdentity());
+ gpArgs->fLocalCoordVar = gp.fInLocalCoords.asShaderVar();
+ } else if (gp.fLocalCoordsWillBeRead) {
+ this->writeLocalCoord(vertBuilder, uniformHandler, gpArgs,
+ gp.fInPosition.asShaderVar(), gp.localMatrix(),
+ &fLocalMatrixUniform);
+ }
// Setup coverage as pass through
if (gp.hasVertexCoverage() && !tweakAlpha) {
@@ -144,8 +145,12 @@
const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
uint32_t key = def.fFlags;
key |= (def.coverage() == 0xff) ? 0x80 : 0;
- key |= (def.localCoordsWillBeRead() && def.localMatrix().hasPerspective()) ? 0x100 : 0;
- key |= ComputePosKey(def.viewMatrix()) << 20;
+ key |= def.localCoordsWillBeRead() ? 0x100 : 0;
+
+ bool usesLocalMatrix = def.localCoordsWillBeRead() &&
+ !def.fInLocalCoords.isInitialized();
+ key = AddMatrixKeys(key, def.viewMatrix(),
+ usesLocalMatrix ? def.localMatrix() : SkMatrix::I());
b->add32(key);
}
@@ -154,12 +159,9 @@
const CoordTransformRange& transformRange) override {
const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>();
- if (!dgp.viewMatrix().isIdentity() &&
- !SkMatrixPriv::CheapEqual(fViewMatrix, dgp.viewMatrix()))
- {
- fViewMatrix = dgp.viewMatrix();
- pdman.setSkMatrix(fViewMatrixUniform, fViewMatrix);
- }
+ this->setTransform(pdman, fViewMatrixUniform, dgp.viewMatrix(), &fViewMatrix);
+ this->setTransform(pdman, fLocalMatrixUniform, dgp.localMatrix(), &fLocalMatrix);
+ this->setTransformDataHelper(pdman, transformRange);
if (!dgp.hasVertexColor() && dgp.color() != fColor) {
pdman.set4fv(fColorUniform, 1, dgp.color().vec());
@@ -170,14 +172,15 @@
pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverage()));
fCoverage = dgp.coverage();
}
- this->setTransformDataHelper(dgp.fLocalMatrix, pdman, transformRange);
}
private:
SkMatrix fViewMatrix;
+ SkMatrix fLocalMatrix;
SkPMColor4f fColor;
uint8_t fCoverage;
UniformHandle fViewMatrixUniform;
+ UniformHandle fLocalMatrixUniform;
UniformHandle fColorUniform;
UniformHandle fCoverageUniform;