• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // VulkanPipelineCachePerf:
7 //   Performance benchmark for the Vulkan Pipeline cache.
8 
9 #include "ANGLEPerfTest.h"
10 
11 #include "libANGLE/renderer/vulkan/vk_cache_utils.h"
12 #include "libANGLE/renderer/vulkan/vk_helpers.h"
13 #include "util/random_utils.h"
14 
15 using namespace rx;
16 
17 namespace
18 {
19 constexpr unsigned int kIterationsPerStep = 100;
20 
21 class VulkanPipelineCachePerfTest : public ANGLEPerfTest
22 {
23   public:
24     VulkanPipelineCachePerfTest();
25     ~VulkanPipelineCachePerfTest();
26 
27     void SetUp() override;
28     void step() override;
29 
30     GraphicsPipelineCache mCache;
31     angle::RNG mRNG;
32 
33     std::vector<vk::GraphicsPipelineDesc> mCacheHits;
34     std::vector<vk::GraphicsPipelineDesc> mCacheMisses;
35     size_t mMissIndex = 0;
36 
37   private:
38     void randomizeDesc(vk::GraphicsPipelineDesc *desc);
39 };
40 
VulkanPipelineCachePerfTest()41 VulkanPipelineCachePerfTest::VulkanPipelineCachePerfTest()
42     : ANGLEPerfTest("VulkanPipelineCachePerf", "", "", kIterationsPerStep)
43 {}
44 
~VulkanPipelineCachePerfTest()45 VulkanPipelineCachePerfTest::~VulkanPipelineCachePerfTest()
46 {
47     mCache.destroy(VK_NULL_HANDLE);
48 }
49 
SetUp()50 void VulkanPipelineCachePerfTest::SetUp()
51 {
52     // Insert a number of random pipeline states.
53     for (int pipelineCount = 0; pipelineCount < 100; ++pipelineCount)
54     {
55         vk::Pipeline pipeline;
56         vk::GraphicsPipelineDesc desc;
57         randomizeDesc(&desc);
58 
59         if (pipelineCount < 10)
60         {
61             mCacheHits.push_back(desc);
62         }
63         mCache.populate(desc, std::move(pipeline));
64     }
65 
66     for (int missCount = 0; missCount < 10000; ++missCount)
67     {
68         vk::GraphicsPipelineDesc desc;
69         randomizeDesc(&desc);
70         mCacheMisses.push_back(desc);
71     }
72 }
73 
randomizeDesc(vk::GraphicsPipelineDesc * desc)74 void VulkanPipelineCachePerfTest::randomizeDesc(vk::GraphicsPipelineDesc *desc)
75 {
76     std::vector<uint8_t> bytes(sizeof(vk::GraphicsPipelineDesc));
77     FillVectorWithRandomUBytes(&mRNG, &bytes);
78     memcpy(desc, bytes.data(), sizeof(vk::GraphicsPipelineDesc));
79 }
80 
step()81 void VulkanPipelineCachePerfTest::step()
82 {
83     vk::RenderPass rp;
84     vk::PipelineLayout pl;
85     vk::PipelineCache pc;
86     vk::ShaderAndSerialMap ssm;
87     const vk::GraphicsPipelineDesc *desc = nullptr;
88     vk::PipelineHelper *result           = nullptr;
89     gl::AttributesMask am;
90     gl::ComponentTypeMask ctm;
91     gl::DrawBufferMask dbm;
92 
93     // The Vulkan handle types are difficult to cast to without #ifdefs.
94     VkShaderModule vs = (VkShaderModule)1;
95     VkShaderModule fs = (VkShaderModule)2;
96     ssm[gl::ShaderType::Vertex].get().get().setHandle(vs);
97     ssm[gl::ShaderType::Fragment].get().get().setHandle(fs);
98 
99     vk::SpecializationConstants defaultSpecConsts{};
100 
101     for (unsigned int iteration = 0; iteration < kIterationsPerStep; ++iteration)
102     {
103         for (const auto &hit : mCacheHits)
104         {
105             (void)mCache.getPipeline(VK_NULL_HANDLE, pc, rp, pl, am, ctm, dbm, ssm,
106                                      defaultSpecConsts, hit, &desc, &result);
107         }
108     }
109 
110     for (int missCount = 0; missCount < 20 && mMissIndex < mCacheMisses.size();
111          ++missCount, ++mMissIndex)
112     {
113         const auto &miss = mCacheMisses[mMissIndex];
114         (void)mCache.getPipeline(VK_NULL_HANDLE, pc, rp, pl, am, ctm, dbm, ssm, defaultSpecConsts,
115                                  miss, &desc, &result);
116     }
117 }
118 
119 }  // anonymous namespace
120 
TEST_F(VulkanPipelineCachePerfTest,Run)121 TEST_F(VulkanPipelineCachePerfTest, Run)
122 {
123     run();
124 }
125