• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "tests/Test.h"
9 
10 #include "include/gpu/graphite/Context.h"
11 #include "include/gpu/graphite/Recorder.h"
12 #include "src/gpu/graphite/PipelineData.h"
13 #include "src/gpu/graphite/PipelineDataCache.h"
14 #include "src/gpu/graphite/RecorderPriv.h"
15 #include "src/gpu/graphite/Uniform.h"
16 
17 using namespace skgpu::graphite;
18 
DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(PipelineDataCacheTest,reporter,context)19 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(PipelineDataCacheTest, reporter, context) {
20     std::unique_ptr<Recorder> recorder = context->makeRecorder();
21 
22     auto cache = recorder->priv().uniformDataCache();
23 
24     REPORTER_ASSERT(reporter, cache->count() == 0);
25 
26     static const int kSize = 16;
27 
28     // Add a new unique UDB
29     static const char kMemory1[kSize] = {
30             7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
31     };
32     UniformDataBlock udb1(SkSpan(kMemory1, kSize));
33     const UniformDataBlock* id1;
34     {
35         id1 = cache->insert(udb1);
36         REPORTER_ASSERT(reporter, SkToBool(id1));
37         REPORTER_ASSERT(reporter, id1 != &udb1);  // must be a separate address
38         REPORTER_ASSERT(reporter, *id1 == udb1);  // but equal contents
39 
40         REPORTER_ASSERT(reporter, cache->count() == 1);
41     }
42 
43     // Try to add a duplicate UDB
44     {
45         static const char kMemory2[kSize] = {
46                 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
47         };
48         UniformDataBlock udb2(SkSpan(kMemory2, kSize));
49         const UniformDataBlock* id2 = cache->insert(udb2);
50         REPORTER_ASSERT(reporter, id2 == id1);
51 
52         REPORTER_ASSERT(reporter, cache->count() == 1);
53     }
54 
55     // Add a second new unique UDB
56     {
57         static const char kMemory3[kSize] = {
58                 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
59         };
60         UniformDataBlock udb3(SkSpan(kMemory3, kSize));
61         const UniformDataBlock* id3 = cache->insert(udb3);
62         REPORTER_ASSERT(reporter, SkToBool(id3));
63         REPORTER_ASSERT(reporter, id3 != id1);
64         REPORTER_ASSERT(reporter, *id3 == udb3);
65 
66         REPORTER_ASSERT(reporter, cache->count() == 2);
67     }
68 
69     // TODO(robertphillips): expand this test to exercise all the UDB comparison failure modes
70 }
71