Path: blob/21.2-virgl/src/asahi/compiler/agx_compile.h
4564 views
/*1* Copyright (C) 2018-2021 Alyssa Rosenzweig <[email protected]>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#ifndef __AGX_PUBLIC_H_24#define __AGX_PUBLIC_H_2526#include "compiler/nir/nir.h"27#include "util/u_dynarray.h"28#include "asahi/lib/agx_pack.h"2930enum agx_push_type {31/* Array of 64-bit pointers to the base addresses (BASES) and array of32* 16-bit sizes for optional bounds checking (SIZES) */33AGX_PUSH_UBO_BASES = 0,34AGX_PUSH_UBO_SIZES = 1,35AGX_PUSH_VBO_BASES = 2,36AGX_PUSH_VBO_SIZES = 3,37AGX_PUSH_SSBO_BASES = 4,38AGX_PUSH_SSBO_SIZES = 5,3940/* Push the attached constant memory */41AGX_PUSH_CONSTANTS = 6,4243/* Push the content of a UBO */44AGX_PUSH_UBO_DATA = 7,4546/* RGBA blend constant (FP32) */47AGX_PUSH_BLEND_CONST = 8,4849/* Keep last */50AGX_PUSH_NUM_TYPES51};5253struct agx_push {54/* Contents to push */55enum agx_push_type type : 8;5657/* Base of where to push, indexed in 16-bit units. The uniform file contains58* 512 = 2^9 such units. */59unsigned base : 9;6061/* Number of 16-bit units to push */62unsigned length : 9;6364/* If set, rather than pushing the specified data, push a pointer to the65* specified data. This is slower to access but enables indirect access, as66* the uniform file does not support indirection. */67bool indirect : 1;6869union {70struct {71uint16_t ubo;72uint16_t offset;73} ubo_data;74};75};7677/* Arbitrary */78#define AGX_MAX_PUSH_RANGES (16)79#define AGX_MAX_VARYINGS (32)8081struct agx_varyings {82unsigned nr_descs, nr_slots;83struct agx_varying_packed packed[AGX_MAX_VARYINGS];84};8586struct agx_shader_info {87unsigned push_ranges;88struct agx_push push[AGX_MAX_PUSH_RANGES];89struct agx_varyings varyings;9091/* Does the shader read the tilebuffer? */92bool reads_tib;9394/* Does the shader write point size? */95bool writes_psiz;96};9798#define AGX_MAX_RTS (8)99#define AGX_MAX_ATTRIBS (16)100#define AGX_MAX_VBUFS (16)101102enum agx_format {103AGX_FORMAT_I8 = 0,104AGX_FORMAT_I16 = 1,105AGX_FORMAT_I32 = 2,106AGX_FORMAT_F16 = 3,107AGX_FORMAT_U8NORM = 4,108AGX_FORMAT_S8NORM = 5,109AGX_FORMAT_U16NORM = 6,110AGX_FORMAT_S16NORM = 7,111AGX_FORMAT_RGB10A2 = 8,112AGX_FORMAT_SRGBA8 = 10,113AGX_FORMAT_RG11B10F = 12,114AGX_FORMAT_RGB9E5 = 13,115116/* Keep last */117AGX_NUM_FORMATS,118};119120struct agx_attribute {121unsigned buf : 5;122unsigned src_offset : 16;123unsigned nr_comps_minus_1 : 2;124enum agx_format format : 4;125};126127struct agx_vs_shader_key {128unsigned num_vbufs;129unsigned vbuf_strides[AGX_MAX_VBUFS];130131struct agx_attribute attributes[AGX_MAX_ATTRIBS];132133/* Set to true for clip coordinates to range [0, 1] instead of [-1, 1] */134bool clip_halfz : 1;135};136137struct agx_fs_shader_key {138enum agx_format tib_formats[AGX_MAX_RTS];139};140141struct agx_shader_key {142union {143struct agx_vs_shader_key vs;144struct agx_fs_shader_key fs;145};146};147148void149agx_compile_shader_nir(nir_shader *nir,150struct agx_shader_key *key,151struct util_dynarray *binary,152struct agx_shader_info *out);153154static const nir_shader_compiler_options agx_nir_options = {155.lower_scmp = true,156.lower_flrp16 = true,157.lower_flrp32 = true,158.lower_ffract = true,159.lower_fmod = true,160.lower_fdiv = true,161.lower_isign = true,162.lower_iabs = true,163.lower_fpow = true,164.lower_find_lsb = true,165.lower_ifind_msb = true,166.lower_fdph = true,167.lower_wpos_pntc = true,168.lower_fsign = true,169.lower_rotate = true,170.lower_pack_split = true,171.lower_insert_byte = true,172.lower_insert_word = true,173.lower_uniforms_to_ubo = true,174.lower_cs_local_index_from_id = true,175176.lower_doubles_options = nir_lower_dmod,177.lower_int64_options = ~(nir_lower_iadd64 | nir_lower_imul_2x32_64),178179.has_fsub = true,180.has_isub = true,181.has_cs_global_id = true,182183.vectorize_io = true,184.fuse_ffma16 = true,185.fuse_ffma32 = true,186.use_interpolated_input_intrinsics = true,187};188189#endif190191192