Flutter Engine
The Flutter Engine
GrGLSLVarying.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
8
15#include "src/sksl/SkSLGLSL.h"
16
18 const char* output,
19 Interpolation interpolation) {
21 GrGLSLVarying v(vsVar.getType());
22 this->addVarying(vsVar.c_str(), &v, interpolation);
23 fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), vsVar.c_str());
24 fProgramBuilder->fFS.codeAppendf("%s = %s;", output, v.fsIn());
25}
26
28 const GrShaderCaps& shaderCaps) {
29 switch (interpolation) {
30 using Interpolation = GrGLSLVaryingHandler::Interpolation;
31 case Interpolation::kInterpolated:
32 return false;
33 case Interpolation::kCanBeFlat:
35 return shaderCaps.fPreferFlatInterpolation;
36 case Interpolation::kMustBeFlat:
38 return true;
39 }
40 SK_ABORT("Invalid interpolation");
41}
42
44 Interpolation interpolation) {
45 SkASSERT(SkSLTypeIsFloatType(varying->type()) || Interpolation::kMustBeFlat == interpolation);
47
48 SkASSERT(varying);
49 SkASSERT(SkSLType::kVoid != varying->fType);
50 v.fType = varying->fType;
54 if (varying->isInVertexShader()) {
55 varying->fVsOut = v.fVsOut.c_str();
57 }
58 if (varying->isInFragmentShader()) {
59 varying->fFsIn = v.fVsOut.c_str();
61 }
62}
63
65 for (auto attr : gp.vertexAttributes()) {
66 this->addAttribute(attr.asShaderVar());
67 }
68 for (auto attr : gp.instanceAttributes()) {
69 this->addAttribute(attr.asShaderVar());
70 }
71}
72
73void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) {
75 for (const GrShaderVar& attr : fVertexInputs.items()) {
76 // if attribute already added, don't add it again
77 if (attr.getName().equals(var.getName())) {
78 return;
79 }
80 }
82}
83
85 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
87 return;
88 }
89 if (const char* extension = caps.noperspectiveInterpolationExtensionString()) {
91 fProgramBuilder->fVS.addFeature(bit, extension);
92 fProgramBuilder->fFS.addFeature(bit, extension);
93 }
94 fDefaultInterpolationModifier = "noperspective";
95}
96
98 for (const VaryingInfo& v : fVaryings.items()) {
99 const char* modifier = v.fIsFlat ? "flat" : fDefaultInterpolationModifier;
100 if (v.fVisibility & kVertex_GrShaderFlag) {
103 }
104 if (v.fVisibility & kFragment_GrShaderFlag) {
105 const char* fsIn = v.fVsOut.c_str();
108 }
109 }
110 this->onFinalize();
111}
112
113void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) const {
114 for (const GrShaderVar& varying : vars.items()) {
115 varying.appendDecl(fProgramBuilder->shaderCaps(), out);
116 out->append(";");
117 }
118}
119
120void GrGLSLVaryingHandler::getVertexDecls(SkString* inputDecls, SkString* outputDecls) const {
121 this->appendDecls(fVertexInputs, inputDecls);
122 this->appendDecls(fVertexOutputs, outputDecls);
123}
124
125void GrGLSLVaryingHandler::getFragDecls(SkString* inputDecls, SkString* outputDecls) const {
126 // We should not have any outputs in the fragment shader when using version 1.10
129 this->appendDecls(fFragInputs, inputDecls);
130 this->appendDecls(fFragOutputs, outputDecls);
131}
static bool use_flat_interpolation(GrGLSLVaryingHandler::Interpolation interpolation, const GrShaderCaps &shaderCaps)
@ kVertex_GrShaderFlag
Definition: GrTypesPriv.h:286
@ kNone_GrShaderFlags
Definition: GrTypesPriv.h:285
@ kFragment_GrShaderFlag
Definition: GrTypesPriv.h:287
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr bool SkSLTypeIsFloatType(SkSLType type)
SkString nameVariable(char prefix, const char *name, bool mangle=true)
const GrShaderCaps * shaderCaps() const
GrGLSLVertexBuilder fVS
GrGLSLFragmentShaderBuilder fFS
bool addFeature(uint32_t featureBit, const char *extensionName)
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
void emitAttributes(const GrGeometryProcessor &)
void addPassThroughAttribute(const GrShaderVar &vsVar, const char *output, Interpolation=Interpolation::kInterpolated)
void getVertexDecls(SkString *inputDecls, SkString *outputDecls) const
void getFragDecls(SkString *inputDecls, SkString *outputDecls) const
GrGLSLProgramBuilder * fProgramBuilder
virtual void onFinalize()=0
void addVarying(const char *name, GrGLSLVarying *varying, Interpolation=Interpolation::kInterpolated)
bool isInVertexShader() const
Definition: GrGLSLVarying.h:64
const char * vsOut() const
Definition: GrGLSLVarying.h:67
bool isInFragmentShader() const
Definition: GrGLSLVarying.h:65
const char * fsIn() const
Definition: GrGLSLVarying.h:68
SkSLType type() const
Definition: GrGLSLVarying.h:62
const AttributeSet & vertexAttributes() const
const AttributeSet & instanceAttributes() const
SkSLType getType() const
Definition: GrShaderVar.h:97
const char * c_str() const
Definition: GrShaderVar.h:94
TypeModifier getTypeModifier() const
Definition: GrShaderVar.h:99
const SkString & getName() const
Definition: GrShaderVar.h:91
const char * c_str() const
Definition: SkString.h:133
T & push_back()
Definition: SkTBlockList.h:90
T & emplace_back(Args &&... args)
Definition: SkTBlockList.h:101
bool empty() const
Definition: SkTBlockList.h:185
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Definition: __init__.py:1
bool fPreferFlatInterpolation
Definition: GrShaderCaps.h:35
const char * noperspectiveInterpolationExtensionString() const
Definition: GrShaderCaps.h:22
bool fFlatInterpolationSupport
Definition: SkSLUtil.h:96
bool fNoPerspectiveInterpolationSupport
Definition: SkSLUtil.h:97
SkSL::GLSLGeneration fGLSLGeneration
Definition: SkSLUtil.h:82