Hash :
909ea88b
Author :
Date :
2020-11-20T13:07:53
Reland "Vulkan: Ignore glFlush to reduce vkQueueSubmits in Asphalt 9" This is a reland of 5cf7472dd161bbda329dfc5e4e65bb6ce0c06fbd The ShareGroupVk::mResourceUseLists was not being cleared each call to RendererVk::submitFrame(), so it was growing indefinitely. Each vk::ResourceUseList within it was cleared, so it was holding an essentially "infinite" list of empty lists, but that caused the loop in RendererVk::submitFrame() to take more and more time until the tests timed out. The fix is to do 'resourceUseLists.clear()' once the loop to release all resources has completed, like releaseResourceUsesAndUpdateSerials() does for each individual list. Additionally, ASSERTs are added to guarantee that the lists are empty when the ContextVk and ShareGroupVk are destroyed. Original change's description: > Vulkan: Ignore glFlush to reduce vkQueueSubmits in Asphalt 9 > > Multithreaded apps can use the following pattern: > > glDrawElements() > glFenceSync() > glFlush() > glWaitSync() > > This currently results in a vkQueueSubmit for every glFlush() to ensure > that the work has landed in the command queue in the correct order. > However, ANGLE can instead avoid the vkQueueSubmit during the glFlush() > in this situation by instead flushing the ContextVk's commands and > ending the render pass to ensure the commands are submitted in the > correct order to the renderer. This improves performance for Asphalt 9 > by reducing frame times from 150-200msec to 35-55msec. > > Specifically, ANGLE will call flushCommandsAndEndRenderPass() when > there is a sync object pending a flush or if the ContextVk is currently > shared. > > Additionally, on all devices except Qualcomm, ANGLE can ignore all other > glFlush() calls entirely and return immediately. For Qualcomm devices, > ANGLE is still required to perform a full flush (resulting in a > vkQueueSubmit), since ignoring the glFlush() reduces the Manhattan 3.0 > offscreen score by ~3%. > > Bug: angleproject:5306 > Bug: angleproject:5425 > Change-Id: I9d747caf5bf306166be0fec630a78caf41208c27 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2552718 > Commit-Queue: Tim Van Patten <timvp@google.com> > Reviewed-by: Charlie Lao <cclao@google.com> > Reviewed-by: Jamie Madill <jmadill@chromium.org> Bug: angleproject:5306 Bug: angleproject:5425 Bug: angleproject:5470 Change-Id: I14ee424d032f22e5285d67accbec078ad1955dd0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2595811 Commit-Queue: Tim Van Patten <timvp@google.com> Reviewed-by: Charlie Lao <cclao@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
class FenceNVTest : public ANGLETest
{
protected:
FenceNVTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
};
class FenceSyncTest : public ANGLETest
{
public:
static constexpr uint32_t kSize = 1024;
protected:
FenceSyncTest()
{
setWindowWidth(kSize);
setWindowHeight(kSize);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
};
// FenceNV objects should respond false to glIsFenceNV until they've been set
TEST_P(FenceNVTest, IsFence)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_NV_fence"));
GLuint fence = 0;
glGenFencesNV(1, &fence);
EXPECT_GL_NO_ERROR();
EXPECT_GL_FALSE(glIsFenceNV(fence));
EXPECT_GL_NO_ERROR();
glSetFenceNV(fence, GL_ALL_COMPLETED_NV);
EXPECT_GL_NO_ERROR();
EXPECT_GL_TRUE(glIsFenceNV(fence));
EXPECT_GL_NO_ERROR();
}
// Test error cases for all FenceNV functions
TEST_P(FenceNVTest, Errors)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_NV_fence"));
EXPECT_GL_TRUE(glTestFenceNV(10)) << "glTestFenceNV should still return TRUE for an invalid "
"fence and generate an INVALID_OPERATION";
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
GLuint fence = 20;
// glGenFencesNV should generate INVALID_VALUE for a negative n and not write anything to the
// fences pointer
glGenFencesNV(-1, &fence);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
EXPECT_EQ(20u, fence);
// Generate a real fence
glGenFencesNV(1, &fence);
EXPECT_GL_NO_ERROR();
EXPECT_GL_TRUE(glTestFenceNV(fence)) << "glTestFenceNV should still return TRUE for a fence "
"that is not started and generate an INVALID_OPERATION";
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// glGetFenceivNV should generate an INVALID_OPERATION for an invalid or unstarted fence and not
// modify the params
GLint result = 30;
glGetFenceivNV(10, GL_FENCE_STATUS_NV, &result);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
EXPECT_EQ(30, result);
glGetFenceivNV(fence, GL_FENCE_STATUS_NV, &result);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
EXPECT_EQ(30, result);
// glSetFenceNV should generate an error for any condition that is not ALL_COMPLETED_NV
glSetFenceNV(fence, 0);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
// glSetFenceNV should generate INVALID_OPERATION for an invalid fence
glSetFenceNV(10, GL_ALL_COMPLETED_NV);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Test that basic usage works and doesn't generate errors or crash
TEST_P(FenceNVTest, BasicOperations)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_NV_fence"));
glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
constexpr size_t kFenceCount = 20;
GLuint fences[kFenceCount] = {0};
glGenFencesNV(static_cast<GLsizei>(ArraySize(fences)), fences);
EXPECT_GL_NO_ERROR();
for (GLuint fence : fences)
{
glClear(GL_COLOR_BUFFER_BIT);
glSetFenceNV(fence, GL_ALL_COMPLETED_NV);
}
// Finish the last fence, all fences before should be marked complete
glFinishFenceNV(fences[kFenceCount - 1]);
for (GLuint fence : fences)
{
GLint status = 0;
glGetFenceivNV(fence, GL_FENCE_STATUS_NV, &status);
EXPECT_GL_NO_ERROR();
// Fence should be complete now that Finish has been called
EXPECT_GL_TRUE(status);
}
EXPECT_PIXEL_EQ(0, 0, 255, 0, 255, 255);
}
// Sync objects should respond true to IsSync after they are created with glFenceSync
TEST_P(FenceSyncTest, IsSync)
{
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
EXPECT_GL_NO_ERROR();
EXPECT_GL_TRUE(glIsSync(sync));
EXPECT_GL_FALSE(glIsSync(reinterpret_cast<GLsync>(40)));
}
// Test error cases for all Sync function
TEST_P(FenceSyncTest, Errors)
{
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
// DeleteSync generates INVALID_VALUE when the sync is not valid
glDeleteSync(reinterpret_cast<GLsync>(20));
EXPECT_GL_ERROR(GL_INVALID_VALUE);
// glFenceSync generates GL_INVALID_ENUM if the condition is not GL_SYNC_GPU_COMMANDS_COMPLETE
EXPECT_EQ(0, glFenceSync(0, 0));
EXPECT_GL_ERROR(GL_INVALID_ENUM);
// glFenceSync generates GL_INVALID_ENUM if the flags is not 0
EXPECT_EQ(0, glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 10));
EXPECT_GL_ERROR(GL_INVALID_VALUE);
// glClientWaitSync generates GL_INVALID_VALUE and returns GL_WAIT_FAILED if flags contains more
// than just GL_SYNC_FLUSH_COMMANDS_BIT
EXPECT_GLENUM_EQ(GL_WAIT_FAILED, glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT | 0x2, 0));
EXPECT_GL_ERROR(GL_INVALID_VALUE);
// glClientWaitSync generates GL_INVALID_VALUE and returns GL_WAIT_FAILED if the sync object is
// not valid
EXPECT_GLENUM_EQ(GL_WAIT_FAILED,
glClientWaitSync(reinterpret_cast<GLsync>(30), GL_SYNC_FLUSH_COMMANDS_BIT, 0));
EXPECT_GL_ERROR(GL_INVALID_VALUE);
// glWaitSync generates GL_INVALID_VALUE if flags is non-zero
glWaitSync(sync, 1, GL_TIMEOUT_IGNORED);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
// glWaitSync generates GL_INVALID_VALUE if GLuint64 is not GL_TIMEOUT_IGNORED
glWaitSync(sync, 0, 0);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
// glWaitSync generates GL_INVALID_VALUE if the sync object is not valid
glWaitSync(reinterpret_cast<GLsync>(30), 0, GL_TIMEOUT_IGNORED);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
// glGetSynciv generates GL_INVALID_VALUE if bufSize is less than zero, results should be
// untouched
GLsizei length = 20;
GLint value = 30;
glGetSynciv(sync, GL_OBJECT_TYPE, -1, &length, &value);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
EXPECT_EQ(20, length);
EXPECT_EQ(30, value);
// glGetSynciv generates GL_INVALID_VALUE if the sync object is not valid, results should be
// untouched
glGetSynciv(reinterpret_cast<GLsync>(30), GL_OBJECT_TYPE, 1, &length, &value);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
EXPECT_EQ(20, length);
EXPECT_EQ(30, value);
}
// Test usage of glGetSynciv
TEST_P(FenceSyncTest, BasicQueries)
{
GLsizei length = 0;
GLint value = 0;
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
glGetSynciv(sync, GL_SYNC_CONDITION, 1, &length, &value);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(GL_SYNC_GPU_COMMANDS_COMPLETE, value);
glGetSynciv(sync, GL_OBJECT_TYPE, 1, &length, &value);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(GL_SYNC_FENCE, value);
glGetSynciv(sync, GL_SYNC_FLAGS, 1, &length, &value);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(0, value);
}
// Test that basic usage works and doesn't generate errors or crash
TEST_P(FenceSyncTest, BasicOperations)
{
// TODO(http://anglebug.com/5425): glClientWaitSync() returns GL_TIMEOUT_EXPIRED
ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
glClear(GL_COLOR_BUFFER_BIT);
glWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
EXPECT_GL_NO_ERROR();
glFlush();
// Don't wait forever to make sure the test terminates
constexpr GLuint64 kTimeout = 1'000'000'000; // 1 second
GLint value = 0;
for (size_t i = 0; i < 20; i++)
{
glClear(GL_COLOR_BUFFER_BIT);
value = glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, kTimeout);
EXPECT_GL_NO_ERROR();
ASSERT_TRUE(value == GL_CONDITION_SATISFIED || value == GL_ALREADY_SIGNALED);
}
}
// Test that multiple fences and draws can be issued
TEST_P(FenceSyncTest, MultipleFenceDraw)
{
constexpr int kNumIterations = 10;
constexpr int kNumDraws = 5;
// Create a texture/FBO to draw to
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture.get());
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, kSize, kSize);
ASSERT_GL_NO_ERROR();
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
ANGLE_GL_PROGRAM(redProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
bool drawGreen = true;
for (int numIterations = 0; numIterations < kNumIterations; ++numIterations)
{
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
ASSERT_GL_NO_ERROR();
for (int i = 0; i < kNumDraws; ++i)
{
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
ASSERT_GL_NO_ERROR();
drawGreen = !drawGreen;
GLuint program = 0;
if (drawGreen)
{
program = greenProgram.get();
}
else
{
program = redProgram.get();
}
drawQuad(program, std::string(essl1_shaders::PositionAttrib()), 0.0f);
ASSERT_GL_NO_ERROR();
glWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
EXPECT_GL_NO_ERROR();
glDeleteSync(sync);
ASSERT_GL_NO_ERROR();
}
// Blit to the default FBO
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, kSize, kSize, 0, 0, kSize, kSize, GL_COLOR_BUFFER_BIT, GL_NEAREST);
ASSERT_GL_NO_ERROR();
swapBuffers();
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLColor color;
if (drawGreen)
{
color = GLColor::green;
}
else
{
color = GLColor::red;
}
EXPECT_PIXEL_RECT_EQ(0, 0, kSize, kSize, color);
}
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(FenceNVTest);
ANGLE_INSTANTIATE_TEST_ES3(FenceSyncTest);