* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrShaderCaps_DEFINED
#define GrShaderCaps_DEFINED
#include "include/core/SkRefCnt.h"
#include "include/private/GrTypesPriv.h"
#include "src/gpu/GrSwizzle.h"
#include "src/gpu/glsl/GrGLSL.h"
namespace SkSL {
class ShaderCapsFactory;
}
struct GrContextOptions;
class SkJSONWriter;
class GrShaderCaps : public SkRefCnt {
public:
* Indicates how GLSL must interact with advanced blend equations. The KHR extension requires
* special layout qualifiers in the fragment shader.
*/
enum AdvBlendEqInteraction {
kNotSupported_AdvBlendEqInteraction,
kAutomatic_AdvBlendEqInteraction,
kGeneralEnable_AdvBlendEqInteraction,
kSpecificEnables_AdvBlendEqInteraction,
kLast_AdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction
};
GrShaderCaps(const GrContextOptions&);
void dumpJSON(SkJSONWriter*) const;
bool supportsDistanceFieldText() const { return fShaderDerivativeSupport; }
bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; }
bool geometryShaderSupport() const { return fGeometryShaderSupport; }
bool gsInvocationsSupport() const { return fGSInvocationsSupport; }
bool pathRenderingSupport() const { return fPathRenderingSupport; }
bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; }
bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; }
bool integerSupport() const { return fIntegerSupport; }
* 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; }
const char* versionDeclString() const { return fVersionDeclString; }
const char* fbFetchColorName() const { return fFBFetchColorName; }
const char* fbFetchExtensionString() const { return fFBFetchExtensionString; }
bool flatInterpolationSupport() const { return fFlatInterpolationSupport; }
bool preferFlatInterpolation() const { return fPreferFlatInterpolation; }
bool noperspectiveInterpolationSupport() const { return fNoPerspectiveInterpolationSupport; }
bool sampleVariablesSupport() const { return fSampleVariablesSupport; }
bool sampleVariablesStencilSupport() const { return fSampleVariablesStencilSupport; }
bool externalTextureSupport() const { return fExternalTextureSupport; }
bool vertexIDSupport() const { return fVertexIDSupport; }
bool fpManipulationSupport() const { return fFPManipulationSupport; }
bool floatIs32Bits() const { return fFloatIs32Bits; }
bool halfIs32Bits() const { return fHalfIs32Bits; }
bool hasLowFragmentPrecision() const { return fHasLowFragmentPrecision; }
bool builtinFMASupport() const { return fBuiltinFMASupport; }
AdvBlendEqInteraction advBlendEqInteraction() const { return fAdvBlendEqInteraction; }
bool mustEnableAdvBlendEqs() const {
return fAdvBlendEqInteraction >= kGeneralEnable_AdvBlendEqInteraction;
}
bool mustEnableSpecificAdvBlendEqs() const {
return fAdvBlendEqInteraction == kSpecificEnables_AdvBlendEqInteraction;
}
bool mustDeclareFragmentShaderOutput() const { return fGLSLGeneration > k110_GrGLSLGeneration; }
bool usesPrecisionModifiers() const { return fUsesPrecisionModifiers; }
bool canUseAnyFunctionInShader() const { return fCanUseAnyFunctionInShader; }
bool canUseMinAndAbsTogether() const { return fCanUseMinAndAbsTogether; }
bool canUseFractForNegativeValues() const { return fCanUseFractForNegativeValues; }
bool mustForceNegatedAtanParamToFloat() const { return fMustForceNegatedAtanParamToFloat; }
bool atan2ImplementedAsAtanYOverX() const { return fAtan2ImplementedAsAtanYOverX; }
bool mustDoOpBetweenFloorAndAbs() const { return fMustDoOpBetweenFloorAndAbs; }
bool canUseFragCoord() const { return fCanUseFragCoord; }
bool incompleteShortIntPrecision() const { return fIncompleteShortIntPrecision; }
bool addAndTrueToLoopCondition() const { return fAddAndTrueToLoopCondition; }
bool unfoldShortCircuitAsTernary() const { return fUnfoldShortCircuitAsTernary; }
bool emulateAbsIntFunction() const { return fEmulateAbsIntFunction; }
bool rewriteDoWhileLoops() const { return fRewriteDoWhileLoops; }
bool removePowWithConstantExponent() const { return fRemovePowWithConstantExponent; }
bool requiresLocalOutputColorForFBFetch() const { return fRequiresLocalOutputColorForFBFetch; }
bool mustObfuscateUniformColor() const { return fMustObfuscateUniformColor; }
bool mustGuardDivisionEvenAfterExplicitZeroCheck() const {
return fMustGuardDivisionEvenAfterExplicitZeroCheck;
}
bool mustWriteToFragColor() const { return fMustWriteToFragColor; }
bool noDefaultPrecisionForExternalSamplers() const {
return fNoDefaultPrecisionForExternalSamplers;
}
const char* shaderDerivativeExtensionString() const {
SkASSERT(this->shaderDerivativeSupport());
return fShaderDerivativeExtensionString;
}
const char* geometryShaderExtensionString() const {
SkASSERT(this->geometryShaderSupport());
return fGeometryShaderExtensionString;
}
const char* gsInvocationsExtensionString() const {
SkASSERT(this->gsInvocationsSupport());
return fGSInvocationsExtensionString;
}
const char* fragCoordConventionsExtensionString() const {
return fFragCoordConventionsExtensionString;
}
const char* secondaryOutputExtensionString() const { return fSecondaryOutputExtensionString; }
const char* externalTextureExtensionString() const {
SkASSERT(this->externalTextureSupport());
return fExternalTextureExtensionString;
}
const char* secondExternalTextureExtensionString() const {
SkASSERT(this->externalTextureSupport());
return fSecondExternalTextureExtensionString;
}
const char* noperspectiveInterpolationExtensionString() const {
SkASSERT(this->noperspectiveInterpolationSupport());
return fNoPerspectiveInterpolationExtensionString;
}
const char* sampleVariablesExtensionString() const {
SkASSERT(this->sampleVariablesSupport() || this->sampleVariablesStencilSupport());
return fSampleVariablesExtensionString;
}
int maxFragmentSamplers() const { return fMaxFragmentSamplers; }
bool textureSwizzleAppliedInShader() const { return fTextureSwizzleAppliedInShader; }
GrGLSLGeneration generation() const { return fGLSLGeneration; }
private:
void applyOptionsOverrides(const GrContextOptions& options);
GrGLSLGeneration fGLSLGeneration;
bool fShaderDerivativeSupport : 1;
bool fGeometryShaderSupport : 1;
bool fGSInvocationsSupport : 1;
bool fPathRenderingSupport : 1;
bool fDstReadInShaderSupport : 1;
bool fDualSourceBlendingSupport : 1;
bool fIntegerSupport : 1;
bool fFBFetchSupport : 1;
bool fFBFetchNeedsCustomOutput : 1;
bool fUsesPrecisionModifiers : 1;
bool fFlatInterpolationSupport : 1;
bool fPreferFlatInterpolation : 1;
bool fNoPerspectiveInterpolationSupport : 1;
bool fSampleVariablesSupport : 1;
bool fSampleVariablesStencilSupport : 1;
bool fExternalTextureSupport : 1;
bool fVertexIDSupport : 1;
bool fFPManipulationSupport : 1;
bool fFloatIs32Bits : 1;
bool fHalfIs32Bits : 1;
bool fHasLowFragmentPrecision : 1;
bool fTextureSwizzleAppliedInShader : 1;
bool fBuiltinFMASupport : 1;
bool fCanUseAnyFunctionInShader : 1;
bool fCanUseMinAndAbsTogether : 1;
bool fCanUseFractForNegativeValues : 1;
bool fMustForceNegatedAtanParamToFloat : 1;
bool fAtan2ImplementedAsAtanYOverX : 1;
bool fMustDoOpBetweenFloorAndAbs : 1;
bool fRequiresLocalOutputColorForFBFetch : 1;
bool fMustObfuscateUniformColor : 1;
bool fMustGuardDivisionEvenAfterExplicitZeroCheck : 1;
bool fCanUseFragCoord : 1;
bool fIncompleteShortIntPrecision : 1;
bool fAddAndTrueToLoopCondition : 1;
bool fUnfoldShortCircuitAsTernary : 1;
bool fEmulateAbsIntFunction : 1;
bool fRewriteDoWhileLoops : 1;
bool fRemovePowWithConstantExponent : 1;
bool fMustWriteToFragColor : 1;
bool fNoDefaultPrecisionForExternalSamplers : 1;
const char* fVersionDeclString;
const char* fShaderDerivativeExtensionString;
const char* fGeometryShaderExtensionString;
const char* fGSInvocationsExtensionString;
const char* fFragCoordConventionsExtensionString;
const char* fSecondaryOutputExtensionString;
const char* fExternalTextureExtensionString;
const char* fSecondExternalTextureExtensionString;
const char* fNoPerspectiveInterpolationExtensionString;
const char* fSampleVariablesExtensionString;
const char* fFBFetchColorName;
const char* fFBFetchExtensionString;
int fMaxFragmentSamplers;
AdvBlendEqInteraction fAdvBlendEqInteraction;
friend class GrCaps;
friend class GrDawnCaps;
friend class GrGLCaps;
friend class GrMockCaps;
friend class GrMtlCaps;
friend class GrVkCaps;
friend class SkSL::ShaderCapsFactory;
};
#endif