2015-06-24 13:59:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
#ifndef GrShaderCaps_DEFINED
|
|
|
|
#define GrShaderCaps_DEFINED
|
2015-06-24 13:59:57 +00:00
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
#include "../private/GrSwizzle.h"
|
|
|
|
#include "../private/GrGLSL.h"
|
2015-06-24 13:59:57 +00:00
|
|
|
|
2016-11-11 20:16:46 +00:00
|
|
|
namespace SkSL {
|
2016-11-29 20:27:52 +00:00
|
|
|
class ShaderCapsFactory;
|
2016-11-11 20:16:46 +00:00
|
|
|
}
|
2016-11-29 18:43:05 +00:00
|
|
|
struct GrContextOptions;
|
2016-11-11 20:16:46 +00:00
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
class GrShaderCaps : public SkRefCnt {
|
2015-06-24 13:59:57 +00:00
|
|
|
public:
|
2016-11-29 18:43:05 +00:00
|
|
|
/** Info about shader variable precision within a given shader stage. That is, this info
|
|
|
|
is relevant to a float (or vecNf) variable declared with a GrSLPrecision
|
|
|
|
in a given GrShaderType. The info here is hoisted from the OpenGL spec. */
|
|
|
|
struct PrecisionInfo {
|
|
|
|
PrecisionInfo() {
|
|
|
|
fLogRangeLow = 0;
|
|
|
|
fLogRangeHigh = 0;
|
|
|
|
fBits = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Is this precision level allowed in the shader stage? */
|
|
|
|
bool supported() const { return 0 != fBits; }
|
|
|
|
|
|
|
|
bool operator==(const PrecisionInfo& that) const {
|
|
|
|
return fLogRangeLow == that.fLogRangeLow && fLogRangeHigh == that.fLogRangeHigh &&
|
|
|
|
fBits == that.fBits;
|
|
|
|
}
|
|
|
|
bool operator!=(const PrecisionInfo& that) const { return !(*this == that); }
|
|
|
|
|
|
|
|
/** floor(log2(|min_value|)) */
|
|
|
|
int fLogRangeLow;
|
|
|
|
/** floor(log2(|max_value|)) */
|
|
|
|
int fLogRangeHigh;
|
|
|
|
/** Number of bits of precision. As defined in OpenGL (with names modified to reflect this
|
|
|
|
struct) :
|
|
|
|
"""
|
|
|
|
If the smallest representable value greater than 1 is 1 + e, then fBits will
|
|
|
|
contain floor(log2(e)), and every value in the range [2^fLogRangeLow,
|
|
|
|
2^fLogRangeHigh] can be represented to at least one part in 2^fBits.
|
|
|
|
"""
|
|
|
|
*/
|
|
|
|
int fBits;
|
|
|
|
};
|
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
/**
|
|
|
|
* Indicates how GLSL must interact with advanced blend equations. The KHR extension requires
|
|
|
|
* special layout qualifiers in the fragment shader.
|
|
|
|
*/
|
|
|
|
enum AdvBlendEqInteraction {
|
|
|
|
kNotSupported_AdvBlendEqInteraction, //<! No _blend_equation_advanced extension
|
|
|
|
kAutomatic_AdvBlendEqInteraction, //<! No interaction required
|
|
|
|
kGeneralEnable_AdvBlendEqInteraction, //<! layout(blend_support_all_equations) out
|
|
|
|
kSpecificEnables_AdvBlendEqInteraction, //<! Specific layout qualifiers per equation
|
|
|
|
|
|
|
|
kLast_AdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction
|
|
|
|
};
|
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
GrShaderCaps(const GrContextOptions&);
|
|
|
|
|
|
|
|
SkString dump() const;
|
|
|
|
|
|
|
|
bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; }
|
|
|
|
bool geometryShaderSupport() const { return fGeometryShaderSupport; }
|
|
|
|
bool pathRenderingSupport() const { return fPathRenderingSupport; }
|
|
|
|
bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; }
|
|
|
|
bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; }
|
|
|
|
bool integerSupport() const { return fIntegerSupport; }
|
|
|
|
bool texelBufferSupport() const { return fTexelBufferSupport; }
|
|
|
|
int imageLoadStoreSupport() const { return fImageLoadStoreSupport; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a
|
|
|
|
* given shader type. If the shader type is not supported or the precision level is not
|
|
|
|
* supported in that shader type then the returned struct will report false when supported() is
|
|
|
|
* called.
|
|
|
|
*/
|
|
|
|
const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType,
|
|
|
|
GrSLPrecision precision) const {
|
|
|
|
return fFloatPrecisions[shaderType][precision];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is there any difference between the float shader variable precision types? If this is true
|
|
|
|
* then unless the shader type is not supported, any call to getFloatShaderPrecisionInfo() would
|
|
|
|
* report the same info for all precisions in all shader types.
|
|
|
|
*/
|
|
|
|
bool floatPrecisionVaries() const { return fShaderPrecisionVaries; }
|
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
/**
|
|
|
|
* Some helper functions for encapsulating various extensions to read FB Buffer on openglES
|
|
|
|
*
|
|
|
|
* TODO(joshualitt) On desktop opengl 4.2+ we can achieve something similar to this effect
|
|
|
|
*/
|
|
|
|
bool fbFetchSupport() const { return fFBFetchSupport; }
|
|
|
|
|
|
|
|
bool fbFetchNeedsCustomOutput() const { return fFBFetchNeedsCustomOutput; }
|
|
|
|
|
|
|
|
bool bindlessTextureSupport() const { return fBindlessTextureSupport; }
|
|
|
|
|
2015-10-22 15:20:00 +00:00
|
|
|
const char* versionDeclString() const { return fVersionDeclString; }
|
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
const char* fbFetchColorName() const { return fFBFetchColorName; }
|
|
|
|
|
|
|
|
const char* fbFetchExtensionString() const { return fFBFetchExtensionString; }
|
|
|
|
|
|
|
|
bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; }
|
|
|
|
|
2016-02-12 20:14:06 +00:00
|
|
|
bool flatInterpolationSupport() const { return fFlatInterpolationSupport; }
|
|
|
|
|
|
|
|
bool noperspectiveInterpolationSupport() const { return fNoPerspectiveInterpolationSupport; }
|
|
|
|
|
2016-03-01 20:12:20 +00:00
|
|
|
bool multisampleInterpolationSupport() const { return fMultisampleInterpolationSupport; }
|
|
|
|
|
2016-02-22 15:55:44 +00:00
|
|
|
bool sampleVariablesSupport() const { return fSampleVariablesSupport; }
|
|
|
|
|
|
|
|
bool sampleMaskOverrideCoverageSupport() const { return fSampleMaskOverrideCoverageSupport; }
|
|
|
|
|
2016-03-11 18:07:37 +00:00
|
|
|
bool externalTextureSupport() const { return fExternalTextureSupport; }
|
|
|
|
|
2016-04-11 20:02:05 +00:00
|
|
|
bool texelFetchSupport() const { return fTexelFetchSupport; }
|
2016-03-11 22:07:38 +00:00
|
|
|
|
2017-05-31 18:51:23 +00:00
|
|
|
bool vertexIDSupport() const { return fVertexIDSupport; }
|
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
AdvBlendEqInteraction advBlendEqInteraction() const { return fAdvBlendEqInteraction; }
|
|
|
|
|
|
|
|
bool mustEnableAdvBlendEqs() const {
|
|
|
|
return fAdvBlendEqInteraction >= kGeneralEnable_AdvBlendEqInteraction;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mustEnableSpecificAdvBlendEqs() const {
|
|
|
|
return fAdvBlendEqInteraction == kSpecificEnables_AdvBlendEqInteraction;
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
bool mustDeclareFragmentShaderOutput() const {
|
|
|
|
return fGLSLGeneration > k110_GrGLSLGeneration;
|
|
|
|
}
|
|
|
|
|
2015-10-21 14:14:17 +00:00
|
|
|
bool usesPrecisionModifiers() const { return fUsesPrecisionModifiers; }
|
|
|
|
|
2017-01-20 15:45:49 +00:00
|
|
|
// Returns whether we can use the glsl function any() in our shader code.
|
2015-10-22 15:20:00 +00:00
|
|
|
bool canUseAnyFunctionInShader() const { return fCanUseAnyFunctionInShader; }
|
|
|
|
|
2015-11-11 14:27:20 +00:00
|
|
|
bool canUseMinAndAbsTogether() const { return fCanUseMinAndAbsTogether; }
|
|
|
|
|
|
|
|
bool mustForceNegatedAtanParamToFloat() const { return fMustForceNegatedAtanParamToFloat; }
|
|
|
|
|
2017-01-20 15:45:49 +00:00
|
|
|
// Returns whether a device incorrectly implements atan(y,x) as atan(y/x)
|
|
|
|
bool atan2ImplementedAsAtanYOverX() const { return fAtan2ImplementedAsAtanYOverX; }
|
|
|
|
|
2016-08-17 17:59:00 +00:00
|
|
|
bool requiresLocalOutputColorForFBFetch() const { return fRequiresLocalOutputColorForFBFetch; }
|
|
|
|
|
2017-02-15 17:41:27 +00:00
|
|
|
// On MacBook, geometry shaders break if they have more than one invocation.
|
|
|
|
bool mustImplementGSInvocationsWithLoop() const { return fMustImplementGSInvocationsWithLoop; }
|
|
|
|
|
2017-05-25 15:34:38 +00:00
|
|
|
bool mustObfuscateUniformColor() const { return fMustObfuscateUniformColor; }
|
|
|
|
|
2015-11-02 14:22:44 +00:00
|
|
|
// Returns the string of an extension that must be enabled in the shader to support
|
|
|
|
// derivatives. If nullptr is returned then no extension needs to be enabled. Before calling
|
|
|
|
// this function, the caller should check that shaderDerivativeSupport exists.
|
|
|
|
const char* shaderDerivativeExtensionString() const {
|
|
|
|
SkASSERT(this->shaderDerivativeSupport());
|
|
|
|
return fShaderDerivativeExtensionString;
|
|
|
|
}
|
2016-02-22 15:55:44 +00:00
|
|
|
|
2015-11-11 14:27:20 +00:00
|
|
|
// Returns the string of an extension that will do all necessary coord transfomations needed
|
|
|
|
// when reading the fragment position. If such an extension does not exisits, this function
|
|
|
|
// returns a nullptr, and all transforms of the frag position must be done manually in the
|
|
|
|
// shader.
|
|
|
|
const char* fragCoordConventionsExtensionString() const {
|
|
|
|
return fFragCoordConventionsExtensionString;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns the name of an extension that must be enabled in the shader, if such a thing is
|
|
|
|
// required in order to use a secondary output in the shader. This returns a nullptr if no such
|
|
|
|
// extension is required. However, the return value of this function does not say whether dual
|
|
|
|
// source blending is supported.
|
|
|
|
const char* secondaryOutputExtensionString() const {
|
|
|
|
return fSecondaryOutputExtensionString;
|
|
|
|
}
|
2015-11-02 14:22:44 +00:00
|
|
|
|
2015-11-22 22:51:00 +00:00
|
|
|
const char* externalTextureExtensionString() const {
|
2016-03-11 18:07:37 +00:00
|
|
|
SkASSERT(this->externalTextureSupport());
|
2015-11-22 22:51:00 +00:00
|
|
|
return fExternalTextureExtensionString;
|
|
|
|
}
|
|
|
|
|
2016-04-11 20:02:05 +00:00
|
|
|
const char* texelBufferExtensionString() const {
|
|
|
|
SkASSERT(this->texelBufferSupport());
|
|
|
|
return fTexelBufferExtensionString;
|
2016-03-11 22:07:38 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 20:14:06 +00:00
|
|
|
const char* noperspectiveInterpolationExtensionString() const {
|
|
|
|
SkASSERT(this->noperspectiveInterpolationSupport());
|
|
|
|
return fNoPerspectiveInterpolationExtensionString;
|
|
|
|
}
|
|
|
|
|
2016-03-01 20:12:20 +00:00
|
|
|
const char* multisampleInterpolationExtensionString() const {
|
|
|
|
SkASSERT(this->multisampleInterpolationSupport());
|
|
|
|
return fMultisampleInterpolationExtensionString;
|
|
|
|
}
|
|
|
|
|
2016-02-22 15:55:44 +00:00
|
|
|
const char* sampleVariablesExtensionString() const {
|
|
|
|
SkASSERT(this->sampleVariablesSupport());
|
|
|
|
return fSampleVariablesExtensionString;
|
|
|
|
}
|
|
|
|
|
2016-11-15 19:05:01 +00:00
|
|
|
const char* imageLoadStoreExtensionString() const {
|
|
|
|
SkASSERT(this->imageLoadStoreSupport());
|
|
|
|
return fImageLoadStoreExtensionString;
|
|
|
|
}
|
|
|
|
|
2016-03-11 18:07:37 +00:00
|
|
|
int maxVertexSamplers() const { return fMaxVertexSamplers; }
|
|
|
|
|
|
|
|
int maxGeometrySamplers() const { return fMaxGeometrySamplers; }
|
|
|
|
|
|
|
|
int maxFragmentSamplers() const { return fMaxFragmentSamplers; }
|
|
|
|
|
|
|
|
int maxCombinedSamplers() const { return fMaxCombinedSamplers; }
|
|
|
|
|
2016-11-29 16:59:17 +00:00
|
|
|
int maxVertexImageStorages() const { return fMaxVertexImageStorages; }
|
2016-11-15 19:05:01 +00:00
|
|
|
|
2016-11-29 16:59:17 +00:00
|
|
|
int maxGeometryImageStorages() const { return fMaxGeometryImageStorages; }
|
2016-11-15 19:05:01 +00:00
|
|
|
|
2016-11-29 16:59:17 +00:00
|
|
|
int maxFragmentImageStorages() const { return fMaxFragmentImageStorages; }
|
2016-11-15 19:05:01 +00:00
|
|
|
|
2016-11-29 16:59:17 +00:00
|
|
|
int maxCombinedImageStorages() const { return fMaxCombinedImageStorages; }
|
2016-11-15 19:05:01 +00:00
|
|
|
|
2015-11-04 12:23:53 +00:00
|
|
|
/**
|
2016-01-08 21:20:12 +00:00
|
|
|
* 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
|
2016-01-12 21:29:26 +00:00
|
|
|
* sampler rather than in the shader. In this case the returned swizzle will always be "rgba".
|
2015-11-04 12:23:53 +00:00
|
|
|
*/
|
2016-01-08 21:20:12 +00:00
|
|
|
const GrSwizzle& configTextureSwizzle(GrPixelConfig config) const {
|
|
|
|
return fConfigTextureSwizzle[config];
|
|
|
|
}
|
2015-11-04 12:23:53 +00:00
|
|
|
|
2016-01-12 21:29:26 +00:00
|
|
|
/** Swizzle that should occur on the fragment shader outputs for a given config. */
|
|
|
|
const GrSwizzle& configOutputSwizzle(GrPixelConfig config) const {
|
|
|
|
return fConfigOutputSwizzle[config];
|
|
|
|
}
|
|
|
|
|
2016-04-11 19:03:08 +00:00
|
|
|
/** Precision qualifier that should be used with a sampler, given its config and visibility. */
|
|
|
|
GrSLPrecision samplerPrecision(GrPixelConfig config, GrShaderFlags visibility) const {
|
|
|
|
return static_cast<GrSLPrecision>(fSamplerPrecisions[visibility][config]);
|
|
|
|
}
|
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
GrGLSLGeneration generation() const { return fGLSLGeneration; }
|
|
|
|
|
|
|
|
private:
|
2016-04-11 19:03:08 +00:00
|
|
|
/** GrCaps subclasses must call this after filling in the shader precision table. */
|
|
|
|
void initSamplerPrecisionTable();
|
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
void applyOptionsOverrides(const GrContextOptions& options);
|
2015-11-04 12:23:53 +00:00
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
GrGLSLGeneration fGLSLGeneration;
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
bool fShaderDerivativeSupport : 1;
|
|
|
|
bool fGeometryShaderSupport : 1;
|
|
|
|
bool fPathRenderingSupport : 1;
|
|
|
|
bool fDstReadInShaderSupport : 1;
|
|
|
|
bool fDualSourceBlendingSupport : 1;
|
|
|
|
bool fIntegerSupport : 1;
|
|
|
|
bool fTexelBufferSupport : 1;
|
|
|
|
bool fImageLoadStoreSupport : 1;
|
|
|
|
bool fShaderPrecisionVaries : 1;
|
2015-06-24 13:59:57 +00:00
|
|
|
bool fDropsTileOnZeroDivide : 1;
|
|
|
|
bool fFBFetchSupport : 1;
|
|
|
|
bool fFBFetchNeedsCustomOutput : 1;
|
|
|
|
bool fBindlessTextureSupport : 1;
|
2015-10-21 14:14:17 +00:00
|
|
|
bool fUsesPrecisionModifiers : 1;
|
2015-10-22 15:20:00 +00:00
|
|
|
bool fCanUseAnyFunctionInShader : 1;
|
2016-02-12 20:14:06 +00:00
|
|
|
bool fFlatInterpolationSupport : 1;
|
|
|
|
bool fNoPerspectiveInterpolationSupport : 1;
|
2016-03-01 20:12:20 +00:00
|
|
|
bool fMultisampleInterpolationSupport : 1;
|
2016-02-22 15:55:44 +00:00
|
|
|
bool fSampleVariablesSupport : 1;
|
|
|
|
bool fSampleMaskOverrideCoverageSupport : 1;
|
2016-03-11 18:07:37 +00:00
|
|
|
bool fExternalTextureSupport : 1;
|
2016-04-11 20:02:05 +00:00
|
|
|
bool fTexelFetchSupport : 1;
|
2017-05-31 18:51:23 +00:00
|
|
|
bool fVertexIDSupport : 1;
|
2015-10-21 14:14:17 +00:00
|
|
|
|
2015-11-11 14:27:20 +00:00
|
|
|
// Used for specific driver bug work arounds
|
|
|
|
bool fCanUseMinAndAbsTogether : 1;
|
|
|
|
bool fMustForceNegatedAtanParamToFloat : 1;
|
2017-01-20 15:45:49 +00:00
|
|
|
bool fAtan2ImplementedAsAtanYOverX : 1;
|
2016-08-17 17:59:00 +00:00
|
|
|
bool fRequiresLocalOutputColorForFBFetch : 1;
|
2017-02-15 17:41:27 +00:00
|
|
|
bool fMustImplementGSInvocationsWithLoop : 1;
|
2017-05-25 15:34:38 +00:00
|
|
|
bool fMustObfuscateUniformColor : 1;
|
2015-11-11 14:27:20 +00:00
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
|
|
|
|
|
2015-10-22 15:20:00 +00:00
|
|
|
const char* fVersionDeclString;
|
2015-06-24 13:59:57 +00:00
|
|
|
|
2015-11-02 14:22:44 +00:00
|
|
|
const char* fShaderDerivativeExtensionString;
|
2015-11-11 14:27:20 +00:00
|
|
|
const char* fFragCoordConventionsExtensionString;
|
|
|
|
const char* fSecondaryOutputExtensionString;
|
2015-11-22 22:51:00 +00:00
|
|
|
const char* fExternalTextureExtensionString;
|
2016-04-11 20:02:05 +00:00
|
|
|
const char* fTexelBufferExtensionString;
|
2016-02-12 20:14:06 +00:00
|
|
|
const char* fNoPerspectiveInterpolationExtensionString;
|
2016-03-01 20:12:20 +00:00
|
|
|
const char* fMultisampleInterpolationExtensionString;
|
2016-02-22 15:55:44 +00:00
|
|
|
const char* fSampleVariablesExtensionString;
|
2016-11-15 19:05:01 +00:00
|
|
|
const char* fImageLoadStoreExtensionString;
|
2015-11-02 14:22:44 +00:00
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
const char* fFBFetchColorName;
|
|
|
|
const char* fFBFetchExtensionString;
|
|
|
|
|
2016-09-27 10:33:05 +00:00
|
|
|
int fMaxVertexSamplers;
|
|
|
|
int fMaxGeometrySamplers;
|
|
|
|
int fMaxFragmentSamplers;
|
|
|
|
int fMaxCombinedSamplers;
|
2016-03-11 18:07:37 +00:00
|
|
|
|
2016-11-29 16:59:17 +00:00
|
|
|
int fMaxVertexImageStorages;
|
|
|
|
int fMaxGeometryImageStorages;
|
|
|
|
int fMaxFragmentImageStorages;
|
|
|
|
int fMaxCombinedImageStorages;
|
2016-11-15 19:05:01 +00:00
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
AdvBlendEqInteraction fAdvBlendEqInteraction;
|
|
|
|
|
2016-01-08 21:20:12 +00:00
|
|
|
GrSwizzle fConfigTextureSwizzle[kGrPixelConfigCnt];
|
2016-01-12 21:29:26 +00:00
|
|
|
GrSwizzle fConfigOutputSwizzle[kGrPixelConfigCnt];
|
2015-11-04 12:23:53 +00:00
|
|
|
|
2016-04-11 19:03:08 +00:00
|
|
|
uint8_t fSamplerPrecisions[(1 << kGrShaderTypeCount)][kGrPixelConfigCnt];
|
|
|
|
|
2015-06-24 13:59:57 +00:00
|
|
|
friend class GrGLCaps; // For initialization.
|
2017-07-31 14:45:52 +00:00
|
|
|
friend class GrMtlCaps;
|
2016-01-13 20:19:30 +00:00
|
|
|
friend class GrVkCaps;
|
2016-11-29 20:27:52 +00:00
|
|
|
friend class SkSL::ShaderCapsFactory;
|
2015-06-24 13:59:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|