2021-10-28 13:58:10 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2021-12-02 15:39:33 +00:00
|
|
|
#include "experimental/graphite/include/Recorder.h"
|
2022-03-01 21:44:48 +00:00
|
|
|
#include "experimental/graphite/src/PipelineDataCache.h"
|
2022-02-04 20:47:51 +00:00
|
|
|
#include "experimental/graphite/src/RecorderPriv.h"
|
2022-03-04 19:00:04 +00:00
|
|
|
#include "src/core/SkPipelineData.h"
|
2022-01-21 15:41:54 +00:00
|
|
|
#include "src/core/SkUniform.h"
|
2021-10-28 13:58:10 +00:00
|
|
|
|
|
|
|
using namespace skgpu;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2022-04-06 15:30:31 +00:00
|
|
|
std::unique_ptr<SkUniformDataBlock> make_udb(const char* data, size_t size) {
|
2022-04-06 19:08:57 +00:00
|
|
|
return std::make_unique<SkUniformDataBlock>(SkMakeSpan(data, size), false);
|
2021-10-28 13:58:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2022-03-01 21:44:48 +00:00
|
|
|
DEF_GRAPHITE_TEST_FOR_CONTEXTS(PipelineDataCacheTest, reporter, context) {
|
2022-01-13 14:51:23 +00:00
|
|
|
std::unique_ptr<Recorder> recorder = context->makeRecorder();
|
2021-10-28 13:58:10 +00:00
|
|
|
|
2022-03-21 17:23:56 +00:00
|
|
|
auto cache = recorder->priv().uniformDataCache();
|
2021-10-28 13:58:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, cache->count() == 0);
|
|
|
|
|
2022-03-21 17:23:56 +00:00
|
|
|
// Nullptr should already be in the cache
|
2021-11-23 21:53:16 +00:00
|
|
|
{
|
2022-03-21 17:23:56 +00:00
|
|
|
UniformDataCache::Index invalid;
|
|
|
|
REPORTER_ASSERT(reporter, !invalid.isValid());
|
|
|
|
|
2022-04-05 17:26:57 +00:00
|
|
|
const SkUniformDataBlock* lookup = cache->lookup(invalid);
|
2022-03-21 17:23:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, !lookup);
|
2021-11-23 21:53:16 +00:00
|
|
|
}
|
|
|
|
|
2022-04-06 15:30:31 +00:00
|
|
|
static const int kSize = 16;
|
|
|
|
|
2022-03-21 17:23:56 +00:00
|
|
|
// Add a new unique UDB
|
2022-04-06 15:30:31 +00:00
|
|
|
static const char kMemory1[kSize] = {
|
|
|
|
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
|
|
|
|
};
|
|
|
|
std::unique_ptr<SkUniformDataBlock> udb1 = make_udb(kMemory1, kSize);
|
2022-03-21 17:23:56 +00:00
|
|
|
UniformDataCache::Index id1;
|
2021-10-28 13:58:10 +00:00
|
|
|
{
|
2022-03-21 17:23:56 +00:00
|
|
|
id1 = cache->insert(*udb1);
|
|
|
|
REPORTER_ASSERT(reporter, id1.isValid());
|
2022-04-05 17:26:57 +00:00
|
|
|
const SkUniformDataBlock* lookup = cache->lookup(id1);
|
2022-03-21 17:23:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, *lookup == *udb1);
|
2021-10-28 13:58:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, cache->count() == 1);
|
|
|
|
}
|
|
|
|
|
2022-03-21 17:23:56 +00:00
|
|
|
// Try to add a duplicate UDB
|
2021-10-28 13:58:10 +00:00
|
|
|
{
|
2022-04-06 15:30:31 +00:00
|
|
|
static const char kMemory2[kSize] = {
|
|
|
|
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
|
|
|
|
};
|
|
|
|
std::unique_ptr<SkUniformDataBlock> udb2 = make_udb(kMemory2, kSize);
|
2022-03-21 17:23:56 +00:00
|
|
|
UniformDataCache::Index id2 = cache->insert(*udb2);
|
|
|
|
REPORTER_ASSERT(reporter, id2.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, id2 == id1);
|
2022-04-05 17:26:57 +00:00
|
|
|
const SkUniformDataBlock* lookup = cache->lookup(id2);
|
2022-03-21 17:23:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, *lookup == *udb1);
|
|
|
|
REPORTER_ASSERT(reporter, *lookup == *udb2);
|
2021-10-28 13:58:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, cache->count() == 1);
|
|
|
|
}
|
|
|
|
|
2022-03-21 17:23:56 +00:00
|
|
|
// Add a second new unique UDB
|
2021-10-28 13:58:10 +00:00
|
|
|
{
|
2022-04-06 15:30:31 +00:00
|
|
|
static const char kMemory3[kSize] = {
|
|
|
|
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
|
|
|
|
};
|
|
|
|
std::unique_ptr<SkUniformDataBlock> udb3 = make_udb(kMemory3, kSize);
|
2022-03-21 17:23:56 +00:00
|
|
|
UniformDataCache::Index id3 = cache->insert(*udb3);
|
|
|
|
REPORTER_ASSERT(reporter, id3.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, id3 != id1);
|
2022-04-05 17:26:57 +00:00
|
|
|
const SkUniformDataBlock* lookup = cache->lookup(id3);
|
2022-03-21 17:23:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, *lookup == *udb3);
|
|
|
|
REPORTER_ASSERT(reporter, *lookup != *udb1);
|
2021-10-28 13:58:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, cache->count() == 2);
|
|
|
|
}
|
|
|
|
|
2022-04-01 20:37:47 +00:00
|
|
|
// TODO(robertphillips): expand this test to exercise all the UDB comparison failure modes
|
2021-10-28 13:58:10 +00:00
|
|
|
}
|