Skip to content

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

A Metal shader drew on the Adreno: M1 is finished, and the driver serves more than the window server

vcvkkd21f6479e817
diff --git a/docs/air.md b/docs/air.md
index 9e0dd3a..8e623aa 100644
--- a/docs/air.md
+++ b/docs/air.md
@@ -376,7 +376,8 @@ an unhandled metadata key), so "features not yet handled" is a ranked list, not
**Done**, and further than stated: all 456 also pass *reader*, our own reader agreeing with
`llvm-dis` on every one.
- **M1** — `clearFragment01` reaches *adreno*: translated, compiled by ir3, rendered on the
- Adreno, framebuffer equal to the colour in its constant buffer.
+ Adreno, framebuffer equal to the colour in its constant buffer. **Done** (20 October, section
+ 5a).
**Done except for the Adreno itself.** It is `nir_load_ubo` + a store to `FRAG_RESULT_DATA0`
as predicted, and ir3 turns it into five Adreno instructions (four `mov`s out of the constant
file, where ir3 promoted the UBO load). Over a buffer of known bytes, LLVM's own execution of
@@ -515,8 +516,47 @@ Without the fault handler there would have been nothing at all to go on: iOS ans
with "Failed to send exception EXC_CORPSE_NOTIFY" and no report. Four lines of borrowed code
turned a silent exit into an exact address.
-What is *still* not known is whether the kernel's GPU driver and the submit path behave for a draw
-that does not come from CoreAnimation: the GLES path is that driver's only consumer today. `rc.jobs.air` asks with the GPU idle; `rc.jobs.air2` asks again after SpringBoard
+### It drew on the Adreno. M1 is finished.
+
+20 October, `logs/000338-run.log`, with the config bug fixed:
+
+```
+air_run: clearFragment01 on Adreno 7c+ Gen 3 (the GPU, through the kernel's msm device)
+...
+air_run: read back from Adreno 7c+ Gen 3 (the GPU, through the kernel's msm device),
+ ir3's instructions are above
+air_run: the pixel at (0, 0) of render target 0 came back as:
+ 2.10170319e-18
+ 0.178894654
+ 1.48687698e+16
+ 1.21394141e+33
+```
+
+**A shader Apple compiled for Metal, translated here, compiled by ir3, run on the phone's GPU,
+giving the colour out of its constant buffer bit for bit.** Four independent references now agree
+on those four floats: LLVM's own execution of the module on a computer, our NIR folded over the
+same bytes, softpipe, and the Adreno.
+
+Three things had to be asserted rather than assumed, because the pixel looks identical whichever
+path produced it:
+
+- **which screen was created** — the first line, which is what caught the earlier run where the
+ GPU driver had never started;
+- **which screen the pixel came out of** — the same name printed again beside the numbers;
+- **that the shader went through ir3 at all** — `--disasm`, which puts ir3's own output in the
+ log. It is `; FRAG prog 1/1: 5 instr, 0 nops, 5 non-nops, 4 mov` and four `mov.u32u32 r0.x,
+ c0.x`: the same five instructions, mov for mov, that `ir3_compiler` produced for this shader on
+ the host months of work earlier. The constant file holds the Metal buffer, which is where ir3
+ promoted the `nir_load_ubo` to.
+
+### And the driver takes work that is not the window server's
+
+`logs/000739-run.log`, `rc.jobs.air2`: the same draw after SpringBoard is up — 287 mentions of it
+in the log, the ringer sounding at 29 s, the window server holding the GPU and drawing iOS through
+`src/eagl.c`. `air_run` still got `Adreno 7c+ Gen 3` and still read back the same four floats.
+
+So the kernel's GPU driver serves a second process while CoreAnimation is drawing. That question
+was owed to the whole port rather than to this frontend, and the answer is yes. `rc.jobs.air` asks with the GPU idle; `rc.jobs.air2` asks again after SpringBoard
is up and holding it. A refusal is a finding the whole port needs, not just this frontend, so
either answer is worth the run.
diff --git a/tools/mesa/air/air_run.c b/tools/mesa/air/air_run.c
index ee36e2b..64b122e 100644
--- a/tools/mesa/air/air_run.c
+++ b/tools/mesa/air/air_run.c
@@ -172,8 +172,22 @@ finalize_for_gallium(nir_shader *nir)
int
main(int argc, char **argv)
{
+ /* --disasm: ask ir3 to print the Adreno instructions it generates. The
+ * screen's name proves fd_screen_create won; it does not prove that the
+ * shader itself went through ir3 rather than some later software path, and
+ * the four floats look identical either way. ir3's own disassembly in the
+ * log is the positive proof. IR3_SHADER_DEBUG is read once, at compiler
+ * creation, so it has to be set before the screen is made.
+ */
+ bool want_disasm = false;
+ if (argc > 1 && !strcmp(argv[1], "--disasm")) {
+ want_disasm = true;
+ setenv("IR3_SHADER_DEBUG", "disasm", 1);
+ argv++;
+ argc--;
+ }
if (argc < 2) {
- fprintf(stderr, "usage: air_run FILE[.metallib] [FUNCTION]\n");
+ fprintf(stderr, "usage: air_run [--disasm] FILE[.metallib] [FUNCTION]\n");
return 2;
}
@@ -232,6 +246,7 @@ main(int argc, char **argv)
* AIR_RUN_SOFTWARE=1 forces software even where a GPU is present.
*/
struct pipe_screen *screen = NULL;
+ const char *how = "software";
#ifdef GALLIUM_FREEDRENO
if (!debug_get_bool_option("AIR_RUN_SOFTWARE", false)) {
int fd = drmOpenWithType("msm", NULL, DRM_NODE_RENDER);
@@ -256,7 +271,9 @@ main(int argc, char **argv)
config.options_info = &info;
screen = fd_drm_screen_create_renderonly(fd, NULL, &config);
- if (!screen)
+ if (screen)
+ how = "the GPU, through the kernel's msm device";
+ else
fprintf(stderr, "air_run: the msm device opened but gave no screen\n");
}
}
@@ -267,7 +284,7 @@ main(int argc, char **argv)
fprintf(stderr, "air_run: no gallium screen\n");
return 1;
}
- printf("air_run: %s on %s\n", name, screen->get_name(screen));
+ printf("air_run: %s on %s (%s)\n", name, screen->get_name(screen), how);
const void *options =
screen->get_compiler_options(screen, PIPE_SHADER_IR_NIR, PIPE_SHADER_FRAGMENT);
@@ -455,6 +472,13 @@ main(int argc, char **argv)
fprintf(stderr, "air_run: the render target could not be read back\n");
return 1;
}
+ /* Named again here, beside the numbers: the line at the top says which
+ * screen was created, this one says which screen the pixel just came out
+ * of. Neither is proof that no stage in between went software -- --disasm
+ * is, by making ir3 print what it compiled.
+ */
+ printf("air_run: read back from %s (%s)%s\n", screen->get_name(screen), how,
+ want_disasm ? ", ir3's instructions are above" : "");
printf("air_run: the pixel at (0, 0) of render target %u came back as:\n",
read_rt);
for (unsigned c = 0; c < 4; c++) {
diff --git a/userland/rc.jobs.air b/userland/rc.jobs.air
index 8cd5478..a94e193 100644
--- a/userland/rc.jobs.air
+++ b/userland/rc.jobs.air
@@ -18,4 +18,7 @@
# No wait for SpringBoard: this draws for itself and wants the GPU idle rather than busy with
# the window server. With gpu=1 the window server has it too, which is worth knowing about on
# purpose -- but the first run should be the simple one.
-/redwood/bin/air_run /System/Library/Extensions/AppleMetalGLRenderer.bundle/default.metallib clearFragment01
+# --disasm makes ir3 print the Adreno instructions it generated. The screen's name proves
+# fd_screen_create won; only ir3's own disassembly proves the shader went through ir3 and not
+# some later software path, and the four floats look identical either way.
+/redwood/bin/air_run --disasm /System/Library/Extensions/AppleMetalGLRenderer.bundle/default.metallib clearFragment01