aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/gpu/GrShaderCaps.h71
-rw-r--r--include/private/GrTypesPriv.h27
-rw-r--r--src/gpu/GrProgramDesc.cpp2
-rw-r--r--src/gpu/GrShaderCaps.cpp104
-rw-r--r--src/gpu/effects/GrEllipseEffect.cpp33
-rw-r--r--src/gpu/effects/GrEllipseEffect.fp26
-rw-r--r--src/gpu/effects/GrRRectEffect.cpp68
-rw-r--r--src/gpu/gl/GrGLCaps.cpp115
-rw-r--r--src/gpu/gl/GrGLCaps.h4
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.cpp4
-rw-r--r--src/gpu/mtl/GrMtlCaps.mm17
-rw-r--r--src/gpu/vk/GrVkCaps.cpp15
-rw-r--r--src/sksl/SkSLCPP.h2
-rw-r--r--src/sksl/SkSLIRGenerator.cpp2
-rw-r--r--src/sksl/SkSLUtil.h4
-rw-r--r--tests/ApplyGammaTest.cpp2
-rw-r--r--tests/SRGBReadWritePixelsTest.cpp4
17 files changed, 141 insertions, 359 deletions
diff --git a/include/gpu/GrShaderCaps.h b/include/gpu/GrShaderCaps.h
index 5ecd58ca59..4c847ac8b0 100644
--- a/include/gpu/GrShaderCaps.h
+++ b/include/gpu/GrShaderCaps.h
@@ -20,40 +20,6 @@ class SkJSONWriter;
class GrShaderCaps : public SkRefCnt {
public:
- /** 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;
- };
-
/**
* Indicates how GLSL must interact with advanced blend equations. The KHR extension requires
* special layout qualifiers in the fragment shader.
@@ -82,24 +48,6 @@ public:
int imageLoadStoreSupport() const { return fImageLoadStoreSupport; }
/**
- * Get the precision info for a variable of type kFloat_GrSLType, kFloat2_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; }
-
- /**
* 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
@@ -136,6 +84,10 @@ public:
bool vertexIDSupport() const { return fVertexIDSupport; }
+ bool floatIs32Bits() const { return fFloatIs32Bits; }
+
+ bool halfIs32Bits() const { return fHalfIs32Bits; }
+
AdvBlendEqInteraction advBlendEqInteraction() const { return fAdvBlendEqInteraction; }
bool mustEnableAdvBlendEqs() const {
@@ -260,17 +212,9 @@ public:
return fConfigOutputSwizzle[config];
}
- /** 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]);
- }
-
GrGLSLGeneration generation() const { return fGLSLGeneration; }
private:
- /** GrCaps subclasses must call this after filling in the shader precision table. */
- void initSamplerPrecisionTable();
-
void applyOptionsOverrides(const GrContextOptions& options);
GrGLSLGeneration fGLSLGeneration;
@@ -284,7 +228,6 @@ private:
bool fIntegerSupport : 1;
bool fTexelBufferSupport : 1;
bool fImageLoadStoreSupport : 1;
- bool fShaderPrecisionVaries : 1;
bool fDropsTileOnZeroDivide : 1;
bool fFBFetchSupport : 1;
bool fFBFetchNeedsCustomOutput : 1;
@@ -300,6 +243,8 @@ private:
bool fExternalTextureSupport : 1;
bool fTexelFetchSupport : 1;
bool fVertexIDSupport : 1;
+ bool fFloatIs32Bits : 1;
+ bool fHalfIs32Bits : 1;
bool fDisableImageMultitexturing : 1;
// Used for specific driver bug work arounds
@@ -311,8 +256,6 @@ private:
bool fMustObfuscateUniformColor : 1;
bool fMustGuardDivisionEvenAfterExplicitZeroCheck : 1;
- PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
-
const char* fVersionDeclString;
const char* fShaderDerivativeExtensionString;
@@ -339,8 +282,6 @@ private:
GrSwizzle fConfigTextureSwizzle[kGrPixelConfigCnt];
GrSwizzle fConfigOutputSwizzle[kGrPixelConfigCnt];
- uint8_t fSamplerPrecisions[(1 << kGrShaderTypeCount)][kGrPixelConfigCnt];
-
friend class GrGLCaps; // For initialization.
friend class GrMockCaps;
friend class GrMtlCaps;
diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h
index a90944064f..cd1c0d4483 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -909,6 +909,33 @@ static inline bool GrPixelConfigIsUnorm(GrPixelConfig config) {
return false;
}
+/**
+ * Precision qualifier that should be used with a sampler.
+ */
+static inline GrSLPrecision GrSLSamplerPrecision(GrPixelConfig config) {
+ switch (config) {
+ case kUnknown_GrPixelConfig:
+ case kAlpha_8_GrPixelConfig:
+ case kGray_8_GrPixelConfig:
+ case kRGB_565_GrPixelConfig:
+ case kRGBA_4444_GrPixelConfig:
+ case kRGBA_8888_GrPixelConfig:
+ case kBGRA_8888_GrPixelConfig:
+ case kSRGBA_8888_GrPixelConfig:
+ case kSBGRA_8888_GrPixelConfig:
+ case kRGBA_8888_sint_GrPixelConfig:
+ return kLow_GrSLPrecision;
+ case kRGBA_float_GrPixelConfig:
+ case kRG_float_GrPixelConfig:
+ return kHigh_GrSLPrecision;
+ case kAlpha_half_GrPixelConfig:
+ case kRGBA_half_GrPixelConfig:
+ return kMedium_GrSLPrecision;
+ }
+ SK_ABORT("Unexpected type");
+ return kHigh_GrSLPrecision;
+}
+
static inline GrPixelConfigIsClamped GrGetPixelConfigIsClamped(GrPixelConfig config) {
return GrPixelConfigIsFloatingPoint(config) ? GrPixelConfigIsClamped::kNo
: GrPixelConfigIsClamped::kYes;
diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp
index a32e0cc28b..9c0add66e6 100644
--- a/src/gpu/GrProgramDesc.cpp
+++ b/src/gpu/GrProgramDesc.cpp
@@ -52,7 +52,7 @@ static uint16_t sampler_key(GrSLType samplerType, GrPixelConfig config, GrShader
GR_STATIC_ASSERT(1 == sizeof(caps.configTextureSwizzle(config).asKey()));
return SkToU16(samplerTypeKey |
caps.configTextureSwizzle(config).asKey() << kSamplerOrImageTypeKeyBits |
- (caps.samplerPrecision(config, visibility) << (8 + kSamplerOrImageTypeKeyBits)));
+ (GrSLSamplerPrecision(config) << (8 + kSamplerOrImageTypeKeyBits)));
}
static void add_sampler_and_image_keys(GrProcessorKeyBuilder* b, const GrResourceIOProcessor& proc,
diff --git a/src/gpu/GrShaderCaps.cpp b/src/gpu/GrShaderCaps.cpp
index 124fd4de40..2d9cd0a39b 100644
--- a/src/gpu/GrShaderCaps.cpp
+++ b/src/gpu/GrShaderCaps.cpp
@@ -13,32 +13,6 @@
////////////////////////////////////////////////////////////////////////////////////////////
-static const char* shader_type_to_string(GrShaderType type) {
- switch (type) {
- case kVertex_GrShaderType:
- return "vertex";
- case kGeometry_GrShaderType:
- return "geometry";
- case kFragment_GrShaderType:
- return "fragment";
- }
- return "";
-}
-
-static const char* precision_to_string(GrSLPrecision p) {
- switch (p) {
- case kLow_GrSLPrecision:
- return "low";
- case kMedium_GrSLPrecision:
- return "medium";
- case kHigh_GrSLPrecision:
- return "high";
- default:
- SK_ABORT("Unexpected precision type.");
- return "";
- }
-}
-
GrShaderCaps::GrShaderCaps(const GrContextOptions& options) {
fGLSLGeneration = k330_GrGLSLGeneration;
fShaderDerivativeSupport = false;
@@ -50,7 +24,6 @@ GrShaderCaps::GrShaderCaps(const GrContextOptions& options) {
fIntegerSupport = false;
fTexelBufferSupport = false;
fImageLoadStoreSupport = false;
- fShaderPrecisionVaries = false;
fDropsTileOnZeroDivide = false;
fFBFetchSupport = false;
fFBFetchNeedsCustomOutput = false;
@@ -73,6 +46,8 @@ GrShaderCaps::GrShaderCaps(const GrContextOptions& options) {
fExternalTextureSupport = false;
fTexelFetchSupport = false;
fVertexIDSupport = false;
+ fFloatIs32Bits = true;
+ fHalfIs32Bits = false;
fVersionDeclString = nullptr;
fShaderDerivativeExtensionString = nullptr;
@@ -113,26 +88,6 @@ void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
writer->appendBool("Texel Buffer Support", fTexelBufferSupport);
writer->appendBool("Image Load Store Support", fImageLoadStoreSupport);
- writer->appendBool("Variable Precision", fShaderPrecisionVaries);
-
- for (int s = 0; s < kGrShaderTypeCount; ++s) {
- GrShaderType shaderType = static_cast<GrShaderType>(s);
- writer->beginArray(SkStringPrintf("%s precisions",
- shader_type_to_string(shaderType)).c_str());
- for (int p = 0; p < kGrSLPrecisionCount; ++p) {
- if (fFloatPrecisions[s][p].supported()) {
- GrSLPrecision precision = static_cast<GrSLPrecision>(p);
- writer->beginObject(nullptr, false);
- writer->appendString("precision", precision_to_string(precision));
- writer->appendS32("log_low", fFloatPrecisions[s][p].fLogRangeLow);
- writer->appendS32("log_high", fFloatPrecisions[s][p].fLogRangeHigh);
- writer->appendS32("bits", fFloatPrecisions[s][p].fBits);
- writer->endObject();
- }
- }
- writer->endArray();
- }
-
static const char* kAdvBlendEqInteractionStr[] = {
"Not Supported",
"Automatic",
@@ -166,6 +121,8 @@ void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
writer->appendBool("External texture support", fExternalTextureSupport);
writer->appendBool("texelFetch support", fTexelFetchSupport);
writer->appendBool("sk_VertexID support", fVertexIDSupport);
+ writer->appendBool("float == fp32", fFloatIs32Bits);
+ writer->appendBool("half == fp32", fHalfIs32Bits);
writer->appendS32("Max VS Samplers", fMaxVertexSamplers);
writer->appendS32("Max GS Samplers", fMaxGeometrySamplers);
@@ -178,59 +135,6 @@ void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
writer->endObject();
}
-void GrShaderCaps::initSamplerPrecisionTable() {
- // Determine the largest precision qualifiers that are effectively the same as lowp/mediump.
- // e.g. if lowp == mediump, then use mediump instead of lowp.
- GrSLPrecision effectiveMediumP[kGrShaderTypeCount];
- GrSLPrecision effectiveLowP[kGrShaderTypeCount];
- for (int s = 0; s < kGrShaderTypeCount; ++s) {
- const PrecisionInfo* info = fFloatPrecisions[s];
- effectiveMediumP[s] = info[kHigh_GrSLPrecision] == info[kMedium_GrSLPrecision] ?
- kHigh_GrSLPrecision : kMedium_GrSLPrecision;
- effectiveLowP[s] = info[kMedium_GrSLPrecision] == info[kLow_GrSLPrecision] ?
- effectiveMediumP[s] : kLow_GrSLPrecision;
- }
-
- // Determine which precision qualifiers should be used with samplers.
- for (int visibility = 0; visibility < (1 << kGrShaderTypeCount); ++visibility) {
- GrSLPrecision mediump = kHigh_GrSLPrecision;
- GrSLPrecision lowp = kHigh_GrSLPrecision;
- for (int s = 0; s < kGrShaderTypeCount; ++s) {
- if (visibility & (1 << s)) {
- mediump = SkTMin(mediump, effectiveMediumP[s]);
- lowp = SkTMin(lowp, effectiveLowP[s]);
- }
-
- GR_STATIC_ASSERT(0 == kLow_GrSLPrecision);
- GR_STATIC_ASSERT(1 == kMedium_GrSLPrecision);
- GR_STATIC_ASSERT(2 == kHigh_GrSLPrecision);
-
- GR_STATIC_ASSERT((1 << kVertex_GrShaderType) == kVertex_GrShaderFlag);
- GR_STATIC_ASSERT((1 << kGeometry_GrShaderType) == kGeometry_GrShaderFlag);
- GR_STATIC_ASSERT((1 << kFragment_GrShaderType) == kFragment_GrShaderFlag);
- GR_STATIC_ASSERT(3 == kGrShaderTypeCount);
- }
-
- uint8_t* table = fSamplerPrecisions[visibility];
- table[kUnknown_GrPixelConfig] = lowp;
- table[kAlpha_8_GrPixelConfig] = lowp;
- table[kGray_8_GrPixelConfig] = lowp;
- table[kRGB_565_GrPixelConfig] = lowp;
- table[kRGBA_4444_GrPixelConfig] = lowp;
- table[kRGBA_8888_GrPixelConfig] = lowp;
- table[kBGRA_8888_GrPixelConfig] = lowp;
- table[kSRGBA_8888_GrPixelConfig] = lowp;
- table[kSBGRA_8888_GrPixelConfig] = lowp;
- table[kRGBA_8888_sint_GrPixelConfig] = lowp;
- table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision;
- table[kRG_float_GrPixelConfig] = kHigh_GrSLPrecision;
- table[kAlpha_half_GrPixelConfig] = mediump;
- table[kRGBA_half_GrPixelConfig] = mediump;
-
- GR_STATIC_ASSERT(14 == kGrPixelConfigCnt);
- }
-}
-
void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
#if GR_TEST_UTILS
fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending;
diff --git a/src/gpu/effects/GrEllipseEffect.cpp b/src/gpu/effects/GrEllipseEffect.cpp
index 4a0f37665c..6b1a8cc59f 100644
--- a/src/gpu/effects/GrEllipseEffect.cpp
+++ b/src/gpu/effects/GrEllipseEffect.cpp
@@ -28,34 +28,33 @@ public:
(void)center;
auto radii = _outer.radii();
(void)radii;
- prevRadii = half2(-1.0);
- useScale = sk_Caps.floatPrecisionVaries;
+ prevRadii = float2(-1.0);
+ useScale = !sk_Caps.floatIs32Bits;
fEllipseVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
kDefault_GrSLPrecision, "ellipse");
if (useScale) {
- fScaleVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType,
+ fScaleVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat2_GrSLType,
kDefault_GrSLPrecision, "scale");
}
fragBuilder->codeAppendf(
- "half2 prevCenter;\nhalf2 prevRadii = half2(%f, %f);\nbool useScale = %s;\nhalf2 d "
- "= half2(sk_FragCoord.xy - %s.xy);\n@if (useScale) {\n d *= %s.y;\n}\nhalf2 Z = "
- "d * half2(%s.zw);\nhalf implicit = dot(Z, d) - 1.0;\nhalf grad_dot = 4.0 * dot(Z, "
- "Z);\ngrad_dot = half(max(float(grad_dot), 0.0001));\nhalf approx_dist = "
- "float(implicit) * inversesqrt(float(grad_dot));\n@if (useScale) {\n "
- "approx_dist *= %s.x;\n}\nhalf alpha;\n@switch (%d) {\n case 0:\n alpha "
- "= half(float(approx_dist) > 0.0 ? 0.0 : 1.",
+ "float2 prevCenter;\nfloat2 prevRadii = float2(%f, %f);\nbool useScale = "
+ "%s;\nfloat2 d = sk_FragCoord.xy - %s.xy;\n@if (useScale) {\n d *= "
+ "%s.y;\n}\nfloat2 Z = d * %s.zw;\nfloat implicit = dot(Z, d) - 1.0;\nfloat "
+ "grad_dot = 4.0 * dot(Z, Z);\ngrad_dot = max(grad_dot, 0.0001);\nfloat approx_dist "
+ "= implicit * inversesqrt(grad_dot);\n@if (useScale) {\n approx_dist *= "
+ "%s.x;\n}\nhalf alpha;\n@switch (%d) {\n case 0:\n alpha = "
+ "half(approx_dist > 0.0 ? 0.0 : 1.0);\n break;\n case 1:\n ",
prevRadii.fX, prevRadii.fY, (useScale ? "true" : "false"),
args.fUniformHandler->getUniformCStr(fEllipseVar),
- fScaleVar.isValid() ? args.fUniformHandler->getUniformCStr(fScaleVar) : "half2(0)",
+ fScaleVar.isValid() ? args.fUniformHandler->getUniformCStr(fScaleVar) : "float2(0)",
args.fUniformHandler->getUniformCStr(fEllipseVar),
- fScaleVar.isValid() ? args.fUniformHandler->getUniformCStr(fScaleVar) : "half2(0)",
+ fScaleVar.isValid() ? args.fUniformHandler->getUniformCStr(fScaleVar) : "float2(0)",
(int)_outer.edgeType());
fragBuilder->codeAppendf(
- "0);\n break;\n case 1:\n alpha = half(clamp(0.5 - "
- "float(approx_dist), 0.0, 1.0));\n break;\n case 2:\n alpha = "
- "half(float(approx_dist) > 0.0 ? 1.0 : 0.0);\n break;\n case 3:\n "
- "alpha = half(clamp(0.5 + float(approx_dist), 0.0, 1.0));\n break;\n "
- "default:\n discard;\n}\n%s = %s * alpha;\n",
+ " alpha = half(clamp(0.5 - approx_dist, 0.0, 1.0));\n break;\n case "
+ "2:\n alpha = half(approx_dist > 0.0 ? 1.0 : 0.0);\n break;\n "
+ "case 3:\n alpha = half(clamp(0.5 + approx_dist, 0.0, 1.0));\n "
+ "break;\n default:\n discard;\n}\n%s = %s * alpha;\n",
args.fOutputColor, args.fInputColor ? args.fInputColor : "half4(1)");
}
diff --git a/src/gpu/effects/GrEllipseEffect.fp b/src/gpu/effects/GrEllipseEffect.fp
index 54641b72c6..27beb85d2f 100644
--- a/src/gpu/effects/GrEllipseEffect.fp
+++ b/src/gpu/effects/GrEllipseEffect.fp
@@ -6,17 +6,17 @@
*/
layout(key) in GrClipEdgeType edgeType;
-in half2 center;
-in half2 radii;
+in float2 center;
+in float2 radii;
-half2 prevCenter;
-half2 prevRadii = half2(-1);
+float2 prevCenter;
+float2 prevRadii = float2(-1);
// The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2)
-// The last two terms can underflow with halfs, so we use floats.
+// The last two terms can underflow when float != fp32, so we also provide a workaround.
uniform float4 ellipse;
-bool useScale = sk_Caps.floatPrecisionVaries;
-layout(when=useScale) uniform half2 scale;
+bool useScale = !sk_Caps.floatIs32Bits;
+layout(when=useScale) uniform float2 scale;
@optimizationFlags { kCompatibleWithCoverageAsAlpha_OptimizationFlag }
@@ -50,7 +50,7 @@ layout(when=useScale) uniform half2 scale;
void main() {
// d is the offset to the ellipse center
- half2 d = sk_FragCoord.xy - ellipse.xy;
+ float2 d = sk_FragCoord.xy - ellipse.xy;
// If we're on a device with a "real" mediump then we'll do the distance computation in a space
// that is normalized by the larger radius. The scale uniform will be scale, 1/scale. The
// inverse squared radii uniform values are already in this normalized space. The center is
@@ -58,14 +58,14 @@ void main() {
@if (useScale) {
d *= scale.y;
}
- half2 Z = d * ellipse.zw;
+ float2 Z = d * ellipse.zw;
// implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1.
- half implicit = dot(Z, d) - 1;
+ float implicit = dot(Z, d) - 1;
// grad_dot is the squared length of the gradient of the implicit.
- half grad_dot = 4 * dot(Z, Z);
+ float grad_dot = 4 * dot(Z, Z);
// Avoid calling inversesqrt on zero.
grad_dot = max(grad_dot, 1e-4);
- half approx_dist = implicit * inversesqrt(grad_dot);
+ float approx_dist = implicit * inversesqrt(grad_dot);
@if (useScale) {
approx_dist *= scale.x;
}
@@ -102,4 +102,4 @@ void main() {
et = (GrClipEdgeType) testData->fRandom->nextULessThan(kGrClipEdgeTypeCnt);
} while (GrClipEdgeType::kHairlineAA == et);
return GrEllipseEffect::Make(et, center, SkPoint::Make(rx, ry));
-} \ No newline at end of file
+}
diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp
index 4b56443b0d..510a26b425 100644
--- a/src/gpu/effects/GrRRectEffect.cpp
+++ b/src/gpu/effects/GrRRectEffect.cpp
@@ -165,9 +165,9 @@ void GLCircularRRectEffect::emitCode(EmitArgs& args) {
fRadiusPlusHalfUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType,
"radiusPlusHalf", &radiusPlusHalfName);
- // If we're on a device with a "real" mediump then the length calculation could overflow.
+ // If we're on a device where float != fp32 then the length calculation could overflow.
SkString clampedCircleDistance;
- if (args.fShaderCaps->floatPrecisionVaries()) {
+ if (!args.fShaderCaps->floatIs32Bits()) {
clampedCircleDistance.printf("clamp(%s.x * (1.0 - length(dxy * %s.y)), 0.0, 1.0);",
radiusPlusHalfName, radiusPlusHalfName);
} else {
@@ -192,13 +192,13 @@ void GLCircularRRectEffect::emitCode(EmitArgs& args) {
// alphas together.
switch (crre.getCircularCornerFlags()) {
case CircularRRectEffect::kAll_CornerFlags:
- fragBuilder->codeAppendf("half2 dxy0 = %s.xy - sk_FragCoord.xy;", rectName);
- fragBuilder->codeAppendf("half2 dxy1 = sk_FragCoord.xy - %s.zw;", rectName);
- fragBuilder->codeAppend("half2 dxy = max(max(dxy0, dxy1), 0.0);");
+ fragBuilder->codeAppendf("float2 dxy0 = %s.xy - sk_FragCoord.xy;", rectName);
+ fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.zw;", rectName);
+ fragBuilder->codeAppend("float2 dxy = max(max(dxy0, dxy1), 0.0);");
fragBuilder->codeAppendf("half alpha = %s;", clampedCircleDistance.c_str());
break;
case CircularRRectEffect::kTopLeft_CornerFlag:
- fragBuilder->codeAppendf("half2 dxy = max(%s.xy - sk_FragCoord.xy, 0.0);",
+ fragBuilder->codeAppendf("float2 dxy = max(%s.xy - sk_FragCoord.xy, 0.0);",
rectName);
fragBuilder->codeAppendf("half rightAlpha = clamp(%s.z - sk_FragCoord.x, 0.0, 1.0);",
rectName);
@@ -208,8 +208,8 @@ void GLCircularRRectEffect::emitCode(EmitArgs& args) {
clampedCircleDistance.c_str());
break;
case CircularRRectEffect::kTopRight_CornerFlag:
- fragBuilder->codeAppendf("half2 dxy = max(half2(sk_FragCoord.x - %s.z, "
- "%s.y - sk_FragCoord.y), 0.0);",
+ fragBuilder->codeAppendf("float2 dxy = max(float2(sk_FragCoord.x - %s.z, "
+ "%s.y - sk_FragCoord.y), 0.0);",
rectName, rectName);
fragBuilder->codeAppendf("half leftAlpha = clamp(sk_FragCoord.x - %s.x, 0.0, 1.0);",
rectName);
@@ -219,7 +219,7 @@ void GLCircularRRectEffect::emitCode(EmitArgs& args) {
clampedCircleDistance.c_str());
break;
case CircularRRectEffect::kBottomRight_CornerFlag:
- fragBuilder->codeAppendf("half2 dxy = max(sk_FragCoord.xy - %s.zw, 0.0);",
+ fragBuilder->codeAppendf("float2 dxy = max(sk_FragCoord.xy - %s.zw, 0.0);",
rectName);
fragBuilder->codeAppendf("half leftAlpha = clamp(sk_FragCoord.x - %s.x, 0.0, 1.0);",
rectName);
@@ -229,8 +229,8 @@ void GLCircularRRectEffect::emitCode(EmitArgs& args) {
clampedCircleDistance.c_str());
break;
case CircularRRectEffect::kBottomLeft_CornerFlag:
- fragBuilder->codeAppendf("half2 dxy = max(half2(%s.x - sk_FragCoord.x, sk_FragCoord.y - "
- "%s.w), 0.0);",
+ fragBuilder->codeAppendf("float2 dxy = max(float2(%s.x - sk_FragCoord.x, "
+ "sk_FragCoord.y - %s.w), 0.0);",
rectName, rectName);
fragBuilder->codeAppendf("half rightAlpha = clamp(%s.z - sk_FragCoord.x, 0.0, 1.0);",
rectName);
@@ -240,36 +240,36 @@ void GLCircularRRectEffect::emitCode(EmitArgs& args) {
clampedCircleDistance.c_str());
break;
case CircularRRectEffect::kLeft_CornerFlags:
- fragBuilder->codeAppendf("half2 dxy0 = %s.xy - sk_FragCoord.xy;", rectName);
- fragBuilder->codeAppendf("half dy1 = sk_FragCoord.y - %s.w;", rectName);
- fragBuilder->codeAppend("half2 dxy = max(half2(dxy0.x, max(dxy0.y, dy1)), 0.0);");
+ fragBuilder->codeAppendf("float2 dxy0 = %s.xy - sk_FragCoord.xy;", rectName);
+ fragBuilder->codeAppendf("float dy1 = sk_FragCoord.y - %s.w;", rectName);
+ fragBuilder->codeAppend("float2 dxy = max(float2(dxy0.x, max(dxy0.y, dy1)), 0.0);");
fragBuilder->codeAppendf("half rightAlpha = clamp(%s.z - sk_FragCoord.x, 0.0, 1.0);",
rectName);
fragBuilder->codeAppendf("half alpha = rightAlpha * %s;",
clampedCircleDistance.c_str());
break;
case CircularRRectEffect::kTop_CornerFlags:
- fragBuilder->codeAppendf("half2 dxy0 = %s.xy - sk_FragCoord.xy;", rectName);
- fragBuilder->codeAppendf("half dx1 = sk_FragCoord.x - %s.z;", rectName);
- fragBuilder->codeAppend("half2 dxy = max(half2(max(dxy0.x, dx1), dxy0.y), 0.0);");
+ fragBuilder->codeAppendf("float2 dxy0 = %s.xy - sk_FragCoord.xy;", rectName);
+ fragBuilder->codeAppendf("float dx1 = sk_FragCoord.x - %s.z;", rectName);
+ fragBuilder->codeAppend("float2 dxy = max(float2(max(dxy0.x, dx1), dxy0.y), 0.0);");
fragBuilder->codeAppendf("half bottomAlpha = clamp(%s.w - sk_FragCoord.y, 0.0, 1.0);",
rectName);
fragBuilder->codeAppendf("half alpha = bottomAlpha * %s;",
clampedCircleDistance.c_str());
break;
case CircularRRectEffect::kRight_CornerFlags:
- fragBuilder->codeAppendf("half dy0 = %s.y - sk_FragCoord.y;", rectName);
- fragBuilder->codeAppendf("half2 dxy1 = sk_FragCoord.xy - %s.zw;", rectName);
- fragBuilder->codeAppend("half2 dxy = max(half2(dxy1.x, max(dy0, dxy1.y)), 0.0);");
+ fragBuilder->codeAppendf("float dy0 = %s.y - sk_FragCoord.y;", rectName);
+ fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.zw;", rectName);
+ fragBuilder->codeAppend("float2 dxy = max(float2(dxy1.x, max(dy0, dxy1.y)), 0.0);");
fragBuilder->codeAppendf("half leftAlpha = clamp(sk_FragCoord.x - %s.x, 0.0, 1.0);",
rectName);
fragBuilder->codeAppendf("half alpha = leftAlpha * %s;",
clampedCircleDistance.c_str());
break;
case CircularRRectEffect::kBottom_CornerFlags:
- fragBuilder->codeAppendf("half dx0 = %s.x - sk_FragCoord.x;", rectName);
- fragBuilder->codeAppendf("half2 dxy1 = sk_FragCoord.xy - %s.zw;", rectName);
- fragBuilder->codeAppend("half2 dxy = max(half2(max(dx0, dxy1.x), dxy1.y), 0.0);");
+ fragBuilder->codeAppendf("float dx0 = %s.x - sk_FragCoord.x;", rectName);
+ fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.zw;", rectName);
+ fragBuilder->codeAppend("float2 dxy = max(float2(max(dx0, dxy1.x), dxy1.y), 0.0);");
fragBuilder->codeAppendf("half topAlpha = clamp(sk_FragCoord.y - %s.y, 0.0, 1.0);",
rectName);
fragBuilder->codeAppendf("half alpha = topAlpha * %s;",
@@ -523,14 +523,14 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
// The code below is a simplified version of the above that performs maxs on the vector
// components before computing distances and alpha values so that only one distance computation
// need be computed to determine the min alpha.
- fragBuilder->codeAppendf("half2 dxy0 = %s.xy - sk_FragCoord.xy;", rectName);
- fragBuilder->codeAppendf("half2 dxy1 = sk_FragCoord.xy - %s.zw;", rectName);
+ fragBuilder->codeAppendf("float2 dxy0 = %s.xy - sk_FragCoord.xy;", rectName);
+ fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.zw;", rectName);
- // If we're on a device with a "real" mediump then we'll do the distance computation in a space
+ // If we're on a device where float != fp32 then we'll do the distance computation in a space
// that is normalized by the largest radius. The scale uniform will be scale, 1/scale. The
// radii uniform values are already in this normalized space.
const char* scaleName = nullptr;
- if (args.fShaderCaps->floatPrecisionVaries()) {
+ if (!args.fShaderCaps->floatIs32Bits()) {
fScaleUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, "scale",
&scaleName);
}
@@ -543,12 +543,12 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
kHalf2_GrSLType,
"invRadiiXY",
&invRadiiXYSqdName);
- fragBuilder->codeAppend("half2 dxy = max(max(dxy0, dxy1), 0.0);");
+ fragBuilder->codeAppend("float2 dxy = max(max(dxy0, dxy1), 0.0);");
if (scaleName) {
fragBuilder->codeAppendf("dxy *= %s.y;", scaleName);
}
// Z is the x/y offsets divided by squared radii.
- fragBuilder->codeAppendf("half2 Z = dxy * %s.xy;", invRadiiXYSqdName);
+ fragBuilder->codeAppendf("float2 Z = dxy * %s.xy;", invRadiiXYSqdName);
break;
}
case SkRRect::kNinePatch_Type: {
@@ -561,11 +561,11 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppendf("dxy0 *= %s.y;", scaleName);
fragBuilder->codeAppendf("dxy1 *= %s.y;", scaleName);
}
- fragBuilder->codeAppend("half2 dxy = max(max(dxy0, dxy1), 0.0);");
+ fragBuilder->codeAppend("float2 dxy = max(max(dxy0, dxy1), 0.0);");
// Z is the x/y offsets divided by squared radii. We only care about the (at most) one
// corner where both the x and y offsets are positive, hence the maxes. (The inverse
// squared radii will always be positive.)
- fragBuilder->codeAppendf("half2 Z = max(max(dxy0 * %s.xy, dxy1 * %s.zw), 0.0);",
+ fragBuilder->codeAppendf("float2 Z = max(max(dxy0 * %s.xy, dxy1 * %s.zw), 0.0);",
invRadiiLTRBSqdName, invRadiiLTRBSqdName);
break;
@@ -574,12 +574,12 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
SK_ABORT("RRect should always be simple or nine-patch.");
}
// implicit is the evaluation of (x/a)^2 + (y/b)^2 - 1.
- fragBuilder->codeAppend("half implicit = dot(Z, dxy) - 1.0;");
+ fragBuilder->codeAppend("float implicit = dot(Z, dxy) - 1.0;");
// grad_dot is the squared length of the gradient of the implicit.
- fragBuilder->codeAppend("half grad_dot = 4.0 * dot(Z, Z);");
+ fragBuilder->codeAppend("float grad_dot = 4.0 * dot(Z, Z);");
// avoid calling inversesqrt on zero.
fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);");
- fragBuilder->codeAppend("half approx_dist = implicit * inversesqrt(grad_dot);");
+ fragBuilder->codeAppend("float approx_dist = implicit * inversesqrt(grad_dot);");
if (scaleName) {
fragBuilder->codeAppendf("approx_dist *= %s.x;", scaleName);
}
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index fe9bce8528..0c185e4a78 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -291,7 +291,7 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
**************************************************************************/
// This must be called after fCoreProfile is set on the GrGLCaps
- this->initGLSL(ctxInfo);
+ this->initGLSL(ctxInfo, gli);
GrShaderCaps* shaderCaps = fShaderCaps.get();
shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
@@ -634,8 +634,6 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
}
- this->initShaderPrecisionTable(ctxInfo, gli, shaderCaps);
-
if (kGL_GrGLStandard == standard) {
if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading")) &&
ctxInfo.vendor() != kIntel_GrGLVendor) {
@@ -760,7 +758,27 @@ const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration
return "<no version>";
}
-void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
+bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
+ if (kGLES_GrGLStandard != ctxInfo.standard() &&
+ ctxInfo.version() < GR_GL_VER(4,1) &&
+ !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
+ // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
+ return true;
+ }
+ // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
+ // geometry shaders don't have lower precision than vertex and fragment.
+ for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
+ GrGLint range[2];
+ GrGLint bits;
+ GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
+ if (range[0] < 127 || range[1] < 127 || bits < 23) {
+ return false;
+ }
+ }
+ return true;
+}
+
+void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
GrGLStandard standard = ctxInfo.standard();
GrGLVersion version = ctxInfo.version();
@@ -937,6 +955,9 @@ void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
}
+ shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
+ shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
+
if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
// The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
// so we must do the abs first in a separate expression.
@@ -1408,92 +1429,6 @@ void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
writer->endObject();
}
-static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
- switch (p) {
- case kLow_GrSLPrecision:
- return GR_GL_LOW_FLOAT;
- case kMedium_GrSLPrecision:
- return GR_GL_MEDIUM_FLOAT;
- case kHigh_GrSLPrecision:
- return GR_GL_HIGH_FLOAT;
- default:
- SK_ABORT("Unexpected precision type.");
- return -1;
- }
-}
-
-static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
- switch (type) {
- case kVertex_GrShaderType:
- return GR_GL_VERTEX_SHADER;
- case kGeometry_GrShaderType:
- return GR_GL_GEOMETRY_SHADER;
- case kFragment_GrShaderType:
- return GR_GL_FRAGMENT_SHADER;
- }
- SK_ABORT("Unknown shader type.");
- return -1;
-}
-
-void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
- const GrGLInterface* intf,
- GrShaderCaps* shaderCaps) {
- if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
- ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
- for (int s = 0; s < kGrShaderTypeCount; ++s) {
- if (kGeometry_GrShaderType != s) {
- GrShaderType shaderType = static_cast<GrShaderType>(s);
- GrGLenum glShader = shader_type_to_gl_shader(shaderType);
- GrShaderCaps::PrecisionInfo* first = nullptr;
- shaderCaps->fShaderPrecisionVaries = false;
- for (int p = 0; p < kGrSLPrecisionCount; ++p) {
- GrSLPrecision precision = static_cast<GrSLPrecision>(p);
- GrGLenum glPrecision = precision_to_gl_float_type(precision);
- GrGLint range[2];
- GrGLint bits;
- GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
- if (bits) {
- shaderCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
- shaderCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
- shaderCaps->fFloatPrecisions[s][p].fBits = bits;
- if (!first) {
- first = &shaderCaps->fFloatPrecisions[s][p];
- }
- else if (!shaderCaps->fShaderPrecisionVaries) {
- shaderCaps->fShaderPrecisionVaries =
- (*first != shaderCaps->fFloatPrecisions[s][p]);
- }
- }
- }
- }
- }
- }
- else {
- // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
- shaderCaps->fShaderPrecisionVaries = false;
- for (int s = 0; s < kGrShaderTypeCount; ++s) {
- if (kGeometry_GrShaderType != s) {
- for (int p = 0; p < kGrSLPrecisionCount; ++p) {
- shaderCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
- shaderCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
- shaderCaps->fFloatPrecisions[s][p].fBits = 23;
- }
- }
- }
- }
- // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
- // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
- // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
- // are recommended against.
- if (shaderCaps->fGeometryShaderSupport) {
- for (int p = 0; p < kGrSLPrecisionCount; ++p) {
- shaderCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
- shaderCaps->fFloatPrecisions[kVertex_GrShaderType][p];
- }
- }
- shaderCaps->initSamplerPrecisionTable();
-}
-
bool GrGLCaps::bgraIsInternalFormat() const {
return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
}
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 923b3f416d..3a50e8a393 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -428,7 +428,7 @@ private:
GrGLenum* externalType) const;
void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
- void initGLSL(const GrGLContextInfo&);
+ void initGLSL(const GrGLContextInfo&, const GrGLInterface*);
bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
void onApplyOptionsOverrides(const GrContextOptions& options) override;
@@ -441,8 +441,6 @@ private:
void initConfigTable(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*,
GrShaderCaps*);
- void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*, GrShaderCaps*);
-
GrGLStandard fStandard;
SkTArray<StencilFormat, true> fStencilFormats;
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 6f8d1be736..118b904540 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -303,7 +303,7 @@ GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(GrSLType s
const char* name,
GrShaderFlags visibility) {
this->updateSamplerCounts(visibility);
- GrSLPrecision precision = this->shaderCaps()->samplerPrecision(config, visibility);
+ GrSLPrecision precision = GrSLSamplerPrecision(config);
GrSwizzle swizzle = this->shaderCaps()->configTextureSwizzle(config);
return this->uniformHandler()->addSampler(visibility, swizzle, samplerType, precision, name);
}
@@ -311,7 +311,7 @@ GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(GrSLType s
GrGLSLProgramBuilder::TexelBufferHandle GrGLSLProgramBuilder::emitTexelBuffer(
GrPixelConfig config, const char* name, GrShaderFlags visibility) {
this->updateSamplerCounts(visibility);
- GrSLPrecision precision = this->shaderCaps()->samplerPrecision(config, visibility);
+ GrSLPrecision precision = GrSLSamplerPrecision(config);
return this->uniformHandler()->addTexelBuffer(visibility, precision, name);
}
diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm
index d431f0a1e1..2354b85e64 100644
--- a/src/gpu/mtl/GrMtlCaps.mm
+++ b/src/gpu/mtl/GrMtlCaps.mm
@@ -229,21 +229,10 @@ void GrMtlCaps::initShaderCaps() {
shaderCaps->fTexelFetchSupport = false;
shaderCaps->fVertexIDSupport = false;
shaderCaps->fImageLoadStoreSupport = false;
- shaderCaps->fShaderPrecisionVaries = false; // ???
- // Metal uses IEEE float and half floats so using those values here.
- for (int s = 0; s < kGrShaderTypeCount; ++s) {
- auto& highp = shaderCaps->fFloatPrecisions[s][kHigh_GrSLPrecision];
- highp.fLogRangeLow = highp.fLogRangeHigh = 127;
- highp.fBits = 23;
-
- auto& mediump = shaderCaps->fFloatPrecisions[s][kMedium_GrSLPrecision];
- mediump.fLogRangeLow = mediump.fLogRangeHigh = 15;
- mediump.fBits = 10;
-
- shaderCaps->fFloatPrecisions[s][kLow_GrSLPrecision] = mediump;
- }
- shaderCaps->initSamplerPrecisionTable();
+ // Metal uses IEEE float and half floats so assuming those values here.
+ shaderCaps->fFloatIs32Bits = true;
+ shaderCaps->fHalfIs32Bits = false;
shaderCaps->fMaxVertexSamplers =
shaderCaps->fMaxFragmentSamplers = 16;
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 2b24205af8..f5c4b342ed 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -259,19 +259,8 @@ void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, uint
shaderCaps->fVertexIDSupport = true;
// Assume the minimum precisions mandated by the SPIR-V spec.
- shaderCaps->fShaderPrecisionVaries = true;
- for (int s = 0; s < kGrShaderTypeCount; ++s) {
- auto& highp = shaderCaps->fFloatPrecisions[s][kHigh_GrSLPrecision];
- highp.fLogRangeLow = highp.fLogRangeHigh = 127;
- highp.fBits = 23;
-
- auto& mediump = shaderCaps->fFloatPrecisions[s][kMedium_GrSLPrecision];
- mediump.fLogRangeLow = mediump.fLogRangeHigh = 14;
- mediump.fBits = 10;
-
- shaderCaps->fFloatPrecisions[s][kLow_GrSLPrecision] = mediump;
- }
- shaderCaps->initSamplerPrecisionTable();
+ shaderCaps->fFloatIs32Bits = true;
+ shaderCaps->fHalfIs32Bits = false;
shaderCaps->fMaxVertexSamplers =
shaderCaps->fMaxGeometrySamplers =
diff --git a/src/sksl/SkSLCPP.h b/src/sksl/SkSLCPP.h
index d67990820b..612a200f28 100644
--- a/src/sksl/SkSLCPP.h
+++ b/src/sksl/SkSLCPP.h
@@ -18,7 +18,7 @@ using std::abs;
// macros to make sk_Caps.<cap name> work from C++ code
#define sk_Caps (*args.fShaderCaps)
-#define floatPrecisionVaries floatPrecisionVaries()
+#define floatIs32Bits floatIs32Bits()
// functions to make GLSL constructors work from C++ code
inline SkPoint float2(float xy) { return SkPoint::Make(xy, xy); }
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index 18b36a4b0f..cfa3049a2c 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -140,7 +140,7 @@ static void fill_caps(const SKSL_CAPS_CLASS& caps,
CAP(mustEnableSpecificAdvBlendEqs);
CAP(mustDeclareFragmentShaderOutput);
CAP(canUseAnyFunctionInShader);
- CAP(floatPrecisionVaries);
+ CAP(floatIs32Bits);
CAP(integerSupport);
#undef CAP
}
diff --git a/src/sksl/SkSLUtil.h b/src/sksl/SkSLUtil.h
index a8be7ef72f..1d9d53f6e8 100644
--- a/src/sksl/SkSLUtil.h
+++ b/src/sksl/SkSLUtil.h
@@ -135,8 +135,8 @@ public:
return false;
}
- bool floatPrecisionVaries() const {
- return false;
+ bool floatIs32Bits() const {
+ return true;
}
bool integerSupport() const {
diff --git a/tests/ApplyGammaTest.cpp b/tests/ApplyGammaTest.cpp
index f2049e7ccc..4147be7f41 100644
--- a/tests/ApplyGammaTest.cpp
+++ b/tests/ApplyGammaTest.cpp
@@ -105,7 +105,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ApplyGamma, reporter, ctxInfo) {
SkAutoTMalloc<uint32_t> read(kW * kH);
// We allow more error on GPUs with lower precision shader variables.
- float error = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.2f : 0.5f;
+ float error = context->caps()->shaderCaps()->halfIs32Bits() ? 0.5f : 1.2f;
for (auto toSRGB : { false, true }) {
sk_sp<SkSurface> dst(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii));
diff --git a/tests/SRGBReadWritePixelsTest.cpp b/tests/SRGBReadWritePixelsTest.cpp
index 6ebdcf7c20..b5d61c1850 100644
--- a/tests/SRGBReadWritePixelsTest.cpp
+++ b/tests/SRGBReadWritePixelsTest.cpp
@@ -184,14 +184,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) {
return;
}
- float error = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.2f : 0.5f;
+ float error = context->caps()->shaderCaps()->halfIs32Bits() ? 0.5f : 1.2f;
// Write srgba data and read as srgba and then as rgba
if (sContext->writePixels(iiSRGBA, origData, 0, 0, 0)) {
// For the all-srgba case, we allow a small error only for devices that have
// precision variation because the srgba data gets converted to linear and back in
// the shader.
- float smallError = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.f : 0.0f;
+ float smallError = context->caps()->shaderCaps()->halfIs32Bits() ? 0.0f : 1.f;
read_and_check_pixels(reporter, sContext.get(), origData, iiSRGBA,
check_srgb_to_linear_to_srgb_conversion, smallError,
"write/read srgba to srgba texture");