40242241c3
This reverts commit 943108b0b2
.
Reason for revert: clockwise GM bad on android.
Original change's description:
> Don't key progams/pipelines on origin.
>
> SkSL language features that are origin sensitive now use a uniform
> to conditionally flip their result rather than generating different
> code.
>
> Previously we would insert a "rt height" uniform if sk_FragCoord needed
> to be flipped. sk_FragCoord,y was implemented as "realFragCoord.y" or
> "rtHeight - realFragCoord.y" depending on SkSL::ProgramSettings::fFlipY.
>
> Now we instead use a two component vector rtFlip and sk_FragCoord.y is
> always "rtFlip.x + rtFlip.y*realFragCoord.y". We configure rtFlip as
> either (0, 1) or (rtHeight, -1). sk_Clockwise and dFdy simiarly use
> rtFlip.y to emit code that always works with either origin.
>
> Bug: skia:12037
>
> Change-Id: I7a09d0caac60a58d72b76645ff31bcabde4086b6
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/414796
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,ethannicholas@google.com
Change-Id: I91cc0d86be216f6c32e453a231de088c991be4b2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:12037
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/425056
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
176 lines
4.6 KiB
C++
176 lines
4.6 KiB
C++
/*
|
|
* Copyright 2020 Google LLC
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#ifndef SKSL_DSL_VAR
|
|
#define SKSL_DSL_VAR
|
|
|
|
#include "include/sksl/DSLExpression.h"
|
|
#include "include/sksl/DSLModifiers.h"
|
|
#include "include/sksl/DSLType.h"
|
|
|
|
namespace SkSL {
|
|
|
|
class IRGenerator;
|
|
class Variable;
|
|
enum class VariableStorage : int8_t;
|
|
|
|
namespace dsl {
|
|
|
|
class DSLVar {
|
|
public:
|
|
/**
|
|
* Creates an empty, unpopulated DSLVar. Can be replaced with a real DSLVar later via `swap`.
|
|
*/
|
|
DSLVar() : fType(kVoid_Type), fDeclared(true) {}
|
|
|
|
/**
|
|
* Constructs a new variable with the specified type and name. The name is used (in mangled
|
|
* form) in the resulting shader code; it is not otherwise important. Since mangling prevents
|
|
* name conflicts and the variable's name is only important when debugging shaders, the name
|
|
* parameter is optional.
|
|
*/
|
|
DSLVar(DSLType type, skstd::string_view name = "var",
|
|
DSLExpression initialValue = DSLExpression());
|
|
|
|
DSLVar(DSLType type, const char* name, DSLExpression initialValue = DSLExpression())
|
|
: DSLVar(type, skstd::string_view(name), std::move(initialValue)) {}
|
|
|
|
DSLVar(DSLType type, DSLExpression initialValue);
|
|
|
|
DSLVar(DSLModifiers modifiers, DSLType type, skstd::string_view name = "var",
|
|
DSLExpression initialValue = DSLExpression());
|
|
|
|
DSLVar(DSLModifiers modifiers, DSLType type, const char* name,
|
|
DSLExpression initialValue = DSLExpression())
|
|
: DSLVar(modifiers, type, skstd::string_view(name), std::move(initialValue)) {}
|
|
|
|
DSLVar(DSLModifiers modifiers, DSLType type, DSLExpression initialValue);
|
|
|
|
DSLVar(DSLVar&&) = default;
|
|
|
|
~DSLVar();
|
|
|
|
skstd::string_view name() const {
|
|
return fName;
|
|
}
|
|
|
|
DSLModifiers modifiers() const {
|
|
return fModifiers;
|
|
}
|
|
|
|
void swap(DSLVar& other);
|
|
|
|
DSLExpression x() {
|
|
return DSLExpression(*this).x();
|
|
}
|
|
|
|
DSLExpression y() {
|
|
return DSLExpression(*this).y();
|
|
}
|
|
|
|
DSLExpression z() {
|
|
return DSLExpression(*this).z();
|
|
}
|
|
|
|
DSLExpression w() {
|
|
return DSLExpression(*this).w();
|
|
}
|
|
|
|
DSLExpression r() {
|
|
return DSLExpression(*this).r();
|
|
}
|
|
|
|
DSLExpression g() {
|
|
return DSLExpression(*this).g();
|
|
}
|
|
|
|
DSLExpression b() {
|
|
return DSLExpression(*this).b();
|
|
}
|
|
|
|
DSLExpression a() {
|
|
return DSLExpression(*this).a();
|
|
}
|
|
|
|
DSLExpression field(skstd::string_view name) {
|
|
return DSLExpression(*this).field(name);
|
|
}
|
|
|
|
DSLPossibleExpression operator=(DSLVar& var) {
|
|
return this->operator=(DSLExpression(var));
|
|
}
|
|
|
|
DSLPossibleExpression operator=(DSLExpression expr);
|
|
|
|
DSLPossibleExpression operator=(int expr) {
|
|
return this->operator=(DSLExpression(expr));
|
|
}
|
|
|
|
DSLPossibleExpression operator=(float expr) {
|
|
return this->operator=(DSLExpression(expr));
|
|
}
|
|
|
|
DSLPossibleExpression operator=(double expr) {
|
|
return this->operator=(DSLExpression(expr));
|
|
}
|
|
|
|
DSLPossibleExpression operator[](DSLExpression&& index);
|
|
|
|
DSLPossibleExpression operator++() {
|
|
return ++DSLExpression(*this);
|
|
}
|
|
|
|
DSLPossibleExpression operator++(int) {
|
|
return DSLExpression(*this)++;
|
|
}
|
|
|
|
DSLPossibleExpression operator--() {
|
|
return --DSLExpression(*this);
|
|
}
|
|
|
|
DSLPossibleExpression operator--(int) {
|
|
return DSLExpression(*this)--;
|
|
}
|
|
|
|
private:
|
|
/**
|
|
* Constructs a reference to a variable that already exists in the symbol table. This is used
|
|
* internally to reference built-in vars.
|
|
*/
|
|
DSLVar(const char* name);
|
|
|
|
DSLModifiers fModifiers;
|
|
// We only need to keep track of the type here so that we can create the SkSL::Variable. For
|
|
// predefined variables this field is unnecessary, so we don't bother tracking it and just set
|
|
// it to kVoid; in other words, you shouldn't generally be relying on this field to be correct.
|
|
// If you need to determine the variable's type, look at DSLWriter::Var(...).type() instead.
|
|
DSLType fType;
|
|
int fUniformHandle = -1;
|
|
std::unique_ptr<SkSL::Statement> fDeclaration;
|
|
const SkSL::Variable* fVar = nullptr;
|
|
skstd::string_view fRawName; // for error reporting
|
|
skstd::string_view fName;
|
|
DSLExpression fInitialValue;
|
|
VariableStorage fStorage;
|
|
bool fDeclared = false;
|
|
|
|
friend DSLVar sk_SampleCoord();
|
|
|
|
friend class DSLCore;
|
|
friend class DSLExpression;
|
|
friend class DSLFunction;
|
|
friend class DSLWriter;
|
|
friend class ::SkSL::IRGenerator;
|
|
};
|
|
|
|
} // namespace dsl
|
|
|
|
} // namespace SkSL
|
|
|
|
|
|
#endif
|