Path: blob/21.2-virgl/src/broadcom/common/v3d_util.c
4560 views
/*1* Copyright © 2021 Raspberry Pi2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "v3d_util.h"24#include "util/macros.h"2526/* Choose a number of workgroups per supergroup that maximizes27* lane occupancy. We can pack up to 16 workgroups into a supergroup.28*/29uint32_t30v3d_csd_choose_workgroups_per_supergroup(struct v3d_device_info *devinfo,31bool has_subgroups,32bool has_tsy_barrier,33uint32_t threads,34uint32_t num_wgs,35uint32_t wg_size)36{37/* FIXME: subgroups may restrict supergroup packing. For now, we disable it38* completely if the shader uses subgroups.39*/40if (has_subgroups)41return 1;4243/* Compute maximum number of batches in a supergroup for this workgroup size.44* Each batch is 16 elements, and we can have up to 16 work groups in a45* supergroup:46*47* max_batches_per_sg = (wg_size * max_wgs_per_sg) / elements_per_batch48* since max_wgs_per_sg = 16 and elements_per_batch = 16, we get:49* max_batches_per_sg = wg_size50*/51uint32_t max_batches_per_sg = wg_size;5253/* QPU threads will stall at TSY barriers until the entire supergroup54* reaches the barrier. Limit the supergroup size to half the QPU threads55* available, so we can have at least 2 supergroups executing in parallel56* and we don't stall all our QPU threads when a supergroup hits a barrier.57*/58if (has_tsy_barrier) {59uint32_t max_qpu_threads = devinfo->qpu_count * threads;60max_batches_per_sg = MIN2(max_batches_per_sg, max_qpu_threads / 2);61}62uint32_t max_wgs_per_sg = max_batches_per_sg * 16 / wg_size;6364uint32_t best_wgs_per_sg = 1;65uint32_t best_unused_lanes = 16;66for (uint32_t wgs_per_sg = 1; wgs_per_sg <= max_wgs_per_sg; wgs_per_sg++) {67/* Don't try to pack more workgroups per supergroup than the total amount68* of workgroups dispatched.69*/70if (wgs_per_sg > num_wgs)71return best_wgs_per_sg;7273/* Compute wasted lines for this configuration and keep track of the74* config with less waste.75*/76uint32_t unused_lanes = (16 - ((wgs_per_sg * wg_size) % 16)) & 0x0f;77if (unused_lanes == 0)78return wgs_per_sg;7980if (unused_lanes < best_unused_lanes) {81best_wgs_per_sg = wgs_per_sg;82best_unused_lanes = unused_lanes;83}84}8586return best_wgs_per_sg;87}888990