Revert "added support for sk_Dimensions to SkSL"

This reverts commit 9335c28e40.

Reason for revert: breaking vulkan and maybe metal in gold

Original change's description:
> added support for sk_Dimensions to SkSL
> 
> Bug: skia:
> Change-Id: I5f6a9941822b7b4a3ad85b22b1bcd31d58320f90
> Reviewed-on: https://skia-review.googlesource.com/146640
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>

TBR=bsalomon@google.com,ethannicholas@google.com

Change-Id: I5e9dcfffd118ef125afb7b7792f16cb51dd779a3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/148680
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2018-08-22 13:56:32 +00:00 committed by Skia Commit-Bot
parent 13df9817f8
commit e6ab998bc2
23 changed files with 107 additions and 176 deletions

View File

@ -127,13 +127,10 @@ void GrGLProgram::setFragmentData(const GrPipeline& pipeline, int* nextTexSample
void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc,
const GrRenderTargetProxy* proxy) {
GrRenderTarget* rt = proxy->peekRenderTarget();
// Load the RT dimension uniform if it is needed
if (fBuiltinUniformHandles.fRTDimensionsUni.isValid() &&
(fRenderTargetState.fRenderTargetSize.fWidth != rt->width() ||
fRenderTargetState.fRenderTargetSize.fHeight != rt->height())) {
fProgramDataManager.set2f(fBuiltinUniformHandles.fRTDimensionsUni,
SkIntToScalar(rt->width()),
SkIntToScalar(rt->height()));
// Load the RT height uniform if it is needed to y-flip gl_FragCoord.
if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
fRenderTargetState.fRenderTargetSize.fHeight != rt->height()) {
fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, SkIntToScalar(rt->height()));
}
// set RT adjustment

View File

