mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-18 07:23:24 +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:
@@ -114,8 +114,10 @@ static int ScanPids(const char* pkg, int* pids) {
|
||||
|
||||
static void Push(long long t, int index, long long cpu) {
|
||||
struct Sample* s = &ring[(ringHead + ringSize) % ringCap];
|
||||
if (ringSize == ringCap) ringHead = (ringHead + 1) % ringCap;
|
||||
else ++ringSize;
|
||||
if (ringSize == ringCap)
|
||||
ringHead = (ringHead + 1) % ringCap;
|
||||
else
|
||||
++ringSize;
|
||||
s->t = t;
|
||||
s->index = index;
|
||||
s->cpu = cpu;
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
#include <unistd.h>
|
||||
|
||||
static volatile sig_atomic_t g_stop = 0;
|
||||
static void onsig(int s) { (void)s; g_stop = 1; }
|
||||
static void onsig(int s) {
|
||||
(void)s;
|
||||
g_stop = 1;
|
||||
}
|
||||
|
||||
#define MAXT 128
|
||||
#define MAXSY 400
|
||||
@@ -29,14 +32,14 @@ static void onsig(int s) { (void)s; g_stop = 1; }
|
||||
struct T {
|
||||
int tid;
|
||||
char name[32];
|
||||
long long cpu0; // utime+stime at start (ticks)
|
||||
long long vcs0; // nr_voluntary_switches at start
|
||||
long long run; // samples with syscall "running"
|
||||
long long sys[MAXSY]; // samples while in syscall nr
|
||||
long long cpu0; // utime+stime at start (ticks)
|
||||
long long vcs0; // nr_voluntary_switches at start
|
||||
long long run; // samples with syscall "running"
|
||||
long long sys[MAXSY]; // samples while in syscall nr
|
||||
long long openerr;
|
||||
};
|
||||
|
||||
static long long readfile(const char *p, char *buf, int n) {
|
||||
static long long readfile(const char* p, char* buf, int n) {
|
||||
int fd = open(p, O_RDONLY);
|
||||
if (fd < 0) return -1;
|
||||
long long r = read(fd, buf, n - 1);
|
||||
@@ -45,12 +48,15 @@ static long long readfile(const char *p, char *buf, int n) {
|
||||
return r;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 4) { fprintf(stderr, "usage: sampler pid dur_s interval_ms out\n"); return 2; }
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 4) {
|
||||
fprintf(stderr, "usage: sampler pid dur_s interval_ms out\n");
|
||||
return 2;
|
||||
}
|
||||
int pid = atoi(argv[1]);
|
||||
int durMs = atoi(argv[2]) * 1000;
|
||||
int intMs = argc > 4 ? atoi(argv[3]) : 2;
|
||||
const char *out = argc > 4 ? argv[4] : "sampler.csv";
|
||||
const char* out = argc > 4 ? argv[4] : "sampler.csv";
|
||||
|
||||
struct T ts[MAXT];
|
||||
int n = 0;
|
||||
@@ -59,35 +65,45 @@ int main(int argc, char **argv) {
|
||||
// initial scan
|
||||
for (int pass = 0; pass < 2; pass++) {
|
||||
snprintf(path, sizeof path, "/proc/%d/task", pid);
|
||||
DIR *d = opendir(path);
|
||||
if (!d) { perror("opendir task"); return 1; }
|
||||
struct dirent *e;
|
||||
DIR* d = opendir(path);
|
||||
if (!d) {
|
||||
perror("opendir task");
|
||||
return 1;
|
||||
}
|
||||
struct dirent* e;
|
||||
n = 0;
|
||||
while ((e = readdir(d)) && n < MAXT) {
|
||||
if (e->d_name[0] == '.') continue;
|
||||
int tid = atoi(e->d_name);
|
||||
if (tid <= 0) continue;
|
||||
struct T *t = &ts[n++];
|
||||
struct T* t = &ts[n++];
|
||||
memset(t, 0, sizeof *t);
|
||||
t->tid = tid;
|
||||
snprintf(path, sizeof path, "/proc/%d/task/%d/comm", pid, tid);
|
||||
if (readfile(path, buf, sizeof buf) > 0) {
|
||||
strncpy(t->name, buf, sizeof t->name - 1);
|
||||
char *nl = strchr(t->name, '\n'); if (nl) *nl = 0;
|
||||
char* nl = strchr(t->name, '\n');
|
||||
if (nl) *nl = 0;
|
||||
}
|
||||
snprintf(path, sizeof path, "/proc/%d/task/%d/stat", pid, tid);
|
||||
long long ut = 0, st = 0;
|
||||
if (readfile(path, buf, sizeof buf) > 0) {
|
||||
// fields: 1 pid, 2 comm, 3 state ... 14 utime, 15 stime.
|
||||
// tokens after ')' start at field 3, so utime is f==11, stime f==12.
|
||||
char *r = strrchr(buf, ')');
|
||||
char* r = strrchr(buf, ')');
|
||||
if (r) {
|
||||
int f = 0; char *sp = r + 1;
|
||||
int f = 0;
|
||||
char* sp = r + 1;
|
||||
while (*sp) {
|
||||
if (f == 11) ut = atoll(sp);
|
||||
if (f == 12) { st = atoll(sp); break; }
|
||||
while (*sp && *sp != ' ') sp++;
|
||||
while (*sp == ' ') sp++;
|
||||
if (f == 12) {
|
||||
st = atoll(sp);
|
||||
break;
|
||||
}
|
||||
while (*sp && *sp != ' ')
|
||||
sp++;
|
||||
while (*sp == ' ')
|
||||
sp++;
|
||||
f++;
|
||||
}
|
||||
}
|
||||
@@ -96,15 +112,15 @@ int main(int argc, char **argv) {
|
||||
snprintf(path, sizeof path, "/proc/%d/task/%d/sched", pid, tid);
|
||||
t->vcs0 = -1;
|
||||
if (readfile(path, buf, sizeof buf) > 0) {
|
||||
char *v = strstr(buf, "nr_voluntary_switches");
|
||||
char* v = strstr(buf, "nr_voluntary_switches");
|
||||
if (v) {
|
||||
char *col = strchr(v, ':');
|
||||
char* col = strchr(v, ':');
|
||||
if (col) t->vcs0 = atoll(col + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
if (n > 1) break; // first pass may catch a dying thread set
|
||||
if (n > 1) break; // first pass may catch a dying thread set
|
||||
usleep(50000);
|
||||
}
|
||||
|
||||
@@ -118,11 +134,20 @@ int main(int argc, char **argv) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
snprintf(path, sizeof path, "/proc/%d/task/%d/syscall", pid, ts[i].tid);
|
||||
long long r = readfile(path, buf, sizeof buf);
|
||||
if (r <= 0) { ts[i].openerr++; continue; }
|
||||
if (!strncmp(buf, "running", 7)) { ts[i].run++; continue; }
|
||||
if (r <= 0) {
|
||||
ts[i].openerr++;
|
||||
continue;
|
||||
}
|
||||
if (!strncmp(buf, "running", 7)) {
|
||||
ts[i].run++;
|
||||
continue;
|
||||
}
|
||||
long nr = -2;
|
||||
if (buf[0] != '-') nr = strtol(buf, NULL, 10);
|
||||
if (nr < 0) { ts[i].run++; continue; } // -1 means running
|
||||
if (nr < 0) {
|
||||
ts[i].run++;
|
||||
continue;
|
||||
} // -1 means running
|
||||
if (nr >= MAXSY) nr = MAXSY - 1;
|
||||
ts[i].sys[nr]++;
|
||||
}
|
||||
@@ -131,24 +156,32 @@ int main(int argc, char **argv) {
|
||||
elapsed = (now.tv_sec - t0.tv_sec) * 1000LL + (now.tv_nsec - t0.tv_nsec) / 1000000LL;
|
||||
}
|
||||
|
||||
FILE *f = fopen(out, "w");
|
||||
if (!f) { perror("fopen out"); return 1; }
|
||||
fprintf(f, "# pid=%d dur_ms=%lld interval_ms=%d samples_per_thread~=%lld\n",
|
||||
pid, elapsed, intMs, elapsed / intMs);
|
||||
FILE* f = fopen(out, "w");
|
||||
if (!f) {
|
||||
perror("fopen out");
|
||||
return 1;
|
||||
}
|
||||
fprintf(f, "# pid=%d dur_ms=%lld interval_ms=%d samples_per_thread~=%lld\n", pid, elapsed, intMs, elapsed / intMs);
|
||||
fprintf(f, "tid,name,cpu_ticks_delta,vcs_delta,run_samples,open_err,sys_hist\n");
|
||||
for (int i = 0; i < n; i++) {
|
||||
struct T *t = &ts[i];
|
||||
struct T* t = &ts[i];
|
||||
long long ut = 0, st = 0;
|
||||
snprintf(path, sizeof path, "/proc/%d/task/%d/stat", pid, t->tid);
|
||||
if (readfile(path, buf, sizeof buf) > 0) {
|
||||
char *r = strrchr(buf, ')');
|
||||
char* r = strrchr(buf, ')');
|
||||
if (r) {
|
||||
int f2 = 0; char *sp = r + 1;
|
||||
int f2 = 0;
|
||||
char* sp = r + 1;
|
||||
while (*sp) {
|
||||
if (f2 == 11) ut = atoll(sp);
|
||||
if (f2 == 12) { st = atoll(sp); break; }
|
||||
while (*sp && *sp != ' ') sp++;
|
||||
while (*sp == ' ') sp++;
|
||||
if (f2 == 12) {
|
||||
st = atoll(sp);
|
||||
break;
|
||||
}
|
||||
while (*sp && *sp != ' ')
|
||||
sp++;
|
||||
while (*sp == ' ')
|
||||
sp++;
|
||||
f2++;
|
||||
}
|
||||
}
|
||||
@@ -156,15 +189,14 @@ int main(int argc, char **argv) {
|
||||
long long vcs = -1;
|
||||
snprintf(path, sizeof path, "/proc/%d/task/%d/sched", pid, t->tid);
|
||||
if (readfile(path, buf, sizeof buf) > 0) {
|
||||
char *v = strstr(buf, "nr_voluntary_switches");
|
||||
char* v = strstr(buf, "nr_voluntary_switches");
|
||||
if (v) {
|
||||
char *col = strchr(v, ':');
|
||||
char* col = strchr(v, ':');
|
||||
if (col) vcs = atoll(col + 1);
|
||||
}
|
||||
}
|
||||
fprintf(f, "%d,%s,%lld,%lld,%lld,%lld,\"", t->tid, t->name,
|
||||
(ut + st) - t->cpu0, (vcs >= 0 && t->vcs0 >= 0) ? vcs - t->vcs0 : -1,
|
||||
t->run, t->openerr);
|
||||
fprintf(f, "%d,%s,%lld,%lld,%lld,%lld,\"", t->tid, t->name, (ut + st) - t->cpu0,
|
||||
(vcs >= 0 && t->vcs0 >= 0) ? vcs - t->vcs0 : -1, t->run, t->openerr);
|
||||
for (int s = 0; s < MAXSY; s++)
|
||||
if (t->sys[s]) fprintf(f, "%d:%lld;", s, t->sys[s]);
|
||||
fprintf(f, "\"\n");
|
||||
|
||||
@@ -18,53 +18,57 @@
|
||||
#undef GL_GLEXT_PROTOTYPES
|
||||
|
||||
namespace MGITest {
|
||||
class P5fPublicMipmapScenario : public ScenarioTest {
|
||||
protected:
|
||||
void Check(bool gpuWritten) {
|
||||
if (!Ready()) return;
|
||||
GLuint texture = 0, fbo = 0;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
std::array<GLubyte, 4 * 4 * 4> red{};
|
||||
for (std::size_t i = 0; i < red.size(); i += 4) {
|
||||
red[i] = 255;
|
||||
red[i + 3] = 255;
|
||||
class P5fPublicMipmapScenario : public ScenarioTest {
|
||||
protected:
|
||||
void Check(bool gpuWritten) {
|
||||
if (!Ready()) return;
|
||||
GLuint texture = 0, fbo = 0;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
std::array<GLubyte, 4 * 4 * 4> red{};
|
||||
for (std::size_t i = 0; i < red.size(); i += 4) {
|
||||
red[i] = 255;
|
||||
red[i + 3] = 255;
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, red.data());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
if (gpuWritten) {
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||
ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GLenum{GL_FRAMEBUFFER_COMPLETE});
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
for (GLint level = 0; level <= 2; ++level) {
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
|
||||
ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GLenum{GL_FRAMEBUFFER_COMPLETE}) << level;
|
||||
std::array<GLubyte, 4> pixel{71, 72, 73, 74};
|
||||
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel.data());
|
||||
EXPECT_EQ(pixel[0], gpuWritten ? 0 : 255) << "mip=" << level;
|
||||
EXPECT_EQ(pixel[1], gpuWritten ? 255 : 0) << "mip=" << level;
|
||||
EXPECT_EQ(pixel[2], 0) << "mip=" << level;
|
||||
EXPECT_EQ(pixel[3], 255) << "mip=" << level;
|
||||
}
|
||||
EXPECT_EQ(glGetError(), GLenum{GL_NO_ERROR});
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
glDeleteTextures(1, &texture);
|
||||
Gl().EndFrame();
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, red.data());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
if (gpuWritten) {
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||
ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GLenum{GL_FRAMEBUFFER_COMPLETE});
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
for (GLint level = 0; level <= 2; ++level) {
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
|
||||
ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GLenum{GL_FRAMEBUFFER_COMPLETE}) << level;
|
||||
std::array<GLubyte, 4> pixel{71, 72, 73, 74};
|
||||
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel.data());
|
||||
EXPECT_EQ(pixel[0], gpuWritten ? 0 : 255) << "mip=" << level;
|
||||
EXPECT_EQ(pixel[1], gpuWritten ? 255 : 0) << "mip=" << level;
|
||||
EXPECT_EQ(pixel[2], 0) << "mip=" << level;
|
||||
EXPECT_EQ(pixel[3], 255) << "mip=" << level;
|
||||
}
|
||||
EXPECT_EQ(glGetError(), GLenum{GL_NO_ERROR});
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
glDeleteTextures(1, &texture);
|
||||
Gl().EndFrame();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TEST_F(P5fPublicMipmapScenario, UploadedRgba8BaseGeneratesRedMipChain) { Check(false); }
|
||||
TEST_F(P5fPublicMipmapScenario, GpuWrittenBaseGeneratesGreenMipChainWithoutStaleCpuUpload) { Check(true); }
|
||||
TEST_F(P5fPublicMipmapScenario, UploadedRgba8BaseGeneratesRedMipChain) {
|
||||
Check(false);
|
||||
}
|
||||
TEST_F(P5fPublicMipmapScenario, GpuWrittenBaseGeneratesGreenMipChainWithoutStaleCpuUpload) {
|
||||
Check(true);
|
||||
}
|
||||
} // namespace MGITest
|
||||
|
||||
Reference in New Issue
Block a user