skia2/tests/graphite/ProgramCacheTest.cpp
Robert Phillips db7f2c67c2 [graphite] Add lookup by unique ID to program and uniform caches
The SortKey will only hold the uniqueID of the program and uniform data. When actually executing the draw we will need to reconnect with the actual data.

Bug: skia:12466
Change-Id: Iea7f0a99d471ea7fe2a3864bdd60255b09289088
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/464926
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2021-10-28 19:43:00 +00:00

68 lines
2.4 KiB
C++

/*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tests/Test.h"
#include "experimental/graphite/include/Context.h"
#include "experimental/graphite/src/ProgramCache.h"
#include "experimental/graphite/src/Recorder.h"
using namespace skgpu;
DEF_GRAPHITE_TEST_FOR_CONTEXTS(ProgramCacheTest, reporter, context) {
Recorder recorder(sk_ref_sp(context));
auto cache = recorder.programCache();
REPORTER_ASSERT(reporter, cache->count() == 0);
// Add an initial unique program
sk_sp<ProgramCache::ProgramInfo> pi1;
{
Combination c1 { ShaderCombo::ShaderType::kNone, SkTileMode::kRepeat, SkBlendMode::kSrc };
pi1 = cache->findOrCreateProgram(c1);
REPORTER_ASSERT(reporter, pi1->id() != ProgramCache::kInvalidProgramID);
REPORTER_ASSERT(reporter, pi1->combo() == c1);
sk_sp<ProgramCache::ProgramInfo> lookup = cache->lookup(pi1->id());
REPORTER_ASSERT(reporter, lookup->id() == pi1->id());
REPORTER_ASSERT(reporter, cache->count() == 1);
}
// Try to add a duplicate program
{
Combination c2 { ShaderCombo::ShaderType::kNone, SkTileMode::kRepeat, SkBlendMode::kSrc };
sk_sp<ProgramCache::ProgramInfo> pi2 = cache->findOrCreateProgram(c2);
REPORTER_ASSERT(reporter, pi2->id() != ProgramCache::kInvalidProgramID);
REPORTER_ASSERT(reporter, pi2->id() == pi1->id());
REPORTER_ASSERT(reporter, pi2->combo() == c2);
sk_sp<ProgramCache::ProgramInfo> lookup = cache->lookup(pi2->id());
REPORTER_ASSERT(reporter, lookup->id() == pi2->id());
REPORTER_ASSERT(reporter, cache->count() == 1);
}
// Add a second unique program
{
Combination c3 { ShaderCombo::ShaderType::kLinearGradient,
SkTileMode::kRepeat,
SkBlendMode::kSrc };
sk_sp<ProgramCache::ProgramInfo> pi3 = cache->findOrCreateProgram(c3);
REPORTER_ASSERT(reporter, pi3->id() != ProgramCache::kInvalidProgramID);
REPORTER_ASSERT(reporter, pi3->id() != pi1->id());
REPORTER_ASSERT(reporter, pi3->combo() == c3);
sk_sp<ProgramCache::ProgramInfo> lookup = cache->lookup(pi3->id());
REPORTER_ASSERT(reporter, lookup->id() == pi3->id());
REPORTER_ASSERT(reporter, cache->count() == 2);
}
// TODO(robertphillips): expand this test to exercise more program variations
}