aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-01-08 11:38:41 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-08 11:38:41 -0800
commit1a1efeacf7cc94a8c2977114dfe230fed3efc105 (patch)
treee91f058ed01fc4c25f410d7609e8123b1af776bc /src/gpu/glsl
parent04d975ac34c97d4869f819d2ad7c9fda47c198af (diff)
Add a class representing texture swizzle.
Store config swizzle GrGLCaps and shader swizzles in GrGLSLCaps. Remove GrTextureAccess's swizzle and update users of it to swizzle in their shader code. GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1567733005 Review URL: https://codereview.chromium.org/1567733005
Diffstat (limited to 'src/gpu/glsl')
-rwxr-xr-xsrc/gpu/glsl/GrGLSLCaps.cpp6
-rwxr-xr-xsrc/gpu/glsl/GrGLSLCaps.h17
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.cpp80
-rw-r--r--src/gpu/glsl/GrGLSLTextureSampler.h4
4 files changed, 23 insertions, 84 deletions
diff --git a/src/gpu/glsl/GrGLSLCaps.cpp b/src/gpu/glsl/GrGLSLCaps.cpp
index cf41f8e765..c82d8333df 100755
--- a/src/gpu/glsl/GrGLSLCaps.cpp
+++ b/src/gpu/glsl/GrGLSLCaps.cpp
@@ -31,9 +31,6 @@ GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options) {
fFBFetchColorName = nullptr;
fFBFetchExtensionString = nullptr;
fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
-
- fMustSwizzleInShader = false;
- memset(fConfigSwizzle, 0, sizeof(fConfigSwizzle));
}
SkString GrGLSLCaps::dump() const {
@@ -67,8 +64,5 @@ SkString GrGLSLCaps::dump() const {
}
void GrGLSLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
- if (options.fUseShaderSwizzling) {
- fMustSwizzleInShader = true;
- }
}
diff --git a/src/gpu/glsl/GrGLSLCaps.h b/src/gpu/glsl/GrGLSLCaps.h
index 21c59e7b16..eba9602e5a 100755
--- a/src/gpu/glsl/GrGLSLCaps.h
+++ b/src/gpu/glsl/GrGLSLCaps.h
@@ -11,6 +11,7 @@
#include "GrCaps.h"
#include "GrGLSL.h"
+#include "GrSwizzle.h"
class GrGLSLCaps : public GrShaderCaps {
public:
@@ -104,14 +105,14 @@ public:
return fExternalTextureExtensionString;
}
- bool mustSwizzleInShader() const { return fMustSwizzleInShader; }
-
/**
- * Returns a string which represents how to map from an internal GLFormat to a given
- * GrPixelConfig. The function mustSwizzleInShader determines whether this swizzle is applied
- * in the generated shader code or using sample state in the 3D API.
+ * Given a texture's config, this determines what swizzle must be appended to accesses to the
+ * texture in generated shader code. Swizzling may be implemented in texture parameters or a
+ * sampler rather than in the shader. In this case the shader swizzle will always be "rgba".
*/
- const char* getSwizzleMap(GrPixelConfig config) const { return fConfigSwizzle[config]; }
+ const GrSwizzle& configTextureSwizzle(GrPixelConfig config) const {
+ return fConfigTextureSwizzle[config];
+ }
GrGLSLGeneration generation() const { return fGLSLGeneration; }
@@ -148,13 +149,11 @@ private:
AdvBlendEqInteraction fAdvBlendEqInteraction;
- bool fMustSwizzleInShader;
- const char* fConfigSwizzle[kGrPixelConfigCnt];
+ GrSwizzle fConfigTextureSwizzle[kGrPixelConfigCnt];
friend class GrGLCaps; // For initialization.
typedef GrShaderCaps INHERITED;
};
-
#endif
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index 5716c0bd12..2d2ff8768e 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -5,70 +5,13 @@
* found in the LICENSE file.
*/
+#include "GrSwizzle.h"
#include "glsl/GrGLSLShaderBuilder.h"
#include "glsl/GrGLSLCaps.h"
#include "glsl/GrGLSLShaderVar.h"
#include "glsl/GrGLSLTextureSampler.h"
#include "glsl/GrGLSLProgramBuilder.h"
-static void map_swizzle(const char* swizzleMap, const char* swizzle, char* mangledSwizzle) {
- int i;
- for (i = 0; '\0' != swizzle[i]; ++i) {
- switch (swizzle[i]) {
- case 'r':
- mangledSwizzle[i] = swizzleMap[0];
- break;
- case 'g':
- mangledSwizzle[i] = swizzleMap[1];
- break;
- case 'b':
- mangledSwizzle[i] = swizzleMap[2];
- break;
- case 'a':
- mangledSwizzle[i] = swizzleMap[3];
- break;
- default:
- SkFAIL("Unsupported swizzle");
- }
- }
- mangledSwizzle[i] ='\0';
-}
-
-static void append_texture_lookup(SkString* out,
- const GrGLSLCaps* glslCaps,
- const char* samplerName,
- const char* coordName,
- GrPixelConfig config,
- const char* swizzle,
- GrSLType varyingType = kVec2f_GrSLType) {
- SkASSERT(coordName);
-
- out->appendf("%s(%s, %s)",
- GrGLSLTexture2DFunctionName(varyingType, glslCaps->generation()),
- samplerName,
- coordName);
-
- char mangledSwizzle[5];
-
- // This refers to any swizzling we may need to get from some backend internal format to the
- // format used in GrPixelConfig. Some backends will automatically do the sizzling for us.
- if (glslCaps->mustSwizzleInShader()) {
- const char* swizzleMap = glslCaps->getSwizzleMap(config);
- // if the map is simply 'rgba' then we don't need to do any manual swizzling to get us to
- // a GrPixelConfig format.
- if (memcmp(swizzleMap, "rgba", 4)) {
- // Manually 'swizzle' the swizzle using our mapping
- map_swizzle(swizzleMap, swizzle, mangledSwizzle);
- swizzle = mangledSwizzle;
- }
- }
-
- // For shader prettiness we omit the swizzle rather than appending ".rgba".
- if (memcmp(swizzle, "rgba", 4)) {
- out->appendf(".%s", swizzle);
- }
-}
-
GrGLSLShaderBuilder::GrGLSLShaderBuilder(GrGLSLProgramBuilder* program)
: fProgramBuilder(program)
, fInputs(GrGLSLProgramBuilder::kVarsPerBlock)
@@ -117,14 +60,21 @@ void GrGLSLShaderBuilder::appendTextureLookup(SkString* out,
const GrGLSLTextureSampler& sampler,
const char* coordName,
GrSLType varyingType) const {
+ const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps();
GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler();
- append_texture_lookup(out,
- fProgramBuilder->glslCaps(),
- uniformHandler->getUniformCStr(sampler.fSamplerUniform),
- coordName,
- sampler.config(),
- sampler.swizzle(),
- varyingType);
+ out->appendf("%s(%s, %s)",
+ GrGLSLTexture2DFunctionName(varyingType, glslCaps->generation()),
+ uniformHandler->getUniformCStr(sampler.fSamplerUniform),
+ 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());
+ }
}
void GrGLSLShaderBuilder::appendTextureLookup(const GrGLSLTextureSampler& sampler,
diff --git a/src/gpu/glsl/GrGLSLTextureSampler.h b/src/gpu/glsl/GrGLSLTextureSampler.h
index a4fbf550f2..fd8bcb26e9 100644
--- a/src/gpu/glsl/GrGLSLTextureSampler.h
+++ b/src/gpu/glsl/GrGLSLTextureSampler.h
@@ -21,17 +21,13 @@ public:
: fSamplerUniform(uniform)
, fConfig(access.getTexture()->config()) {
SkASSERT(kUnknown_GrPixelConfig != fConfig);
- memcpy(fSwizzle, access.getSwizzle(), 5);
}
GrPixelConfig config() const { return fConfig; }
- // this is .abcd
- const char* swizzle() const { return fSwizzle; }
private:
UniformHandle fSamplerUniform;
GrPixelConfig fConfig;
- char fSwizzle[5];
friend class GrGLSLShaderBuilder;
};