Enable narrowing conversions automatically for Runtime Effects.

Previously, it was possible to compile runtime effects with narrowing
conversions disabled; e.g. skslc would do this. A Runtime Effect-based
ProgramKind now enables narrowing conversions automatically. (The
setting flag could still be turned on manually as well.)

Change-Id: I912c9adda77c29ccfda3b1d85d106315f648d624
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/435916
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2021-08-02 19:03:30 -04:00 committed by SkCQ
parent 1c38121964
commit addccaf9cf
5 changed files with 17 additions and 14 deletions

View File

@ -226,7 +226,6 @@ SkRuntimeEffect::Result SkRuntimeEffect::MakeFromSource(SkString sksl,
settings.fInlineThreshold = 0;
settings.fForceNoInline = options.forceNoInline;
settings.fEnforceES2Restrictions = options.enforceES2Restrictions;
settings.fAllowNarrowingConversions = true;
program = compiler->convertProgram(kind, SkSL::String(sksl.c_str(), sksl.size()), settings);
if (!program) {

View File

@ -459,6 +459,11 @@ std::unique_ptr<Program> Compiler::convertProgram(
settings.fRemoveDeadFunctions &= settings.fOptimize;
settings.fRemoveDeadVariables &= settings.fOptimize;
// Runtime effects always allow narrowing conversions.
if (ProgramConfig::IsRuntimeEffect(kind)) {
settings.fAllowNarrowingConversions = true;
}
fErrorText = "";
fErrorCount = 0;
fInliner.reset();

View File

@ -245,7 +245,7 @@ private:
}
bool isRuntimeEffect() const {
return fContext.fConfig->isRuntimeEffect();
return ProgramConfig::IsRuntimeEffect(fContext.fConfig->fKind);
}
const ShaderCapsClass& caps() const {

View File

@ -30,11 +30,10 @@ struct ProgramSettings {
bool fForceHighPrecision = false;
// if true, add -0.5 bias to LOD of all texture lookups
bool fSharpenTextures = false;
// if the program needs to create an RTFlip uniform, this is its offset in the uniform
// buffer
// if the program needs to create an RTFlip uniform, this is its offset in the uniform buffer
int fRTFlipOffset = -1;
// if the program needs to create an RTFlip uniform and is creating spriv, this is the
// binding and set number of the uniform buffer.
// if the program needs to create an RTFlip uniform and is creating SPIR-V, this is the binding
// and set number of the uniform buffer.
int fRTFlipBinding = -1;
int fRTFlipSet = -1;
// If layout(set=S, binding=B) is not specified for a uniform, these values will be used.
@ -53,8 +52,8 @@ struct ProgramSettings {
int fInlineThreshold = SkSL::kDefaultInlineThreshold;
// If true, every function in the generated program will be given the `noinline` modifier.
bool fForceNoInline = false;
// If true, implicit conversions to lower precision numeric types are allowed
// (eg, float to half)
// If true, implicit conversions to lower precision numeric types are allowed (e.g., float to
// half). These are always allowed when compiling Runtime Effects.
bool fAllowNarrowingConversions = false;
// If true, then Debug code will run SPIR-V output through the validator to ensure its
// correctness
@ -91,13 +90,13 @@ struct ProgramConfig {
bool strictES2Mode() const {
return fSettings.fEnforceES2Restrictions &&
(this->isRuntimeEffect() || fKind == ProgramKind::kGeneric);
(IsRuntimeEffect(fKind) || fKind == ProgramKind::kGeneric);
}
bool isRuntimeEffect() const {
return (fKind == ProgramKind::kRuntimeColorFilter ||
fKind == ProgramKind::kRuntimeShader ||
fKind == ProgramKind::kRuntimeBlender);
static bool IsRuntimeEffect(ProgramKind kind) {
return (kind == ProgramKind::kRuntimeColorFilter ||
kind == ProgramKind::kRuntimeShader ||
kind == ProgramKind::kRuntimeBlender);
}
};

View File

@ -90,7 +90,7 @@ static bool check_parameters(const Context& context,
Modifiers m = param->modifiers();
if (isMain) {
if (context.fConfig->isRuntimeEffect()) {
if (ProgramConfig::IsRuntimeEffect(context.fConfig->fKind)) {
// We verify that the signature is fully correct later. For now, if this is a
// runtime effect of any flavor, a float2 param is supposed to be the coords, and a
// half4/float parameter is supposed to be the input or destination color: