Path: blob/21.2-virgl/src/freedreno/ir3/ir3_compiler.h
4565 views
/*1* Copyright (C) 2013 Rob Clark <[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*22* Authors:23* Rob Clark <[email protected]>24*/2526#ifndef IR3_COMPILER_H_27#define IR3_COMPILER_H_2829#include "util/disk_cache.h"30#include "util/log.h"3132#include "ir3.h"3334struct ir3_ra_reg_set;35struct ir3_shader;3637struct ir3_compiler {38struct fd_device *dev;39uint32_t gpu_id;40uint32_t shader_count;4142struct disk_cache *disk_cache;4344/* If true, UBO accesses are assumed to be bounds-checked as defined by45* VK_EXT_robustness2 and optimizations may have to be more conservative.46*/47bool robust_ubo_access;4849/*50* Configuration options for things that are handled differently on51* different generations:52*/5354/* a4xx (and later) drops SP_FS_FLAT_SHAD_MODE_REG_* for flat-interpolate55* so we need to use ldlv.u32 to load the varying directly:56*/57bool flat_bypass;5859/* on a3xx, we need to add one to # of array levels:60*/61bool levels_add_one;6263/* on a3xx, we need to scale up integer coords for isaml based64* on LoD:65*/66bool unminify_coords;6768/* on a3xx do txf_ms w/ isaml and scaled coords: */69bool txf_ms_with_isaml;7071/* on a4xx, for array textures we need to add 0.5 to the array72* index coordinate:73*/74bool array_index_add_half;7576/* on a6xx, rewrite samgp to sequence of samgq0-3 in vertex shaders:77*/78bool samgq_workaround;7980/* on a650, vertex shader <-> tess control io uses LDL/STL */81bool tess_use_shared;8283/* The maximum number of constants, in vec4's, across the entire graphics84* pipeline.85*/86uint16_t max_const_pipeline;8788/* The maximum number of constants, in vec4's, for VS+HS+DS+GS. */89uint16_t max_const_geom;9091/* The maximum number of constants, in vec4's, for FS. */92uint16_t max_const_frag;9394/* A "safe" max constlen that can be applied to each shader in the95* pipeline which we guarantee will never exceed any combined limits.96*/97uint16_t max_const_safe;9899/* The maximum number of constants, in vec4's, for compute shaders. */100uint16_t max_const_compute;101102/* Number of instructions that the shader's base address and length103* (instrlen divides instruction count by this) must be aligned to.104*/105uint32_t instr_align;106107/* on a3xx, the unit of indirect const load is higher than later gens (in108* vec4 units):109*/110uint32_t const_upload_unit;111112/* The base number of threads per wave. Some stages may be able to double113* this.114*/115uint32_t threadsize_base;116117/* On at least a6xx, waves are always launched in pairs. In calculations118* about occupancy, we pretend that each wave pair is actually one wave,119* which simplifies many of the calculations, but means we have to120* multiply threadsize_base by this number.121*/122uint32_t wave_granularity;123124/* The maximum number of simultaneous waves per core. */125uint32_t max_waves;126127/* This is theoretical maximum number of vec4 registers that one wave of128* the base threadsize could use. To get the actual size of the register129* file in bytes one would need to compute:130*131* reg_size_vec4 * threadsize_base * wave_granularity * 16 (bytes per vec4)132*133* However this number is more often what we actually need. For example, a134* max_reg more than half of this will result in a doubled threadsize135* being impossible (because double-sized waves take up twice as many136* registers). Also, the formula for the occupancy given a particular137* register footprint is simpler.138*139* It is in vec4 units because the register file is allocated140* with vec4 granularity, so it's in the same units as max_reg.141*/142uint32_t reg_size_vec4;143144/* The size of local memory in bytes */145uint32_t local_mem_size;146147/* The number of total branch stack entries, divided by wave_granularity. */148uint32_t branchstack_size;149150/* Whether clip+cull distances are supported */151bool has_clip_cull;152153/* Whether private memory is supported */154bool has_pvtmem;155};156157void ir3_compiler_destroy(struct ir3_compiler *compiler);158struct ir3_compiler *ir3_compiler_create(struct fd_device *dev, uint32_t gpu_id,159bool robust_ubo_access);160161void ir3_disk_cache_init(struct ir3_compiler *compiler);162void ir3_disk_cache_init_shader_key(struct ir3_compiler *compiler,163struct ir3_shader *shader);164bool ir3_disk_cache_retrieve(struct ir3_compiler *compiler,165struct ir3_shader_variant *v);166void ir3_disk_cache_store(struct ir3_compiler *compiler,167struct ir3_shader_variant *v);168169int ir3_compile_shader_nir(struct ir3_compiler *compiler,170struct ir3_shader_variant *so);171172/* gpu pointer size in units of 32bit registers/slots */173static inline unsigned174ir3_pointer_size(struct ir3_compiler *compiler)175{176return (compiler->gpu_id >= 500) ? 2 : 1;177}178179enum ir3_shader_debug {180IR3_DBG_SHADER_VS = BITFIELD_BIT(0),181IR3_DBG_SHADER_TCS = BITFIELD_BIT(1),182IR3_DBG_SHADER_TES = BITFIELD_BIT(2),183IR3_DBG_SHADER_GS = BITFIELD_BIT(3),184IR3_DBG_SHADER_FS = BITFIELD_BIT(4),185IR3_DBG_SHADER_CS = BITFIELD_BIT(5),186IR3_DBG_DISASM = BITFIELD_BIT(6),187IR3_DBG_OPTMSGS = BITFIELD_BIT(7),188IR3_DBG_FORCES2EN = BITFIELD_BIT(8),189IR3_DBG_NOUBOOPT = BITFIELD_BIT(9),190IR3_DBG_NOFP16 = BITFIELD_BIT(10),191IR3_DBG_NOCACHE = BITFIELD_BIT(11),192193/* DEBUG-only options: */194IR3_DBG_SCHEDMSGS = BITFIELD_BIT(20),195IR3_DBG_RAMSGS = BITFIELD_BIT(21),196197/* Only used for the disk-caching logic: */198IR3_DBG_ROBUST_UBO_ACCESS = BITFIELD_BIT(30),199};200201extern enum ir3_shader_debug ir3_shader_debug;202extern const char *ir3_shader_override_path;203204static inline bool205shader_debug_enabled(gl_shader_stage type)206{207if (ir3_shader_debug & IR3_DBG_DISASM)208return true;209210switch (type) {211case MESA_SHADER_VERTEX:212return !!(ir3_shader_debug & IR3_DBG_SHADER_VS);213case MESA_SHADER_TESS_CTRL:214return !!(ir3_shader_debug & IR3_DBG_SHADER_TCS);215case MESA_SHADER_TESS_EVAL:216return !!(ir3_shader_debug & IR3_DBG_SHADER_TES);217case MESA_SHADER_GEOMETRY:218return !!(ir3_shader_debug & IR3_DBG_SHADER_GS);219case MESA_SHADER_FRAGMENT:220return !!(ir3_shader_debug & IR3_DBG_SHADER_FS);221case MESA_SHADER_COMPUTE:222return !!(ir3_shader_debug & IR3_DBG_SHADER_CS);223default:224debug_assert(0);225return false;226}227}228229static inline void230ir3_debug_print(struct ir3 *ir, const char *when)231{232if (ir3_shader_debug & IR3_DBG_OPTMSGS) {233mesa_logi("%s:", when);234ir3_print(ir);235}236}237238#endif /* IR3_COMPILER_H_ */239240241