Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e7e25ac

Browse files
lhkbobSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Remove workarounds to support legacy coord transforms
Bug: skia:10416 Change-Id: I2f1b87521174d18afc59f12832441010cb94ea3f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299294 Reviewed-by: Brian Salomon <[email protected]> Commit-Queue: Michael Ludwig <[email protected]>
1 parent 9f2a333 commit e7e25ac

7 files changed

+69
-188
lines changed

src/gpu/GrPrimitiveProcessor.cpp

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,17 @@
1515
* the transform code is applied.
1616
*/
1717
enum SampleFlag {
18-
kExplicitlySampled_Flag = 0b0000001, // GrFP::isSampledWithExplicitCoords()
18+
kExplicitlySampled_Flag = 0b00001, // GrFP::isSampledWithExplicitCoords()
1919

20-
kLegacyCoordTransform_Flag = 0b0000010, // !GrFP::coordTransform(i)::isNoOp()
20+
kLegacyCoordTransform_Flag = 0b00010, // !GrFP::coordTransform(i)::isNoOp()
2121

22-
kNone_SampleMatrix_Flag = 0b0000100, // GrFP::sampleMatrix()::isNoOp()
23-
kConstUniform_SampleMatrix_Flag = 0b0001000, // GrFP::sampleMatrix()::isConstUniform()
24-
kVariable_SampleMatrix_Flag = 0b0001100, // GrFP::sampleMatrix()::isVariable()
25-
26-
// Legacy coord transforms specialize on identity, S+T, no-perspective, and general matrix types
27-
// FIXME these (and kLegacyCoordTransform) can be removed once all FPs no longer use them
28-
kLCT_ScaleTranslate_Matrix_Flag = 0b0010000, // GrFP::coordTransform(i)::isScaleTranslate()
29-
kLCT_NoPersp_Matrix_Flag = 0b0100000, // !GrFP::coordTransform(i)::hasPerspective()
30-
kLCT_General_Matrix_Flag = 0b0110000, // any other matrix type
22+
kNone_SampleMatrix_Flag = 0b00100, // GrFP::sampleMatrix()::isNoOp()
23+
kConstUniform_SampleMatrix_Flag = 0b01000, // GrFP::sampleMatrix()::isConstUniform()
24+
kVariable_SampleMatrix_Flag = 0b01100, // GrFP::sampleMatrix()::isVariable()
3125

3226
// Currently, sample(matrix) only specializes on no-perspective or general.
3327
// FIXME add new flags as more matrix types are supported.
34-
kPersp_Matrix_Flag = 0b1000000, // GrFP::sampleMatrix()::fHasPerspective
28+
kPersp_Matrix_Flag = 0b10000, // GrFP::sampleMatrix()::fHasPerspective
3529
};
3630

3731
GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrProcessor(classID) {}
@@ -42,31 +36,16 @@ const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::textureSampler
4236
}
4337

