Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_compiler.h
4570 views
/*1* Copyright (c) 2012-2015 Etnaviv Project2*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, sub license,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 the11* next paragraph) shall be included in all copies or substantial portions12* of the 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 NON-INFRINGEMENT. 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 OTHER20* DEALINGS IN THE SOFTWARE.21*22* Authors:23* Wladimir J. van der Laan <[email protected]>24*/2526#ifndef H_ETNAVIV_COMPILER27#define H_ETNAVIV_COMPILER2829#include "etnaviv_context.h"30#include "etnaviv_internal.h"31#include "etnaviv_shader.h"32#include "pipe/p_compiler.h"33#include "pipe/p_shader_tokens.h"34#include "compiler/shader_enums.h"35#include "util/disk_cache.h"3637/* XXX some of these are pretty arbitrary limits, may be better to switch38* to dynamic allocation at some point.39*/40#define ETNA_MAX_TEMPS (64) /* max temp register count of all Vivante hw */41#define ETNA_MAX_TOKENS (2048)42#define ETNA_MAX_IMM (1024) /* max const+imm in 32-bit words */43#define ETNA_MAX_DECL (2048) /* max declarations */44#define ETNA_MAX_DEPTH (32)45#define ETNA_MAX_INSTRUCTIONS (2048)4647/**48* Compiler state saved across compiler invocations, for any expensive global49* setup.50*/51struct etna_compiler {52uint32_t shader_count;53struct ra_regs *regs;5455struct disk_cache *disk_cache;56};5758/* compiler output per input/output */59struct etna_shader_inout {60int reg; /* native register */61int slot; /* nir: gl_varying_slot or gl_vert_attrib */62int num_components;63};6465struct etna_shader_io_file {66size_t num_reg;67struct etna_shader_inout reg[ETNA_NUM_INPUTS];68};6970/* shader object, for linking */71struct etna_shader_variant {72uint32_t id; /* for debug */7374/* shader variants form a linked list */75struct etna_shader_variant *next;7677/* replicated here to avoid passing extra ptrs everywhere */78struct etna_shader *shader;79struct etna_shader_key key;8081struct etna_bo *bo; /* cached code memory bo handle (for icache) */8283/*84* Below here is serialized when written to disk cache:85*/86uint32_t *code;87struct etna_shader_uniform_info uniforms;8889/*90* The following macros are used by the shader disk cache save/91* restore paths to serialize/deserialize the variant. Any92* pointers that require special handling in store_variant()93* and retrieve_variant() should go above here.94*/95#define VARIANT_CACHE_START offsetof(struct etna_shader_variant, stage)96#define VARIANT_CACHE_PTR(v) (((char *)v) + VARIANT_CACHE_START)97#define VARIANT_CACHE_SIZE (sizeof(struct etna_shader_variant) - VARIANT_CACHE_START)9899gl_shader_stage stage;100uint32_t code_size; /* code size in uint32 words */101unsigned num_loops;102unsigned num_temps;103104/* ETNA_DIRTY_* flags that, when set in context dirty, mean that the105* uniforms have to get (partial) reloaded. */106uint32_t uniforms_dirty_bits;107108/* inputs (for linking) for fs, the inputs must be in register 1..N */109struct etna_shader_io_file infile;110111/* outputs (for linking) */112struct etna_shader_io_file outfile;113114/* special inputs/outputs (vs only) */115int vs_id_in_reg; /* vertexid+instanceid input */116int vs_pos_out_reg; /* VS position output */117int vs_pointsize_out_reg; /* VS point size output */118uint32_t vs_load_balancing;119120/* special outputs (ps only) */121int ps_color_out_reg; /* color output register */122int ps_depth_out_reg; /* depth output register */123124/* unknown input property (XX_INPUT_COUNT, field UNK8) */125uint32_t input_count_unk8;126127/* shader is larger than GPU instruction limit, thus needs icache */128bool needs_icache;129130/* shader uses pixel kill/discard */131bool uses_discard;132};133134struct etna_varying {135uint32_t pa_attributes;136uint8_t num_components;137uint8_t use[4];138uint8_t reg;139};140141struct etna_shader_link_info {142/* each PS input is annotated with the VS output reg */143unsigned num_varyings;144struct etna_varying varyings[ETNA_NUM_INPUTS];145int pcoord_varying_comp_ofs;146};147148struct etna_compiler *149etna_compiler_create(const char *renderer);150151void152etna_compiler_destroy(const struct etna_compiler *compiler);153154bool155etna_compile_shader(struct etna_shader_variant *shader);156157void158etna_dump_shader(const struct etna_shader_variant *shader);159160bool161etna_link_shader(struct etna_shader_link_info *info,162const struct etna_shader_variant *vs, const struct etna_shader_variant *fs);163164void165etna_destroy_shader(struct etna_shader_variant *shader);166167/* NIR compiler */168169bool170etna_compile_shader_nir(struct etna_shader_variant *shader);171172bool173etna_link_shader_nir(struct etna_shader_link_info *info,174const struct etna_shader_variant *vs,175const struct etna_shader_variant *fs);176177#endif178179180