Add addFragPosUniform to GrGLrogramBuilder
BUG=skia: Review URL: https://codereview.chromium.org/1434483002
This commit is contained in:
parent
cf1d19805a
commit
f3bace9392
@ -143,17 +143,15 @@ const char* GrGLFragmentShaderBuilder::fragmentPosition() {
|
|||||||
static const char* kTempName = "tmpXYFragCoord";
|
static const char* kTempName = "tmpXYFragCoord";
|
||||||
static const char* kCoordName = "fragCoordYDown";
|
static const char* kCoordName = "fragCoordYDown";
|
||||||
if (!fSetupFragPosition) {
|
if (!fSetupFragPosition) {
|
||||||
// temporarily change the stage index because we're inserting non-stage code.
|
|
||||||
GrGLProgramBuilder::AutoStageRestore asr(fProgramBuilder);
|
|
||||||
SkASSERT(!fProgramBuilder->fUniformHandles.fRTHeightUni.isValid());
|
SkASSERT(!fProgramBuilder->fUniformHandles.fRTHeightUni.isValid());
|
||||||
const char* rtHeightName;
|
const char* rtHeightName;
|
||||||
|
|
||||||
fProgramBuilder->fUniformHandles.fRTHeightUni =
|
fProgramBuilder->fUniformHandles.fRTHeightUni =
|
||||||
fProgramBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
|
fProgramBuilder->addFragPosUniform(GrGLProgramBuilder::kFragment_Visibility,
|
||||||
kFloat_GrSLType,
|
kFloat_GrSLType,
|
||||||
kDefault_GrSLPrecision,
|
kDefault_GrSLPrecision,
|
||||||
"RTHeight",
|
"RTHeight",
|
||||||
&rtHeightName);
|
&rtHeightName);
|
||||||
|
|
||||||
// The Adreno compiler seems to be very touchy about access to "gl_FragCoord".
|
// 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,
|
// Accessing glFragCoord.zw can cause a program to fail to link. Additionally,
|
||||||
|
@ -56,7 +56,6 @@ GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args)
|
|||||||
: fVS(this)
|
: fVS(this)
|
||||||
, fGS(this)
|
, fGS(this)
|
||||||
, fFS(this, args.fDesc->header().fFragPosKey)
|
, fFS(this, args.fDesc->header().fFragPosKey)
|
||||||
, fOutOfStage(true)
|
|
||||||
, fStageIndex(-1)
|
, fStageIndex(-1)
|
||||||
, fGeometryProcessor(nullptr)
|
, fGeometryProcessor(nullptr)
|
||||||
, fXferProcessor(nullptr)
|
, fXferProcessor(nullptr)
|
||||||
@ -107,13 +106,13 @@ GrGLProgramBuilder::SeparableVaryingHandle GrGLProgramBuilder::addSeparableVaryi
|
|||||||
return SeparableVaryingHandle(varyingInfo.fLocation);
|
return SeparableVaryingHandle(varyingInfo.fLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* name) {
|
void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* name, bool mangle) {
|
||||||
if ('\0' == prefix) {
|
if ('\0' == prefix) {
|
||||||
*out = name;
|
*out = name;
|
||||||
} else {
|
} else {
|
||||||
out->printf("%c%s", prefix, name);
|
out->printf("%c%s", prefix, name);
|
||||||
}
|
}
|
||||||
if (!fOutOfStage) {
|
if (mangle) {
|
||||||
if (out->endsWith('_')) {
|
if (out->endsWith('_')) {
|
||||||
// Names containing "__" are reserved.
|
// Names containing "__" are reserved.
|
||||||
out->append("x");
|
out->append("x");
|
||||||
@ -122,11 +121,12 @@ void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* na
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::addUniformArray(
|
GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::internalAddUniformArray(
|
||||||
uint32_t visibility,
|
uint32_t visibility,
|
||||||
GrSLType type,
|
GrSLType type,
|
||||||
GrSLPrecision precision,
|
GrSLPrecision precision,
|
||||||
const char* name,
|
const char* name,
|
||||||
|
bool mangleName,
|
||||||
int count,
|
int count,
|
||||||
const char** outName) {
|
const char** outName) {
|
||||||
SkASSERT(name && strlen(name));
|
SkASSERT(name && strlen(name));
|
||||||
@ -148,7 +148,7 @@ GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::addUniformArray(
|
|||||||
if ('u' == name[0]) {
|
if ('u' == name[0]) {
|
||||||
prefix = '\0';
|
prefix = '\0';
|
||||||
}
|
}
|
||||||
this->nameVariable(uni.fVariable.accessName(), prefix, name);
|
this->nameVariable(uni.fVariable.accessName(), prefix, name, mangleName);
|
||||||
uni.fVariable.setArrayCount(count);
|
uni.fVariable.setArrayCount(count);
|
||||||
uni.fVisibility = visibility;
|
uni.fVisibility = visibility;
|
||||||
uni.fVariable.setPrecision(precision);
|
uni.fVariable.setPrecision(precision);
|
||||||
|
@ -68,7 +68,11 @@ public:
|
|||||||
GrSLPrecision precision,
|
GrSLPrecision precision,
|
||||||
const char* name,
|
const char* name,
|
||||||
int arrayCount,
|
int arrayCount,
|
||||||
const char** outName = nullptr) = 0;
|
const char** outName = nullptr) {
|
||||||
|
return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
|
||||||
|
outName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0;
|
virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0;
|
||||||
|
|
||||||
@ -86,6 +90,15 @@ public:
|
|||||||
/*
|
/*
|
||||||
* *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
|
* *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
|
||||||
*/
|
*/
|
||||||
|
private:
|
||||||
|
virtual UniformHandle internalAddUniformArray(
|
||||||
|
uint32_t visibility,
|
||||||
|
GrSLType type,
|
||||||
|
GrSLPrecision precision,
|
||||||
|
const char* name,
|
||||||
|
bool mangleName,
|
||||||
|
int arrayCount,
|
||||||
|
const char** outName) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO move this into GrGLGPBuilder and move them both out of this file
|
// TODO move this into GrGLGPBuilder and move them both out of this file
|
||||||
@ -239,13 +252,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*);
|
static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*);
|
||||||
|
|
||||||
UniformHandle addUniformArray(uint32_t visibility,
|
|
||||||
GrSLType type,
|
|
||||||
GrSLPrecision precision,
|
|
||||||
const char* name,
|
|
||||||
int arrayCount,
|
|
||||||
const char** outName) override;
|
|
||||||
|
|
||||||
const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override {
|
const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override {
|
||||||
return fUniforms[u.toIndex()].fVariable;
|
return fUniforms[u.toIndex()].fVariable;
|
||||||
}
|
}
|
||||||
@ -298,10 +304,29 @@ protected:
|
|||||||
const GrProgramDesc& desc() const { return *fArgs.fDesc; }
|
const GrProgramDesc& desc() const { return *fArgs.fDesc; }
|
||||||
const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(); }
|
const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(); }
|
||||||
|
|
||||||
|
UniformHandle internalAddUniformArray(uint32_t visibility,
|
||||||
|
GrSLType type,
|
||||||
|
GrSLPrecision precision,
|
||||||
|
const char* name,
|
||||||
|
bool mangleName,
|
||||||
|
int arrayCount,
|
||||||
|
const char** outName) override;
|
||||||
|
|
||||||
|
// Used to add a uniform for frag position without mangling the name of the uniform inside of a
|
||||||
|
// stage.
|
||||||
|
UniformHandle addFragPosUniform(uint32_t visibility,
|
||||||
|
GrSLType type,
|
||||||
|
GrSLPrecision precision,
|
||||||
|
const char* name,
|
||||||
|
const char** outName) {
|
||||||
|
SkDebugf("in my frag pos thing\n");
|
||||||
|
return this->internalAddUniformArray(visibility, type, precision, name, false, 0, outName);
|
||||||
|
}
|
||||||
|
|
||||||
// Generates a name for a variable. The generated string will be name prefixed by the prefix
|
// Generates a name for a variable. The generated string will be name prefixed by the prefix
|
||||||
// char (unless the prefix is '\0'). It also mangles the name to be stage-specific if we're
|
// char (unless the prefix is '\0'). It also will mangle the name to be stage-specific unless
|
||||||
// generating stage code.
|
// explicitly asked not to.
|
||||||
void nameVariable(SkString* out, char prefix, const char* name);
|
void nameVariable(SkString* out, char prefix, const char* name, bool mangle = true);
|
||||||
// Generates a possibly mangled name for a stage variable and writes it to the fragment shader.
|
// Generates a possibly mangled name for a stage variable and writes it to the fragment shader.
|
||||||
// If GrGLSLExpr4 has a valid name then it will use that instead
|
// If GrGLSLExpr4 has a valid name then it will use that instead
|
||||||
void nameExpression(GrGLSLExpr4*, const char* baseName);
|
void nameExpression(GrGLSLExpr4*, const char* baseName);
|
||||||
@ -356,22 +381,11 @@ protected:
|
|||||||
// stage offset for variable name mangling, and also ensures verfication variables in the
|
// stage offset for variable name mangling, and also ensures verfication variables in the
|
||||||
// fragment shader are cleared.
|
// fragment shader are cleared.
|
||||||
void reset() {
|
void reset() {
|
||||||
this->enterStage();
|
|
||||||
this->addStage();
|
this->addStage();
|
||||||
fFS.reset();
|
fFS.reset();
|
||||||
}
|
}
|
||||||
void addStage() { fStageIndex++; }
|
void addStage() { fStageIndex++; }
|
||||||
|
|
||||||
// This simple class exits the stage and then restores the stage when it goes out of scope
|
|
||||||
class AutoStageRestore {
|
|
||||||
public:
|
|
||||||
AutoStageRestore(GrGLProgramBuilder* pb)
|
|
||||||
: fPB(pb), fOutOfStage(pb->fOutOfStage) { pb->exitStage(); }
|
|
||||||
~AutoStageRestore() { fPB->fOutOfStage = fOutOfStage; }
|
|
||||||
private:
|
|
||||||
GrGLProgramBuilder* fPB;
|
|
||||||
bool fOutOfStage;
|
|
||||||
};
|
|
||||||
class AutoStageAdvance {
|
class AutoStageAdvance {
|
||||||
public:
|
public:
|
||||||
AutoStageAdvance(GrGLProgramBuilder* pb)
|
AutoStageAdvance(GrGLProgramBuilder* pb)
|
||||||
@ -380,12 +394,10 @@ protected:
|
|||||||
// Each output to the fragment processor gets its own code section
|
// Each output to the fragment processor gets its own code section
|
||||||
fPB->fFS.nextStage();
|
fPB->fFS.nextStage();
|
||||||
}
|
}
|
||||||
~AutoStageAdvance() { fPB->exitStage(); }
|
~AutoStageAdvance() {}
|
||||||
private:
|
private:
|
||||||
GrGLProgramBuilder* fPB;
|
GrGLProgramBuilder* fPB;
|
||||||
};
|
};
|
||||||
void exitStage() { fOutOfStage = true; }
|
|
||||||
void enterStage() { fOutOfStage = false; }
|
|
||||||
int stageIndex() const { return fStageIndex; }
|
int stageIndex() const { return fStageIndex; }
|
||||||
|
|
||||||
const char* rtAdjustment() const { return "rtAdjustment"; }
|
const char* rtAdjustment() const { return "rtAdjustment"; }
|
||||||
@ -397,7 +409,6 @@ protected:
|
|||||||
GrGLVertexBuilder fVS;
|
GrGLVertexBuilder fVS;
|
||||||
GrGLGeometryBuilder fGS;
|
GrGLGeometryBuilder fGS;
|
||||||
GrGLFragmentShaderBuilder fFS;
|
GrGLFragmentShaderBuilder fFS;
|
||||||
bool fOutOfStage;
|
|
||||||
int fStageIndex;
|
int fStageIndex;
|
||||||
|
|
||||||
GrGLInstalledGeoProc* fGeometryProcessor;
|
GrGLInstalledGeoProc* fGeometryProcessor;
|
||||||
|
Loading…
Reference in New Issue
Block a user