Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/perf_tests/VulkanPipelineCachePerf.cpp
1693 views
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
41
VulkanPipelineCachePerfTest::VulkanPipelineCachePerfTest()
42
: ANGLEPerfTest("VulkanPipelineCachePerf", "", "", kIterationsPerStep)
43
{}
44
45
VulkanPipelineCachePerfTest::~VulkanPipelineCachePerfTest()
46
{
47
mCache.destroy(VK_NULL_HANDLE);
48
}
49
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
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
81
void VulkanPipelineCachePerfTest::step()
82
{
83
vk::RenderPass rp;
84
vk::PipelineLayout pl;
85
vk::PipelineCache pc;
86
vk::ShaderModule sm;
87
const vk::GraphicsPipelineDesc *desc = nullptr;
88
vk::PipelineHelper *result = nullptr;
89
gl::AttributesMask am;
90
gl::ComponentTypeMask ctm;
91
92
vk::SpecializationConstants defaultSpecConsts{};
93
94
for (unsigned int iteration = 0; iteration < kIterationsPerStep; ++iteration)
95
{
96
for (const auto &hit : mCacheHits)
97
{
98
(void)mCache.getPipeline(VK_NULL_HANDLE, pc, rp, pl, am, ctm, &sm, &sm, nullptr,
99
nullptr, nullptr, defaultSpecConsts, hit, &desc, &result);
100
}
101
}
102
103
for (int missCount = 0; missCount < 20 && mMissIndex < mCacheMisses.size();
104
++missCount, ++mMissIndex)
105
{
106
const auto &miss = mCacheMisses[mMissIndex];
107
(void)mCache.getPipeline(VK_NULL_HANDLE, pc, rp, pl, am, ctm, &sm, &sm, nullptr, nullptr,
108
nullptr, defaultSpecConsts, miss, &desc, &result);
109
}
110
}
111
112
} // anonymous namespace
113
114
TEST_F(VulkanPipelineCachePerfTest, Run)
115
{
116
run();
117
}
118
119