aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/glsl')
-rwxr-xr-xsrc/gpu/glsl/GrGLSLCaps.cpp6
-rwxr-xr-xsrc/gpu/glsl/GrGLSLCaps.h12
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.cpp36
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.h16
4 files changed, 52 insertions, 18 deletions
diff --git a/src/gpu/glsl/GrGLSLCaps.cpp b/src/gpu/glsl/GrGLSLCaps.cpp
index 60bea8663a..1f4b855f5d 100755
--- a/src/gpu/glsl/GrGLSLCaps.cpp
+++ b/src/gpu/glsl/GrGLSLCaps.cpp
@@ -29,13 +29,13 @@ GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options) {
fSampleVariablesSupport = false;
fSampleMaskOverrideCoverageSupport = false;
fExternalTextureSupport = false;
- fBufferTextureSupport = false;
+ fTexelFetchSupport = false;
fVersionDeclString = nullptr;
fShaderDerivativeExtensionString = nullptr;
fFragCoordConventionsExtensionString = nullptr;
fSecondaryOutputExtensionString = nullptr;
fExternalTextureExtensionString = nullptr;
- fBufferTextureExtensionString = nullptr;
+ fTexelBufferExtensionString = nullptr;
fNoPerspectiveInterpolationExtensionString = nullptr;
fMultisampleInterpolationExtensionString = nullptr;
fSampleVariablesExtensionString = nullptr;
@@ -82,7 +82,7 @@ SkString GrGLSLCaps::dump() const {
r.appendf("Sample mask override coverage support: %s\n", (fSampleMaskOverrideCoverageSupport ?
"YES" : "NO"));
r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
- r.appendf("Buffer texture support: %s\n", (fBufferTextureSupport ? "YES" : "NO"));
+ r.appendf("texelFetch support: %s\n", (fTexelFetchSupport ? "YES" : "NO"));
r.appendf("Max VS Samplers: %d\n", fMaxVertexSamplers);
r.appendf("Max GS Samplers: %d\n", fMaxGeometrySamplers);
r.appendf("Max FS Samplers: %d\n", fMaxFragmentSamplers);
diff --git a/src/gpu/glsl/GrGLSLCaps.h b/src/gpu/glsl/GrGLSLCaps.h
index a1d458a547..d18b71ae75 100755
--- a/src/gpu/glsl/GrGLSLCaps.h
+++ b/src/gpu/glsl/GrGLSLCaps.h
@@ -66,7 +66,7 @@ public:
bool externalTextureSupport() const { return fExternalTextureSupport; }
- bool bufferTextureSupport() const { return fBufferTextureSupport; }
+ bool texelFetchSupport() const { return fTexelFetchSupport; }
AdvBlendEqInteraction advBlendEqInteraction() const { return fAdvBlendEqInteraction; }
@@ -120,9 +120,9 @@ public:
return fExternalTextureExtensionString;
}
- const char* bufferTextureExtensionString() const {
- SkASSERT(this->bufferTextureSupport());
- return fBufferTextureExtensionString;
+ const char* texelBufferExtensionString() const {
+ SkASSERT(this->texelBufferSupport());
+ return fTexelBufferExtensionString;
}
const char* noperspectiveInterpolationExtensionString() const {
@@ -194,7 +194,7 @@ private:
bool fSampleVariablesSupport : 1;
bool fSampleMaskOverrideCoverageSupport : 1;
bool fExternalTextureSupport : 1;
- bool fBufferTextureSupport : 1;
+ bool fTexelFetchSupport : 1;
// Used for specific driver bug work arounds
bool fCanUseMinAndAbsTogether : 1;
@@ -206,7 +206,7 @@ private:
const char* fFragCoordConventionsExtensionString;
const char* fSecondaryOutputExtensionString;
const char* fExternalTextureExtensionString;
- const char* fBufferTextureExtensionString;
+ const char* fTexelBufferExtensionString;
const char* fNoPerspectiveInterpolationExtensionString;
const char* fMultisampleInterpolationExtensionString;
const char* fSampleVariablesExtensionString;
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index 91a0f9b1b5..1031f84460 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -93,14 +93,7 @@ void GrGLSLShaderBuilder::appendTextureLookup(SkString* out,
coordName);
}
- // This refers to any swizzling we may need to get from some backend internal format to the
- // format used in GrPixelConfig. If this is implemented by the GrGpu object, then swizzle will
- // be rgba. For shader prettiness we omit the swizzle rather than appending ".rgba".
- const GrSwizzle& configSwizzle = glslCaps->configTextureSwizzle(sampler.config());
-
- if (configSwizzle != GrSwizzle::RGBA()) {
- out->appendf(".%s", configSwizzle.c_str());
- }
+ this->appendTextureSwizzle(out, sampler.config());
}
void GrGLSLShaderBuilder::appendTextureLookup(const GrGLSLSampler& sampler,
@@ -118,6 +111,33 @@ void GrGLSLShaderBuilder::appendTextureLookupAndModulate(const char* modulation,
this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str());
}
+void GrGLSLShaderBuilder::appendTexelFetch(SkString* out,
+ const GrGLSLSampler& sampler,
+ const char* coordExpr) const {
+ const GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler();
+ SkASSERT(fProgramBuilder->glslCaps()->texelFetchSupport());
+ SkASSERT(GrSLTypeIsSamplerType(
+ uniformHandler->getUniformVariable(sampler.fSamplerUniform).getType()));
+
+ out->appendf("texelFetch(%s, %s)",
+ uniformHandler->getUniformCStr(sampler.fSamplerUniform),
+ coordExpr);
+
+ this->appendTextureSwizzle(out, sampler.config());
+}
+
+void GrGLSLShaderBuilder::appendTexelFetch(const GrGLSLSampler& sampler, const char* coordExpr) {
+ this->appendTexelFetch(&this->code(), sampler, coordExpr);
+}
+
+void GrGLSLShaderBuilder::appendTextureSwizzle(SkString* out, GrPixelConfig config) const {
+ const GrSwizzle& configSwizzle = fProgramBuilder->glslCaps()->configTextureSwizzle(config);
+
+ if (configSwizzle != GrSwizzle::RGBA()) {
+ out->appendf(".%s", configSwizzle.c_str());
+ }
+}
+
bool GrGLSLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionName) {
if (featureBit & fFeaturesAddedMask) {
return false;
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.h b/src/gpu/glsl/GrGLSLShaderBuilder.h
index 6f8bf68bab..c14df53915 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.h
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.h
@@ -34,7 +34,7 @@ public:
const char* coordName,
GrSLType coordType = kVec2f_GrSLType) const;
- /** Version of above that appends the result to the fragment shader code instead.*/
+ /** Version of above that appends the result to the shader code instead.*/
void appendTextureLookup(const GrGLSLSampler&,
const char* coordName,
GrSLType coordType = kVec2f_GrSLType);
@@ -49,6 +49,14 @@ public:
const char* coordName,
GrSLType coordType = kVec2f_GrSLType);
+ /** Fetches an unfiltered texel from a sampler at integer coordinates. coordExpr must match the
+ dimensionality of the sampler and must be within the sampler's range. coordExpr is emitted
+ exactly once, so expressions like "idx++" are acceptable. */
+ void appendTexelFetch(SkString* out, const GrGLSLSampler&, const char* coordExpr) const;
+
+ /** Version of above that appends the result to the shader code instead.*/
+ void appendTexelFetch(const GrGLSLSampler&, const char* coordExpr);
+
/**
* Adds a #define directive to the top of the shader.
*/
@@ -175,6 +183,12 @@ protected:
void compileAndAppendLayoutQualifiers();
+ /* Appends any swizzling we may need to get from some backend internal format to the format used
+ * in GrPixelConfig. If this is implemented by the GrGpu object, then swizzle will be rgba. For
+ * shader prettiness we omit the swizzle rather than appending ".rgba".
+ */
+ void appendTextureSwizzle(SkString* out, GrPixelConfig) const;
+
void nextStage() {
fShaderStrings.push_back();
fCompilerStrings.push_back(this->code().c_str());