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-03-21 17:23:56 +00:00
|
|
|
std::unique_ptr<SkUniformDataBlock> make_udb(int numUniforms, int dataSize) {
|
2021-10-28 13:58:10 +00:00
|
|
|
static constexpr int kMaxUniforms = 3;
|
2022-01-21 15:41:54 +00:00
|
|
|
static constexpr SkUniform kUniforms[kMaxUniforms] {
|
|
|
|
{"point0", SkSLType::kFloat2 },
|
|
|
|
{"point1", SkSLType::kFloat2 },
|
|
|
|
{"point2", SkSLType::kFloat2 },
|
2021-10-28 13:58:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkASSERT(numUniforms <= kMaxUniforms);
|
|
|
|
|
2022-02-02 14:52:50 +00:00
|
|
|
sk_sp<SkUniformData> ud = SkUniformData::Make(SkSpan<const SkUniform>(kUniforms, numUniforms),
|
|
|
|
dataSize);
|
2021-10-28 13:58:10 +00:00
|
|
|
for (int i = 0; i < numUniforms; ++i) {
|
|
|
|
ud->offsets()[i] = i;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < dataSize; ++i) {
|
|
|
|
ud->data()[i] = i % 255;
|
|
|
|
}
|
|
|
|
|
2022-03-21 17:23:56 +00:00
|
|
|
return std::make_unique<SkUniformDataBlock>(std::move(ud));
|
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());
|
|
|
|
|
|
|
|
SkUniformDataBlock* lookup = cache->lookup(invalid);
|
|
|
|
REPORTER_ASSERT(reporter, !lookup);
|
2021-11-23 21:53:16 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 17:23:56 +00:00
|
|
|
// Add a new unique UDB
|
|
|
|
std::unique_ptr<SkUniformDataBlock> udb1 = make_udb(2, 16);
|
|
|
|
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());
|
|
|
|
SkUniformDataBlock* lookup = cache->lookup(id1);
|
|
|
|
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-03-21 17:23:56 +00:00
|
|
|
std::unique_ptr<SkUniformDataBlock> udb2 = make_udb(2, 16);
|
|
|
|
UniformDataCache::Index id2 = cache->insert(*udb2);
|
|
|
|
REPORTER_ASSERT(reporter, id2.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, id2 == id1);
|
|
|
|
SkUniformDataBlock* lookup = cache->lookup(id2);
|
|
|
|
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-03-21 17:23:56 +00:00
|
|
|
std::unique_ptr<SkUniformDataBlock> udb3 = make_udb(3, 16);
|
|
|
|
UniformDataCache::Index id3 = cache->insert(*udb3);
|
|
|
|
REPORTER_ASSERT(reporter, id3.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, id3 != id1);
|
|
|
|
SkUniformDataBlock* lookup = cache->lookup(id3);
|
|
|
|
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-03-01 21:44:48 +00:00
|
|
|
// TODO(robertphillips): expand this test to exercise all the PD comparison failure modes
|
2021-10-28 13:58:10 +00:00
|
|
|
}
|