Fixed sample_matrix_constant GM
This GM was not actually doing what the name implied, and when
switched over to use a constant matrix, turned out to not work.
This fixes it so constant matrices properly affect child processors.
Change-Id: I1f6b271dbf43c18515c0c72701bf8bbf60eb4c59
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293716
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp
index 3ef36d4..d4eb2af 100644
--- a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp
@@ -14,6 +14,8 @@
#include "src/gpu/glsl/GrGLSLVarying.h"
#include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h"
+#include <unordered_map>
+
void GrGLSLGeometryProcessor::emitCode(EmitArgs& args) {
GrGPArgs gpArgs;
this->onEmitCode(args, &gpArgs);
@@ -142,23 +144,34 @@
void GrGLSLGeometryProcessor::emitTransformCode(GrGLSLVertexBuilder* vb,
GrGLSLUniformHandler* uniformHandler) {
+ std::unordered_map<const GrFragmentProcessor*, const char*> localCoordsMap;
for (const auto& tr : fTransformInfos) {
switch (tr.fFP->sampleMatrix().fKind) {
- case SkSL::SampleMatrix::Kind::kConstantOrUniform:
+ case SkSL::SampleMatrix::Kind::kConstantOrUniform: {
+ SkString localCoords;
+ localCoordsMap.insert({ tr.fFP, tr.fName });
+ if (tr.fFP->sampleMatrix().fBase) {
+ SkASSERT(localCoordsMap[tr.fFP->sampleMatrix().fBase]);
+ localCoords = SkStringPrintf("float3(%s, 1)",
+ localCoordsMap[tr.fFP->sampleMatrix().fBase]);
+ } else {
+ localCoords = tr.fLocalCoords.c_str();
+ }
vb->codeAppend("{\n");
uniformHandler->writeUniformMappings(tr.fFP->sampleMatrix().fOwner, vb);
if (tr.fType == kFloat2_GrSLType) {
vb->codeAppendf("%s = (%s * %s * %s).xy", tr.fName,
tr.fFP->sampleMatrix().fExpression.c_str(), tr.fMatrix.c_str(),
- tr.fLocalCoords.c_str());
+ localCoords.c_str());
} else {
SkASSERT(tr.fType == kFloat3_GrSLType);
vb->codeAppendf("%s = %s * %s * %s", tr.fName,
tr.fFP->sampleMatrix().fExpression.c_str(), tr.fMatrix.c_str(),
- tr.fLocalCoords.c_str());
+ localCoords.c_str());
}
vb->codeAppend(";\n");
vb->codeAppend("}\n");
+ }
default:
break;
}