From 58d138334d92c18d183873fd70a0481f4edf7535 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sun, 11 Sep 2022 12:03:01 -0400 Subject: [PATCH] asahi: Shuffle IOGPU structs We need the header to be common between gfx and compute, but everything else seems to be different. Shuffle so we can decode compute without any terrible hacks. I don't know the exact layout and don't care: the layout of the fields here is all software defined in macOS, even though the *values* are defined by hardware (or firmware in a few cases). Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/cmdbuf.xml | 196 ++++++++++++++++++-------------------- src/asahi/lib/decode.c | 50 ++++------ src/gallium/drivers/asahi/magic.c | 41 ++++---- 3 files changed, 129 insertions(+), 158 deletions(-) diff --git a/src/asahi/lib/cmdbuf.xml b/src/asahi/lib/cmdbuf.xml index 66aaa38..be39707 100644 --- a/src/asahi/lib/cmdbuf.xml +++ b/src/asahi/lib/cmdbuf.xml @@ -714,33 +714,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -773,84 +746,105 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - + + + + - - - + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/asahi/lib/decode.c b/src/asahi/lib/decode.c index ccfc6ba..d8e343e 100644 --- a/src/asahi/lib/decode.c +++ b/src/asahi/lib/decode.c @@ -611,26 +611,10 @@ agxdecode_cmdstream(unsigned cmdbuf_handle, unsigned map_handle, bool verbose) /* Print the IOGPU stuff */ agx_unpack(agxdecode_dump_stream, cmdbuf->ptr.cpu, IOGPU_HEADER, cmd); DUMP_UNPACKED(IOGPU_HEADER, cmd, "IOGPU Header\n"); - agx_unpack(agxdecode_dump_stream, ((uint32_t *) cmdbuf->ptr.cpu) + 160, - IOGPU_INTERNAL_PIPELINES, pip); - DUMP_CL(IOGPU_INTERNAL_PIPELINES, ((uint32_t *) cmdbuf->ptr.cpu) + 160, "Internal pipelines"); - DUMP_CL(IOGPU_AUX_FRAMEBUFFER, ((uint32_t *) cmdbuf->ptr.cpu) + 228, "Aux Framebuffer"); - - agx_unpack(agxdecode_dump_stream, ((uint32_t *) cmdbuf->ptr.cpu) + 292, - IOGPU_CLEAR_Z_S, clearzs); - DUMP_UNPACKED(IOGPU_CLEAR_Z_S, clearzs, "Clear Z/S"); - - /* Guard against changes */ - uint32_t zeroes[356 - 344] = { 0 }; - assert(memcmp(((uint32_t *) cmdbuf->ptr.cpu) + 344, zeroes, 4 * (356 - 344)) == 0); - - DUMP_CL(IOGPU_MISC, ((uint32_t *) cmdbuf->ptr.cpu) + 356, "Misc"); - - /* Should be unused, we think */ - for (unsigned i = (0x6B0 / 4); i < (cmd.attachment_offset / 4); ++i) { - assert(((uint32_t *) cmdbuf->ptr.cpu)[i] == 0); - } + agx_unpack(agxdecode_dump_stream, ((uint32_t *) cmdbuf->ptr.cpu) + 16, + IOGPU_GRAPHICS, gfx); + DUMP_UNPACKED(IOGPU_GRAPHICS, gfx, "Graphics\n"); DUMP_CL(IOGPU_ATTACHMENT_COUNT, ((uint8_t *) cmdbuf->ptr.cpu + cmd.attachment_offset), "Attachment count"); @@ -642,33 +626,31 @@ agxdecode_cmdstream(unsigned cmdbuf_handle, unsigned map_handle, bool verbose) DUMP_CL(IOGPU_ATTACHMENT, ptr, "Attachment"); } - uint64_t *encoder = ((uint64_t *) cmdbuf->ptr.cpu) + 7; - if (cmd.unk_5 == 3) - agxdecode_stateful(*encoder, "Encoder", agxdecode_cdm, verbose); + agxdecode_stateful(cmd.encoder, "Encoder", agxdecode_cdm, verbose); else - agxdecode_stateful(*encoder, "Encoder", agxdecode_vdm, verbose); + agxdecode_stateful(cmd.encoder, "Encoder", agxdecode_vdm, verbose); - if (pip.clear_pipeline_unk) { - fprintf(agxdecode_dump_stream, "Unk: %X\n", pip.clear_pipeline_unk); - agxdecode_stateful(pip.clear_pipeline, "Clear pipeline", + if (gfx.clear_pipeline_unk) { + fprintf(agxdecode_dump_stream, "Unk: %X\n", gfx.clear_pipeline_unk); + agxdecode_stateful(gfx.clear_pipeline, "Clear pipeline", agxdecode_pipeline, verbose); } - if (pip.store_pipeline_unk) { - assert(pip.store_pipeline_unk == 0x4); - agxdecode_stateful(pip.store_pipeline, "Store pipeline", + if (gfx.store_pipeline_unk) { + assert(gfx.store_pipeline_unk == 0x4); + agxdecode_stateful(gfx.store_pipeline, "Store pipeline", agxdecode_pipeline, verbose); } - assert((clearzs.partial_reload_pipeline_unk & 0xF) == 0x4); - if (clearzs.partial_reload_pipeline) { - agxdecode_stateful(clearzs.partial_reload_pipeline, + assert((gfx.partial_reload_pipeline_unk & 0xF) == 0x4); + if (gfx.partial_reload_pipeline) { + agxdecode_stateful(gfx.partial_reload_pipeline, "Partial reload pipeline", agxdecode_pipeline, verbose); } - if (clearzs.partial_store_pipeline) { - agxdecode_stateful(clearzs.partial_store_pipeline, + if (gfx.partial_store_pipeline) { + agxdecode_stateful(gfx.partial_store_pipeline, "Partial store pipeline", agxdecode_pipeline, verbose); } diff --git a/src/gallium/drivers/asahi/magic.c b/src/gallium/drivers/asahi/magic.c index 767001b..6964eea 100644 --- a/src/gallium/drivers/asahi/magic.c +++ b/src/gallium/drivers/asahi/magic.c @@ -186,7 +186,13 @@ demo_cmdbuf(uint64_t *buf, size_t size, uint64_t depth_buffer = 0; uint64_t stencil_buffer = 0; - agx_pack(map + 160, IOGPU_INTERNAL_PIPELINES, cfg) { + agx_pack(map + 16, IOGPU_GRAPHICS, cfg) { + cfg.opengl_depth_clipping = true; + + cfg.deflake_1 = deflake_1; + cfg.deflake_2 = deflake_2; + cfg.deflake_3 = deflake_buffer; + cfg.clear_pipeline_bind = 0xffff8002 | (clear_pipeline_textures ? 0x210 : 0); cfg.clear_pipeline = pipeline_clear; @@ -223,9 +229,6 @@ demo_cmdbuf(uint64_t *buf, size_t size, cfg.zls_control.s_load_enable = !should_clear_stencil; } - cfg.depth_buffer_if_clearing = depth_buffer; - cfg.stencil_buffer = stencil_buffer; - /* It's unclear how tile size is conveyed for depth/stencil targets, * which interactions with mipmapping (for example of a 33x33 * depth/stencil attachment) @@ -233,18 +236,17 @@ demo_cmdbuf(uint64_t *buf, size_t size, if (zsbuf->u.tex.level != 0) unreachable("todo: mapping other levels"); - cfg.depth_buffer = depth_buffer; + cfg.depth_buffer_1 = depth_buffer; + cfg.depth_buffer_2 = depth_buffer; + + cfg.stencil_buffer_1 = stencil_buffer; cfg.stencil_buffer_2 = stencil_buffer; } - } - agx_pack(map + 228, IOGPU_AUX_FRAMEBUFFER, cfg) { - cfg.width = framebuffer->width; - cfg.height = framebuffer->height; + cfg.width_1 = framebuffer->width; + cfg.height_1 = framebuffer->height; cfg.pointer = unk_buffer_2; - } - agx_pack(map + 292, IOGPU_CLEAR_Z_S, cfg) { cfg.set_when_reloading_z_or_s_1 = clear_pipeline_textures; if (depth_buffer && !should_clear_depth) { @@ -265,16 +267,14 @@ demo_cmdbuf(uint64_t *buf, size_t size, cfg.partial_store_pipeline_bind = 0x12; cfg.partial_store_pipeline = pipeline_store; - } - agx_pack(map + 356, IOGPU_MISC, cfg) { - cfg.depth_buffer = depth_buffer; - cfg.stencil_buffer = stencil_buffer; + cfg.depth_buffer_3 = depth_buffer; + cfg.stencil_buffer_3 = stencil_buffer; cfg.encoder_id = encoder_id; cfg.unknown_buffer = demo_unk6(pool); - cfg.width = framebuffer->width; - cfg.height = framebuffer->height; - cfg.unk_80 = clear_pipeline_textures ? 0x0 : 0x1; + cfg.width_2 = framebuffer->width; + cfg.height_2 = framebuffer->height; + cfg.unk_352 = clear_pipeline_textures ? 0x0 : 0x1; } unsigned offset_unk = (484 * 4); @@ -294,11 +294,6 @@ demo_cmdbuf(uint64_t *buf, size_t size, cfg.attachment_length = nr_attachments * AGX_IOGPU_ATTACHMENT_LENGTH; cfg.unknown_offset = offset_unk; cfg.encoder = encoder_ptr; - cfg.opengl_depth_clipping = true; - - cfg.deflake_1 = deflake_1; - cfg.deflake_2 = deflake_2; - cfg.deflake_3 = deflake_buffer; } return total_size; -- 2.7.4