Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
Frames without missing parts: a frame's end sends what Mesa holds back to the kernel
vcvkkf5249c04b93c
diff --git a/README.md b/README.mdindex d5d3aab..0efbaea 100644--- a/README.md+++ b/README.md@@ -351,6 +351,16 @@ CoreAnimation; если GPU не запустился, в журнале однШейдеры CoreAnimation считаются с полной точностью (`lowp` и `mediump` в них определены как `highp`): 16-битного`mediump` у Adreno не хватало на таблицу цветов градиента — фон виджета «Погода» шёл полосами; `glprecision=0`возвращает как написано.+Кадр уходит на панель, когда GPU закончил последнюю отправку, в которой была его поверхность; но freedreno после+`glFlush` может придержать последнюю небольшую отправку кадра, чтобы слить её со следующей, и тогда панель+показывала кадр, в котором нарисованы только ранние части: обои без иконок, прямоугольники из старой картинки —+на кадр-другой при каждом открытии Пункта управления, Центра уведомлений, Поиска и приложений (заметно с тех пор,+как экран стал sRGB: с P3 последние отправки кадра были другими). Теперь конец кадра в `userland/src/eagl.c`+просит у Mesa забор с флагом сброса и не ждёт его: всё придержанное сразу уходит в ядро, GPU не ждём; частота+кадров та же (`rc.jobs.fps`). `glsync=0` выключает это для проверки, `RC_JOBS=rc.jobs.gfx` с записью экрана —+жесты, на которых это было видно. Для проверок есть и `gpu_keep=0` (ядро не держит буферы программ для повторной+выдачи; `gpu_keep=2` — держит, но выдаёт очищенными) и параметр загрузчика `gamut=p3` (в дереве устройств+остаётся «artwork-display-gamut» P3 самого iPhone — Safari тогда рисует чёрные страницы).`glframes=1` — строка на каждый кадр оконного сервера: когда он кончен (время ядра), сколько отрисовок, в какую поверхность экрана, прямоугольник отсечения первой отрисовки в неё и отрисовки размытия с переменным радиусом; вместе с `rec_ring=1` кадры записи сопоставляются со строками.`glcensus=1` ведёт перепись: каждая отрисовка без программы (номер и имя функции, где на экране, с какимитекстурами и числами, чем нарисована здесь) — при первой встрече, и каждые десять секунд счёт по функциям; туда жеdiff --git a/userland/rc.jobs.gfx b/userland/rc.jobs.gfxnew file mode 100644index 0000000..8bd7ec3--- /dev/null+++ b/userland/rc.jobs.gfx@@ -0,0 +1,10 @@+# Commands run by the launchd job com.redwood.demo (see com.redwood.demo.plist).+# The moments with a blur or a fresh window, for the screen recording (rec_secs=N rec_start=S): once SpringBoard is+# up, Control Center pulled down from the top right corner and closed, Notification Center pulled down from the+# top left and closed, Search pulled down on the home screen and closed, Settings opened and closed with the home+# gesture; twice over, two seconds apart.+/redwood/bin/sound_test springboard+/redwood/bin/rwtouch wait 20 swipe 0.92 0.003 0.92 0.5 300 wait 2.5 button home wait 2 swipe 0.2 0.003 0.2 0.6 300 wait 2.5 button home wait 2+/redwood/bin/rwtouch swipe 0.5 0.4 0.5 0.7 300 wait 2.5 button home wait 2 tap 0.615 0.71 wait 2.5 swipe 0.5 0.995 0.5 0.55 150 wait 2+/redwood/bin/rwtouch swipe 0.92 0.003 0.92 0.5 300 wait 2.5 button home wait 2 swipe 0.2 0.003 0.2 0.6 300 wait 2.5 button home wait 2+/redwood/bin/rwtouch swipe 0.5 0.4 0.5 0.7 300 wait 2.5 button home wait 2 tap 0.615 0.71 wait 2.5 swipe 0.5 0.995 0.5 0.55 150 wait 2diff --git a/userland/src/eagl.c b/userland/src/eagl.cindex 958401f..7cc8ca0 100644--- a/userland/src/eagl.c+++ b/userland/src/eagl.c@@ -120,6 +120,8 @@ typedef GLDEBUGPROC GLDEBUGPROCKHR;#define GL_COLOR_ATTACHMENT0 0x8ce0#define GL_FRAMEBUFFER_COMPLETE 0x8cd5#define GL_FRAMEBUFFER 0x8d40+#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117+#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001#define VBLUR_LEVELS 8 /* levels of a blur whose radius varies, the picture itself included */#define VBLUR_CHAINS 6 /* ... such blurs kept track of at a time */@@ -305,6 +307,7 @@ static int share_surfaces = 1; /* boot-arg glcopy=1: 0 */* here in any case; glwait=0: nowhere, to see what the waiting costs (and frames half drawn).*/static int wait_for_frames = 1;+static int sync_frames = 1; /* boot-arg glsync=0 (a test): a frame's end does not push what Mesa holds back (frame_end()) *//** EXT_shader_framebuffer_fetch -- a fragment shader reads the pixel it is about to write -- is* what CoreAnimation draws a number of things with where the library offers it: the shadows@@ -810,6 +813,21 @@ frame_end(struct eagl *e, bool finished)}if (in_place != 0 && !finished && wait_for_frames) {glFinish(); /* the display's driver reads the surface as soon as it is told of it */+ } else if (in_place != 0 && !finished && sync_frames) {+ /*+ * The display's driver waits for the last submission that named the surface -- but Mesa's+ * freedreno may still hold the frame's last batch back after glFlush, to merge it with the+ * next (submit merging, for small submissions), and then the frame goes to the panel with only+ * its earlier batches drawn: the wallpaper without the icons, blocks of an older picture,+ * for a frame. A fence that is asked to flush and waited for not at all sends everything held+ * back to the kernel now; the GPU is not waited for.+ */+ GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);++ if (sync != NULL) {+ (void)glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, 0);+ glDeleteSync(sync);+ }}waited = now_us();for (unsigned i = 0; i < e->image_count; i++) {@@ -3021,6 +3039,7 @@ install(void)shown_texture = (GLuint)strtoul(argument + 7, NULL, 10);}share_surfaces = strstr(arguments, "glcopy=1") == NULL;+ sync_frames = strstr(arguments, "glsync=0") == NULL;if (strstr(arguments, "glwait=0") != NULL || (strstr(arguments, "glwait=1") == NULL && display_waits())) {wait_for_frames = 0;}diff --git a/xnu/files/iokit/Kernel/RedwoodGPU.cpp b/xnu/files/iokit/Kernel/RedwoodGPU.cppindex a6e5352..8b2dc4d 100644--- a/xnu/files/iokit/Kernel/RedwoodGPU.cpp+++ b/xnu/files/iokit/Kernel/RedwoodGPU.cpp@@ -391,6 +391,7 @@ struct gpu_kept {#define GPU_KEPT_BYTES (160ull << 20)#define GPU_KEPT_SECONDS 60 /* a buffer not asked for again in so long is let go */#define GPU_KEEP_FROM (256u << 10) /* bytes: smaller ones are not worth it */+static TUNABLE(uint32_t, gGPUKeep, "gpu_keep", 1); /* boot-arg gpu_keep=0 (a test): none kept; gpu_keep=2: kept ones cleared when given again */class RedwoodGPUUserClient : public IOUserClient{@@ -657,7 +658,7 @@ RedwoodGPUUserClient::keep(IOMemoryDescriptor * memory, uint8_t * kernel, uint64{struct gpu_kept * place = NULL;- if (size < GPU_KEEP_FROM || size > GPU_KEPT_BYTES / 4 || memory == NULL ||+ if (gGPUKeep == 0 || size < GPU_KEEP_FROM || size > GPU_KEPT_BYTES / 4 || memory == NULL ||(kernel == NULL && OSDynamicCast(IOBufferMemoryDescriptor, memory) == NULL)) {return false;}@@ -733,6 +734,9 @@ RedwoodGPUUserClient::gemNew(struct msm_gem_new * request)fKeptBytes -= size;gGPUStat.given_again++;IOLockUnlock(gGPULock);+ if (gGPUKeep == 2) {+ bzero(b->kernel, (size_t) b->size);+ }return kIOReturnSuccess;}}diff --git a/xnuloader/loader.c b/xnuloader/loader.cindex 6fa06ce..3a0d27c 100644--- a/xnuloader/loader.c+++ b/xnuloader/loader.c@@ -420,11 +420,13 @@ dt_prop_padded(struct dt_writer *w, const char *name, const char *value, uint32_* server's renderer here do (eight bits, BGRA), and every page comes out black. Here the screen is* what the framebuffer is: sRGB.*/+static int gamut_p3; /* boot-arg gamut=p3 (a test): the iPhone's own "P3" left in place */+static voiddt_identity(struct dt_writer *w, const struct identity_prop *props, uint32_t count, const unsigned char *data){for (uint32_t i = 0; i < count; i++) {- if (str_eq(props[i].name, "artwork-display-gamut")) {+ if (str_eq(props[i].name, "artwork-display-gamut") && !gamut_p3) {dt_prop(w, props[i].name, "sRGB", 5);continue;}@@ -1743,6 +1745,7 @@ run_kernel(int have_checkpoint, uint64_t checkpoint)battery_requested |= starts_with(c, "battery=1") && (c == pi.cmdline || c[-1] == ' ') &&(c[9] == 0 || c[9] == ' ');torch_requested |= starts_with(c, "torch=") && (c == pi.cmdline || c[-1] == ' ') && c[6] >= '1' && c[6] <= '9';+ gamut_p3 |= starts_with(c, "gamut=p3") && (c == pi.cmdline || c[-1] == ' ');}if (battery_requested) {charger_start();