Path: blob/21.2-virgl/src/panfrost/util/pan_ir.c
4560 views
/*1* Copyright (C) 2020 Collabora Ltd.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*22* Authors (Collabora):23* Alyssa Rosenzweig <[email protected]>24*/2526#include "pan_ir.h"27#include "util/macros.h"2829/* Converts a per-component mask to a byte mask */3031uint16_t32pan_to_bytemask(unsigned bytes, unsigned mask)33{34switch (bytes) {35case 0:36assert(mask == 0);37return 0;3839case 8:40return mask;4142case 16: {43unsigned space =44(mask & 0x1) |45((mask & 0x2) << (2 - 1)) |46((mask & 0x4) << (4 - 2)) |47((mask & 0x8) << (6 - 3)) |48((mask & 0x10) << (8 - 4)) |49((mask & 0x20) << (10 - 5)) |50((mask & 0x40) << (12 - 6)) |51((mask & 0x80) << (14 - 7));5253return space | (space << 1);54}5556case 32: {57unsigned space =58(mask & 0x1) |59((mask & 0x2) << (4 - 1)) |60((mask & 0x4) << (8 - 2)) |61((mask & 0x8) << (12 - 3));6263return space | (space << 1) | (space << 2) | (space << 3);64}6566case 64: {67unsigned A = (mask & 0x1) ? 0xFF : 0x00;68unsigned B = (mask & 0x2) ? 0xFF : 0x00;69return A | (B << 8);70}7172default:73unreachable("Invalid register mode");74}75}7677void78pan_block_add_successor(pan_block *block, pan_block *successor)79{80assert(block);81assert(successor);8283/* Cull impossible edges */84if (block->unconditional_jumps)85return;8687for (unsigned i = 0; i < ARRAY_SIZE(block->successors); ++i) {88if (block->successors[i]) {89if (block->successors[i] == successor)90return;91else92continue;93}9495block->successors[i] = successor;96_mesa_set_add(successor->predecessors, block);97return;98}99100unreachable("Too many successors");101}102103/* Prints a NIR ALU type in Bifrost-style ".f32" ".i8" etc */104105void106pan_print_alu_type(nir_alu_type t, FILE *fp)107{108unsigned size = nir_alu_type_get_type_size(t);109nir_alu_type base = nir_alu_type_get_base_type(t);110111switch (base) {112case nir_type_int:113fprintf(fp, ".i");114break;115case nir_type_uint:116fprintf(fp, ".u");117break;118case nir_type_bool:119fprintf(fp, ".b");120break;121case nir_type_float:122fprintf(fp, ".f");123break;124default:125fprintf(fp, ".unknown");126break;127}128129fprintf(fp, "%u", size);130}131132/* Could optimize with a better data structure if anyone cares, TODO: profile */133134unsigned135pan_lookup_pushed_ubo(struct panfrost_ubo_push *push, unsigned ubo, unsigned offs)136{137struct panfrost_ubo_word word = {138.ubo = ubo,139.offset = offs140};141142for (unsigned i = 0; i < push->count; ++i) {143if (memcmp(push->words + i, &word, sizeof(word)) == 0)144return i;145}146147unreachable("UBO not pushed");148149}150151152