Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/perf_tests/MultisampledRenderToTexturePerf.cpp
1693 views
1
//
2
// Copyright 2020 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
// MultisampledRenderToTextureBenchmark:
7
// Performance test for rendering to multisampled-render-to-texture attachments.
8
//
9
10
#include "ANGLEPerfTest.h"
11
12
#include <iostream>
13
#include <random>
14
#include <sstream>
15
16
#include "test_utils/gl_raii.h"
17
#include "util/shader_utils.h"
18
19
using namespace angle;
20
21
namespace
22
{
23
constexpr uint32_t kMultipassPassCount = 5;
24
25
struct MultisampledRenderToTextureParams final : public RenderTestParams
26
{
27
MultisampledRenderToTextureParams()
28
{
29
iterationsPerStep = 1;
30
trackGpuTime = true;
31
32
textureWidth = 1920;
33
textureHeight = 1080;
34
35
multiplePasses = false;
36
withDepthStencil = false;
37
}
38
39
std::string story() const override;
40
41
GLsizei textureWidth;
42
GLsizei textureHeight;
43
44
bool multiplePasses;
45
bool withDepthStencil;
46
};
47
48
std::ostream &operator<<(std::ostream &os, const MultisampledRenderToTextureParams &params)
49
{
50
return os << params.backendAndStory().substr(1);
51
}
52
53
std::string MultisampledRenderToTextureParams::story() const
54
{
55
std::stringstream strstr;
56
57
strstr << RenderTestParams::story();
58
59
if (multiplePasses)
60
{
61
strstr << "_multipass";
62
}
63
64
if (withDepthStencil)
65
{
66
strstr << "_ds";
67
}
68
69
return strstr.str();
70
}
71
72
class MultisampledRenderToTextureBenchmark
73
: public ANGLERenderTest,
74
public ::testing::WithParamInterface<MultisampledRenderToTextureParams>
75
{
76
public:
77
MultisampledRenderToTextureBenchmark();
78
79
void initializeBenchmark() override;
80
void destroyBenchmark() override;
81
void drawBenchmark() override;
82
83
protected:
84
void initShaders();
85
86
GLuint mFramebuffer = 0;
87
GLuint mProgram = 0;
88
GLuint mColorTexture = 0;
89
GLuint mDepthStencilRenderbuffer = 0;
90
91
std::vector<uint8_t> mTextureData;
92
};
93
94
MultisampledRenderToTextureBenchmark::MultisampledRenderToTextureBenchmark()
95
: ANGLERenderTest("MultisampledRenderToTexture", GetParam())
96
{
97
// Crashes on nvidia+d3d11. http://crbug.com/945415
98
if (GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
99
{
100
mSkipTest = true;
101
}
102
103
// Fails on Windows7 NVIDIA Vulkan, presumably due to old drivers. http://crbug.com/1096510
104
if (IsWindows7() && IsNVIDIA() &&
105
GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
106
{
107
mSkipTest = true;
108
}
109
110
// Fails on Pixel 4 GLES: http://anglebug.com/5120
111
if (IsPixel4() && GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
112
{
113
mSkipTest = true;
114
}
115
116
// http://anglebug.com/5380
117
if (IsLinux() && IsAMD() &&
118
GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE &&
119
GetParam().multiplePasses && GetParam().withDepthStencil)
120
{
121
mSkipTest = true;
122
}
123
124
// http://anglebug.com/6319
125
if (IsLinux() && IsIntel() &&
126
GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
127
{
128
mSkipTest = true;
129
}
130
}
131
132
void MultisampledRenderToTextureBenchmark::initializeBenchmark()
133
{
134
if (!IsGLExtensionEnabled("GL_EXT_multisampled_render_to_texture"))
135
{
136
mSkipTest = true;
137
return;
138
}
139
140
const auto &params = GetParam();
141
142
initShaders();
143
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
144
glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
145
146
glGenFramebuffers(1, &mFramebuffer);
147
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
148
149
glGenTextures(1, &mColorTexture);
150
glBindTexture(GL_TEXTURE_2D, mColorTexture);
151
152
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, params.textureWidth, params.textureHeight, 0, GL_RGBA,
153
GL_UNSIGNED_BYTE, nullptr);
154
glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
155
mColorTexture, 0, 4);
156
157
if (params.withDepthStencil)
158
{
159
glGenRenderbuffers(1, &mDepthStencilRenderbuffer);
160
glBindRenderbuffer(GL_RENDERBUFFER, mDepthStencilRenderbuffer);
161
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8,
162
params.textureWidth, params.textureHeight);
163
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
164
mDepthStencilRenderbuffer);
165
}
166
167
ASSERT_GL_NO_ERROR();
168
}
169
170
void MultisampledRenderToTextureBenchmark::initShaders()
171
{
172
constexpr char kVS[] = R"(void main()
173
{
174
gl_Position = vec4(0, 0, 0, 1);
175
})";
176
177
constexpr char kFS[] = R"(precision mediump float;
178
void main()
179
{
180
gl_FragColor = vec4(0);
181
})";
182
183
mProgram = CompileProgram(kVS, kFS);
184
ASSERT_NE(0u, mProgram);
185
186
glUseProgram(mProgram);
187
188
ASSERT_GL_NO_ERROR();
189
}
190
191
void MultisampledRenderToTextureBenchmark::destroyBenchmark()
192
{
193
glDeleteFramebuffers(1, &mFramebuffer);
194
glDeleteRenderbuffers(1, &mDepthStencilRenderbuffer);
195
glDeleteTextures(1, &mColorTexture);
196
glDeleteProgram(mProgram);
197
}
198
199
void MultisampledRenderToTextureBenchmark::drawBenchmark()
200
{
201
const auto &params = GetParam();
202
203
GLTexture mMockTexture;
204
glBindTexture(GL_TEXTURE_2D, mMockTexture);
205
206
startGpuTimer();
207
208
// Initially clear the color attachment to avoid having to load from the resolved image. The
209
// depth/stencil attachment doesn't need this as it's contents are always undefined between
210
// render passes.
211
glClear(GL_COLOR_BUFFER_BIT);
212
213
const uint32_t passCount = params.multiplePasses ? kMultipassPassCount : 1;
214
for (uint32_t pass = 0; pass < passCount; ++pass)
215
{
216
// Perform a draw just to have something in the render pass. With the position attributes
217
// not set, a constant default value is used, resulting in a very cheap draw.
218
glDrawArrays(GL_TRIANGLES, 0, 3);
219
220
// Force the render pass to break by cheaply reading back from the color attachment.
221
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0);
222
}
223
stopGpuTimer();
224
225
ASSERT_GL_NO_ERROR();
226
}
227
228
MultisampledRenderToTextureParams D3D11Params(bool multiplePasses, bool withDepthStencil)
229
{
230
MultisampledRenderToTextureParams params;
231
params.eglParameters = egl_platform::D3D11();
232
params.majorVersion = 3;
233
params.minorVersion = 0;
234
params.multiplePasses = multiplePasses;
235
params.withDepthStencil = withDepthStencil;
236
return params;
237
}
238
239
MultisampledRenderToTextureParams OpenGLOrGLESParams(bool multiplePasses, bool withDepthStencil)
240
{
241
MultisampledRenderToTextureParams params;
242
params.eglParameters = egl_platform::OPENGL_OR_GLES();
243
params.majorVersion = 3;
244
params.minorVersion = 0;
245
params.multiplePasses = multiplePasses;
246
params.withDepthStencil = withDepthStencil;
247
return params;
248
}
249
250
MultisampledRenderToTextureParams VulkanParams(bool multiplePasses, bool withDepthStencil)
251
{
252
MultisampledRenderToTextureParams params;
253
params.eglParameters = egl_platform::VULKAN();
254
params.majorVersion = 3;
255
params.minorVersion = 0;
256
params.multiplePasses = multiplePasses;
257
params.withDepthStencil = withDepthStencil;
258
return params;
259
}
260
261
} // anonymous namespace
262
263
TEST_P(MultisampledRenderToTextureBenchmark, Run)
264
{
265
run();
266
}
267
268
using namespace params;
269
270
ANGLE_INSTANTIATE_TEST(MultisampledRenderToTextureBenchmark,
271
D3D11Params(false, false),
272
D3D11Params(true, true),
273
OpenGLOrGLESParams(false, false),
274
OpenGLOrGLESParams(true, true),
275
VulkanParams(false, false),
276
VulkanParams(true, false),
277
VulkanParams(false, true),
278
VulkanParams(true, true));
279
280