skia2/tests/sksl/dslfp/GrDSLFPTest_IfStatement.dsl.cpp
John Stiles b9fc6e45c2 Support 'layout(when)' expressions in DSL C++.
This required some changes to how we name variables in DSL.
When-expressions are designed to expect a local C++ variable with the
same name as the layout key. This constraint means our DSLVar variables
CANNOT have the same name as the layout key. Now, all DSL variables are
given a prefix. We try to keep the code tidy by using just a leading
underscore as the prefix, where it's safe to do so. (The C++ naming
rules put some underscore-names out of bounds, but underscore followed
by a lowercase letter is safe.)

Change-Id: Iaa8878042329b9909096f05712d5cf636ea01822
Bug: skia:11854
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/400623
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-04-26 15:17:38 +00:00

74 lines
3.5 KiB
C++

/**************************************************************************************************
*** This file was autogenerated from GrDSLFPTest_IfStatement.fp; do not modify.
**************************************************************************************************/
/* TODO(skia:11854): DSLCPPCodeGenerator is currently a work in progress. */
#include "GrDSLFPTest_IfStatement.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"
#include "src/sksl/dsl/priv/DSLFPs.h"
#include "src/sksl/dsl/priv/DSLWriter.h"
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wcomma"
#endif
class GrGLSLDSLFPTest_IfStatement : public GrGLSLFragmentProcessor {
public:
GrGLSLDSLFPTest_IfStatement() {}
void emitCode(EmitArgs& args) override {
const GrDSLFPTest_IfStatement& _outer = args.fFp.cast<GrDSLFPTest_IfStatement>();
(void) _outer;
using namespace SkSL::dsl;
StartFragmentProcessor(this, &args);
[[maybe_unused]] const auto& one = _outer.one;
Var _one(kConst_Modifier, DSLType(kHalf_Type), "one", Half(one));
Declare(_one);
Var _color(kNo_Modifier, DSLType(kHalf4_Type), "color", Half4(0.0f));
Declare(_color);
If(Swizzle(_color, X, Y) == Swizzle(_color, Z, W), /*Then:*/ _color.w() = _one);
If(Swizzle(_color, X, Y) == Swizzle(_color, Z, W), /*Then:*/ Block(_color.x() = _color.w()));
If(_color.x() == _color.y(), /*Then:*/ _color = Swizzle(_color, W, X, W, W), /*Else:*/ _color = Swizzle(_color, X, X, X, W));
If(((_color.x() + _color.y()) + _color.z()) + _color.w() == _one, /*Then:*/ Block(_color = Half4(-1.0f)), /*Else:*/ If(((_color.x() + _color.y()) + _color.z()) + _color.w() == 2.0f, /*Then:*/ Block(_color = Half4(-2.0f)), /*Else:*/ Block(_color = Swizzle(_color, Y, Y, W, W))));
If(_color.x() == _one, /*Then:*/ Block(If(_color.x() == 2.0f, /*Then:*/ Block(_color = Swizzle(_color, X, X, X, X)), /*Else:*/ Block(_color = Swizzle(_color, Y, Y, Y, Y)))), /*Else:*/ Block(If(_color.z() * _color.w() == _one, /*Then:*/ Block(_color = Swizzle(_color, X, Z, Y, W)), /*Else:*/ Block(_color = Swizzle(_color, W, W, W, W)))));
Return(_color);
EndFragmentProcessor();
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
}
};
std::unique_ptr<GrGLSLFragmentProcessor> GrDSLFPTest_IfStatement::onMakeProgramImpl() const {
return std::make_unique<GrGLSLDSLFPTest_IfStatement>();
}
void GrDSLFPTest_IfStatement::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
b->add32(sk_bit_cast<uint32_t>(one), "one");
}
bool GrDSLFPTest_IfStatement::onIsEqual(const GrFragmentProcessor& other) const {
const GrDSLFPTest_IfStatement& that = other.cast<GrDSLFPTest_IfStatement>();
(void) that;
if (one != that.one) return false;
return true;
}
GrDSLFPTest_IfStatement::GrDSLFPTest_IfStatement(const GrDSLFPTest_IfStatement& src)
: INHERITED(kGrDSLFPTest_IfStatement_ClassID, src.optimizationFlags())
, one(src.one) {
this->cloneAndRegisterAllChildProcessors(src);
}
std::unique_ptr<GrFragmentProcessor> GrDSLFPTest_IfStatement::clone() const {
return std::make_unique<GrDSLFPTest_IfStatement>(*this);
}
#if GR_TEST_UTILS
SkString GrDSLFPTest_IfStatement::onDumpInfo() const {
return SkStringPrintf("(one=%f)", one);
}
#endif