From 04236b39124264d6b9d969de6cfefbe35ad6b598 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 27 May 2026 09:41:29 -0400 Subject: [PATCH] jay: merge partition blocks The way we construct partitions, it is tricky to avoid empty blocks sometimes leading to mergeable adjacent blocks. Simplify this at runtime. Stats are kind of a mixed bag but this is the obvious right thing to do. simd16: Totals: Instrs: 2752919 -> 2752284 (-0.02%); split: -0.03%, +0.01% CodeSize: 41105312 -> 41096640 (-0.02%); split: -0.03%, +0.01% Totals from 236 (8.92% of 2647) affected shaders: Instrs: 740015 -> 739380 (-0.09%); split: -0.12%, +0.04% CodeSize: 11076496 -> 11067824 (-0.08%); split: -0.11%, +0.04% simd32: Totals: Instrs: 4121085 -> 4121638 (+0.01%); split: -0.01%, +0.02% CodeSize: 61394672 -> 61404720 (+0.02%); split: -0.00%, +0.02% Totals from 145 (5.48% of 2647) affected shaders: Instrs: 1104897 -> 1105450 (+0.05%); split: -0.02%, +0.07% CodeSize: 16845728 -> 16855776 (+0.06%); split: -0.02%, +0.08% Signed-off-by: Alyssa Rosenzweig Part-of: --- src/intel/compiler/jay/jay_partition.c | 49 +++++++++++++++++--------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/intel/compiler/jay/jay_partition.c b/src/intel/compiler/jay/jay_partition.c index 6d489f42170..629d22a1795 100644 --- a/src/intel/compiler/jay/jay_partition.c +++ b/src/intel/compiler/jay/jay_partition.c @@ -36,25 +36,42 @@ build_partition(jay_shader *shader, struct jay_partition_builder *b, unsigned n) .units_x16[MEM] = 16 / jay_grf_per_gpr(shader), }; + /* Drop empty blocks and merge the resulting neighbours. This avoids needless + * partition boundaries that would unnecessarily constrain RA, while allowing + * the caller the convenience of passing in holes sometimes. + */ + signed j = -1; for (unsigned i = 0; i < n; ++i) { - if (b[i].len_grf) { - enum jay_file file = b[i].file; - unsigned len_gpr = (b[i].len_grf * p->units_x16[file]) / 16; - bool grf = file < JAY_NUM_GRF_FILES; - assert(p->nr_blocks[file] < JAY_PARTITION_BLOCKS); + struct jay_partition_builder B = b[i]; + if (j >= 0 && + B.file == b[j].file && + B.stride == b[j].stride && + B.type == b[j].type) { - p->blocks[file][p->nr_blocks[file]++] = (struct jay_register_block) { - .start_grf = grf ? base_grf : 0, - .start_gpr = base_gpr[file], - .len_gpr = (b[i].len_grf * p->units_x16[file]) / 16, - .stride = b[i].stride, - .type = b[i].type, - }; + b[j].len_grf += B.len_grf; + } else if (B.len_grf) { + b[++j] = B; + } + } - if (file < JAY_NUM_GRF_FILES) { - base_grf += b[i].len_grf; - base_gpr[file] += len_gpr; - } + /* Translate to jay_register_block */ + for (signed i = 0; i <= j; ++i) { + enum jay_file file = b[i].file; + unsigned len_gpr = (b[i].len_grf * p->units_x16[file]) / 16; + bool grf = file < JAY_NUM_GRF_FILES; + assert(p->nr_blocks[file] < JAY_PARTITION_BLOCKS); + + p->blocks[file][p->nr_blocks[file]++] = (struct jay_register_block) { + .start_grf = grf ? base_grf : 0, + .start_gpr = base_gpr[file], + .len_gpr = (b[i].len_grf * p->units_x16[file]) / 16, + .stride = b[i].stride, + .type = b[i].type, + }; + + if (file < JAY_NUM_GRF_FILES) { + base_grf += b[i].len_grf; + base_gpr[file] += len_gpr; } }