Hash :
68b47e58
Author :
Date :
2022-11-16T10:46:59
Vulkan: Initial support for VK_EXT_graphics_pipeline_library When available, this change uses VK_EXT_graphics_pipeline_library to create pipelines. Currently, it is only used when graphicsPipelineLibraryFastLinking is available. This restricts the use of this extension to devices where monolithic pipelines are not any more performant than linked libraries. A future change adds support for other implementations by providing async pipeline creation. Bug: angleproject:7369 Change-Id: I1e3b7ac4aa56e75c7d6f4d0d5ea91cb0b862e581 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4031489 Reviewed-by: Charlie Lao <cclao@google.com> Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Reviewed-by: Steven Noonan <steven@valvesoftware.com> Commit-Queue: Shahbaz Youssefi <syoussefi@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 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
//
// Copyright 2018 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.
//
// EGLBlobCacheTest:
// Unit tests for the EGL_ANDROID_blob_cache extension.
// Must be included first to prevent errors with "None".
#include "test_utils/ANGLETest.h"
#include <map>
#include <vector>
#include "common/PackedEnums.h"
#include "common/angleutils.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/MultiThreadSteps.h"
#include "test_utils/gl_raii.h"
#include "util/EGLWindow.h"
using namespace angle;
constexpr char kEGLExtName[] = "EGL_ANDROID_blob_cache";
enum class CacheOpResult
{
SetSuccess,
GetNotFound,
GetMemoryTooSmall,
GetSuccess,
ValueNotSet,
EnumCount
};
angle::PackedEnumMap<CacheOpResult, std::string> kCacheOpToString = {
{CacheOpResult::SetSuccess, "SetSuccess"},
{CacheOpResult::GetNotFound, "GetNotFound"},
{CacheOpResult::GetMemoryTooSmall, "GetMemoryTooSmall"},
{CacheOpResult::GetSuccess, "GetSuccess"},
{CacheOpResult::ValueNotSet, "ValueNotSet"},
};
std::ostream &operator<<(std::ostream &os, CacheOpResult result)
{
return os << kCacheOpToString[result];
}
namespace
{
std::map<std::vector<uint8_t>, std::vector<uint8_t>> gApplicationCache;
CacheOpResult gLastCacheOpResult = CacheOpResult::ValueNotSet;
void SetBlob(const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize)
{
std::vector<uint8_t> keyVec(keySize);
memcpy(keyVec.data(), key, keySize);
std::vector<uint8_t> valueVec(valueSize);
memcpy(valueVec.data(), value, valueSize);
gApplicationCache[keyVec] = valueVec;
gLastCacheOpResult = CacheOpResult::SetSuccess;
}
EGLsizeiANDROID GetBlob(const void *key,
EGLsizeiANDROID keySize,
void *value,
EGLsizeiANDROID valueSize)
{
std::vector<uint8_t> keyVec(keySize);
memcpy(keyVec.data(), key, keySize);
auto entry = gApplicationCache.find(keyVec);
if (entry == gApplicationCache.end())
{
// A compile+link operation can generate multiple queries to the cache; one per shader, one
// for link, and in the Vulkan backend, potentially also one for the pipeline cache. For
// the purposes of the test, make sure that any of these hitting the cache is considered a
// success, particularly because it's valid for the pipeline cache entry not to exist in the
// cache.
if (gLastCacheOpResult != CacheOpResult::GetSuccess)
{
gLastCacheOpResult = CacheOpResult::GetNotFound;
}
return 0;
}
if (entry->second.size() <= static_cast<size_t>(valueSize))
{
memcpy(value, entry->second.data(), entry->second.size());
gLastCacheOpResult = CacheOpResult::GetSuccess;
}
else
{
gLastCacheOpResult = CacheOpResult::GetMemoryTooSmall;
}
return entry->second.size();
}
} // anonymous namespace
class EGLBlobCacheTest : public ANGLETest<>
{
protected:
EGLBlobCacheTest() : mHasBlobCache(false)
{
// Force disply caching off. Blob cache functions require it.
forceNewDisplay();
}
void testSetUp() override
{
EGLDisplay display = getEGLWindow()->getDisplay();
mHasBlobCache = IsEGLDisplayExtensionEnabled(display, kEGLExtName);
}
void testTearDown() override { gApplicationCache.clear(); }
bool programBinaryAvailable() { return IsGLExtensionEnabled("GL_OES_get_program_binary"); }
bool mHasBlobCache;
};
// Makes sure the extension exists and works
TEST_P(EGLBlobCacheTest, Functional)
{
EGLDisplay display = getEGLWindow()->getDisplay();
EXPECT_TRUE(mHasBlobCache);
eglSetBlobCacheFuncsANDROID(display, SetBlob, GetBlob);
ASSERT_EGL_SUCCESS();
constexpr char kVertexShaderSrc[] = R"(attribute vec4 aTest;
attribute vec2 aPosition;
varying vec4 vTest;
void main()
{
vTest = aTest;
gl_Position = vec4(aPosition, 0.0, 1.0);
gl_PointSize = 1.0;
})";
constexpr char kFragmentShaderSrc[] = R"(precision mediump float;
varying vec4 vTest;
void main()
{
gl_FragColor = vTest;
})";
constexpr char kVertexShaderSrc2[] = R"(attribute vec4 aTest;
attribute vec2 aPosition;
varying vec4 vTest;
void main()
{
vTest = aTest;
gl_Position = vec4(aPosition, 1.0, 1.0);
gl_PointSize = 1.0;
})";
constexpr char kFragmentShaderSrc2[] = R"(precision mediump float;
varying vec4 vTest;
void main()
{
gl_FragColor = vTest - vec4(0.0, 1.0, 0.0, 0.0);
})";
// Compile a shader so it puts something in the cache
if (programBinaryAvailable())
{
ANGLE_GL_PROGRAM(program, kVertexShaderSrc, kFragmentShaderSrc);
EXPECT_EQ(CacheOpResult::SetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
// Compile the same shader again, so it would try to retrieve it from the cache
program.makeRaster(kVertexShaderSrc, kFragmentShaderSrc);
ASSERT_TRUE(program.valid());
EXPECT_EQ(CacheOpResult::GetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
// Compile another shader, which should create a new entry
program.makeRaster(kVertexShaderSrc2, kFragmentShaderSrc2);
ASSERT_TRUE(program.valid());
EXPECT_EQ(CacheOpResult::SetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
// Compile the first shader again, which should still reside in the cache
program.makeRaster(kVertexShaderSrc, kFragmentShaderSrc);
ASSERT_TRUE(program.valid());
EXPECT_EQ(CacheOpResult::GetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
}
}
// Tests error conditions of the APIs.
TEST_P(EGLBlobCacheTest, NegativeAPI)
{
EXPECT_TRUE(mHasBlobCache);
// Test bad display
eglSetBlobCacheFuncsANDROID(EGL_NO_DISPLAY, nullptr, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
eglSetBlobCacheFuncsANDROID(EGL_NO_DISPLAY, SetBlob, GetBlob);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
EGLDisplay display = getEGLWindow()->getDisplay();
// Test bad arguments
eglSetBlobCacheFuncsANDROID(display, nullptr, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglSetBlobCacheFuncsANDROID(display, SetBlob, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglSetBlobCacheFuncsANDROID(display, nullptr, GetBlob);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
// Set the arguments once and test setting them again (which should fail)
eglSetBlobCacheFuncsANDROID(display, SetBlob, GetBlob);
ASSERT_EGL_SUCCESS();
eglSetBlobCacheFuncsANDROID(display, SetBlob, GetBlob);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
// Try again with bad parameters
eglSetBlobCacheFuncsANDROID(EGL_NO_DISPLAY, nullptr, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
eglSetBlobCacheFuncsANDROID(display, nullptr, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglSetBlobCacheFuncsANDROID(display, SetBlob, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglSetBlobCacheFuncsANDROID(display, nullptr, GetBlob);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
}
// Regression test for including the fragment output locatins in the program key.
// http://anglebug.com/4535
TEST_P(EGLBlobCacheTest, FragmentOutputLocationKey)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_blend_func_extended") ||
getClientMajorVersion() < 3);
EGLDisplay display = getEGLWindow()->getDisplay();
EXPECT_TRUE(mHasBlobCache);
eglSetBlobCacheFuncsANDROID(display, SetBlob, GetBlob);
ASSERT_EGL_SUCCESS();
// Compile a shader so it puts something in the cache
if (programBinaryAvailable())
{
constexpr char kFragmentShaderSrc[] = R"(#version 300 es
#extension GL_EXT_blend_func_extended : require
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
out vec4 FragData;
out vec4 SecondaryFragData;
void main() {
FragData = src;
SecondaryFragData = src1;
})";
constexpr char kVertexShaderSrc[] = R"(#version 300 es
in vec4 position;
void main() {
gl_Position = position;
})";
GLuint program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc, [](GLuint p) {
glBindFragDataLocationEXT(p, 0, "FragData[0]");
glBindFragDataLocationIndexedEXT(p, 0, 1, "SecondaryFragData[0]");
});
ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::SetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
// Re-link the program with different fragment output bindings
program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc, [](GLuint p) {
glBindFragDataLocationEXT(p, 0, "FragData");
glBindFragDataLocationIndexedEXT(p, 0, 1, "SecondaryFragData");
});
ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::SetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
}
}
// Checks that the shader cache, which is used when this extension is available, is working
// properly.
TEST_P(EGLBlobCacheTest, ShaderCacheFunctional)
{
ANGLE_SKIP_TEST_IF(!IsVulkan());
EGLDisplay display = getEGLWindow()->getDisplay();
EXPECT_TRUE(mHasBlobCache);
eglSetBlobCacheFuncsANDROID(display, SetBlob, GetBlob);
ASSERT_EGL_SUCCESS();
constexpr char kVertexShaderSrc[] = R"(attribute vec4 aTest;
attribute vec2 aPosition;
varying vec4 vTest;
void main()
{
vTest = aTest;
gl_Position = vec4(aPosition, 0.0, 1.0);
gl_PointSize = 1.0;
})";
constexpr char kFragmentShaderSrc[] = R"(precision mediump float;
varying vec4 vTest;
void main()
{
gl_FragColor = vTest;
})";
// Compile a shader so it puts something in the cache
GLuint shaderID = CompileShader(GL_VERTEX_SHADER, kVertexShaderSrc);
ASSERT_TRUE(shaderID != 0);
EXPECT_EQ(CacheOpResult::SetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
glDeleteShader(shaderID);
// Compile the same shader again, so it would try to retrieve it from the cache
shaderID = CompileShader(GL_VERTEX_SHADER, kVertexShaderSrc);
ASSERT_TRUE(shaderID != 0);
EXPECT_EQ(CacheOpResult::GetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
glDeleteShader(shaderID);
// Compile another shader, which should create a new entry
shaderID = CompileShader(GL_FRAGMENT_SHADER, kFragmentShaderSrc);
ASSERT_TRUE(shaderID != 0);
EXPECT_EQ(CacheOpResult::SetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
glDeleteShader(shaderID);
// Compile the first shader again, which should still reside in the cache
shaderID = CompileShader(GL_VERTEX_SHADER, kVertexShaderSrc);
ASSERT_TRUE(shaderID != 0);
EXPECT_EQ(CacheOpResult::GetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::ValueNotSet;
glDeleteShader(shaderID);
}
// Tests compiling a program in multiple threads, then fetching the compiled program/shaders from
// the cache. We then perform a draw call and test the result to ensure nothing was corrupted.
TEST_P(EGLBlobCacheTest, ThreadSafety)
{
ANGLE_SKIP_TEST_IF(!IsVulkan());
EGLDisplay display = getEGLWindow()->getDisplay();
EXPECT_TRUE(mHasBlobCache);
eglSetBlobCacheFuncsANDROID(display, SetBlob, GetBlob);
ASSERT_EGL_SUCCESS();
auto threadFunc = [&](int threadID, EGLDisplay dpy, EGLSurface surface, EGLContext context) {
EXPECT_EGL_TRUE(eglMakeCurrent(dpy, surface, surface, context));
ANGLE_GL_PROGRAM(unusedProgramTemp1, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
// Insert a new entry into the cache unique to this thread.
std::stringstream ss;
ss << essl1_shaders::vs::Simple() << "//" << threadID;
std::string newEntryVSSource = ss.str().c_str();
ANGLE_GL_PROGRAM(unusedProgramTemp2, newEntryVSSource.c_str(), essl1_shaders::fs::Red());
};
constexpr int kNumThreads = 32;
std::vector<LockStepThreadFunc> threadFuncs(kNumThreads);
for (int i = 0; i < kNumThreads; ++i)
{
threadFuncs[i] = [=](EGLDisplay dpy, EGLSurface surface, EGLContext context) {
return threadFunc(i, dpy, surface, context);
};
}
gLastCacheOpResult = CacheOpResult::ValueNotSet;
RunLockStepThreads(getEGLWindow(), threadFuncs.size(), threadFuncs.data());
EXPECT_GL_NO_ERROR();
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
EXPECT_EQ(CacheOpResult::GetSuccess, gLastCacheOpResult);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
}
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(EGLBlobCacheTest);