aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar cdalton <cdalton@nvidia.com>2016-04-11 13:02:05 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-11 13:02:05 -0700
commitf8a6ce8d8c54cab5456d3099fa07e460c889c2e6 (patch)
tree81b9feb4858bf59708338b8952e6d473b7b2119b /src/gpu
parent3f6f76f98b6b37d17d1492791ff0feb1b7586bd6 (diff)
Add GLSL support for texelFetch
Adds a cap and builder methods for texelFetch. This is required for texel buffers. Also moves the texel buffer cap into the general shader caps, and adds glTexBufferRange to the GL interface. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1869063005 Review URL: https://codereview.chromium.org/1869063005
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrCaps.cpp2
-rw-r--r--src/gpu/gl/GrGLAssembleInterface.cpp6
-rw-r--r--src/gpu/gl/GrGLCaps.cpp31
-rw-r--r--src/gpu/gl/GrGLInterface.cpp8
-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
8 files changed, 87 insertions, 30 deletions
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index 41f5b9b391..1056c426aa 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -15,6 +15,7 @@ GrShaderCaps::GrShaderCaps() {
fDstReadInShaderSupport = false;
fDualSourceBlendingSupport = false;
fIntegerSupport = false;
+ fTexelBufferSupport = false;
fShaderPrecisionVaries = false;
}
@@ -51,6 +52,7 @@ SkString GrShaderCaps::dump() const {
r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
r.appendf("Integer Support : %s\n", gNY[fIntegerSupport]);
+ r.appendf("Texel Buffer Support : %s\n", gNY[fTexelBufferSupport]);
r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]);
diff --git a/src/gpu/gl/GrGLAssembleInterface.cpp b/src/gpu/gl/GrGLAssembleInterface.cpp
index bc7dc8a100..ba27b36790 100644
--- a/src/gpu/gl/GrGLAssembleInterface.cpp
+++ b/src/gpu/gl/GrGLAssembleInterface.cpp
@@ -207,6 +207,9 @@ const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) {
if (glVer >= GR_GL_VER(3,1)) {
GET_PROC(TexBuffer);
}
+ if (glVer >= GR_GL_VER(4,3)) {
+ GET_PROC(TexBufferRange);
+ }
GET_PROC(TexImage2D);
GET_PROC(TexParameteri);
GET_PROC(TexParameteriv);
@@ -655,10 +658,13 @@ const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) {
if (version >= GR_GL_VER(3,2)) {
GET_PROC(TexBuffer);
+ GET_PROC(TexBufferRange);
} else if (extensions.has("GL_OES_texture_buffer")) {
GET_PROC_SUFFIX(TexBuffer, OES);
+ GET_PROC_SUFFIX(TexBufferRange, OES);
} else if (extensions.has("GL_EXT_texture_buffer")) {
GET_PROC_SUFFIX(TexBuffer, EXT);
+ GET_PROC_SUFFIX(TexBufferRange, EXT);
}
GET_PROC(TexImage2D);
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index fc2c8ce398..0322a0f57c 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -736,18 +736,27 @@ void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
}
if (kGL_GrGLStandard == standard) {
- glslCaps->fBufferTextureSupport = ctxInfo.version() > GR_GL_VER(3, 1) &&
- ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
+ glslCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
} else {
- if (ctxInfo.version() > GR_GL_VER(3, 2) &&
- ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
- glslCaps->fBufferTextureSupport = true;
- } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
- glslCaps->fBufferTextureSupport = true;
- glslCaps->fBufferTextureExtensionString = "GL_OES_texture_buffer";
- } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
- glslCaps->fBufferTextureSupport = true;
- glslCaps->fBufferTextureExtensionString = "GL_EXT_texture_buffer";
+ glslCaps->fTexelFetchSupport =
+ ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
+ }
+
+ if (glslCaps->fTexelFetchSupport) {
+ if (kGL_GrGLStandard == standard) {
+ glslCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(4, 3) &&
+ ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
+ } else {
+ if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
+ ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
+ glslCaps->fTexelBufferSupport = true;
+ } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
+ glslCaps->fTexelBufferSupport = true;
+ glslCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
+ } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
+ glslCaps->fTexelBufferSupport = true;
+ glslCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
+ }
}
}
diff --git a/src/gpu/gl/GrGLInterface.cpp b/src/gpu/gl/GrGLInterface.cpp
index 9cd7e68647..4e6ad08611 100644
--- a/src/gpu/gl/GrGLInterface.cpp
+++ b/src/gpu/gl/GrGLInterface.cpp
@@ -414,10 +414,16 @@ bool GrGLInterface::validate() const {
RETURN_FALSE_INTERFACE;
}
}
+ if (glVer >= GR_GL_VER(4,3)) {
+ if (nullptr == fFunctions.fTexBufferRange) {
+ RETURN_FALSE_INTERFACE;
+ }
+ }
} else {
if (glVer >= GR_GL_VER(3,2) || fExtensions.has("GL_OES_texture_buffer") ||
fExtensions.has("GL_EXT_texture_buffer")) {
- if (nullptr == fFunctions.fTexBuffer) {
+ if (nullptr == fFunctions.fTexBuffer ||
+ nullptr == fFunctions.fTexBufferRange) {
RETURN_FALSE_INTERFACE;
}
}
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());