@ -159,12 +159,6 @@ void GrGLProgramBuilder::computeCountsAndStrides(GrGLuint programID,
SkASSERT(fInstanceStride == primProc.debugOnly_instanceStride());
}
void GrGLProgramBuilder::addInputVars(const SkSL::Program::Inputs& inputs) {
if (inputs.fRTDimensions) {
this->addRTDimensionsUniform(SKSL_RTDIMENSIONS_NAME);
}
}
GrGLProgram* GrGLProgramBuilder::finalize() {
TRACE_EVENT0("skia", TRACE_FUNC);
@ -210,7 +204,9 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
if (GR_GL_GET_ERROR(this->gpu()->glInterface()) == GR_GL_NO_ERROR) {
cached = this->checkLinkStatus(programID);
if (cached) {
this->addInputVars(inputs);
if (inputs.fRTHeight) {
this->addRTHeightUniform(SKSL_RTHEIGHT_NAME);
}
this->computeCountsAndStrides(programID, primProc, false);
}
} else {
@ -235,7 +231,9 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
return nullptr;
}
inputs = fs->fInputs;
this->addInputVars(inputs);
if (inputs.fRTHeight) {
this->addRTHeightUniform(SKSL_RTHEIGHT_NAME);
}
if (!this->compileAndAttachShaders(glsl.c_str(), glsl.size(), programID,
GR_GL_FRAGMENT_SHADER, &shadersToDelete, settings,
inputs)) {

View File

@ -48,7 +48,6 @@ private:
GrGLProgramBuilder(GrGLGpu*, const GrPipeline&, const GrPrimitiveProcessor&,
GrProgramDesc*);
void addInputVars(const SkSL::Program::Inputs& inputs);
bool compileAndAttachShaders(const char* glsl,
int length,
GrGLuint programId,

View File

@ -371,12 +371,12 @@ void GrGLSLProgramBuilder::appendUniformDecls(GrShaderFlags visibility, SkString
this->uniformHandler()->appendUniformDecls(visibility, out);
}
void GrGLSLProgramBuilder::addRTDimensionsUniform(const char* name) {
SkASSERT(!fUniformHandles.fRTDimensionsUni.isValid());
void GrGLSLProgramBuilder::addRTHeightUniform(const char* name) {
SkASSERT(!fUniformHandles.fRTHeightUni.isValid());
GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
fUniformHandles.fRTDimensionsUni =
fUniformHandles.fRTHeightUni =
uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag,
kFloat2_GrSLType, kDefault_GrSLPrecision,
kHalf_GrSLType, kDefault_GrSLPrecision,
name, false, 0, nullptr);
}

View File

@ -49,9 +49,9 @@ public:
return this->uniformHandler()->samplerSwizzle(handle);
}
// Used to add a uniform for the RenderTarget height (used for sk_Dimensions and sk_FragCoord)
// without mangling the name of the uniform inside of a stage.
void addRTDimensionsUniform(const char* name);
// Used to add a uniform for the RenderTarget height (used for frag position) without mangling
// the name of the uniform inside of a stage.
void addRTHeightUniform(const char* name);
// Generates a name for a variable. The generated string will be name prefixed by the prefix
// char (unless the prefix is '\0'). It also will mangle the name to be stage-specific unless

View File

@ -20,9 +20,9 @@ class GrGLSLProgramBuilder;
// Handles for program uniforms (other than per-effect uniforms)
struct GrGLSLBuiltinUniformHandles {
GrGLSLProgramDataManager::UniformHandle fRTAdjustmentUni;
// Render target dimensions, used to implement sk_Dimensions and to calculate sk_FragCoord when
// We use the render target height to provide a y-down frag coord when specifying
// origin_upper_left is not supported.
GrGLSLProgramDataManager::UniformHandle fRTDimensionsUni;
GrGLSLProgramDataManager::UniformHandle fRTHeightUni;
};
class GrGLSLUniformHandler {

View File

@ -145,11 +145,9 @@ void GrMtlPipelineState::setRenderTargetState(const GrRenderTargetProxy* proxy)
GrRenderTarget* rt = proxy->peekRenderTarget();
// Load the RT height uniform if it is needed to y-flip gl_FragCoord.
if (fBuiltinUniformHandles.fRTDimensionsUni.isValid() &&
(fRenderTargetState.fRenderTargetSize.fWidth != rt->width() ||
fRenderTargetState.fRenderTargetSize.fHeight != rt->height())) {
fDataManager.set2f(fBuiltinUniformHandles.fRTDimensionsUni, SkIntToScalar(rt->width()),
SkIntToScalar(rt->height()));
if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
fRenderTargetState.fRenderTargetSize.fHeight != rt->height()) {
fDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, SkIntToScalar(rt->height()));
}
// set RT adjustment

View File

@ -70,8 +70,8 @@ id<MTLLibrary> GrMtlPipelineStateBuilder::createMtlShaderLibrary(
if (shaderLibrary == nil) {
return nil;
}
if (inputs.fRTDimensions) {
this->addRTDimensionsUniform(SKSL_RTDIMENSIONS_NAME);
if (inputs.fRTHeight) {
this->addRTHeightUniform(SKSL_RTHEIGHT_NAME);
}
if (inputs.fFlipY) {
desc->setSurfaceOriginKey(GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(

View File

@ -350,11 +350,9 @@ void GrVkPipelineState::setRenderTargetState(const GrRenderTargetProxy* proxy) {
GrRenderTarget* rt = proxy->peekRenderTarget();
// Load the RT height uniform if it is needed to y-flip gl_FragCoord.
if (fBuiltinUniformHandles.fRTDimensionsUni.isValid() &&
(fRenderTargetState.fRenderTargetSize.fWidth != rt->width() ||
fRenderTargetState.fRenderTargetSize.fHeight != rt->height())) {
fDataManager.set2f(fBuiltinUniformHandles.fRTDimensionsUni, SkIntToScalar(rt->height()),
SkIntToScalar(rt->width()));
if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
fRenderTargetState.fRenderTargetSize.fHeight != rt->height()) {
fDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, SkIntToScalar(rt->height()));
}
// set RT adjustment

View File

@ -75,8 +75,8 @@ bool GrVkPipelineStateBuilder::createVkShaderModule(VkShaderStageFlagBits stage,
if (!result) {
return false;
}
if (inputs.fRTDimensions) {
this->addRTDimensionsUniform(SKSL_RTDIMENSIONS_NAME);
if (inputs.fRTHeight) {
this->addRTHeightUniform(SKSL_RTHEIGHT_NAME);
}
if (inputs.fFlipY) {
desc->setSurfaceOriginKey(GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(

View File

@ -57,7 +57,6 @@ Differences from GLSL
Use swizzles instead.
* Use texture() instead of textureProj(), e.g. texture(sampler2D, float3) is
equivalent to GLSL's textureProj(sampler2D, float3)
* Render target dimensions are available via sk_Dimensions
* some built-in functions and one or two rarely-used language features are not
yet supported (sorry!)

View File

@ -246,9 +246,6 @@ void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) {
this->write("%s");
fFormatArgs.push_back(String("args.fOutputColor"));
break;
case SK_DIMENSIONS_BUILTIN:
this->write("sk_Dimensions");
break;
default:
if (ref.fVariable.fType.kind() == Type::kSampler_Kind) {
this->write("%s");
@ -449,9 +446,6 @@ void CPPCodeGenerator::addUniform(const Variable& var) {
}
}
void CPPCodeGenerator::writeInputVars() {
}
void CPPCodeGenerator::writePrivateVars() {
for (const auto& p : fProgram) {
if (ProgramElement::kVar_Kind == p.fKind) {

View File

@ -68,8 +68,6 @@ private:
void writeVarInitializer(const Variable& var, const Expression& value) override;
void writeInputVars() override;
void writePrivateVars();
void writePrivateVarValues();

View File

@ -28,7 +28,6 @@
#define SK_LASTFRAGCOLOR_BUILTIN 10008
#define SK_MAIN_X_BUILTIN 10009
#define SK_MAIN_Y_BUILTIN 10010
#define SK_DIMENSIONS_BUILTIN 10011
#define SK_FRAGCOORD_BUILTIN 15
#define SK_CLOCKWISE_BUILTIN 17
#define SK_VERTEXID_BUILTIN 42

View File

@ -693,7 +693,7 @@ void GLSLCodeGenerator::writeFragCoord() {
if (!fProgram.fSettings.fFlipY) {
this->write("gl_FragCoord");
} else if (const char* extension =
fProgram.fSettings.fCaps->fragCoordConventionsExtensionString()) {
fProgram.fSettings.fCaps->fragCoordConventionsExtensionString()) {
if (!fSetupFragPositionGlobal) {
if (fProgram.fSettings.fCaps->generation() < k150_GrGLSLGeneration) {
this->writeExtension(extension);
@ -703,18 +703,25 @@ void GLSLCodeGenerator::writeFragCoord() {
}
this->write("gl_FragCoord");
} else {
if (!fSetupFragPositionLocal) {
if (!fSetupFragPositionGlobal) {
// The Adreno compiler seems to be very touchy about access to "gl_FragCoord".
// Accessing glFragCoord.zw can cause a program to fail to link. Additionally,
// depending on the surrounding code, accessing .xy with a uniform involved can
// do the same thing. Copying gl_FragCoord.xy into a temp float2 beforehand
// (and only accessing .xy) seems to "fix" things.
const char* precision = usesPrecisionModifiers() ? "highp " : "";
fGlobals.writeText("uniform ");
fGlobals.writeText(precision);
fGlobals.writeText("float " SKSL_RTHEIGHT_NAME ";\n");
fSetupFragPositionGlobal = true;
}
if (!fSetupFragPositionLocal) {
const char* precision = usesPrecisionModifiers() ? "highp " : "";
fFunctionHeader += precision;
fFunctionHeader += " vec2 _sktmpCoord = gl_FragCoord.xy;\n";
fFunctionHeader += precision;
fFunctionHeader += " vec4 sk_FragCoord = vec4(_sktmpCoord.x, " SKSL_RTDIMENSIONS_NAME
".y - _sktmpCoord.y, 1.0, 1.0);\n";
fFunctionHeader += " vec4 sk_FragCoord = vec4(_sktmpCoord.x, " SKSL_RTHEIGHT_NAME
" - _sktmpCoord.y, 1.0, 1.0);\n";
fSetupFragPositionLocal = true;
}
this->write("sk_FragCoord");
@ -733,9 +740,6 @@ void GLSLCodeGenerator::writeVariableReference(const VariableReference& ref) {
case SK_FRAGCOORD_BUILTIN:
this->writeFragCoord();
break;
case SK_DIMENSIONS_BUILTIN:
this->write("u_skRTDimensions");
break;
case SK_CLOCKWISE_BUILTIN:
this->write(fProgram.fSettings.fFlipY ? "(!gl_FrontFacing)" : "gl_FrontFacing");
break;
@ -1373,15 +1377,6 @@ void GLSLCodeGenerator::writeProgramElement(const ProgramElement& e) {
}
}
void GLSLCodeGenerator::writeInputVars() {
if (fProgram.fInputs.fRTDimensions) {
const char* precision = usesPrecisionModifiers() ? "highp " : "";
fGlobals.writeText("uniform ");
fGlobals.writeText(precision);
fGlobals.writeText("vec2 " SKSL_RTDIMENSIONS_NAME ";\n");
}
}
bool GLSLCodeGenerator::generateCode() {
fProgramKind = fProgram.fKind;
if (fProgramKind != Program::kPipelineStage_Kind) {
@ -1400,7 +1395,6 @@ bool GLSLCodeGenerator::generateCode() {
fOut = rawOut;
write_stringstream(fExtensions, *rawOut);
this->writeInputVars();
write_stringstream(fGlobals, *rawOut);
if (!fProgram.fSettings.fCaps->canUseFragCoord()) {

View File

@ -118,7 +118,7 @@ protected:
void writeModifiers(const Modifiers& modifiers, bool globalContext);
virtual void writeInputVars();
void writeGlobalVars(const VarDeclaration& vs);
virtual void writeVarInitializer(const Variable& var, const Expression& value);

View File

@ -1025,22 +1025,16 @@ std::unique_ptr<Expression> IRGenerator::convertIdentifier(const ASTIdentifier&
}
case Symbol::kVariable_Kind: {
const Variable* var = (const Variable*) result;
switch (var->fModifiers.fLayout.fBuiltin) {
case SK_DIMENSIONS_BUILTIN:
fInputs.fRTDimensions = true;
break;
#ifndef SKSL_STANDALONE
case SK_FRAGCOORD_BUILTIN:
if (var->fModifiers.fLayout.fBuiltin == SK_FRAGCOORD_BUILTIN) {
fInputs.fFlipY = true;
if (fSettings->fFlipY &&
(!fSettings->fCaps ||
!fSettings->fCaps->fragCoordConventionsExtensionString())) {
fInputs.fRTDimensions = true;
}
}
#endif
if (var->fModifiers.fLayout.fBuiltin == SK_FRAGCOORD_BUILTIN) {
fInputs.fFlipY = true;
if (fSettings->fFlipY &&
(!fSettings->fCaps ||
!fSettings->fCaps->fragCoordConventionsExtensionString())) {
fInputs.fRTHeight = true;
}
}
#endif
// default to kRead_RefKind; this will be corrected later if the variable is written to
return std::unique_ptr<VariableReference>(new VariableReference(
identifier.fOffset,

View File

@ -1710,48 +1710,7 @@ std::unique_ptr<SPIRVCodeGenerator::LValue> SPIRVCodeGenerator::getLValue(const
}
}
SpvId SPIRVCodeGenerator::loadDimensions(OutputStream& out) {
if (fRTDimensionsStructId == (SpvId) -1) {
// dimensions variable hasn't been written yet
std::shared_ptr<SymbolTable> st(new SymbolTable(&fErrors));
SkASSERT(fRTDimensionsFieldIndex == (SpvId) -1);
std::vector<Type::Field> fields;
fields.emplace_back(Modifiers(), SKSL_RTDIMENSIONS_NAME, fContext.fFloat2_Type.get());
StringFragment name("sksl_synthetic_uniforms");
Type intfStruct(-1, name, fields);
Layout layout(0, -1, -1, 1, -1, -1, -1, -1, Layout::Format::kUnspecified,
Layout::kUnspecified_Primitive, -1, -1, "", Layout::kNo_Key,
StringFragment());
Variable* intfVar = new Variable(-1,
Modifiers(layout, Modifiers::kUniform_Flag),
name,
intfStruct,
Variable::kGlobal_Storage);
fSynthetics.takeOwnership(intfVar);
InterfaceBlock intf(-1, intfVar, name, String(""),
std::vector<std::unique_ptr<Expression>>(), st);
fRTDimensionsStructId = this->writeInterfaceBlock(intf);
fRTDimensionsFieldIndex = 0;
}
SkASSERT(fRTDimensionsFieldIndex != (SpvId) -1);
IntLiteral fieldIndex(fContext, -1, fRTDimensionsFieldIndex);
SpvId fieldIndexId = this->writeIntLiteral(fieldIndex);
SpvId dimensionsPtr = this->nextId();
this->writeOpCode(SpvOpAccessChain, 5, out);
this->writeWord(this->getPointerType(*fContext.fFloat2_Type, SpvStorageClassUniform), out);
this->writeWord(dimensionsPtr, out);
this->writeWord(fRTDimensionsStructId, out);
this->writeWord(fieldIndexId, out);
SpvId result = this->nextId();
this->writeInstruction(SpvOpLoad, this->getType(*fContext.fFloat2_Type), result, dimensionsPtr,
out);
return result;
}
SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, OutputStream& out) {
if (ref.fVariable.fModifiers.fLayout.fBuiltin == SK_DIMENSIONS_BUILTIN) {
return this->loadDimensions(out);
}
SpvId result = this->nextId();
auto entry = fVariableMap.find(&ref.fVariable);
SkASSERT(entry != fVariableMap.end());
@ -1760,20 +1719,50 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, O
if (ref.fVariable.fModifiers.fLayout.fBuiltin == SK_FRAGCOORD_BUILTIN &&
fProgram.fSettings.fFlipY) {
// need to remap to a top-left coordinate system
// write float4(gl_FragCoord.x, u_skRTDimensions.y - gl_FragCoord.y, 0.0, 1.0)
if (fRTHeightStructId == (SpvId) -1) {
// height variable hasn't been written yet
std::shared_ptr<SymbolTable> st(new SymbolTable(&fErrors));
SkASSERT(fRTHeightFieldIndex == (SpvId) -1);
std::vector<Type::Field> fields;
fields.emplace_back(Modifiers(), SKSL_RTHEIGHT_NAME, fContext.fFloat_Type.get());
StringFragment name("sksl_synthetic_uniforms");
Type intfStruct(-1, name, fields);
Layout layout(0, -1, -1, 1, -1, -1, -1, -1, Layout::Format::kUnspecified,
Layout::kUnspecified_Primitive, -1, -1, "", Layout::kNo_Key,
StringFragment());
Variable* intfVar = new Variable(-1,
Modifiers(layout, Modifiers::kUniform_Flag),
name,
intfStruct,
Variable::kGlobal_Storage);
fSynthetics.takeOwnership(intfVar);
InterfaceBlock intf(-1, intfVar, name, String(""),
std::vector<std::unique_ptr<Expression>>(), st);
fRTHeightStructId = this->writeInterfaceBlock(intf);
fRTHeightFieldIndex = 0;
}
SkASSERT(fRTHeightFieldIndex != (SpvId) -1);
// write float4(gl_FragCoord.x, u_skRTHeight - gl_FragCoord.y, 0.0, 1.0)
SpvId xId = this->nextId();
this->writeInstruction(SpvOpCompositeExtract, this->getType(*fContext.fFloat_Type), xId,
result, 0, out);
SpvId dimensions = this->loadDimensions(out);
SpvId height = this->nextId();
this->writeInstruction(SpvOpCompositeExtract, this->getType(*fContext.fFloat_Type), height,
dimensions, 1, out);
IntLiteral fieldIndex(fContext, -1, fRTHeightFieldIndex);
SpvId fieldIndexId = this->writeIntLiteral(fieldIndex);
SpvId heightPtr = this->nextId();
this->writeOpCode(SpvOpAccessChain, 5, out);
this->writeWord(this->getPointerType(*fContext.fFloat_Type, SpvStorageClassUniform), out);
this->writeWord(heightPtr, out);
this->writeWord(fRTHeightStructId, out);
this->writeWord(fieldIndexId, out);
SpvId heightRead = this->nextId();
this->writeInstruction(SpvOpLoad, this->getType(*fContext.fFloat_Type), heightRead,
heightPtr, out);
SpvId rawYId = this->nextId();
this->writeInstruction(SpvOpCompositeExtract, this->getType(*fContext.fFloat_Type), rawYId,
result, 1, out);
SpvId flippedYId = this->nextId();
this->writeInstruction(SpvOpFSub, this->getType(*fContext.fFloat_Type), flippedYId,
height, rawYId, out);
heightRead, rawYId, out);
FloatLiteral zero(fContext, -1, 0.0);
SpvId zeroId = writeFloatLiteral(zero);
FloatLiteral one(fContext, -1, 1.0);
@ -2562,8 +2551,7 @@ void SPIRVCodeGenerator::writeLayout(const Layout& layout, SpvId target) {
fCapabilities |= (((uint64_t) 1) << SpvCapabilityInputAttachment);
}
if (layout.fBuiltin >= 0 && layout.fBuiltin != SK_FRAGCOLOR_BUILTIN &&
layout.fBuiltin != SK_IN_BUILTIN && layout.fBuiltin != SK_OUT_BUILTIN &&
layout.fBuiltin != SK_DIMENSIONS_BUILTIN) {
layout.fBuiltin != SK_IN_BUILTIN && layout.fBuiltin != SK_OUT_BUILTIN) {
this->writeInstruction(SpvOpDecorate, target, SpvDecorationBuiltIn, layout.fBuiltin,
fDecorationBuffer);
}
@ -2627,14 +2615,13 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
fDefaultLayout;
SpvId result = this->nextId();
const Type* type = &intf.fVariable.fType;
if (fProgram.fInputs.fRTDimensions) {
SkASSERT(fRTDimensionsStructId == (SpvId) -1);
SkASSERT(fRTDimensionsFieldIndex == (SpvId) -1);
if (fProgram.fInputs.fRTHeight) {
SkASSERT(fRTHeightStructId == (SpvId) -1);
SkASSERT(fRTHeightFieldIndex == (SpvId) -1);
std::vector<Type::Field> fields = type->fields();
fRTDimensionsStructId = result;
fRTDimensionsFieldIndex = fields.size();
fields.emplace_back(Modifiers(), StringFragment(SKSL_RTDIMENSIONS_NAME),
fContext.fFloat2_Type.get());
fRTHeightStructId = result;
fRTHeightFieldIndex = fields.size();
fields.emplace_back(Modifiers(), StringFragment(SKSL_RTHEIGHT_NAME), fContext.fFloat_Type.get());
type = new Type(type->fOffset, type->name(), fields);
}
SpvId typeId;
@ -2665,7 +2652,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
}
this->writeLayout(layout, result);
fVariableMap[&intf.fVariable] = result;
if (fProgram.fInputs.fRTDimensions) {
if (fProgram.fInputs.fRTHeight) {
delete type;
}
return result;

View File

@ -143,8 +143,6 @@ private:
void writeVarDeclarations(const VarDeclarations& decl, OutputStream& out);
SpvId loadDimensions(OutputStream& out);
SpvId writeVariableReference(const VariableReference& ref, OutputStream& out);
std::unique_ptr<LValue> getLValue(const Expression& value, OutputStream& out);
@ -343,8 +341,8 @@ private:
SpvId fCurrentBlock;
std::stack<SpvId> fBreakTarget;
std::stack<SpvId> fContinueTarget;
SpvId fRTDimensionsStructId = (SpvId) -1;
SpvId fRTDimensionsFieldIndex = (SpvId) -1;
SpvId fRTHeightStructId = (SpvId) -1;
SpvId fRTHeightFieldIndex = (SpvId) -1;
// holds variables synthesized during output, for lifetime purposes
SymbolTable fSynthetics;
int fSkInCount = 1;

View File

@ -18,8 +18,8 @@
#include "SkSLProgramElement.h"
#include "SkSLSymbolTable.h"
// name of the render target dimensions uniform
#define SKSL_RTDIMENSIONS_NAME "u_skRTDimensions"
// name of the render target height uniform
#define SKSL_RTHEIGHT_NAME "u_skRTHeight"
namespace SkSL {
@ -88,20 +88,20 @@ struct Program {
};
struct Inputs {
// if true, this program requires the render target dimensions uniform to be defined
bool fRTDimensions;
// if true, this program requires the render target height uniform to be defined
bool fRTHeight;
// if true, this program must be recompiled if the flipY setting changes. If false, the
// program will compile to the same code regardless of the flipY setting.
bool fFlipY;
void reset() {
fRTDimensions = false;
fRTHeight = false;
fFlipY = false;
}
bool isEmpty() {
return !fRTDimensions && !fFlipY;
return !fRTHeight && !fFlipY;
}
};

View File

@ -20,8 +20,6 @@ layout(builtin=10003) half4 sk_InColor;
layout(builtin=10004) out half4 sk_OutColor;
layout(builtin=10005) float2[] sk_TransformedCoords2D;
layout(builtin=10006) sampler2D[] sk_TextureSamplers;
layout(builtin=10011) float2 sk_Dimensions;
half4 process(fragmentProcessor fp);
)

View File

@ -17,6 +17,5 @@ layout(builtin=9999) out half4 gl_SecondaryFragColorEXT;
layout(location=0,index=0,builtin=10001) out half4 sk_FragColor;
layout(builtin=10008) half4 sk_LastFragColor;
layout(builtin=10011) float2 sk_Dimensions;
)

View File

@ -1070,7 +1070,7 @@ DEF_TEST(SkSLFragCoord, r) {
" gl_FragColor.xy = gl_FragCoord.xy;\n"
"}\n",
&inputs);
REPORTER_ASSERT(r, !inputs.fRTDimensions);
REPORTER_ASSERT(r, !inputs.fRTHeight);
caps = SkSL::ShaderCapsFactory::FragCoordsNew();
settings.fCaps = caps.get();
@ -1084,7 +1084,7 @@ DEF_TEST(SkSLFragCoord, r) {
" sk_FragColor.xy = gl_FragCoord.xy;\n"
"}\n",
&inputs);
REPORTER_ASSERT(r, !inputs.fRTDimensions);
REPORTER_ASSERT(r, !inputs.fRTHeight);
caps = SkSL::ShaderCapsFactory::Default();
settings.fCaps = caps.get();
@ -1092,16 +1092,15 @@ DEF_TEST(SkSLFragCoord, r) {
"void main() { sk_FragColor.xy = sk_FragCoord.xy; }",
settings,
"#version 400\n"
"uniform vec2 u_skRTDimensions;\n"
"uniform float u_skRTHeight;\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" vec2 _sktmpCoord = gl_FragCoord.xy;\n"
" vec4 sk_FragCoord = vec4(_sktmpCoord.x, u_skRTDimensions.y - _sktmpCoord.y, 1.0,"
" 1.0);\n"
" vec4 sk_FragCoord = vec4(_sktmpCoord.x, u_skRTHeight - _sktmpCoord.y, 1.0, 1.0);\n"
" sk_FragColor.xy = sk_FragCoord.xy;\n"
"}\n",
&inputs);
REPORTER_ASSERT(r, inputs.fRTDimensions);
REPORTER_ASSERT(r, inputs.fRTHeight);
settings.fFlipY = false;
test(r,
@ -1113,7 +1112,7 @@ DEF_TEST(SkSLFragCoord, r) {
" sk_FragColor.xy = gl_FragCoord.xy;\n"
"}\n",
&inputs);
REPORTER_ASSERT(r, !inputs.fRTDimensions);
REPORTER_ASSERT(r, !inputs.fRTHeight);
test(r,
"in float4 pos; void main() { sk_Position = pos; }",
@ -1155,24 +1154,6 @@ DEF_TEST(SkSLFragCoord, r) {
"}\n");
}
DEF_TEST(SkSLDimensions, r) {
SkSL::Program::Settings settings;
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
settings.fCaps = caps.get();
SkSL::Program::Inputs inputs;
test(r,
"void main() { sk_FragColor.r = sk_FragCoord.x / sk_Dimensions.x; }",
settings,
"#version 400\n"
"uniform vec2 u_skRTDimensions;\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" sk_FragColor.x = gl_FragCoord.x / u_skRTDimensions.x;\n"
"}\n",
&inputs);
REPORTER_ASSERT(r, inputs.fRTDimensions);
}
DEF_TEST(SkSLClockwise, r) {
test(r,
"void main() { sk_FragColor = half4(sk_Clockwise ? +1 : -1); }",