1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (c) 2012-2015 Etnaviv Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 12bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 13bf215546Sopenharmony_ci * of the Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Wladimir J. van der Laan <laanwj@gmail.com> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#ifndef H_ETNAVIV_COMPILER 28bf215546Sopenharmony_ci#define H_ETNAVIV_COMPILER 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "etnaviv_context.h" 31bf215546Sopenharmony_ci#include "etnaviv_internal.h" 32bf215546Sopenharmony_ci#include "etnaviv_shader.h" 33bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 34bf215546Sopenharmony_ci#include "pipe/p_shader_tokens.h" 35bf215546Sopenharmony_ci#include "compiler/shader_enums.h" 36bf215546Sopenharmony_ci#include "util/disk_cache.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci/* XXX some of these are pretty arbitrary limits, may be better to switch 39bf215546Sopenharmony_ci * to dynamic allocation at some point. 40bf215546Sopenharmony_ci */ 41bf215546Sopenharmony_ci#define ETNA_MAX_TEMPS (64) /* max temp register count of all Vivante hw */ 42bf215546Sopenharmony_ci#define ETNA_MAX_TOKENS (2048) 43bf215546Sopenharmony_ci#define ETNA_MAX_IMM (1024) /* max const+imm in 32-bit words */ 44bf215546Sopenharmony_ci#define ETNA_MAX_DEPTH (32) 45bf215546Sopenharmony_ci#define ETNA_MAX_INSTRUCTIONS (2048) 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci/** 48bf215546Sopenharmony_ci * Compiler state saved across compiler invocations, for any expensive global 49bf215546Sopenharmony_ci * setup. 50bf215546Sopenharmony_ci */ 51bf215546Sopenharmony_cistruct etna_compiler { 52bf215546Sopenharmony_ci uint32_t shader_count; 53bf215546Sopenharmony_ci struct ra_regs *regs; 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci nir_shader_compiler_options options; 56bf215546Sopenharmony_ci struct disk_cache *disk_cache; 57bf215546Sopenharmony_ci}; 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci/* compiler output per input/output */ 60bf215546Sopenharmony_cistruct etna_shader_inout { 61bf215546Sopenharmony_ci int reg; /* native register */ 62bf215546Sopenharmony_ci int slot; /* nir: gl_varying_slot or gl_vert_attrib */ 63bf215546Sopenharmony_ci int num_components; 64bf215546Sopenharmony_ci}; 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_cistruct etna_shader_io_file { 67bf215546Sopenharmony_ci size_t num_reg; 68bf215546Sopenharmony_ci struct etna_shader_inout reg[ETNA_NUM_INPUTS]; 69bf215546Sopenharmony_ci}; 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci/* shader object, for linking */ 72bf215546Sopenharmony_cistruct etna_shader_variant { 73bf215546Sopenharmony_ci uint32_t id; /* for debug */ 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci /* shader variants form a linked list */ 76bf215546Sopenharmony_ci struct etna_shader_variant *next; 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci /* replicated here to avoid passing extra ptrs everywhere */ 79bf215546Sopenharmony_ci struct etna_shader *shader; 80bf215546Sopenharmony_ci struct etna_shader_key key; 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci struct etna_bo *bo; /* cached code memory bo handle (for icache) */ 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci /* 85bf215546Sopenharmony_ci * Below here is serialized when written to disk cache: 86bf215546Sopenharmony_ci */ 87bf215546Sopenharmony_ci uint32_t *code; 88bf215546Sopenharmony_ci struct etna_shader_uniform_info uniforms; 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci /* 91bf215546Sopenharmony_ci * The following macros are used by the shader disk cache save/ 92bf215546Sopenharmony_ci * restore paths to serialize/deserialize the variant. Any 93bf215546Sopenharmony_ci * pointers that require special handling in store_variant() 94bf215546Sopenharmony_ci * and retrieve_variant() should go above here. 95bf215546Sopenharmony_ci */ 96bf215546Sopenharmony_ci#define VARIANT_CACHE_START offsetof(struct etna_shader_variant, stage) 97bf215546Sopenharmony_ci#define VARIANT_CACHE_PTR(v) (((char *)v) + VARIANT_CACHE_START) 98bf215546Sopenharmony_ci#define VARIANT_CACHE_SIZE (sizeof(struct etna_shader_variant) - VARIANT_CACHE_START) 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ci gl_shader_stage stage; 101bf215546Sopenharmony_ci uint32_t code_size; /* code size in uint32 words */ 102bf215546Sopenharmony_ci unsigned num_loops; 103bf215546Sopenharmony_ci unsigned num_temps; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci /* ETNA_DIRTY_* flags that, when set in context dirty, mean that the 106bf215546Sopenharmony_ci * uniforms have to get (partial) reloaded. */ 107bf215546Sopenharmony_ci uint32_t uniforms_dirty_bits; 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci /* inputs (for linking) for fs, the inputs must be in register 1..N */ 110bf215546Sopenharmony_ci struct etna_shader_io_file infile; 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci /* outputs (for linking) */ 113bf215546Sopenharmony_ci struct etna_shader_io_file outfile; 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci /* special inputs/outputs (vs only) */ 116bf215546Sopenharmony_ci int vs_id_in_reg; /* vertexid+instanceid input */ 117bf215546Sopenharmony_ci int vs_pos_out_reg; /* VS position output */ 118bf215546Sopenharmony_ci int vs_pointsize_out_reg; /* VS point size output */ 119bf215546Sopenharmony_ci uint32_t vs_load_balancing; 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci /* special outputs (ps only) */ 122bf215546Sopenharmony_ci int ps_color_out_reg; /* color output register */ 123bf215546Sopenharmony_ci int ps_depth_out_reg; /* depth output register */ 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci /* unknown input property (XX_INPUT_COUNT, field UNK8) */ 126bf215546Sopenharmony_ci uint32_t input_count_unk8; 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci /* shader is larger than GPU instruction limit, thus needs icache */ 129bf215546Sopenharmony_ci bool needs_icache; 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci /* shader uses pixel kill/discard */ 132bf215546Sopenharmony_ci bool uses_discard; 133bf215546Sopenharmony_ci}; 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_cistruct etna_varying { 136bf215546Sopenharmony_ci uint32_t pa_attributes; 137bf215546Sopenharmony_ci uint8_t num_components; 138bf215546Sopenharmony_ci uint8_t use[4]; 139bf215546Sopenharmony_ci uint8_t reg; 140bf215546Sopenharmony_ci}; 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_cistruct etna_shader_link_info { 143bf215546Sopenharmony_ci /* each PS input is annotated with the VS output reg */ 144bf215546Sopenharmony_ci unsigned num_varyings; 145bf215546Sopenharmony_ci struct etna_varying varyings[ETNA_NUM_INPUTS]; 146bf215546Sopenharmony_ci int pcoord_varying_comp_ofs; 147bf215546Sopenharmony_ci}; 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_cistruct etna_compiler * 150bf215546Sopenharmony_cietna_compiler_create(const char *renderer, const struct etna_specs *specs); 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_civoid 153bf215546Sopenharmony_cietna_compiler_destroy(const struct etna_compiler *compiler); 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ciconst nir_shader_compiler_options * 156bf215546Sopenharmony_cietna_compiler_get_options(struct etna_compiler *compiler); 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_cibool 159bf215546Sopenharmony_cietna_compile_shader(struct etna_shader_variant *shader); 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_civoid 162bf215546Sopenharmony_cietna_dump_shader(const struct etna_shader_variant *shader); 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_cibool 165bf215546Sopenharmony_cietna_link_shader(struct etna_shader_link_info *info, 166bf215546Sopenharmony_ci const struct etna_shader_variant *vs, 167bf215546Sopenharmony_ci const struct etna_shader_variant *fs); 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_civoid 170bf215546Sopenharmony_cietna_destroy_shader(struct etna_shader_variant *shader); 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci#endif 173