1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2023 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // RGBImageAllocationBenchmark:
7*8975f5c5SAndroid Build Coastguard Worker // GL_RGB8 image allocation and loading using GL_UNSIGNED_BYTE.
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard Worker #include "ANGLEPerfTest.h"
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker #include <iostream>
13*8975f5c5SAndroid Build Coastguard Worker #include <random>
14*8975f5c5SAndroid Build Coastguard Worker #include <sstream>
15*8975f5c5SAndroid Build Coastguard Worker
16*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/gl_raii.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "util/shader_utils.h"
18*8975f5c5SAndroid Build Coastguard Worker
19*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
20*8975f5c5SAndroid Build Coastguard Worker
21*8975f5c5SAndroid Build Coastguard Worker namespace
22*8975f5c5SAndroid Build Coastguard Worker {
23*8975f5c5SAndroid Build Coastguard Worker struct RGBImageAllocationParams final : public RenderTestParams
24*8975f5c5SAndroid Build Coastguard Worker {
RGBImageAllocationParams__anon7d937d990111::RGBImageAllocationParams25*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationParams() { iterationsPerStep = 1; }
26*8975f5c5SAndroid Build Coastguard Worker
27*8975f5c5SAndroid Build Coastguard Worker std::string story() const override;
28*8975f5c5SAndroid Build Coastguard Worker
29*8975f5c5SAndroid Build Coastguard Worker // Used to indicate whether the tested source pointer should be 4-byte-aligned.
30*8975f5c5SAndroid Build Coastguard Worker bool aligned;
31*8975f5c5SAndroid Build Coastguard Worker size_t textureSize;
32*8975f5c5SAndroid Build Coastguard Worker };
33*8975f5c5SAndroid Build Coastguard Worker
operator <<(std::ostream & os,const RGBImageAllocationParams & params)34*8975f5c5SAndroid Build Coastguard Worker std::ostream &operator<<(std::ostream &os, const RGBImageAllocationParams ¶ms)
35*8975f5c5SAndroid Build Coastguard Worker {
36*8975f5c5SAndroid Build Coastguard Worker return os << params.backendAndStory().substr(1);
37*8975f5c5SAndroid Build Coastguard Worker }
38*8975f5c5SAndroid Build Coastguard Worker
story() const39*8975f5c5SAndroid Build Coastguard Worker std::string RGBImageAllocationParams::story() const
40*8975f5c5SAndroid Build Coastguard Worker {
41*8975f5c5SAndroid Build Coastguard Worker std::stringstream strstr;
42*8975f5c5SAndroid Build Coastguard Worker
43*8975f5c5SAndroid Build Coastguard Worker strstr << RenderTestParams::story() << "_size" << textureSize
44*8975f5c5SAndroid Build Coastguard Worker << (aligned ? "_4bytealigned_src" : "_non4bytealigned_src");
45*8975f5c5SAndroid Build Coastguard Worker
46*8975f5c5SAndroid Build Coastguard Worker return strstr.str();
47*8975f5c5SAndroid Build Coastguard Worker }
48*8975f5c5SAndroid Build Coastguard Worker
49*8975f5c5SAndroid Build Coastguard Worker struct RGBColor
50*8975f5c5SAndroid Build Coastguard Worker {
RGBColor__anon7d937d990111::RGBColor51*8975f5c5SAndroid Build Coastguard Worker RGBColor() : r(0), g(0), b(0) {}
RGBColor__anon7d937d990111::RGBColor52*8975f5c5SAndroid Build Coastguard Worker RGBColor(uint8_t r, uint8_t g, uint8_t b) : r(r), g(g), b(b) {}
53*8975f5c5SAndroid Build Coastguard Worker uint8_t r;
54*8975f5c5SAndroid Build Coastguard Worker uint8_t g;
55*8975f5c5SAndroid Build Coastguard Worker uint8_t b;
56*8975f5c5SAndroid Build Coastguard Worker };
57*8975f5c5SAndroid Build Coastguard Worker
58*8975f5c5SAndroid Build Coastguard Worker class RGBImageAllocationBenchmark : public ANGLERenderTest,
59*8975f5c5SAndroid Build Coastguard Worker public ::testing::WithParamInterface<RGBImageAllocationParams>
60*8975f5c5SAndroid Build Coastguard Worker {
61*8975f5c5SAndroid Build Coastguard Worker public:
62*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationBenchmark();
63*8975f5c5SAndroid Build Coastguard Worker
64*8975f5c5SAndroid Build Coastguard Worker void initializeBenchmark() override;
65*8975f5c5SAndroid Build Coastguard Worker void drawBenchmark() override;
66*8975f5c5SAndroid Build Coastguard Worker void destroyBenchmark() override;
67*8975f5c5SAndroid Build Coastguard Worker
68*8975f5c5SAndroid Build Coastguard Worker protected:
69*8975f5c5SAndroid Build Coastguard Worker std::vector<RGBColor> mColors;
70*8975f5c5SAndroid Build Coastguard Worker GLuint mTexture;
71*8975f5c5SAndroid Build Coastguard Worker size_t mOffset;
72*8975f5c5SAndroid Build Coastguard Worker size_t mTextureSize;
73*8975f5c5SAndroid Build Coastguard Worker };
74*8975f5c5SAndroid Build Coastguard Worker
RGBImageAllocationBenchmark()75*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationBenchmark::RGBImageAllocationBenchmark()
76*8975f5c5SAndroid Build Coastguard Worker : ANGLERenderTest("RGBImageAllocation", GetParam())
77*8975f5c5SAndroid Build Coastguard Worker {
78*8975f5c5SAndroid Build Coastguard Worker mOffset = (GetParam().aligned) ? 0 : 1;
79*8975f5c5SAndroid Build Coastguard Worker mTextureSize = GetParam().textureSize;
80*8975f5c5SAndroid Build Coastguard Worker }
81*8975f5c5SAndroid Build Coastguard Worker
initializeBenchmark()82*8975f5c5SAndroid Build Coastguard Worker void RGBImageAllocationBenchmark::initializeBenchmark()
83*8975f5c5SAndroid Build Coastguard Worker {
84*8975f5c5SAndroid Build Coastguard Worker // Initialize texture. The size in this test should be set to a power of two for easier data
85*8975f5c5SAndroid Build Coastguard Worker // allocation and avoiding alignment issues.
86*8975f5c5SAndroid Build Coastguard Worker ASSERT(gl::isPow2(mTextureSize));
87*8975f5c5SAndroid Build Coastguard Worker glGenTextures(1, &mTexture);
88*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, mTexture);
89*8975f5c5SAndroid Build Coastguard Worker glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, mTextureSize, mTextureSize);
90*8975f5c5SAndroid Build Coastguard Worker
91*8975f5c5SAndroid Build Coastguard Worker // Initialize color data. It is expected for the color data pointer to be 4-byte-aligned. If
92*8975f5c5SAndroid Build Coastguard Worker // necessary, an extra pixel is allocated in the beginning to test the non-aligned case.
93*8975f5c5SAndroid Build Coastguard Worker ASSERT(reinterpret_cast<uintptr_t>(mColors.data()) % 4 == 0);
94*8975f5c5SAndroid Build Coastguard Worker mColors.resize(mOffset + mTextureSize * mTextureSize);
95*8975f5c5SAndroid Build Coastguard Worker for (size_t i = 0; i < mTextureSize * mTextureSize; i++)
96*8975f5c5SAndroid Build Coastguard Worker {
97*8975f5c5SAndroid Build Coastguard Worker mColors[mOffset + i] = RGBColor(1, 2, 3);
98*8975f5c5SAndroid Build Coastguard Worker }
99*8975f5c5SAndroid Build Coastguard Worker }
100*8975f5c5SAndroid Build Coastguard Worker
destroyBenchmark()101*8975f5c5SAndroid Build Coastguard Worker void RGBImageAllocationBenchmark::destroyBenchmark()
102*8975f5c5SAndroid Build Coastguard Worker {
103*8975f5c5SAndroid Build Coastguard Worker glDeleteTextures(1, &mTexture);
104*8975f5c5SAndroid Build Coastguard Worker }
105*8975f5c5SAndroid Build Coastguard Worker
drawBenchmark()106*8975f5c5SAndroid Build Coastguard Worker void RGBImageAllocationBenchmark::drawBenchmark()
107*8975f5c5SAndroid Build Coastguard Worker {
108*8975f5c5SAndroid Build Coastguard Worker // Copy the next color data.
109*8975f5c5SAndroid Build Coastguard Worker glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mTextureSize, mTextureSize, GL_RGB, GL_UNSIGNED_BYTE,
110*8975f5c5SAndroid Build Coastguard Worker mColors.data() + mOffset);
111*8975f5c5SAndroid Build Coastguard Worker glFinish();
112*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
113*8975f5c5SAndroid Build Coastguard Worker }
114*8975f5c5SAndroid Build Coastguard Worker
VulkanParams(bool aligned,size_t textureSize)115*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationParams VulkanParams(bool aligned, size_t textureSize)
116*8975f5c5SAndroid Build Coastguard Worker {
117*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationParams params;
118*8975f5c5SAndroid Build Coastguard Worker params.eglParameters = egl_platform::VULKAN();
119*8975f5c5SAndroid Build Coastguard Worker params.majorVersion = 3;
120*8975f5c5SAndroid Build Coastguard Worker params.minorVersion = 0;
121*8975f5c5SAndroid Build Coastguard Worker params.aligned = aligned;
122*8975f5c5SAndroid Build Coastguard Worker params.textureSize = textureSize;
123*8975f5c5SAndroid Build Coastguard Worker return params;
124*8975f5c5SAndroid Build Coastguard Worker }
125*8975f5c5SAndroid Build Coastguard Worker
OpenGLOrGLESParams(bool aligned,size_t textureSize)126*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationParams OpenGLOrGLESParams(bool aligned, size_t textureSize)
127*8975f5c5SAndroid Build Coastguard Worker {
128*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationParams params;
129*8975f5c5SAndroid Build Coastguard Worker params.eglParameters = egl_platform::OPENGL_OR_GLES();
130*8975f5c5SAndroid Build Coastguard Worker params.majorVersion = 3;
131*8975f5c5SAndroid Build Coastguard Worker params.minorVersion = 0;
132*8975f5c5SAndroid Build Coastguard Worker params.aligned = aligned;
133*8975f5c5SAndroid Build Coastguard Worker params.textureSize = textureSize;
134*8975f5c5SAndroid Build Coastguard Worker return params;
135*8975f5c5SAndroid Build Coastguard Worker }
136*8975f5c5SAndroid Build Coastguard Worker
MetalParams(bool aligned,size_t textureSize)137*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationParams MetalParams(bool aligned, size_t textureSize)
138*8975f5c5SAndroid Build Coastguard Worker {
139*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationParams params;
140*8975f5c5SAndroid Build Coastguard Worker params.eglParameters = egl_platform::METAL();
141*8975f5c5SAndroid Build Coastguard Worker params.majorVersion = 3;
142*8975f5c5SAndroid Build Coastguard Worker params.minorVersion = 0;
143*8975f5c5SAndroid Build Coastguard Worker params.aligned = aligned;
144*8975f5c5SAndroid Build Coastguard Worker params.textureSize = textureSize;
145*8975f5c5SAndroid Build Coastguard Worker return params;
146*8975f5c5SAndroid Build Coastguard Worker }
147*8975f5c5SAndroid Build Coastguard Worker
D3D11Params(bool aligned,size_t textureSize)148*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationParams D3D11Params(bool aligned, size_t textureSize)
149*8975f5c5SAndroid Build Coastguard Worker {
150*8975f5c5SAndroid Build Coastguard Worker RGBImageAllocationParams params;
151*8975f5c5SAndroid Build Coastguard Worker params.eglParameters = egl_platform::D3D11();
152*8975f5c5SAndroid Build Coastguard Worker params.majorVersion = 3;
153*8975f5c5SAndroid Build Coastguard Worker params.minorVersion = 0;
154*8975f5c5SAndroid Build Coastguard Worker params.aligned = aligned;
155*8975f5c5SAndroid Build Coastguard Worker params.textureSize = textureSize;
156*8975f5c5SAndroid Build Coastguard Worker return params;
157*8975f5c5SAndroid Build Coastguard Worker }
158*8975f5c5SAndroid Build Coastguard Worker
159*8975f5c5SAndroid Build Coastguard Worker } // anonymous namespace
160*8975f5c5SAndroid Build Coastguard Worker
161*8975f5c5SAndroid Build Coastguard Worker // Runs the test to measure the performance of RGB8 image allocation and loading.
TEST_P(RGBImageAllocationBenchmark,Run)162*8975f5c5SAndroid Build Coastguard Worker TEST_P(RGBImageAllocationBenchmark, Run)
163*8975f5c5SAndroid Build Coastguard Worker {
164*8975f5c5SAndroid Build Coastguard Worker run();
165*8975f5c5SAndroid Build Coastguard Worker }
166*8975f5c5SAndroid Build Coastguard Worker
167*8975f5c5SAndroid Build Coastguard Worker using namespace params;
168*8975f5c5SAndroid Build Coastguard Worker
169*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(RGBImageAllocationBenchmark,
170*8975f5c5SAndroid Build Coastguard Worker VulkanParams(true, 256),
171*8975f5c5SAndroid Build Coastguard Worker VulkanParams(true, 2048),
172*8975f5c5SAndroid Build Coastguard Worker VulkanParams(false, 2048),
173*8975f5c5SAndroid Build Coastguard Worker OpenGLOrGLESParams(true, 256),
174*8975f5c5SAndroid Build Coastguard Worker OpenGLOrGLESParams(true, 2048),
175*8975f5c5SAndroid Build Coastguard Worker OpenGLOrGLESParams(false, 2048),
176*8975f5c5SAndroid Build Coastguard Worker MetalParams(true, 256),
177*8975f5c5SAndroid Build Coastguard Worker MetalParams(true, 2048),
178*8975f5c5SAndroid Build Coastguard Worker MetalParams(false, 2048),
179*8975f5c5SAndroid Build Coastguard Worker D3D11Params(true, 256),
180*8975f5c5SAndroid Build Coastguard Worker D3D11Params(true, 2048),
181*8975f5c5SAndroid Build Coastguard Worker D3D11Params(false, 2048));
182