1 //
2 // Copyright 2022 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 // AstcDecompressorPerf: Performance test for the ASTC decompressor.
7 //
8
9 #include "ANGLEPerfTest.h"
10
11 #include <gmock/gmock.h>
12
13 #include "common/WorkerThread.h"
14 #include "image_util/AstcDecompressor.h"
15 #include "image_util/AstcDecompressorTestUtils.h"
16
17 using namespace testing;
18
19 namespace
20 {
21 using angle::AstcDecompressor;
22 using angle::WorkerThreadPool;
23
24 struct AstcDecompressorParams
25 {
AstcDecompressorParams__anon4441e4e30111::AstcDecompressorParams26 AstcDecompressorParams(uint32_t width, uint32_t height) : width(width), height(height) {}
27
28 uint32_t width;
29 uint32_t height;
30 };
31
operator <<(std::ostream & os,const AstcDecompressorParams & params)32 std::ostream &operator<<(std::ostream &os, const AstcDecompressorParams ¶ms)
33 {
34 os << params.width << "x" << params.height;
35 return os;
36 }
37
38 class AstcDecompressorPerfTest : public ANGLEPerfTest,
39 public WithParamInterface<AstcDecompressorParams>
40 {
41 public:
42 AstcDecompressorPerfTest();
43
44 void step() override;
45
46 std::string getName();
47
48 AstcDecompressor &mDecompressor;
49 std::vector<uint8_t> mInput;
50 std::vector<uint8_t> mOutput;
51 std::shared_ptr<WorkerThreadPool> mSingleThreadPool;
52 std::shared_ptr<WorkerThreadPool> mMultiThreadPool;
53 };
54
AstcDecompressorPerfTest()55 AstcDecompressorPerfTest::AstcDecompressorPerfTest()
56 : ANGLEPerfTest(getName(), "", "_run", 1, "us"),
57 mDecompressor(AstcDecompressor::get()),
58 mInput(makeAstcCheckerboard(GetParam().width, GetParam().height)),
59 mOutput(GetParam().width * GetParam().height * 4),
60 mSingleThreadPool(WorkerThreadPool::Create(1, ANGLEPlatformCurrent())),
61 mMultiThreadPool(WorkerThreadPool::Create(0, ANGLEPlatformCurrent()))
62 {}
63
step()64 void AstcDecompressorPerfTest::step()
65 {
66 mDecompressor.decompress(mSingleThreadPool, mMultiThreadPool, GetParam().width,
67 GetParam().height, 8, 8, mInput.data(), mInput.size(), mOutput.data());
68 }
69
getName()70 std::string AstcDecompressorPerfTest::getName()
71 {
72 std::stringstream ss;
73 ss << UnitTest::GetInstance()->current_test_suite()->name() << "/" << GetParam();
74 return ss.str();
75 }
76
77 // Measures the speed of ASTC decompression on the CPU.
TEST_P(AstcDecompressorPerfTest,Run)78 TEST_P(AstcDecompressorPerfTest, Run)
79 {
80 if (!mDecompressor.available())
81 skipTest("ASTC decompressor not available");
82
83 this->run();
84 }
85
86 INSTANTIATE_TEST_SUITE_P(,
87 AstcDecompressorPerfTest,
88 Values(AstcDecompressorParams(16, 16),
89 AstcDecompressorParams(256, 256),
90 AstcDecompressorParams(1024, 1024)),
91 PrintToStringParamName());
92
93 } // anonymous namespace
94