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-01-21 15:41:54 +00:00
|
|
|
#include "src/core/SkUniform.h"
|
|
|
|
#include "src/core/SkUniformData.h"
|
2021-10-28 13:58:10 +00:00
|
|
|
|
|
|
|
using namespace skgpu;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2022-03-01 21:44:48 +00:00
|
|
|
std::unique_ptr<SkPipelineData> make_pd(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-01 21:44:48 +00:00
|
|
|
return std::make_unique<SkPipelineData>(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-01 21:44:48 +00:00
|
|
|
auto cache = recorder->priv().pipelineDataCache();
|
2021-10-28 13:58:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, cache->count() == 0);
|
|
|
|
|
2021-11-23 21:53:16 +00:00
|
|
|
// Nullptr should already be in the cache and return kInvalidUniformID
|
|
|
|
{
|
|
|
|
uint32_t result0 = cache->insert(nullptr);
|
2022-03-01 21:44:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, result0 == PipelineDataCache::kInvalidUniformID);
|
2021-11-23 21:53:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, cache->count() == 0);
|
|
|
|
}
|
|
|
|
|
2022-03-01 21:44:48 +00:00
|
|
|
// Add a new unique PD
|
|
|
|
SkPipelineData* danglingPD1 = nullptr;
|
2021-11-23 21:53:16 +00:00
|
|
|
uint32_t result1;
|
2021-10-28 13:58:10 +00:00
|
|
|
{
|
2022-03-01 21:44:48 +00:00
|
|
|
std::unique_ptr<SkPipelineData> pd1 = make_pd(2, 16);
|
|
|
|
danglingPD1 = pd1.get();
|
|
|
|
result1 = cache->insert(std::move(pd1));
|
|
|
|
REPORTER_ASSERT(reporter, result1 != PipelineDataCache::kInvalidUniformID);
|
|
|
|
SkPipelineData* lookup = cache->lookup(result1);
|
|
|
|
REPORTER_ASSERT(reporter, lookup == danglingPD1);
|
2021-10-28 13:58:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, cache->count() == 1);
|
|
|
|
}
|
|
|
|
|
2022-03-01 21:44:48 +00:00
|
|
|
// Try to add a duplicate PD
|
2021-10-28 13:58:10 +00:00
|
|
|
{
|
2022-03-01 21:44:48 +00:00
|
|
|
std::unique_ptr<SkPipelineData> pd2 = make_pd(2, 16);
|
|
|
|
SkPipelineData* danglingPD2 = pd2.get();
|
|
|
|
uint32_t result2 = cache->insert(std::move(pd2));
|
|
|
|
REPORTER_ASSERT(reporter, result2 != PipelineDataCache::kInvalidUniformID);
|
2021-11-23 21:53:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, result2 == result1);
|
2022-03-01 21:44:48 +00:00
|
|
|
SkPipelineData* lookup = cache->lookup(result2);
|
|
|
|
REPORTER_ASSERT(reporter, lookup != danglingPD2);
|
|
|
|
REPORTER_ASSERT(reporter, lookup == danglingPD1);
|
2021-10-28 13:58:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, cache->count() == 1);
|
|
|
|
}
|
|
|
|
|
2022-03-01 21:44:48 +00:00
|
|
|
// Add a second new unique PD
|
2021-10-28 13:58:10 +00:00
|
|
|
{
|
2022-03-01 21:44:48 +00:00
|
|
|
std::unique_ptr<SkPipelineData> pd3 = make_pd(3, 16);
|
|
|
|
SkPipelineData* danglingPD3 = pd3.get();
|
|
|
|
uint32_t result3 = cache->insert(std::move(pd3));
|
|
|
|
REPORTER_ASSERT(reporter, result3 != PipelineDataCache::kInvalidUniformID);
|
2021-11-23 21:53:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, result3 != result1);
|
2022-03-01 21:44:48 +00:00
|
|
|
SkPipelineData* lookup = cache->lookup(result3);
|
|
|
|
REPORTER_ASSERT(reporter, lookup == danglingPD3);
|
|
|
|
REPORTER_ASSERT(reporter, lookup != danglingPD1);
|
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
|
|
|
}
|