skia2/tests/sksl/fp/golden/GrNestedCall.cpp
John Stiles 569249be6c Improve support for function prototypes in SkSL.
Previously, when a prototype was parsed, this added a function
declaration to the symbol table, but the prototype itself was not
re-emitted during code generation. This meant that the final code might
not be valid, since the absence of prototypes meant that the code might
attempt to invoke a function before its declaration. Now, prototypes are
stored in the ProgramElement list and re-emitted during code generation
for GLSL/Metal/CPP. (SPIR-V doesn't name its functions at all.)

Change-Id: I76446c796000eb0b56f964d82457122182c28b87
Bug: skia:10872
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/331136
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-11-03 19:09:25 +00:00

73 lines
3.0 KiB
C++

/*#pragma settings NoInline*/
/**************************************************************************************************
*** This file was autogenerated from GrNestedCall.fp; do not modify.
**************************************************************************************************/
#include "GrNestedCall.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 GrGLSLNestedCall : public GrGLSLFragmentProcessor {
public:
GrGLSLNestedCall() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrNestedCall& _outer = args.fFp.cast<GrNestedCall>();
(void) _outer;
SkString func1_name = fragBuilder->getMangledFunctionName("func1");
const GrShaderVar func1_args[] = { };
SkString func2_name = fragBuilder->getMangledFunctionName("func2");
const GrShaderVar func2_args[] = { };
SkString func3_name = fragBuilder->getMangledFunctionName("func3");
const GrShaderVar func3_args[] = { };
fragBuilder->emitFunctionPrototype(kHalf4_GrSLType, func1_name.c_str(), {func1_args, 0});
fragBuilder->emitFunctionPrototype(kHalf4_GrSLType, func2_name.c_str(), {func2_args, 0});
fragBuilder->emitFunctionPrototype(kHalf4_GrSLType, func3_name.c_str(), {func3_args, 0});
const String func1_impl = String::printf(R"SkSL(return %s();
)SkSL"
, func2_name.c_str());
fragBuilder->emitFunction(kHalf4_GrSLType, func1_name.c_str(), {func1_args, 0}, func1_impl.c_str());
const String func2_impl = String::printf(R"SkSL(return %s();
)SkSL"
, func3_name.c_str());
fragBuilder->emitFunction(kHalf4_GrSLType, func2_name.c_str(), {func2_args, 0}, func2_impl.c_str());
fragBuilder->codeAppendf(
R"SkSL(%s = %s();
)SkSL"
, args.fOutputColor, func1_name.c_str());
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
}
};
GrGLSLFragmentProcessor* GrNestedCall::onCreateGLSLInstance() const {
return new GrGLSLNestedCall();
}
void GrNestedCall::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
}
bool GrNestedCall::onIsEqual(const GrFragmentProcessor& other) const {
const GrNestedCall& that = other.cast<GrNestedCall>();
(void) that;
return true;
}
bool GrNestedCall::usesExplicitReturn() const {
return false;
}
GrNestedCall::GrNestedCall(const GrNestedCall& src)
: INHERITED(kGrNestedCall_ClassID, src.optimizationFlags()) {
this->cloneAndRegisterAllChildProcessors(src);
}
std::unique_ptr<GrFragmentProcessor> GrNestedCall::clone() const {
return std::make_unique<GrNestedCall>(*this);
}
#if GR_TEST_UTILS
SkString GrNestedCall::onDumpInfo() const {
return SkString();
}
#endif