mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-19 07:51:57 +09:00
[Chore] (MG_Backend, MG_Backend/DirectGLES, MG_Backend/DirectVulkan, MG_Backend/MGPipe, MG_Backend/Record, MG_Benchmark/Buffer, MG_Benchmark/Container, MG_Benchmark/Driver, MG_Benchmark/Program, MG_Benchmark/ShaderCache, MG_Benchmark/Transpile, MG_Gbm, MG_Impl, MG_Impl/CGLImpl, MG_Impl/DyldInterpose, MG_Impl/EGLImpl, MG_Impl/GLImpl, MG_Impl/GLXImpl, MG_Impl/NSOpenGLImpl, MG_Impl/Pipe, MG_Impl/WGLImpl, MG_IntegrationTest, MG_IntegrationTest/Harness, MG_IntegrationTest/Scenarios, MG_Pipe, MG_Remote, MG_Remote/Client, MG_Remote/Protocol, MG_Remote/Server, MG_Remote/Transport, MG_Remote/Wire, MG_State/EGLState, MG_State/GLState, MG_Test, MG_Test/Backend, MG_Test/BackendLoader, MG_Test/Buffer, MG_Test/EGLState, MG_Test/Framebuffer, MG_Test/Gbm, MG_Test/Pipe, MG_Test/Pipeline, MG_Test/Program, MG_Test/Query, MG_Test/SelfTest, MG_Test/ShaderTranspiler, MG_Test/State, MG_Test/Swapchain, MG_Test/Texture, MG_Test/Util, MG_Test/VertexArray, MG_Test/Wire, MG_Util/Async, MG_Util/BackendLoaders, MG_Util/Converters, MG_Util/Damage, MG_Util/Debug, MG_Util/Math, MG_Util/Metrics, MG_Util/SelfTest, MG_Util/ShaderTranspiler, MG_Util/Texture, MG_Util/X11, MobileGL, scripts/data, tools/cts, tools/device_bench, tools/spikes, tools/trace_replay, tools/wgl-smoke): clang-format every C and C++ source
- Layout only: token streams match up to split literals, continuations and using order - The size totals fall, so the structure baseline is lowered
This commit is contained in:
@@ -180,16 +180,16 @@ BENCHMARK(BM_UpdateDataPartially)->Unit(benchmark::kMillisecond)->UseRealTime();
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Initialize();
|
||||
benchmark ::MaybeReenterWithoutASLR(argc, argv);
|
||||
benchmark::MaybeReenterWithoutASLR(argc, argv);
|
||||
char arg0_default[] = "benchmark";
|
||||
char* args_default = reinterpret_cast<char*>(arg0_default);
|
||||
if (!argv) {
|
||||
argc = 1;
|
||||
argv = &args_default;
|
||||
}
|
||||
::benchmark ::Initialize(&argc, argv);
|
||||
if (::benchmark ::ReportUnrecognizedArguments(argc, argv)) return 1;
|
||||
::benchmark ::RunSpecifiedBenchmarks();
|
||||
::benchmark ::Shutdown();
|
||||
::benchmark::Initialize(&argc, argv);
|
||||
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1;
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
::benchmark::Shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,8 @@ namespace {
|
||||
Vector<Uint64> SequentialKeys(SizeT n) {
|
||||
Vector<Uint64> keys;
|
||||
keys.reserve(n);
|
||||
for (SizeT i = 0; i < n; ++i) keys.push_back(static_cast<Uint64>(i) + 1);
|
||||
for (SizeT i = 0; i < n; ++i)
|
||||
keys.push_back(static_cast<Uint64>(i) + 1);
|
||||
return keys;
|
||||
}
|
||||
|
||||
@@ -89,7 +90,8 @@ namespace {
|
||||
Vector<Uint64> keys;
|
||||
keys.reserve(n);
|
||||
std::mt19937_64 rng(0xC0FFEE);
|
||||
for (SizeT i = 0; i < n; ++i) keys.push_back(rng());
|
||||
for (SizeT i = 0; i < n; ++i)
|
||||
keys.push_back(rng());
|
||||
return keys;
|
||||
}
|
||||
|
||||
@@ -117,7 +119,8 @@ namespace {
|
||||
template <typename Key>
|
||||
UnorderedMap<Key, Uint64> Populated(const Vector<Key>& keys) {
|
||||
UnorderedMap<Key, Uint64> map;
|
||||
for (SizeT i = 0; i < keys.size(); ++i) map[keys[i]] = i;
|
||||
for (SizeT i = 0; i < keys.size(); ++i)
|
||||
map[keys[i]] = i;
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -160,7 +163,8 @@ namespace {
|
||||
const auto& keys = CachedKeys<KeyVec, Make>(static_cast<SizeT>(state.range(0)));
|
||||
for (auto _ : state) {
|
||||
UnorderedMap<typename KeyVec::value_type, Uint64> map;
|
||||
for (SizeT i = 0; i < keys.size(); ++i) map[keys[i]] = i;
|
||||
for (SizeT i = 0; i < keys.size(); ++i)
|
||||
map[keys[i]] = i;
|
||||
benchmark::DoNotOptimize(map.size());
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations() * static_cast<Int64>(keys.size()));
|
||||
@@ -175,8 +179,10 @@ namespace {
|
||||
state.PauseTiming();
|
||||
auto map = Populated(keys);
|
||||
state.ResumeTiming();
|
||||
for (SizeT i = 0; i < keys.size(); i += 2) benchmark::DoNotOptimize(map.erase(keys[i]));
|
||||
for (SizeT i = 0; i < keys.size(); i += 2) map[keys[i]] = i;
|
||||
for (SizeT i = 0; i < keys.size(); i += 2)
|
||||
benchmark::DoNotOptimize(map.erase(keys[i]));
|
||||
for (SizeT i = 0; i < keys.size(); i += 2)
|
||||
map[keys[i]] = i;
|
||||
benchmark::DoNotOptimize(map.size());
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations() * static_cast<Int64>(keys.size()));
|
||||
@@ -192,7 +198,8 @@ namespace {
|
||||
state.PauseTiming();
|
||||
auto map = Populated(keys);
|
||||
state.ResumeTiming();
|
||||
for (auto it = map.begin(); it != map.end();) it = map.erase(it);
|
||||
for (auto it = map.begin(); it != map.end();)
|
||||
it = map.erase(it);
|
||||
benchmark::DoNotOptimize(map.size());
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations() * static_cast<Int64>(keys.size()));
|
||||
@@ -206,7 +213,8 @@ namespace {
|
||||
auto map = Populated(keys);
|
||||
for (auto _ : state) {
|
||||
Uint64 acc = 0;
|
||||
for (const auto& entry : map) acc += entry.second;
|
||||
for (const auto& entry : map)
|
||||
acc += entry.second;
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations() * static_cast<Int64>(keys.size()));
|
||||
@@ -214,11 +222,8 @@ namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
#define MGL_MAP_BENCH(WORKLOAD, SHAPE, VEC, MAKER) \
|
||||
BENCHMARK_TEMPLATE(WORKLOAD, VEC, MAKER) \
|
||||
->Name(#WORKLOAD "/" #SHAPE) \
|
||||
->RangeMultiplier(8) \
|
||||
->Range(kMinSize, kMaxSize)
|
||||
#define MGL_MAP_BENCH(WORKLOAD, SHAPE, VEC, MAKER) \
|
||||
BENCHMARK_TEMPLATE(WORKLOAD, VEC, MAKER)->Name(#WORKLOAD "/" #SHAPE)->RangeMultiplier(8)->Range(kMinSize, kMaxSize)
|
||||
|
||||
MGL_MAP_BENCH(LookupHit, sequential, Vector<Uint64>, SequentialKeys);
|
||||
MGL_MAP_BENCH(LookupHit, pointer, Vector<Uint64>, PointerKeys);
|
||||
|
||||
@@ -185,8 +185,7 @@ GLF(void, glBindAttribLocation, (GLuint, GLuint, const GLchar*))
|
||||
GLF(void, glUniform3fv, (GLint, GLsizei, const float*))
|
||||
GLF(void, glDrawArrays, (GLenum, GLint, GLsizei))
|
||||
GLF(void, glDrawElementsBaseVertex, (GLenum, GLsizei, GLenum, const void*, GLint))
|
||||
GLF(void, glMultiDrawElementsBaseVertex,
|
||||
(GLenum, const GLsizei*, GLenum, const void* const*, GLsizei, const GLint*))
|
||||
GLF(void, glMultiDrawElementsBaseVertex, (GLenum, const GLsizei*, GLenum, const void* const*, GLsizei, const GLint*))
|
||||
GLF(void, glBindBufferRange, (GLenum, GLuint, GLuint, GLintptr, GLsizeiptr))
|
||||
GLF(void, glBindBufferBase, (GLenum, GLuint, GLuint))
|
||||
GLF(GLuint, glGetUniformBlockIndex, (GLuint, const GLchar*))
|
||||
@@ -216,7 +215,6 @@ static int cmp_u64(const void* a, const void* b) {
|
||||
return x < y ? -1 : x > y;
|
||||
}
|
||||
|
||||
|
||||
/* Scene, cases and the case table live next door so the Android plugin's
|
||||
* in-process benchmark runs byte-identical bodies. */
|
||||
static void bench_gl_failed(const char* what, const char* detail) {
|
||||
@@ -285,8 +283,7 @@ static void run_case(const char* name, case_fn body, long a, long b, long opsPer
|
||||
uint64_t med = samples[g_frames / 2];
|
||||
double frameMs = med / 1e6;
|
||||
double nsPerOp = opsPerFrame > 0 ? (double)med / (double)opsPerFrame : 0.0;
|
||||
printf("%s,%d,%ld,%.3f,%.1f,%.1f\n", name, g_frames, opsPerFrame, frameMs, nsPerOp,
|
||||
1e9 / (double)med);
|
||||
printf("%s,%d,%ld,%.3f,%.1f,%.1f\n", name, g_frames, opsPerFrame, frameMs, nsPerOp, 1e9 / (double)med);
|
||||
fflush(stdout);
|
||||
if (glGetError() != GL_NO_ERROR) fprintf(stderr, "WARN: GL error after %s\n", name);
|
||||
}
|
||||
@@ -302,8 +299,7 @@ static EGLDisplay surfaceless_display(void) {
|
||||
if (!fn) fn = dlsym(g_provider, "eglGetPlatformDisplayEXT");
|
||||
if (!fn) fn = g_eglGetProcAddress("eglGetPlatformDisplayEXT");
|
||||
if (!fn) return NULL;
|
||||
return ((EGLDisplay(*)(EGLenum, void*, const void*))fn)(EGL_PLATFORM_SURFACELESS_MESA,
|
||||
EGL_DEFAULT_DISPLAY, NULL);
|
||||
return ((EGLDisplay (*)(EGLenum, void*, const void*))fn)(EGL_PLATFORM_SURFACELESS_MESA, EGL_DEFAULT_DISPLAY, NULL);
|
||||
}
|
||||
|
||||
/* ---- EGL bootstrap: one provider library, pbuffer, desktop-GL context ---- */
|
||||
@@ -315,9 +311,12 @@ static int boot_egl(void) {
|
||||
fprintf(stderr, "FAIL: dlopen %s: %s\n", libpath, dlerror());
|
||||
return 1;
|
||||
}
|
||||
#define ESYM(name) \
|
||||
void* p_##name = dlsym(g_provider, #name); \
|
||||
if (!p_##name) { fprintf(stderr, "FAIL: dlsym %s\n", #name); return 1; }
|
||||
#define ESYM(name) \
|
||||
void* p_##name = dlsym(g_provider, #name); \
|
||||
if (!p_##name) { \
|
||||
fprintf(stderr, "FAIL: dlsym %s\n", #name); \
|
||||
return 1; \
|
||||
}
|
||||
ESYM(eglGetDisplay)
|
||||
ESYM(eglInitialize)
|
||||
ESYM(eglChooseConfig)
|
||||
@@ -329,9 +328,9 @@ static int boot_egl(void) {
|
||||
ESYM(eglGetError)
|
||||
g_eglGetProcAddress = (void* (*)(const char*))p_eglGetProcAddress;
|
||||
|
||||
EGLint (*getError)(void) = (EGLint(*)(void))p_eglGetError;
|
||||
EGLint (*getError)(void) = (EGLint (*)(void))p_eglGetError;
|
||||
EGLBoolean (*initialize)(EGLDisplay, EGLint*, EGLint*) =
|
||||
(EGLBoolean(*)(EGLDisplay, EGLint*, EGLint*))p_eglInitialize;
|
||||
(EGLBoolean (*)(EGLDisplay, EGLint*, EGLint*))p_eglInitialize;
|
||||
|
||||
/* The default display first: it is the one a windowed app would get, and
|
||||
* on a desktop it is the one that reaches the real GPU - which is the
|
||||
@@ -343,7 +342,7 @@ static int boot_egl(void) {
|
||||
* the work being timed. */
|
||||
EGLint maj = 0, min = 0;
|
||||
const char* how = "default display";
|
||||
EGLDisplay dpy = ((EGLDisplay(*)(void*))p_eglGetDisplay)(EGL_DEFAULT_DISPLAY);
|
||||
EGLDisplay dpy = ((EGLDisplay (*)(void*))p_eglGetDisplay)(EGL_DEFAULT_DISPLAY);
|
||||
if (!dpy || !initialize(dpy, &maj, &min)) {
|
||||
dpy = surfaceless_display();
|
||||
how = "surfaceless display";
|
||||
@@ -359,22 +358,26 @@ static int boot_egl(void) {
|
||||
// native driver as the baseline. The .inc picks ESSL shader sources when the
|
||||
// context turns out to be ES.
|
||||
EGLBoolean (*chooseConfig)(EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*) =
|
||||
(EGLBoolean(*)(EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*))p_eglChooseConfig;
|
||||
(EGLBoolean (*)(EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*))p_eglChooseConfig;
|
||||
EGLContext (*createContext)(EGLDisplay, EGLConfig, EGLContext, const EGLint*) =
|
||||
(EGLContext(*)(EGLDisplay, EGLConfig, EGLContext, const EGLint*))p_eglCreateContext;
|
||||
EGLBoolean (*bindApi)(EGLenum) = (EGLBoolean(*)(EGLenum))p_eglBindAPI;
|
||||
(EGLContext (*)(EGLDisplay, EGLConfig, EGLContext, const EGLint*))p_eglCreateContext;
|
||||
EGLBoolean (*bindApi)(EGLenum) = (EGLBoolean (*)(EGLenum))p_eglBindAPI;
|
||||
|
||||
EGLConfig cfg = NULL;
|
||||
EGLint ncfg = 0;
|
||||
EGLContext ctx = EGL_NO_CONTEXT;
|
||||
|
||||
if (bindApi(EGL_OPENGL_API)) {
|
||||
const EGLint cfgAttribs[] = {EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_RED_SIZE, 8,
|
||||
EGL_DEPTH_SIZE, 24, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_NONE};
|
||||
const EGLint cfgAttribs[] = {EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_RED_SIZE, 8, EGL_DEPTH_SIZE, 24,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_NONE};
|
||||
if (chooseConfig(dpy, cfgAttribs, &cfg, 1, &ncfg) && ncfg >= 1) {
|
||||
const EGLint ctxAttribs[] = {EGL_CONTEXT_MAJOR_VERSION, 3, EGL_CONTEXT_MINOR_VERSION, 2,
|
||||
const EGLint ctxAttribs[] = {EGL_CONTEXT_MAJOR_VERSION,
|
||||
3,
|
||||
EGL_CONTEXT_MINOR_VERSION,
|
||||
2,
|
||||
EGL_CONTEXT_OPENGL_PROFILE_MASK,
|
||||
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT, EGL_NONE};
|
||||
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
|
||||
EGL_NONE};
|
||||
ctx = createContext(dpy, cfg, EGL_NO_CONTEXT, ctxAttribs);
|
||||
if (ctx == EGL_NO_CONTEXT) ctx = createContext(dpy, cfg, EGL_NO_CONTEXT, NULL);
|
||||
}
|
||||
@@ -384,9 +387,19 @@ static int boot_egl(void) {
|
||||
fprintf(stderr, "FAIL: neither OpenGL nor OpenGL ES is bindable on this provider\n");
|
||||
return 1;
|
||||
}
|
||||
const EGLint esCfgAttribs[] = {EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_DEPTH_SIZE, 24,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, EGL_NONE};
|
||||
const EGLint esCfgAttribs[] = {EGL_SURFACE_TYPE,
|
||||
EGL_PBUFFER_BIT,
|
||||
EGL_RED_SIZE,
|
||||
8,
|
||||
EGL_GREEN_SIZE,
|
||||
8,
|
||||
EGL_BLUE_SIZE,
|
||||
8,
|
||||
EGL_DEPTH_SIZE,
|
||||
24,
|
||||
EGL_RENDERABLE_TYPE,
|
||||
EGL_OPENGL_ES3_BIT,
|
||||
EGL_NONE};
|
||||
ncfg = 0;
|
||||
if (!chooseConfig(dpy, esCfgAttribs, &cfg, 1, &ncfg) || ncfg < 1) {
|
||||
// EGL_SURFACE_TYPE 0 matches any config: a stack that offers no
|
||||
@@ -411,12 +424,10 @@ static int boot_egl(void) {
|
||||
* exactly what EGL_KHR_surfaceless_context takes, so the same call covers
|
||||
* both. */
|
||||
const EGLint pbAttribs[] = {EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE};
|
||||
EGLSurface surf = ((EGLSurface(*)(EGLDisplay, EGLConfig, const EGLint*))p_eglCreatePbufferSurface)(
|
||||
dpy, cfg, pbAttribs);
|
||||
if (surf == EGL_NO_SURFACE)
|
||||
fprintf(stderr, "no pbuffer (0x%x), using a surfaceless context\n", getError());
|
||||
if (!((EGLBoolean(*)(EGLDisplay, EGLSurface, EGLSurface, EGLContext))p_eglMakeCurrent)(dpy, surf,
|
||||
surf, ctx)) {
|
||||
EGLSurface surf =
|
||||
((EGLSurface (*)(EGLDisplay, EGLConfig, const EGLint*))p_eglCreatePbufferSurface)(dpy, cfg, pbAttribs);
|
||||
if (surf == EGL_NO_SURFACE) fprintf(stderr, "no pbuffer (0x%x), using a surfaceless context\n", getError());
|
||||
if (!((EGLBoolean (*)(EGLDisplay, EGLSurface, EGLSurface, EGLContext))p_eglMakeCurrent)(dpy, surf, surf, ctx)) {
|
||||
fprintf(stderr, "FAIL: eglMakeCurrent (0x%x)\n", getError());
|
||||
return 1;
|
||||
}
|
||||
@@ -424,32 +435,75 @@ static int boot_egl(void) {
|
||||
/* Core GL entry points: eglGetProcAddress first (EGL 1.5 serves core
|
||||
* functions), provider dlsym as fallback (both glvnd and MobileGL export
|
||||
* the gl* symbols directly). */
|
||||
#define RESOLVE(name) \
|
||||
do { \
|
||||
*(void**)&name = g_eglGetProcAddress(#name); \
|
||||
if (!name) *(void**)&name = dlsym(g_provider, #name); \
|
||||
if (!name) { fprintf(stderr, "FAIL: resolve %s\n", #name); return 1; } \
|
||||
#define RESOLVE(name) \
|
||||
do { \
|
||||
*(void**)&name = g_eglGetProcAddress(#name); \
|
||||
if (!name) *(void**)&name = dlsym(g_provider, #name); \
|
||||
if (!name) { \
|
||||
fprintf(stderr, "FAIL: resolve %s\n", #name); \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
RESOLVE(glClear); RESOLVE(glClearColor); RESOLVE(glEnable); RESOLVE(glViewport);
|
||||
RESOLVE(glDisable); RESOLVE(glBlendFuncSeparate); RESOLVE(glDrawBuffers);
|
||||
RESOLVE(glGetString); RESOLVE(glGetError); RESOLVE(glFinish); RESOLVE(glFlush);
|
||||
RESOLVE(glGenBuffers); RESOLVE(glBindBuffer); RESOLVE(glBufferData); RESOLVE(glBufferSubData);
|
||||
RESOLVE(glGenVertexArrays); RESOLVE(glBindVertexArray); RESOLVE(glEnableVertexAttribArray);
|
||||
RESOLVE(glVertexAttribPointer); RESOLVE(glGenTextures); RESOLVE(glBindTexture);
|
||||
RESOLVE(glActiveTexture); RESOLVE(glTexImage2D); RESOLVE(glTexSubImage2D);
|
||||
RESOLVE(glTexParameteri); RESOLVE(glGenerateMipmap); RESOLVE(glCreateShader);
|
||||
RESOLVE(glPixelStorei); RESOLVE(glGetIntegerv);
|
||||
RESOLVE(glShaderSource); RESOLVE(glCompileShader); RESOLVE(glGetShaderiv);
|
||||
RESOLVE(glGetShaderInfoLog); RESOLVE(glCreateProgram); RESOLVE(glAttachShader);
|
||||
RESOLVE(glLinkProgram); RESOLVE(glGetProgramiv); RESOLVE(glUseProgram);
|
||||
RESOLVE(glGetUniformLocation); RESOLVE(glUniform1i); RESOLVE(glUniform3f);
|
||||
RESOLVE(glUniformMatrix4fv); RESOLVE(glDrawElements); RESOLVE(glBindAttribLocation);
|
||||
RESOLVE(glUniform3fv); RESOLVE(glDrawArrays); RESOLVE(glDrawElementsBaseVertex);
|
||||
RESOLVE(glBindBufferRange); RESOLVE(glBindBufferBase);
|
||||
RESOLVE(glGetUniformBlockIndex); RESOLVE(glUniformBlockBinding);
|
||||
RESOLVE(glGenSamplers); RESOLVE(glBindSampler); RESOLVE(glSamplerParameteri);
|
||||
RESOLVE(glGenFramebuffers); RESOLVE(glBindFramebuffer); RESOLVE(glGenRenderbuffers);
|
||||
RESOLVE(glBindRenderbuffer); RESOLVE(glRenderbufferStorage); RESOLVE(glFramebufferRenderbuffer);
|
||||
RESOLVE(glClear);
|
||||
RESOLVE(glClearColor);
|
||||
RESOLVE(glEnable);
|
||||
RESOLVE(glViewport);
|
||||
RESOLVE(glDisable);
|
||||
RESOLVE(glBlendFuncSeparate);
|
||||
RESOLVE(glDrawBuffers);
|
||||
RESOLVE(glGetString);
|
||||
RESOLVE(glGetError);
|
||||
RESOLVE(glFinish);
|
||||
RESOLVE(glFlush);
|
||||
RESOLVE(glGenBuffers);
|
||||
RESOLVE(glBindBuffer);
|
||||
RESOLVE(glBufferData);
|
||||
RESOLVE(glBufferSubData);
|
||||
RESOLVE(glGenVertexArrays);
|
||||
RESOLVE(glBindVertexArray);
|
||||
RESOLVE(glEnableVertexAttribArray);
|
||||
RESOLVE(glVertexAttribPointer);
|
||||
RESOLVE(glGenTextures);
|
||||
RESOLVE(glBindTexture);
|
||||
RESOLVE(glActiveTexture);
|
||||
RESOLVE(glTexImage2D);
|
||||
RESOLVE(glTexSubImage2D);
|
||||
RESOLVE(glTexParameteri);
|
||||
RESOLVE(glGenerateMipmap);
|
||||
RESOLVE(glCreateShader);
|
||||
RESOLVE(glPixelStorei);
|
||||
RESOLVE(glGetIntegerv);
|
||||
RESOLVE(glShaderSource);
|
||||
RESOLVE(glCompileShader);
|
||||
RESOLVE(glGetShaderiv);
|
||||
RESOLVE(glGetShaderInfoLog);
|
||||
RESOLVE(glCreateProgram);
|
||||
RESOLVE(glAttachShader);
|
||||
RESOLVE(glLinkProgram);
|
||||
RESOLVE(glGetProgramiv);
|
||||
RESOLVE(glUseProgram);
|
||||
RESOLVE(glGetUniformLocation);
|
||||
RESOLVE(glUniform1i);
|
||||
RESOLVE(glUniform3f);
|
||||
RESOLVE(glUniformMatrix4fv);
|
||||
RESOLVE(glDrawElements);
|
||||
RESOLVE(glBindAttribLocation);
|
||||
RESOLVE(glUniform3fv);
|
||||
RESOLVE(glDrawArrays);
|
||||
RESOLVE(glDrawElementsBaseVertex);
|
||||
RESOLVE(glBindBufferRange);
|
||||
RESOLVE(glBindBufferBase);
|
||||
RESOLVE(glGetUniformBlockIndex);
|
||||
RESOLVE(glUniformBlockBinding);
|
||||
RESOLVE(glGenSamplers);
|
||||
RESOLVE(glBindSampler);
|
||||
RESOLVE(glSamplerParameteri);
|
||||
RESOLVE(glGenFramebuffers);
|
||||
RESOLVE(glBindFramebuffer);
|
||||
RESOLVE(glGenRenderbuffers);
|
||||
RESOLVE(glBindRenderbuffer);
|
||||
RESOLVE(glRenderbufferStorage);
|
||||
RESOLVE(glFramebufferRenderbuffer);
|
||||
RESOLVE(glCheckFramebufferStatus);
|
||||
// Optional: end_frame_wait() falls back to glFinish when a stack has no
|
||||
// sync objects, so resolve without failing the run.
|
||||
|
||||
@@ -222,16 +222,16 @@ BENCHMARK(BM_CompileAndLink)->Unit(benchmark::kMillisecond);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Initialize();
|
||||
benchmark ::MaybeReenterWithoutASLR(argc, argv);
|
||||
benchmark::MaybeReenterWithoutASLR(argc, argv);
|
||||
char arg0_default[] = "benchmark";
|
||||
char* args_default = reinterpret_cast<char*>(arg0_default);
|
||||
if (!argv) {
|
||||
argc = 1;
|
||||
argv = &args_default;
|
||||
}
|
||||
::benchmark ::Initialize(&argc, argv);
|
||||
if (::benchmark ::ReportUnrecognizedArguments(argc, argv)) return 1;
|
||||
::benchmark ::RunSpecifiedBenchmarks();
|
||||
::benchmark ::Shutdown();
|
||||
::benchmark::Initialize(&argc, argv);
|
||||
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1;
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
::benchmark::Shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -108,8 +108,7 @@ void main() {
|
||||
|
||||
class CacheModeScope {
|
||||
public:
|
||||
explicit CacheModeScope(const Bool enabled)
|
||||
: m_saved(MG_Config::Features.ShaderTranslationCache) {
|
||||
explicit CacheModeScope(const Bool enabled) : m_saved(MG_Config::Features.ShaderTranslationCache) {
|
||||
MG_Config::Features.ShaderTranslationCache =
|
||||
enabled ? MG_Config::QuirkOverride::ForceOn : MG_Config::QuirkOverride::ForceOff;
|
||||
}
|
||||
@@ -339,8 +338,7 @@ BENCHMARK(BM_SharedShaderLink_CacheOn)->Arg(0)->Arg(120)->Unit(benchmark::kMicro
|
||||
// ---------------------------------------------------------------------------------------
|
||||
static void BM_EsslTranspile_CacheOff(benchmark::State& state) {
|
||||
MobileGL::Initialize();
|
||||
const Vector<Uint32> spirv =
|
||||
BuildSanitizedFragmentSpirv(SwizzleLikeFragment("", static_cast<int>(state.range(0))));
|
||||
const Vector<Uint32> spirv = BuildSanitizedFragmentSpirv(SwizzleLikeFragment("", static_cast<int>(state.range(0))));
|
||||
if (spirv.empty()) {
|
||||
state.SkipWithError("could not build the fragment module");
|
||||
return;
|
||||
@@ -359,8 +357,7 @@ BENCHMARK(BM_EsslTranspile_CacheOff)->Arg(0)->Arg(120)->Unit(benchmark::kMicrose
|
||||
|
||||
static void BM_EsslTranspile_CacheOn(benchmark::State& state) {
|
||||
MobileGL::Initialize();
|
||||
const Vector<Uint32> spirv =
|
||||
BuildSanitizedFragmentSpirv(SwizzleLikeFragment("", static_cast<int>(state.range(0))));
|
||||
const Vector<Uint32> spirv = BuildSanitizedFragmentSpirv(SwizzleLikeFragment("", static_cast<int>(state.range(0))));
|
||||
if (spirv.empty()) {
|
||||
state.SkipWithError("could not build the fragment module");
|
||||
return;
|
||||
@@ -413,8 +410,7 @@ BENCHMARK(BM_EsslTranspile_CacheOn)->Arg(0)->Arg(120)->Unit(benchmark::kMicrosec
|
||||
// hit rate reported below is high but not exactly 1.0 per iteration.
|
||||
namespace {
|
||||
String UniqueFragmentSource(const Uint64 serial, const int padLines) {
|
||||
return SwizzleLikeFragment("", padLines) +
|
||||
"\n// unique-" + std::to_string(serial) + "\n";
|
||||
return SwizzleLikeFragment("", padLines) + "\n// unique-" + std::to_string(serial) + "\n";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -104,9 +104,9 @@ namespace {
|
||||
// kMaxReps. Three untimed warm-up calls first, so allocator growth and first-touch page
|
||||
// faults land outside the sample set.
|
||||
template <typename F>
|
||||
Stat Measure(F&& body, const double budgetMs = 250.0, const int minReps = 15,
|
||||
const int maxReps = 2000) {
|
||||
for (int i = 0; i < 3; ++i) body();
|
||||
Stat Measure(F&& body, const double budgetMs = 250.0, const int minReps = 15, const int maxReps = 2000) {
|
||||
for (int i = 0; i < 3; ++i)
|
||||
body();
|
||||
|
||||
std::vector<double> samples;
|
||||
samples.reserve(64);
|
||||
@@ -127,9 +127,9 @@ namespace {
|
||||
// stages whose set-up (a fresh glslang parse, a fresh link) has to happen per iteration
|
||||
// and must NOT be counted.
|
||||
template <typename F>
|
||||
Stat MeasureInner(F&& body, const double budgetMs = 250.0, const int minReps = 15,
|
||||
const int maxReps = 2000) {
|
||||
for (int i = 0; i < 3; ++i) (void)body();
|
||||
Stat MeasureInner(F&& body, const double budgetMs = 250.0, const int minReps = 15, const int maxReps = 2000) {
|
||||
for (int i = 0; i < 3; ++i)
|
||||
(void)body();
|
||||
|
||||
std::vector<double> samples;
|
||||
samples.reserve(64);
|
||||
@@ -137,8 +137,7 @@ namespace {
|
||||
while (true) {
|
||||
samples.push_back(body());
|
||||
if (static_cast<int>(samples.size()) >= maxReps) break;
|
||||
const double elapsedMs =
|
||||
std::chrono::duration<double, std::milli>(Clock::now() - start).count();
|
||||
const double elapsedMs = std::chrono::duration<double, std::milli>(Clock::now() - start).count();
|
||||
if (static_cast<int>(samples.size()) >= minReps && elapsedMs >= budgetMs) break;
|
||||
}
|
||||
return Summarize(samples);
|
||||
@@ -146,21 +145,20 @@ namespace {
|
||||
|
||||
struct Row {
|
||||
std::string corpus;
|
||||
std::string stage; // "VS" / "FS" / "program"
|
||||
std::string stage; // "VS" / "FS" / "program"
|
||||
std::string what;
|
||||
std::string kind; // roundtrip / probe / frontend / crosscompile / baseline / merged
|
||||
std::string kind; // roundtrip / probe / frontend / crosscompile / baseline / merged
|
||||
size_t moduleWords = 0;
|
||||
Stat stat;
|
||||
};
|
||||
|
||||
std::vector<Row> g_rows;
|
||||
|
||||
void Emit(const std::string& corpus, const std::string& stage, const std::string& what,
|
||||
const std::string& kind, size_t words, const Stat& s) {
|
||||
void Emit(const std::string& corpus, const std::string& stage, const std::string& what, const std::string& kind,
|
||||
size_t words, const Stat& s) {
|
||||
g_rows.push_back(Row{corpus, stage, what, kind, words, s});
|
||||
std::printf("%-14s %-8s %-40s %-13s %7zu %10.1f %10.1f %10.1f %6d\n", corpus.c_str(),
|
||||
stage.c_str(), what.c_str(), kind.c_str(), words, s.medianUs, s.p10Us,
|
||||
s.p90Us, s.reps);
|
||||
std::printf("%-14s %-8s %-40s %-13s %7zu %10.1f %10.1f %10.1f %6d\n", corpus.c_str(), stage.c_str(),
|
||||
what.c_str(), kind.c_str(), words, s.medianUs, s.p10Us, s.p90Us, s.reps);
|
||||
std::fflush(stdout);
|
||||
}
|
||||
|
||||
@@ -648,24 +646,22 @@ void main() {
|
||||
|
||||
struct BuiltProgram {
|
||||
std::vector<GLenum> types;
|
||||
std::vector<std::vector<unsigned>> raw; // straight out of GlslangToSpv
|
||||
std::vector<std::vector<unsigned>> sanitized; // after SanitizeAndOptimizeBinary
|
||||
std::vector<std::vector<unsigned>> raw; // straight out of GlslangToSpv
|
||||
std::vector<std::vector<unsigned>> sanitized; // after SanitizeAndOptimizeBinary
|
||||
};
|
||||
|
||||
// Fresh parse of both stages. glslang mutates a TShader during link/mapIO, so anything
|
||||
// that needs to be timed repeatedly has to rebuild these each iteration.
|
||||
std::vector<SharedPtr<glslang::TShader>> ParseBoth(const std::string& vsPre,
|
||||
const std::string& fsPre,
|
||||
std::vector<SharedPtr<glslang::TShader>> ParseBoth(const std::string& vsPre, const std::string& fsPre,
|
||||
const CompileEnv& env) {
|
||||
std::vector<SharedPtr<glslang::TShader>> out;
|
||||
for (const auto& [type, src] :
|
||||
{std::pair<GLenum, const std::string*>{GL_VERTEX_SHADER, &vsPre},
|
||||
std::pair<GLenum, const std::string*>{GL_FRAGMENT_SHADER, &fsPre}}) {
|
||||
for (const auto& [type, src] : {std::pair<GLenum, const std::string*>{GL_VERTEX_SHADER, &vsPre},
|
||||
std::pair<GLenum, const std::string*>{GL_FRAGMENT_SHADER, &fsPre}}) {
|
||||
ShaderAttrib attrib{.shaderType = type, .sourceStr = *src, .flags = 0, .env = &env};
|
||||
auto r = ShaderCompiler::CompileShader(attrib);
|
||||
if (!r) {
|
||||
std::fprintf(stderr, "PARSE FAILED (%s):\n%s\n",
|
||||
type == GL_VERTEX_SHADER ? "VS" : "FS", r.error().log.c_str());
|
||||
std::fprintf(stderr, "PARSE FAILED (%s):\n%s\n", type == GL_VERTEX_SHADER ? "VS" : "FS",
|
||||
r.error().log.c_str());
|
||||
std::abort();
|
||||
}
|
||||
out.push_back(r.value());
|
||||
@@ -843,8 +839,7 @@ void main() {
|
||||
}
|
||||
{
|
||||
Stat s = Measure([&] {
|
||||
auto ctx = spvtools::BuildModule(SPV_ENV_VULKAN_1_1, SilentConsumer(),
|
||||
mod.data(), mod.size());
|
||||
auto ctx = spvtools::BuildModule(SPV_ENV_VULKAN_1_1, SilentConsumer(), mod.data(), mod.size());
|
||||
benchmarkSink(ctx != nullptr);
|
||||
});
|
||||
Emit(name, stage, "BASELINE BuildModule only (parse, no emit)", "baseline", words, s);
|
||||
@@ -859,27 +854,19 @@ void main() {
|
||||
Emit(name, stage, "ProbeSpirvGateFeatures (merged 2 gates)", "probe", words, s);
|
||||
}
|
||||
{
|
||||
Stat s = Measure([&] {
|
||||
benchmarkSink(ShaderCompiler::DeclaresViewportIndexBuiltin(mod));
|
||||
});
|
||||
Stat s = Measure([&] { benchmarkSink(ShaderCompiler::DeclaresViewportIndexBuiltin(mod)); });
|
||||
Emit(name, stage, "DeclaresViewportIndexBuiltin", "probe", words, s);
|
||||
}
|
||||
{
|
||||
Stat s = Measure([&] {
|
||||
benchmarkSink(ShaderCompiler::DeclaresMultisampledImage(mod));
|
||||
});
|
||||
Stat s = Measure([&] { benchmarkSink(ShaderCompiler::DeclaresMultisampledImage(mod)); });
|
||||
Emit(name, stage, "DeclaresMultisampledImage", "probe", words, s);
|
||||
}
|
||||
{
|
||||
Stat s = Measure([&] {
|
||||
benchmarkSink(ShaderCompiler::DeclaresFormatlessStorageImage(mod));
|
||||
});
|
||||
Stat s = Measure([&] { benchmarkSink(ShaderCompiler::DeclaresFormatlessStorageImage(mod)); });
|
||||
Emit(name, stage, "DeclaresFormatlessStorageImage", "probe", words, s);
|
||||
}
|
||||
{
|
||||
Stat s = Measure([&] {
|
||||
benchmarkSink(ShaderCompiler::ModuleDeclaresBufferTextureSampler(mod));
|
||||
});
|
||||
Stat s = Measure([&] { benchmarkSink(ShaderCompiler::ModuleDeclaresBufferTextureSampler(mod)); });
|
||||
Emit(name, stage, "ModuleDeclaresBufferTextureSampler", "probe", words, s);
|
||||
}
|
||||
{
|
||||
@@ -931,8 +918,7 @@ void main() {
|
||||
ShaderCompiler::LowerDrawParametersForEssl(mod, out, false);
|
||||
benchmarkSink(out.size());
|
||||
});
|
||||
Emit(name, stage, "LowerDrawParametersForEssl (no-op stage: def-use cost)",
|
||||
"roundtrip", words, s);
|
||||
Emit(name, stage, "LowerDrawParametersForEssl (no-op stage: def-use cost)", "roundtrip", words, s);
|
||||
}
|
||||
{
|
||||
Stat s = Measure([&] {
|
||||
@@ -993,8 +979,7 @@ void main() {
|
||||
session.CreateOptions(&options);
|
||||
spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_GLSL_VERSION, 320);
|
||||
spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_ES, SPVC_TRUE);
|
||||
spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_VULKAN_SEMANTICS,
|
||||
SPVC_FALSE);
|
||||
spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_VULKAN_SEMANTICS, SPVC_FALSE);
|
||||
session.SetOptions(options);
|
||||
const char* result = nullptr;
|
||||
session.Compile(&result);
|
||||
@@ -1010,23 +995,19 @@ void main() {
|
||||
Stat s = Measure([&] {
|
||||
const Vector<Uint32>* eff = &mod;
|
||||
Vector<uint32_t> a, b, c, d, e, f;
|
||||
if (isVs && ShaderCompiler::LowerDrawParametersForEssl(*eff, a, false) && !a.empty())
|
||||
eff = &a;
|
||||
if (isVs && ShaderCompiler::LowerDrawParametersForEssl(*eff, a, false) && !a.empty()) eff = &a;
|
||||
auto gates = ShaderCompiler::ProbeSpirvGateFeatures(*eff);
|
||||
if (gates.DeclaresMultisampledImage &&
|
||||
ShaderCompiler::ClampMultisampleFetchesForEssl(*eff, b, 4, 1, 1, 4, false) &&
|
||||
!b.empty())
|
||||
ShaderCompiler::ClampMultisampleFetchesForEssl(*eff, b, 4, 1, 1, 4, false) && !b.empty())
|
||||
eff = &b;
|
||||
if (isVs && ShaderCompiler::SplitArrayVertexInputsForEssl(*eff, c, false) &&
|
||||
!c.empty() && c != *eff)
|
||||
if (isVs && ShaderCompiler::SplitArrayVertexInputsForEssl(*eff, c, false) && !c.empty() &&
|
||||
c != *eff)
|
||||
eff = &c;
|
||||
if (ShaderCompiler::StripUboMemberRelaxedPrecisionForEssl(*eff, d, false) && !d.empty())
|
||||
eff = &d;
|
||||
if (ShaderCompiler::StripUboMemberRelaxedPrecisionForEssl(*eff, d, false) && !d.empty()) eff = &d;
|
||||
if (ShaderCompiler::LowerRectImages(*eff, e, false) && !e.empty()) eff = &e;
|
||||
if (ShaderCompiler::Lower1DArrayImagesForEssl(*eff, f, false) && !f.empty()) eff = &f;
|
||||
Vector<uint32_t> g;
|
||||
if (!isVs && ShaderCompiler::LegalizeFragmentOutputIndexingForEssl(*eff, g, false) &&
|
||||
!g.empty())
|
||||
if (!isVs && ShaderCompiler::LegalizeFragmentOutputIndexingForEssl(*eff, g, false) && !g.empty())
|
||||
eff = &g;
|
||||
benchmarkSink(eff->size());
|
||||
});
|
||||
@@ -1043,8 +1024,7 @@ void main() {
|
||||
opt.RegisterPass(SplitArrayVertexInputsPass::CreateSplitArrayVertexInputsPass());
|
||||
}
|
||||
opt.RegisterPass(ClampMultisampleFetchPass::CreateClampMultisampleFetchPass(4, 1, 1, 4));
|
||||
opt.RegisterPass(
|
||||
StripUboMemberRelaxedPrecisionPass::CreateStripUboMemberRelaxedPrecisionPass());
|
||||
opt.RegisterPass(StripUboMemberRelaxedPrecisionPass::CreateStripUboMemberRelaxedPrecisionPass());
|
||||
opt.RegisterPass(NormalizeRectCoordinatesPass::CreateNormalizeRectCoordinatesPass());
|
||||
spvtools::OptimizerOptions o;
|
||||
o.set_run_validator(false);
|
||||
@@ -1065,8 +1045,7 @@ void main() {
|
||||
opt.RegisterPass(SplitArrayVertexInputsPass::CreateSplitArrayVertexInputsPass());
|
||||
}
|
||||
opt.RegisterPass(ClampMultisampleFetchPass::CreateClampMultisampleFetchPass(4, 1, 1, 4));
|
||||
opt.RegisterPass(
|
||||
StripUboMemberRelaxedPrecisionPass::CreateStripUboMemberRelaxedPrecisionPass());
|
||||
opt.RegisterPass(StripUboMemberRelaxedPrecisionPass::CreateStripUboMemberRelaxedPrecisionPass());
|
||||
opt.RegisterPass(NormalizeRectCoordinatesPass::CreateNormalizeRectCoordinatesPass());
|
||||
opt.RegisterPass(Lower1DArrayImagesPass::CreateLower1DArrayImagesPass());
|
||||
spvtools::OptimizerOptions o;
|
||||
@@ -1112,15 +1091,14 @@ int main(int argc, char** argv) {
|
||||
std::printf("# floor loop; sample me\n");
|
||||
std::fflush(stdout);
|
||||
for (;;) {
|
||||
ShaderAttrib a{
|
||||
.shaderType = GL_VERTEX_SHADER, .sourceStr = pre, .flags = 0, .env = &env};
|
||||
ShaderAttrib a{.shaderType = GL_VERTEX_SHADER, .sourceStr = pre, .flags = 0, .env = &env};
|
||||
auto r = ShaderCompiler::CompileShader(a);
|
||||
benchmarkSink(r.has_value());
|
||||
}
|
||||
}
|
||||
|
||||
std::printf("\n%-14s %-8s %-40s %-13s %7s %10s %10s %10s %6s\n", "corpus", "stage", "what",
|
||||
"kind", "words", "median_us", "p10_us", "p90_us", "reps");
|
||||
std::printf("\n%-14s %-8s %-40s %-13s %7s %10s %10s %10s %6s\n", "corpus", "stage", "what", "kind", "words",
|
||||
"median_us", "p10_us", "p90_us", "reps");
|
||||
std::printf("%s\n", std::string(120, '-').c_str());
|
||||
|
||||
// The per-parse FLOOR. glslang caches its version/profile built-in symbol table across
|
||||
@@ -1136,13 +1114,11 @@ int main(int argc, char** argv) {
|
||||
String pre = src;
|
||||
PreprocessShaderSource(ShaderStage::Vertex, pre, env);
|
||||
Stat s = Measure([&] {
|
||||
ShaderAttrib a{
|
||||
.shaderType = GL_VERTEX_SHADER, .sourceStr = pre, .flags = 0, .env = &env};
|
||||
ShaderAttrib a{.shaderType = GL_VERTEX_SHADER, .sourceStr = pre, .flags = 0, .env = &env};
|
||||
auto r = ShaderCompiler::CompileShader(a);
|
||||
benchmarkSink(r.has_value());
|
||||
});
|
||||
Emit("floor", "VS", std::string("glslang.parse of empty main(), #version ") + label,
|
||||
"frontend", 0, s);
|
||||
Emit("floor", "VS", std::string("glslang.parse of empty main(), #version ") + label, "frontend", 0, s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1177,8 +1153,8 @@ int main(int argc, char** argv) {
|
||||
150.0, 15, 400);
|
||||
glslang::SetThreadPoolAllocator(nullptr);
|
||||
Emit("floor", "VS", " of which: TBuiltIns::initialize (generate only)", "frontend", 0, s);
|
||||
std::printf("# generated built-in declaration text: common %zu bytes, vertex stage %zu bytes\n",
|
||||
commonBytes, stageBytes);
|
||||
std::printf("# generated built-in declaration text: common %zu bytes, vertex stage %zu bytes\n", commonBytes,
|
||||
stageBytes);
|
||||
}
|
||||
|
||||
// Splitting the floor further: how much of it is object set-up that never touches the
|
||||
@@ -1216,8 +1192,8 @@ int main(int argc, char** argv) {
|
||||
Emit("floor", "VS", " parse() with NO MobileGL env configuration", "frontend", 0, bare);
|
||||
}
|
||||
|
||||
std::printf("\n%-14s %-8s %-40s %-13s %7s %10s %10s %10s %6s\n", "corpus", "stage", "what",
|
||||
"kind", "words", "median_us", "p10_us", "p90_us", "reps");
|
||||
std::printf("\n%-14s %-8s %-40s %-13s %7s %10s %10s %10s %6s\n", "corpus", "stage", "what", "kind", "words",
|
||||
"median_us", "p10_us", "p90_us", "reps");
|
||||
std::printf("%s\n", std::string(120, '-').c_str());
|
||||
|
||||
ProfileCorpus("tiny", kTinyVs, kTinyFs);
|
||||
|
||||
Reference in New Issue
Block a user