• 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,CtsEnforcement::kNextRelease)19 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(PipelineDataCacheTest, reporter, context,
20                                    CtsEnforcement::kNextRelease) {
21     std::unique_ptr<Recorder> recorder = context->makeRecorder();
22 
23     auto cache = recorder->priv().uniformDataCache();
24 
25     REPORTER_ASSERT(reporter, cache->count() == 0);
26 
27     static const int kSize = 16;
28 
29     // Add a new unique UDB
30     static const char kMemory1[kSize] = {
31             7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
32     };
33     UniformDataBlock udb1(SkSpan(kMemory1, kSize));
34     const UniformDataBlock* id1;
35     {
36         id1 = cache->insert(udb1);
37         REPORTER_ASSERT(reporter, SkToBool(id1));
38         REPORTER_ASSERT(reporter, id1 != &udb1);  // must be a separate address
39         REPORTER_ASSERT(reporter, *id1 == udb1);  // but equal contents
40 
41         REPORTER_ASSERT(reporter, cache->count() == 1);
42     }
43 
44     // Try to add a duplicate UDB
45     {
46         static const char kMemory2[kSize] = {
47                 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
48         };
49         UniformDataBlock udb2(SkSpan(kMemory2, kSize));
50         const UniformDataBlock* id2 = cache->insert(udb2);
51         REPORTER_ASSERT(reporter, id2 == id1);
52 
53         REPORTER_ASSERT(reporter, cache->count() == 1);
54     }
55 
56     // Add a second new unique UDB
57     {
58         static const char kMemory3[kSize] = {
59                 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
60         };
61         UniformDataBlock udb3(SkSpan(kMemory3, kSize));
62         const UniformDataBlock* id3 = cache->insert(udb3);
63         REPORTER_ASSERT(reporter, SkToBool(id3));
64         REPORTER_ASSERT(reporter, id3 != id1);
65         REPORTER_ASSERT(reporter, *id3 == udb3);
66 
67         REPORTER_ASSERT(reporter, cache->count() == 2);
68     }
69 
70     // TODO(robertphillips): expand this test to exercise all the UDB comparison failure modes
71 }
72