Path: blob/21.2-virgl/src/amd/common/ac_binary.c
7075 views
/*1* Copyright 2014 Advanced Micro Devices, 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, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#include "ac_binary.h"2425#include "ac_gpu_info.h"26#include "util/u_math.h"27#include "util/u_memory.h"2829#include <gelf.h>30#include <libelf.h>31#include <sid.h>32#include <stdio.h>3334#define SPILLED_SGPRS 0x435#define SPILLED_VGPRS 0x83637/* Parse configuration data in .AMDGPU.config section format. */38void ac_parse_shader_binary_config(const char *data, size_t nbytes, unsigned wave_size,39bool really_needs_scratch, const struct radeon_info *info,40struct ac_shader_config *conf)41{42uint32_t scratch_size = 0;4344for (size_t i = 0; i < nbytes; i += 8) {45unsigned reg = util_le32_to_cpu(*(uint32_t *)(data + i));46unsigned value = util_le32_to_cpu(*(uint32_t *)(data + i + 4));47switch (reg) {48case R_00B028_SPI_SHADER_PGM_RSRC1_PS:49case R_00B128_SPI_SHADER_PGM_RSRC1_VS:50case R_00B228_SPI_SHADER_PGM_RSRC1_GS:51case R_00B848_COMPUTE_PGM_RSRC1:52case R_00B428_SPI_SHADER_PGM_RSRC1_HS:53if (wave_size == 32 || info->wave64_vgpr_alloc_granularity == 8)54conf->num_vgprs = MAX2(conf->num_vgprs, (G_00B028_VGPRS(value) + 1) * 8);55else56conf->num_vgprs = MAX2(conf->num_vgprs, (G_00B028_VGPRS(value) + 1) * 4);5758conf->num_sgprs = MAX2(conf->num_sgprs, (G_00B028_SGPRS(value) + 1) * 8);59/* TODO: LLVM doesn't set FLOAT_MODE for non-compute shaders */60conf->float_mode = G_00B028_FLOAT_MODE(value);61conf->rsrc1 = value;62break;63case R_00B02C_SPI_SHADER_PGM_RSRC2_PS:64conf->lds_size = MAX2(conf->lds_size, G_00B02C_EXTRA_LDS_SIZE(value));65/* TODO: LLVM doesn't set SHARED_VGPR_CNT for all shader types */66conf->num_shared_vgprs = G_00B02C_SHARED_VGPR_CNT(value);67conf->rsrc2 = value;68break;69case R_00B12C_SPI_SHADER_PGM_RSRC2_VS:70conf->num_shared_vgprs = G_00B12C_SHARED_VGPR_CNT(value);71conf->rsrc2 = value;72break;73case R_00B22C_SPI_SHADER_PGM_RSRC2_GS:74conf->num_shared_vgprs = G_00B22C_SHARED_VGPR_CNT(value);75conf->rsrc2 = value;76break;77case R_00B42C_SPI_SHADER_PGM_RSRC2_HS:78conf->num_shared_vgprs = G_00B42C_SHARED_VGPR_CNT(value);79conf->rsrc2 = value;80break;81case R_00B84C_COMPUTE_PGM_RSRC2:82conf->lds_size = MAX2(conf->lds_size, G_00B84C_LDS_SIZE(value));83conf->rsrc2 = value;84break;85case R_00B8A0_COMPUTE_PGM_RSRC3:86conf->num_shared_vgprs = G_00B8A0_SHARED_VGPR_CNT(value);87conf->rsrc3 = value;88break;89case R_0286CC_SPI_PS_INPUT_ENA:90conf->spi_ps_input_ena = value;91break;92case R_0286D0_SPI_PS_INPUT_ADDR:93conf->spi_ps_input_addr = value;94break;95case R_0286E8_SPI_TMPRING_SIZE:96case R_00B860_COMPUTE_TMPRING_SIZE:97/* WAVESIZE is in units of 256 dwords. */98scratch_size = value;99break;100case SPILLED_SGPRS:101conf->spilled_sgprs = value;102break;103case SPILLED_VGPRS:104conf->spilled_vgprs = value;105break;106default: {107static bool printed;108109if (!printed) {110fprintf(stderr,111"Warning: LLVM emitted unknown "112"config register: 0x%x\n",113reg);114printed = true;115}116} break;117}118}119120if (!conf->spi_ps_input_addr)121conf->spi_ps_input_addr = conf->spi_ps_input_ena;122123if (really_needs_scratch) {124/* sgprs spills aren't spilling */125conf->scratch_bytes_per_wave = G_00B860_WAVESIZE(scratch_size) * 256 * 4;126}127128/* GFX 10.3 internally:129* - aligns VGPRS to 16 for Wave32 and 8 for Wave64130* - aligns LDS to 1024131*132* For shader-db stats, set num_vgprs that the hw actually uses.133*/134if (info->chip_class >= GFX10_3) {135conf->num_vgprs = align(conf->num_vgprs, wave_size == 32 ? 16 : 8);136}137138/* Enable 64-bit and 16-bit denormals, because there is no performance139* cost.140*141* Don't enable denormals for 32-bit floats, because:142* - denormals disable output modifiers143* - denormals break v_mad_f32144* - GFX6 & GFX7 would be very slow145*/146conf->float_mode &= ~V_00B028_FP_ALL_DENORMS;147conf->float_mode |= V_00B028_FP_64_DENORMS;148}149150151