From 93695ceb4841813fe4668ea63be0d196e9fa9ef7 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 17 Aug 2024 15:09:30 -0400 Subject: [PATCH] asahi: factor out agx_usc_shared_non_fragment Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/agx_usc.h | 34 +++++++++++++++++++++++++++ src/gallium/drivers/asahi/agx_state.c | 22 +---------------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/asahi/lib/agx_usc.h b/src/asahi/lib/agx_usc.h index ed9e4e911d0..7348eb984db 100644 --- a/src/asahi/lib/agx_usc.h +++ b/src/asahi/lib/agx_usc.h @@ -6,6 +6,7 @@ #pragma once #include "asahi/genxml/agx_pack.h" +#include "agx_compile.h" /* Opaque structure representing a USC program being constructed */ struct agx_usc_builder { @@ -103,3 +104,36 @@ agx_usc_shared_none(struct agx_usc_builder *b) cfg.bytes_per_threadgroup = 65536; } } + +static void +agx_usc_shared_non_fragment(struct agx_usc_builder *b, + struct agx_shader_info *info, + unsigned variable_shared_mem) +{ + if (info->stage == PIPE_SHADER_FRAGMENT) { + return; + } else if (info->stage == PIPE_SHADER_COMPUTE && info->imageblock_stride) { + assert(info->local_size == 0 && "we don't handle this interaction"); + assert(variable_shared_mem == 0 && "we don't handle this interaction"); + + agx_usc_pack(b, SHARED, cfg) { + cfg.layout = AGX_SHARED_LAYOUT_32X32; + cfg.uses_shared_memory = true; + cfg.sample_count = 1; + cfg.sample_stride_in_8_bytes = + DIV_ROUND_UP(info->imageblock_stride, 8); + cfg.bytes_per_threadgroup = cfg.sample_stride_in_8_bytes * 8 * 32 * 32; + } + } else if (info->stage == PIPE_SHADER_COMPUTE || + info->stage == PIPE_SHADER_TESS_CTRL) { + unsigned size = info->local_size + variable_shared_mem; + + agx_usc_pack(b, SHARED, cfg) { + cfg.layout = AGX_SHARED_LAYOUT_VERTEX_COMPUTE; + cfg.bytes_per_threadgroup = size > 0 ? size : 65536; + cfg.uses_shared_memory = size > 0; + } + } else { + agx_usc_shared_none(b); + } +} diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 5361dab403b..8a8ab4e4784 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -2986,28 +2986,8 @@ agx_build_pipeline(struct agx_batch *batch, struct agx_compiled_shader *cs, if (stage == PIPE_SHADER_FRAGMENT) { agx_usc_push_packed(&b, SHARED, &batch->tilebuffer_layout.usc); - } else if (stage == PIPE_SHADER_COMPUTE && cs->b.info.imageblock_stride) { - assert(cs->b.info.local_size == 0 && "we don't handle this interaction"); - assert(variable_shared_mem == 0 && "we don't handle this interaction"); - - agx_usc_pack(&b, SHARED, cfg) { - cfg.layout = AGX_SHARED_LAYOUT_32X32; - cfg.uses_shared_memory = true; - cfg.sample_count = 1; - cfg.sample_stride_in_8_bytes = - DIV_ROUND_UP(cs->b.info.imageblock_stride, 8); - cfg.bytes_per_threadgroup = cfg.sample_stride_in_8_bytes * 8 * 32 * 32; - } - } else if (stage == PIPE_SHADER_COMPUTE || stage == PIPE_SHADER_TESS_CTRL) { - unsigned size = cs->b.info.local_size + variable_shared_mem; - - agx_usc_pack(&b, SHARED, cfg) { - cfg.layout = AGX_SHARED_LAYOUT_VERTEX_COMPUTE; - cfg.bytes_per_threadgroup = size > 0 ? size : 65536; - cfg.uses_shared_memory = size > 0; - } } else { - agx_usc_shared_none(&b); + agx_usc_shared_non_fragment(&b, &cs->b.info, variable_shared_mem); } if (linked) {