4438
uint32_t GrPrimitiveProcessor::computeCoordTransformsKey(const GrFragmentProcessor& fp) const {
45-
// This is highly coupled with the code in GrGLSLGeometryProcessor::emitTransforms().
46-
// At this point, all effects either don't use legacy coord transforms, or only use 1.
47-
SkASSERT(fp.numCoordTransforms() <= 1);
39+
// This is highly coupled with the code in GrGLSLGeometryProcessor::collectTransforms().
40+
// At this point, all effects do not use really coord transforms; they may implicitly report
41+
// a noop coord transform but this does not impact the key.
42+
SkASSERT(fp.numCoordTransforms() == 0 ||
43+
(fp.numCoordTransforms() == 1 && fp.coordTransform(0).isNoOp()));
4844

4945
uint32_t key = 0;
5046
if (fp.isSampledWithExplicitCoords()) {
5147
key |= kExplicitlySampled_Flag;
5248
}
53-
if (fp.numCoordTransforms() > 0) {
54-
const GrCoordTransform& coordTransform = fp.coordTransform(0);
55-
if (!coordTransform.isNoOp()) {
56-
// A true identity matrix shouldn't result in a coord transform; proxy normalization
57-
// and flipping will eventually present as a scale+translate matrix.
58-
SkASSERT(!coordTransform.matrix().isIdentity() || coordTransform.normalize() ||
59-
coordTransform.reverseY());
60-
key |= kLegacyCoordTransform_Flag;
61-
if (coordTransform.matrix().isScaleTranslate()) {
62-
key |= kLCT_ScaleTranslate_Matrix_Flag;
63-
} else if (!coordTransform.matrix().hasPerspective()) {
64-
key |= kLCT_NoPersp_Matrix_Flag;
65-
} else {
66-
key |= kLCT_General_Matrix_Flag;
67-
}
68-
}
69-
}
7049

7150
switch(fp.sampleMatrix().fKind) {
7251
case SkSL::SampleMatrix::Kind::kNone:

src/gpu/GrPrimitiveProcessor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "src/gpu/GrShaderVar.h"
1515
#include "src/gpu/GrSwizzle.h"
1616

17-
class GrCoordTransform;
18-
1917
/*
2018
* The GrPrimitiveProcessor represents some kind of geometric primitive. This includes the shape
2119
* of the primitive and the inherent color of the primitive. The GrPrimitiveProcessor is

src/gpu/gl/builders/GrGLProgramBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "src/core/SkWriteBuffer.h"
1616
#include "src/gpu/GrAutoLocaleSetter.h"
1717
#include "src/gpu/GrContextPriv.h"
18-
#include "src/gpu/GrCoordTransform.h"
1918
#include "src/gpu/GrPersistentCacheUtils.h"
2019
#include "src/gpu/GrProgramDesc.h"
2120
#include "src/gpu/GrShaderCaps.h"

src/gpu/glsl/GrGLSLFragmentProcessor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* found in the LICENSE file.
66
*/
77

8-
#include "src/gpu/GrCoordTransform.h"
98
#include "src/gpu/GrFragmentProcessor.h"
109
#include "src/gpu/GrProcessor.h"
1110
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"

src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -153,45 +153,13 @@ SkString GrGLSLFPFragmentBuilder::writeProcessorFunction(GrGLSLFragmentProcessor
153153
// transforms), the value that would have been passed to _coords is lifted to the vertex shader
154154
// and stored in a unique varying. In that case it uses that variable and does not have a
155155
// second actual argument for _coords.
156-
// FIXME: Once GrCoordTransforms are gone, and we can more easily associated this varying with
157-
// the sample call site, then invokeChild() can pass the varying in, instead of requiring this
158-
// dynamic signature.
159-
int paramCount;
156+
// FIXME: An alternative would be to have all FP functions have a float2 argument, and the
157+
// parent FP invokes it with the varying reference when it's been lifted to the vertex shader.
158+
int paramCount = 2;
160159
GrShaderVar params[] = { GrShaderVar(args.fInputColor, kHalf4_GrSLType),
161160
GrShaderVar(args.fSampleCoord, kFloat2_GrSLType) };
162161

163-
if (args.fFp.isSampledWithExplicitCoords()) {
164-
// All invokeChild() that point to 'fp' will evaluate these expressions and pass the float2
165-
// in, so we need the 2nd argument.
166-
paramCount = 2;
167-
168-
// FIXME: This is only needed for the short term until FPs no longer put transformation
169-
// data in a GrCoordTransform (and we can then mark the parameter as read-only)
170-
if (args.fTransformedCoords.count() > 0) {
171-
SkASSERT(args.fTransformedCoords.count() == 1);
172-
173-
const GrShaderVar& transform = args.fTransformedCoords[0].fTransform;
174-
switch (transform.getType()) {
175-
case kFloat4_GrSLType:
176-
// This is a scale+translate, so there's no perspective division needed
177-
this->codeAppendf("%s = %s * %s.xz + %s.yw;\n", args.fSampleCoord,
178-
args.fSampleCoord,
179-
transform.c_str(),
180-
transform.c_str());
181-
break;
182-
case kFloat3x3_GrSLType:
183-
this->codeAppend("{\n");
184-
this->codeAppendf("float3 _coords3 = (%s * %s.xy1);\n",
185-
transform.c_str(), args.fSampleCoord);
186-
this->codeAppendf("%s = _coords3.xy / _coords3.z;\n", args.fSampleCoord);
187-
this->codeAppend("}\n");
188-
break;
189-
default:
190-
SkASSERT(transform.getType() == kVoid_GrSLType);
191-
break;
192-
}
193-
}
194-
} else {
162+
if (!args.fFp.isSampledWithExplicitCoords()) {
195163
// Sampled with a const/uniform matrix and/or a legacy coord transform. The actual
196164
// transformation code is emitted in the vertex shader, so this only has to access it.
197165
// Add a float2 _coords variable that maps to the associated varying and replaces the
@@ -210,15 +178,15 @@ SkString GrGLSLFPFragmentBuilder::writeProcessorFunction(GrGLSLFragmentProcessor
210178
// and since we won't actually have a function parameter for local coords, add
211179
// it as a local variable.
212180
this->codeAppendf("float2 %s = %s.xy / %s.z;\n", args.fSampleCoord,
213-
varying.getName().c_str(), varying.getName().c_str());
181+
varying.getName().c_str(), varying.getName().c_str());
214182
break;
215183
default:
216184
SkDEBUGFAILF("Unexpected varying type for coord: %s %d\n",
217185
varying.getName().c_str(), (int) varying.getType());
218186
break;
219187
}
220188
}
221-
}
189+
} // else the function keeps its two arguments
222190

223191
this->codeAppendf("half4 %s;\n", args.fOutputColor);
224192
fp->emitCode(args);

0 commit comments

Comments
 (0)