Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fe7aed6

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Reduce number of trials needed by ProcessorOptimizationValidationTest.
The current algorithm runs an exponentially-increasing number of trials based on the number of children supported by the fragment processor and has become a large drag on test times. This version runs a fixed number of trials to determine which optimization bits are able to appear, and then continues running trials until each potential optimization has been demonstrated successfully five times. The algorithm doesn't attempt to check interactions between the various optimization bits (e.g. a hypothetical bug that might only occur when two optimizations interact with one another) but hopefully the minimum of 100 successful trials is enough to shake out most issues. Change-Id: I4eba7ace84739027a5aea8f8f895b44c4532b816 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304059 Commit-Queue: John Stiles <[email protected]> Reviewed-by: Greg Daniel <[email protected]> Reviewed-by: Brian Osman <[email protected]> Auto-Submit: John Stiles <[email protected]>
1 parent e64ae86 commit fe7aed6

File tree

1 file changed

+50
-19
lines changed

1 file changed

+50
-19
lines changed

tests/ProcessorTest.cpp

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class TestFP : public GrFragmentProcessor {
109109
private:
110110
TestFP(const SkTArray<GrSurfaceProxyView>& views)
111111
: INHERITED(kTestFP_ClassID, kNone_OptimizationFlags) {
112-
for (const auto& view : views) {
112+
for (const GrSurfaceProxyView& view : views) {
113113
this->registerChild(GrTextureEffect::Make(view, kUnknown_SkAlphaType));
114114
}
115115
}
@@ -454,8 +454,8 @@ bool legal_modulation(const GrColor in[3], const GrColor out[3]) {
454454
// Use the most stepped up frame
455455
int maxInIdx = inf[0][i] > inf[1][i] ? 0 : 1;
456456
maxInIdx = inf[maxInIdx][i] > inf[2][i] ? maxInIdx : 2;
457-
const auto& in = inf[maxInIdx];
458-
const auto& out = outf[maxInIdx];
457+
const SkPMColor4f& in = inf[maxInIdx];
458+
const SkPMColor4f& out = outf[maxInIdx];
459459
if (in[i] > 0) {
460460
fpPreColorModulation[i] = out[i] / in[i];
461461
}
@@ -565,29 +565,51 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
565565

566566
// Because processor factories configure themselves in random ways, this is not exhaustive.
567567
for (int i = 0; i < FPFactory::Count(); ++i) {
568-
// Create a temp FP of this type just to see the number of children that it uses. Then
569-
// increase the number of attempts if the FP has child FPs, since optimizations will depend
570-
// on child optimizations being present.
571-
std::unique_ptr<GrFragmentProcessor> fp = fpGenerator.make(i, /*inputFP=*/nullptr);
572-
573-
int timesToInvokeFactory = 5;
574-
for (int j = 0; j < fp->numChildProcessors(); ++j) {
575-
// This value made a reasonable trade off between time and coverage when this test was
576-
// written.
577-
timesToInvokeFactory *= FPFactory::Count() / 2;
578-
}
568+
int optimizedForOpaqueInput = 0;
569+
int optimizedForCoverageAsAlpha = 0;
570+
int optimizedForConstantOutputForInput = 0;
579571

580-
#if defined(__MSVC_RUNTIME_CHECKS)
572+
#ifdef __MSVC_RUNTIME_CHECKS
581573
// This test is infuriatingly slow with MSVC runtime checks enabled
582-
timesToInvokeFactory = 1;
574+
static constexpr int kMinimumTrials = 1;
575+
static constexpr int kMaximumTrials = 1;
576+
static constexpr int kExpectedSuccesses = 1;
577+
#else
578+
// We start by testing each fragment-processor 100 times, watching the optimization bits
579+
// that appear. If we see an optimization bit appear in those first 100 trials, we keep
580+
// running tests until we see at least five successful trials that have this optimization
581+
// bit enabled. If we never see a particular optimization bit after 100 trials, we assume
582+
// that this FP doesn't support that optimization at all.
583+
static constexpr int kMinimumTrials = 100;
584+
static constexpr int kMaximumTrials = 2000;
585+
static constexpr int kExpectedSuccesses = 5;
583586
#endif
584587

585-
for (int j = 0; j < timesToInvokeFactory; ++j) {
588+
for (int trial = 0;; ++trial) {
586589
// Create a randomly-configured FP.
587590
fpGenerator.reroll();
588-
fp = fpGenerator.make(i, inputTexture1);
591+
std::unique_ptr<GrFragmentProcessor> fp = fpGenerator.make(i, inputTexture1);
592+
593+
// If we have iterated enough times and seen a sufficient number of successes on each
594+
// optimization bit that can be returned, stop running trials.
595+
if (trial >= kMinimumTrials) {
596+
bool moreTrialsNeeded = (optimizedForOpaqueInput > 0 &&
597+
optimizedForOpaqueInput < kExpectedSuccesses) ||
598+
(optimizedForCoverageAsAlpha > 0 &&
599+
optimizedForCoverageAsAlpha < kExpectedSuccesses) ||
600+
(optimizedForConstantOutputForInput > 0 &&
601+
optimizedForConstantOutputForInput < kExpectedSuccesses);
602+
if (!moreTrialsNeeded) break;
603+
604+
if (trial >= kMaximumTrials) {
605+
SkDebugf("Abandoning ProcessorOptimizationValidationTest after %d trials. "
606+
"Seed: 0x%08x, processor: %s.",
607+
kMaximumTrials, fpGenerator.initialSeed(), fp->name());
608+
break;
609+
}
610+
}
589611

590-
// Skip further testing if it has no optimization bits enabled.
612+
// Skip further testing if this trial has no optimization bits enabled.
591613
if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() &&
592614
!fp->compatibleWithCoverageAsAlpha()) {
593615
continue;
@@ -600,6 +622,15 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
600622
// constant-output or preserving-opacity tests.
601623
render_fp(context, rtc.get(), fpGenerator.make(i, inputTexture2), readData2.data());
602624
render_fp(context, rtc.get(), fpGenerator.make(i, inputTexture3), readData3.data());
625+
++optimizedForCoverageAsAlpha;
626+
}
627+
628+
if (fp->hasConstantOutputForConstantInput()) {
629+
++optimizedForConstantOutputForInput;
630+
}
631+
632+
if (fp->preservesOpaqueInput()) {
633+
++optimizedForOpaqueInput;
603634
}
604635

605636
// Draw base frame last so that rtc holds the original FP behavior if we need to dump

0 commit comments

Comments
 (0)