Path: blob/21.2-virgl/src/freedreno/common/freedreno_devices.py
4565 views
#1# Copyright © 2021 Google, Inc.2#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.2122from mako.template import Template23import sys2425def max_bitfield_val(high, low, shift):26return ((1 << (high - low)) - 1) << shift2728class State(object):29def __init__(self):30# List of unique device-info structs, multiple different GPU ids31# can map to a single info struct in cases where the differences32# are not sw visible, or the only differences are parameters33# queried from the kernel (like GMEM size)34self.gpu_infos = []3536# Table mapping GPU id to device-info struct37self.gpus = {}3839def info_index(self, gpu_info):40i = 041for info in self.gpu_infos:42if gpu_info == info:43return i44i += 145raise Error("invalid info")4647s = State()4849def add_gpus(ids, info):50for id in ids:51s.gpus[id] = info5253class GPUId(object):54def __init__(self, gpu_id, name=None):55self.gpu_id = gpu_id56if name == None:57name = "FD%d" % gpu_id58self.name = name5960class Struct(object):61"""A helper class that stringifies itself to a 'C' struct initializer62"""63def __str__(self):64s = "{"65for name, value in vars(self).items():66s += "." + name + "=" + str(value) + ","67return s + "}"6869class GPUInfo(Struct):70"""Base class for any generation of adreno, consists of GMEM layout71related parameters7273Note that tile_max_h is normally only constrained by corresponding74bitfield size/shift (ie. VSC_BIN_SIZE, or similar), but tile_max_h75tends to have lower limits, in which case a comment will describe76the bitfield size/shift77"""78def __init__(self, gmem_align_w, gmem_align_h,79tile_align_w, tile_align_h,80tile_max_w, tile_max_h, num_vsc_pipes):81self.gmem_align_w = gmem_align_w82self.gmem_align_h = gmem_align_h83self.tile_align_w = tile_align_w84self.tile_align_h = tile_align_h85self.tile_max_w = tile_max_w86self.tile_max_h = tile_max_h87self.num_vsc_pipes = num_vsc_pipes8889s.gpu_infos.append(self)909192class A6xxGPUInfo(GPUInfo):93"""The a6xx generation has a lot more parameters, and is broken down94into distinct sub-generations. The template parameter avoids95duplication of parameters that are unique to the sub-generation.96"""97def __init__(self, template, num_sp_cores, num_ccu,98RB_UNKNOWN_8E04_blit, PC_UNKNOWN_9805,99SP_UNKNOWN_A0F8):100super().__init__(gmem_align_w = 16, gmem_align_h = 4,101tile_align_w = 32, tile_align_h = 32,102tile_max_w = 1024, # max_bitfield_val(5, 0, 5)103tile_max_h = max_bitfield_val(14, 8, 4),104num_vsc_pipes = 32)105assert(num_sp_cores == num_ccu)106107self.num_sp_cores = num_sp_cores108109# 96 tile alignment seems correlated to 3 CCU110if num_ccu == 3:111self.tile_align_w = 96112113self.a6xx = Struct()114self.a6xx.magic = Struct()115116# Various "magic" register values:117self.a6xx.magic.RB_UNKNOWN_8E04_blit = RB_UNKNOWN_8E04_blit118self.a6xx.magic.PC_UNKNOWN_9805 = PC_UNKNOWN_9805119self.a6xx.magic.SP_UNKNOWN_A0F8 = SP_UNKNOWN_A0F8120121# Things that earlier gens have and later gens remove, provide122# defaults here and let them be overridden by sub-gen template:123self.a6xx.has_cp_reg_write = True124self.a6xx.has_8bpp_ubwc = True125126for name, val in template.items():127setattr(self.a6xx, name, val)128129# a2xx is really two sub-generations, a20x and a22x, but we don't currently130# capture that in the device-info tables131add_gpus([132GPUId(200),133GPUId(201),134GPUId(205),135GPUId(220),136], GPUInfo(137gmem_align_w = 32, gmem_align_h = 32,138tile_align_w = 32, tile_align_h = 32,139tile_max_w = 512,140tile_max_h = ~0, # TODO141num_vsc_pipes = 8,142))143144add_gpus([145GPUId(305),146GPUId(307),147GPUId(320),148GPUId(330),149], GPUInfo(150gmem_align_w = 32, gmem_align_h = 32,151tile_align_w = 32, tile_align_h = 32,152tile_max_w = 992, # max_bitfield_val(4, 0, 5)153tile_max_h = max_bitfield_val(9, 5, 5),154num_vsc_pipes = 8,155))156157add_gpus([158GPUId(405),159GPUId(420),160GPUId(430),161], GPUInfo(162gmem_align_w = 32, gmem_align_h = 32,163tile_align_w = 32, tile_align_h = 32,164tile_max_w = 1024, # max_bitfield_val(4, 0, 5)165tile_max_h = max_bitfield_val(9, 5, 5),166num_vsc_pipes = 8,167))168169add_gpus([170GPUId(510),171GPUId(530),172GPUId(540),173], GPUInfo(174gmem_align_w = 64, gmem_align_h = 32,175tile_align_w = 64, tile_align_h = 32,176tile_max_w = 1024, # max_bitfield_val(7, 0, 5)177tile_max_h = max_bitfield_val(16, 9, 5),178num_vsc_pipes = 16,179))180181# a6xx can be divided into distinct sub-generations, where certain device-182# info parameters are keyed to the sub-generation. These templates reduce183# the copypaste184185# a615, a618, a630:186a6xx_gen1 = dict(187fibers_per_sp = 128 * 16,188reg_size_vec4 = 96,189ccu_cntl_gmem_unk2 = True,190indirect_draw_wfm_quirk = True,191)192193# a640, a680:194a6xx_gen2 = dict(195fibers_per_sp = 128 * 4 * 16,196reg_size_vec4 = 96,197supports_multiview_mask = True,198has_z24uint_s8uint = True,199indirect_draw_wfm_quirk = True,200)201202# a650:203a6xx_gen3 = dict(204fibers_per_sp = 128 * 2 * 16,205reg_size_vec4 = 64,206supports_multiview_mask = True,207has_z24uint_s8uint = True,208tess_use_shared = True,209storage_16bit = True,210has_tex_filter_cubic = True,211has_sample_locations = True,212)213214# a635, a650:215a6xx_gen4 = dict(216fibers_per_sp = 128 * 2 * 16,217reg_size_vec4 = 64,218supports_multiview_mask = True,219has_z24uint_s8uint = True,220tess_use_shared = True,221storage_16bit = True,222has_tex_filter_cubic = True,223has_sample_locations = True,224has_cp_reg_write = False,225has_8bpp_ubwc = False,226)227228add_gpus([229GPUId(615),230GPUId(618),231], A6xxGPUInfo(232a6xx_gen1,233num_sp_cores = 1,234num_ccu = 1,235RB_UNKNOWN_8E04_blit = 0x00100000,236PC_UNKNOWN_9805 = 0,237SP_UNKNOWN_A0F8 = 0,238))239240add_gpus([241GPUId(630),242], A6xxGPUInfo(243a6xx_gen1,244num_sp_cores = 2,245num_ccu = 2,246RB_UNKNOWN_8E04_blit = 0x01000000,247PC_UNKNOWN_9805 = 1,248SP_UNKNOWN_A0F8 = 1,249))250251add_gpus([252GPUId(640),253], A6xxGPUInfo(254a6xx_gen2,255num_sp_cores = 2,256num_ccu = 2,257RB_UNKNOWN_8E04_blit = 0x00100000,258PC_UNKNOWN_9805 = 1,259SP_UNKNOWN_A0F8 = 1,260))261262add_gpus([263GPUId(650),264], A6xxGPUInfo(265a6xx_gen3,266num_sp_cores = 3,267num_ccu = 3,268RB_UNKNOWN_8E04_blit = 0x04100000,269PC_UNKNOWN_9805 = 2,270SP_UNKNOWN_A0F8 = 2,271))272273add_gpus([274GPUId(635, "Adreno 7c Gen 3"),275], A6xxGPUInfo(276a6xx_gen4,277num_sp_cores = 2,278num_ccu = 2,279RB_UNKNOWN_8E04_blit = 0x00100000,280PC_UNKNOWN_9805 = 1,281SP_UNKNOWN_A0F8 = 1,282))283284add_gpus([285GPUId(660),286], A6xxGPUInfo(287a6xx_gen4,288num_sp_cores = 3,289num_ccu = 3,290RB_UNKNOWN_8E04_blit = 0x04100000,291PC_UNKNOWN_9805 = 2,292SP_UNKNOWN_A0F8 = 2,293))294295template = """\296/* Copyright (C) 2021 Google, Inc.297*298* Permission is hereby granted, free of charge, to any person obtaining a299* copy of this software and associated documentation files (the "Software"),300* to deal in the Software without restriction, including without limitation301* the rights to use, copy, modify, merge, publish, distribute, sublicense,302* and/or sell copies of the Software, and to permit persons to whom the303* Software is furnished to do so, subject to the following conditions:304*305* The above copyright notice and this permission notice (including the next306* paragraph) shall be included in all copies or substantial portions of the307* Software.308*309* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR310* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,311* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL312* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER313* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING314* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS315* IN THE SOFTWARE.316*/317318#include "freedreno_dev_info.h"319320/* Map python to C: */321#define True true322#define False false323324%for info in s.gpu_infos:325static const struct fd_dev_info __info${s.info_index(info)} = ${str(info)};326%endfor327328const struct fd_dev_id fd_dev_ids[] = {329%for id, info in s.gpus.items():330{ ${id.gpu_id}, "${id.name}", &__info${s.info_index(info)} },331%endfor332};333const unsigned fd_dev_ids_count = ${len(s.gpus)};334"""335336print(Template(template).render(s=s))337338339340