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
One texture per slot, so a misbinding cannot read right; and the Adreno texture job
vcvkk192ea3d873ef
diff --git a/tools/mesa/air/air_run.c b/tools/mesa/air/air_run.cindex 71302af..9d3036d 100644--- a/tools/mesa/air/air_run.c+++ b/tools/mesa/air/air_run.c@@ -79,10 +79,17 @@#define TEX_X 1#define TEX_Y 1+/* Slot is in the value on purpose. Binding one texture to every slot makes a+ * shader that reads the wrong slot return the right texel, which is a test+ * passing for the wrong reason -- the third time that shape of mistake has+ * turned up here, after the 2D texture bound for a 3D sampler and the colour+ * attachment nothing stored to. Looked for deliberately this time rather than+ * tripped over: slot n adds a thousand times n, so a misbinding is visible.+ */static void-texel_value(unsigned x, unsigned y, unsigned z, float out[4])+texel_value(unsigned slot, unsigned x, unsigned y, unsigned z, float out[4]){- out[0] = 100.0f + x;+ out[0] = 100.0f + x + 1000.0f * slot;out[1] = 200.0f + y;out[2] = 300.0f + x + y + z;out[3] = 400.0f;@@ -549,31 +556,33 @@ main(int argc, char **argv)unsigned depth = target == PIPE_TEXTURE_3D ? TEX_SIZE : 1;unsigned tex_z = target == PIPE_TEXTURE_3D ? TEX_Y : 0;- float texels[TEX_SIZE * TEX_SIZE * TEX_SIZE * 4];- int32_t itexels[TEX_SIZE * TEX_SIZE * TEX_SIZE * 4];- for (unsigned z = 0; z < depth; z++) {- for (unsigned y = 0; y < TEX_SIZE; y++) {- for (unsigned x = 0; x < TEX_SIZE; x++) {- unsigned i = ((z * TEX_SIZE + y) * TEX_SIZE + x) * 4;- texel_value(x, y, z, &texels[i]);- for (unsigned c = 0; c < 4; c++)- itexels[i + c] = (int32_t)texels[i + c];- }- }- }-struct pipe_resource ttempl = {.target = target,.format = tex_format,.width0 = TEX_SIZE, .height0 = TEX_SIZE, .depth0 = depth, .array_size = 1,.bind = PIPE_BIND_SAMPLER_VIEW,};- struct pipe_resource *tex = screen->resource_create(screen, &ttempl);struct pipe_box box = { .width = TEX_SIZE, .height = TEX_SIZE, .depth = depth };- pipe->texture_subdata(pipe, tex, 0, PIPE_MAP_WRITE, &box,- tex_is_float ? (const void *)texels : (const void *)itexels,- TEX_SIZE * 4 * sizeof(float),- TEX_SIZE * TEX_SIZE * 4 * sizeof(float));+ struct pipe_resource *texes[PIPE_MAX_SAMPLERS] = { 0 };+ for (unsigned slot = 0; slot < num_tex && slot < PIPE_MAX_SAMPLERS; slot++) {+ float texels[TEX_SIZE * TEX_SIZE * TEX_SIZE * 4];+ int32_t itexels[TEX_SIZE * TEX_SIZE * TEX_SIZE * 4];+ for (unsigned z = 0; z < depth; z++) {+ for (unsigned y = 0; y < TEX_SIZE; y++) {+ for (unsigned x = 0; x < TEX_SIZE; x++) {+ unsigned i = ((z * TEX_SIZE + y) * TEX_SIZE + x) * 4;+ texel_value(slot, x, y, z, &texels[i]);+ for (unsigned c = 0; c < 4; c++)+ itexels[i + c] = (int32_t)texels[i + c];+ }+ }+ }+ texes[slot] = screen->resource_create(screen, &ttempl);+ pipe->texture_subdata(pipe, texes[slot], 0, PIPE_MAP_WRITE, &box,+ tex_is_float ? (const void *)texels : (const void *)itexels,+ TEX_SIZE * 4 * sizeof(float),+ TEX_SIZE * TEX_SIZE * 4 * sizeof(float));+ }void *sampler = pipe->create_sampler_state(pipe, &(struct pipe_sampler_state){.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE,@@ -588,17 +597,17 @@ main(int argc, char **argv)void *samplers[PIPE_MAX_SAMPLERS] = { 0 };for (unsigned i = 0; i < num_tex && i < PIPE_MAX_SAMPLERS; i++) {struct pipe_sampler_view vtempl = { 0 };- u_sampler_view_default_template(&vtempl, tex, tex->format);- views[i] = pipe->create_sampler_view(pipe, tex, &vtempl);+ u_sampler_view_default_template(&vtempl, texes[i], texes[i]->format);+ views[i] = pipe->create_sampler_view(pipe, texes[i], &vtempl);samplers[i] = sampler;}pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num_tex, 0, false, views);pipe->bind_sampler_states(pipe, PIPE_SHADER_FRAGMENT, 0, num_tex, samplers);float want[4];- texel_value(TEX_X, TEX_Y, tex_z, want);- printf("air_run: %u texture%s bound: %ux%ux%u %s, texel (x,y,z) = "- "(100+x, 200+y, 300+x+y+z, 400), nearest, clamped\n",+ texel_value(0, TEX_X, TEX_Y, tex_z, want);+ printf("air_run: %u texture%s bound: %ux%ux%u %s, texel (x,y,z) of slot n = "+ "(100+x+1000n, 200+y, 300+x+y+z, 400), nearest, clamped\n",num_tex, num_tex == 1 ? "" : "s", TEX_SIZE, TEX_SIZE, depth,util_format_short_name(tex_format));printf("air_run: expected %.9g %.9g %.9g %.9g (the centre of texel %u,%u,%u sampled "diff --git a/userland/rc.jobs.airtex b/userland/rc.jobs.airtexnew file mode 100644index 0000000..882c1df--- /dev/null+++ b/userland/rc.jobs.airtex@@ -0,0 +1,26 @@+# Commands run by the launchd job com.redwood.demo (see com.redwood.demo.plist).+#+# The six texture shaders that return the exact texel on softpipe, run on the real Adreno+# (RC_JOBS=rc.jobs.airtex). This is the question softpipe cannot answer: it takes a+# pipe_sampler_view and samples it in C, while a6xx wants real descriptors in memory, a+# sampler state block and the right binding slots for the texture instructions ir3 emits.+# Six exact texels on softpipe say nothing about any of that.+#+# air_run binds a texture per slot whose texel (x,y,z) of slot n is+# (100+x+1000n, 200+y, 300+x+y+z, 400) -- the slot is in the value so that reading the+# wrong slot cannot return the right texel -- a nearest sampler with clamped addressing,+# and a coordinate at the centre of texel (1,1). So each line below must print exactly:+#+# 2D float/int/uint: 101 201 302 400+# 3D float/int/uint: 101 201 303 400+#+# Nearest filtering at a texel centre has no weights to round and clamping has no+# arithmetic, so a mismatch here can only be binding or descriptors -- the narrowest+# failure this test will ever have. Read each "on ..." line before its numbers.+# (the full path on every line: nothing here promises these go through a shell)+/redwood/bin/air_run /System/Library/Extensions/AppleMetalGLRenderer.bundle/default.metallib texturedFragment2DFloat+/redwood/bin/air_run /System/Library/Extensions/AppleMetalGLRenderer.bundle/default.metallib texturedFragment3DFloat+/redwood/bin/air_run /System/Library/Extensions/AppleMetalGLRenderer.bundle/default.metallib texturedFragment2DInt+/redwood/bin/air_run /System/Library/Extensions/AppleMetalGLRenderer.bundle/default.metallib texturedFragment3DInt+/redwood/bin/air_run /System/Library/Extensions/AppleMetalGLRenderer.bundle/default.metallib texturedFragment2DUInt+/redwood/bin/air_run /System/Library/Extensions/AppleMetalGLRenderer.bundle/default.metallib texturedFragment3DUInt