Remove fragmentProcessor field access
Change-Id: Iafeb13812851271a5262730e9c0642d4469c273f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375020 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: John Stiles <johnstiles@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
c15c19c6e1
commit
029851d951
@ -17,8 +17,6 @@ sksl_fp_error_tests = [
|
||||
|
||||
sksl_fp_tests = [
|
||||
"/sksl/fp/GrChildProcessorAndGlobal.fp",
|
||||
"/sksl/fp/GrChildProcessorFieldAccess.fp",
|
||||
"/sksl/fp/GrChildProcessorInlineFieldAccess.fp",
|
||||
"/sksl/fp/GrChildProcessorSampleCoords.fp",
|
||||
"/sksl/fp/GrChildProcessorSampleMatrixAndCoords.fp",
|
||||
"/sksl/fp/GrChildProcessorSampleMatrixConstant.fp",
|
||||
|
@ -1,10 +0,0 @@
|
||||
in fragmentProcessor child;
|
||||
bool opaque = child.preservesOpaqueInput;
|
||||
|
||||
half4 main() {
|
||||
if (opaque) {
|
||||
return sample(child);
|
||||
} else {
|
||||
return half4(0.5);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
in fragmentProcessor child;
|
||||
|
||||
half4 main() {
|
||||
if (child.preservesOpaqueInput) {
|
||||
return sample(child);
|
||||
} else {
|
||||
return half4(1);
|
||||
}
|
||||
}
|
@ -14,20 +14,6 @@
|
||||
|
||||
namespace SkSL {
|
||||
|
||||
/**
|
||||
* Returns the struct fields for FragmentProcessors; these are intended to parallel the C++ API for
|
||||
* GrFragmentProcessor.
|
||||
*/
|
||||
static std::vector<Type::Field> make_fp_fields(const Type* intType, const Type* boolType) {
|
||||
Modifiers mods{Layout(), Modifiers::kConst_Flag};
|
||||
return {Type::Field(mods, "numTextureSamplers", intType),
|
||||
Type::Field(mods, "numChildProcessors", intType),
|
||||
Type::Field(mods, "usesLocalCoords", boolType),
|
||||
Type::Field(mods, "compatibleWithCoverageAsAlpha", boolType),
|
||||
Type::Field(mods, "preservesOpaqueInput", boolType),
|
||||
Type::Field(mods, "hasConstantOutputForConstantInput", boolType)};
|
||||
}
|
||||
|
||||
/** Create a scalar type. */
|
||||
std::unique_ptr<Type> BuiltinTypes::MakeScalarType(const char* name,
|
||||
Type::NumberKind numberKind,
|
||||
@ -96,12 +82,6 @@ std::unique_ptr<Type> BuiltinTypes::MakeOtherType(const char* name) {
|
||||
return std::unique_ptr<Type>(new Type(name));
|
||||
}
|
||||
|
||||
/** Create an "other" (special) type that supports field access. */
|
||||
std::unique_ptr<Type> BuiltinTypes::MakeOtherStruct(const char* name,
|
||||
std::vector<Type::Field> fields) {
|
||||
return std::unique_ptr<Type>(new Type(name, std::move(fields)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the core SkSL types.
|
||||
*/
|
||||
@ -272,7 +252,6 @@ BuiltinTypes::BuiltinTypes()
|
||||
, fBVec(MakeGenericType("$bvec",
|
||||
{fInvalid.get(), fBool2.get(), fBool3.get(), fBool4.get()}))
|
||||
, fSkCaps(MakeOtherType("$sk_Caps"))
|
||||
, fFragmentProcessor(
|
||||
MakeOtherStruct("fragmentProcessor", make_fp_fields(fInt.get(), fBool.get()))) {}
|
||||
, fFragmentProcessor(MakeOtherType("fragmentProcessor")) {}
|
||||
|
||||
} // namespace SkSL
|
||||
|
@ -154,7 +154,6 @@ private:
|
||||
static std::unique_ptr<Type> MakeSamplerType(const char* name, const Type& textureType);
|
||||
static std::unique_ptr<Type> MakeSeparateSamplerType(const char* name);
|
||||
static std::unique_ptr<Type> MakeOtherType(const char* name);
|
||||
static std::unique_ptr<Type> MakeOtherStruct(const char* name, std::vector<Type::Field> fields);
|
||||
};
|
||||
|
||||
} // namespace SkSL
|
||||
|
@ -344,32 +344,6 @@ void CPPCodeGenerator::writeSwitchStatement(const SwitchStatement& s) {
|
||||
INHERITED::writeSwitchStatement(s);
|
||||
}
|
||||
|
||||
void CPPCodeGenerator::writeFieldAccess(const FieldAccess& access) {
|
||||
if (access.base()->type().name() == "fragmentProcessor") {
|
||||
// Special field access on fragment processors are converted into function calls on
|
||||
// GrFragmentProcessor's getters.
|
||||
if (!access.base()->is<VariableReference>()) {
|
||||
fErrors.error(access.base()->fOffset, "fragmentProcessor must be a reference\n");
|
||||
return;
|
||||
}
|
||||
|
||||
const Type::Field& field =
|
||||
fContext.fTypes.fFragmentProcessor->fields()[access.fieldIndex()];
|
||||
const Variable& var = *access.base()->as<VariableReference>().variable();
|
||||
String cppAccess = String::printf("_outer.childProcessor(%d)->%s()",
|
||||
this->getChildFPIndex(var),
|
||||
String(field.fName).c_str());
|
||||
|
||||
if (fCPPMode) {
|
||||
this->write(cppAccess.c_str());
|
||||
} else {
|
||||
writeRuntimeValue(*field.fType, Layout(), cppAccess);
|
||||
}
|
||||
return;
|
||||
}
|
||||
INHERITED::writeFieldAccess(access);
|
||||
}
|
||||
|
||||
int CPPCodeGenerator::getChildFPIndex(const Variable& var) const {
|
||||
int index = 0;
|
||||
for (const ProgramElement* p : fProgram.elements()) {
|
||||
|
@ -45,8 +45,6 @@ private:
|
||||
|
||||
void writeSwizzle(const Swizzle& swizzle) override;
|
||||
|
||||
void writeFieldAccess(const FieldAccess& access) override;
|
||||
|
||||
void writeVariableReference(const VariableReference& ref) override;
|
||||
|
||||
String getSamplerHandle(const Variable& var);
|
||||
|
@ -2604,7 +2604,6 @@ std::unique_ptr<Expression> IRGenerator::convertFieldExpression(const ASTNode& f
|
||||
return std::make_unique<Setting>(fieldNode.fOffset, field, type);
|
||||
}
|
||||
switch (baseType.typeKind()) {
|
||||
case Type::TypeKind::kOther:
|
||||
case Type::TypeKind::kStruct:
|
||||
return this->convertField(std::move(base), field);
|
||||
default:
|
||||
|
@ -282,7 +282,7 @@ public:
|
||||
}
|
||||
|
||||
const std::vector<Field>& fields() const {
|
||||
SkASSERT(this->isStruct() || fTypeKind == TypeKind::kOther);
|
||||
SkASSERT(this->isStruct());
|
||||
return fFields;
|
||||
}
|
||||
|
||||
@ -382,13 +382,6 @@ private:
|
||||
, fTypeKind(TypeKind::kOther)
|
||||
, fNumberKind(NumberKind::kNonnumeric) {}
|
||||
|
||||
// Constructor for MakeOtherStruct.
|
||||
Type(const char* name, std::vector<Field> fields)
|
||||
: INHERITED(-1, kSymbolKind, name)
|
||||
, fTypeKind(TypeKind::kOther)
|
||||
, fNumberKind(NumberKind::kNonnumeric)
|
||||
, fFields(std::move(fields)) {}
|
||||
|
||||
// Constructor for MakeEnumType and MakeSeparateSamplerType.
|
||||
Type(String name, TypeKind kind)
|
||||
: INHERITED(-1, kSymbolKind, "")
|
||||
|
@ -1,63 +0,0 @@
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
*** This file was autogenerated from GrChildProcessorFieldAccess.fp; do not modify.
|
||||
**************************************************************************************************/
|
||||
#include "GrChildProcessorFieldAccess.h"
|
||||
|
||||
#include "src/core/SkUtils.h"
|
||||
#include "src/gpu/GrTexture.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
|
||||
#include "src/sksl/SkSLCPP.h"
|
||||
#include "src/sksl/SkSLUtil.h"
|
||||
class GrGLSLChildProcessorFieldAccess : public GrGLSLFragmentProcessor {
|
||||
public:
|
||||
GrGLSLChildProcessorFieldAccess() {}
|
||||
void emitCode(EmitArgs& args) override {
|
||||
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
||||
const GrChildProcessorFieldAccess& _outer = args.fFp.cast<GrChildProcessorFieldAccess>();
|
||||
(void) _outer;
|
||||
opaque = _outer.childProcessor(0)->preservesOpaqueInput();
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(bool opaque = %s;
|
||||
if (opaque) {)SkSL"
|
||||
, (opaque ? "true" : "false"));
|
||||
SkString _sample0 = this->invokeChild(0, args);
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(
|
||||
return %s;
|
||||
} else {
|
||||
return half4(0.5);
|
||||
}
|
||||
)SkSL"
|
||||
, _sample0.c_str());
|
||||
}
|
||||
private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
|
||||
}
|
||||
bool opaque = false;
|
||||
};
|
||||
std::unique_ptr<GrGLSLFragmentProcessor> GrChildProcessorFieldAccess::onMakeProgramImpl() const {
|
||||
return std::make_unique<GrGLSLChildProcessorFieldAccess>();
|
||||
}
|
||||
void GrChildProcessorFieldAccess::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
|
||||
}
|
||||
bool GrChildProcessorFieldAccess::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrChildProcessorFieldAccess& that = other.cast<GrChildProcessorFieldAccess>();
|
||||
(void) that;
|
||||
return true;
|
||||
}
|
||||
GrChildProcessorFieldAccess::GrChildProcessorFieldAccess(const GrChildProcessorFieldAccess& src)
|
||||
: INHERITED(kGrChildProcessorFieldAccess_ClassID, src.optimizationFlags()) {
|
||||
this->cloneAndRegisterAllChildProcessors(src);
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrChildProcessorFieldAccess::clone() const {
|
||||
return std::make_unique<GrChildProcessorFieldAccess>(*this);
|
||||
}
|
||||
#if GR_TEST_UTILS
|
||||
SkString GrChildProcessorFieldAccess::onDumpInfo() const {
|
||||
return SkString();
|
||||
}
|
||||
#endif
|
@ -1,36 +0,0 @@
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
*** This file was autogenerated from GrChildProcessorFieldAccess.fp; do not modify.
|
||||
**************************************************************************************************/
|
||||
#ifndef GrChildProcessorFieldAccess_DEFINED
|
||||
#define GrChildProcessorFieldAccess_DEFINED
|
||||
|
||||
#include "include/core/SkM44.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
|
||||
#include "src/gpu/GrFragmentProcessor.h"
|
||||
|
||||
class GrChildProcessorFieldAccess : public GrFragmentProcessor {
|
||||
public:
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrChildProcessorFieldAccess(std::move(child)));
|
||||
}
|
||||
GrChildProcessorFieldAccess(const GrChildProcessorFieldAccess& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "ChildProcessorFieldAccess"; }
|
||||
private:
|
||||
GrChildProcessorFieldAccess(std::unique_ptr<GrFragmentProcessor> child)
|
||||
: INHERITED(kGrChildProcessorFieldAccess_ClassID, kNone_OptimizationFlags) {
|
||||
this->registerChild(std::move(child), SkSL::SampleUsage::PassThrough()); }
|
||||
std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
#if GR_TEST_UTILS
|
||||
SkString onDumpInfo() const override;
|
||||
#endif
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||
using INHERITED = GrFragmentProcessor;
|
||||
};
|
||||
#endif
|
@ -1,60 +0,0 @@
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
*** This file was autogenerated from GrChildProcessorInlineFieldAccess.fp; do not modify.
|
||||
**************************************************************************************************/
|
||||
#include "GrChildProcessorInlineFieldAccess.h"
|
||||
|
||||
#include "src/core/SkUtils.h"
|
||||
#include "src/gpu/GrTexture.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
|
||||
#include "src/sksl/SkSLCPP.h"
|
||||
#include "src/sksl/SkSLUtil.h"
|
||||
class GrGLSLChildProcessorInlineFieldAccess : public GrGLSLFragmentProcessor {
|
||||
public:
|
||||
GrGLSLChildProcessorInlineFieldAccess() {}
|
||||
void emitCode(EmitArgs& args) override {
|
||||
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
||||
const GrChildProcessorInlineFieldAccess& _outer = args.fFp.cast<GrChildProcessorInlineFieldAccess>();
|
||||
(void) _outer;
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(if (%s) {)SkSL"
|
||||
, (_outer.childProcessor(0)->preservesOpaqueInput() ? "true" : "false"));
|
||||
SkString _sample0 = this->invokeChild(0, args);
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(
|
||||
return %s;
|
||||
} else {
|
||||
return half4(1.0);
|
||||
}
|
||||
)SkSL"
|
||||
, _sample0.c_str());
|
||||
}
|
||||
private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
|
||||
}
|
||||
};
|
||||
std::unique_ptr<GrGLSLFragmentProcessor> GrChildProcessorInlineFieldAccess::onMakeProgramImpl() const {
|
||||
return std::make_unique<GrGLSLChildProcessorInlineFieldAccess>();
|
||||
}
|
||||
void GrChildProcessorInlineFieldAccess::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
|
||||
}
|
||||
bool GrChildProcessorInlineFieldAccess::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrChildProcessorInlineFieldAccess& that = other.cast<GrChildProcessorInlineFieldAccess>();
|
||||
(void) that;
|
||||
return true;
|
||||
}
|
||||
GrChildProcessorInlineFieldAccess::GrChildProcessorInlineFieldAccess(const GrChildProcessorInlineFieldAccess& src)
|
||||
: INHERITED(kGrChildProcessorInlineFieldAccess_ClassID, src.optimizationFlags()) {
|
||||
this->cloneAndRegisterAllChildProcessors(src);
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrChildProcessorInlineFieldAccess::clone() const {
|
||||
return std::make_unique<GrChildProcessorInlineFieldAccess>(*this);
|
||||
}
|
||||
#if GR_TEST_UTILS
|
||||
SkString GrChildProcessorInlineFieldAccess::onDumpInfo() const {
|
||||
return SkString();
|
||||
}
|
||||
#endif
|
@ -1,36 +0,0 @@
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
*** This file was autogenerated from GrChildProcessorInlineFieldAccess.fp; do not modify.
|
||||
**************************************************************************************************/
|
||||
#ifndef GrChildProcessorInlineFieldAccess_DEFINED
|
||||
#define GrChildProcessorInlineFieldAccess_DEFINED
|
||||
|
||||
#include "include/core/SkM44.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
|
||||
#include "src/gpu/GrFragmentProcessor.h"
|
||||
|
||||
class GrChildProcessorInlineFieldAccess : public GrFragmentProcessor {
|
||||
public:
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrChildProcessorInlineFieldAccess(std::move(child)));
|
||||
}
|
||||
GrChildProcessorInlineFieldAccess(const GrChildProcessorInlineFieldAccess& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "ChildProcessorInlineFieldAccess"; }
|
||||
private:
|
||||
GrChildProcessorInlineFieldAccess(std::unique_ptr<GrFragmentProcessor> child)
|
||||
: INHERITED(kGrChildProcessorInlineFieldAccess_ClassID, kNone_OptimizationFlags) {
|
||||
this->registerChild(std::move(child), SkSL::SampleUsage::PassThrough()); }
|
||||
std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
#if GR_TEST_UTILS
|
||||
SkString onDumpInfo() const override;
|
||||
#endif
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||
using INHERITED = GrFragmentProcessor;
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user