Add support for ShaderCapsFactory to skslc.

In a followup CL, this will allow SkSL golden tests to control their
caps settings.

Change-Id: I2aace30e5567de8a52690c89b27bbab0c2d766e3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317177
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-09-15 15:37:24 -04:00 committed by Skia Commit-Bot
parent 1592361414
commit 194b9b9334
4 changed files with 164 additions and 94 deletions

View File

@ -141,7 +141,7 @@ void IRGenerator::popSymbolTable() {
fSymbolTable = fSymbolTable->fParent;
}
static void fill_caps(const SKSL_CAPS_CLASS& caps,
static void fill_caps(const SkSL::ShaderCapsClass& caps,
std::unordered_map<String, Program::Settings::Value>* capsMap) {
#define CAP(name) \
capsMap->insert(std::make_pair(String(#name), Program::Settings::Value(caps.name())))

View File

@ -11,6 +11,7 @@
#include "src/sksl/SkSLFileOutputStream.h"
#include "src/sksl/SkSLIRGenerator.h"
#include "src/sksl/SkSLStringStream.h"
#include "src/sksl/SkSLUtil.h"
#include "src/sksl/ir/SkSLEnum.h"
#include "src/sksl/ir/SkSLUnresolvedFunction.h"
@ -66,7 +67,10 @@ int main(int argc, const char** argv) {
printf("error reading '%s'\n", argv[1]);
exit(2);
}
SkSL::ShaderCapsPointer caps = SkSL::ShaderCapsFactory::Standalone();
SkSL::Program::Settings settings;
settings.fCaps = caps.get();
SkSL::String name(argv[2]);
if (name.endsWith(".spirv")) {
SkSL::FileOutputStream out(argv[2]);

View File

@ -18,7 +18,15 @@ namespace SkSL {
#if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
StandaloneShaderCaps standaloneCaps;
#endif
ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() {
return std::make_shared<StandaloneShaderCaps>();
}
#else
ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() {
return sk_make_sp<GrShaderCaps>(GrContextOptions());
}
#endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
void sksl_abort() {
#ifdef SKSL_STANDALONE

View File

@ -48,239 +48,295 @@ enum GrGLSLGeneration {
k320es_GrGLSLGeneration,
};
#define SKSL_CAPS_CLASS StandaloneShaderCaps
class StandaloneShaderCaps {
public:
GrGLSLGeneration fGLSLGeneration = k400_GrGLSLGeneration;
GrGLSLGeneration generation() const {
return k400_GrGLSLGeneration;
return fGLSLGeneration;
}
bool fAtan2ImplementedAsAtanYOverX = false;
bool atan2ImplementedAsAtanYOverX() const {
return false;
return fAtan2ImplementedAsAtanYOverX;
}
bool fCanUseMinAndAbsTogether = true;
bool canUseMinAndAbsTogether() const {
return true;
return fCanUseMinAndAbsTogether;
}
bool fMustForceNegatedAtanParamToFloat = false;
bool mustForceNegatedAtanParamToFloat() const {
return false;
return fMustForceNegatedAtanParamToFloat;
}
bool fGeometryShaderSupport = true;
bool geometryShaderSupport() const {
return fGeometryShaderSupport;
}
bool fShaderDerivativeSupport = true;
bool shaderDerivativeSupport() const {
return true;
return fShaderDerivativeSupport;
}
bool fUsesPrecisionModifiers = true;
bool usesPrecisionModifiers() const {
return true;
return fUsesPrecisionModifiers;
}
bool fMustDeclareFragmentShaderOutput = true;
bool mustDeclareFragmentShaderOutput() const {
return true;
return fMustDeclareFragmentShaderOutput;
}
bool fFBFetchSupport = true;
bool fbFetchSupport() const {
return true;
return fFBFetchSupport;
}
bool fFBFetchNeedsCustomOutput = false;
bool fbFetchNeedsCustomOutput() const {
return false;
return fFBFetchNeedsCustomOutput;
}
bool fFlatInterpolationSupport = true;
bool flatInterpolationSupport() const {
return true;
return fFlatInterpolationSupport;
}
bool fNoperspectiveInterpolationSupport = true;
bool noperspectiveInterpolationSupport() const {
return true;
return fNoperspectiveInterpolationSupport;
}
bool fMultisampleInterpolationSupport = true;
bool multisampleInterpolationSupport() const {
return true;
return fMultisampleInterpolationSupport;
}
bool fSampleMaskSupport = true;
bool sampleMaskSupport() const {
return true;
return fSampleMaskSupport;
}
bool fExternalTextureSupport = true;
bool externalTextureSupport() const {
return true;
return fExternalTextureSupport;
}
bool fMustDoOpBetweenFloorAndAbs = false;
bool mustDoOpBetweenFloorAndAbs() const {
return false;
return fMustDoOpBetweenFloorAndAbs;
}
bool fMustGuardDivisionEvenAfterExplicitZeroCheck = false;
bool mustGuardDivisionEvenAfterExplicitZeroCheck() const {
return false;
return fMustGuardDivisionEvenAfterExplicitZeroCheck;
}
bool fInBlendModesFailRandomlyForAllZeroVec = false;
bool inBlendModesFailRandomlyForAllZeroVec() const {
return false;
return fInBlendModesFailRandomlyForAllZeroVec;
}
bool fMustEnableAdvBlendEqs = false;
bool mustEnableAdvBlendEqs() const {
return false;
return fMustEnableAdvBlendEqs;
}
bool fMustEnableSpecificAdvBlendEqs = false;
bool mustEnableSpecificAdvBlendEqs() const {
return false;
return fMustEnableSpecificAdvBlendEqs;
}
bool fCanUseAnyFunctionInShader = false;
bool canUseAnyFunctionInShader() const {
return false;
return fCanUseAnyFunctionInShader;
}
bool fNoDefaultPrecisionForExternalSamplers = false;
bool noDefaultPrecisionForExternalSamplers() const {
return false;
return fNoDefaultPrecisionForExternalSamplers;
}
bool fFloatIs32Bits = true;
bool floatIs32Bits() const {
return true;
return fFloatIs32Bits;
}
bool fIntegerSupport = false;
bool integerSupport() const {
return false;
return fIntegerSupport;
}
bool fBuiltinFMASupport = true;
bool builtinFMASupport() const {
return true;
return fBuiltinFMASupport;
}
bool fCanUseDoLoops = false;
bool canUseDoLoops() const {
// we define this to false in standalone so we don't use do loops while inlining in FP files
// (which would then, being baked in, end up being used even in contexts where do loops are
// not allowed)
return false;
return fCanUseDoLoops;
}
const char* fShaderDerivativeExtensionString = nullptr;
const char* shaderDerivativeExtensionString() const {
return nullptr;
return fShaderDerivativeExtensionString;
}
const char* fFragCoordConventionsExtensionString = nullptr;
const char* fragCoordConventionsExtensionString() const {
return nullptr;
return fFragCoordConventionsExtensionString;
}
const char* fGeometryShaderExtensionString = nullptr;
const char* geometryShaderExtensionString() const {
return nullptr;
return fGeometryShaderExtensionString;
}
const char* fGSInvocationsExtensionString = nullptr;
const char* gsInvocationsExtensionString() const {
return nullptr;
return fGSInvocationsExtensionString;
}
const char* fExternalTextureExtensionString = nullptr;
const char* externalTextureExtensionString() const {
return nullptr;
return fExternalTextureExtensionString;
}
const char* fSecondExternalTextureExtensionString = nullptr;
const char* secondExternalTextureExtensionString() const {
return nullptr;
return fSecondExternalTextureExtensionString;
}
const char* fVersionDeclString = "";
const char* versionDeclString() const {
return "";
return fVersionDeclString;
}
bool fGSInvocationsSupport = true;
bool gsInvocationsSupport() const {
return true;
return fGSInvocationsSupport;
}
bool fCanUseFractForNegativeValues = true;
bool canUseFractForNegativeValues() const {
return true;
return fCanUseFractForNegativeValues;
}
bool fCanUseFragCoord = true;
bool canUseFragCoord() const {
return true;
return fCanUseFragCoord;
}
bool fIncompleteShortIntPrecision = false;
bool incompleteShortIntPrecision() const {
return false;
return fIncompleteShortIntPrecision;
}
bool fAddAndTrueToLoopCondition = false;
bool addAndTrueToLoopCondition() const {
return false;
return fAddAndTrueToLoopCondition;
}
bool fUnfoldShortCircuitAsTernary = false;
bool unfoldShortCircuitAsTernary() const {
return false;
return fUnfoldShortCircuitAsTernary;
}
bool fEmulateAbsIntFunction = false;
bool emulateAbsIntFunction() const {
return false;
return fEmulateAbsIntFunction;
}
bool fRewriteDoWhileLoops = false;
bool rewriteDoWhileLoops() const {
return false;
return fRewriteDoWhileLoops;
}
bool fRemovePowWithConstantExponent = false;
bool removePowWithConstantExponent() const {
return false;
return fRemovePowWithConstantExponent;
}
const char* fFBFetchColorName = nullptr;
const char* fbFetchColorName() const {
return nullptr;
return fFBFetchColorName;
}
};
using ShaderCapsClass = StandaloneShaderCaps;
using ShaderCapsPointer = std::shared_ptr<StandaloneShaderCaps>;
extern StandaloneShaderCaps standaloneCaps;
#else
#define SKSL_CAPS_CLASS GrShaderCaps
using ShaderCapsClass = GrShaderCaps;
using ShaderCapsPointer = sk_sp<GrShaderCaps>;
#endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
// Various sets of caps for use in tests
class ShaderCapsFactory {
public:
static sk_sp<GrShaderCaps> Default() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer Default() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fShaderDerivativeSupport = true;
return result;
}
static sk_sp<GrShaderCaps> Version450Core() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer Standalone() {
return MakeShaderCaps();
}
static ShaderCapsPointer Version450Core() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 450 core";
return result;
}
static sk_sp<GrShaderCaps> Version110() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer Version110() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 110";
result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration;
return result;
}
static sk_sp<GrShaderCaps> UsesPrecisionModifiers() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer UsesPrecisionModifiers() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fUsesPrecisionModifiers = true;
return result;
}
static sk_sp<GrShaderCaps> CannotUseMinAndAbsTogether() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer CannotUseMinAndAbsTogether() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fCanUseMinAndAbsTogether = false;
return result;
}
static sk_sp<GrShaderCaps> CannotUseFractForNegativeValues() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer CannotUseFractForNegativeValues() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fCanUseFractForNegativeValues = false;
return result;
}
static sk_sp<GrShaderCaps> MustForceNegatedAtanParamToFloat() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer MustForceNegatedAtanParamToFloat() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fMustForceNegatedAtanParamToFloat = true;
return result;
}
static sk_sp<GrShaderCaps> ShaderDerivativeExtensionString() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer ShaderDerivativeExtensionString() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fShaderDerivativeSupport = true;
result->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
@ -288,39 +344,39 @@ public:
return result;
}
static sk_sp<GrShaderCaps> FragCoordsOld() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer FragCoordsOld() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 110";
result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration;
result->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
return result;
}
static sk_sp<GrShaderCaps> FragCoordsNew() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer FragCoordsNew() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
return result;
}
static sk_sp<GrShaderCaps> GeometryShaderSupport() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer GeometryShaderSupport() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fGeometryShaderSupport = true;
result->fGSInvocationsSupport = true;
return result;
}
static sk_sp<GrShaderCaps> NoGSInvocationsSupport() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer NoGSInvocationsSupport() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fGeometryShaderSupport = true;
result->fGSInvocationsSupport = false;
return result;
}
static sk_sp<GrShaderCaps> GeometryShaderExtensionString() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer GeometryShaderExtensionString() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 310es";
result->fGeometryShaderSupport = true;
result->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
@ -328,8 +384,8 @@ public:
return result;
}
static sk_sp<GrShaderCaps> GSInvocationsExtensionString() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer GSInvocationsExtensionString() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fGeometryShaderSupport = true;
result->fGSInvocationsSupport = true;
@ -337,8 +393,8 @@ public:
return result;
}
static sk_sp<GrShaderCaps> VariousCaps() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer VariousCaps() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fExternalTextureSupport = true;
result->fFBFetchSupport = false;
@ -346,63 +402,65 @@ public:
return result;
}
static sk_sp<GrShaderCaps> CannotUseFragCoord() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer CannotUseFragCoord() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fCanUseFragCoord = false;
return result;
}
static sk_sp<GrShaderCaps> IncompleteShortIntPrecision() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer IncompleteShortIntPrecision() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 310es";
result->fUsesPrecisionModifiers = true;
result->fIncompleteShortIntPrecision = true;
return result;
}
static sk_sp<GrShaderCaps> AddAndTrueToLoopCondition() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer AddAndTrueToLoopCondition() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fAddAndTrueToLoopCondition = true;
return result;
}
static sk_sp<GrShaderCaps> UnfoldShortCircuitAsTernary() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer UnfoldShortCircuitAsTernary() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fUnfoldShortCircuitAsTernary = true;
return result;
}
static sk_sp<GrShaderCaps> EmulateAbsIntFunction() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer EmulateAbsIntFunction() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fEmulateAbsIntFunction = true;
return result;
}
static sk_sp<GrShaderCaps> RewriteDoWhileLoops() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer RewriteDoWhileLoops() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fRewriteDoWhileLoops = true;
return result;
}
static sk_sp<GrShaderCaps> RemovePowWithConstantExponent() {
sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
static ShaderCapsPointer RemovePowWithConstantExponent() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";
result->fRemovePowWithConstantExponent = true;
return result;
}
static sk_sp<GrShaderCaps> SampleMaskSupport() {
sk_sp<GrShaderCaps> result = Default();
static ShaderCapsPointer SampleMaskSupport() {
ShaderCapsPointer result = Default();
result->fSampleMaskSupport = true;
return result;
}
private:
static ShaderCapsPointer MakeShaderCaps();
};
#endif
#if !defined(SKSL_STANDALONE)
bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType);
@ -414,4 +472,4 @@ NORETURN void sksl_abort();
} // namespace SkSL
#endif
#endif // SKSL_UTIL