aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r--src/gpu/glsl/GrGLSL.h4
-rw-r--r--src/gpu/glsl/GrGLSLFragmentProcessor.cpp16
-rw-r--r--src/gpu/glsl/GrGLSLFragmentProcessor.h7
-rw-r--r--src/gpu/glsl/GrGLSLPrimitiveProcessor.h3
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.cpp84
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.h9
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.h1
-rw-r--r--src/gpu/glsl/GrGLSLXferProcessor.h3
8 files changed, 92 insertions, 35 deletions
diff --git a/src/gpu/glsl/GrGLSL.h b/src/gpu/glsl/GrGLSL.h
index 9f5f2b05b4..844b7c76db 100644
--- a/src/gpu/glsl/GrGLSL.h
+++ b/src/gpu/glsl/GrGLSL.h
@@ -58,7 +58,7 @@ bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration);
*/
inline const char* GrGLSLTexture2DFunctionName(GrSLType coordType, GrSLType samplerType,
GrGLSLGeneration glslGen) {
- SkASSERT(GrSLTypeIsSamplerType(samplerType));
+ SkASSERT(GrSLTypeIs2DTextureType(samplerType));
SkASSERT(kVec2f_GrSLType == coordType || kVec3f_GrSLType == coordType);
// GL_TEXTURE_RECTANGLE_ARB is written against OpenGL 2.0/GLSL 1.10. At that time there were
// separate texture*() functions. In OpenGL 3.0/GLSL 1.30 the different texture*() functions
@@ -127,6 +127,8 @@ static inline const char* GrGLSLTypeString(GrSLType t) {
return "samplerExternalOES";
case kSampler2DRect_GrSLType:
return "sampler2DRect";
+ case kSamplerBuffer_GrSLType:
+ return "samplerBuffer";
case kBool_GrSLType:
return "bool";
case kInt_GrSLType:
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
index c3e57bc314..42538eaf0f 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
@@ -75,18 +75,25 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu
* Textures work the same way as transforms.
*/
int firstCoordAt = args.fFp.numTransformsExclChildren();
- int firstSamplerAt = args.fFp.numTexturesExclChildren();
+ int firstTextureAt = args.fFp.numTexturesExclChildren();
+ int firstBufferAt = args.fFp.numBuffersExclChildren();
for (int i = 0; i < childIndex; ++i) {
firstCoordAt += args.fFp.childProcessor(i).numTransforms();
- firstSamplerAt += args.fFp.childProcessor(i).numTextures();
+ firstTextureAt += args.fFp.childProcessor(i).numTextures();
+ firstBufferAt += args.fFp.childProcessor(i).numBuffers();
}
GrGLSLTransformedCoordsArray childCoords;
SamplerArray childTexSamplers;
+ SamplerArray childBufferSamplers;
if (childProc.numTransforms() > 0) {
childCoords.push_back_n(childProc.numTransforms(), &args.fCoords[firstCoordAt]);
}
if (childProc.numTextures() > 0) {
- childTexSamplers.push_back_n(childProc.numTextures(), &args.fTexSamplers[firstSamplerAt]);
+ childTexSamplers.push_back_n(childProc.numTextures(), &args.fTexSamplers[firstTextureAt]);
+ }
+ if (childProc.numBuffers() > 0) {
+ childBufferSamplers.push_back_n(childProc.numBuffers(),
+ &args.fBufferSamplers[firstBufferAt]);
}
// emit the code for the child in its own scope
@@ -100,7 +107,8 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu
outputColor,
inputColor,
childCoords,
- childTexSamplers);
+ childTexSamplers,
+ childBufferSamplers);
this->childProcessor(childIndex)->emitCode(childArgs);
fragBuilder->codeAppend("}\n");
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h
index 5c71340a1c..9fc4a8c436 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.h
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h
@@ -60,7 +60,8 @@ public:
const char* outputColor,
const char* inputColor,
const GrGLSLTransformedCoordsArray& coords,
- const SamplerArray& texSamplers)
+ const SamplerArray& texSamplers,
+ const SamplerArray& bufferSamplers)
: fFragBuilder(fragBuilder)
, fUniformHandler(uniformHandler)
, fGLSLCaps(caps)
@@ -68,7 +69,8 @@ public:
, fOutputColor(outputColor)
, fInputColor(inputColor)
, fCoords(coords)
- , fTexSamplers(texSamplers) {}
+ , fTexSamplers(texSamplers)
+ , fBufferSamplers(bufferSamplers) {}
GrGLSLFPFragmentBuilder* fFragBuilder;
GrGLSLUniformHandler* fUniformHandler;
const GrGLSLCaps* fGLSLCaps;
@@ -77,6 +79,7 @@ public:
const char* fInputColor;
const GrGLSLTransformedCoordsArray& fCoords;
const SamplerArray& fTexSamplers;
+ const SamplerArray& fBufferSamplers;
};
virtual void emitCode(EmitArgs&) = 0;
diff --git a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h
index fc0c4788b5..4bd5fefd9f 100644
--- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h
+++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h
@@ -43,6 +43,7 @@ public:
const char* outputColor,
const char* outputCoverage,
const SamplerArray& texSamplers,
+ const SamplerArray& bufferSamplers,
const TransformsIn& transformsIn,
TransformsOut* transformsOut)
: fVertBuilder(vertBuilder)
@@ -54,6 +55,7 @@ public:
, fOutputColor(outputColor)
, fOutputCoverage(outputCoverage)
, fTexSamplers(texSamplers)
+ , fBufferSamplers(bufferSamplers)
, fTransformsIn(transformsIn)
, fTransformsOut(transformsOut) {}
GrGLSLVertexBuilder* fVertBuilder;
@@ -65,6 +67,7 @@ public:
const char* fOutputColor;
const char* fOutputCoverage;
const SamplerArray& fTexSamplers;
+ const SamplerArray& fBufferSamplers;
const TransformsIn& fTransformsIn;
TransformsOut* fTransformsOut;
};
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index ccb078b144..88ef5b9245 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -98,7 +98,8 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps());
SkSTArray<4, GrGLSLSampler> texSamplers(proc.numTextures());
- this->emitSamplers(proc, &texSamplers);
+ SkSTArray<2, GrGLSLSampler> bufferSamplers(proc.numBuffers());
+ this->emitSamplers(proc, &texSamplers, &bufferSamplers);
GrGLSLGeometryProcessor::EmitArgs args(&fVS,
&fFS,
@@ -109,6 +110,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
outputColor->c_str(),
outputCoverage->c_str(),
texSamplers,
+ bufferSamplers,
fCoordTransforms,
&fOutCoords);
fGeometryProcessor->emitCode(args);
@@ -149,7 +151,8 @@ void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance();
SkSTArray<4, GrGLSLSampler> texSamplers(fp.numTextures());
- this->emitSamplers(fp, &texSamplers);
+ SkSTArray<2, GrGLSLSampler> bufferSamplers(fp.numBuffers());
+ this->emitSamplers(fp, &texSamplers, &bufferSamplers);
GrGLSLFragmentProcessor::EmitArgs args(&fFS,
this->uniformHandler(),
@@ -158,7 +161,8 @@ void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
output->c_str(),
input.isOnes() ? nullptr : input.c_str(),
fOutCoords[index],
- texSamplers);
+ texSamplers,
+ bufferSamplers);
fragProc->emitCode(args);
// We have to check that effects and the code they emit are consistent, ie if an effect
@@ -194,7 +198,8 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp,
fFS.codeAppend(openBrace.c_str());
SkSTArray<4, GrGLSLSampler> texSamplers(xp.numTextures());
- this->emitSamplers(xp, &texSamplers);
+ SkSTArray<2, GrGLSLSampler> bufferSamplers(xp.numBuffers());
+ this->emitSamplers(xp, &texSamplers, &bufferSamplers);
bool usePLSDstRead = (plsState == GrPixelLocalStorageState::kFinish_GrPixelLocalStorageState);
GrGLSLXferProcessor::EmitArgs args(&fFS,
@@ -205,6 +210,7 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp,
fFS.getPrimaryColorOutputName(),
fFS.getSecondaryColorOutputName(),
texSamplers,
+ bufferSamplers,
usePLSDstRead);
fXferProcessor->emitCode(args);
@@ -215,41 +221,65 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp,
}
void GrGLSLProgramBuilder::emitSamplers(const GrProcessor& processor,
- GrGLSLSampler::SamplerArray* outTexSamplers) {
- int numTextures = processor.numTextures();
- UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextures);
+ GrGLSLSampler::SamplerArray* outTexSamplers,
+ GrGLSLSampler::SamplerArray* outBufferSamplers) {
SkString name;
+ int numTextures = processor.numTextures();
for (int t = 0; t < numTextures; ++t) {
const GrTextureAccess& access = processor.textureAccess(t);
- GrShaderFlags visibility = access.getVisibility();
- if (visibility & kVertex_GrShaderFlag) {
- ++fNumVertexSamplers;
- }
- if (visibility & kGeometry_GrShaderFlag) {
- SkASSERT(this->primitiveProcessor().willUseGeoShader());
- ++fNumGeometrySamplers;
- }
- if (visibility & kFragment_GrShaderFlag) {
- ++fNumFragmentSamplers;
- }
GrSLType samplerType = access.getTexture()->samplerType();
if (kSamplerExternal_GrSLType == samplerType) {
const char* externalFeatureString = this->glslCaps()->externalTextureExtensionString();
// We shouldn't ever create a GrGLTexture that requires external sampler type
SkASSERT(externalFeatureString);
- this->addFeature(visibility,
+ this->addFeature(access.getVisibility(),
1 << GrGLSLShaderBuilder::kExternalTexture_GLSLPrivateFeature,
externalFeatureString);
}
- GrSLPrecision precision = this->glslCaps()->samplerPrecision(access.getTexture()->config(),
- visibility);
- name.printf("Sampler%d", t);
- localSamplerUniforms[t] = this->uniformHandler()->addUniform(visibility,
- samplerType,
- precision,
- name.c_str());
- outTexSamplers->emplace_back(localSamplerUniforms[t], access.getTexture()->config());
+ name.printf("TextureSampler%d", t);
+ this->emitSampler(samplerType, access.getTexture()->config(),
+ name.c_str(), access.getVisibility(), outTexSamplers);
+ }
+
+ if (int numBuffers = processor.numBuffers()) {
+ SkASSERT(this->glslCaps()->texelBufferSupport());
+ GrShaderFlags texelBufferVisibility = kNone_GrShaderFlags;
+
+ for (int b = 0; b < numBuffers; ++b) {
+ const GrBufferAccess& access = processor.bufferAccess(b);
+ name.printf("BufferSampler%d", b);
+ this->emitSampler(kSamplerBuffer_GrSLType, access.texelConfig(), name.c_str(),
+ access.visibility(), outBufferSamplers);
+ texelBufferVisibility |= access.visibility();
+ }
+
+ if (const char* extension = this->glslCaps()->texelBufferExtensionString()) {
+ this->addFeature(texelBufferVisibility,
+ 1 << GrGLSLShaderBuilder::kTexelBuffer_GLSLPrivateFeature,
+ extension);
+ }
+ }
+}
+
+void GrGLSLProgramBuilder::emitSampler(GrSLType samplerType,
+ GrPixelConfig config,
+ const char* name,
+ GrShaderFlags visibility,
+ GrGLSLSampler::SamplerArray* outSamplers) {
+ if (visibility & kVertex_GrShaderFlag) {
+ ++fNumVertexSamplers;
+ }
+ if (visibility & kGeometry_GrShaderFlag) {
+ SkASSERT(this->primitiveProcessor().willUseGeoShader());
+ ++fNumGeometrySamplers;
+ }
+ if (visibility & kFragment_GrShaderFlag) {
+ ++fNumFragmentSamplers;
}
+ GrSLPrecision precision = this->glslCaps()->samplerPrecision(config, visibility);
+ UniformHandle u = this->uniformHandler()->addUniform(visibility, samplerType, precision, name);
+ fSamplerUniforms.push_back(u);
+ outSamplers->emplace_back(u, config);
}
void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) {
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h
index 4d253c73bf..3ce7daf349 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.h
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.h
@@ -146,7 +146,14 @@ private:
const GrGLSLExpr4& coverageIn,
bool ignoresCoverage,
GrPixelLocalStorageState plsState);
- void emitSamplers(const GrProcessor& processor, GrGLSLSampler::SamplerArray* outTexSamplers);
+ void emitSamplers(const GrProcessor& processor,
+ GrGLSLSampler::SamplerArray* outTexSamplers,
+ GrGLSLSampler::SamplerArray* outBufferSamplers);
+ void emitSampler(GrSLType samplerType,
+ GrPixelConfig,
+ const char* name,
+ GrShaderFlags visibility,
+ GrGLSLSampler::SamplerArray* outSamplers);
void emitFSOutputSwizzle(bool hasSecondaryOutput);
bool checkSamplerCounts();
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.h b/src/gpu/glsl/GrGLSLShaderBuilder.h
index c14df53915..ef7963f83a 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.h
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.h
@@ -153,6 +153,7 @@ protected:
kBlendEquationAdvanced_GLSLPrivateFeature,
kBlendFuncExtended_GLSLPrivateFeature,
kExternalTexture_GLSLPrivateFeature,
+ kTexelBuffer_GLSLPrivateFeature,
kFramebufferFetch_GLSLPrivateFeature,
kNoPerspectiveInterpolation_GLSLPrivateFeature,
kSampleVariables_GLSLPrivateFeature,
diff --git a/src/gpu/glsl/GrGLSLXferProcessor.h b/src/gpu/glsl/GrGLSLXferProcessor.h
index 3f190ce82f..adc3d41765 100644
--- a/src/gpu/glsl/GrGLSLXferProcessor.h
+++ b/src/gpu/glsl/GrGLSLXferProcessor.h
@@ -33,6 +33,7 @@ public:
const char* outputPrimary,
const char* outputSecondary,
const SamplerArray& texSamplers,
+ const SamplerArray& bufferSamplers,
const bool usePLSDstRead)
: fXPFragBuilder(fragBuilder)
, fUniformHandler(uniformHandler)
@@ -43,6 +44,7 @@ public:
, fOutputPrimary(outputPrimary)
, fOutputSecondary(outputSecondary)
, fTexSamplers(texSamplers)
+ , fBufferSamplers(bufferSamplers)
, fUsePLSDstRead(usePLSDstRead) {}
GrGLSLXPFragmentBuilder* fXPFragBuilder;
@@ -54,6 +56,7 @@ public:
const char* fOutputPrimary;
const char* fOutputSecondary;
const SamplerArray& fTexSamplers;
+ const SamplerArray& fBufferSamplers;
bool fUsePLSDstRead;
};
/**