aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl
diff options
context:
space:
mode:
authorGravatar Chris Dalton <csmartdalton@google.com>2018-02-02 11:06:30 -0700
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-02 18:43:29 +0000
commit7b046312edd9219ba8e66c255f5347c000b69ee1 (patch)
tree1119465d75682b9d5952e30695033d1105a24c93 /src/gpu/glsl
parent7a9263906c677c0fa5636521e3cc58ba60837720 (diff)
ccpr: Don't use flat interpolation when it is slow
Bug: skia: Change-Id: I1bc087187541183fdbaa5f2b93e8b8d287ac8ef8 Reviewed-on: https://skia-review.googlesource.com/102100 Commit-Queue: Chris Dalton <csmartdalton@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r--src/gpu/glsl/GrGLSLVarying.cpp44
-rw-r--r--src/gpu/glsl/GrGLSLVarying.h30
2 files changed, 36 insertions, 38 deletions
diff --git a/src/gpu/glsl/GrGLSLVarying.cpp b/src/gpu/glsl/GrGLSLVarying.cpp
index 5a57613b3a..c5cef3492a 100644
--- a/src/gpu/glsl/GrGLSLVarying.cpp
+++ b/src/gpu/glsl/GrGLSLVarying.cpp
@@ -10,36 +10,44 @@
#include "glsl/GrGLSLProgramBuilder.h"
void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::Attribute* input,
- const char* output) {
- GrSLType type = GrVertexAttribTypeToSLType(input->fType);
- GrGLSLVarying v(type);
- this->addVarying(input->fName, &v);
- this->writePassThroughAttribute(input, output, v);
-}
-
-void GrGLSLVaryingHandler::addFlatPassThroughAttribute(const GrGeometryProcessor::Attribute* input,
- const char* output) {
+ const char* output,
+ Interpolation interpolation) {
+ SkASSERT(!fProgramBuilder->primitiveProcessor().willUseGeoShader());
GrSLType type = GrVertexAttribTypeToSLType(input->fType);
GrGLSLVarying v(type);
- this->addFlatVarying(input->fName, &v);
- this->writePassThroughAttribute(input, output, v);
-}
-
-void GrGLSLVaryingHandler::writePassThroughAttribute(const GrGeometryProcessor::Attribute* input,
- const char* output, const GrGLSLVarying& v) {
- SkASSERT(!fProgramBuilder->primitiveProcessor().willUseGeoShader());
+ this->addVarying(input->fName, &v, interpolation);
fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), input->fName);
fProgramBuilder->fFS.codeAppendf("%s = %s;", output, v.fsIn());
}
-void GrGLSLVaryingHandler::internalAddVarying(const char* name, GrGLSLVarying* varying, bool flat) {
+static bool use_flat_interpolation(GrGLSLVaryingHandler::Interpolation interpolation,
+ const GrShaderCaps& shaderCaps) {
+ switch (interpolation) {
+ using Interpolation = GrGLSLVaryingHandler::Interpolation;
+ case Interpolation::kInterpolated:
+ return false;
+ case Interpolation::kCanBeFlat:
+ SkASSERT(!shaderCaps.preferFlatInterpolation() ||
+ shaderCaps.flatInterpolationSupport());
+ return shaderCaps.preferFlatInterpolation();
+ case Interpolation::kMustBeFlat:
+ SkASSERT(shaderCaps.flatInterpolationSupport());
+ return true;
+ }
+ SK_ABORT("Invalid interpolation");
+ return false;
+}
+
+void GrGLSLVaryingHandler::addVarying(const char* name, GrGLSLVarying* varying,
+ Interpolation interpolation) {
+ SkASSERT(GrSLTypeIsFloatType(varying->type()) || Interpolation::kMustBeFlat == interpolation);
bool willUseGeoShader = fProgramBuilder->primitiveProcessor().willUseGeoShader();
VaryingInfo& v = fVaryings.push_back();
SkASSERT(varying);
SkASSERT(kVoid_GrSLType != varying->fType);
v.fType = varying->fType;
- v.fIsFlat = flat;
+ v.fIsFlat = use_flat_interpolation(interpolation, *fProgramBuilder->shaderCaps());
fProgramBuilder->nameVariable(&v.fVsOut, 'v', name);
v.fVisibility = kNone_GrShaderFlags;
if (varying->isInVertexShader()) {
diff --git a/src/gpu/glsl/GrGLSLVarying.h b/src/gpu/glsl/GrGLSLVarying.h
index dac9bb771f..57704ad075 100644
--- a/src/gpu/glsl/GrGLSLVarying.h
+++ b/src/gpu/glsl/GrGLSLVarying.h
@@ -79,6 +79,12 @@ public:
*/
void setNoPerspective();
+ enum class Interpolation {
+ kInterpolated,
+ kCanBeFlat, // Use "flat" if it will be faster.
+ kMustBeFlat // Use "flat" even if it is known to be slow.
+ };
+
/*
* addVarying allows fine grained control for setting up varyings between stages. Calling this
* function will make sure all necessary decls are setup for the client. The client however is
@@ -87,20 +93,8 @@ public:
* addPassThroughAttribute.
* TODO convert most uses of addVarying to addPassThroughAttribute
*/
- void addVarying(const char* name, GrGLSLVarying* varying) {
- SkASSERT(GrSLTypeIsFloatType(varying->type())); // Integers must use addFlatVarying.
- this->internalAddVarying(name, varying, false /*flat*/);
- }
-
- /*
- * addFlatVarying sets up a varying whose value is constant across every fragment. The graphics
- * pipeline will pull its value from the final vertex of the draw primitive (provoking vertex).
- * Flat interpolation is not always supported and the user must check the caps before using.
- * TODO: Some platforms can change the provoking vertex. Should we be resetting this knob?
- */
- void addFlatVarying(const char* name, GrGLSLVarying* varying) {
- this->internalAddVarying(name, varying, true /*flat*/);
- }
+ void addVarying(const char* name, GrGLSLVarying* varying,
+ Interpolation = Interpolation::kInterpolated);
/*
* The GP can use these calls to pass an attribute through all shaders directly to 'output' in
@@ -110,8 +104,8 @@ public:
* that will be set as the output varying for all emitted vertices.
* TODO it might be nicer behavior to have a flag to declare output inside these calls
*/
- void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, const char* output);
- void addFlatPassThroughAttribute(const GrGeometryProcessor::Attribute*, const char* output);
+ void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, const char* output,
+ Interpolation = Interpolation::kInterpolated);
void emitAttributes(const GrGeometryProcessor& gp);
@@ -148,10 +142,6 @@ protected:
GrGLSLProgramBuilder* fProgramBuilder;
private:
- void internalAddVarying(const char* name, GrGLSLVarying*, bool flat);
- void writePassThroughAttribute(const GrGeometryProcessor::Attribute*, const char* output,
- const GrGLSLVarying&);
-
void addAttribute(const GrShaderVar& var);
virtual void onFinalize() = 0;