1b8e80941Smrg/* 2b8e80941Smrg * Copyright (c) 2012-2015 Etnaviv Project 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sub license, 8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 9b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the 12b8e80941Smrg * next paragraph) shall be included in all copies or substantial portions 13b8e80941Smrg * of the Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21b8e80941Smrg * DEALINGS IN THE SOFTWARE. 22b8e80941Smrg * 23b8e80941Smrg * Authors: 24b8e80941Smrg * Wladimir J. van der Laan <laanwj@gmail.com> 25b8e80941Smrg */ 26b8e80941Smrg 27b8e80941Smrg#ifndef H_ETNAVIV_COMPILER 28b8e80941Smrg#define H_ETNAVIV_COMPILER 29b8e80941Smrg 30b8e80941Smrg#include "etnaviv_context.h" 31b8e80941Smrg#include "etnaviv_internal.h" 32b8e80941Smrg#include "etnaviv_shader.h" 33b8e80941Smrg#include "pipe/p_compiler.h" 34b8e80941Smrg#include "pipe/p_shader_tokens.h" 35b8e80941Smrg 36b8e80941Smrg/* XXX some of these are pretty arbitrary limits, may be better to switch 37b8e80941Smrg * to dynamic allocation at some point. 38b8e80941Smrg */ 39b8e80941Smrg#define ETNA_MAX_TEMPS (64) /* max temp register count of all Vivante hw */ 40b8e80941Smrg#define ETNA_MAX_TOKENS (2048) 41b8e80941Smrg#define ETNA_MAX_IMM (1024) /* max const+imm in 32-bit words */ 42b8e80941Smrg#define ETNA_MAX_DECL (2048) /* max declarations */ 43b8e80941Smrg#define ETNA_MAX_DEPTH (32) 44b8e80941Smrg#define ETNA_MAX_INSTRUCTIONS (2048) 45b8e80941Smrg 46b8e80941Smrg/* compiler output per input/output */ 47b8e80941Smrgstruct etna_shader_inout { 48b8e80941Smrg int reg; /* native register */ 49b8e80941Smrg struct tgsi_declaration_semantic semantic; /* tgsi semantic name and index */ 50b8e80941Smrg int num_components; 51b8e80941Smrg}; 52b8e80941Smrg 53b8e80941Smrgstruct etna_shader_io_file { 54b8e80941Smrg size_t num_reg; 55b8e80941Smrg struct etna_shader_inout reg[ETNA_NUM_INPUTS]; 56b8e80941Smrg}; 57b8e80941Smrg 58b8e80941Smrg/* shader object, for linking */ 59b8e80941Smrgstruct etna_shader_variant { 60b8e80941Smrg uint32_t id; /* for debug */ 61b8e80941Smrg 62b8e80941Smrg uint processor; /* TGSI_PROCESSOR_... */ 63b8e80941Smrg uint32_t code_size; /* code size in uint32 words */ 64b8e80941Smrg uint32_t *code; 65b8e80941Smrg unsigned num_loops; 66b8e80941Smrg unsigned num_temps; 67b8e80941Smrg 68b8e80941Smrg struct etna_shader_uniform_info uniforms; 69b8e80941Smrg 70b8e80941Smrg /* ETNA_DIRTY_* flags that, when set in context dirty, mean that the 71b8e80941Smrg * uniforms have to get (partial) reloaded. */ 72b8e80941Smrg uint32_t uniforms_dirty_bits; 73b8e80941Smrg 74b8e80941Smrg /* inputs (for linking) for fs, the inputs must be in register 1..N */ 75b8e80941Smrg struct etna_shader_io_file infile; 76b8e80941Smrg 77b8e80941Smrg /* outputs (for linking) */ 78b8e80941Smrg struct etna_shader_io_file outfile; 79b8e80941Smrg 80b8e80941Smrg /* index into outputs (for linking) */ 81b8e80941Smrg int output_count_per_semantic[TGSI_SEMANTIC_COUNT]; 82b8e80941Smrg struct etna_shader_inout * *output_per_semantic_list; /* list of pointers to outputs */ 83b8e80941Smrg struct etna_shader_inout **output_per_semantic[TGSI_SEMANTIC_COUNT]; 84b8e80941Smrg 85b8e80941Smrg /* special outputs (vs only) */ 86b8e80941Smrg int vs_pos_out_reg; /* VS position output */ 87b8e80941Smrg int vs_pointsize_out_reg; /* VS point size output */ 88b8e80941Smrg uint32_t vs_load_balancing; 89b8e80941Smrg 90b8e80941Smrg /* special outputs (ps only) */ 91b8e80941Smrg int ps_color_out_reg; /* color output register */ 92b8e80941Smrg int ps_depth_out_reg; /* depth output register */ 93b8e80941Smrg 94b8e80941Smrg /* unknown input property (XX_INPUT_COUNT, field UNK8) */ 95b8e80941Smrg uint32_t input_count_unk8; 96b8e80941Smrg 97b8e80941Smrg /* shader is larger than GPU instruction limit, thus needs icache */ 98b8e80941Smrg bool needs_icache; 99b8e80941Smrg 100b8e80941Smrg /* shader variants form a linked list */ 101b8e80941Smrg struct etna_shader_variant *next; 102b8e80941Smrg 103b8e80941Smrg /* replicated here to avoid passing extra ptrs everywhere */ 104b8e80941Smrg struct etna_shader *shader; 105b8e80941Smrg struct etna_shader_key key; 106b8e80941Smrg 107b8e80941Smrg struct etna_bo *bo; /* cached code memory bo handle (for icache) */ 108b8e80941Smrg}; 109b8e80941Smrg 110b8e80941Smrgstruct etna_varying { 111b8e80941Smrg uint32_t pa_attributes; 112b8e80941Smrg uint8_t num_components; 113b8e80941Smrg uint8_t use[4]; 114b8e80941Smrg uint8_t reg; 115b8e80941Smrg}; 116b8e80941Smrg 117b8e80941Smrgstruct etna_shader_link_info { 118b8e80941Smrg /* each PS input is annotated with the VS output reg */ 119b8e80941Smrg unsigned num_varyings; 120b8e80941Smrg struct etna_varying varyings[ETNA_NUM_INPUTS]; 121b8e80941Smrg int pcoord_varying_comp_ofs; 122b8e80941Smrg}; 123b8e80941Smrg 124b8e80941Smrgbool 125b8e80941Smrgetna_compile_shader(struct etna_shader_variant *shader); 126b8e80941Smrg 127b8e80941Smrgvoid 128b8e80941Smrgetna_dump_shader(const struct etna_shader_variant *shader); 129b8e80941Smrg 130b8e80941Smrgbool 131b8e80941Smrgetna_link_shader(struct etna_shader_link_info *info, 132b8e80941Smrg const struct etna_shader_variant *vs, const struct etna_shader_variant *fs); 133b8e80941Smrg 134b8e80941Smrgvoid 135b8e80941Smrgetna_destroy_shader(struct etna_shader_variant *shader); 136b8e80941Smrg 137b8e80941Smrg#endif 138